[pango/more-space-tweaks: 2/2] cairo: Work harder to measure space
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/more-space-tweaks: 2/2] cairo: Work harder to measure space
- Date: Sat, 18 Dec 2021 00:57:05 +0000 (UTC)
commit e4323aed09eb62b5be6a80167592cbe34da4b52f
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 17 18:07:58 2021 -0500
cairo: Work harder to measure space
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.
pango/pangocairo-font.c | 24 +++++++++++++++++++++---
tests/layouts/no-space.layout | 12 ++++++------
tests/layouts/valid-14.layout | 18 ++++++------------
3 files changed, 33 insertions(+), 21 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)
{
diff --git a/tests/layouts/no-space.layout b/tests/layouts/no-space.layout
index 0d4ef481..12f878f6 100644
--- a/tests/layouts/no-space.layout
+++ b/tests/layouts/no-space.layout
@@ -21,8 +21,8 @@
"is-wrapped" : false,
"is-ellipsized" : false,
"unknown-glyphs" : 4,
- "width" : 44032,
- "height" : 44032,
+ "width" : 261120,
+ "height" : 261120,
"log-attrs" : [
{
"char-break" : true,
@@ -105,13 +105,13 @@
"glyphs" : [
{
"glyph" : 268435488,
- "width" : 0,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 0
},
{
"glyph" : 268435488,
- "width" : 0,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 1
},
@@ -123,13 +123,13 @@
},
{
"glyph" : 268435488,
- "width" : 0,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 5
},
{
"glyph" : 268435488,
- "width" : 0,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 6
}
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index 10cef38b..69d061b0 100644
--- a/tests/layouts/valid-14.layout
+++ b/tests/layouts/valid-14.layout
@@ -189,8 +189,8 @@
"runs" : [
{
"offset" : 0,
- "length" : 3,
- "text" : "你",
+ "length" : 6,
+ "text" : "你好",
"bidi-level" : 0,
"gravity" : "south",
"language" : "en-us",
@@ -241,9 +241,9 @@
]
},
{
- "offset" : 3,
- "length" : 4,
- "text" : "好 ",
+ "offset" : 6,
+ "length" : 1,
+ "text" : " ",
"bidi-level" : 0,
"gravity" : "south",
"language" : "xx",
@@ -266,16 +266,10 @@
"end-x-offset" : 0,
"glyphs" : [
{
- "glyph" : 1,
+ "glyph" : 268435488,
"width" : 15360,
"is-cluster-start" : true,
"log-cluster" : 0
- },
- {
- "glyph" : 268435488,
- "width" : 0,
- "is-cluster-start" : true,
- "log-cluster" : 3
}
]
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]