From 38e96bee1f902dc3d2ca55dd9c4c920c2b75bf2a Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 11 Sep 2023 19:45:58 +0800 Subject: [PATCH] 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) : New option. --- etc/PROBLEMS | 12 ++++++++++++ src/sfntfont.c | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/etc/PROBLEMS b/etc/PROBLEMS index faeee2a3035..11659c66e68 100644 --- a/etc/PROBLEMS +++ b/etc/PROBLEMS @@ -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 diff --git a/src/sfntfont.c b/src/sfntfont.c index 64dbffad03f..12fecb32df5 100644 --- a/src/sfntfont.c +++ b/src/sfntfont.c @@ -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 -- 2.39.5