[pango/no-space-box: 7/7] cairo: Give missing spaces a better width



commit 98f8809ef2ba4d671536af405dad4a1477950170
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 6 16:45:49 2019 -0400

    cairo: Give missing spaces a better width
    
    We are not rendering hex boxes for missing spaces,
    so we don't need to give them the hex box width.

 pango/pangocairo-font.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
---
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index df77f43b..8b1f12d3 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -671,6 +671,45 @@ _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)
+{
+  const char hexdigits[] = "0123456789ABCDEF";
+  char c[2] = {0, 0};
+  int i;
+  double hex_width;
+  int width;
+
+  /* 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.
+   */
+
+  hex_width = 0;
+  for (i = 0 ; i < 16 ; i++)
+    {
+      cairo_text_extents_t extents;
+
+      c[0] = hexdigits[i];
+      cairo_scaled_font_text_extents (cf_priv->scaled_font, c, &extents);
+      hex_width += extents.width;
+    }
+  width = pango_units_from_double (hex_width / 16);
+
+  if (ink_rect)
+    {
+      ink_rect->x = ink_rect->y = ink_rect->height = 0;
+      ink_rect->width = width;
+    }
+  if (logical_rect)
+    {
+      *logical_rect = cf_priv->font_extents;
+      logical_rect->width = width;
+    }
+}
+
 static void
 _pango_cairo_font_private_get_glyph_extents_missing (PangoCairoFontPrivate *cf_priv,
                                                     PangoGlyph             glyph,
@@ -681,6 +720,12 @@ _pango_cairo_font_private_get_glyph_extents_missing (PangoCairoFontPrivate *cf_p
   gunichar ch;
   gint rows, cols;
 
+  if (glyph == (0x20 | PANGO_GLYPH_UNKNOWN_FLAG))
+    {
+      get_space_extents (cf_priv, ink_rect, logical_rect);
+      return;
+    }
+
   hbi = _pango_cairo_font_private_get_hex_box_info (cf_priv);
   if (!hbi)
     {
@@ -768,6 +813,7 @@ _pango_cairo_font_private_glyph_extents_cache_init (PangoCairoFontPrivate *cf_pr
   return TRUE;
 }
 
+
 /* Fills in the glyph extents cache entry
  */
 static void


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