[pango/visible-things: 6/12] cairo: Better hex boxes for ignorables



commit 95b9504c6c077d04d3911af4ef2360c0f29001f8
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 7 14:05:44 2019 -0400

    cairo: Better hex boxes for ignorables
    
    For ignorable characters such as U+00AD, Soft Hyphen,
    render a hex box with their 'nickname', which is a
    2-6 character short form such as SHY.

 pango/pangocairo-font.c   | 15 ++++++++++++---
 pango/pangocairo-render.c | 26 ++++++++++++++++++++------
 2 files changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 8b1f12d3..3bf83857 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -735,11 +735,20 @@ _pango_cairo_font_private_get_glyph_extents_missing (PangoCairoFontPrivate *cf_p
 
   ch = glyph & ~PANGO_GLYPH_UNKNOWN_FLAG;
 
-  rows = hbi->rows;
   if (G_UNLIKELY (glyph == PANGO_GLYPH_INVALID_INPUT || ch > 0x10FFFF))
-    cols = 1;
+    {
+      rows = hbi->rows;
+      cols = 1;
+    }
+  else if (pango_get_ignorable_size (ch, &rows, &cols))
+    {
+      /* We special-case ignorables when rendering hex boxes */
+    }
   else
-    cols = ((glyph & ~PANGO_GLYPH_UNKNOWN_FLAG) > 0xffff ? 6 : 4) / rows;
+    {
+      rows = hbi->rows;
+      cols = ((glyph & ~PANGO_GLYPH_UNKNOWN_FLAG) > 0xffff ? 6 : 4) / rows;
+    }
 
   if (ink_rect)
     {
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index 3db3de5e..01d6c2ab 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -159,6 +159,7 @@
 #include "pango-font-private.h"
 #include "pangocairo-private.h"
 #include "pango-glyph-item.h"
+#include "pango-impl-utils.h"
 
 typedef struct _PangoCairoRendererClass PangoCairoRendererClass;
 
@@ -369,10 +370,12 @@ _pango_cairo_renderer_draw_unknown_glyph (PangoCairoRenderer *crenderer,
   int row, col;
   int rows, cols;
   double width, lsb;
-  char hexbox_string[2] = {0, 0};
+  char hexbox_string[2] = { 0, 0 };
   PangoCairoFontHexBoxInfo *hbi;
   gunichar ch;
   gboolean invalid_input;
+  char *p;
+  const char *name;
 
   cairo_save (crenderer->cr);
 
@@ -386,15 +389,23 @@ _pango_cairo_renderer_draw_unknown_glyph (PangoCairoRenderer *crenderer,
       goto done;
     }
 
-  rows = hbi->rows;
   if (G_UNLIKELY (invalid_input))
     {
+      rows = hbi->rows;
       cols = 1;
     }
+  else if ((name = pango_get_ignorable_size (ch, &rows, &cols)))
+    {
+      /* Nothing else to do, we render 'default ignorable' chars
+       * as hex box with their nick.
+       */
+    }
   else
     {
+      rows = hbi->rows;
       cols = (ch > 0xffff ? 6 : 4) / rows;
       g_snprintf (buf, sizeof(buf), (ch > 0xffff) ? "%06X" : "%04X", ch);
+      name = buf;
     }
 
   width = (3 * hbi->pad_x + cols * (hbi->digit_width + hbi->pad_x));
@@ -413,18 +424,21 @@ _pango_cairo_renderer_draw_unknown_glyph (PangoCairoRenderer *crenderer,
     goto done;
 
   x0 = cx + lsb + hbi->pad_x * 2;
-  y0 = cy + hbi->box_descent - hbi->pad_y * 2;
+  y0 = cy + hbi->box_descent - hbi->pad_y * 2 - ((hbi->rows - rows) * hbi->digit_height / 2);
 
-  for (row = 0; row < rows; row++)
+  for (row = 0, p = name; row < rows; row++)
     {
       double y = y0 - (rows - 1 - row) * (hbi->digit_height + hbi->pad_y);
-      for (col = 0; col < cols; col++)
+      for (col = 0; col < cols; col++, p++)
        {
          double x = x0 + col * (hbi->digit_width + hbi->pad_x);
 
+          if (!p)
+            goto done;
+
          cairo_move_to (crenderer->cr, x, y);
 
-         hexbox_string[0] = buf[row * cols + col];
+          hexbox_string[0] = p[0];
 
          if (crenderer->do_path)
              cairo_text_path (crenderer->cr, hexbox_string);


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