summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-11 11:31:43 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-11 15:19:17 -0400
commit4315d4f49b054e8d322fe87845bc3843f7523835 (patch)
tree5f4f544542319d1126ea58b80d3b8f3a4938aed0
parente445b8978ea73ab60f5462af4403987d73300a1f (diff)
downloadpango-4315d4f49b054e8d322fe87845bc3843f7523835.tar.gz
Add pango_item_apply_attrs
This adds attrs that are overlapping the range of the item to the extra_attrs in the analysis.
-rw-r--r--pango/pango-item.c45
-rw-r--r--pango/pango-item.h4
2 files changed, 49 insertions, 0 deletions
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 8c368874..787fb65e 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -153,3 +153,48 @@ pango_item_split (PangoItem *orig,
return new_item;
}
+
+static int
+compare_attr (gconstpointer p1, gconstpointer p2)
+{
+ if (pango_attribute_equal ((PangoAttribute *)p1, (PangoAttribute *)p2))
+ return 0;
+
+ return 1;
+}
+
+void
+pango_item_apply_attrs (PangoItem *item,
+ PangoAttrIterator *iter)
+{
+ int start, end;
+ GSList *attrs = NULL;
+
+ do
+ {
+ pango_attr_iterator_range (iter, &start, &end);
+
+ if (start >= item->offset + item->length)
+ break;
+
+ if (end >= item->offset)
+ {
+ GSList *list, *l;
+
+ list = pango_attr_iterator_get_attrs (iter);
+ for (l = list; l; l = l->next)
+ {
+ if (!g_slist_find_custom (attrs, l->data, compare_attr))
+
+ attrs = g_slist_prepend (attrs, pango_attribute_copy (l->data));
+ }
+ g_slist_free_full (list, (GDestroyNotify)pango_attribute_destroy);
+ }
+
+ if (end >= item->offset + item->length)
+ break;
+ }
+ while (pango_attr_iterator_next (iter));
+
+ item->analysis.extra_attrs = g_slist_concat (item->analysis.extra_attrs, attrs);
+}
diff --git a/pango/pango-item.h b/pango/pango-item.h
index cb6a7ed3..2d7e58a1 100644
--- a/pango/pango-item.h
+++ b/pango/pango-item.h
@@ -23,6 +23,7 @@
#define __PANGO_ITEM_H__
#include <pango/pango-types.h>
+#include <pango/pango-attributes.h>
G_BEGIN_DECLS
@@ -112,6 +113,9 @@ PANGO_AVAILABLE_IN_ALL
PangoItem *pango_item_split (PangoItem *orig,
int split_index,
int split_offset);
+PANGO_AVAILABLE_IN_1_44
+void pango_item_apply_attrs (PangoItem *item,
+ PangoAttrIterator *iter);
G_END_DECLS