My custom font is set—it’s a family with regular and bold—and I can use drawText
and drawTextAligned
with it. Everything works until I try to measure text:
This returns values too small, as if the current font is ignored:
local w, h = gfx.getTextSize("W")
Is this a bug? Maybe it’s measuring the system font?
Specifying the fontFamily manually has the same problem—the stated fontFamily is ignored:
local w, h = gfx.getTextSize("W", playDINfamily)
So I tried using getTextWidth
instead, which requires specifying a font, but I can’t seem to get the current font (“normal” would be fine for now), only the current font family. This bricks the Simulator with index a nil value (global 'playDINfamily’)
:
local w = playDINfamily[gfx.font.kVariantNormal]:getTextWidth("W”)
But playDINfamily is working, and I’m rendering styled text with it: it’s a global, alongside misc. global variables that are working fine in the same script.
Workaround: I have to load a redundant individual font variant instead, to get it to deliver correct measurement:
local w = gfx.font.new("Fonts/PlayDIN-19"):getTextWidth("W")
That seems inefficient, since the font I’m using is already loaded. So I’d love to just be able to measure the CURRENT font that drawText
etc. uses. Any way to do that?
(And I haven’t found any way to get getTextSize
to use a custom font at all. If I want to measure styled text or the height, I’ll be stuck.)
TIA!