Standardize Font Appearance
Neville Smythe
neville.smythe at optusnet.com.au
Sun Sep 4 21:11:56 EDT 2022
Actually it is possible to ensure the baselines of fields are consistent across platforms without having to use conditionals.
From experimentation it appears that the baseline is given (relative to the top of the field) by
the top margin - 3*fontAscent/4 -1
where the fontAscent is item 2 of measureText(text,fld,”bounds”) (note this is a negative number; in macOS it is the traditional font ascent, in Windows I think it is the traditional font top )
Since the bottom margin is ignored in this placement, we can force the baseline to be at the bottom margin as follows:
put the margins of fld “foo" into tMargins
put item 4 of tMargins into tBottomMargin
put measuretext(fld “foo",fld “foo",bounds) into tFontInfo
put 1 + the height of fld “foo” - tBottomMargin + round(3*(item 2 of tFontInfo)/4) into tTopMargin
put tTopMargin into item 2 of tMargins
set the margins of fld “foo" to tMargins
The pixel length of text however cannot be made consistent across platforms, and one can only allow some extra padding to make sure the text appears unmangled. My very limited experiments with just the fonts NotoSans and NotoSerif at textSize 13 and the text “A standard label:” indicate that
Mac Monterey and Windows 10 : text widths are the same
Mac High Sierra : about 8% longer
Linux Ubuntu: about 15% longer (!!)
Other fonts differ more widely between platforms and system versions (perhaps most weirdly 13pt Times on the Mac looks like 9pt)
Neville Smythe
More information about the use-livecode
mailing list