Provide an option to disable font instruction code execution

* etc/PROBLEMS: Mention instruction code woes and illustrate how
to circumvent them.

* src/sfntfont.c (sfntfont_setup_interpreter): Respect
Vsfnt_uninstructable_family_regexp.
(syms_of_sfntfont) <Vsfnt_uninstructable_family_regexp>: New
option.
This commit is contained in:
Po Lu 2023-09-11 19:45:58 +08:00
parent f6568dabf2
commit 38e96bee1f
2 changed files with 39 additions and 1 deletions

View file

@ -3526,6 +3526,18 @@ points the test font attempts to hide.
Since this behavior does not influence the display of real fonts, no
action will be taken to address this problem.
** Some other font's instruction code produces undesirable results.
Executing instruction code is not a strict requirement for producing
correct display results from most current fonts. If a font's
instruction code produces results that are merely unpleasing, but not
incorrect, then the font was presumably not designed for Emacs's
scaler. If its uninstructed glyphs are satisfactory (such as if your
screen resolution is high to the extent that scaling artifacts prove
invisible), disable instruction code execution by appending its family
name to the variable 'sfnt-uninstructable-font-regexp', then
restarting Emacs.
** CJK text does not display in Emacs, but does in other programs.
When inserting CJK text into a buffer or visiting a file containing

View file

@ -2667,6 +2667,18 @@ sfntfont_setup_interpreter (struct sfnt_font_info *info,
struct sfnt_interpreter *interpreter;
const char *error;
struct sfnt_graphics_state state;
Lisp_Object regexp;
/* If Vsfnt_uninstructable_family_regexp matches this font, then
return. */
regexp = Vsfnt_uninstructable_family_regexp;
if (STRINGP (regexp)
&& (fast_string_match_ignore_case (regexp,
desc->family)
>= 0))
return;
/* Load the cvt, fpgm and prep already read. */
@ -3952,12 +3964,26 @@ syms_of_sfntfont (void)
of the font backend. */
DEFVAR_LISP ("sfnt-default-family-alist", Vsfnt_default_family_alist,
doc: /* Alist between "emulated" and actual font family names.
Much Emacs code assumes that font families named "Monospace" and "Sans
Serif" exist, and map to the default monospace and Sans Serif fonts on
a system. When the `sfnt' font driver is asked to look for a font
with one of the families in this alist, it uses its value instead. */);
Vsfnt_default_family_alist = Qnil;
DEFVAR_LISP ("sfnt-uninstructable-family-regexp",
Vsfnt_uninstructable_family_regexp,
doc: /* Regexp matching font families whose glyphs must not be instructed.
If nil, instruction code supplied by all fonts will be executed. This
variable takes effect when a font entity is opened, not after, and
therefore won't affect the scaling of realized faces until their
frames' font caches are cleared (see `clear-font-cache').
TrueType fonts incorporate instruction code executed to fit each glyph
to a pixel grid, so as to improve the visual fidelity of each glyph by
eliminating artifacts and chance effects consequent upon the direct
upscaling of glyph outline data. Instruction code is occasionally
incompatible with Emacs and must be disregarded. */);
Vsfnt_uninstructable_family_regexp = Qnil;
}
void