summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--pango/pango-attributes.c81
-rw-r--r--pango/pango-attributes.h5
3 files changed, 87 insertions, 0 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 3b70e980..11aabcae 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -425,6 +425,7 @@ pango_attr_list_insert_before
pango_attr_list_change
pango_attr_list_splice
pango_attr_list_filter
+pango_attr_list_update
PangoAttrFilterFunc
pango_attr_list_get_attributes
pango_attr_list_get_iterator
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index ac27251d..17549ffd 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1599,6 +1599,87 @@ pango_attr_list_change (PangoAttrList *list,
}
/**
+ * pango_attr_list_update:
+ * @list: a #PangoAttrList
+ * @pos: the position of the change
+ * @remove: the number of removed bytes
+ * @add: the number of added bytes
+ *
+ * Update indices of attributes in @list for
+ * a change in the text they refer to.
+ *
+ * The change that this function applies is
+ * removing @remove bytes at position @pos
+ * and inserting @add bytes instead.
+ *
+ * Attributes that fall entirely in the
+ * (@pos, @pos + @remove) range are removed.
+ *
+ * Attributes that start or end inside the
+ * (@pos, @pos + @remove) range are shortened to
+ * reflect the removal.
+ *
+ * Attributes start and end positions are updated
+ * if they are behind @pos + @remove.
+ *
+ * Since: 1.44
+ */
+void
+pango_attr_list_update (PangoAttrList *list,
+ int pos,
+ int remove,
+ int add)
+{
+ GSList *l, *prev, *next;
+
+ prev = NULL;
+ l = list->attributes;
+ while (l)
+ {
+ next = l->next;
+ PangoAttribute *attr = l->data;
+
+ if (attr->start_index >= pos &&
+ attr->end_index < pos + remove)
+ {
+ pango_attribute_destroy (attr);
+ if (prev == NULL)
+ list->attributes = next;
+ else
+ prev->next = next;
+
+ g_slist_free_1 (l);
+ }
+ else
+ {
+ prev = l;
+
+ 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)
+ {
+ attr->end_index += add - remove;
+ }
+ }
+
+ l = next;
+ }
+}
+
+/**
* pango_attr_list_splice:
* @list: a #PangoAttrList
* @other: another #PangoAttrList
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index 1f43c27f..6f021c06 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -547,6 +547,11 @@ void pango_attr_list_splice (PangoAttrList *list,
PangoAttrList *other,
gint pos,
gint len);
+PANGO_AVAILABLE_IN_1_44
+void pango_attr_list_update (PangoAttrList *list,
+ int pos,
+ int remove,
+ int add);
PANGO_AVAILABLE_IN_1_2
PangoAttrList *pango_attr_list_filter (PangoAttrList *list,