[pango/log-attr-tweaks: 2/2] layout: Make log attrs settable




commit 83e7230b10072c67e30b5a433e5a0668235764c2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 21 01:22:27 2021 -0400

    layout: Make log attrs settable
    
    This lets users tweak log attrs.
    
    Fixes: #33, #132

 pango/pango-layout.c | 39 +++++++++++++++++++++++++++++++++++++++
 pango/pango-layout.h | 11 ++++++++---
 2 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 1f4fd782..9e86bcd5 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -322,6 +322,13 @@ pango_layout_copy (PangoLayout *src)
   /* Dupped */
   layout->text = g_strdup (src->text);
 
+  if (src->log_attrs)
+    {
+      layout->n_chars = src->n_chars;
+      layout->log_attrs = g_new (PangoLogAttr, src->n_chars + 1);
+      memcpy (layout->log_attrs, src->log_attrs, sizeof (PangoLogAttr) * (src->n_chars + 1));
+    }
+
   /* Value fields */
   memcpy (&layout->copy_begin, &src->copy_begin,
           G_STRUCT_OFFSET (PangoLayout, copy_end) - G_STRUCT_OFFSET (PangoLayout, copy_begin));
@@ -1559,6 +1566,38 @@ pango_layout_get_log_attrs (PangoLayout   *layout,
     *n_attrs = layout->n_chars + 1;
 }
 
+/**
+ * pango_layout_set_log_attrs:
+ * @layout: a `PangoLayout`
+ * @attrs: `PangoLogAttr` array to use
+ * @n_attrs: length of @attrs
+ *
+ * Sets logical attributes to use instead of the default ones.
+ *
+ * The expected use of this function is to call
+ * [method@Pango.Layout.get_log_attrs], tweak the attributes,
+ * and then call this function.
+ *
+ * Note that `PangoLayout` clears its logical attributes when
+ * either the text of attributes of @layout change, so tweaks
+ * will have to be re-applied after such a change.
+ *
+ * Since: 1.50
+ */
+void
+pango_layout_set_log_attrs (PangoLayout        *layout,
+                            const PangoLogAttr *attrs,
+                            int                 n_attrs)
+{
+  g_return_if_fail (layout->n_chars + 1 == n_attrs);
+
+  if (!layout->log_attrs)
+    layout->log_attrs = g_new (PangoLogAttr, layout->n_chars + 1);
+  memcpy (layout->log_attrs, attrs, sizeof (PangoLogAttr) * (layout->n_chars + 1));
+
+  layout_changed (layout);
+}
+
 /**
  * pango_layout_get_log_attrs_readonly:
  * @layout: a `PangoLayout`
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 9436dbcb..7b039be7 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -276,12 +276,17 @@ guint    pango_layout_get_serial      (PangoLayout    *layout);
 
 PANGO_AVAILABLE_IN_ALL
 void     pango_layout_get_log_attrs (PangoLayout    *layout,
-                                    PangoLogAttr  **attrs,
-                                    gint           *n_attrs);
+                                     PangoLogAttr  **attrs,
+                                     gint           *n_attrs);
 
 PANGO_AVAILABLE_IN_1_30
 const PangoLogAttr *pango_layout_get_log_attrs_readonly (PangoLayout *layout,
-                                                        gint        *n_attrs);
+                                                         gint        *n_attrs);
+
+PANGO_AVAILABLE_IN_1_50
+void     pango_layout_set_log_attrs (PangoLayout        *layout,
+                                     const PangoLogAttr *attrs,
+                                     int                 n_attrs);
 
 PANGO_AVAILABLE_IN_ALL
 void     pango_layout_index_to_pos         (PangoLayout    *layout,


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