I think it is possible to get perfect vertical text placement with some tricks.
By measuring the total font height and where the actual text is visible from top and bottom you can get the percentage offset required to get perfect placement. Because its different on simulator, Android and iOS you need to do this at least 3 times. From what I’m seeing the offset stays consistent across devices within a platform. Thus you only need to do this once for each platform.
My results with S4, Note1 and Nexus7, some iOS devices, simulator and Android emulator are here. Basically you are seeing 3 guide lines set at a certain Y position and text using the module either sits on top, bottom or centred 100% correctly across all these devices.
If someone can test more devices that would be great. Link to APK file.
Download runnable Corona main example: https://bitbucket.org/Jonjonsson/fontoffsetmodule/get/default.zip How to use custom font is in readme.
Example code for the default font I have previously measured. Should have exact vertical font placement across all devices (I hope).
[lua]
local text = require(“FontOffset”)
– Add offset for the default font, once for each platform.
– text.addOffset( fontSize, deviceType, fontHeight, fontTopSpace, fontBottomSpace)
text.addOffset(40, “simulator”, 48, 10, 9) – Same values as readme
text.addOffset(40, “android”, 135, 35, 28)
text.addOffset(40, “ios”, 96, 17, 22 )
– Make a 100px guide line that our text should be hugging
local guide = display.newLine(0, 100, display.contentWidth, 100)
– Even though the font size 40 was measured we can use different sizes (30 here)
local test = display.newText(“TEXT AT 1OOPX”, 0, 0, native.systemFont, 30)
text.setPosition(test, 10, 100)
print(“Font Y location”, test.y, “Font height”, test.height)
print(“Actual text Y location”, test.actualY, “Actual text height”, test.actualHeight)
– Ouput is
– Font Y location 93 Font height 36
– Actual text Y location 100 Actual text height 23
[/lua]
Result (hopefully with all devices):