From 0d34c10108585b4cfed042aa2ef501780b2d2193 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 27 Sep 2012 14:08:30 -0400 Subject: Fixup grapheme clusters After adding pango_shape_full() and passing full paragraph text to HarfBuzz, we were getting cluster values relative to beginning to paragraph back from HarfBuzz, and I forgot to account for that. Caused severe crashes. Fixes: Bug 684959 - crash after "Add pango_shape_full()" and the dupes... --- modules/basic/basic-fc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/basic/basic-fc.c b/modules/basic/basic-fc.c index ef0277ea..991ad299 100644 --- a/modules/basic/basic-fc.c +++ b/modules/basic/basic-fc.c @@ -317,6 +317,7 @@ basic_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, hb_glyph_position_t *hb_position; int last_cluster; guint i, num_glyphs; + unsigned int item_offset = item_text - paragraph_text; g_return_if_fail (font != NULL); g_return_if_fail (analysis != NULL); @@ -362,7 +363,7 @@ basic_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, hb_buffer_set_script (hb_buffer, hb_glib_script_to_script (analysis->script)); hb_buffer_set_language (hb_buffer, hb_language_from_string (pango_language_to_string (analysis->language), -1)); - hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_text - paragraph_text, item_length); + hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_offset, item_length); hb_shape (hb_font, hb_buffer, NULL, 0); if (PANGO_GRAVITY_IS_IMPROPER (analysis->gravity)) @@ -376,7 +377,7 @@ basic_engine_shape (PangoEngineShape *engine G_GNUC_UNUSED, for (i = 0; i < num_glyphs; i++) { glyphs->glyphs[i].glyph = hb_glyph->codepoint; - glyphs->log_clusters[i] = hb_glyph->cluster; + glyphs->log_clusters[i] = hb_glyph->cluster - item_offset; glyphs->glyphs[i].attr.is_cluster_start = glyphs->log_clusters[i] != last_cluster; hb_glyph++; last_cluster = glyphs->log_clusters[i]; -- cgit v1.2.1