summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-01-07 21:26:14 -0500
committerMatthias Clasen <mclasen@redhat.com>2022-01-09 23:39:32 -0500
commit703b471929ef56da609644c5a631f08d949711f8 (patch)
tree6b6c0b8895f3bb1ca271616a98b7c5c102848c42
parentbe198b0875a92238e3b7d5a208bfb5db15be44ae (diff)
downloadpango-703b471929ef56da609644c5a631f08d949711f8.tar.gz
Reinstate previous behavior or pango_attr_list_splice
If gap is zero, don't limit the inserted attributes; that does not make sense. Spell out the different use cases in the docs. Testcase included. Fixes: #607
-rw-r--r--pango/pango-attributes.c20
-rw-r--r--tests/testattributes.c18
2 files changed, 35 insertions, 3 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index e0272d0d..311c63ea 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1810,10 +1810,16 @@ pango_attr_list_update (PangoAttrList *list,
* that applies at position @pos in @list by an amount @len,
* and then calling [method@Pango.AttrList.change] with a copy
* of each attribute in @other in sequence (offset in position
- * by @pos, and limited in lengh to @len).
+ * by @pos, and limited in length to @len).
*
* This operation proves useful for, for instance, inserting
* a pre-edit string in the middle of an edit buffer.
+ *
+ * For backwards compatibility, the function behaves differently
+ * when @len is 0. In this case, the attributes from @other are
+ * not imited to @len, and are just overlayed on top of @list.
+ *
+ * This mode is useful for merging two lists of attributes together.
*/
void
pango_attr_list_splice (PangoAttrList *list,
@@ -1868,8 +1874,16 @@ pango_attr_list_splice (PangoAttrList *list,
for (i = 0, p = other->attributes->len; i < p; i++)
{
PangoAttribute *attr = pango_attribute_copy (g_ptr_array_index (other->attributes, i));
- attr->start_index = MIN (CLAMP_ADD (attr->start_index, upos), end);
- attr->end_index = MIN (CLAMP_ADD (attr->end_index, upos), end);
+ if (ulen > 0)
+ {
+ attr->start_index = MIN (CLAMP_ADD (attr->start_index, upos), end);
+ attr->end_index = MIN (CLAMP_ADD (attr->end_index, upos), end);
+ }
+ else
+ {
+ attr->start_index = CLAMP_ADD (attr->start_index, upos);
+ attr->end_index = CLAMP_ADD (attr->end_index, upos);
+ }
/* Same as above, the attribute could be squashed to zero-length; here
* pango_attr_list_change() will take care of deleting it.
diff --git a/tests/testattributes.c b/tests/testattributes.c
index aaf270f5..7f0d8bf3 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -1202,6 +1202,23 @@ test_iter_epsilon_zero (void)
g_string_free (s, TRUE);
}
+static void
+test_gnumeric_splice (void)
+{
+ PangoAttrList *list, *list2;
+
+ list = pango_attr_list_from_string ("0 -1 font-desc \"Sans 10\"\n");
+ list2 = pango_attr_list_from_string ("1 2 weight bold\n");
+
+ pango_attr_list_splice (list, list2, 0, 0);
+
+ assert_attr_list (list, "0 4294967295 font-desc \"Sans 10\"\n"
+ "1 2 weight bold\n");
+
+ pango_attr_list_unref (list);
+ pango_attr_list_unref (list2);
+}
+
int
main (int argc, char *argv[])
{
@@ -1240,6 +1257,7 @@ main (int argc, char *argv[])
g_test_add_func ("/attributes/iter/get_font", test_iter_get_font);
g_test_add_func ("/attributes/iter/get_attrs", test_iter_get_attrs);
g_test_add_func ("/attributes/iter/epsilon_zero", test_iter_epsilon_zero);
+ g_test_add_func ("/attributes/gnumeric-splice", test_gnumeric_splice);
return g_test_run ();
}