Skip to content

Commit 206b5fd

Browse files
Fix - TextPresenter ignores FontStretch property (#12947)
* Test * Fix
1 parent 3515b99 commit 206b5fd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Avalonia.Controls/Presenters/TextPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ protected virtual TextLayout CreateTextLayout()
476476
var caretIndex = CaretIndex;
477477
var preeditText = PreeditText;
478478
var text = GetCombinedText(Text, caretIndex, preeditText);
479-
var typeface = new Typeface(FontFamily, FontStyle, FontWeight);
479+
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
480480
var selectionStart = SelectionStart;
481481
var selectionEnd = SelectionEnd;
482482
var start = Math.Min(selectionStart, selectionEnd);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using Avalonia.Controls.Presenters;
3+
using Avalonia.Media;
34
using Avalonia.UnitTests;
45
using Xunit;
56

@@ -51,5 +52,28 @@ public void Text_Presenter_Replaces_Formatted_Text_With_Password_Char()
5152
Assert.Equal("****", actual);
5253
}
5354
}
55+
56+
[Theory]
57+
[InlineData(FontStretch.Condensed)]
58+
[InlineData(FontStretch.Expanded)]
59+
[InlineData(FontStretch.Normal)]
60+
[InlineData(FontStretch.ExtraCondensed)]
61+
[InlineData(FontStretch.SemiCondensed)]
62+
[InlineData(FontStretch.ExtraExpanded)]
63+
[InlineData(FontStretch.SemiExpanded)]
64+
[InlineData(FontStretch.UltraCondensed)]
65+
[InlineData(FontStretch.UltraExpanded)]
66+
public void TextPresenter_Should_Use_FontStretch_Property(FontStretch fontStretch)
67+
{
68+
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
69+
{
70+
var presenter = new TextPresenter { FontStretch = fontStretch, Text = "test" };
71+
Assert.NotNull(presenter.TextLayout);
72+
Assert.Equal(1, presenter.TextLayout.TextLines.Count);
73+
Assert.Equal(1, presenter.TextLayout.TextLines[0].TextRuns.Count);
74+
Assert.NotNull(presenter.TextLayout.TextLines[0].TextRuns[0].Properties);
75+
Assert.Equal(fontStretch, presenter.TextLayout.TextLines[0].TextRuns[0].Properties.Typeface.Stretch);
76+
}
77+
}
5478
}
5579
}

0 commit comments

Comments
 (0)