[gtk/css-line-height2: 6/8] textview: Set line height from css




commit faf19253e359a5953ed730c698ce1925d7bd5fbb
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 7 12:30:11 2021 -0400

    textview: Set line height from css
    
    Set the line height in the default attributes from
    the CSS style.
    This makes line height work in GtkTextView.

 gtk/gtktextattributes.h |  1 +
 gtk/gtktextlayout.c     |  5 ++++-
 gtk/gtktextview.c       | 13 +++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtktextattributes.h b/gtk/gtktextattributes.h
index 5f539914d1..3648dabf7c 100644
--- a/gtk/gtktextattributes.h
+++ b/gtk/gtktextattributes.h
@@ -158,6 +158,7 @@ struct _GtkTextAttributes
   guint no_breaks : 1;
   guint show_spaces : 3; /* PangoShowFlags */
   guint no_hyphens : 1;
+  guint line_height_is_absolute : 1;
 };
 
 GtkTextAttributes* gtk_text_attributes_new         (void);
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index f082b016d6..127c4dfe1a 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1640,7 +1640,10 @@ add_text_attrs (GtkTextLayout      *layout,
 
   if (style->line_height != 0.0)
     {
-      attr = pango_attr_line_height_new (style->line_height);
+      if (style->line_height_is_absolute)
+        attr = pango_attr_line_height_new_absolute (style->line_height * PANGO_SCALE);
+      else
+        attr = pango_attr_line_height_new (style->line_height);
       attr->start_index = start;
       attr->end_index = start + byte_count;
 
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 6e1a922e37..87726b0ff4 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -57,6 +57,7 @@
 #include "gtknative.h"
 #include "gtkwidgetprivate.h"
 #include "gtkjoinedmenuprivate.h"
+#include "gtkcsslineheightvalueprivate.h"
 
 /**
  * GtkTextView:
@@ -7642,6 +7643,7 @@ gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
   GtkCssStyle *style;
   const GdkRGBA black = { 0, };
   const GdkRGBA *color;
+  double height;
 
   if (!values->appearance.bg_rgba)
     values->appearance.bg_rgba = gdk_rgba_copy (&black);
@@ -7659,6 +7661,17 @@ gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
     pango_font_description_free (values->font);
 
   values->font = gtk_css_style_get_pango_font (style);
+
+  values->line_height = 0.0;
+  values->line_height_is_absolute = FALSE;
+
+  height = gtk_css_line_height_value_get (style->font->line_height);
+  if (height != 0.0)
+    {
+      values->line_height = height;
+      if (gtk_css_number_value_get_dimension (style->font->line_height) == GTK_CSS_DIMENSION_LENGTH)
+        values->line_height_is_absolute = TRUE;
+    }
 }
 
 static void


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