Bug? Android 14, Label.TextSize doesn't play well with font scaling


Licensed User
Longtime User
Since the update to Android 14 we had some customer complaining that our applications wouldn't launch.
The condition to trigger this error is that the system font would be changed to be bigger than the default size.
For my test i just set it at the biggest

This was ultimately tracked down to a function, used throughout the application, that autosizes the font of a label. The core of the function is this loop
w = cvs.MeasureText(text, xui.CreateFont(lbl.Typeface, lbl.TextSize)).Width + pad(0) + pad(2)
h = su.MeasureMultilineTextHeight(lbl, lbl.Text) + pad(1) + pad(3)
Do While w < lbl.Width And h < lbl.Height
  lbl.textSize = lbl.textSize + 1
  w = cvs.MeasureText(text,xui.CreateFont(lbl.Typeface, lbl.TextSize)).Width + pad(0) + pad(2) 'text is the string containing the widest text, set before the loop
  h = su.MeasureMultilineTextHeight(lbl, lbl.Text) + pad(1) + pad(3)
  If block = False Then Sleep(0)
lbl.TextSize = lbl.TextSize - 1
and we would get ANRs that indicated MeasureMultilineTextHeight as the cause.
However, attaching the debugger showed that the real problem is that the TextSize property of a label cannot go higher than "X" (12.997 in this particular device, as Samsung S23)
Adding +1 would result in TextSize ultimately stopping 12.997, so as you can see it results into an infinite loop.
It doesn't really limit at 12.997, it's just that 13.997 gets scaled back to 12.997 (in fact if i set it to, for example, 20 i actually get 17) so

Looking at Textsize at every step of the loop:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12.5, 12.75, 12.875.... you get the drift

The source of the bug is probably the Nonlinear Font Scaling "Feature" in Android 14. See: https://developer.android.com/about/versions/14/features#non-linear-font-scaling
Combined, apparently, with how we set TextSize. I have used absolute values as i don't know if i should use something else.

I attached a sample application that exhibit the problem In a Pixel 6A and a Samsung S23, should also exhibit it in the emulator, but i don't think i have one set up at the moment to test.
I don't really know how to work around the issue


  • TestTextSize.zip
    9.7 KB · Views: 49