diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-02-16 22:05:43 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-02-16 22:05:43 +0000 |
commit | 7f846326d416e9ab3eadca9f02b9a0129095f30b (patch) | |
tree | 4b2812b858cd830ca1282e3697d029ca347df24a /pango/pango-attributes.c | |
parent | 4f335d6e4a3f5b4e6ddd1cd78f919aa80c990262 (diff) | |
download | pango-7f846326d416e9ab3eadca9f02b9a0129095f30b.tar.gz |
Make refcounted.
Wed Feb 16 16:39:46 2000 Owen Taylor <otaylor@redhat.com>
* libpango/pango-coverage.c (pango_coverage_get): Make refcounted.
* libpango/modules.c (struct _PangoEnginePair): Since we don't
currently unload engines, cache loaded engines. (Not really
quite satisfactory, but should work OK)
* libpango/pango-context.c (pango_context_get_font_description):
Added a global font description.
* libpango/modules.c (_pango_find_map): Allow NULL
language tags.
* libpango/pango-context.c (pango_itemize) examples/viewer.c:
Switch itemize over to take a PangoAttrList.
* examples/viewer.c: Conform to changes in itemization interface
* libpango/font.[ch]: Add a compare function for FontDescription
* libpango/pango-attributes.[ch]: Change the iteration iterface
to be more convenient.
* libpango/pango-context.[ch]: Add the ability to set a default font.
* libpango/pango-context.[ch]: Take the font for itemization from
the attributes on the text.
* libpango/pangox.c: Cache currently loaded fonts, and cache
coverages.
Diffstat (limited to 'pango/pango-attributes.c')
-rw-r--r-- | pango/pango-attributes.c | 107 |
1 files changed, 60 insertions, 47 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 35f353db..cdbbbbbb 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -32,6 +32,8 @@ struct _PangoAttrIterator { GSList *next_attribute; GList *attribute_stack; + int start_index; + int end_index; }; static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass, @@ -550,6 +552,8 @@ pango_attr_list_unref (PangoAttrList *list) } g_slist_free (list->attributes); + + g_free (list); } } @@ -726,22 +730,42 @@ pango_attr_list_change (PangoAttrList *list, PangoAttrIterator * pango_attr_list_get_iterator (PangoAttrList *list) { - PangoAttrIterator *result; + PangoAttrIterator *iterator; g_return_val_if_fail (list != NULL, NULL); - result = g_new (PangoAttrIterator, 1); - result->next_attribute = list->attributes; - result->attribute_stack = NULL; + iterator = g_new (PangoAttrIterator, 1); + iterator->next_attribute = list->attributes; + iterator->attribute_stack = NULL; - while (result->next_attribute && - ((PangoAttribute *)result->next_attribute->data)->start_index == 0) - { - result->attribute_stack = g_list_prepend (result->attribute_stack, result->next_attribute->data); - result->next_attribute = result->next_attribute->next; - } + iterator->start_index = 0; + iterator->end_index = 0; - return result; + if (!pango_attr_iterator_next (iterator)) + iterator->end_index = G_MAXINT; + + return iterator; +} + +/** + * pango_attr_iterator_range: + * @iterator: a #PangoAttrIterator + * @start: location to store the start of the range + * @end: location to store the end of the range + * + * Get the range of the current segment. + **/ +void +pango_attr_iterator_range (PangoAttrIterator *iterator, + gint *start, + gint *end) +{ + g_return_if_fail (iterator != NULL); + + if (start) + *start = iterator->start_index; + if (end) + *end = iterator->end_index; } /** @@ -750,63 +774,52 @@ pango_attr_list_get_iterator (PangoAttrList *list) * * Advance the iterator until the next change of style. * - * Return value: the index of the next change of position, or -1 if iterator - * is at the end of the list. + * Return value: %FALSE if the iterator is at the end of the list, otherwise %TRUE **/ -int +gboolean pango_attr_iterator_next (PangoAttrIterator *iterator) { - int next_index = G_MAXINT; GList *tmp_list; g_return_val_if_fail (iterator != NULL, -1); if (!iterator->next_attribute && !iterator->attribute_stack) - return -1; - - tmp_list = iterator->attribute_stack; - while (tmp_list) - { - PangoAttribute *attr = tmp_list->data; - if (attr->end_index < next_index) - next_index = attr->end_index; - } + return FALSE; - tmp_list = iterator->attribute_stack; + iterator->start_index = iterator->end_index; + iterator->end_index = G_MAXINT; - if (iterator->next_attribute) - { - int next_start = ((PangoAttribute *)iterator->next_attribute->data)->start_index; - - if (next_start <= next_index) - { - do - { - iterator->attribute_stack = g_list_prepend (iterator->attribute_stack, iterator->next_attribute->data); - iterator->next_attribute = iterator->next_attribute->next; - } - while (iterator->next_attribute && - ((PangoAttribute *)iterator->next_attribute->data)->start_index == next_start); - } - - if (next_start < next_index) - return next_start; - } - + tmp_list = iterator->attribute_stack; while (tmp_list) { GList *next = tmp_list->next; + PangoAttribute *attr = tmp_list->data; - if (((PangoAttribute *)tmp_list->data)->start_index == next_index) + if (attr->end_index == iterator->start_index) { iterator->attribute_stack = g_list_remove_link (iterator->attribute_stack, tmp_list); g_list_free_1 (tmp_list); } + else + { + iterator->end_index = MIN (iterator->end_index, attr->end_index); + } tmp_list = next; } - - return next_index; + + while (iterator->next_attribute && + ((PangoAttribute *)iterator->next_attribute->data)->start_index == iterator->start_index) + { + iterator->attribute_stack = g_list_prepend (iterator->attribute_stack, iterator->next_attribute->data); + iterator->end_index = MIN (iterator->end_index, ((PangoAttribute *)iterator->next_attribute->data)->end_index); + iterator->next_attribute = iterator->next_attribute->next; + } + + if (iterator->next_attribute) + iterator->end_index = MIN (iterator->end_index, ((PangoAttribute *)iterator->next_attribute->data)->start_index); + + return TRUE; } /** |