diff options
Diffstat (limited to 'pango/pango-attributes.c')
-rw-r--r-- | pango/pango-attributes.c | 151 |
1 files changed, 77 insertions, 74 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 1fa8c399..4f96135b 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1253,7 +1253,7 @@ pango_attr_show_new (PangoShowFlags flags) * Return value: (transfer full): the newly allocated #PangoAttribute, * which should be freed with pango_attribute_destroy(). * - * Since: 1.45 + * Since: 1.46 **/ PangoAttribute * pango_attr_overline_new (PangoOverline overline) @@ -1281,7 +1281,7 @@ pango_attr_overline_new (PangoOverline overline) * Return value: (transfer full): the newly allocated #PangoAttribute, * which should be freed with pango_attribute_destroy(). * - * Since: 1.45 + * Since: 1.46 **/ PangoAttribute * pango_attr_overline_color_new (guint16 red, @@ -1523,11 +1523,12 @@ pango_attr_list_insert_before (PangoAttrList *list, **/ void pango_attr_list_change (PangoAttrList *list, - PangoAttribute *attr) + PangoAttribute *attr) { guint i, p; guint start_index = attr->start_index; guint end_index = attr->end_index; + gboolean inserted; g_return_if_fail (list != NULL); @@ -1543,6 +1544,7 @@ pango_attr_list_change (PangoAttrList *list, return; } + inserted = FALSE; for (i = 0, p = list->attributes->len; i < p; i++) { PangoAttribute *tmp_attr = g_ptr_array_index (list->attributes, i); @@ -1550,6 +1552,7 @@ pango_attr_list_change (PangoAttrList *list, if (tmp_attr->start_index > start_index) { g_ptr_array_insert (list->attributes, i, attr); + inserted = TRUE; break; } @@ -1559,8 +1562,8 @@ pango_attr_list_change (PangoAttrList *list, if (tmp_attr->end_index < start_index) continue; /* This attr does not overlap with the new one */ + g_assert (tmp_attr->start_index <= start_index); g_assert (tmp_attr->end_index >= start_index); - g_assert (start_index <= tmp_attr->end_index); if (pango_attribute_equal (tmp_attr, attr)) { @@ -1579,21 +1582,22 @@ pango_attr_list_change (PangoAttrList *list, pango_attribute_destroy (attr); attr = tmp_attr; + inserted = TRUE; break; } else { /* Split, truncate, or remove the old attribute */ - if (tmp_attr->end_index > attr->end_index) + if (tmp_attr->end_index > end_index) { PangoAttribute *end_attr = pango_attribute_copy (tmp_attr); - end_attr->start_index = attr->end_index; + end_attr->start_index = end_index; pango_attr_list_insert (list, end_attr); } - if (tmp_attr->start_index == attr->start_index) + if (tmp_attr->start_index == start_index) { pango_attribute_destroy (tmp_attr); g_ptr_array_remove_index (list->attributes, i); @@ -1601,12 +1605,12 @@ pango_attr_list_change (PangoAttrList *list, } else { - tmp_attr->end_index = attr->start_index; + tmp_attr->end_index = start_index; } } } - if (i == p) + if (!inserted) { /* we didn't insert attr yet */ pango_attr_list_insert (list, attr); @@ -1693,40 +1697,41 @@ pango_attr_list_update (PangoAttrList *list, { guint i, p; - for (i = 0, p = list->attributes->len; i < p; i++) - { - PangoAttribute *attr = g_ptr_array_index (list->attributes, i); - - if (attr->start_index >= pos && - attr->end_index < pos + remove) - { - pango_attribute_destroy (attr); - g_ptr_array_remove_index (list->attributes, i); - i--; /* Look at this index again */ - p--; - continue; - } - - 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 (list->attributes) + for (i = 0, p = list->attributes->len; i < p; i++) + { + PangoAttribute *attr = g_ptr_array_index (list->attributes, i); - if (attr->end_index >= pos && + if (attr->start_index >= pos && attr->end_index < pos + remove) - { - attr->end_index = pos; - } - else if (attr->end_index >= pos + remove) - { - attr->end_index += add - remove; - } - } + { + pango_attribute_destroy (attr); + g_ptr_array_remove_index (list->attributes, i); + i--; /* Look at this index again */ + p--; + continue; + } + + 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; + } + } } /** @@ -1771,26 +1776,27 @@ pango_attr_list_splice (PangoAttrList *list, */ #define CLAMP_ADD(a,b) (((a) + (b) < (a)) ? G_MAXUINT : (a) + (b)) - for (i = 0, p = list->attributes->len; i < p; i++) - { - PangoAttribute *attr = g_ptr_array_index (list->attributes, i);; - - if (attr->start_index <= upos) - { - if (attr->end_index > upos) - attr->end_index = CLAMP_ADD (attr->end_index, ulen); - } - else - { - /* This could result in a zero length attribute if it - * gets squashed up against G_MAXUINT, but deleting such - * an element could (in theory) suprise the caller, so - * we don't delete it. - */ - attr->start_index = CLAMP_ADD (attr->start_index, ulen); - attr->end_index = CLAMP_ADD (attr->end_index, ulen); - } - } + if (list->attributes) + for (i = 0, p = list->attributes->len; i < p; i++) + { + PangoAttribute *attr = g_ptr_array_index (list->attributes, i);; + + if (attr->start_index <= upos) + { + if (attr->end_index > upos) + attr->end_index = CLAMP_ADD (attr->end_index, ulen); + } + else + { + /* This could result in a zero length attribute if it + * gets squashed up against G_MAXUINT, but deleting such + * an element could (in theory) suprise the caller, so + * we don't delete it. + */ + attr->start_index = CLAMP_ADD (attr->start_index, ulen); + attr->end_index = CLAMP_ADD (attr->end_index, ulen); + } + } if (!other->attributes || other->attributes->len == 0) return; @@ -1862,6 +1868,7 @@ pango_attr_list_equal (PangoAttrList *list, { GPtrArray *attrs, *other_attrs; guint64 skip_bitmask = 0; + guint i; if (list == other_list) return TRUE; @@ -1878,12 +1885,13 @@ pango_attr_list_equal (PangoAttrList *list, if (attrs->len != other_attrs->len) return FALSE; - for (guint i = 0; i < attrs->len; i++) + for (i = 0; i < attrs->len; i++) { PangoAttribute *attr = g_ptr_array_index (attrs, i); gboolean attr_equal = FALSE; + guint other_attr_index; - for (guint other_attr_index = 0; other_attr_index < other_attrs->len; other_attr_index++) + for (other_attr_index = 0; other_attr_index < other_attrs->len; other_attr_index++) { PangoAttribute *other_attr = g_ptr_array_index (other_attrs, other_attr_index); guint64 other_attr_bitmask = other_attr_index < 64 ? 1 << other_attr_index : 0; @@ -1995,7 +2003,7 @@ pango_attr_iterator_range (PangoAttrIterator *iterator, gboolean pango_attr_iterator_next (PangoAttrIterator *iterator) { - guint i; + int i; g_return_val_if_fail (iterator != NULL, FALSE); @@ -2008,19 +2016,14 @@ pango_attr_iterator_next (PangoAttrIterator *iterator) if (iterator->attribute_stack) { - for (i = 0; i < iterator->attribute_stack->len; i++) + for (i = iterator->attribute_stack->len - 1; i>= 0; i--) { const PangoAttribute *attr = g_ptr_array_index (iterator->attribute_stack, i); if (attr->end_index == iterator->start_index) - { - g_ptr_array_remove_index (iterator->attribute_stack, i); /* Can't use index_fast :( */; - i--; - } + g_ptr_array_remove_index (iterator->attribute_stack, i); /* Can't use index_fast :( */ else - { - iterator->end_index = MIN (iterator->end_index, attr->end_index); - } + iterator->end_index = MIN (iterator->end_index, attr->end_index); } } @@ -2128,14 +2131,14 @@ PangoAttribute * pango_attr_iterator_get (PangoAttrIterator *iterator, PangoAttrType type) { - guint i; + int i; g_return_val_if_fail (iterator != NULL, NULL); if (!iterator->attribute_stack) return NULL; - for (i = 0; i < iterator->attribute_stack->len; i++) + for (i = iterator->attribute_stack->len - 1; i>= 0; i--) { PangoAttribute *attr = g_ptr_array_index (iterator->attribute_stack, i); |