Especially not Corona’s extra special blog threads. People have been killed for less. You have been warned.
Hi @mimetic,
In my testing, “baselineOffset” doesn’t necessarily yield the same thing as Apple’s reference for “Cap Height”. Are you sure you’re getting those results across multiple fonts? I don’t seem to be getting that, but perhaps my tests aren’t the same as yours.
Also, what is the most accurate method you’ve found to get the baseline of the text? I’m using TextObject.y-TextObject.baselineOffset which seems to work fine.
Brent
You are right, I am not achieve cap-height!
I am trying to align text to a box, either at cap-height (top of a letter, e.g. A) or ascender height (e.g. The top of a character including the accent, e.g. À).
Positioning the text object with TextObject.baselineOffset aligns to the ascender height (Avenir-Black 48pt)… and sometimes not, depending on font size (e.g. Avenir-Black 14pt).
So, I don’t know what’s going on, now. This works consistently across font sizes, and more importantly, matches InDesign layout perfectly.
See my text render code : https://github.com/mimetic/corona-textrender
Run the main.lua in the “/examples” folder. However, tweak the styles in the examples/assets folder to see the first line change.
local function GetYAdjustment(text, font) -- Best match for Ascent (includes accents, e.g. À) local metrics = graphics.getFontMetrics( font, text.size ) yAdjustment = metrics.height - text.height -- Alternative method: To align to the Cap Height: yAdjustment = text.baselineOffset return yAdjustment end
Hi @mimetic,
Thanks, I’ll check out your project soon.
In the meantime, does this new graphic clarify the key aspects, and did I get all of the details correct?
https://docs.coronalabs.com/api/library/graphics/getFontMetrics.html
Brent
Brent and / or Rob,
Any input no my leading / linespacing question? There are workarounds for this, so it’s not critical or urgent of course, but this seems like an easy feature addition.
The way we generate our text objects (pass the string to an OS specific API that returns an image texture and mask containing the results), there isn’t a good way to get or control those values. We are not generating native text but an image to push into OpenGL. This limits the available functionality.
Rob
Brent, yes, the graphic is perfect.
The way we generate our text objects (pass the string to an OS specific API that returns an image texture and mask containing the results), there isn’t a good way to get or control those values. We are not generating native text but an image to push into OpenGL. This limits the available functionality.
Rob, thank you for this kind of explanation. It helps a lot to know this level of detail when we discuss these matters.