Browse Source

Fix MeasureText for empty glyph clusters

pull/4240/head
Benedikt Schroeder 6 years ago
parent
commit
4e53adb9d4
  1. 7
      src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs
  2. 4
      src/Skia/Avalonia.Skia/TextShaperImpl.cs
  3. 1
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

7
src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs

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

4
src/Skia/Avalonia.Skia/TextShaperImpl.cs

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

1
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

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

Loading…
Cancel
Save