From d6527dd41616e32a224d70cd0a531940ea38b82d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 18 Nov 2022 14:02:17 -0500 Subject: Fix char offset calculations When dealing with multi-paragraph layouts, the char offsets of the items are expected to be relative to the beginning of the text, not relative to the beginning of the current paragraph. This error was introduced in a03bf5bc6b07ba6e. Fixes: #716 --- pango/itemize.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pango/itemize.c b/pango/itemize.c index cf9d6a8f..35f17d54 100644 --- a/pango/itemize.c +++ b/pango/itemize.c @@ -1495,13 +1495,14 @@ handle_variants (const char *text, static GList * reorder_items (PangoContext *context, - GList *items) + GList *items, + int initial_offset) { - int char_offset = 0; + int char_offset = initial_offset; items = g_list_reverse (items); - /* Also cmpute the char offset for each item here */ + /* Also compute the char offset for each item here */ for (GList *l = items; l; l = l->next) { PangoItemPrivate *item = l->data; @@ -1544,6 +1545,7 @@ pango_itemize_with_font (PangoContext *context, const PangoFontDescription *desc) { ItemizeState state; + int initial_offset; g_return_val_if_fail (context->font_map != NULL, NULL); @@ -1559,7 +1561,9 @@ pango_itemize_with_font (PangoContext *context, itemize_state_finish (&state); - return reorder_items (context, state.result); + initial_offset = g_utf8_strlen (text, start_index); + + return reorder_items (context, state.result, initial_offset); } /* Apply post-processing steps that may require log attrs. -- cgit v1.2.1