summaryrefslogtreecommitdiff
path: root/pango/pangocairo-font.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-17 18:07:58 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-12-17 19:56:42 -0500
commite4323aed09eb62b5be6a80167592cbe34da4b52f (patch)
treee184e40e75c7623e01016ece6c5736c6edb47d7f /pango/pangocairo-font.c
parentcc50534f6a360ea48ff4edeca0d8a9d84062a9ba (diff)
downloadpango-more-space-tweaks.tar.gz
cairo: Work harder to measure spacemore-space-tweaks
When coming up with a width for a missing space, we were just measuring the hex digits. But in subsetted fonts, such as the ones we use for ci, hex digits might well be missing. Take that into account and still provide some nonzero width for space. Update affected tests.
Diffstat (limited to 'pango/pangocairo-font.c')
-rw-r--r--pango/pangocairo-font.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index c2bcc51b..02a976d8 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -676,27 +676,45 @@ get_space_extents (PangoCairoFontPrivate *cf_priv,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
+ cairo_scaled_font_t *scaled_font;
const char hexdigits[] = "0123456789ABCDEF";
char c[2] = {0, 0};
int i;
double hex_width;
int width;
+ int n_chars;
/* 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.
*/
+ scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv);
hex_width = 0;
+ n_chars = 0;
for (i = 0 ; i < 16 ; i++)
{
cairo_text_extents_t extents;
c[0] = hexdigits[i];
- cairo_scaled_font_text_extents (_pango_cairo_font_private_get_scaled_font (cf_priv), c, &extents);
- hex_width += extents.width;
+ cairo_scaled_font_text_extents (scaled_font, c, &extents);
+ if (extents.width > 0)
+ {
+ hex_width += extents.width;
+ n_chars++;
+ }
+ }
+
+ if (n_chars == 0)
+ {
+ cairo_font_extents_t extents;
+
+ cairo_scaled_font_extents (scaled_font, &extents);
+ hex_width += extents.max_x_advance;
+ n_chars++;
}
- width = pango_units_from_double (hex_width / 16);
+
+ width = pango_units_from_double (hex_width / n_chars);
if (ink_rect)
{