[pango/log-attr-tweaks: 34/35] layout: Make log attrs settable
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/log-attr-tweaks: 34/35] layout: Make log attrs settable
- Date: Thu, 26 Aug 2021 12:22:27 +0000 (UTC)
commit 0bd8bc300f838da4ba2fa01e2785bf3cf0865a4b
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 6b14a5dd..e5e4806e 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -324,6 +324,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));
@@ -1561,6 +1568,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 3b30a251..d492c795 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]