From e77df055f63ed72278684ac6c426af4f74114fc0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 6 Aug 2008 08:39:53 +0000 Subject: [PATCH] =?utf8?q?Bug=20431394=20=E2=80=93=20Use=20pango=5Fglyph?= =?utf8?q?=5Fitem=5Fiter=20in=20more=20places?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2008-08-06 Behdad Esfahbod 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 --- ChangeLog | 7 ++++++ pango/glyphstring.c | 70 ++++++++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 796baa2..031634a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-08-06 Behdad Esfahbod + 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. + +2008-08-06 Behdad Esfahbod + Bug 377948 – Make pango_glyph_item_iter public * pango/pango-glyph-item.c (pango_glyph_item_iter_copy), diff --git a/pango/glyphstring.c b/pango/glyphstring.c index 75a008c..42601d5 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; } } -- 2.7.4