Browse Source

Fix MeasureText for empty glyph clusters

Benedikt Schroeder 5 years ago
parent
commit
4e53adb9d4

+ 6 - 1
src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs

@@ -377,7 +377,7 @@ namespace Avalonia.Media.TextFormatting
                 {
                     var glyph = glyphRun.GlyphIndices[i];
 
-                    var advance = glyphTypeface.GetGlyphAdvance(glyph);
+                    var advance = glyphTypeface.GetGlyphAdvance(glyph) * glyphRun.Scale;
 
                     if (currentWidth + advance > availableWidth)
                     {
@@ -411,6 +411,11 @@ namespace Avalonia.Media.TextFormatting
                 return glyphRun.Characters.Length;
             }
 
+            if (glyphRun.GlyphClusters.IsEmpty)
+            {
+                return glyphCount;
+            }
+
             var firstCluster = glyphRun.GlyphClusters[0];
 
             var lastCluster = glyphRun.GlyphClusters[glyphCount];

+ 2 - 2
src/Skia/Avalonia.Skia/TextShaperImpl.cs

@@ -90,9 +90,9 @@ namespace Avalonia.Skia
                         {
                             count++;
 
-                            buffer.Add('\u200D', cluster);
-
                             buffer.Add('\u200C', cluster);
+
+                            buffer.Add('\u200D', cluster);
                         }
                         else
                         {

+ 1 - 0
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

@@ -34,6 +34,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
                         Background = Brushes.Red,
                         Child = textBlock = new TextBlock
                         {
+                            TextWrapping = TextWrapping.NoWrap,
                             Text = "Hello World",
                         }
                     }