diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-08-22 11:13:35 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-02-22 08:34:16 -0500 |
commit | 4875b69b25bd389501fa8726c9723be85c56c3de (patch) | |
tree | be7f3bc2294a454726535a542a911012b570ae89 | |
parent | ab16846f5440fa29069fc38680b2f04f6e1d3ecd (diff) | |
download | pango-4875b69b25bd389501fa8726c9723be85c56c3de.tar.gz |
Do coverage trimming incrementally
Some tradeoffs here.
FcFontSetSort returns faster (5.4ms vs 6.75ms),
but we have much bigger fontset (~ 4k fonts vs ~200),
and we have to keep extra data around (the charset, and
the skip table).
-rw-r--r-- | pango/pangofc-fontmap.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index aa90345e..d859c493 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -766,6 +766,12 @@ struct _PangoFcPatterns { FcPattern *pattern; FcPattern *match; FcFontSet *fontset; + + char *skip; /* 0: undetermined, 1: skip: 2: include */ + + FcCharSet *cs; /* merged charset of the coverage of the + * non-undetermined fonts. + */ }; static FcFontSet * @@ -860,7 +866,7 @@ sort_in_thread (GTask *task, fontset = FcFontSetSort (td->config, &td->fonts, 1, td->pattern, - FcTrue, + FcFalse, NULL, &result); @@ -948,6 +954,9 @@ pango_fc_patterns_unref (PangoFcPatterns *pats) if (pats->fontset) FcFontSetDestroy (pats->fontset); + g_clear_pointer (&pats->skip, g_free); + g_clear_pointer (&pats->cs, FcCharSetDestroy); + g_cond_clear (&pats->cond); g_mutex_clear (&pats->mutex); @@ -1066,10 +1075,40 @@ pango_fc_patterns_get_font_pattern (PangoFcPatterns *pats, int i, gboolean *prep if (fontset) { - if (i < fontset->nfont) + int f, k; + + /* Find the i'th fontset skipping the ones that are + * not adding coverage. + */ + + if (!pats->skip) + { + pats->skip = g_new0 (char, fontset->nfont); + pats->cs = FcCharSetCreate (); + } + + for (f = 0, k = 0; f < fontset->nfont && k < i; f++) + { + if (pats->skip[f] == 0) /* calculate whether to skip */ + { + FcCharSet *fcs; + FcBool added = FcFalse; + + FcPatternGetCharSet (fontset->fonts[f], "charset", 0, &fcs); + + FcCharSetMerge (pats->cs, fcs, &added); + + pats->skip[f] = added ? 2 : 1; + } + + if (pats->skip[f] == 2) /* don't skip */ + k++; + } + + if (f < fontset->nfont) { *prepare = TRUE; - return fontset->fonts[i]; + return fontset->fonts[f]; } } |