Benedikt Stebner
11 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
35 additions and
3 deletions
-
src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs
-
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs
|
|
|
@ -574,10 +574,11 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
{ |
|
|
|
var measuredLength = 0; |
|
|
|
var currentWidth = 0.0; |
|
|
|
var runIndex = 0; |
|
|
|
|
|
|
|
for (var i = 0; i < textRuns.Count; ++i) |
|
|
|
for (; runIndex < textRuns.Count; ++runIndex) |
|
|
|
{ |
|
|
|
var currentRun = textRuns[i]; |
|
|
|
var currentRun = textRuns[runIndex]; |
|
|
|
|
|
|
|
switch (currentRun) |
|
|
|
{ |
|
|
|
@ -630,7 +631,14 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
runLength = clusterLength; |
|
|
|
} |
|
|
|
|
|
|
|
return measuredLength + runLength; |
|
|
|
measuredLength += runLength; |
|
|
|
|
|
|
|
if (runIndex < textRuns.Count - 1 && runLength == currentRun.Length && textRuns[runIndex + 1] is TextEndOfLine endOfLine) |
|
|
|
{ |
|
|
|
measuredLength += endOfLine.Length; |
|
|
|
} |
|
|
|
|
|
|
|
return measuredLength; |
|
|
|
} |
|
|
|
|
|
|
|
currentWidth += clusterWidth; |
|
|
|
|
|
|
|
@ -1160,6 +1160,30 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Wrap_With_LineEnd() |
|
|
|
{ |
|
|
|
using (Start()) |
|
|
|
{ |
|
|
|
var defaultProperties = |
|
|
|
new GenericTextRunProperties(Typeface.Default, 72, foregroundBrush: Brushes.Black); |
|
|
|
|
|
|
|
var paragraphProperties = new GenericTextParagraphProperties(defaultProperties, textWrap: TextWrapping.Wrap); |
|
|
|
|
|
|
|
var textLayout = new TextLayout(new SingleBufferTextSource("01", defaultProperties, true), paragraphProperties, maxWidth: 36); |
|
|
|
|
|
|
|
Assert.Equal(2, textLayout.TextLines.Count); |
|
|
|
|
|
|
|
var lastLine = textLayout.TextLines.Last(); |
|
|
|
|
|
|
|
Assert.Equal(2, lastLine.TextRuns.Count); |
|
|
|
|
|
|
|
var lastRun = lastLine.TextRuns.Last(); |
|
|
|
|
|
|
|
Assert.IsAssignableFrom<TextEndOfLine>(lastRun); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static IDisposable Start() |
|
|
|
{ |
|
|
|
var disposable = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface |
|
|
|
|