diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-05-24 01:41:01 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-05-24 01:41:01 +0000 |
commit | 3dab00ded913500cf5953d33dca469ba4fb0ac81 (patch) | |
tree | 0198b538263298dd09d90bad5cbcc59a52477672 | |
parent | c40a071b47aff7f50cdf48fc94b63baa5f1c82f6 (diff) | |
parent | 6e363555a5ed76756a5bc8eb4914dc2e4af9c3b5 (diff) | |
download | pango-3dab00ded913500cf5953d33dca469ba4fb0ac81.tar.gz |
Merge branch 'more-attr-update-fixes' into 'master'
Explicitly preserve unlimited attributes
See merge request GNOME/pango!338
-rw-r--r-- | pango/pango-attributes.c | 42 | ||||
-rw-r--r-- | tests/testmisc.c | 10 |
2 files changed, 34 insertions, 18 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 8b4b2f7a..0d604f3d 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1760,28 +1760,34 @@ pango_attr_list_update (PangoAttrList *list, continue; } - if (attr->start_index >= pos && - attr->start_index < pos + remove) - { - attr->start_index = pos + add; - } - else if (attr->start_index >= pos + remove) + if (attr->start_index != PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING) { - attr->start_index += add - remove; + if (attr->start_index >= pos && + attr->start_index < pos + remove) + { + attr->start_index = pos + add; + } + else if (attr->start_index >= pos + remove) + { + attr->start_index += add - remove; + } } - if (attr->end_index >= pos && - attr->end_index < pos + remove) - { - attr->end_index = pos; - } - else if (attr->end_index >= pos + remove) + if (attr->end_index != PANGO_ATTR_INDEX_TO_TEXT_END) { - if (add > remove && - G_MAXUINT - attr->end_index < add - remove) - attr->end_index = G_MAXUINT; - else - attr->end_index += add - remove; + if (attr->end_index >= pos && + attr->end_index < pos + remove) + { + attr->end_index = pos; + } + else if (attr->end_index >= pos + remove) + { + if (add > remove && + G_MAXUINT - attr->end_index < add - remove) + attr->end_index = G_MAXUINT; + else + attr->end_index += add - remove; + } } } } diff --git a/tests/testmisc.c b/tests/testmisc.c index 0767eb7a..b4467a63 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -125,23 +125,33 @@ static void test_attr_list_update (void) { PangoAttribute *weight_attr; + PangoAttribute *fg_attr; PangoAttrList *list; weight_attr = pango_attr_weight_new (700); weight_attr->start_index = 4; weight_attr->end_index = 6; + fg_attr = pango_attr_foreground_new (0, 0, 65535); + fg_attr->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING; + fg_attr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END; + list = pango_attr_list_new(); pango_attr_list_insert (list, weight_attr); + pango_attr_list_insert (list, fg_attr); g_assert_cmpuint (weight_attr->start_index, ==, 4); g_assert_cmpuint (weight_attr->end_index, ==, 6); + g_assert_cmpuint (fg_attr->start_index, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING); + g_assert_cmpuint (fg_attr->end_index, ==, PANGO_ATTR_INDEX_TO_TEXT_END); // Delete 1 byte at position 2 pango_attr_list_update (list, 2, 1, 0); g_assert_cmpuint (weight_attr->start_index, ==, 3); g_assert_cmpuint (weight_attr->end_index, ==, 5); + g_assert_cmpuint (fg_attr->start_index, ==, PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING); + g_assert_cmpuint (fg_attr->end_index, ==, PANGO_ATTR_INDEX_TO_TEXT_END); pango_attr_list_unref (list); } |