This module attempts pixel perfect vertical font placement for Corona SDK.
TLDR; Font placing is handled differently on all platforms, however the percentage of offsets from top and bottom stay the same from device to device within a platform. The module calculates the px offset required to get accurate position after adding sample offsets for each platform manually.
This module aims to make that easy but to achieve perfect placement there needs to be some manual work done. You must measure how many px the font has of empty space at the top and bottom for each platform (Simulator (win + mac), Android, iOS). However individual device measurement is not required which would be quite impossible on Android anyway.
The sample included works with the default font.
Adding custom font
To add a custom font you must measure it in Simulator, Android and iOS. Example: you make a mask behind a font, take a screenshot, open it in an image editor and count the pixels.
Detailed steps (this code is in main2.lua):
Make a text object in the correct font size you plan on using (40 in this example).
local test = display.newText("THIS IS A TEST!", 10, 10, native.systemFont, 40)
Make a mask so you can clearly see where the font starts and stops vertically
local mask = display.newRect(0, 10, display.contentWidth , test.height) mask : setFillColor(255,0,0) mask.alpha = 0.50
Take screenshot of screen, on simulator, and Android and iOS Device.
From example above: <http://i.imgur.com/mL3aSbh.png>
Open up in image editor and get the total height and pixels above and below
Use a marque tool that reports pixels <http://i.imgur.com/ic8Ttvp.png>
Now that we have all the required info for the default font size 40 on the simulator we require the module and add the information.
fontOffset.addOffset(fontSize, deviceType, fontHeight, fontTopSpace, fontBottomSpace)
See example in main.lua
One you have an offset or 2 added you set text position with "setPosition" function.
local test = display.newText("THIS IS A TEST!", 0, 0, native.systemFont, 40)
fontOffset.setPosition(test, 10, 10, display.TopLeftReferencePoint)