Skip to content

Fix - TextPresenter ignores FontStretch property #12947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Presenters/TextPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ protected virtual TextLayout CreateTextLayout()
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Avalonia.Controls.Presenters;
using Avalonia.Media;
using Avalonia.UnitTests;
using Xunit;

Expand Down Expand Up @@ -51,5 +52,28 @@ public void Text_Presenter_Replaces_Formatted_Text_With_Password_Char()
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);
}
}
}
}