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




commit 2ee2dea6c30b06d1e5d74da3e8eb8a3fceb0c493
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.

 docs/pango_rendering.md   |  4 ++--
 utils/viewer-pangocairo.c | 35 +++++++++++++++++++++++------------
 2 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/docs/pango_rendering.md b/docs/pango_rendering.md
index 4bec5176..5b6c9ecf 100644
--- a/docs/pango_rendering.md
+++ b/docs/pango_rendering.md
@@ -36,5 +36,5 @@ Justification
 Rendering
 : takes a string of positioned glyphs, and renders them onto a surface.
   This is accomplished by a [class@Pango.Renderer] object. The functions
-  pango_cairo_show_glyph_string() and pango_cairo_show_layout() use a
-  [class@Pango.Renderer] to draw text onto a cairo surface.
+  [func@PangoCairo.show_glyph_string] and [func@PangoCairo.show_layout] use
+  a [class@Pango.Renderer] to draw text onto a cairo surface.
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]