[gtk/css-line-height2: 1/7] textview: Add line height plumbing




commit e0375f2ba02b99b14322657d3887dfe421b768e5
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 5 22:22:50 2021 -0400

    textview: Add line height plumbing
    
    This adds a line-height property to GtkTexttag and a
    line_height field to GtkTextAttributes, and translates
    it to a pango attribute.

 gtk/gtktextattributes.c |  4 ++++
 gtk/gtktextattributes.h |  2 ++
 gtk/gtktextlayout.c     | 14 ++++++++++++--
 gtk/gtktexttag.c        | 36 ++++++++++++++++++++++++++++++++++++
 gtk/gtktexttagprivate.h |  1 +
 5 files changed, 55 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktextattributes.c b/gtk/gtktextattributes.c
index 738caa6bc1..fbc63a7d63 100644
--- a/gtk/gtktextattributes.c
+++ b/gtk/gtktextattributes.c
@@ -387,6 +387,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
       if (tag->priv->pixels_inside_wrap_set)
         dest->pixels_inside_wrap = vals->pixels_inside_wrap;
 
+      if (tag->priv->line_height_set)
+        dest->line_height = vals->line_height;
+
       if (tag->priv->tabs_set)
         {
           if (dest->tabs)
@@ -457,6 +460,7 @@ _gtk_text_tag_affects_size (GtkTextTag *tag)
     priv->pixels_above_lines_set ||
     priv->pixels_below_lines_set ||
     priv->pixels_inside_wrap_set ||
+    priv->line_height_set ||
     priv->tabs_set ||
     priv->underline_set ||
     priv->overline_set ||
diff --git a/gtk/gtktextattributes.h b/gtk/gtktextattributes.h
index 05f7750247..5f539914d1 100644
--- a/gtk/gtktextattributes.h
+++ b/gtk/gtktextattributes.h
@@ -147,6 +147,8 @@ struct _GtkTextAttributes
   int pixels_below_lines;
   int pixels_inside_wrap;
 
+  float line_height;
+
   int letter_spacing;
 
   guint invisible : 1;
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index 80fb0a2bf1..0e722dd326 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1551,7 +1551,7 @@ add_generic_attrs (GtkTextLayout      *layout,
       
       pango_attr_list_insert (attrs, attr);
     }
-  
+
   if (!size_only)
     {
       attr = gtk_text_attr_appearance_new (appearance);
@@ -1638,6 +1638,17 @@ add_text_attrs (GtkTextLayout      *layout,
       pango_attr_list_insert (attrs, attr);
     }
 
+#if PANGO_VERSION_CHECK(1, 49, 0)
+  if (style->line_height != 0.0)
+    {
+      attr = pango_attr_line_height_new (style->line_height);
+      attr->start_index = start;
+      attr->end_index = start + byte_count;
+
+      pango_attr_list_insert (attrs, attr);
+    }
+#endif
+
   if (style->font_features)
     {
       attr = pango_attr_font_features_new (style->font_features);
@@ -1673,7 +1684,6 @@ add_text_attrs (GtkTextLayout      *layout,
 
       pango_attr_list_insert (attrs, attr);
     }
-
 }
 
 static void
diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c
index fdf17a6efc..cebc1ddbe4 100644
--- a/gtk/gtktexttag.c
+++ b/gtk/gtktexttag.c
@@ -107,6 +107,7 @@ enum {
   PROP_PIXELS_ABOVE_LINES,
   PROP_PIXELS_BELOW_LINES,
   PROP_PIXELS_INSIDE_WRAP,
+  PROP_LINE_HEIGHT,
   PROP_EDITABLE,
   PROP_WRAP_MODE,
   PROP_JUSTIFICATION,
@@ -150,6 +151,7 @@ enum {
   PROP_PIXELS_ABOVE_LINES_SET,
   PROP_PIXELS_BELOW_LINES_SET,
   PROP_PIXELS_INSIDE_WRAP_SET,
+  PROP_LINE_HEIGHT_SET,
   PROP_EDITABLE_SET,
   PROP_WRAP_MODE_SET,
   PROP_JUSTIFICATION_SET,
@@ -596,6 +598,21 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
                                                      0,
                                                      GTK_PARAM_READWRITE));
 
+  /**
+   * GtkTexTag:line-height:
+   *
+   * Factor to scale line height by.
+   *
+   * Since: 4.6
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_LINE_HEIGHT,
+                                   g_param_spec_float ("line-height",
+                                                       P_("Line height factor"),
+                                                       P_("The factor to apply to line height"),
+                                                       0.0, 10.0, 0.0,
+                                                       GTK_PARAM_READWRITE));
+
   /**
    * GtkTextTag:strikethrough:
    *
@@ -936,6 +953,10 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
                 P_("Pixels inside wrap set"),
                 P_("Whether this tag affects the number of pixels between wrapped lines"));
 
+  ADD_SET_PROP ("line-height-set", PROP_LINE_HEIGHT_SET,
+                P_("Line height set"),
+                P_("Whether this tag affects the height of lines"));
+
   ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
                 P_("Strikethrough set"),
                 P_("Whether this tag affects strikethrough"));
@@ -1573,6 +1594,13 @@ gtk_text_tag_set_property (GObject      *object,
       size_changed = TRUE;
       break;
 
+    case PROP_LINE_HEIGHT:
+      priv->line_height_set = TRUE;
+      priv->values->line_height = g_value_get_float (value);
+      g_object_notify (object, "line-height-set");
+      size_changed = TRUE;
+      break;
+
     case PROP_EDITABLE:
       priv->editable_set = TRUE;
       priv->values->editable = g_value_get_boolean (value);
@@ -2022,6 +2050,10 @@ gtk_text_tag_get_property (GObject      *object,
       g_value_set_int (value,  priv->values->pixels_inside_wrap);
       break;
 
+    case PROP_LINE_HEIGHT:
+      g_value_set_float (value, priv->values->line_height);
+      break;
+
     case PROP_EDITABLE:
       g_value_set_boolean (value, priv->values->editable);
       break;
@@ -2169,6 +2201,10 @@ gtk_text_tag_get_property (GObject      *object,
       g_value_set_boolean (value, priv->pixels_inside_wrap_set);
       break;
 
+    case PROP_LINE_HEIGHT_SET:
+      g_value_set_boolean (value, priv->line_height_set);
+      break;
+
     case PROP_EDITABLE_SET:
       g_value_set_boolean (value, priv->editable_set);
       break;
diff --git a/gtk/gtktexttagprivate.h b/gtk/gtktexttagprivate.h
index b0bd079532..2b7b078bda 100644
--- a/gtk/gtktexttagprivate.h
+++ b/gtk/gtktexttagprivate.h
@@ -71,6 +71,7 @@ struct _GtkTextTagPrivate
   guint pixels_above_lines_set : 1;
   guint pixels_below_lines_set : 1;
   guint pixels_inside_wrap_set : 1;
+  guint line_height_set : 1;
   guint tabs_set : 1;
   guint underline_set : 1;
   guint overline_set : 1;


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