Browse Source

Merge pull request #10840 from Gillibald/fixes/getTextBoundsEndOfParagraph

[Text]Fix GetTextBounds
pull/10874/head
Max Katz 3 years ago
committed by GitHub
parent
commit
e579a56ace
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  2. 27
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

18
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@ -701,7 +701,14 @@ namespace Avalonia.Media.TextFormatting
if (directionalWidth == 0)
{
//In case a run only contains a linebreak we don't want to skip it.
if (currentRun is ShapedTextRun shaped && currentRun.Length - shaped.GlyphRun.Metrics.NewLineLength > 0)
if (currentRun is ShapedTextRun shaped)
{
if(currentRun.Length - shaped.GlyphRun.Metrics.NewLineLength > 0)
{
continue;
}
}
else
{
continue;
}
@ -840,7 +847,14 @@ namespace Avalonia.Media.TextFormatting
if (directionalWidth == 0)
{
//In case a run only contains a linebreak we don't want to skip it.
if (currentRun is ShapedTextRun shaped && currentRun.Length - shaped.GlyphRun.Metrics.NewLineLength > 0)
if (currentRun is ShapedTextRun shaped)
{
if (currentRun.Length - shaped.GlyphRun.Metrics.NewLineLength > 0)
{
continue;
}
}
else
{
continue;
}

27
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

@ -994,6 +994,33 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
}
}
[Fact]
public void Should_GetTextBounds_With_EndOfParagraph_RightToLeft()
{
var text = "لوحة المفاتيح العربية";
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 textBounds = textLine.GetTextBounds(0, 1);
Assert.Equal(1, textBounds.Count);
var firstBounds = textBounds.First();
Assert.True(firstBounds.TextRunBounds.Count > 0);
}
}
private class FixedRunsTextSource : ITextSource
{
private readonly IReadOnlyList<TextRun> _textRuns;

Loading…
Cancel
Save