From 13927965b0bf20010224a7d444a06237eda4b8d4 Mon Sep 17 00:00:00 2001 From: "gavin%gavinsharp.com" Date: Wed, 2 May 2007 20:35:08 +0000 Subject: [PATCH] Bug 378695: SetupClusterBoundaries in gfxPangoFonts.cpp misinterprets attrs from pango_break, patch by Karl Tomlinson , r=roc --- gfx/thebes/src/gfxPangoFonts.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gfx/thebes/src/gfxPangoFonts.cpp b/gfx/thebes/src/gfxPangoFonts.cpp index 0273819f0d2..6af5f7c7916 100644 --- a/gfx/thebes/src/gfxPangoFonts.cpp +++ b/gfx/thebes/src/gfxPangoFonts.cpp @@ -950,19 +950,23 @@ SetupClusterBoundaries(gfxTextRun* aTextRun, const gchar *aUTF8, PRUint32 aUTF8L return; } + // Pango says "the array of PangoLogAttr passed in must have at least N+1 + // elements, if there are N characters in the text being broken". + // Could use g_utf8_strlen(aUTF8, aUTF8Length) + 1 but the memory savings + // may not be worth the call. nsAutoTArray buffer; if (!buffer.AppendElements(aUTF8Length + 1)) return; - // Pango says "the array of PangoLogAttr passed in must have at least N+1 - // elements, if there are N characters in the text being broken" - pango_break(aUTF8, aUTF8Length, aAnalysis, buffer.Elements(), aUTF8Length + 1); + pango_break(aUTF8, aUTF8Length, aAnalysis, + buffer.Elements(), buffer.Length()); const gchar *p = aUTF8; const gchar *end = aUTF8 + aUTF8Length; + const PangoLogAttr *attr = buffer.Elements(); gfxTextRun::CompressedGlyph g; while (p < end) { - if (!buffer[p - aUTF8].is_cursor_position) { + if (!attr->is_cursor_position) { aTextRun->SetCharacterGlyph(aUTF16Offset, g.SetClusterContinuation()); } ++aUTF16Offset; @@ -974,6 +978,7 @@ SetupClusterBoundaries(gfxTextRun* aTextRun, const gchar *aUTF8, PRUint32 aUTF8L } // We produced this utf8 so we don't need to worry about malformed stuff p = g_utf8_next_char(p); + ++attr; } }