pango r2680 - in trunk: . pango
- From: behdad svn gnome org
- To: svn-commits-list gnome org
- Subject: pango r2680 - in trunk: . pango
- Date: Wed, 6 Aug 2008 08:39:53 +0000 (UTC)
Author: behdad
Date: Wed Aug 6 08:39:53 2008
New Revision: 2680
URL: http://svn.gnome.org/viewvc/pango?rev=2680&view=rev
Log:
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.
Modified:
trunk/ChangeLog
trunk/pango/glyphstring.c
Modified: trunk/pango/glyphstring.c
==============================================================================
--- trunk/pango/glyphstring.c (original)
+++ trunk/pango/glyphstring.c Wed Aug 6 08:39:53 2008
@@ -321,49 +321,47 @@
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++)
- {
- int glyph_index = (embedding_level % 2 == 0) ? i : glyphs->num_glyphs - i - 1;
+ /* 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, char_index, num_chars, cluster_width = 0, char_width;
+
+ for (glyph_index = iter.start_glyph;
+ glyph_index != iter.end_glyph;
+ glyph_index += dir)
+ {
+ cluster_width += glyphs->glyphs[glyph_index].geometry.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;
+ num_chars = iter.end_char - iter.start_char;
+ if (num_chars) /* pedantic */
+ {
+ char_width = cluster_width / num_chars;
- if (i < glyphs->num_glyphs)
- {
- while (p < text + glyphs->log_clusters[glyph_index])
- {
- next_cluster++;
- p = g_utf8_next_char (p);
- }
- }
- else
+ 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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]