summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-08-06 18:04:15 -0700
committerMatthias Clasen <mclasen@redhat.com>2019-08-06 18:04:15 -0700
commit06b923da6ee5973b7a5828b47e9a2ec8658b9265 (patch)
tree3a3dde4f6c5809d1a9875e5f11e98980a11dd459
parent5af6340eef9833f0f8e878939e88d98b11813578 (diff)
downloadpango-06b923da6ee5973b7a5828b47e9a2ec8658b9265.tar.gz
Better filtering by font format
As Behdad pointed out, we were mixing up font format filtering and coverage trimming.
-rw-r--r--pango/pangofc-fontmap.c62
1 files changed, 47 insertions, 15 deletions
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)