diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-21 23:12:45 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-23 20:43:49 -0400 |
commit | 6bf91907514a3730ca0622adb72df94910f0f9fa (patch) | |
tree | 2becc126be7834e2a344140bfb999f2226309f2a | |
parent | c407656eab8777cfdbdf7f5109dba72795f7e996 (diff) | |
download | pango-6bf91907514a3730ca0622adb72df94910f0f9fa.tar.gz |
break: Add pango_attr_break api
So far, we've been applying attribute-based
customization while doing per-item tailoring.
But this is suboptimal, since it means we don't
have a full view of the log attrs, and can't
do invariant fixes that cross item boundaries.
Therefore, add a separate pango_attr_break
api that applies attributes to to the whole
paragraph, and make PangoLayout use it.
-rw-r--r-- | pango/break.c | 42 | ||||
-rw-r--r-- | pango/pango-break.h | 7 | ||||
-rw-r--r-- | pango/pango-layout.c | 22 |
3 files changed, 62 insertions, 9 deletions
diff --git a/pango/break.c b/pango/break.c index 271c8db7..c55d5f22 100644 --- a/pango/break.c +++ b/pango/break.c @@ -1729,6 +1729,8 @@ tailor_break (const char *text, * and can be %NULL. * * See [func@Pango.tailor_break] for language-specific breaks. + * + * See [func@Pango.attr_break] for attribute-based customization. */ void pango_default_break (const char *text, @@ -1754,8 +1756,8 @@ pango_default_break (const char *text, * For most purposes you may want to use * [func@Pango.get_log_attrs]. * - * Deprecated: 1.44: Use [func@Pango.default_break] and - * [func@Pango.tailor_break] + * Deprecated: 1.44: Use [func@Pango.default_break], + * [func@Pango.tailor_break] and func@Pango.attr_break]. */ void pango_break (const char *text, @@ -1790,6 +1792,10 @@ pango_break (const char *text, * If @offset is not -1, it is used to apply attributes * from @analysis that are relevant to line breaking. * + * Note that it is better to pass -1 for @offset and + * use [func@Pango.attr_break] to apply attributes to + * the whole paragraph. + * * Since: 1.44 */ void @@ -1818,6 +1824,38 @@ pango_tailor_break (const char *text, } /** + * pango_attr_break: + * @text: text to break. Must be valid UTF-8 + * @length: length of text in bytes (may be -1 if @text is nul-terminated) + * @attr_list: `PangoAttrList` to apply + * @offset: Byte offset of @text from the beginning of the paragraph + * @attrs: (array length=attrs_len): array with one `PangoLogAttr` + * per character in @text, plus one extra, to be filled in + * @attrs_len: length of @attrs array + * + * Apply customization from attributes to the breaks in @attrs. + * + * The line breaks are assumed to have been produced + * by [func@Pango.default_break] and [func@Pango.tailor_break]. + * + * Since: 1.50 + */ +void +pango_attr_break (const char *text, + int length, + PangoAttrList *attr_list, + int offset, + PangoLogAttr *attrs, + int attrs_len) +{ + GSList *attributes; + + attributes = pango_attr_list_get_attributes (attr_list); + break_attrs (text, length, attributes, offset, attrs, attrs_len); + g_slist_free_full (attributes, (GDestroyNotify)pango_attribute_destroy); +} + +/** * pango_get_log_attrs: * @text: text to process. Must be valid UTF-8 * @length: length in bytes of @text diff --git a/pango/pango-break.h b/pango/pango-break.h index f514d168..a8e6c5b9 100644 --- a/pango/pango-break.h +++ b/pango/pango-break.h @@ -123,6 +123,13 @@ void pango_tailor_break (const char *text, PangoLogAttr *attrs, int attrs_len); +PANGO_AVAILABLE_IN_1_50 +void pango_attr_break (const char *text, + int length, + PangoAttrList *attr_list, + int offset, + PangoLogAttr *attrs, + int attrs_len); G_END_DECLS diff --git a/pango/pango-layout.c b/pango/pango-layout.c index f78d7daf..b6e0c217 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -4214,12 +4214,13 @@ process_line (PangoLayout *layout, } static void -get_items_log_attrs (const char *text, - int start, - int length, - GList *items, - PangoLogAttr *log_attrs, - int log_attrs_len) +get_items_log_attrs (const char *text, + int start, + int length, + GList *items, + PangoAttrList *attrs, + PangoLogAttr *log_attrs, + int log_attrs_len) { int offset = 0; GList *l; @@ -4235,12 +4236,18 @@ get_items_log_attrs (const char *text, pango_tailor_break (text + item->offset, item->length, &item->analysis, - item->offset, + -1, log_attrs + offset, item->num_chars + 1); offset += item->num_chars; } + + if (attrs && items) + { + PangoItem *item = items->data; + pango_attr_break (text + start, length, attrs, item->offset, log_attrs, log_attrs_len); + } } static PangoAttrList * @@ -4517,6 +4524,7 @@ pango_layout_check_lines (PangoLayout *layout) start - layout->text, delimiter_index + delim_len, state.items, + shape_attrs, layout->log_attrs + start_offset, layout->n_chars + 1 - start_offset); |