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




commit 4759afcc3e3ab7ff54460b9148bfbef51495d23e
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 0e722dd326..a0cd16697d 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1641,7 +1641,10 @@ add_text_attrs (GtkTextLayout      *layout,
 #if PANGO_VERSION_CHECK(1, 49, 0)
   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 3f603f1bdc..46944bf82e 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:
@@ -7640,6 +7641,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);
@@ -7657,6 +7659,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]