Browse Source

Fix - TextPresenter ignores FontStretch property (#12947)

* Test

* Fix
release/11.0.5-rc1
Vladimir Drobyshev 2 years ago
committed by Steven Kirk
parent
commit
81a5220f2d
  1. 2
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  2. 24
      tests/Avalonia.Controls.UnitTests/Presenters/TextPresenter_Tests.cs

2
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -476,7 +476,7 @@ namespace Avalonia.Controls.Presenters
var caretIndex = CaretIndex;
var preeditText = PreeditText;
var text = GetCombinedText(Text, caretIndex, preeditText);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd;
var start = Math.Min(selectionStart, selectionEnd);

24
tests/Avalonia.Controls.UnitTests/Presenters/TextPresenter_Tests.cs

@ -1,5 +1,6 @@
using System.Linq;
using Avalonia.Controls.Presenters;
using Avalonia.Media;
using Avalonia.UnitTests;
using Xunit;
@ -51,5 +52,28 @@ namespace Avalonia.Controls.UnitTests.Presenters
Assert.Equal("****", actual);
}
}
[Theory]
[InlineData(FontStretch.Condensed)]
[InlineData(FontStretch.Expanded)]
[InlineData(FontStretch.Normal)]
[InlineData(FontStretch.ExtraCondensed)]
[InlineData(FontStretch.SemiCondensed)]
[InlineData(FontStretch.ExtraExpanded)]
[InlineData(FontStretch.SemiExpanded)]
[InlineData(FontStretch.UltraCondensed)]
[InlineData(FontStretch.UltraExpanded)]
public void TextPresenter_Should_Use_FontStretch_Property(FontStretch fontStretch)
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var presenter = new TextPresenter { FontStretch = fontStretch, Text = "test" };
Assert.NotNull(presenter.TextLayout);
Assert.Equal(1, presenter.TextLayout.TextLines.Count);
Assert.Equal(1, presenter.TextLayout.TextLines[0].TextRuns.Count);
Assert.NotNull(presenter.TextLayout.TextLines[0].TextRuns[0].Properties);
Assert.Equal(fontStretch, presenter.TextLayout.TextLines[0].TextRuns[0].Properties.Typeface.Stretch);
}
}
}
}

Loading…
Cancel
Save