[pango/ligature-caret-rtl-fixes: 1/7] pango-view: Be more careful about caret positions




commit 0fa8f933e051248b83230502754d000f693bb276
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 27 00:35:57 2021 -0400

    pango-view: Be more careful about caret positions
    
    Don't show carets where they don't belong.
    Skip non-cursor positions.

 utils/viewer-pangocairo.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index af4925e3..fa53d9fb 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -409,10 +409,16 @@ render_callback (PangoLayout *layout,
 
       if (annotate & ANNOTATE_CARET_POSITIONS)
         {
+          const PangoLogAttr *attrs;
+          int n_attrs;
+          int offset;
+
           /* draw the caret positions in purple */
           cairo_save (cr);
           cairo_set_source_rgba (cr, 1.0, 0.0, 1.0, 0.5);
 
+          attrs = pango_layout_get_log_attrs_readonly (layout, &n_attrs);
+
           iter = pango_layout_get_iter (layout);
           do
             {
@@ -431,24 +437,29 @@ render_callback (PangoLayout *layout,
               text = pango_layout_get_text (layout);
               start = text + run->item->offset;
 
+              offset = g_utf8_strlen (text, start - text);
+
               y = pango_layout_iter_get_baseline (iter);
 
               trailing = FALSE;
               p = start;
               for (int i = 0; i <= run->item->num_chars; i++)
                 {
-                  pango_glyph_string_index_to_x (run->glyphs,
-                                                 text + run->item->offset,
-                                                 run->item->length,
-                                                 &run->item->analysis,
-                                                 p - start,
-                                                 trailing,
-                                                 &x);
-                  x += rect.x;
-
-                  cairo_arc (cr, x / PANGO_SCALE, y / PANGO_SCALE, 3.0, 0, 2*G_PI);
-                  cairo_close_path (cr);
-                  cairo_fill (cr);
+                  if (attrs[offset + i].is_cursor_position)
+                    {
+                      pango_glyph_string_index_to_x (run->glyphs,
+                                                     text + run->item->offset,
+                                                     run->item->length,
+                                                     &run->item->analysis,
+                                                     p - start,
+                                                     trailing,
+                                                     &x);
+                      x += rect.x;
+
+                      cairo_arc (cr, x / PANGO_SCALE, y / PANGO_SCALE, 3.0, 0, 2*G_PI);
+                      cairo_close_path (cr);
+                      cairo_fill (cr);
+                   }
 
                   if (i < run->item->num_chars)
                     p = g_utf8_next_char (p);


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