[pango/pango2: 91/201] Add a line spacing attribute




commit f80c9dacb39b62dcd254b52647d4b785fca9f9b0
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 | 29 +++++++++++++++++++++++++++++
 pango/pango-attributes.h |  5 +++++
 2 files changed, 34 insertions(+)
---
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 18232367..055c3948 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1549,6 +1549,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
@@ -1613,6 +1637,7 @@ pango_attribute_as_int (PangoAttribute *attr)
     case PANGO_ATTR_INSERT_HYPHENS:
     case PANGO_ATTR_OVERLINE:
     case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
+    case PANGO_ATTR_LINE_SPACING:
     case PANGO_ATTR_TEXT_TRANSFORM:
     case PANGO_ATTR_WORD:
     case PANGO_ATTR_SENTENCE:
@@ -3053,6 +3078,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]