diff --git a/gfx/thebes/src/gfxPangoFonts.cpp b/gfx/thebes/src/gfxPangoFonts.cpp index febd5e8b3c2..e32ce9b64b3 100644 --- a/gfx/thebes/src/gfxPangoFonts.cpp +++ b/gfx/thebes/src/gfxPangoFonts.cpp @@ -1049,27 +1049,36 @@ SetupClusterBoundaries(gfxTextRun* aTextRun, const gchar *aUTF8, PRUint32 aUTF8L if (!buffer.AppendElements(aUTF8Length + 1)) return; - 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 (!attr->is_cursor_position) { - aTextRun->SetCharacterGlyph(aUTF16Offset, g.SetClusterContinuation()); - } - ++aUTF16Offset; - - gunichar ch = g_utf8_get_char(p); - NS_ASSERTION(!IS_SURROGATE(ch), "Shouldn't have surrogates in UTF8"); - if (ch >= 0x10000) { + PangoLogAttr *attr = buffer.Elements(); + pango_break(p, end - p, aAnalysis, attr, buffer.Length()); + + while (p < end) { + if (!attr->is_cursor_position) { + aTextRun->SetCharacterGlyph(aUTF16Offset, g.SetClusterContinuation()); + } ++aUTF16Offset; + + gunichar ch = g_utf8_get_char(p); + NS_ASSERTION(!IS_SURROGATE(ch), "Shouldn't have surrogates in UTF8"); + if (ch >= 0x10000) { + ++aUTF16Offset; + } + // We produced this utf8 so we don't need to worry about malformed stuff + p = g_utf8_next_char(p); + ++attr; + + if (ch == 0) { + // pango_break (pango 1.16.2) only analyses text before the + // first NUL (but sets one extra attr), so call pango_break + // again to analyse after the NUL. + break; + } } - // We produced this utf8 so we don't need to worry about malformed stuff - p = g_utf8_next_char(p); - ++attr; } }