[pango/no-space-box] Don't render hex boxes for space



commit ee8e1d93115866c1c3e6bbc45b550e7e512a491a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 6 11:46:50 2019 -0400

    Don't render hex boxes for space
    
    This is never what we want, and it is easy
    enough to synthesize a reasonably looking
    space by just doing nothing.

 pango/pangocairo-font.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 pango/pangocairo-render.c |  7 ++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
---
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
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index d3b3d34d..99154e77 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -507,7 +507,12 @@ pango_cairo_renderer_show_text_glyphs (PangoRenderer        *renderer,
                      base_y + (double)(gi->geometry.y_offset) / PANGO_SCALE;
 
          if (gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG)
-           _pango_cairo_renderer_draw_unknown_glyph (crenderer, font, gi, cx, cy);
+            {
+              if (gi->glyph == (0x20 | PANGO_GLYPH_UNKNOWN_FLAG))
+                ; /* no hex boxes for space, please */
+              else
+               _pango_cairo_renderer_draw_unknown_glyph (crenderer, font, gi, cx, cy);
+            }
          else
            {
              cairo_glyphs[count].index = gi->glyph;


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