[pango/ignore-more-unsupported-fonts] fc: Ignore more unsupported font formats



commit d7b706d8f2a6d15b34dabbd38ab8389de5e71ff8
Author: Khaled Hosny <khaledhosny eglug org>
Date:   Sun Aug 4 12:26:07 2019 +0200

    fc: Ignore more unsupported font formats
    
    FontConfig uses FreeType’s FT_Get_X11_Font_Format() to get the font
    format. From the list of font formats it supports, only “TrueType” and
    “CFF” are supported by HarfBuzz. We now check explicitly for supported
    formats and reject anything else:
    
https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/include/freetype/internal/services/svfntfmt.h#n36
    
    FreeType, however, seems to use “CFF” for both OpenType fonts with CFF
    table (.otf) and bare CFF fonts (.cff), but the later are not supported
    by HarfBuzz although they rather rare (outside of PDF files, which
    shouldn’t be rendered with Pango), so it should be OK.

 pango/pangofc-fontmap.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index bddd5410..d0a01115 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -895,6 +895,20 @@ 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)
@@ -925,8 +939,7 @@ pango_fc_fontset_load_next_font (PangoFcFontset *fontset,
 
   res = FcPatternGetString (font_pattern, FC_FONTFORMAT, 0, (FcChar8 **)(void*)&s);
   g_assert (res == FcResultMatch);
-  /* harfbuzz does not support these */
-  if (strcmp (s, "Type 1") == 0 || strcmp (s, "PCF") == 0)
+  if (!pango_fc_is_supported_font_format (s))
     font = NULL;
   else
     font = pango_fc_font_map_new_font (fontset->key->fontmap,
@@ -1394,8 +1407,8 @@ pango_fc_font_map_list_families (PangoFontMap      *fontmap,
 
          res = FcPatternGetString (fontset->fonts[i], FC_FONTFORMAT, 0, (FcChar8 **)(void*)&s);
          g_assert (res == FcResultMatch);
-          if (strcmp (s, "Type 1") == 0 || strcmp (s, "PCF") == 0)
-            continue; /* harfbuzz does not support these */
+          if (!pango_fc_is_supported_font_format (s))
+            continue;
 
          res = FcPatternGetString (fontset->fonts[i], FC_FAMILY, 0, (FcChar8 **)(void*)&s);
          g_assert (res == FcResultMatch);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]