-
Notifications
You must be signed in to change notification settings - Fork 21
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
Is it unsound to perform text shaping while an OutlineBuilder exists? #72
Comments
|
The actual implementations of OutlineBuilder require borrowing a bunch of data obtained from the DynamicFontTableProvider |
Right it seems that I was misunderstanding your question. Normally you would not be able to call If so, shaping currently mutates the
As you pointed out in #52 the library is not currently well structured for this type of use. The API evolved for our use case which is load a bunch of fonts, shape the text, and then generate a PDF. I'm not sure if/when we'll be able to dedicate the time to remedying that. |
I'm saying that it's definitely unsound because there are aliasing mutable references which is forbidden.
This is kind of sad, because |
Perhaps a silly idea: what if you parsed the font twice and used one instance for the |
I had this idea once but I actually forgot to try it. This will probably work. In fact, I don't see any reason why it wouldn't. The data structures returned by a call to shape do not contain any references to the font, and therefore can just be... transferred. However you want. This can be used to cause panics and crashes and unexpected behavior... or it can be used for performance. I'm definitely going to try implementing that now, thank you! |
@wezm Is it possible for |
If the compiler allows it then there shouldn't be any safety issues. |
dang, DynamicFontTableProvider and its darn Box. probably should get rid of that one day |
In order to get an OutlineBuilder, you have to do some parsing using the font's FontTableProvider. This means the OutlineBuilder borrows from the FontTableProvider, which means it borrows from the Font.
Then, if you need to shape some text, you need to... call
Font::shape
which takes&mut self
.This is aliasing a mutable reference with preexisting shared references.
That means the most obvious low-hanging-fruit for caching (obtaining the OutlineBuilder up-front at load time) is unsound.
I did not notice this because I have to use piles of unsafe code to store the font and related data in a pinned struct. Therefore the borrow checker is significantly inhibited. see #52
Now that I think about it, it seems like a huge API issue, as well as a performance issue. Parsing tables to get an OutlineBuilder each frame in a game for example (required not to violate the borrowing rules), sounds like a huge problem.
The text was updated successfully, but these errors were encountered: