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

feat: add font resolve support and builder api #118

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

zimond
Copy link
Collaborator

@zimond zimond commented Jun 17, 2022

fixes #101 #115

The idea is to add a new ResvgBuilder type, which does all the pre-resvg resolving stuff. Behind the scene it uses the xml reader which resvg uses and find all text nodes, try to gather font information of them (by using a naive ancestor-inheritance logic) and output all fonts needed via a new api texts_to_resolve().

Users could use this new api to get whatever font they have which satisfies the given font key, and call resolve_font(buffer) to feed the font buffer to the builder.

Later on, builder will uses these fonts to construct the font_db::Database instance so that the texts will not be eliminated by resvg/usvg.

Some drawbacks:

  • This font attributes tracking logic is not perfect, e.g. CSS will not be parsed. Even though the logic in usvg is also not perfect, the impl in this PR is worse.
  • Using fonts that don't meet the query is not supported. E.g. if the SVG wants monospace and you want to render it by providing a ubuntu mono font, it would just fail.

@vercel
Copy link

vercel bot commented Jun 17, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
resvg-js ✅ Ready (Inspect) Visit Preview Jul 15, 2022 at 3:31AM (UTC)

@zimond
Copy link
Collaborator Author

zimond commented Jun 17, 2022

Ideally all the drawbacks mentions above could be fixed by using a dirty hack and heavily manipulate the file before feeding to usvg, but the code will end up be too similar to sillyvg and I'm afraid I cannot opensource it right now.

@shtse8
Copy link

shtse8 commented Jul 20, 2022

looking forward to this pr

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.

Feature request: support loading fonts with raw data
2 participants