[pango/matthiasc/for-main] pango-view: Fix caret visualization
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/matthiasc/for-main] pango-view: Fix caret visualization
- Date: Sat, 28 Aug 2021 18:48:42 +0000 (UTC)
commit d7bdf800f283f42df2526b495bbead8b4a6bdc92
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..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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]