diff --git a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs index 73dd3366aa..5c43a1c94f 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs @@ -477,25 +477,28 @@ namespace Avalonia.Media.TextFormatting { case ShapedTextCharacters shapedTextCharacters: { - var firstCluster = shapedTextCharacters.ShapedBuffer.GlyphClusters[0]; - var lastCluster = firstCluster; - - for (var i = 0; i < shapedTextCharacters.ShapedBuffer.Length; i++) + if(shapedTextCharacters.ShapedBuffer.Length > 0) { - var glyphInfo = shapedTextCharacters.ShapedBuffer[i]; + var firstCluster = shapedTextCharacters.ShapedBuffer.GlyphClusters[0]; + var lastCluster = firstCluster; - if (currentWidth + glyphInfo.GlyphAdvance > paragraphWidth) + for (var i = 0; i < shapedTextCharacters.ShapedBuffer.Length; i++) { - measuredLength += Math.Max(0, lastCluster - firstCluster); + var glyphInfo = shapedTextCharacters.ShapedBuffer[i]; - goto found; - } + if (currentWidth + glyphInfo.GlyphAdvance > paragraphWidth) + { + measuredLength += Math.Max(0, lastCluster - firstCluster); - lastCluster = glyphInfo.GlyphCluster; - currentWidth += glyphInfo.GlyphAdvance; - } + goto found; + } - measuredLength += currentRun.TextSourceLength; + lastCluster = glyphInfo.GlyphCluster; + currentWidth += glyphInfo.GlyphAdvance; + } + + measuredLength += currentRun.TextSourceLength; + } break; }