Bug 42517

Summary: Setting font size of Label to exactly 12 (WinRT) or 15 (UWP) results in much larger font
Product: Forms Reporter: Tom Gregorovic <gregorovic.tomas>
Component: WindowsAssignee: Bugzilla <bugzilla>
Status: CONFIRMED ---    
Severity: normal CC: FieldstrikeMobile, jas, jt_xamarin, sahou
Priority: Normal    
Version: 2.3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: ac, uwp Is this bug a regression?: No
Last known good build:
Attachments: font sizes on WinRT
font size on UWP
UWP

Description Tom Gregorovic 2016-07-13 13:26:11 UTC
Created attachment 16646 [details]
font sizes on WinRT

In Xamarin.Forms Windows PCL project, if I set FontSize of Label to exactly 12 (WinRT) or 15 (UWP), which is what  Device.GetNamedSize(NamedSize.Default, typeof(Label)) returns, the rendered font size is much larger, even larger than of label with font size +1.

Looking into Xamarin.Forms code on git (https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/FontExtensions.cs and https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/LabelRenderer.cs) it seems the font is recognized as default, but than font size of medium is used, which is much larger.
On iOS and Android default font size is the same as medium.

Example code:

var stack = new StackLayout()
{
    Orientation = StackOrientation.Vertical
};

for (var i = -4; i < 4; i++) { stack.Children.Add(new Label() { Text = "font size " + (Device.GetNamedSize(NamedSize.Default, typeof(Label)) + i), FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) + i }); };
Comment 1 Tom Gregorovic 2016-07-13 13:26:59 UTC
Created attachment 16647 [details]
font size on UWP
Comment 2 Samantha Houts [MSFT] 2016-07-13 22:07:23 UTC
Created attachment 16657 [details]
UWP

I don't see the same behavior when I try this locally. I've used my local machine and the mobile emulators to test it, and it seems to be the correct size for both UWP and WinRT. Have the default font sizes on your device been changed?
Comment 3 Tom Gregorovic 2016-07-14 07:51:47 UTC
You are right, we set different font size in platform page xaml:
FontSize="{StaticResource TextStyleLargeFontSize}" 
Sorry I haven't mentioned it before.

Even thought I think this behavior is not correct.
Comment 4 Samantha Houts [MSFT] 2016-07-19 16:56:10 UTC
Thank you for the clarification!
Comment 5 John 2017-02-17 23:02:22 UTC
Is there a fix/workaround to ensure that a font size of 15 does not appear larger than a font size of 16?

It appears that a font size of 15 actually renders the same as size 23 in a UWP Windows desktop app.  This is an even bigger discrepancy than is visible with the mobile app, where it looks like 15 is more like 18, according to Tom's attachment 16657 [details].

I created a dynamic font sizer that determines the appropriate font size to fit in an area and when it hits 15, my layout can break since the font is larger than my calculations expect.
Comment 6 John 2017-02-17 23:16:51 UTC
It appears that a font size of 15 actually renders the same as size 23 in a UWP Windows desktop app.  This is an even bigger discrepancy than is visible with the mobile app, where it looks like 15 is more like 18, according to Tom's attachment 16657 [details].

I created a dynamic font sizer that determines the appropriate font size to fit in an area and when it hits 15, my layout can break since the font is larger than my calculations expect.

Luckily, I found an easy workaround for this.  Don't use integer values.  As long as it's not exactly 12 or exactly 15, the "font bloating" won't happen.  For instance, use 12.01 or 15.01 instead.
Comment 7 John 2017-02-17 23:18:40 UTC
Sorry for the double post!  I misunderstood the comment conflict resolution options.  I would delete my earlier post (Comment 5) if I could (and if someone else can, feel free to delete that one and this one, too.)