summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-09 14:57:57 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-09 15:11:18 -0400
commit903c9bf4b0ee86038c5fa4b430a2ceff71d621b9 (patch)
treec062a51949e0707c3b2628b984daa9902b9e9d81 /pango/pango-layout.c
parent587c159a8b835a84f4ee5ec731052b2dc3c02aee (diff)
downloadpango-903c9bf4b0ee86038c5fa4b430a2ceff71d621b9.tar.gz
Fix corner cases around line ends
pango_layout_index_to_line_and_extents needs to return a run rect even if the line has no non-empty runs. Failing to do so was causing cursors at the end of lines to have a height of 0 or 1, which is not what we want. Add a testcase.
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index fa13ad59..e73a001d 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1820,25 +1820,30 @@ pango_layout_index_to_line_and_extents (PangoLayout *layout,
PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (&iter);
if (tmp_line->start_index > index)
- break; /* index was in paragraph delimiters */
+ break; /* index was in paragraph delimiters */
line = tmp_line;
pango_layout_iter_get_line_extents (&iter, NULL, line_rect);
- if (line->start_index + line->length > index)
+ if (!iter.line_list_link->next ||
+ ((PangoLayoutLine *)iter.line_list_link->next->data)->start_index > index)
{
if (run_rect)
{
+ *run_rect = *line_rect;
+
while (TRUE)
{
PangoLayoutRun *run = _pango_layout_iter_get_run (&iter);
+ if (!run)
+ break;
+
+ pango_layout_iter_get_run_extents (&iter, NULL, run_rect);
+
if (run->item->offset <= index && index < run->item->offset + run->item->length)
- {
- pango_layout_iter_get_run_extents (&iter, NULL, run_rect);
- break;
- }
+ break;
if (!pango_layout_iter_next_run (&iter))
break;
@@ -2329,11 +2334,10 @@ 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);
+
if (run->item->offset <= index && index < run->item->offset + run->item->length)
- {
- pango_layout_iter_get_run_extents (&iter, NULL, &logical_rect);
- break;
- }
+ break;
if (!pango_layout_iter_next_run (&iter))
break;
@@ -2459,8 +2463,8 @@ pango_layout_get_cursor_pos (PangoLayout *layout,
{
PangoDirection dir1, dir2;
int level1, level2;
- PangoRectangle line_rect;
- PangoRectangle run_rect;
+ PangoRectangle line_rect = { 666, };
+ PangoRectangle run_rect = { 666, };
PangoLayoutLine *layout_line = NULL; /* Quiet GCC */
int x1_trailing;
int x2;