summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--pango/pango-attributes.c42
-rw-r--r--pango/pango-attributes.h5
3 files changed, 48 insertions, 0 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 9bf20619..60d360d6 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -410,6 +410,7 @@ pango_attr_list_insert_before
pango_attr_list_change
pango_attr_list_splice
pango_attr_list_filter
+pango_attr_list_apply_delta
PangoAttrFilterFunc
pango_attr_list_get_iterator
PangoAttrIterator
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 85e5a240..f641e9ac 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1599,6 +1599,48 @@ pango_attr_list_change (PangoAttrList *list,
}
/**
+ * pango_attr_list_apply_delta:
+ * @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 start and end positions are updated
+ * if they are behind @pos + @remove. Positions
+ * that fall into the (@pos, @pos + @remove) range
+ * are not updated, since we don't know how the
+ * removed and added text affects them.
+ */
+void
+pango_attr_list_apply_delta (PangoAttrList *list,
+ int pos,
+ int remove,
+ int add)
+{
+ GSList *l;
+
+ for (l = list->attributes; l; l = l->next)
+ {
+ PangoAttribute *attr = l->data;
+
+ if (attr->end_index < pos)
+ continue;
+
+ if (attr->start_index >= pos + remove)
+ attr->start_index += add - remove;
+ if (attr->end_index >= pos + remove)
+ attr->end_index += add - remove;
+ }
+}
+
+/**
* pango_attr_list_splice:
* @list: a #PangoAttrList
* @other: another #PangoAttrList
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index cff495b2..b933bc11 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_apply_delta (PangoAttrList *list,
+ int pos,
+ int remove,
+ int add);
PANGO_AVAILABLE_IN_1_2
PangoAttrList *pango_attr_list_filter (PangoAttrList *list,