diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-08-27 20:39:14 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-08-27 20:39:14 -0400 |
commit | 94b7c4ae13e3b71ffc283db1989389f22bd66446 (patch) | |
tree | 43ccbd82c43dd2537cd927d9b154ddceb053c6e1 /pango/pangofc-fontmap.c | |
parent | a3517dcc6de9bae1193075b7112aa7db97b39dcc (diff) | |
download | pango-94b7c4ae13e3b71ffc283db1989389f22bd66446.tar.gz |
fc: Avoid extra copies of family names
When we create a PangoFcFont from an FcPattern,
we know that the pattern will live as long as
the font and the font description we create
at the same time. So there is no need to copy
the strings we get out of the pattern.
Diffstat (limited to 'pango/pangofc-fontmap.c')
-rw-r--r-- | pango/pangofc-fontmap.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index e21032f3..51f71cb1 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -2774,6 +2774,14 @@ pango_fc_convert_width_to_pango (int fc_stretch) PangoFontDescription * pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_size) { + return font_description_from_pattern (pattern, include_size, FALSE); +} + +PangoFontDescription * +font_description_from_pattern (FcPattern *pattern, + gboolean include_size, + gboolean shallow) +{ PangoFontDescription *desc; PangoStyle style; PangoWeight weight; @@ -2782,8 +2790,7 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz PangoGravity gravity; PangoVariant variant; gboolean all_caps; - - FcChar8 *s; + const char *s; int i; double d; FcResult res; @@ -2793,7 +2800,10 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz res = FcPatternGetString (pattern, FC_FAMILY, 0, (FcChar8 **) &s); g_assert (res == FcResultMatch); - pango_font_description_set_family (desc, (gchar *)s); + if (shallow) + pango_font_description_set_family_static (desc, s); + else + pango_font_description_set_family (desc, s); if (FcPatternGetInteger (pattern, FC_SLANT, 0, &i) == FcResultMatch) style = pango_fc_convert_slant_to_pango (i); @@ -2821,8 +2831,6 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz for (int i = 0; i < 32; i++) { - const char *s; - if (FcPatternGetString (pattern, FC_FONT_FEATURES, i, (FcChar8 **)&s) == FcResultMatch) { if (strcmp (s, "smcp=1") == 0) @@ -2907,7 +2915,12 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz if (include_size && FcPatternGetString (pattern, FC_FONT_VARIATIONS, 0, (FcChar8 **)&s) == FcResultMatch) { if (s && *s) - pango_font_description_set_variations (desc, (char *)s); + { + if (shallow) + pango_font_description_set_variations_static (desc, s); + else + pango_font_description_set_variations (desc, s); + } } return desc; |