summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-13 23:04:02 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-13 23:05:29 -0400
commitc489cf77e64edc55bb583dc05352f3e24f0ae72c (patch)
treebbee112e01ee4fac8d054497b765f9ed9bc8e82a
parentc8212c485827cddd3c9a6a7c2a57e54d9254a10c (diff)
downloadpango-c489cf77e64edc55bb583dc05352f3e24f0ae72c.tar.gz
Add a function to update attribute lists
Add a function that can update positions of attributes as the underlying text is changing. This is meant to be used to update an attribute list as text transformations are applied, like capitalization.
-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,