-
Notifications
You must be signed in to change notification settings - Fork 229
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
Render text in wasm32-unknown-unknown #229
Comments
Believe me, I know =) https://github.com/RazrFalcon/rustybuzz
The harfbuzz dependency is mandatory. I do not plan reducing text rendering to Latin only, since this is against the SVG spec. Anyway, Rust version will be way smaller.
In your code or in usvg? Because usvg does this too. Basically, the resvg 0.10 roadmap looks like this:
|
In usvg; I meant that I'm calling usvg::Tree::from_str repeatedly, which loads fonts everytime. It sounds like resvg 0.10 will exactly make wasm work. Let me know how I can help! |
Yes, resvg/usvg were focused on correctness, spec conformance for now. And since I'm almost finished with the spec, I can start optimizing it bit by bit. Right now, I'm implementing a zero-allocation variable fonts support in |
HarfBuzz builds to WASM just fine, I have been using it for months, see https://github.com/harfbuzz/harfbuzzjs |
Oh? I'm not too familiar with the wasm/Rust interop, but there may be some way to get https://crates.io/crates/harfbuzz-sys to expose the JS bindings. I'd personally prefer a pure Rust stack, so the work on rustybuzz is awesome. |
@RazrFalcon, I got text support in web working for the simple Latin LTR case, to unblock getting my project on the web. Before Rustybuzz is complete, do you think it's worth exposing this functionality to all users of usvg? The change is reasonably small: dabreegster@97ff395 and dabreegster/fontdb@04c8ffc. I can send PRs if you'd like. If it muddies up the API too much, I'm fine just pinning to my fork temporarily. |
No, I thinks that a fork is the best solution for now. As for rustybuzz, I have no idea when it became pure Rust. Sadly, I don't have time right now to work on it. |
I guess it's fixed now. |
Congratulations on the rustybuzz release! There are a few small build changes to fontdb and usvg to avoid native dependencies like memmap; I'm preparing PRs now. |
Oh, I've forgot about it. Since I've done with huge rewrites (tiny-skia, rustybuzz), I hope to release resvg/usvg more often. |
"usvg currently works great in wasm environments as long as the optional "text" feature is disabled." |
@DerKarlos Can you clarify what you want to do? |
Thank you for your fast replay! |
The issue is fixed; usvg works just fine in wasm now. You need to disable the system-fonts feature. Something like this should help. If you want to see a quick demo of usvg rendering text on wasm, see here. |
That sounds good. But sorry, I am new to Rust and what ever I try, at last memmap2 gets used by wasm-pack and: The demo looks good but where to find the source? Or any example (with an Cargo.toml) to read SVC and write it to a byte array? |
I assume this is what you want.
|
Hm? To build my project, I use |
https://github.com/a-b-street/abstreet/tree/master/widgetry_demo, and the
Is your repository online? No promises, but easier to help looking at your specific issue. |
You may see my code, I send you an invite. |
Thanks for the invitation, I'll take a look when I find time. The demo crate pulls in the |
Sorry, I still don't see a way. The crux may be the tiny_skia. Your examples are just the "main.rs", no how to build. Bin is no problem but could you please add the files to build to WASM and how to call carto? |
usvg currently works great in wasm environments as long as the optional "text" feature is disabled. I'd love to get text support working too. From my understanding so far, there are at least 3 issues:
The first two are relatively straightforward. As part of #202, design an API to feed a FontDB into usvg that can be instantiated many different ways, one of them just being raw bytes of a font file. (include_bytes! is a low-effort way to get this working in a wasm environment.)
The harfbuzz dependency seems harder. My requirements are limited to simple Latin left-to-right text; harfbuzz is overkill. I found font2svg and think it might be possible to make something much simpler. Before I go down this rabbit hole, I wanted to ask for your advice.
Background
I'm using usvg in A/B Street to turn both normal SVG files and text into paths for lyon, which then give me polygons. This does the usvg->lyon->my simple Polygon abstraction path, based off this example from lyon. I'm using this same pipeline for text as well. (There are many inefficient and silly things that the text pipeline does right now, like constantly re-load fonts.) In a few weeks, I'm hoping to properly split off my drawing, geometry, and GUI libraries as new crates for other people to use. These libraries attempt to give exactly the same experience on native and web -- not using system UI controls/style -- without any changes to user code needed for different platforms.
The text was updated successfully, but these errors were encountered: