Skip to content
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

API Clarifications #2

Closed
weichx opened this issue May 31, 2020 · 2 comments
Closed

API Clarifications #2

weichx opened this issue May 31, 2020 · 2 comments

Comments

@weichx
Copy link

weichx commented May 31, 2020

A few things came up for me when trying to use this package and I was hoping someone could lend a hand. I'm using the JSON output and am confused about the planeBounds and atlasBounds fields. I think atlas bounds are the pixel space coordinates in the texture for a given glyph and I can calculate uvs using atlasBounds divided by atlas dimensions. Is this correct?

Secondly I have no idea what planeBounds is for, I was looking for a description in the docs but didn't see anything. Could you give me a quick explaination?

Lastly, I'm trying to figure out the relationship between emRange, pixelRange, and size in ems. What I'd like to do is generate a font at a given point size but after tinkering a while I didn't figure out how to do this, could you please point me in the right direction?

Thanks! By the way I'm really impressed with the atlas generation performance, Unity's TextMeshPro takes up to 30 seconds to build an atlas but msdf-atlas-gen is around 100ms for the same font.

@Chlumsky
Copy link
Owner

You are correct about atlasBounds, by dividing by the atlas dimensions, you get the texture coordinates. The planeBounds are for positioning the glyphs in the output "plane" (I couldn't come up with a better term), that is, where to put the textured rectangle when typesetting the text, relative to the baseline "cursor" that then moves by advance to the right. This tells you for example that the character y should be positioned lower than Y even though they might have similar height.

As for the units, font size (-size) is specified as pixels per EM, the size of an EM is taken from the font file's metadata, and this should be the same as the px font size unit in CSS. I believe the conversion rate for point size is simply 1px = 0.75pt, so you just have to multiply your point size by 4/3. The -emrange and -pxrange values specify the width of the range of representable distances in either unit, I am not sure what is unclear about these.

@weichx
Copy link
Author

weichx commented May 31, 2020

Great, that's really helpful and should be enough for me to continue working with this. Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants