diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-27 00:35:57 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-27 08:46:39 -0400 |
commit | 0fa8f933e051248b83230502754d000f693bb276 (patch) | |
tree | 9cc0061d69d4e10fe1470531342206a53a465b1c /utils | |
parent | 371171b65600729c3220826430ee1a0993541dbd (diff) | |
download | pango-0fa8f933e051248b83230502754d000f693bb276.tar.gz |
pango-view: Be more careful about caret positions
Don't show carets where they don't belong.
Skip non-cursor positions.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/viewer-pangocairo.c | 35 |
1 files 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); |