summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-06-08 17:41:58 +0000
committerMatthias Clasen <mclasen@redhat.com>2020-06-08 17:41:58 +0000
commit8175bfe7ebbdd885cfdab857783aa2e5f7c136e4 (patch)
tree7d358946ca78f9fd242aeed26c44a1fbb2e47982
parent1fb9e50c73bb8c6389c7eaa9adb2eee13642d2ff (diff)
parent4d8e71471984fb0fc147d1a64695ad5f18576fde (diff)
downloadpango-8175bfe7ebbdd885cfdab857783aa2e5f7c136e4.tar.gz
Merge branch 'wip/baedert/for-master2' into 'master'
Wip/baedert/for master2 See merge request GNOME/pango!190
-rw-r--r--pango/break.c30
-rw-r--r--pango/ellipsize.c15
-rw-r--r--pango/pango-attributes-private.h48
-rw-r--r--pango/pango-attributes.c96
-rw-r--r--pango/pango-glyph-item.c20
-rw-r--r--pango/pango-layout.c175
-rw-r--r--pango/pangocairo-context.c10
-rw-r--r--tests/layouts/valid-3.expected1
-rw-r--r--tests/layouts/valid-4.expected1
-rw-r--r--tests/test-common.c3
-rw-r--r--tests/testattributes.c11
11 files changed, 277 insertions, 133 deletions
diff --git a/pango/break.c b/pango/break.c
index 875d776c..58bf2f90 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -24,6 +24,7 @@
#include "pango-break.h"
#include "pango-script-private.h"
#include "pango-emoji-private.h"
+#include "pango-attributes-private.h"
#include "pango-break-table.h"
#include "pango-impl-utils.h"
#include <string.h>
@@ -1596,7 +1597,7 @@ tailor_break (const char *text,
res = break_script (text, length, analysis, attrs, attrs_len);
- if (item_offset >= 0)
+ if (item_offset >= 0 && analysis->extra_attrs)
res |= break_attrs (text, length, analysis->extra_attrs, item_offset, attrs, attrs_len);
return res;
@@ -1905,31 +1906,36 @@ break_attrs (const char *text,
PangoLogAttr *log_attrs,
int log_attrs_len)
{
- PangoAttrList *list;
- PangoAttrIterator *iter;
+ PangoAttrList list;
+ PangoAttrIterator iter;
GSList *l;
- list = pango_attr_list_new ();
+ _pango_attr_list_init (&list);
for (l = attributes; l; l = l->next)
{
PangoAttribute *attr = l->data;
if (attr->klass->type == PANGO_ATTR_ALLOW_BREAKS)
- pango_attr_list_insert (list, pango_attribute_copy (attr));
+ pango_attr_list_insert (&list, pango_attribute_copy (attr));
}
- iter = pango_attr_list_get_iterator (list);
+ if (!_pango_attr_list_has_attributes (&list))
+ {
+ _pango_attr_list_destroy (&list);
+ return FALSE;
+ }
+
+ _pango_attr_list_get_iterator (&list, &iter);
do {
- PangoAttribute *attr;
+ const PangoAttribute *attr = pango_attr_iterator_get (&iter, PANGO_ATTR_ALLOW_BREAKS);
- attr = pango_attr_iterator_get (iter, PANGO_ATTR_ALLOW_BREAKS);
if (attr && ((PangoAttrInt*)attr)->value == 0)
{
int start, end;
int start_pos, end_pos;
int pos;
- pango_attr_iterator_range (iter, &start, &end);
+ pango_attr_iterator_range (&iter, &start, &end);
if (start < offset)
start_pos = 0;
else
@@ -1946,10 +1952,10 @@ break_attrs (const char *text,
log_attrs[pos].is_char_break = FALSE;
}
}
- } while (pango_attr_iterator_next (iter));
+ } while (pango_attr_iterator_next (&iter));
- pango_attr_iterator_destroy (iter);
- pango_attr_list_unref (list);
+ _pango_attr_iterator_destroy (&iter);
+ _pango_attr_list_destroy (&list);
return TRUE;
}
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index 4b27025e..4eb98a1a 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -25,6 +25,7 @@
#include "pango-glyph-item.h"
#include "pango-layout-private.h"
#include "pango-font-private.h"
+#include "pango-attributes-private.h"
#include "pango-impl-utils.h"
typedef struct _EllipsizeState EllipsizeState;
@@ -299,7 +300,7 @@ itemize_text (EllipsizeState *state,
static void
shape_ellipsis (EllipsizeState *state)
{
- PangoAttrList *attrs = pango_attr_list_new ();
+ PangoAttrList attrs;
GSList *run_attrs;
PangoItem *item;
PangoGlyphString *glyphs;
@@ -309,6 +310,8 @@ shape_ellipsis (EllipsizeState *state)
int len;
int i;
+ _pango_attr_list_init (&attrs);
+
/* Create/reset state->ellipsis_run
*/
if (!state->ellipsis_run)
@@ -333,7 +336,7 @@ shape_ellipsis (EllipsizeState *state)
attr->start_index = 0;
attr->end_index = G_MAXINT;
- pango_attr_list_insert (attrs, attr);
+ pango_attr_list_insert (&attrs, attr);
}
g_slist_free (run_attrs);
@@ -341,7 +344,7 @@ shape_ellipsis (EllipsizeState *state)
fallback = pango_attr_fallback_new (FALSE);
fallback->start_index = 0;
fallback->end_index = G_MAXINT;
- pango_attr_list_insert (attrs, fallback);
+ pango_attr_list_insert (&attrs, fallback);
/* First try using a specific ellipsis character in the best matching font
*/
@@ -350,7 +353,7 @@ shape_ellipsis (EllipsizeState *state)
else
ellipsis_text = "\342\200\246"; /* U+2026: HORIZONTAL ELLIPSIS */
- item = itemize_text (state, ellipsis_text, attrs);
+ item = itemize_text (state, ellipsis_text, &attrs);
/* If that fails we use "..." in the first matching font
*/
@@ -365,10 +368,10 @@ shape_ellipsis (EllipsizeState *state)
((PangoAttrInt *)fallback)->value = TRUE;
ellipsis_text = "...";
- item = itemize_text (state, ellipsis_text, attrs);
+ item = itemize_text (state, ellipsis_text, &attrs);
}
- pango_attr_list_unref (attrs);
+ _pango_attr_list_destroy (&attrs);
state->ellipsis_run->item = item;
diff --git a/pango/pango-attributes-private.h b/pango/pango-attributes-private.h
new file mode 100644
index 00000000..b913cc2f
--- /dev/null
+++ b/pango/pango-attributes-private.h
@@ -0,0 +1,48 @@
+/* Pango
+ * pango-attributes-private.h: Internal structures of PangoLayout
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PANGO_ATTRIBUTES_PRIVATE_H__
+#define __PANGO_ATTRIBUTES_PRIVATE_H__
+
+struct _PangoAttrIterator
+{
+ GSList *next_attribute;
+ GList *attribute_stack;
+ guint start_index;
+ guint end_index;
+};
+
+struct _PangoAttrList
+{
+ guint ref_count;
+ GSList *attributes;
+ GSList *attributes_tail;
+};
+
+void _pango_attr_list_init (PangoAttrList *list);
+void _pango_attr_list_destroy (PangoAttrList *list);
+gboolean _pango_attr_list_has_attributes (const PangoAttrList *list);
+
+void _pango_attr_list_get_iterator (PangoAttrList *list,
+ PangoAttrIterator *iterator);
+
+void _pango_attr_iterator_destroy (PangoAttrIterator *iterator);
+
+
+#endif
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 03a45de4..97c7aeaf 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -34,23 +34,9 @@
#include <string.h>
#include "pango-attributes.h"
+#include "pango-attributes-private.h"
#include "pango-impl-utils.h"
-struct _PangoAttrList
-{
- guint ref_count;
- GSList *attributes;
- GSList *attributes_tail;
-};
-
-struct _PangoAttrIterator
-{
- GSList *next_attribute;
- GList *attribute_stack;
- guint start_index;
- guint end_index;
-};
-
static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass,
guint16 red,
guint16 green,
@@ -1320,6 +1306,14 @@ G_DEFINE_BOXED_TYPE (PangoAttrList, pango_attr_list,
pango_attr_list_copy,
pango_attr_list_unref);
+void
+_pango_attr_list_init (PangoAttrList *list)
+{
+ list->ref_count = 1;
+ list->attributes = NULL;
+ list->attributes_tail = NULL;
+}
+
/**
* pango_attr_list_new:
*
@@ -1333,9 +1327,7 @@ pango_attr_list_new (void)
{
PangoAttrList *list = g_slice_new (PangoAttrList);
- list->ref_count = 1;
- list->attributes = NULL;
- list->attributes_tail = NULL;
+ _pango_attr_list_init (list);
return list;
}
@@ -1361,6 +1353,23 @@ pango_attr_list_ref (PangoAttrList *list)
return list;
}
+void
+_pango_attr_list_destroy (PangoAttrList *list)
+{
+ GSList *tmp_list;
+
+ tmp_list = list->attributes;
+ while (tmp_list)
+ {
+ PangoAttribute *attr = tmp_list->data;
+ tmp_list = tmp_list->next;
+
+ attr->klass->destroy (attr);
+ }
+
+ g_slist_free (list->attributes);
+}
+
/**
* pango_attr_list_unref:
* @list: (nullable): a #PangoAttrList, may be %NULL
@@ -1372,8 +1381,6 @@ pango_attr_list_ref (PangoAttrList *list)
void
pango_attr_list_unref (PangoAttrList *list)
{
- GSList *tmp_list;
-
if (list == NULL)
return;
@@ -1381,17 +1388,7 @@ pango_attr_list_unref (PangoAttrList *list)
if (g_atomic_int_dec_and_test ((int *) &list->ref_count))
{
- tmp_list = list->attributes;
- while (tmp_list)
- {
- PangoAttribute *attr = tmp_list->data;
- tmp_list = tmp_list->next;
-
- attr->klass->destroy (attr);
- }
-
- g_slist_free (list->attributes);
-
+ _pango_attr_list_destroy (list);
g_slice_free (PangoAttrList, list);
}
}
@@ -1992,11 +1989,31 @@ pango_attr_list_equal (PangoAttrList *list,
return TRUE;
}
+gboolean
+_pango_attr_list_has_attributes (const PangoAttrList *list)
+{
+ return list && (list->attributes != NULL);
+}
+
G_DEFINE_BOXED_TYPE (PangoAttrIterator,
pango_attr_iterator,
pango_attr_iterator_copy,
pango_attr_iterator_destroy)
+void
+_pango_attr_list_get_iterator (PangoAttrList *list,
+ PangoAttrIterator *iterator)
+{
+ iterator->next_attribute = list->attributes;
+ iterator->attribute_stack = NULL;
+
+ iterator->start_index = 0;
+ iterator->end_index = 0;
+
+ if (!pango_attr_iterator_next (iterator))
+ iterator->end_index = G_MAXUINT;
+}
+
/**
* pango_attr_list_get_iterator:
* @list: a #PangoAttrList
@@ -2015,14 +2032,7 @@ pango_attr_list_get_iterator (PangoAttrList *list)
g_return_val_if_fail (list != NULL, NULL);
iterator = g_slice_new (PangoAttrIterator);
- iterator->next_attribute = list->attributes;
- iterator->attribute_stack = NULL;
-
- iterator->start_index = 0;
- iterator->end_index = 0;
-
- if (!pango_attr_iterator_next (iterator))
- iterator->end_index = G_MAXUINT;
+ _pango_attr_list_get_iterator (list, iterator);
return iterator;
}
@@ -2135,6 +2145,12 @@ pango_attr_iterator_copy (PangoAttrIterator *iterator)
return copy;
}
+void
+_pango_attr_iterator_destroy (PangoAttrIterator *iterator)
+{
+ g_list_free (iterator->attribute_stack);
+}
+
/**
* pango_attr_iterator_destroy:
* @iterator: a #PangoAttrIterator.
@@ -2146,7 +2162,7 @@ pango_attr_iterator_destroy (PangoAttrIterator *iterator)
{
g_return_if_fail (iterator != NULL);
- g_list_free (iterator->attribute_stack);
+ _pango_attr_iterator_destroy (iterator);
g_slice_free (PangoAttrIterator, iterator);
}
diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c
index eb880608..326ae37f 100644
--- a/pango/pango-glyph-item.c
+++ b/pango/pango-glyph-item.c
@@ -24,6 +24,7 @@
#include "pango-glyph-item.h"
#include "pango-impl-utils.h"
+#include "pango-attributes-private.h"
#define LTR(glyph_item) (((glyph_item)->item->analysis.level % 2) == 0)
@@ -584,7 +585,7 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
const char *text,
PangoAttrList *list)
{
- PangoAttrIterator *iter = pango_attr_list_get_iterator (list);
+ PangoAttrIterator iter;
GSList *result = NULL;
ApplyAttrsState state;
gboolean start_new_segment = FALSE;
@@ -607,15 +608,16 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
/* Advance the attr iterator to the start of the item
*/
+ _pango_attr_list_get_iterator (list, &iter);
do
{
- pango_attr_iterator_range (iter, &range_start, &range_end);
+ pango_attr_iterator_range (&iter, &range_start, &range_end);
if (range_end > glyph_item->item->offset)
break;
}
- while (pango_attr_iterator_next (iter));
+ while (pango_attr_iterator_next (&iter));
- state.segment_attrs = pango_attr_iterator_get_attrs (iter);
+ state.segment_attrs = pango_attr_iterator_get_attrs (&iter);
is_ellipsis = (glyph_item->item->analysis.flags & PANGO_ANALYSIS_FLAG_IS_ELLIPSIS) != 0;
@@ -644,7 +646,7 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
{
result = g_slist_prepend (result,
split_before_cluster_start (&state));
- state.segment_attrs = pango_attr_iterator_get_attrs (iter);
+ state.segment_attrs = pango_attr_iterator_get_attrs (&iter);
}
start_new_segment = FALSE;
@@ -663,8 +665,8 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
*/
start_new_segment = TRUE;
- have_next = pango_attr_iterator_next (iter);
- pango_attr_iterator_range (iter, &range_start, &range_end);
+ have_next = pango_attr_iterator_next (&iter);
+ pango_attr_iterator_range (&iter, &range_start, &range_end);
if (range_start >= state.iter.end_index) /* New range doesn't intersect this cluster */
{
@@ -688,7 +690,7 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
}
state.segment_attrs = g_slist_concat (state.segment_attrs,
- pango_attr_iterator_get_attrs (iter));
+ pango_attr_iterator_get_attrs (&iter));
}
while (have_next);
}
@@ -702,7 +704,7 @@ pango_glyph_item_apply_attrs (PangoGlyphItem *glyph_item,
if (LTR (glyph_item))
result = g_slist_reverse (result);
- pango_attr_iterator_destroy (iter);
+ _pango_attr_iterator_destroy (&iter);
return result;
}
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 643f5623..24444ed4 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -78,6 +78,7 @@
#include <string.h>
#include "pango-layout-private.h"
+#include "pango-attributes-private.h"
typedef struct _ItemProperties ItemProperties;
@@ -362,6 +363,11 @@ pango_layout_set_width (PangoLayout *layout,
if (width != layout->width)
{
layout->width = width;
+
+ /* Increasing the width can only decrease the line count */
+ if (layout->line_count == 1 && width > layout->width)
+ return;
+
layout_changed (layout);
}
}
@@ -673,11 +679,21 @@ pango_layout_get_line_spacing (PangoLayout *layout)
**/
void
pango_layout_set_attributes (PangoLayout *layout,
- PangoAttrList *attrs)
+ PangoAttrList *attrs)
{
PangoAttrList *old_attrs;
+
g_return_if_fail (layout != NULL);
+ /* Both empty */
+ if (!attrs && !layout->attrs)
+ return;
+
+ /* Also both empty */
+ if (!_pango_attr_list_has_attributes (layout->attrs) &&
+ !_pango_attr_list_has_attributes (attrs))
+ return;
+
old_attrs = layout->attrs;
/* We always clear lines such that this function can be called
@@ -701,7 +717,8 @@ pango_layout_set_attributes (PangoLayout *layout,
*
* Gets the attribute list for the layout, if any.
*
- * Return value: (transfer none): a #PangoAttrList.
+ * Return value: (transfer none) (nullable): a #PangoAttrList or %NULL
+ * if none was set.
**/
PangoAttrList*
pango_layout_get_attributes (PangoLayout *layout)
@@ -1114,15 +1131,22 @@ pango_layout_set_text (PangoLayout *layout,
old_text = layout->text;
if (length < 0)
- layout->text = g_strdup (text);
+ {
+ layout->length = strlen (text);
+ layout->text = g_strndup (text, layout->length);
+ }
else if (length > 0)
- /* This is not exactly what we want. We don't need the padding...
- */
- layout->text = g_strndup (text, length);
+ {
+ /* This is not exactly what we want. We don't need the padding...
+ */
+ layout->length = length;
+ layout->text = g_strndup (text, length);
+ }
else
- layout->text = g_malloc0 (1);
-
- layout->length = strlen (layout->text);
+ {
+ layout->length = 0;
+ layout->text = g_malloc0 (1);
+ }
/* validate it, and replace invalid bytes with -1 */
start = layout->text;
@@ -2924,7 +2948,8 @@ pango_layout_get_pixel_size (PangoLayout *layout,
{
PangoRectangle logical_rect;
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+ pango_layout_get_extents_internal (layout, NULL, &logical_rect, NULL);
+ pango_extents_to_pixels (&logical_rect, NULL);
if (width)
*width = logical_rect.width;
@@ -3057,8 +3082,8 @@ ensure_tab_width (PangoLayout *layout)
GList *items;
PangoAttribute *attr;
PangoAttrList *layout_attrs;
- PangoAttrList *tmp_attrs;
- PangoAttrIterator *iter;
+ PangoAttrList tmp_attrs;
+ PangoAttrIterator iter;
PangoFontDescription *font_desc = pango_font_description_copy_static (pango_context_get_font_description (layout->context));
PangoLanguage *language;
PangoShapeFlags shape_flags = PANGO_SHAPE_NONE;
@@ -3067,30 +3092,30 @@ ensure_tab_width (PangoLayout *layout)
shape_flags |= PANGO_SHAPE_ROUND_POSITIONS;
layout_attrs = pango_layout_get_effective_attributes (layout);
- iter = pango_attr_list_get_iterator (layout_attrs);
- pango_attr_iterator_get_font (iter, font_desc, &language, NULL);
+ _pango_attr_list_get_iterator (layout_attrs, &iter);
+ pango_attr_iterator_get_font (&iter, font_desc, &language, NULL);
- tmp_attrs = pango_attr_list_new ();
+ _pango_attr_list_init (&tmp_attrs);
attr = pango_attr_font_desc_new (font_desc);
pango_font_description_free (font_desc);
- pango_attr_list_insert_before (tmp_attrs, attr);
+ pango_attr_list_insert_before (&tmp_attrs, attr);
if (language)
{
attr = pango_attr_language_new (language);
- pango_attr_list_insert_before (tmp_attrs, attr);
+ pango_attr_list_insert_before (&tmp_attrs, attr);
}
- items = pango_itemize (layout->context, " ", 0, 1, tmp_attrs, NULL);
+ items = pango_itemize (layout->context, " ", 0, 1, &tmp_attrs, NULL);
- pango_attr_iterator_destroy (iter);
+ _pango_attr_iterator_destroy (&iter);
if (layout_attrs != layout->attrs)
{
pango_attr_list_unref (layout_attrs);
layout_attrs = NULL;
}
- pango_attr_list_unref (tmp_attrs);
+ _pango_attr_list_destroy (&tmp_attrs);
item = items->data;
pango_shape_with_flags (" ", 8, " ", 8, &item->analysis, glyphs, shape_flags);
@@ -3458,18 +3483,18 @@ get_need_hyphen (PangoItem *item,
const char *p;
gboolean prev_space;
gboolean prev_hyphen;
- PangoAttrList *attrs;
- PangoAttrIterator *iter;
+ PangoAttrList attrs;
+ PangoAttrIterator iter;
GSList *l;
- attrs = pango_attr_list_new ();
+ _pango_attr_list_init (&attrs);
for (l = item->analysis.extra_attrs; l; l = l->next)
{
PangoAttribute *attr = l->data;
if (attr->klass->type == PANGO_ATTR_INSERT_HYPHENS)
- pango_attr_list_change (attrs, pango_attribute_copy (attr));
+ pango_attr_list_change (&attrs, pango_attribute_copy (attr));
}
- iter = pango_attr_list_get_iterator (attrs);
+ _pango_attr_list_get_iterator (&attrs, &iter);
for (i = 0, p = text + item->offset; i < item->num_chars; i++, p = g_utf8_next_char (p))
{
@@ -3481,15 +3506,15 @@ get_need_hyphen (PangoItem *item,
pos = p - text;
do {
- pango_attr_iterator_range (iter, &start, &end);
+ pango_attr_iterator_range (&iter, &start, &end);
if (end > pos)
break;
- } while (pango_attr_iterator_next (iter));
+ } while (pango_attr_iterator_next (&iter));
if (start <= pos && pos < end)
{
PangoAttribute *attr;
- attr = pango_attr_iterator_get (iter, PANGO_ATTR_INSERT_HYPHENS);
+ attr = pango_attr_iterator_get (&iter, PANGO_ATTR_INSERT_HYPHENS);
if (attr)
insert_hyphens = ((PangoAttrInt*)attr)->value;
@@ -3554,8 +3579,8 @@ get_need_hyphen (PangoItem *item,
prev_hyphen = hyphen;
}
- pango_attr_iterator_destroy (iter);
- pango_attr_list_unref (attrs);
+ _pango_attr_iterator_destroy (&iter);
+ _pango_attr_list_destroy (&attrs);
}
static gboolean
@@ -4087,17 +4112,25 @@ pango_layout_get_effective_attributes (PangoLayout *layout)
if (layout->attrs)
attrs = pango_attr_list_copy (layout->attrs);
else
- attrs = pango_attr_list_new ();
+ attrs = NULL;
if (layout->font_desc)
{
PangoAttribute *attr = pango_attr_font_desc_new (layout->font_desc);
+
+ if (!attrs)
+ attrs = pango_attr_list_new ();
+
pango_attr_list_insert_before (attrs, attr);
}
if (layout->single_paragraph)
{
PangoAttribute *attr = pango_attr_show_new (PANGO_SHOW_LINE_BREAKS);
+
+ if (!attrs)
+ attrs = pango_attr_list_new ();
+
pango_attr_list_insert_before (attrs, attr);
}
@@ -4157,20 +4190,20 @@ apply_attributes_to_items (GList *items,
PangoAttrList *attrs)
{
GList *l;
- PangoAttrIterator *iter;
+ PangoAttrIterator iter;
if (!attrs)
return;
- iter = pango_attr_list_get_iterator (attrs);
+ _pango_attr_list_get_iterator (attrs, &iter);
for (l = items; l; l = l->next)
{
PangoItem *item = l->data;
- pango_item_apply_attrs (item, iter);
+ pango_item_apply_attrs (item, &iter);
}
- pango_attr_iterator_destroy (iter);
+ _pango_attr_iterator_destroy (&iter);
}
static void
@@ -4217,7 +4250,7 @@ pango_layout_check_lines (PangoLayout *layout)
PangoAttrList *attrs;
PangoAttrList *itemize_attrs;
PangoAttrList *shape_attrs;
- PangoAttrIterator *iter;
+ PangoAttrIterator iter;
PangoDirection prev_base_dir = PANGO_DIRECTION_NEUTRAL, base_dir = PANGO_DIRECTION_NEUTRAL;
ParaBreakState state;
@@ -4235,13 +4268,19 @@ pango_layout_check_lines (PangoLayout *layout)
pango_layout_set_text (layout, NULL, 0);
attrs = pango_layout_get_effective_attributes (layout);
+ if (attrs)
+ {
+ shape_attrs = pango_attr_list_filter (attrs, affects_break_or_shape, NULL);
+ itemize_attrs = pango_attr_list_filter (attrs, affects_itemization, NULL);
- shape_attrs = pango_attr_list_filter (attrs, affects_break_or_shape, NULL);
- itemize_attrs = pango_attr_list_filter (attrs, affects_itemization, NULL);
- if (itemize_attrs)
- iter = pango_attr_list_get_iterator (itemize_attrs);
+ if (itemize_attrs)
+ _pango_attr_list_get_iterator (itemize_attrs, &iter);
+ }
else
- iter = NULL;
+ {
+ shape_attrs = NULL;
+ itemize_attrs = NULL;
+ }
layout->log_attrs = g_new (PangoLogAttr, layout->n_chars + 1);
@@ -4319,7 +4358,7 @@ pango_layout_check_lines (PangoLayout *layout)
start - layout->text,
end - start,
itemize_attrs,
- iter);
+ itemize_attrs ? &iter : NULL);
apply_attributes_to_items (state.items, shape_attrs);
@@ -4376,17 +4415,14 @@ pango_layout_check_lines (PangoLayout *layout)
apply_attributes_to_runs (layout, attrs);
layout->lines = g_slist_reverse (layout->lines);
- if (iter)
- pango_attr_iterator_destroy (iter);
-
if (itemize_attrs)
- pango_attr_list_unref (itemize_attrs);
-
- if (shape_attrs)
- pango_attr_list_unref (shape_attrs);
+ {
+ pango_attr_list_unref (itemize_attrs);
+ _pango_attr_iterator_destroy (&iter);
+ }
- if (attrs)
- pango_attr_list_unref (attrs);
+ pango_attr_list_unref (shape_attrs);
+ pango_attr_list_unref (attrs);
}
#pragma GCC diagnostic pop
@@ -4840,12 +4876,14 @@ pango_layout_get_empty_extents_at_index (PangoLayout *layout,
*/
if (layout->attrs)
{
- PangoAttrIterator *iter = pango_attr_list_get_iterator (layout->attrs);
+ PangoAttrIterator iter;
int start, end;
+ _pango_attr_list_get_iterator (layout->attrs, &iter);
+
do
{
- pango_attr_iterator_range (iter, &start, &end);
+ pango_attr_iterator_range (&iter, &start, &end);
if (start <= index && index < end)
{
@@ -4855,7 +4893,7 @@ pango_layout_get_empty_extents_at_index (PangoLayout *layout,
free_font_desc = TRUE;
}
- pango_attr_iterator_get_font (iter,
+ pango_attr_iterator_get_font (&iter,
font_desc,
NULL,
NULL);
@@ -4864,9 +4902,9 @@ pango_layout_get_empty_extents_at_index (PangoLayout *layout,
}
}
- while (pango_attr_iterator_next (iter));
+ while (pango_attr_iterator_next (&iter));
- pango_attr_iterator_destroy (iter);
+ _pango_attr_iterator_destroy (&iter);
}
font = pango_context_load_font (layout->context, font_desc);
@@ -6182,7 +6220,6 @@ _pango_layout_get_iter (PangoLayout *layout,
PangoLayoutIter*iter)
{
int run_start_index;
- PangoRectangle logical_rect;
g_return_if_fail (PANGO_IS_LAYOUT (layout));
@@ -6206,11 +6243,25 @@ _pango_layout_get_iter (PangoLayout *layout,
iter->run = NULL;
iter->line_extents = NULL;
- pango_layout_get_extents_internal (layout,
- NULL,
- &logical_rect,
- &iter->line_extents);
- iter->layout_width = layout->width == -1 ? logical_rect.width : layout->width;
+
+ if (layout->width == -1)
+ {
+ PangoRectangle logical_rect;
+
+ pango_layout_get_extents_internal (layout,
+ NULL,
+ &logical_rect,
+ &iter->line_extents);
+ iter->layout_width = logical_rect.width;
+ }
+ else
+ {
+ pango_layout_get_extents_internal (layout,
+ NULL,
+ NULL,
+ &iter->line_extents);
+ iter->layout_width = layout->width;
+ }
iter->line_index = 0;
update_run (iter, run_start_index);
diff --git a/pango/pangocairo-context.c b/pango/pangocairo-context.c
index d2e66c4b..1b8bfbba 100644
--- a/pango/pangocairo-context.c
+++ b/pango/pangocairo-context.c
@@ -242,7 +242,15 @@ pango_cairo_context_set_font_options (PangoContext *context,
g_return_if_fail (PANGO_IS_CONTEXT (context));
- info = get_context_info (context, TRUE);
+ info = get_context_info (context, TRUE);
+
+ if (!info->set_options && !options)
+ return;
+
+ if (info->set_options &&
+ options &&
+ cairo_font_options_equal (info->set_options, options))
+ return;
if (info->set_options || options)
pango_context_changed (context);
diff --git a/tests/layouts/valid-3.expected b/tests/layouts/valid-3.expected
index 247c61bf..7f9d9e2f 100644
--- a/tests/layouts/valid-3.expected
+++ b/tests/layouts/valid-3.expected
@@ -8,7 +8,6 @@ lines: 2
--- attributes
-range 0 2147483647
--- lines
diff --git a/tests/layouts/valid-4.expected b/tests/layouts/valid-4.expected
index 09f143f3..dae4e065 100644
--- a/tests/layouts/valid-4.expected
+++ b/tests/layouts/valid-4.expected
@@ -9,7 +9,6 @@ width: 194560
--- attributes
-range 0 2147483647
--- lines
diff --git a/tests/test-common.c b/tests/test-common.c
index 608b405c..786973f1 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -151,6 +151,9 @@ print_attr_list (PangoAttrList *attrs, GString *string)
{
PangoAttrIterator *iter;
+ if (!attrs)
+ return;
+
iter = pango_attr_list_get_iterator (attrs);
do {
gint start, end;
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 9964f3d0..6b5e849b 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -100,7 +100,7 @@ assert_attributes (GSList *attrs,
s = g_string_new ("");
print_attributes (attrs, s);
g_assert_cmpstr (s->str, ==, expected);
- g_string_free (s, FALSE);
+ g_string_free (s, TRUE);
}
static void
@@ -358,6 +358,15 @@ test_iter (void)
PangoAttrIterator *copy;
gint start, end;
+ /* Empty list */
+ list = pango_attr_list_new ();
+ iter = pango_attr_list_get_iterator (list);
+
+ g_assert_false (pango_attr_iterator_next (iter));
+ g_assert_null (pango_attr_iterator_get_attrs (iter));
+ pango_attr_iterator_destroy (iter);
+ pango_attr_list_unref (list);
+
list = pango_attr_list_new ();
attr = pango_attr_size_new (10);
pango_attr_list_insert (list, attr);