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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
0 deletions
-
src/Skia/Avalonia.Skia/GlyphRunImpl.cs
-
tests/Avalonia.Skia.UnitTests/Media/GlyphRunTests.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; |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|