[gtksourceview] gutterlines: improve yrange calculation



commit 32c049d52e388297af17f88ea38e3f19d978f44a
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 26 16:08:07 2021 -0700

    gutterlines: improve yrange calculation
    
    This could be slighly more expensive for the single line case, but we
    really have to do that anyway or we won't take line-height into account.
    
    Additionally, the first/last doesn't seem to be perfect in terms of
    aligning with the pango run, but it does seem to be within a pixel.
    
    Fixes #227

 gtksourceview/gtksourcegutterlines.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterlines.c b/gtksourceview/gtksourcegutterlines.c
index 70e209d6..26a62a94 100644
--- a/gtksourceview/gtksourcegutterlines.c
+++ b/gtksourceview/gtksourcegutterlines.c
@@ -181,14 +181,13 @@ _gtk_source_gutter_lines_new (GtkTextView       *text_view,
 
                if G_LIKELY (single_line)
                {
-                       GdkRectangle rect;
+                       /* Need to use yrange so that line-height can be taken
+                        * into account.
+                        */
+                       gtk_text_view_get_line_yrange (text_view, &iter, &info.y, &info.height);
 
-                       gtk_text_view_get_iter_location (text_view, &iter, &rect);
-
-                       info.y = rect.y;
-                       info.height = rect.height;
-                       info.first_height = rect.height;
-                       info.last_height = rect.height;
+                       info.first_height = info.height;
+                       info.last_height = info.height;
                }
                else
                {
@@ -210,13 +209,9 @@ _gtk_source_gutter_lines_new (GtkTextView       *text_view,
                                if (needs_wrap_first)
                                {
                                        gtk_text_view_get_iter_location (text_view, &iter, &rect);
-                                       info.first_height = rect.height;
 
-                                       if (info.y != rect.y)
-                                       {
-                                               info.height -= rect.y - info.y;
-                                               info.y = rect.y;
-                                       }
+                                       /* Try to somewhat handle line-height correctly */
+                                       info.first_height = ((rect.y - info.y) * 2) + rect.height;
                                }
                                else
                                {
@@ -241,8 +236,8 @@ _gtk_source_gutter_lines_new (GtkTextView       *text_view,
                                                gtk_text_view_get_iter_location (text_view, &iter, &rect);
                                        }
 
-                                       info.last_height = rect.height;
-                                       info.height = rect.y + rect.height - info.y;
+                                       /* Try to somewhat handle line-height correctly */
+                                       info.last_height = ((info.y + info.height) - (rect.y + rect.height)) 
* 2 + rect.height;
                                }
                                else
                                {


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