summaryrefslogtreecommitdiff
path: root/pango/glyphstring.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2008-08-06 08:39:53 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2008-08-06 08:39:53 +0000
commite77df055f63ed72278684ac6c426af4f74114fc0 (patch)
tree724ef4645ec69850598630d81045e45b00ca9251 /pango/glyphstring.c
parentd0f90842d2a7c0a35eae34c54d174d68fc0f3dc0 (diff)
downloadpango-e77df055f63ed72278684ac6c426af4f74114fc0.tar.gz
Bug 431394 – Use pango_glyph_item_iter in more places
2008-08-06 Behdad Esfahbod <behdad@gnome.org> Bug 431394 – Use pango_glyph_item_iter in more places * pango/glyphstring.c (pango_glyph_string_get_logical_widths): Use pango_glyph_item_iter for cluster iteration. svn path=/trunk/; revision=2680
Diffstat (limited to 'pango/glyphstring.c')
-rw-r--r--pango/glyphstring.c70
1 files changed, 34 insertions, 36 deletions
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index 75a008c4..42601d52 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -321,49 +321,47 @@ pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
int embedding_level,
int *logical_widths)
{
- int i, j;
- int last_cluster = 0;
- int width = 0;
- int last_cluster_width = 0;
- const char *p = text; /* Points to start of current cluster */
-
- for (i=0; i<=glyphs->num_glyphs; i++)
+ /* Build a PangoGlyphItem so we can use PangoGlyphItemIter.
+ * This API should have been made to take a PangoGlyphItem... */
+ PangoItem item = {0, length, g_utf8_strlen (text, length),
+ {NULL, NULL, NULL,
+ embedding_level, PANGO_GRAVITY_AUTO, 0,
+ PANGO_SCRIPT_UNKNOWN, NULL,
+ NULL}};
+ PangoGlyphItem glyph_item = {&item, glyphs};
+ PangoGlyphItemIter iter;
+ gboolean has_cluster;
+ int dir;
+
+ dir = embedding_level % 2 == 0 ? +1 : -1;
+ for (has_cluster = pango_glyph_item_iter_init_start (&iter, &glyph_item, text);
+ has_cluster;
+ has_cluster = pango_glyph_item_iter_next_cluster (&iter))
{
- int glyph_index = (embedding_level % 2 == 0) ? i : glyphs->num_glyphs - i - 1;
+ int glyph_index, char_index, num_chars, cluster_width = 0, char_width;
- /* If this glyph belongs to a new cluster, or we're at the end, find
- * the start of the next cluster, and assign the widths for this cluster.
- */
- if (i == glyphs->num_glyphs || p != text + glyphs->log_clusters[glyph_index])
- {
- int next_cluster = last_cluster;
+ for (glyph_index = iter.start_glyph;
+ glyph_index != iter.end_glyph;
+ glyph_index += dir)
+ {
+ cluster_width += glyphs->glyphs[glyph_index].geometry.width;
+ }
- if (i < glyphs->num_glyphs)
- {
- while (p < text + glyphs->log_clusters[glyph_index])
- {
- next_cluster++;
- p = g_utf8_next_char (p);
- }
- }
- else
+ num_chars = iter.end_char - iter.start_char;
+ if (num_chars) /* pedantic */
+ {
+ char_width = cluster_width / num_chars;
+
+ for (char_index = iter.start_char;
+ char_index < iter.end_char;
+ char_index++)
{
- while (p < text + length)
- {
- next_cluster++;
- p = g_utf8_next_char (p);
- }
+ logical_widths[char_index] = char_width;
}
- for (j = last_cluster; j < next_cluster; j++)
- logical_widths[j] = (width - last_cluster_width) / (next_cluster - last_cluster);
-
- last_cluster = next_cluster;
- last_cluster_width = width;
+ /* add any residues to the first char */
+ logical_widths[iter.start_char] += cluster_width - (char_width * num_chars);
}
-
- if (i < glyphs->num_glyphs)
- width += glyphs->glyphs[glyph_index].geometry.width;
}
}