-
Notifications
You must be signed in to change notification settings - Fork 37
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
Shape plan caching #87
Comments
Sure. The only thing stoping me is time. |
I think exposing it and letting consumers handle the cache is good. I'll look into how we can check whether the font matches and make a PR next week. |
Hey @laurmaedje - are you working on a PR? In a project of mine, In terms of handling mismatches between the plan and the face provided as an argument to
Thoughts? |
@vorporeal 1 and 2 probably would not work, since we have to figure out how to differentiate fonts to begin with. Which is kinda impossible at the moment. |
@vorporeal Feel free to, I didn't really get to it. @RazrFalcon Storing What's the main concern here? That rustybuzz will panic or that it will shape garbage? If it's just the latter, I think it's not a big deal and user error. |
Agreed that if it's just a matter of garbage in, garbage out, then it's reasonable to push the responsibility of avoiding mismatch issues onto the caller and clearly document that in the API. |
I honestly don't know. Garbage is the best case scenario. Crash in the worst. Hard to tell. Someone has to test it. Moving responsibility to the user is unfortunate, but I have no idea how to handle it otherwise. We cannot really guarantee font uniqueness otherwise. |
What we do in HB, which is probably not feasible in Rust, is that the shape_plan keeps a pointer (but no reference) to the face, and just double-checks that they two match. It's a heuristic only. |
I think in HB it won't crash if you use the wrong shape-plan, just garbage. But I'm not sure. |
I can do some manual testing today and see whether I can produce any panics. |
Ran a quick test using forked versions of Correct rendering: Rendering with a single At least for my two simple tests (I ran another with English+Hebrew), improper In terms of implementation, I landed on this: pub fn shape_with_plan(
face: &Face,
features: &[Feature],
plan: &mut Option<ShapePlan>,
buffer: UnicodeBuffer
) -> GlyphBuffer {
...
}
For example: let shape_plan = match shape_plan_cache.entry(font.id()) {
Entry::Occupied(occ) => occ.into_mut(),
Entry::Vacant(vac) => vac.insert(None),
};
let glyph_buffer = rustybuzz::shape_with_plan(font, &[], shape_plan, buffer); It's a bit unusual for Rust, but I felt it was better than exposing a |
This requires mutable access to the shape plan. Personally, I would prefer it to take a manually constructed |
Yeah, good point. In terms of cache keys - the |
@vorporeal I would suggest simply exposing the current
|
Sounds good. Is there a reason you're not including the |
I guess we have to store them in |
#88 is the PR I made based on the above discussion. |
I suppose this issue can be closed then? |
Yep! |
Shape plan caching was dropped during the port. However, in some experiments I did a while ago, creating the shape plan was a nontrivial amount of the work done. Looking at the definition of
fn shape
, it seems to be trivial to offer anfn shape_with_plan
API and exposeShapePlan::new
. What do you think?The text was updated successfully, but these errors were encountered: