Skip to content

Commit 7813c96

Browse files
committed
Revert AvaloniaUI#16601 that is introducing an invalid calculation for the OverhangLeading
Add tests for OverhangLeading and OverhangTrailing
1 parent e5dca61 commit 7813c96

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/Skia/Avalonia.Skia/GlyphRunImpl.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ public GlyphRunImpl(IGlyphTypeface glyphTypeface, double fontRenderingEmSize,
8080

8181
currentX += advance;
8282
}
83-
84-
if (runBounds.Left < 0)
85-
{
86-
runBounds = runBounds.Translate(new Vector(-runBounds.Left, 0));
87-
}
88-
8983
ArrayPool<SKRect>.Shared.Return(glyphBounds);
9084

9185
BaselineOrigin = baselineOrigin;

tests/Avalonia.Skia.UnitTests/Avalonia.Skia.UnitTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
<EmbeddedResource Include="..\Avalonia.RenderTests\*\*.ttf" />
1313
<None Remove="Fonts\DejaVuSans.ttf" />
1414
<None Remove="Fonts\Manrope-Light.ttf" />
15+
<None Remove="Fonts\SourceSerif4_36pt-Italic.ttf" />
1516
<None Remove="Fonts\WinSymbols3.ttf" />
1617
<EmbeddedResource Include="Fonts\DejaVuSans.ttf" />
1718
<EmbeddedResource Include="Fonts\Manrope-Light.ttf" />
19+
<EmbeddedResource Include="Fonts\SourceSerif4_36pt-Italic.ttf" />
1820
<EmbeddedResource Include="Fonts\WinSymbols3.ttf" />
1921
</ItemGroup>
2022
<ItemGroup>
Binary file not shown.

tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,35 @@ public void Should_Measure_TextLayoutSymbolWithAndWidthIncludingTrailingWhitespa
11871187
}
11881188
}
11891189

1190+
[Fact]
1191+
public void Should_Measure_TextLayoutWithOverhangLeading()
1192+
{
1193+
using (Start())
1194+
{
1195+
const string symbolsFont = "resm:Avalonia.Skia.UnitTests.Fonts?assembly=Avalonia.Skia.UnitTests#Source Serif 4 36pt";
1196+
var typeFace = new Typeface(symbolsFont);
1197+
var textLayout0 = new TextLayout("f", typeFace, 44.0, Brushes.White);
1198+
Assert.Equal(8.0, textLayout0.OverhangLeading);
1199+
Assert.Equal(8.5040000000000013, textLayout0.OverhangTrailing);
1200+
Assert.Equal(12.495999999999999, textLayout0.WidthIncludingTrailingWhitespace);
1201+
1202+
var textLayout1 = new TextLayout("ff", typeFace, 44.0, Brushes.White);
1203+
Assert.Equal(8.0, textLayout1.OverhangLeading);
1204+
Assert.Equal(8.8440000000000012, textLayout1.OverhangTrailing);
1205+
Assert.Equal(24.155999999999999, textLayout1.WidthIncludingTrailingWhitespace);
1206+
1207+
var textLayout2 = new TextLayout("y", typeFace, 44.0, Brushes.White);
1208+
Assert.Equal(6.0, textLayout2.OverhangLeading);
1209+
Assert.Equal(0.58399999999999963, textLayout2.OverhangTrailing);
1210+
Assert.Equal(20.416, textLayout2.WidthIncludingTrailingWhitespace);
1211+
1212+
var textLayout3 = new TextLayout("yy", typeFace, 44.0, Brushes.White);
1213+
Assert.Equal(6.0, textLayout3.OverhangLeading);
1214+
Assert.Equal(0.58399999999999608, textLayout3.OverhangTrailing);
1215+
Assert.Equal(41.052, textLayout3.WidthIncludingTrailingWhitespace);
1216+
}
1217+
}
1218+
11901219
private static IDisposable Start()
11911220
{
11921221
var disposable = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface

0 commit comments

Comments
 (0)