A fontset is a list of fonts, each assigned to a range of character codes. An individual font cannot display the whole range of characters that Emacs supports, but a fontset can. Fontsets have names, just as fonts do, and you can use a fontset name in place of a font name when you specify the font for a frame or a face. Here is information about defining a fontset under Lisp program control.
create-fontset-from-fontset-specfontset-spec &optional style-variant-p noerror ¶
This function defines a new fontset according to the specification string fontset-spec. The string should have this format:
Whitespace characters before and after the commas are ignored.
The first part of the string, fontpattern, should have the form of a standard X font name, except that the last two fields should be ‘fontset-alias’.
The new fontset has two names, one long and one short. The long name is
fontpattern in its entirety. The short name is
‘fontset-alias’. You can refer to the fontset by either
name. If a fontset with the same name already exists, an error is
signaled, unless noerror is non-
nil, in which case this
function does nothing.
If optional argument style-variant-p is non-
nil, that says
to create bold, italic and bold-italic variants of the fontset as well.
These variant fontsets do not have a short name, only a long one, which
is made by altering fontpattern to indicate the bold and/or italic
The specification string also says which fonts to use in the fontset. See below for the details.
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 the specification string.
For the remaining character sets, those that you don’t specify explicitly, Emacs chooses a font based on fontpattern: it replaces ‘fontset-alias’ with a value that names one character set. For the ASCII character set, ‘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 not useful because it is better to use the smaller font in its own size, which Emacs does.
Thus if fontpattern is this,
the font specification for ASCII characters would be this:
and the font specification for Chinese GB2312 characters would be this:
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 below:
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.
set-fontset-fontfontset characters font-spec &optional frame add ¶
This function modifies the existing fontset to use the font specified by font-spec for displaying the specified characters.
If fontset is
nil, this function modifies the fontset of
the selected frame or that of frame if frame is not
If fontset is
t, this function modifies the default
fontset, whose short name as a string is ‘fontset-default’.
The characters argument can be a single character which should
be displayed using font-spec. It can also be a cons cell
(from . to), where from and to are
characters. In that case, use font-spec for all the characters
in the range from and to (inclusive).
characters may be a charset symbol (see Character Sets). In that case, use font-spec for all the characters in the charset.
characters may be a script symbol (see char-script-table). In that case, use font-spec for all the characters belonging to the script.
characters may be
nil, which means to use font-spec
for any character in fontset for which no font-spec is
font-spec may be a font-spec object created by the function
font-spec (see Low-Level Font Representation).
font-spec may be a cons cell
(family . registry), where family is a family name of a font
(possibly including a foundry name at the head), and registry is
a registry name of a font (possibly including an encoding name at the
font-spec may be a font name, a string.
font-spec may be
nil, which explicitly specifies that
there’s no font for the specified characters. This is useful,
for example, to avoid expensive system-wide search for fonts for
characters that have no glyphs, like those from the Unicode Private
Use Area (PUA).
The optional argument add, if non-
nil, specifies how to
add font-spec to the font specifications previously set for
characters. If it is
prepend, font-spec is
prepended to the existing specs. If it is
font-spec is appended. By default, font-spec overwrites
the previously set font specs.
For instance, this changes the default fontset to use a font whose
family name is ‘Kochi Gothic’ for all characters belonging to
(set-fontset-font t 'japanese-jisx0208 (font-spec :family "Kochi Gothic"))
This function returns non-
nil if Emacs ought to be able to
display char. Or more precisely, if the selected frame’s fontset
has a font to display the character set that char belongs to.
Fontsets can specify a font on a per-character basis; when the fontset does that, this function’s value may not be accurate.
This function may return non-
nil even when there is no font
available, since it also checks whether the coding system for the text
terminal can encode the character (see Terminal I/O Encoding).