elisp: Fontsets
37.12.11 Fontsets
-----------------
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.
-- Function: create-fontset-from-fontset-spec fontset-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:
FONTPATTERN, [CHARSET:FONT]...
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 status.
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,
-*-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 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.
-- Function: set-fontset-font name character font-spec &optional frame
add
This function modifies the existing fontset NAME to use the font
matching with FONT-SPEC for the specified CHARACTER.
If NAME is ‘nil’, this function modifies the fontset of the
selected frame or that of FRAME if FRAME is not ‘nil’.
If NAME is ‘t’, this function modifies the default fontset, whose
short name is ‘fontset-default’.
In addition to specifying a single codepoint, CHARACTER may be a
cons ‘(FROM . TO)’, where FROM and TO are character codepoints. In
that case, use FONT-SPEC for all the characters in the range FROM
and TO (inclusive).
CHARACTER may be a charset. In that case, use FONT-SPEC for all
character in the charsets.
CHARACTER may be a script name. In that case, use FONT-SPEC for
all character in the charsets.
FONT-SPEC may be a font-spec object created by the function
‘font-spec’ (Low-Level Font).
FONT-SPEC may be a cons; ‘(FAMILY . REGISTRY)’, where FAMILY is a
family name of a font (possibly including a foundry name at the
head), REGISTRY is a registry name of a font (possibly including an
encoding name at the tail).
FONT-SPEC may be a font name string.
FONT-SPEC may be ‘nil’, which explicitly specifies that there’s no
font for the specified CHARACTER. 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. If it is
‘prepend’, FONT-SPEC is prepended. If it is ‘append’, FONT-SPEC is
appended. By default, FONT-SPEC overrides the previous settings.
For instance, this changes the default fontset to use a font of
which family name is ‘Kochi Gothic’ for all characters belonging to
the charset ‘japanese-jisx0208’.
(set-fontset-font t 'japanese-jisx0208
(font-spec :family "Kochi Gothic"))
-- Function: char-displayable-p char
This function returns ‘t’ if Emacs ought to be able to display
CHAR. 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.