elisp: Font Selection
37.12.9 Font Selection
----------------------
Before Emacs can draw a character on a graphical display, it must select
a “font” for that character(1). (emacs)Fonts. Normally, Emacs
automatically chooses a font based on the faces assigned to that
character—specifically, the face attributes ‘:family’, ‘:weight’,
‘:slant’, and ‘:width’ (Face Attributes). The choice of font
also depends on the character to be displayed; some fonts can only
display a limited set of characters. If no available font exactly fits
the requirements, Emacs looks for the “closest matching font”. The
variables in this section control how Emacs makes this selection.
-- User Option: face-font-family-alternatives
If a given family is specified but does not exist, this variable
specifies alternative font families to try. Each element should
have this form:
(FAMILY ALTERNATE-FAMILIES...)
If FAMILY is specified but not available, Emacs will try the other
families given in ALTERNATE-FAMILIES, one by one, until it finds a
family that does exist.
-- User Option: face-font-selection-order
If there is no font that exactly matches all desired face
attributes (‘:width’, ‘:height’, ‘:weight’, and ‘:slant’), this
variable specifies the order in which these attributes should be
considered when selecting the closest matching font. The value
should be a list containing those four attribute symbols, in order
of decreasing importance. The default is ‘(:width :height :weight
:slant)’.
Font selection first finds the best available matches for the first
attribute in the list; then, among the fonts which are best in that
way, it searches for the best matches in the second attribute, and
so on.
The attributes ‘:weight’ and ‘:width’ have symbolic values in a
range centered around ‘normal’. Matches that are more extreme
(farther from ‘normal’) are somewhat preferred to matches that are
less extreme (closer to ‘normal’); this is designed to ensure that
non-normal faces contrast with normal ones, whenever possible.
One example of a case where this variable makes a difference is
when the default font has no italic equivalent. With the default
ordering, the ‘italic’ face will use a non-italic font that is
similar to the default one. But if you put ‘:slant’ before
‘:height’, the ‘italic’ face will use an italic font, even if its
height is not quite right.
-- User Option: face-font-registry-alternatives
This variable lets you specify alternative font registries to try,
if a given registry is specified and doesn’t exist. Each element
should have this form:
(REGISTRY ALTERNATE-REGISTRIES...)
If REGISTRY is specified but not available, Emacs will try the
other registries given in ALTERNATE-REGISTRIES, one by one, until
it finds a registry that does exist.
Emacs can make use of scalable fonts, but by default it does not use
them.
-- User Option: scalable-fonts-allowed
This variable controls which scalable fonts to use. A value of
‘nil’, the default, means do not use scalable fonts. ‘t’ means to
use any scalable font that seems appropriate for the text.
Otherwise, the value must be a list of regular expressions. Then a
scalable font is enabled for use if its name matches any regular
expression in the list. For example,
(setq scalable-fonts-allowed '("iso10646-1$"))
allows the use of scalable fonts with registry ‘iso10646-1’.
-- Variable: face-font-rescale-alist
This variable specifies scaling for certain faces. Its value
should be a list of elements of the form
(FONTNAME-REGEXP . SCALE-FACTOR)
If FONTNAME-REGEXP matches the font name that is about to be used,
this says to choose a larger similar font according to the factor
SCALE-FACTOR. You would use this feature to normalize the font
size if certain fonts are bigger or smaller than their nominal
heights and widths would suggest.
---------- Footnotes ----------
(1) In this context, the term “font” has nothing to do with Font Lock
(Font Lock Mode).