1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-07 04:10:27 -08:00

Whitelist some incorrectly labeled "color" fonts under Xft

* etc/PROBLEMS: Document problem with fonts incorrectly labeled
as color fonts under Xft.

* src/ftfont.c (xft_color_font_whitelisted_p): New function.
(ftfont_spec_pattern, ftfont_list): Respect whitelisting of
"color" fonts under Xft.
* src/xftfont.c (syms_of_xftfont): New variable
`xft-color-font-whitelist'.
This commit is contained in:
Po Lu 2022-05-19 20:10:19 +08:00
parent 0a4d9f26ee
commit c154309976
3 changed files with 54 additions and 1 deletions

View file

@ -805,6 +805,22 @@ to take advantage of.
* Runtime problems related to font handling
** Some fonts are detected but not usable under Xft.
Some fonts might not be usable under Emacs even though they show up in
the font family list when Emacs is built with Xft. This is because
Emacs prevents fonts that have color glyphs (such as color Emoji) from
being used, since they typically cause Xft crashes.
On some GNU/Linux systems, fonts (such as Source Code Pro) that do not
have color glyphs are reported as color fonts, causing them to be
unavailable when using Xft. This is known to happen under Fedora
GNU/Linux 36 or later, and possibly other distributions as well.
If you encounter a such a font, you can enable it while ignoring other
fonts that actually have color glyphs by adding its family name to the
list `xft-color-font-whitelist'.
** Characters are displayed as empty boxes or with wrong font under X.
*** This may be due to your local fontconfig customization.

View file

@ -645,8 +645,29 @@ ftfont_get_open_type_spec (Lisp_Object otf_spec)
return spec;
}
#if defined HAVE_XFT && defined FC_COLOR
static bool
xft_color_font_whitelisted_p (const char *family)
{
Lisp_Object tem, name;
tem = Vxft_color_font_whitelist;
FOR_EACH_TAIL_SAFE (tem)
{
name = XCAR (tem);
if (STRINGP (name) && !strcmp (family, SSDATA (name)))
return true;
}
return false;
}
#endif
static FcPattern *
ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **otspec, const char **langname)
ftfont_spec_pattern (Lisp_Object spec, char *otlayout,
struct OpenTypeSpec **otspec, const char **langname)
{
Lisp_Object tmp, extra;
FcPattern *pattern = NULL;
@ -785,6 +806,8 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots
/* We really don't like color fonts, they cause Xft crashes. See
Bug#30874. */
if (xft_ignore_color_fonts
&& (NILP (AREF (spec, FONT_FAMILY_INDEX))
|| NILP (Vxft_color_font_whitelist))
&& ! FcPatternAddBool (pattern, FC_COLOR, FcFalse))
goto err;
#endif
@ -930,7 +953,12 @@ ftfont_list (struct frame *f, Lisp_Object spec)
returns them even when it shouldn't really do so, so we
need to manually skip them here (Bug#37786). */
FcBool b;
FcChar8 *str;
if (xft_ignore_color_fonts
&& (FcPatternGetString (fontset->fonts[i], FC_FAMILY,
0, &str) != FcResultMatch
|| !xft_color_font_whitelisted_p ((char *) str))
&& FcPatternGetBool (fontset->fonts[i], FC_COLOR, 0, &b)
== FcResultMatch && b != FcFalse)
continue;

View file

@ -797,6 +797,15 @@ syms_of_xftfont (void)
This is needed with some fonts to correct vertical overlap of glyphs. */);
xft_font_ascent_descent_override = 0;
DEFVAR_LISP ("xft-color-font-whitelist", Vxft_color_font_whitelist,
doc: /* List of "color" font families that don't actually have color glyphs.
Some fonts (such as Source Code Pro) are reported as color fonts, but
do not actually have glyphs with colors that can cause Xft crashes.
The font families in this list will not be ignored when
`xft-ignore-color-fonts' is non-nil. */);
Vxft_color_font_whitelist = list1 (build_pure_c_string ("Source Code Pro"));
pdumper_do_now_and_after_load (syms_of_xftfont_for_pdumper);
}