[pango/pango2: 78/168] layout: Add spacing back
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 78/168] layout: Add spacing back
- Date: Wed, 8 Jun 2022 10:22:17 +0000 (UTC)
commit 6ce60bf0d869f0dfda454be070479bbe97a40e1a
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-attributes.c | 4 +--
pango/pango-layout.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++-
pango/pango-layout.h | 7 +++++
pango/serializer.c | 3 ++
4 files changed, 92 insertions(+), 3 deletions(-)
---
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 055c3948..a8d20697 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1557,8 +1557,8 @@ pango_attr_line_height_new_absolute (int height)
* if not overridden by line spacing attributes.
*
* This affects the values returned by
- * [method@Pango.LayoutLine.get_extents],
- * [method@Pango.LayoutIter.get_line_extents].
+ * [method Pango Line.get_extents],
+ * [method@Pango.LineIter.get_line_extents].
*/
PangoAttribute *
pango_attr_line_spacing_new (int spacing)
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 05247339..6dacf398 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -68,6 +68,7 @@ struct _PangoLayout
PangoAttrList *attrs;
PangoFontDescription *font_desc;
float line_height;
+ int spacing;
int width;
int height;
PangoTabArray *tabs;
@@ -95,6 +96,7 @@ enum
PROP_ATTRIBUTES,
PROP_FONT_DESCRIPTION,
PROP_LINE_HEIGHT,
+ PROP_SPACING,
PROP_WIDTH,
PROP_HEIGHT,
PROP_TABS,
@@ -123,6 +125,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;
@@ -174,6 +177,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;
@@ -246,6 +253,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;
@@ -353,6 +364,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)
*
@@ -561,6 +585,13 @@ get_effective_attributes (PangoLayout *layout)
pango_attr_line_height_new (layout->line_height));
}
+ if (layout->spacing != 0)
+ {
+ attrs = ensure_attrs (layout, attrs);
+ pango_attr_list_insert_before (attrs,
+ pango_attr_line_spacing_new (layout->spacing));
+ }
+
if (layout->single_paragraph)
{
attrs = ensure_attrs (layout, attrs);
@@ -803,6 +834,7 @@ pango_layout_copy (PangoLayout *layout)
if (layout->font_desc)
copy->font_desc = pango_font_description_copy (layout->font_desc);
copy->line_height = layout->line_height;
+ copy->spacing = layout->spacing;
copy->width = layout->width;
copy->height = layout->height;
if (layout->tabs)
@@ -1067,11 +1099,58 @@ pango_layout_get_line_height (PangoLayout *layout)
return layout->line_height;
}
+/**
+ * pango_layout_set_spacing:
+ * @layout: a `PangoLayout`
+ * @spacing: the amount of spacing, in Pango units
+ *
+ * Sets the amount of spacing 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`.
* @width: the desired width in Pango units, or -1 to indicate that no
- * wrapping or ellipsization should be performed.
+ * wrapping or ellipsization should be performed
*
* Sets the width to which the lines of the layout should
* be wrapped or ellipsized.
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 1a30b68c..95a2f302 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);
diff --git a/pango/serializer.c b/pango/serializer.c
index ba387d5d..92b05063 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -828,6 +828,9 @@ layout_to_json (GtkJsonPrinter *printer,
if (pango_layout_get_line_height (layout) != 0.)
gtk_json_printer_add_number (printer, "line-height", pango_layout_get_line_height (layout));
+ if (pango_layout_get_spacing (layout) != 0)
+ gtk_json_printer_add_integer (printer, "spacing", pango_layout_get_spacing (layout));
+
if (flags & PANGO_LAYOUT_SERIALIZE_OUTPUT)
{
const PangoLogAttr *log_attrs;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]