diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-28 13:52:25 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-28 14:48:31 -0400 |
commit | d7bdf800f283f42df2526b495bbead8b4a6bdc92 (patch) | |
tree | d35fd061acb1b93f69f7121a7e9d707dedf2be20 /utils | |
parent | c5476151a3a2f05cadbd81b976fad1ac6ed52102 (diff) | |
download | pango-d7bdf800f283f42df2526b495bbead8b4a6bdc92.tar.gz |
pango-view: Fix caret visualization
I was confusing char and byte offsets here.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/viewer-pangocairo.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c index b010c3f3..c239b62a 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[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 |