diff options
author | Matthias Clasen <mclasen@redhat.com> | 2017-09-05 07:37:31 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-01-03 12:41:46 +0000 |
commit | efa66e7b634050ef395418b544b012a4a5183973 (patch) | |
tree | 4823301a56e843fb864b7e25b8aef5f530e51f2d /pango/pangofc-shape.c | |
parent | 95c2aaaa9a1f0167e832a3d31700ae51e519fff4 (diff) | |
download | pango-efa66e7b634050ef395418b544b012a4a5183973.tar.gz |
Add initial support for OpenType font variations
This commit lets PangoFontDescription carry font variation
information as a string. Only pangocairo has been updated
to make use of this information. We pass it to harfbuzz
for shaping, and we pass it to cairo when creating scaled
fonts.
Diffstat (limited to 'pango/pangofc-shape.c')
-rw-r--r-- | pango/pangofc-shape.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c index 57f70000..a59ca67c 100644 --- a/pango/pangofc-shape.c +++ b/pango/pangofc-shape.c @@ -278,6 +278,38 @@ pango_fc_get_hb_font_funcs (void) return funcs; } +static void +parse_variations (const char *variations, + hb_variation_t **hb_variations, + guint *n_variations) +{ + guint n; + hb_variation_t *var; + int i; + const char *p; + + n = 1; + for (i = 0; variations[i]; i++) + { + if (variations[i] == ',') + n++; + } + + var = g_new (hb_variation_t, n); + + p = variations; + n = 0; + while (p && *p) + { + char *end = strchr (p, ','); + if (hb_variation_from_string (p, end ? end - p: -1, &var[n])) + n++; + p = end ? end + 1 : NULL; + } + + *hb_variations = var; + *n_variations = n; +} void _pango_fc_shape (PangoFont *font, @@ -306,6 +338,7 @@ _pango_fc_shape (PangoFont *font, unsigned int num_features = 0; double x_scale_inv, y_scale_inv; PangoGlyphInfo *infos; + const char *variations; g_return_if_fail (font != NULL); g_return_if_fail (analysis != NULL); @@ -347,6 +380,18 @@ _pango_fc_shape (PangoFont *font, fc_font->is_hinted ? ft_face->size->metrics.x_ppem : 0, fc_font->is_hinted ? ft_face->size->metrics.y_ppem : 0); + variations = pango_fc_font_key_get_variations (key); + if (variations) + { + guint n_variations; + hb_variation_t *hb_variations; + + parse_variations (variations, &hb_variations, &n_variations); + hb_font_set_variations (hb_font, hb_variations, n_variations); + + g_free (hb_variations); + } + hb_buffer = acquire_buffer (&free_buffer); hb_direction = PANGO_GRAVITY_IS_VERTICAL (analysis->gravity) ? HB_DIRECTION_TTB : HB_DIRECTION_LTR; |