Skip to content

Commit

Permalink
Rewrite pango_fc_is_supported_font_format
Browse files Browse the repository at this point in the history
Since we now require fontconig 2.15, we can use FC_FONT_WRAPPER,
which is a much better fit. At the same time, explicitly reject
patterns without FC_FILE, since our caching is based on the
filename.
  • Loading branch information
Matthias Clasen committed Nov 27, 2024
1 parent 86c852f commit fe7cc1d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions pango/pangofc-fontmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,29 +1067,22 @@ static gboolean
pango_fc_is_supported_font_format (FcPattern* pattern)
{
FcResult res;
const char *fontformat;
const char *file;
const char *fontwrapper;

/* Harfbuzz loads woff fonts, but we don't get any glyphs */
/* Patterns without FC_FILE are problematic, since our caching is based
* on filenames.
*/
res = FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **)(void*)&file);
if (res == FcResultMatch &&
(g_str_has_suffix (file, ".woff") ||
g_str_has_suffix (file, ".woff2")))
if (res != FcResultMatch)
return FALSE;

res = FcPatternGetString (pattern, FC_FONTFORMAT, 0, (FcChar8 **)(void*)&fontformat);
/* Harfbuzz supports only SFNT fonts. */
res = FcPatternGetString (pattern, FC_FONT_WRAPPER, 0, (FcChar8 **)(void*)&fontwrapper);
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
* 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;
return strcmp (fontwrapper, "SFNT") == 0;
}

static FcFontSet *
Expand Down

0 comments on commit fe7cc1d

Please sign in to comment.