-
Notifications
You must be signed in to change notification settings - Fork 71
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
Getting the number of faces #126
Comments
What about this function? https://docs.rs/ttf-parser/latest/ttf_parser/fn.fonts_in_collection.html |
Thanks! I'm afk, but seems like that's what I have been missing, will submit a small docs clarification soon. Do you know how efficient is the iteration over all faces? Does it cause a re-parse, or worse, require a clone of the original data on each face retrieval? |
It just reads the first few bytes of the face to determine if it's a font collection and then how many fonts are in it. It's as cheap as cheap can be. |
@notgull sadly, it seems the story is a bit more complex. You are absolutely correct that |
Forgive me if I'm misunderstanding, but if you've already passed the font data into an I feel like this is an XY problem. Do you have more information on what you're trying to do? |
@nyurik I have no relation to I'm not sure what you're trying to do, but just in case you have to understand that faces in a font collection are not independent. They can reference the same TrueType tables. That's the whole point. |
@notgull and @RazrFalcon thank you so much for a quick reply! I am the maintainer of Martin tile server (maps), and trying to add dynamic font generation support using sdf_font_tools crates. Users of Martin will ask for one or more fonts, e.g. HTTP During startup, I need to iterate over all available fonts and their faces, discover available glyph codepoints and store them as bit-sets. On request, I will iterate over the combined bitset for the requested codepoint range, generate needed SDF images for glyphs and send them to the client. Eventually I may pre-cache SDF images at a significantly higher memory requirements. Currently, sdf_font_tools uses freetype-rs bindings, and I don't even have a way to iterate over available glyphs - instead I brute-force it with I would like to switch to a Rust-based font parsing/rendering stack, and hence the rusttype lib which uses ttf-parser. |
You may want to look into |
I don't think you need The typical
You should not keep |
@RazrFalcon do you know why rusttype uses owned_ttf_parser? I presumed it is the Rust re-implementation of the freetype-rs. Here's the code that actually calls freetype face rendering functions - is this something i can do directly from ttf-parser, or do i need a separate lib for that?
|
Maybe they find it easier. Idk. The only thing missing from PS: I think you're optimizing for a non-existing case. |
If memory serves |
Thanks, I wasn't aware rusttype was semi-dead. Both |
If I recall correctly, |
|
It seems there is currently no way to find out how many faces a font file has. The relevant code reads it internally, but I do not see any way to access this info. In
freetype-rs
, there is a method to get the face count after the index-0 face has been loaded. While not ideal, it seems like this is an OK solution here as well? Also, perhaps there could be a way to not re-parse the metadata, but instead have a way to iterate over all faces, yielding one face at a time?https://github.com/RazrFalcon/ttf-parser/blob/ba2d9c8b9a207951b7b07e9481bc74688762bd21/src/lib.rs#L666-L671
The text was updated successfully, but these errors were encountered: