diff options
-rw-r--r-- | pango/pangocairo-font.c | 24 | ||||
-rw-r--r-- | tests/layouts/no-space.layout | 12 | ||||
-rw-r--r-- | 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 } ] }, |