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

Support for user-provided font loading callbacks #769

Merged
merged 9 commits into from
Jun 1, 2024

Conversation

laurmaedje
Copy link
Contributor

@laurmaedje laurmaedje commented Jun 1, 2024

This PR adds support for user-provided font loading callbacks.

Here is small overview of the changes:

  • The Options now contain an Arc<Database> and a new FontResolver<'a>. The fontdb arguments on other top-level functions were removed.
  • The ImageHrefResolver is now ImageHrefResolver<'a> (since it might as well). With the default resolvers, you just get Options<'static>.
  • The resolver functions take &mut Arc<Database>, so they can mutate the database with Arc::make_mut if necessary, but if they don't need to add a font, we don't force the database to be cloned.
  • For each tree conversion, we have an Arc<Database> in the Cache, which is populated over the course of conversion. It is only cloned if fonts are actually added.
  • The database from the Cache is moved into the Tree after conversion and users can access it with tree.fontdb() to make sense of the IDs in their Spans.
  • Sub-SVGs start with a fresh database from the Options, but share the same resolver.
  • The database in the Options is never mutated (it's &Options after all)

One small change in fontdb is necessary to make writing a custom FontResolver possible, or at least convenient: The best function to add a new font is push_face_info, but it doesn't return the new ID it assigned. I've opened RazrFalcon/fontdb#66 to change that. As it is a breaking change, resvg would need to update to a new release of fontdb. (Alternatively, we could make it non-breaking with a new function.)

Supersedes #754

@laurmaedje laurmaedje changed the title Arc database Support for user-provided font loading callbacks Jun 1, 2024
@RazrFalcon
Copy link
Collaborator

Bumped fontdb

@laurmaedje
Copy link
Contributor Author

Bumped fontdb

Thanks, that was quick! Since this PR doesn't directly depend on the fontdb changes (only users need it), the dependency can be updated separately from this PR, but if you want I can also update it here.

@RazrFalcon
Copy link
Collaborator

Let update fontdb as well.

@laurmaedje
Copy link
Contributor Author

Done

@RazrFalcon RazrFalcon merged commit 0b33ace into linebender:master Jun 1, 2024
3 checks passed
@RazrFalcon
Copy link
Collaborator

I guess we're ready for a new resvg release?

@LaurenzV
Copy link
Contributor

LaurenzV commented Jun 1, 2024

More than ready! 😄

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

Successfully merging this pull request may close these issues.

3 participants