Browse Source
Merge pull request #4853 from Gillibald/fixes/4851
Properly handle multiple line breaks
pull/4870/head
Benedikt Stebner
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
23 additions and
11 deletions
-
src/Avalonia.Visuals/Media/GlyphRun.cs
-
src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs
-
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs
|
|
|
@ -399,14 +399,14 @@ namespace Avalonia.Media |
|
|
|
|
|
|
|
if (characterIndex > GlyphClusters[GlyphClusters.Length - 1]) |
|
|
|
{ |
|
|
|
return _glyphClusters.End; |
|
|
|
return _glyphClusters.Length - 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (characterIndex < GlyphClusters[GlyphClusters.Length - 1]) |
|
|
|
{ |
|
|
|
return _glyphClusters.End; |
|
|
|
return _glyphClusters.Length - 1; |
|
|
|
} |
|
|
|
|
|
|
|
if (characterIndex > GlyphClusters[0]) |
|
|
|
|
|
|
|
@ -339,14 +339,6 @@ namespace Avalonia.Media.TextFormatting |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
//The line breaker isn't treating \n\r as a pair so we have to fix that here.
|
|
|
|
if (textRun.Text[lineBreak.PositionMeasure] == '\n' |
|
|
|
&& textRun.Text[lineBreak.PositionWrap] == '\r') |
|
|
|
{ |
|
|
|
lineBreak = new LineBreak(lineBreak.PositionMeasure, lineBreak.PositionWrap + 1, |
|
|
|
lineBreak.Required); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -417,7 +417,6 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData("abcde\r\n", 7)] // Carriage Return + Line Feed
|
|
|
|
[InlineData("abcde\n\r", 7)] // This isn't valid but we somehow have to support it.
|
|
|
|
[InlineData("abcde\u000A", 6)] // Line Feed
|
|
|
|
[InlineData("abcde\u000B", 6)] // Vertical Tab
|
|
|
|
[InlineData("abcde\u000C", 6)] // Form Feed
|
|
|
|
@ -575,6 +574,27 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Process_Multiple_NewLines_Properly() |
|
|
|
{ |
|
|
|
using (Start()) |
|
|
|
{ |
|
|
|
var text = "123\r\n\r\n456\r\n\r\n"; |
|
|
|
var layout = new TextLayout( |
|
|
|
text, |
|
|
|
Typeface.Default, |
|
|
|
12.0f, |
|
|
|
Brushes.Black); |
|
|
|
|
|
|
|
Assert.Equal(5, layout.TextLines.Count); |
|
|
|
|
|
|
|
Assert.Equal("123\r\n", layout.TextLines[0].TextRuns[0].Text); |
|
|
|
Assert.Equal("\r\n", layout.TextLines[1].TextRuns[0].Text); |
|
|
|
Assert.Equal("456\r\n", layout.TextLines[2].TextRuns[0].Text); |
|
|
|
Assert.Equal("\r\n", layout.TextLines[3].TextRuns[0].Text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Wrap_Min_OneCharacter_EveryLine() |
|
|
|
{ |
|
|
|
|