Browse Source
Fix TextLayout.OverhandLeading calculation (#13287)
* Fix overhand leading calculation
* Fix test on Mac
* Fix tests
pull/13357/head
Benedikt Stebner
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
29 additions and
9 deletions
-
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
-
src/Skia/Avalonia.Skia/GlyphRunImpl.cs
-
tests/Avalonia.Skia.UnitTests/Media/GlyphRunTests.cs
-
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs
-
BIN
tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png
|
|
|
@ -1328,7 +1328,9 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
} |
|
|
|
|
|
|
|
var start = GetParagraphOffsetX(width, widthIncludingWhitespace); |
|
|
|
var overhangLeading = Math.Max(0, bounds.Left - start); |
|
|
|
//The width of overhanging pixels at the origin
|
|
|
|
var overhangLeading = Math.Max(0, start - bounds.Left); |
|
|
|
//The width of overhanging pixels at the end
|
|
|
|
var overhangTrailing = Math.Max(0, bounds.Width - widthIncludingWhitespace); |
|
|
|
var hasOverflowed = width > _paragraphWidth; |
|
|
|
|
|
|
|
|
|
|
|
@ -70,11 +70,6 @@ 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; |
|
|
|
|
|
|
|
@ -176,18 +176,18 @@ namespace Avalonia.Skia.UnitTests.Media |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void GlyphRun_With_Leading_Space_Has_Correct_InBounds() |
|
|
|
public void GlyphRun_With_Leading_Space_Has_Correct_InkBounds() |
|
|
|
{ |
|
|
|
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 shapedBuffer = TextShaper.Current.ShapeText(" I", options); |
|
|
|
|
|
|
|
var glyphRun1 = CreateGlyphRun(shapedBuffer); |
|
|
|
var bounds = glyphRun1.InkBounds; |
|
|
|
|
|
|
|
Assert.Equal(shapedBuffer[0].GlyphAdvance, bounds.Width); |
|
|
|
Assert.True(bounds.Left > 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1259,6 +1259,29 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_GetPreviousCharacterHit_Non_Trailing() |
|
|
|
{ |
|
|
|
var text = "123.45.67.•"; |
|
|
|
|
|
|
|
using (Start()) |
|
|
|
{ |
|
|
|
var defaultProperties = new GenericTextRunProperties(Typeface.Default); |
|
|
|
var textSource = new SingleBufferTextSource(text, defaultProperties, true); |
|
|
|
|
|
|
|
var formatter = new TextFormatterImpl(); |
|
|
|
|
|
|
|
var textLine = |
|
|
|
formatter.FormatLine(textSource, 0, double.PositiveInfinity, |
|
|
|
new GenericTextParagraphProperties(FlowDirection.LeftToRight, TextAlignment.Left, |
|
|
|
true, true, defaultProperties, TextWrapping.NoWrap, 0, 0, 0)); |
|
|
|
|
|
|
|
var characterHit = textLine.GetPreviousCaretCharacterHit(new CharacterHit(10, 1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class FixedRunsTextSource : ITextSource |
|
|
|
{ |
|
|
|
private readonly IReadOnlyList<TextRun> _textRuns; |
|
|
|
|
Width:
|
Height:
|
Size: 528 B
Width:
|
Height:
|
Size: 529 B
|