diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-07-06 16:45:49 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-07-07 11:26:53 -0400 |
commit | 98f8809ef2ba4d671536af405dad4a1477950170 (patch) | |
tree | 7e22d13435811cff0e9e2c9034cf448bcbf6acf7 /pango/pangocairo-font.c | |
parent | e2e2e7f10ff352ccdc9d4ced4e71a5d73f4177a8 (diff) | |
download | pango-98f8809ef2ba4d671536af405dad4a1477950170.tar.gz |
cairo: Give missing spaces a better width
We are not rendering hex boxes for missing spaces,
so we don't need to give them the hex box width.
Diffstat (limited to 'pango/pangocairo-font.c')
-rw-r--r-- | pango/pangocairo-font.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index df77f43b..8b1f12d3 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -672,6 +672,45 @@ _pango_cairo_font_private_is_metrics_hinted (PangoCairoFontPrivate *cf_priv) } static void +get_space_extents (PangoCairoFontPrivate *cf_priv, + PangoRectangle *ink_rect, + PangoRectangle *logical_rect) +{ + const char hexdigits[] = "0123456789ABCDEF"; + char c[2] = {0, 0}; + int i; + double hex_width; + int width; + + /* we don't render missing spaces as hex boxes, + * so come up with some width to use. For lack + * of anything better, use average hex digit width. + */ + + hex_width = 0; + for (i = 0 ; i < 16 ; i++) + { + cairo_text_extents_t extents; + + c[0] = hexdigits[i]; + cairo_scaled_font_text_extents (cf_priv->scaled_font, c, &extents); + hex_width += extents.width; + } + width = pango_units_from_double (hex_width / 16); + + if (ink_rect) + { + ink_rect->x = ink_rect->y = ink_rect->height = 0; + ink_rect->width = width; + } + if (logical_rect) + { + *logical_rect = cf_priv->font_extents; + logical_rect->width = width; + } +} + +static void _pango_cairo_font_private_get_glyph_extents_missing (PangoCairoFontPrivate *cf_priv, PangoGlyph glyph, PangoRectangle *ink_rect, @@ -681,6 +720,12 @@ _pango_cairo_font_private_get_glyph_extents_missing (PangoCairoFontPrivate *cf_p gunichar ch; gint rows, cols; + if (glyph == (0x20 | PANGO_GLYPH_UNKNOWN_FLAG)) + { + get_space_extents (cf_priv, ink_rect, logical_rect); + return; + } + hbi = _pango_cairo_font_private_get_hex_box_info (cf_priv); if (!hbi) { @@ -768,6 +813,7 @@ _pango_cairo_font_private_glyph_extents_cache_init (PangoCairoFontPrivate *cf_pr return TRUE; } + /* Fills in the glyph extents cache entry */ static void |