[pango/block-cursor-fixes: 2/4] Fix pango_layout_index_to_pos results




commit 7a0bbde18c64f0abb75a5b5aa576ba8af22da3de
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 19 18:33:59 2021 -0400

    Fix pango_layout_index_to_pos results
    
    We were returning wildly incorrect results for
    anything but the first run in a line.

 pango/pango-layout.c | 15 +++++++++------
 1 file 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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]