[pango/matthiasc/for-main: 15/15] pango-view: Fix caret visualization




commit 6d897496e02213f6dd637f95a39191e0952ab33f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 28 13:52:25 2021 -0400

    pango-view: Fix caret visualization
    
    I was confusing char and byte offsets here.

 utils/viewer-pangocairo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c
index b010c3f3..e82724a0 100644
--- a/utils/viewer-pangocairo.c
+++ b/utils/viewer-pangocairo.c
@@ -536,10 +536,17 @@ render_callback (PangoLayout *layout,
 
           const char *text = pango_layout_get_text (layout);
           int length = g_utf8_strlen (text, -1);
-          for (int i = 0; i <= length; i++)
+          const char *p;
+          int i;
+          for (i = 0, p = text; i <= length; i++, p = g_utf8_next_char (p))
             {
               PangoRectangle rect;
-              pango_layout_get_caret_pos (layout, i, &rect, NULL);
+
+              if (!attrs[offset + i].is_cursor_position)
+                continue;
+
+              pango_layout_get_caret_pos (layout, p - text, &rect, NULL);
+              g_print ("draw caret pos at %d\n", i);
 
               cairo_move_to (cr,
                              (double)rect.x / PANGO_SCALE - lw / 2


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