-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vertical Metrics? #44
Comments
It is in the plan. My 'current' dev queue ...
then I will revisit this #44 after #24 is closed Thank you for your interest. Welcome all pull-requests. :) |
#10 -> may fix this problem PaintLab/PixelFarm#3 |
So, my problem is this... I'm trying to implement an MSDF font renderer in my game engine. I'm using the Typography library to rasterize a TTF into a texture atlas. Simple enough. I want the Atlas index to contain the UV of the glyph on the page, and the WH of the glyph on the page. In order to render this at runtime, I need additional information that I can't seem to get from the library. I am currently approximating the Y offset with the following code fYOffset = fAscender - (glyphHeight-((float)translate.y) + fDecender); where fAscender and fDecender are the typeface ascender and decender values, converted to pixel space. I also made a small change to MsdfGlyphGen where it calculates the border width and calculates the translate value. The original code uses border = w/5 as a margin for both width and height -- but this knocks off the glyph width/height aspect ratio. Anyway - the code I'm using to approximate the Y offset is almost correct, but it doesn't work in certain cases, and I'm at a loss as to why. However, it would be so much easier if I could just access the bearingY from the vertical metrics for the TTF... Alternatively - I'm probably missing something fundamental, and this is already dead easy :) |
from
and
then I will look for that values again. :) |
Where dose a glyphHeight value come from?,
or
|
Here's the guts of the loop I'm using to generate the glyphs. I implemented my own Atlas class (BinaryTreeAtlas) that builds multiple atlas pages `
` |
I find the largest bounds of the typeface, and try to work out the offset of the glyph with respect to that bounding box - based on the width/height returned from the msdfShape.findBounds. It gets a bit sticky with glyphs that extend below the baseline, and I'm pretty sure its entirely the wrong way to do it :) |
Thank you. |
When I look from the view of actual glyph matrics (from glyph's points and contours). But from the Msdfgen lib's view, ...
(this version) not provide enough information to calculate the values you want and
(yes, you are nearly to the answer!) I will add method(s) that provide information for Msdfgen lib |
@hexland This is an early fix.
|
For Vertical Matric features in OpenType
|
Thanks for that. I believe I have it working now. I was using the typeface.Bounds to calculate 'the largest bounding area' and then calculate the pixel scale value from there (e.g. I want to scale the font to a 64x64 glyph texture).
The 'err' value was needed because I was seeing some very very slight vertical alignment issues due to accruing rounding errors when dealing between fractional glyph coordinates and integer pixels when placing the glyph on the glyph texture. The rendering code at runtime is relatively simple...
Thanks so much for your help! |
With your current method,... |
It makes no difference at the end of the day - the values were pretty much the same. What I have found is that I'm having some vertical alignment issues because I used the typeface bounds to work out the pixel scale -- this was causing issues at game runtime with vertical centering - the glyphs were always higher than where I expected. I found that I had to calculate the typeface bounds by stepping through only the printable glyphs (or the subset of glyphs that I'm using for that language) and calculate the pixel scale from those bounds instead of the whole typeface... some of the ascender and descender values in the typeface were pretty large, and skewing the bounds results (resulting in my typeface being higher or lower in relation to where I expected it to be). I know this is the wrong way to think about it, and I really should go back and rethink how I'm doing runtime rendering, but I'm slammed with other tasks right now. I'll deal with it later. (for example, if I were to add additional new glyphs that might have disproportionately large ascenders or descenders, it affects the vertical alignment of the whole font) |
@hexland 👍 Thank you! :) |
Any idea when you'll be implementing Vertical Metrics support in OpenFont?
The text was updated successfully, but these errors were encountered: