[pango/line-breaker: 4/9] Add a line spacing attribute




commit 8e5c39e68d51aece5aaed69e748bdd46e13a3375
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 23 22:42:50 2022 -0500

    Add a line spacing attribute
    
    This will be used to restore the PangoLayout spacing
    property.

 pango/pango-attributes.c | 28 ++++++++++++++++++++++++++++
 pango/pango-attributes.h |  5 +++++
 2 files changed, 33 insertions(+)
---
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index faeb95b0..8f58fe6e 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1554,6 +1554,30 @@ pango_attr_line_height_new_absolute (int height)
   return pango_attr_int_new (&klass, height);
 }
 
+/**
+ * pango_attr_line_spacing_new:
+ * @spacing: the line spacing, in %PANGO_SCALE-ths of a point
+ *
+ * Spacing to be added to the leading from font metrics,
+ * if not overridden by line spacing attributes.
+ *
+ * This affects the values returned by
+ * [method@Pango.LayoutLine.get_extents],
+ * [method@Pango.LayoutIter.get_line_extents].
+ */
+PangoAttribute *
+pango_attr_line_spacing_new (int spacing)
+{
+  static const PangoAttrClass klass = {
+    PANGO_ATTR_LINE_SPACING,
+    pango_attr_int_copy,
+    pango_attr_int_destroy,
+    pango_attr_int_equal
+  };
+
+  return pango_attr_int_new (&klass, spacing);
+}
+
 /**
  * pango_attr_text_transform_new:
  * @transform: `PangoTextTransform` to apply
@@ -3046,6 +3070,10 @@ pango_attr_list_from_string (const char *text)
           FLOAT_ATTR(line_height);
           break;
 
+        case PANGO_ATTR_LINE_SPACING:
+          INT_ATTR(line_spacing, int);
+          break;
+
         case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
           integer = g_ascii_strtoll (p, &endp, 10);
           if (!is_valid_end_char (*endp)) goto fail;
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index 1f32714b..c16649c5 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -82,6 +82,8 @@ typedef struct _PangoAttrFontFeatures PangoAttrFontFeatures;
  * @PANGO_ATTR_PARAGRAPH: override segmentation to classify the range of the attribute as a single paragraph 
([struct@Pango.AttrInt]).
  * @PANGO_ATTR_BASELINE_SHIFT: baseline displacement ([struct@Pango.AttrInt]). Since 1.50
  * @PANGO_ATTR_FONT_SCALE: font-relative size change ([struct@Pango.AttrInt]). Since 1.50
+ * @PANGO_ATTR_LINE_SPACING: extra space to add to the leading from the font metrics (if
+ *   not overridden by line height attribute) ([struct@Pango.AttrInt])
  *
  * The `PangoAttrType` distinguishes between different types of attributes.
  *
@@ -131,6 +133,7 @@ typedef enum
   PANGO_ATTR_BASELINE_SHIFT,    /* PangoAttrSize */
   PANGO_ATTR_FONT_SCALE,        /* PangoAttrInt */
   PANGO_ATTR_PARAGRAPH,         /* PangoAttrInt */
+  PANGO_ATTR_LINE_SPACING,      /* PangoAttrInt */
 } PangoAttrType;
 
 /**
@@ -611,6 +614,8 @@ PANGO_AVAILABLE_IN_1_50
 PangoAttribute *        pango_attr_line_height_new              (double                       factor);
 PANGO_AVAILABLE_IN_1_50
 PangoAttribute *        pango_attr_line_height_new_absolute     (int                          height);
+PANGO_AVAILABLE_IN_ALL
+PangoAttribute *        pango_attr_line_spacing_new             (int                          spacing);
 PANGO_AVAILABLE_IN_1_50
 PangoAttribute *        pango_attr_text_transform_new           (PangoTextTransform transform);
 


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