summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-19 18:33:59 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-20 02:08:46 -0400
commit7a0bbde18c64f0abb75a5b5aa576ba8af22da3de (patch)
tree7213b995087386ec6977a0125e36b3efc727edb8 /pango/pango-layout.c
parentcaa20e046d65fa4d09981e8983fe1092bfb3e236 (diff)
downloadpango-7a0bbde18c64f0abb75a5b5aa576ba8af22da3de.tar.gz
Fix pango_layout_index_to_pos results
We were returning wildly incorrect results for anything but the first run in a line.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index ee58243b..ac7eaab0 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -2374,7 +2374,8 @@ pango_layout_index_to_pos (PangoLayout *layout,
int index,
PangoRectangle *pos)
{
- PangoRectangle logical_rect;
+ PangoRectangle line_logical_rect;
+ PangoRectangle run_logical_rect;
PangoLayoutIter iter;
PangoLayoutLine *layout_line = NULL;
int x_pos;
@@ -2404,6 +2405,8 @@ pango_layout_index_to_pos (PangoLayout *layout,
break;
}
+ pango_layout_iter_get_line_extents (&iter, NULL, &line_logical_rect);
+
layout_line = tmp_line;
if (layout_line->start_index + layout_line->length > index)
@@ -2412,7 +2415,7 @@ pango_layout_index_to_pos (PangoLayout *layout,
{
PangoLayoutRun *run = _pango_layout_iter_get_run (&iter);
- pango_layout_iter_get_run_extents (&iter, NULL, &logical_rect);
+ pango_layout_iter_get_run_extents (&iter, NULL, &run_logical_rect);
if (run->item->offset <= index && index < run->item->offset + run->item->length)
break;
@@ -2431,16 +2434,16 @@ pango_layout_index_to_pos (PangoLayout *layout,
}
}
- pos->y = logical_rect.y;
- pos->height = logical_rect.height;
+ pos->y = run_logical_rect.y;
+ pos->height = run_logical_rect.height;
pango_layout_line_index_to_x (layout_line, index, 0, &x_pos);
- pos->x = logical_rect.x + x_pos;
+ pos->x = line_logical_rect.x + x_pos;
if (index < layout_line->start_index + layout_line->length)
{
pango_layout_line_index_to_x (layout_line, index, 1, &x_pos);
- pos->width = (logical_rect.x + x_pos) - pos->x;
+ pos->width = (line_logical_rect.x + x_pos) - pos->x;
}
else
pos->width = 0;