From 06b923da6ee5973b7a5828b47e9a2ec8658b9265 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 6 Aug 2019 18:04:15 -0700 Subject: Better filtering by font format As Behdad pointed out, we were mixing up font format filtering and coverage trimming. --- pango/pangofc-fontmap.c | 62 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'pango') diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index d0a01115..68ab5e45 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -807,6 +807,42 @@ pango_fc_patterns_get_pattern (PangoFcPatterns *pats) return pats->pattern; } +static gboolean +pango_fc_is_supported_font_format (const char *fontformat) +{ + /* harfbuzz supports only SFNT fonts. */ + /* FIXME: "CFF" is used for both CFF in OpenType and bare CFF files, but + * HarfBuzz does not support the later and FontConfig does not seem + * to have a way to tell them apart. + */ + if (g_ascii_strcasecmp (fontformat, "TrueType") == 0 || + g_ascii_strcasecmp (fontformat, "CFF") == 0) + return TRUE; + return FALSE; +} + +static FcFontSet * +filter_fontset_by_format (FcFontSet *fontset) +{ + FcFontSet *result; + int i; + + result = FcFontSetCreate (); + + for (i = 0; i < fontset->nfont; i++) + { + FcResult res; + const char *s; + + res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, (FcChar8 **)(void*)&s); + g_assert (res == FcResultMatch); + if (pango_fc_is_supported_font_format (s)) + FcFontSetAdd (result, FcPatternDuplicate (fontset->fonts[i])); + } + + return result; +} + static FcPattern * pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prepare) { @@ -827,7 +863,17 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep if (!pats->fontset) { FcResult result; - pats->fontset = FcFontSort (pats->fontmap->priv->config, pats->pattern, FcTrue, NULL, &result); + FcFontSet *fontset; + FcFontSet *filtered; + + fontset = FcFontSort (pats->fontmap->priv->config, pats->pattern, FcFalse, NULL, &result); + filtered = filter_fontset_by_format (fontset); + FcFontSetDestroy (fontset); + + pats->fontset = FcFontSetSort (pats->fontmap->priv->config, &filtered, 1, pats->pattern, FcTrue, NULL, &result); + + FcFontSetDestroy (filtered); + if (pats->match) { FcPatternDestroy (pats->match); @@ -895,20 +941,6 @@ pango_fc_fontset_get_key (PangoFcFontset *fontset) return fontset->key; } -static gboolean -pango_fc_is_supported_font_format (const char *fontformat) -{ - /* harfbuzz supports only SFNT fonts. */ - /* FIXME: "CFF" is used for both CFF in OpenType and bare CFF files, but - * HarfBuzz does not support the later and FontConfig does not seem - * to have a way to tell them apart. - */ - if (g_ascii_strcasecmp (fontformat, "TrueType") == 0 || - g_ascii_strcasecmp (fontformat, "CFF") == 0) - return TRUE; - return FALSE; -} - static PangoFont * pango_fc_fontset_load_next_font (PangoFcFontset *fontset, gboolean *has_more) -- cgit v1.2.1