diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-21 01:22:27 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-26 08:22:17 -0400 |
commit | 0bd8bc300f838da4ba2fa01e2785bf3cf0865a4b (patch) | |
tree | 1febade7586cd43e86f7c76c906b264f8e81da53 /pango/pango-layout.c | |
parent | 801e93cfa39a450d28a35ad8a36f84faab19fd36 (diff) | |
download | pango-0bd8bc300f838da4ba2fa01e2785bf3cf0865a4b.tar.gz |
layout: Make log attrs settable
This lets users tweak log attrs.
Fixes: #33, #132
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r-- | pango/pango-layout.c | 39 |
1 files changed, 39 insertions, 0 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)); @@ -1562,6 +1569,38 @@ pango_layout_get_log_attrs (PangoLayout *layout, } /** + * 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` * @n_attrs: (out): location to store the number of the attributes in |