summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-18 01:07:42 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-12-18 01:07:42 +0000
commit4eb4b83af55ed3a2b4f957d776885b5f543a435e (patch)
treee184e40e75c7623e01016ece6c5736c6edb47d7f
parent6390bd6230b030218d3ea70ef39ea8f2938840fa (diff)
parente4323aed09eb62b5be6a80167592cbe34da4b52f (diff)
downloadpango-4eb4b83af55ed3a2b4f957d776885b5f543a435e.tar.gz
Merge branch 'more-space-tweaks' into 'main'
shape: More tweaks to space handling See merge request GNOME/pango!557
-rw-r--r--pango/pangocairo-font.c24
-rw-r--r--pango/shape.c20
-rw-r--r--tests/layouts/no-space.layout22
-rw-r--r--tests/layouts/valid-14.layout4
4 files changed, 50 insertions, 20 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/pango/shape.c b/pango/shape.c
index 90334cc1..30bceb80 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -137,12 +137,24 @@ pango_hb_font_get_nominal_glyph (hb_font_t *font,
if (hb_font_get_nominal_glyph (context->parent, unicode, glyph))
return TRUE;
- /* HarfBuzz knows how to synthesize spaces, so never replace them
- * with unknown glyphs, but we do need to tell HarfBuzz that the
- * font does not have a glyph.
+ /* HarfBuzz knows how to synthesize other spaces from 0x20, so never
+ * replace them with unknown glyphs, just tell HarfBuzz that we don't
+ * have a glyph.
+ *
+ * For 0x20, on the other hand, we need to pretend that we have a glyph
+ * and rely on our glyph extents code to provide a reasonable width for
+ * PANGO_GET_UNKNOWN_WIDTH (0x20).
*/
if (g_unichar_type (unicode) == G_UNICODE_SPACE_SEPARATOR)
- return FALSE;
+ {
+ if (unicode == 0x20)
+ {
+ *glyph = PANGO_GET_UNKNOWN_GLYPH (0x20);
+ return TRUE;
+ }
+
+ return FALSE;
+ }
*glyph = PANGO_GET_UNKNOWN_GLYPH (unicode);
diff --git a/tests/layouts/no-space.layout b/tests/layouts/no-space.layout
index 07f6aa06..12f878f6 100644
--- a/tests/layouts/no-space.layout
+++ b/tests/layouts/no-space.layout
@@ -20,9 +20,9 @@
"output" : {
"is-wrapped" : false,
"is-ellipsized" : false,
- "unknown-glyphs" : 0,
- "width" : 220160,
- "height" : 220160,
+ "unknown-glyphs" : 4,
+ "width" : 261120,
+ "height" : 261120,
"log-attrs" : [
{
"char-break" : true,
@@ -104,14 +104,14 @@
"end-x-offset" : 0,
"glyphs" : [
{
- "glyph" : 0,
- "width" : 44032,
+ "glyph" : 268435488,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 0
},
{
- "glyph" : 0,
- "width" : 44032,
+ "glyph" : 268435488,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 1
},
@@ -122,14 +122,14 @@
"log-cluster" : 2
},
{
- "glyph" : 0,
- "width" : 44032,
+ "glyph" : 268435488,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 5
},
{
- "glyph" : 0,
- "width" : 44032,
+ "glyph" : 268435488,
+ "width" : 54272,
"is-cluster-start" : true,
"log-cluster" : 6
}
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index 9bfd7723..69d061b0 100644
--- a/tests/layouts/valid-14.layout
+++ b/tests/layouts/valid-14.layout
@@ -23,7 +23,7 @@
"output" : {
"is-wrapped" : false,
"is-ellipsized" : true,
- "unknown-glyphs" : 0,
+ "unknown-glyphs" : 1,
"width" : 161792,
"height" : 161792,
"log-attrs" : [
@@ -266,7 +266,7 @@
"end-x-offset" : 0,
"glyphs" : [
{
- "glyph" : 0,
+ "glyph" : 268435488,
"width" : 15360,
"is-cluster-start" : true,
"log-cluster" : 0