[pango/unsupported-formats] fc: Don't return fonts with unsupported formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/unsupported-formats] fc: Don't return fonts with unsupported formats
- Date: Sun, 4 Aug 2019 00:56:52 +0000 (UTC)
commit bc9160fa29d3c59841bbd3e3f049bc5093ac89f4
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 3 17:48:50 2019 -0400
fc: Don't return fonts with unsupported formats
Make pango_fontset_foreach skip fonts that
in formats that harfbuzz doesn't support.
Some reshuffling was necessary since previously
the code was assuming that the first NULL
indicates the end of available fonts.
pango/pangofc-fontmap.c | 64 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 15 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 43ab7dbc..bddd5410 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -896,18 +896,24 @@ pango_fc_fontset_get_key (PangoFcFontset *fontset)
}
static PangoFont *
-pango_fc_fontset_load_next_font (PangoFcFontset *fontset)
+pango_fc_fontset_load_next_font (PangoFcFontset *fontset,
+ gboolean *has_more)
{
FcPattern *pattern, *font_pattern;
PangoFont *font;
gboolean prepare;
+ FcResult res;
+ const char *s;
pattern = pango_fc_patterns_get_pattern (fontset->patterns);
font_pattern = pango_fc_patterns_get_font_pattern (fontset->patterns,
fontset->patterns_i++,
&prepare);
if (G_UNLIKELY (!font_pattern))
- return NULL;
+ {
+ *has_more = FALSE;
+ return NULL;
+ }
if (prepare)
{
@@ -917,26 +923,35 @@ pango_fc_fontset_load_next_font (PangoFcFontset *fontset)
return NULL;
}
- font = pango_fc_font_map_new_font (fontset->key->fontmap,
- fontset->key,
- font_pattern);
+ 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)
+ font = NULL;
+ else
+ font = pango_fc_font_map_new_font (fontset->key->fontmap,
+ fontset->key,
+ font_pattern);
if (prepare)
FcPatternDestroy (font_pattern);
+ *has_more = TRUE;
+
return font;
}
static PangoFont *
pango_fc_fontset_get_font_at (PangoFcFontset *fontset,
- unsigned int i)
+ unsigned int i,
+ gboolean *has_more)
{
while (i >= fontset->fonts->len)
{
- PangoFont *font = pango_fc_fontset_load_next_font (fontset);
+ PangoFont *font = pango_fc_fontset_load_next_font (fontset, has_more);
g_ptr_array_add (fontset->fonts, font);
g_ptr_array_add (fontset->coverages, NULL);
- if (!font)
+ if (!*has_more)
return NULL;
}
@@ -1013,11 +1028,20 @@ pango_fc_fontset_get_font (PangoFontset *fontset,
PangoCoverage *coverage;
int result = -1;
unsigned int i;
+ gboolean has_more;
- for (i = 0;
- pango_fc_fontset_get_font_at (fcfontset, i);
- i++)
+ for (i = 0; TRUE; i++)
{
+ font = pango_fc_fontset_get_font_at (fcfontset, i, &has_more);
+
+ if (font == NULL)
+ {
+ if (has_more)
+ continue;
+ else
+ break;
+ }
+
coverage = g_ptr_array_index (fcfontset->coverages, i);
if (coverage == NULL)
@@ -1042,7 +1066,7 @@ pango_fc_fontset_get_font (PangoFontset *fontset,
if (G_UNLIKELY (result == -1))
return NULL;
- font = g_ptr_array_index(fcfontset->fonts, result);
+ font = g_ptr_array_index (fcfontset->fonts, result);
return g_object_ref (font);
}
@@ -1053,12 +1077,21 @@ pango_fc_fontset_foreach (PangoFontset *fontset,
{
PangoFcFontset *fcfontset = PANGO_FC_FONTSET (fontset);
PangoFont *font;
+ gboolean has_more;
unsigned int i;
- for (i = 0;
- (font = pango_fc_fontset_get_font_at (fcfontset, i));
- i++)
+ for (i = 0; TRUE; i++)
{
+ font = pango_fc_fontset_get_font_at (fcfontset, i, &has_more);
+
+ if (font == NULL)
+ {
+ if (has_more)
+ continue;
+ else
+ break;
+ }
+
if ((*func) (fontset, font, data))
return;
}
@@ -1360,6 +1393,7 @@ pango_fc_font_map_list_families (PangoFontMap *fontmap,
PangoFcFamily *temp_family;
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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]