Browse Source

Fixes leading space GlyphRun.InkBounds (#13268)

* Make sure glyph bounds of whitespaces are calculated properly

* Add unit test
pull/13271/head
Benedikt Stebner 2 years ago
committed by GitHub
parent
commit
312e6089f8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Skia/Avalonia.Skia/GlyphRunImpl.cs
  2. 16
      tests/Avalonia.Skia.UnitTests/Media/GlyphRunTests.cs

5
src/Skia/Avalonia.Skia/GlyphRunImpl.cs

@ -70,6 +70,11 @@ namespace Avalonia.Skia
var gBounds = glyphBounds[i];
var advance = glyphInfos[i].GlyphAdvance;
if(gBounds.Width == 0)
{
gBounds = new SKRect(0, 0, (float)advance, 1);
}
runBounds = runBounds.Union(new Rect(currentX + gBounds.Left, baselineOrigin.Y + gBounds.Top, gBounds.Width, gBounds.Height));
currentX += advance;

16
tests/Avalonia.Skia.UnitTests/Media/GlyphRunTests.cs

@ -175,6 +175,22 @@ namespace Avalonia.Skia.UnitTests.Media
}
}
[Fact]
public void GlyphRun_With_Leading_Space_Has_Correct_InBounds()
{
using (Start())
{
var typeface = new Typeface("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#Inter");
var options = new TextShaperOptions(typeface.GlyphTypeface, 14);
var shapedBuffer = TextShaper.Current.ShapeText(" ", options);
var glyphRun1 = CreateGlyphRun(shapedBuffer);
var bounds = glyphRun1.InkBounds;
Assert.Equal(shapedBuffer[0].GlyphAdvance, bounds.Width);
}
}
private static List<Rect> BuildRects(GlyphRun glyphRun)
{
var height = glyphRun.Bounds.Height;

Loading…
Cancel
Save