[pango/line-breaker: 9/9] layout: Add spacing back




commit 4959acd947114ea64a274213df31f50fd8cb605c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 23 23:06:05 2022 -0500

    layout: Add spacing back
    
    Implement the PangoLayout:spacing property by
    translating it into a line-spacing attribute.

 pango/pango-layout.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 pango/pango-layout.h |  7 +++++
 2 files changed, 83 insertions(+)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 2b61ca5c..286c9aa3 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -20,6 +20,7 @@ struct _PangoLayout
   PangoAttrList *attrs;
   PangoFontDescription *font_desc;
   float line_height;
+  int spacing;
   int width;
   int height;
   PangoTabArray *tabs;
@@ -47,6 +48,7 @@ enum
   PROP_ATTRIBUTES,
   PROP_FONT_DESCRIPTION,
   PROP_LINE_HEIGHT,
+  PROP_SPACING,
   PROP_WIDTH,
   PROP_HEIGHT,
   PROP_TABS,
@@ -75,6 +77,7 @@ pango_layout_init (PangoLayout *layout)
   layout->alignment = PANGO_ALIGN_NATURAL;
   layout->ellipsize = PANGO_ELLIPSIZE_NONE;
   layout->line_height = 0.0;
+  layout->spacing = 0;
   layout->auto_dir = TRUE;
   layout->text = g_strdup ("");
   layout->length = 0;
@@ -126,6 +129,10 @@ pango_layout_set_property (GObject      *object,
       pango_layout_set_line_height (layout, g_value_get_float (value));
       break;
 
+    case PROP_SPACING:
+      pango_layout_set_spacing (layout, g_value_get_int (value));
+      break;
+
     case PROP_WIDTH:
       pango_layout_set_width (layout, g_value_get_int (value));
       break;
@@ -198,6 +205,10 @@ pango_layout_get_property (GObject      *object,
       g_value_set_float (value, layout->line_height);
       break;
 
+    case PROP_SPACING:
+      g_value_set_int (value, layout->spacing);
+      break;
+
     case PROP_WIDTH:
       g_value_set_int (value, layout->width);
       break;
@@ -305,6 +316,19 @@ pango_layout_class_init (PangoLayoutClass *class)
                                                 0., G_MAXFLOAT, 0.,
                                                 G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * PangoLayout:spacing: (attributes org.gtk.Property.get=pango_layout_get_spacing 
org.gtk.Property.set=pango_layout_set_spacing)
+   *
+   * Spacing to add between the lines of the `PangoLayout`.
+   *
+   * The spacing is specified in Pango units.
+   *
+   * The default value is 0.
+   */
+  props[PROP_SPACING] = g_param_spec_int ("spacing", "spacing", "spacing",
+                                        0, G_MAXINT, 0,
+                                        G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   /**
    * PangoLayout:width: (attributes org.gtk.Property.get=pango_layout_get_width 
org.gtk.Property.set=pango_layout_set_width)
    *
@@ -507,6 +531,10 @@ get_effective_attributes (PangoLayout *layout)
     pango_attr_list_insert_before (ensure_attrs (layout, attrs),
                                    pango_attr_line_height_new (layout->line_height));
 
+  if (layout->spacing != 0)
+    pango_attr_list_insert_before (ensure_attrs (layout, attrs),
+                                   pango_attr_line_spacing_new (layout->spacing));
+
   if (layout->single_paragraph)
     pango_attr_list_insert_before (ensure_attrs (layout, attrs),
                                    pango_attr_paragraph_new ());
@@ -1009,6 +1037,54 @@ pango_layout_get_line_height (PangoLayout *layout)
   return layout->line_height;
 }
 
+/**
+ * pango_layout_set_spacing:
+ * @layout: a `PangoLayout`
+ * @spacing: the amount of spacing
+ *
+ * Sets the amount of spacing in Pango units between
+ * the lines of the layout.
+ *
+ * When placing lines with spacing, Pango arranges things so that
+ *
+ *     line2.top = line1.bottom + spacing
+ *
+ * The default value is 0.
+ *
+ * Spacing only takes effect if the line height is not
+ * overridden via [method@Pango.Layout.set_line_height].
+ */
+void
+pango_layout_set_spacing (PangoLayout *layout,
+                          int          spacing)
+{
+  g_return_if_fail (PANGO_IS_LAYOUT (layout));
+
+  if (layout->spacing == spacing)
+    return;
+
+  layout->spacing = spacing;
+
+  g_object_notify_by_pspec (G_OBJECT (layout), props[PROP_SPACING]);
+  layout_changed (layout);
+}
+
+/**
+ * pango_layout_get_spacing:
+ * @layout: a `PangoLayout`
+ *
+ * Gets the amount of spacing between the lines of the layout.
+ *
+ * Return value: the spacing in Pango units
+ */
+int
+pango_layout_get_spacing (PangoLayout *layout)
+{
+  g_return_val_if_fail (PANGO_IS_LAYOUT (layout), 0);
+
+  return layout->spacing;
+}
+
 /**
  * pango_layout_set_width:
  * @layout: a `PangoLayout`.
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 6e939984..c183716d 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -70,6 +70,13 @@ PANGO_AVAILABLE_IN_ALL
 float                   pango_layout_get_line_height
                                                     (PangoLayout                  *layout);
 
+PANGO_AVAILABLE_IN_ALL
+void                    pango_layout_set_spacing    (PangoLayout                  *layout,
+                                                     int                           spacing);
+
+PANGO_AVAILABLE_IN_ALL
+int                     pango_layout_get_spacing    (PangoLayout                  *layout);
+
 PANGO_AVAILABLE_IN_ALL
 void                    pango_layout_set_width      (PangoLayout                  *layout,
                                                      int                           width);


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