Skip to main content

22.14 Defining Fontsets

When running on X, Emacs creates a standard fontset automatically according to the value of standard-fontset-spec. This fontset’s name is

-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard

or just β€˜fontset-standard’ for short.

On GNUstep and macOS, the standard fontset is created using the value of ns-standard-fontset-spec, and on MS Windows it is created using the value of w32-standard-fontset-spec.

Bold, italic, and bold-italic variants of the standard fontset are created automatically. Their names have β€˜bold’ instead of β€˜medium’, or β€˜i’ instead of β€˜r’, or both.

Emacs generates a fontset automatically, based on any default ASCII font that you specify with the β€˜Font’ resource or the β€˜-fn’ argument, or the default font that Emacs found when it started. This is the startup fontset and its name is fontset-startup. Emacs generates this fontset by replacing the charset_registry field with β€˜fontset’, and replacing the charset_encoding field with β€˜startup’, then using the resulting string to specify a fontset.

For instance, if you start Emacs with a font of this form,

emacs -fn "*courier-medium-r-normal--14-140-*-iso8859-1"

Emacs generates the following fontset and uses it for the initial X window frame:

-*-courier-medium-r-normal-*-14-140-*-*-*-*-fontset-startup

The startup fontset will use the font that you specify, or a variant with a different registry and encoding, for all the characters that are supported by that font, and fallback on β€˜fontset-default’ for other characters.

With the X resource β€˜Emacs.Font’, you can specify a fontset name just like an actual font name. But be careful not to specify a fontset name in a wildcard resource like β€˜Emacs*Font’—that wildcard specification matches various other resources, such as for menus, and menus cannot handle fontsets. See X Resources.

You can specify additional fontsets using X resources named β€˜Fontset-n’, where n is an integer starting from 0. The resource value should have this form:

fontpattern, [charset:font]…

where fontpattern should have the form of a standard X font name (see the previous fontset-startup example), except for the last two fields. They should have the form β€˜fontset-alias’.

Each fontset has two names, one long and one short. The long name is fontpattern. The short name is β€˜fontset-alias’, the last 2 fields of the long name (e.g., β€˜fontset-startup’ for the fontset automatically created at startup). You can refer to the fontset by either name.

The construct β€˜charset:font’ specifies which font to use (in this fontset) for one particular character set. Here, charset is the name of a character set, and font is the font to use for that character set. You can use this construct any number of times in defining one fontset.

For the other character sets, Emacs chooses a font based on fontpattern. It replaces β€˜fontset-alias’ with values that describe the character set. For the ASCII character font, β€˜fontset-alias’ is replaced with β€˜ISO8859-1’.

In addition, when several consecutive fields are wildcards, Emacs collapses them into a single wildcard. This is to prevent use of auto-scaled fonts. Fonts made by scaling larger fonts are not usable for editing, and scaling a smaller font is also not useful, because it is better to use the smaller font in its own size, which is what Emacs does.

Thus if fontpattern is this,

-*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24

the font specification for ASCII characters would be this:

-*-fixed-medium-r-normal-*-24-*-ISO8859-1

and the font specification for Chinese GB2312 characters would be this:

-*-fixed-medium-r-normal-*-24-*-gb2312*-*

You may not have any Chinese font matching the above font specification. Most X distributions include only Chinese fonts that have β€˜song ti’ or β€˜fangsong ti’ in the family field. In such a case, β€˜Fontset-n’ can be specified as:

Emacs.Fontset-0: -*-fixed-medium-r-normal-*-24-*-*-*-*-*-fontset-24,\
chinese-gb2312:-*-*-medium-r-normal-*-24-*-gb2312*-*

Then, the font specifications for all but Chinese GB2312 characters have β€˜fixed’ in the family field, and the font specification for Chinese GB2312 characters has a wild card β€˜*’ in the family field.

The function that processes the fontset resource value to create the fontset is called create-fontset-from-fontset-spec. You can also call this function explicitly to create a fontset.

See Fonts, for more information about font naming.