[pango/more-space-tweaks: 1/2] shape: More tweaks to space handling




commit cc50534f6a360ea48ff4edeca0d8a9d84062a9ba
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 17 18:06:31 2021 -0500

    shape: More tweaks to space handling
    
    It is a difficult dance between HarfBuzz and pango
    which glyphs we let hb synthesize, and which ones
    we need to fake ourselves.
    
    HarfBuzz knows how to create other spaces from 0x20,
    so if the font is lacking spaces, we want to tell
    HarfBuzz that we don't have that glyph *except* for
    0x20 where we need to fake one, and provide HarfBuzz
    with a suitable width.
    
    Update affected tests.

 pango/shape.c                 | 20 ++++++++++++++++----
 tests/layouts/no-space.layout | 22 +++++++++++-----------
 tests/layouts/valid-14.layout | 20 +++++++++++++-------
 3 files changed, 40 insertions(+), 22 deletions(-)
---
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..0d4ef481 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" : 44032,
+    "height" : 44032,
     "log-attrs" : [
       {
         "char-break" : true,
@@ -104,14 +104,14 @@
             "end-x-offset" : 0,
             "glyphs" : [
               {
-                "glyph" : 0,
-                "width" : 44032,
+                "glyph" : 268435488,
+                "width" : 0,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               },
               {
-                "glyph" : 0,
-                "width" : 44032,
+                "glyph" : 268435488,
+                "width" : 0,
                 "is-cluster-start" : true,
                 "log-cluster" : 1
               },
@@ -122,14 +122,14 @@
                 "log-cluster" : 2
               },
               {
-                "glyph" : 0,
-                "width" : 44032,
+                "glyph" : 268435488,
+                "width" : 0,
                 "is-cluster-start" : true,
                 "log-cluster" : 5
               },
               {
-                "glyph" : 0,
-                "width" : 44032,
+                "glyph" : 268435488,
+                "width" : 0,
                 "is-cluster-start" : true,
                 "log-cluster" : 6
               }
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index 9bfd7723..10cef38b 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" : [
@@ -189,8 +189,8 @@
         "runs" : [
           {
             "offset" : 0,
-            "length" : 6,
-            "text" : "你好",
+            "length" : 3,
+            "text" : "你",
             "bidi-level" : 0,
             "gravity" : "south",
             "language" : "en-us",
@@ -241,9 +241,9 @@
             ]
           },
           {
-            "offset" : 6,
-            "length" : 1,
-            "text" : " ",
+            "offset" : 3,
+            "length" : 4,
+            "text" : "好 ",
             "bidi-level" : 0,
             "gravity" : "south",
             "language" : "xx",
@@ -266,10 +266,16 @@
             "end-x-offset" : 0,
             "glyphs" : [
               {
-                "glyph" : 0,
+                "glyph" : 1,
                 "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]