-
Notifications
You must be signed in to change notification settings - Fork 60
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
Why ttf_parser::Face need a lifetime? #37
Comments
You should use owned-ttf-parser instead.
No. ttf-parser parses the font parts on demand. Parsing the whole font into the memory is absurd and no one is doing this. The lifetime is required, since |
Hey @RazrFalcon , #[derive(Resource, Default)]
pub struct FontCacheRes {
font_content: HashMap<u64, CachedFont>,
}
#[derive(Default)]
pub struct CachedFont {
pub content: Vec<u8>,
// https://github.com/RazrFalcon/ttf-parser/issues/37
// pub face: Option<Face>, // TODO: Cache Face?
pub font: Font,
}
impl CachedFont {
// pub fn get_or_create_face(&'a mut self) -> &'a Face<'a> {
// if self.face.is_none() {
// self.face = Face::from_slice(&self.content, 0);
// }
// self.face.as_ref().unwrap()
// }
} Given the lifetime requirements of Thanks :) |
As the comment above mentioned - just use owned-ttf-parser. And yes, depending on your performance requirements you might be fine with re-parsing the |
thanks for the quick reply 🙏 Can I use |
Yes. |
Thanks for the quick information. I'll explore both caching and not caching the Face to see what works best for my SVG text rendering project. Also, a big thanks for developing rustybuzz & ttf-parser – it looks like a great fit for my needs 👍🙏 |
https://github.com/RazrFalcon/ttf-parser/blob/master/src/lib.rs#L580
It seems Face need reference the bytes for a long time.
I can not understand of the lifetime here, why it is necessity?
Is font parse not one-time action?
For this reason, I can't simply define a struct attr like:
This puts a lot of restrictions on the code design.
But i really can't figure it out.
The text was updated successfully, but these errors were encountered: