[pango/visible-things: 8/11] layout: Make tab visible too



commit 422724272c8c06034c45ed19615cc0eebae292c2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 7 16:44:35 2019 -0400

    layout: Make tab visible too
    
    When the 'visible space' option is set, also
    arrange for tab characters to be passed on to
    the rendering layer as non-empty.

 pango/pango-layout.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9a6e96a7..51204a51 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -2974,6 +2974,7 @@ pango_layout_line_leaked (PangoLayoutLine *line)
  *****************/
 
 static void shape_tab (PangoLayoutLine  *line,
+                       PangoItem        *item,
                       PangoGlyphString *glyphs);
 
 static void
@@ -3168,8 +3169,25 @@ line_width (PangoLayoutLine *line)
   return width;
 }
 
+static gboolean
+showing_space (const PangoAnalysis *analysis)
+{
+  GSList *l;
+
+  for (l = analysis->extra_attrs; l; l = l->next)
+    {
+      PangoAttribute *attr = l->data;
+
+      if (attr->klass->type == PANGO_ATTR_SHOW_SPACE)
+        return ((PangoAttrInt*)attr)->value != 0;
+    }
+
+  return FALSE;
+}
+
 static void
 shape_tab (PangoLayoutLine  *line,
+           PangoItem        *item,
           PangoGlyphString *glyphs)
 {
   int i, space_width;
@@ -3178,7 +3196,10 @@ shape_tab (PangoLayoutLine  *line,
 
   pango_glyph_string_set_size (glyphs, 1);
 
-  glyphs->glyphs[0].glyph = PANGO_GLYPH_EMPTY;
+  if (showing_space (&item->analysis))
+    glyphs->glyphs[0].glyph = PANGO_GET_UNKNOWN_GLYPH ('\t');
+  else
+    glyphs->glyphs[0].glyph = PANGO_GLYPH_EMPTY;
   glyphs->glyphs[0].geometry.x_offset = 0;
   glyphs->glyphs[0].geometry.y_offset = 0;
   glyphs->glyphs[0].attr.is_cluster_start = 1;
@@ -3314,7 +3335,7 @@ shape_run (PangoLayoutLine *line,
   PangoGlyphString *glyphs = pango_glyph_string_new ();
 
   if (layout->text[item->offset] == '\t')
-    shape_tab (line, glyphs);
+    shape_tab (line, item, glyphs);
   else
     {
       if (state->properties.shape_set)


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