summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2020-06-25 10:02:21 +0200
committerMarco Trevisan (TreviƱo) <mail@3v1n0.net>2021-05-05 16:38:25 +0200
commit8a744cd515f31daef4e9a95a751b11d777e6774e (patch)
treefe937fe6ca1767459fc4c63439f79d61b94b2ca2
parentac07f75e9c1c560f0e8243426ef4f12a2ff1a7e8 (diff)
downloadpango-8a744cd515f31daef4e9a95a751b11d777e6774e.tar.gz
fcfontmap: Always reject unsupported font formats
Fixes https://gitlab.gnome.org/GNOME/pango/-/issues/484 and https://gitlab.gnome.org/GNOME/pango/-/issues/457 (cherry-picked from commit fe1ee773)
-rw-r--r--pango/pangofc-fontmap.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 535a6f0e..ade3cffc 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -808,8 +808,15 @@ pango_fc_patterns_get_pattern (PangoFcPatterns *pats)
}
static gboolean
-pango_fc_is_supported_font_format (const char *fontformat)
+pango_fc_is_supported_font_format (FcPattern* pattern)
{
+ FcResult res;
+ const char *fontformat;
+
+ res = FcPatternGetString (pattern, FC_FONTFORMAT, 0, (FcChar8 **)(void*)&fontformat);
+ if (res != FcResultMatch)
+ return FALSE;
+
/* 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
@@ -831,11 +838,7 @@ filter_fontset_by_format (FcFontSet *fontset)
for (i = 0; i < fontset->nfont; i++)
{
- FcResult res;
- const char *s;
-
- res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, (FcChar8 **)(void*)&s);
- if (res == FcResultMatch && pango_fc_is_supported_font_format (s))
+ if (pango_fc_is_supported_font_format (fontset->fonts[i]))
FcFontSetAdd (result, FcPatternDuplicate (fontset->fonts[i]));
}
@@ -851,34 +854,32 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep
if (!pats->match && !pats->fontset)
pats->match = FcFontMatch (pats->fontmap->priv->config, pats->pattern, &result);
- if (pats->match)
+ if (pats->match && pango_fc_is_supported_font_format (pats->match))
{
*prepare = FALSE;
return pats->match;
}
}
- else
+
+ if (!pats->fontset)
{
- if (!pats->fontset)
- {
- FcResult result;
- FcFontSet *fontset;
- FcFontSet *filtered;
+ FcResult result;
+ FcFontSet *fontset;
+ FcFontSet *filtered;
- fontset = FcFontSort (pats->fontmap->priv->config, pats->pattern, FcFalse, NULL, &result);
- filtered = filter_fontset_by_format (fontset);
- FcFontSetDestroy (fontset);
+ 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);
+ pats->fontset = FcFontSetSort (pats->fontmap->priv->config, &filtered, 1, pats->pattern, FcTrue, NULL, &result);
- FcFontSetDestroy (filtered);
+ FcFontSetDestroy (filtered);
- if (pats->match)
- {
- FcPatternDestroy (pats->match);
- pats->match = NULL;
- }
- }
+ if (pats->match)
+ {
+ FcPatternDestroy (pats->match);
+ pats->match = NULL;
+ }
}
*prepare = TRUE;
@@ -1404,8 +1405,7 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap,
int variable;
PangoFcFamily *temp_family;
- res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, (FcChar8 **)(void*)&s);
- if (res != FcResultMatch || !pango_fc_is_supported_font_format (s))
+ if (!pango_fc_is_supported_font_format (fontset->fonts[i]))
continue;
res = FcPatternGetString (fontset->fonts[i], FC_FAMILY, 0, (FcChar8 **)(void*)&s);