Skip to content

Commit d03a2c6

Browse files
FodaMike Corsaro
andauthored
[Windows] Fix FontImageSource resize behavior (#21212)
* Fix FontImageSource resize behavior and add additional tests * Update test for icons * Migrate test to seperate file * Revert font change * Update ref image --------- Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
1 parent b089ff4 commit d03a2c6

File tree

8 files changed

+113
-20
lines changed

8 files changed

+113
-20
lines changed

src/Controls/samples/Controls.Sample.UITests/Controls.Sample.UITests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<MauiImage Include="Resources\Images\dotnet_bot.svg" Link="Resources\Images\small_dotnet_bot.svg" Color="#FFFFFF" BaseSize="64,64" />
4747
<MauiImage Include="Resources\AppIcons\appicon.svg" ForegroundFile="Resources\AppIcons\appicon_foreground.svg" IsAppIcon="true" />
4848
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#FFFFFF" BaseSize="168,208" />
49+
<MauiFont Include="Resources\Fonts\OpenSans-Regular.ttf" />
4950
</ItemGroup>
50-
51+
5152
<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />
52-
5353
</Project>

src/Controls/samples/Controls.Sample.UITests/Issues/Issue18242.xaml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,37 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
x:Class="Maui.Controls.Sample.Issues.Issue18242"
55
Title="Issue 18242">
6-
<VerticalStackLayout
7-
Padding="12">
8-
<Label
6+
<VerticalStackLayout
7+
Padding="12"
8+
Grid.Column="0">
9+
<Label
910
AutomationId="WaitForStubControl"
1011
Text="1. The image must adapt to the size of the Button and be in the position determined by the ContentLayout property."/>
11-
<Label
12+
<Label
1213
Text="Button with Height"/>
13-
<Button
14+
<Button
1415
HeightRequest="50"
1516
ImageSource="dotnet_bot.png"
1617
ContentLayout="Left,10"
1718
Text="Button"/>
18-
<Label
19+
<Label
1920
Text="Button without Height"/>
20-
<Button
21+
<Button
2122
ImageSource="dotnet_bot.png"
2223
ContentLayout="Left,10"
2324
Text="Button"/>
24-
<Label
25+
<Label
2526
Text="2. The image must adapt to the size of the ImageButton."/>
26-
<Label
27+
<Label
2728
Text="ImageButton with Height"/>
28-
<ImageButton
29+
<ImageButton
2930
HeightRequest="30"
3031
WidthRequest="50"
3132
Source="dotnet_bot.png"/>
32-
<Label
33-
Text="ImageButton without Height"/>
34-
<ImageButton
35-
WidthRequest="50"
36-
Source="dotnet_bot.png"/>
37-
</VerticalStackLayout>
33+
<Label
34+
Text="ImageButton without Height"/>
35+
<ImageButton
36+
WidthRequest="50"
37+
Source="dotnet_bot.png"/>
38+
</VerticalStackLayout>
3839
</ContentPage>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue21202"
5+
Title="Issue 21202">
6+
<VerticalStackLayout
7+
Padding="12"
8+
Grid.Column="1">
9+
<Label
10+
AutomationId="WaitForStubControl"
11+
Text="1. Font image source should not be stretched on button with height requested."/>
12+
<Button
13+
FontSize="18"
14+
HeightRequest="60"
15+
HorizontalOptions="Fill"
16+
Text="Button with height request set"
17+
TextTransform="Uppercase"
18+
FontFamily="OpenSansRegular">
19+
<Button.ImageSource>
20+
<FontImageSource Glyph="A" Color="Black" FontFamily="OpenSansRegular"/>
21+
</Button.ImageSource>
22+
</Button>
23+
<Label
24+
Text="2. Font image source should not be stretched on button without height requested."/>
25+
<Button
26+
FontSize="18"
27+
HorizontalOptions="Fill"
28+
Text="Button without height request"
29+
TextTransform="Uppercase"
30+
FontFamily="OpenSansRegular">
31+
<Button.ImageSource>
32+
<FontImageSource Glyph="A" Color="Black" FontFamily="OpenSansRegular"/>
33+
</Button.ImageSource>
34+
</Button>
35+
<Label
36+
Text="3. Button without height request should resize to font image source size."/>
37+
<Button
38+
FontSize="18"
39+
HorizontalOptions="Fill"
40+
Text="Button without height request, resize to font image"
41+
TextTransform="Uppercase"
42+
FontFamily="OpenSansRegular">
43+
<Button.ImageSource>
44+
<FontImageSource Glyph="A" Size="60" Color="Black" FontFamily="OpenSansRegular"/>
45+
</Button.ImageSource>
46+
</Button>
47+
</VerticalStackLayout>
48+
</ContentPage>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Controls.Xaml;
3+
4+
namespace Maui.Controls.Sample.Issues
5+
{
6+
[XamlCompilation(XamlCompilationOptions.Compile)]
7+
[Issue(IssueTracker.Github, 21202, "FontImageSource incorrectly sized", PlatformAffected.UWP)]
8+
public partial class Issue21202 : ContentPage
9+
{
10+
public Issue21202()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

src/Controls/samples/Controls.Sample.UITests/MauiProgram.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ public static class MauiProgram
1111
public static MauiApp CreateMauiApp() =>
1212
MauiApp
1313
.CreateBuilder()
14-
#if IOS || ANDROID
14+
#if IOS || ANDROID
1515
.UseMauiMaps()
16-
#endif
16+
#endif
1717
.UseMauiApp<App>()
18+
.ConfigureFonts(fonts =>
19+
{
20+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
21+
})
1822
.Build();
1923
}
2024

Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.AppiumTests.Issues
6+
{
7+
public class Issue21202 : _IssuesUITest
8+
{
9+
public Issue21202(TestDevice device) : base(device)
10+
{
11+
}
12+
13+
public override string Issue => "FontImageSource incorrectly sized";
14+
15+
[Test]
16+
public void Issue21202Test()
17+
{
18+
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.iOS }, "Only Windows for now");
19+
20+
App.WaitForElement("WaitForStubControl");
21+
22+
VerifyScreenshot();
23+
}
24+
}
25+
}
25.6 KB
Loading

0 commit comments

Comments
 (0)