[pango/empty-line-height-attr-fix: 4/5] Fix cursor pos height in some cases




commit 189e193d670ee04adfe3644ad73aa206e1e4b06b
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Oct 19 14:16:59 2021 -0400

    Fix cursor pos height in some cases
    
    For empty runs, we were sometimes using line height,
    which may be scaled up by the line-height attribute.
    
    Fix that.
    
    Update one affected test.

 pango/pango-layout.c            | 46 +++++++++++++++++++++++++----------------
 tests/layouts/valid-22.expected |  2 +-
 2 files changed, 29 insertions(+), 19 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index ff2b2fba..6e761f2c 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -193,6 +193,7 @@ static void pango_layout_get_item_properties (PangoItem      *item,
 static void pango_layout_get_empty_extents_and_height_at_index (PangoLayout    *layout,
                                                                 int             index,
                                                                 PangoRectangle *logical_rect,
+                                                                gboolean        apply_line_height,
                                                                 int            *height);
 
 static void pango_layout_finalize    (GObject          *object);
@@ -1908,17 +1909,15 @@ pango_layout_index_to_line_and_extents (PangoLayout     *layout,
           {
             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)
+                      break;
+
                     if (run->item->offset <= index && index < run->item->offset + run->item->length)
                       break;
 
@@ -4482,7 +4481,7 @@ pango_layout_check_lines (PangoLayout *layout)
     {
       PangoRectangle logical = { 0, };
       int height = 0;
-      pango_layout_get_empty_extents_and_height_at_index (layout, 0, &logical, &height);
+      pango_layout_get_empty_extents_and_height_at_index (layout, 0, &logical, TRUE, &height);
       state.line_height = layout->line_spacing == 0.0 ? logical.height : layout->line_spacing * height;
     }
 
@@ -5115,6 +5114,7 @@ static void
 pango_layout_get_empty_extents_and_height_at_index (PangoLayout    *layout,
                                                     int             index,
                                                     PangoRectangle *logical_rect,
+                                                    gboolean        apply_line_height,
                                                     int             *height)
 {
   if (logical_rect)
@@ -5196,7 +5196,8 @@ pango_layout_get_empty_extents_and_height_at_index (PangoLayout    *layout,
 
               pango_font_metrics_unref (metrics);
 
-              if (absolute_line_height != 0 || line_height_factor != 0.0)
+              if (apply_line_height &&
+                  (absolute_line_height != 0 || line_height_factor != 0.0))
                 {
                   int line_height, leading;
 
@@ -5228,14 +5229,6 @@ pango_layout_get_empty_extents_and_height_at_index (PangoLayout    *layout,
     }
 }
 
-static void
-pango_layout_line_get_empty_extents_and_height (PangoLayoutLine *line,
-                                                PangoRectangle  *logical_rect,
-                                                int             *height)
-{
-  pango_layout_get_empty_extents_and_height_at_index (line->layout, line->start_index, logical_rect, height);
-}
-
 static void
 pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
                                          PangoRectangle *run_ink,
@@ -5503,7 +5496,7 @@ pango_layout_line_get_extents_and_height (PangoLayoutLine *line,
       PangoRectangle r, *rect;
 
       rect = logical_rect ? logical_rect : &r;
-      pango_layout_line_get_empty_extents_and_height (line, rect, height);
+      pango_layout_get_empty_extents_and_height_at_index (line->layout, line->start_index, rect, TRUE, 
height);
     }
 
   if (caching)
@@ -7365,18 +7358,35 @@ pango_layout_iter_get_run_extents (PangoLayoutIter *iter,
     }
   else
     {
-      /* The empty run at the end of a line */
+      if (iter->line->runs)
+        {
+          /* The empty run at the end of a non-empty line */
+          PangoLayoutRun *run = g_slist_last (iter->line->runs)->data;
+          pango_layout_run_get_extents_and_height (run, ink_rect, logical_rect, NULL, NULL);
+        }
+      else
+        {
+          PangoRectangle r;
+
+          pango_layout_get_empty_extents_and_height_at_index (iter->layout, 0, &r, FALSE, NULL);
 
-      pango_layout_iter_get_line_extents (iter, ink_rect, logical_rect);
+          if (ink_rect)
+            *ink_rect = r;
+
+          if (logical_rect)
+            *logical_rect = r;
+        }
 
       if (ink_rect)
         {
+          offset_y (iter, &ink_rect->y);
           ink_rect->x = iter->run_x;
           ink_rect->width = 0;
         }
 
       if (logical_rect)
         {
+          offset_y (iter, &logical_rect->y);
           logical_rect->x = iter->run_x;
           logical_rect->width = 0;
         }
diff --git a/tests/layouts/valid-22.expected b/tests/layouts/valid-22.expected
index 69c09b04..2e61a60b 100644
--- a/tests/layouts/valid-22.expected
+++ b/tests/layouts/valid-22.expected
@@ -57,7 +57,7 @@ range 11 2147483647
 
 --- cursor positions
 
-0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(1) 12(0) 
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 10(1) 12(0) 
 
 --- lines
 


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