Browse Source
Merge pull request #9284 from Gillibald/fixes/limitedTypefaceCrash
Prevent a crash that is caused by limited typefaces
pull/9292/head
Benedikt Stebner
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
16 additions and
13 deletions
-
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; |
|
|
|
} |
|
|
|
|