resvg-js
resvg-js copied to clipboard
feat: add font resolve support and builder api
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 aubuntu mono
font, it would just fail.
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) |
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.
looking forward to this pr