[pango/better-space-size] Use a better size for missing space




commit 08fe3ba501262d772e2ce63c8cc51a6ac33e03a1
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 21 07:51:41 2021 -0500

    Use a better size for missing space
    
    Follow the Microsoft Typography recommendations from
    https://docs.microsoft.com/en-us/typography/develop/character-design-standards/whitespace
    and use half of an em for missing space.
    
    Update affected tests.
    
    Fixes: #647

 pango/pangocairo-font.c       | 43 ++++---------------------------------------
 tests/layouts/no-space.layout | 10 +++++-----
 tests/layouts/valid-14.layout |  4 ++--
 tests/layouts/valid-20.layout |  4 ++--
 tests/layouts/vertical.layout | 28 ++++++++++++++--------------
 5 files changed, 27 insertions(+), 62 deletions(-)
---
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 02a976d8..5eb385d9 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -671,50 +671,15 @@ _pango_cairo_font_private_is_metrics_hinted (PangoCairoFontPrivate *cf_priv)
   return cf_priv->is_hinted;
 }
 
+
 static void
 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 (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++;
-    }
+  /* See https://docs.microsoft.com/en-us/typography/develop/character-design-standards/whitespace */
 
-  width = pango_units_from_double (hex_width / n_chars);
+  int width = pango_font_get_absolute_size (PANGO_FONT (cf_priv->cfont)) / 2;
 
   if (ink_rect)
     {
@@ -934,7 +899,7 @@ _pango_cairo_font_private_get_glyph_extents (PangoCairoFontPrivate *cf_priv,
     }
   else if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
     {
-      _pango_cairo_font_private_get_glyph_extents_missing(cf_priv, glyph, ink_rect, logical_rect);
+      _pango_cairo_font_private_get_glyph_extents_missing (cf_priv, glyph, ink_rect, logical_rect);
       return;
     }
 
diff --git a/tests/layouts/no-space.layout b/tests/layouts/no-space.layout
index 7b62c2e1..646450c1 100644
--- a/tests/layouts/no-space.layout
+++ b/tests/layouts/no-space.layout
@@ -21,7 +21,7 @@
     "is-wrapped" : false,
     "is-ellipsized" : false,
     "unknown-glyphs" : 4,
-    "width" : 261120,
+    "width" : 130048,
     "height" : 45056,
     "log-attrs" : [
       {
@@ -105,13 +105,13 @@
             "glyphs" : [
               {
                 "glyph" : 268435488,
-                "width" : 54272,
+                "width" : 21504,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               },
               {
                 "glyph" : 268435488,
-                "width" : 54272,
+                "width" : 21504,
                 "is-cluster-start" : true,
                 "log-cluster" : 1
               },
@@ -123,13 +123,13 @@
               },
               {
                 "glyph" : 268435488,
-                "width" : 54272,
+                "width" : 21504,
                 "is-cluster-start" : true,
                 "log-cluster" : 5
               },
               {
                 "glyph" : 268435488,
-                "width" : 54272,
+                "width" : 21504,
                 "is-cluster-start" : true,
                 "log-cluster" : 6
               }
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index 593e538e..07c80f17 100644
--- a/tests/layouts/valid-14.layout
+++ b/tests/layouts/valid-14.layout
@@ -235,7 +235,7 @@
               },
               {
                 "glyph" : 1058,
-                "width" : 6144,
+                "width" : 14336,
                 "log-cluster" : 0
               }
             ]
@@ -267,7 +267,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435488,
-                "width" : 15360,
+                "width" : 7168,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
diff --git a/tests/layouts/valid-20.layout b/tests/layouts/valid-20.layout
index 93b8a1b1..db692b73 100644
--- a/tests/layouts/valid-20.layout
+++ b/tests/layouts/valid-20.layout
@@ -140,7 +140,7 @@
                 "glyph" : 244,
                 "width" : 15360,
                 "x-offset" : 14764,
-                "y-offset" : 3844,
+                "y-offset" : 3845,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               },
@@ -156,7 +156,7 @@
                 "glyph" : 273,
                 "width" : 15360,
                 "x-offset" : 14764,
-                "y-offset" : 3506,
+                "y-offset" : 3507,
                 "is-cluster-start" : true,
                 "log-cluster" : 2
               }
diff --git a/tests/layouts/vertical.layout b/tests/layouts/vertical.layout
index e8619bfb..a7f65068 100644
--- a/tests/layouts/vertical.layout
+++ b/tests/layouts/vertical.layout
@@ -128,7 +128,7 @@
               {
                 "glyph" : 1,
                 "width" : 32768,
-                "x-offset" : 28835,
+                "x-offset" : 28836,
                 "y-offset" : 9945,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
@@ -136,7 +136,7 @@
               {
                 "glyph" : 2,
                 "width" : 32768,
-                "x-offset" : 28835,
+                "x-offset" : 28836,
                 "y-offset" : 10764,
                 "is-cluster-start" : true,
                 "log-cluster" : 1
@@ -144,8 +144,8 @@
               {
                 "glyph" : 3,
                 "width" : 32768,
-                "x-offset" : 28835,
-                "y-offset" : 10452,
+                "x-offset" : 28836,
+                "y-offset" : 10453,
                 "is-cluster-start" : true,
                 "log-cluster" : 2
               }
@@ -179,24 +179,24 @@
               {
                 "glyph" : 4,
                 "width" : 32768,
-                "x-offset" : 28835,
-                "y-offset" : 16383,
+                "x-offset" : 28836,
+                "y-offset" : 16384,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               },
               {
                 "glyph" : 5,
                 "width" : 32768,
-                "x-offset" : 28835,
-                "y-offset" : 16383,
+                "x-offset" : 28836,
+                "y-offset" : 16384,
                 "is-cluster-start" : true,
                 "log-cluster" : 3
               },
               {
                 "glyph" : 7,
                 "width" : 32768,
-                "x-offset" : 28835,
-                "y-offset" : 16383,
+                "x-offset" : 28836,
+                "y-offset" : 16384,
                 "is-cluster-start" : true,
                 "log-cluster" : 6
               }
@@ -230,7 +230,7 @@
               {
                 "glyph" : 1,
                 "width" : 32768,
-                "x-offset" : 28835,
+                "x-offset" : 28836,
                 "y-offset" : 9945,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
@@ -238,7 +238,7 @@
               {
                 "glyph" : 2,
                 "width" : 32768,
-                "x-offset" : 28835,
+                "x-offset" : 28836,
                 "y-offset" : 10764,
                 "is-cluster-start" : true,
                 "log-cluster" : 1
@@ -246,8 +246,8 @@
               {
                 "glyph" : 3,
                 "width" : 32768,
-                "x-offset" : 28835,
-                "y-offset" : 10452,
+                "x-offset" : 28836,
+                "y-offset" : 10453,
                 "is-cluster-start" : true,
                 "log-cluster" : 2
               }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]