Bug 42517 - Setting font size of Label to exactly 12 (WinRT) or 15 (UWP) results in much larger font
Summary: Setting font size of Label to exactly 12 (WinRT) or 15 (UWP) results in much ...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-13 13:26 UTC by Tom Gregorovic
Modified: 2017-06-22 02:03 UTC (History)
4 users (show)

Tags: ac, uwp
Is this bug a regression?: No
Last known good build:


Attachments
font sizes on WinRT (13.30 KB, image/png)
2016-07-13 13:26 UTC, Tom Gregorovic
Details
font size on UWP (17.13 KB, image/png)
2016-07-13 13:26 UTC, Tom Gregorovic
Details
UWP (5.27 KB, image/png)
2016-07-13 22:07 UTC, Samantha Houts [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 42517 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

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.)