tldraw / tldraw

whiteboard / infinite canvas SDK
https://tldraw.dev
Other
35.85k stars 2.21k forks source link

[Feature]: Embedded Fonts Should Only Include Necessary Data For Used Character Set #4145

Open seflless opened 4 months ago

seflless commented 4 months ago

What's the feature?

Tldraw currently embeds the entire font for each referenced in exported file. The files can become quite large because of this.

Eg. this simple Tldraw test file that uses all 4 built in fonts, generates a >400K svg file

Notes

Contact Details

francoislaberge@gmail.com

Code of Conduct

linear[bot] commented 4 months ago

TLD-2629 [Feature]: Embedded Fonts Should Only Include Necessary Data For Used Character Set

seflless commented 4 months ago

I did a quick test today using the subset-font package and it worked out of the gate. But it uses harfbuzzjs, which has a >500K .wasm file. This is a large dependency. Here's the test repo

I'm assuming ideally you'd want something built in that can run client side, perhaps it should be first built as an extra dependency people can opt-into for Tldraw?

seflless commented 4 months ago

The reduction in size was pretty dramatic.

The font went from 153KB to 4KB. My exported SVG file went from 209KB to 10KB.

mimecuvalo commented 4 months ago

I did a quick test today using the subset-font package and it worked out of the gate. But it uses harfbuzzjs, which has a >500K .wasm file. This is a large dependency. Here's the test repo

That's super neat. But yeah, that dependency size is prohibitively large :-/ I think you're right that it's something that should be opt-ed into. We're formulating slowly a plan on how to be able to opt into things in a generalized way so this type of behavior could also be something that fits in with that strategy.