[gtk/css-line-height: 3/4] textview: Add line-spacing plumbing




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

    textview: Add line-spacing plumbing
    
    This adds a line-spacing property to GtkTextAttributes
    and GtkTextTag.

 gtk/gtktextattributes.c |  4 ++++
 gtk/gtktextattributes.h |  2 ++
 gtk/gtktextlayout.c     |  2 ++
 gtk/gtktexttag.c        | 30 ++++++++++++++++++++++++++++++
 gtk/gtktexttagprivate.h |  1 +
 5 files changed, 39 insertions(+)
---
diff --git a/gtk/gtktextattributes.c b/gtk/gtktextattributes.c
index 738caa6bc1..becbad4202 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_spacing_set)
+        dest->line_spacing = vals->line_spacing;
+
       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_spacing_set ||
     priv->tabs_set ||
     priv->underline_set ||
     priv->overline_set ||
diff --git a/gtk/gtktextattributes.h b/gtk/gtktextattributes.h
index 05f7750247..479b961b3a 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_spacing;
+
   int letter_spacing;
 
   guint invisible : 1;
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index ea5e85a577..208604f9c2 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1277,6 +1277,8 @@ set_para_values (GtkTextLayout      *layout,
   pango_layout_set_spacing (display->layout,
                             style->pixels_inside_wrap * PANGO_SCALE);
 
+  pango_layout_set_line_spacing (display->layout, style->line_spacing);
+
   if (style->tabs)
     pango_layout_set_tabs (display->layout, style->tabs);
 
diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c
index fdf17a6efc..273f8c0c78 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_SPACING,
   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_SPACING_SET,
   PROP_EDITABLE_SET,
   PROP_WRAP_MODE_SET,
   PROP_JUSTIFICATION_SET,
@@ -585,6 +587,8 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
    * GtkTextTag:pixels-inside-wrap:
    *
    * Pixels of blank space between wrapped lines in a paragraph.
+   *
+   * Ignored if line-spacing is set.
    */
   g_object_class_install_property (object_class,
                                    PROP_PIXELS_INSIDE_WRAP,
@@ -596,6 +600,21 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
                                                      0,
                                                      GTK_PARAM_READWRITE));
 
+  /**
+   * GtkTextag:line-spacing:
+   *
+   * The line spacing factor that is applied between consecutive lines.
+   *
+   * Since: 4.4
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_LINE_SPACING,
+                                   g_param_spec_float ("line-spacing",
+                                                     P_("Linespacing"),
+                                                     P_("The factor for spacing between lines"),
+                                                     0.0, 10.0, 0.0,
+                                                     GTK_PARAM_READWRITE));
+
   /**
    * GtkTextTag:strikethrough:
    *
@@ -936,6 +955,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-spacing-set", PROP_LINE_SPACING_SET,
+                P_("Linespacing set"),
+                P_("Whether this tag affects spacing between wrapped lines"));
+
   ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
                 P_("Strikethrough set"),
                 P_("Whether this tag affects strikethrough"));
@@ -1573,6 +1596,13 @@ gtk_text_tag_set_property (GObject      *object,
       size_changed = TRUE;
       break;
 
+    case PROP_LINE_SPACING:
+      priv->line_spacing_set = TRUE;
+      priv->values->line_spacing = g_value_get_float (value);
+      g_object_notify (object, "line-spacing-set");
+      size_changed = TRUE;
+      break;
+
     case PROP_EDITABLE:
       priv->editable_set = TRUE;
       priv->values->editable = g_value_get_boolean (value);
diff --git a/gtk/gtktexttagprivate.h b/gtk/gtktexttagprivate.h
index b0bd079532..f78eba76f0 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_spacing_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]