vercel / satori

Enlightened library to convert HTML and CSS to SVG
https://og-playground.vercel.app
Mozilla Public License 2.0
10.95k stars 240 forks source link

Switch to Harfbuzz #83

Open shuding opened 2 years ago

shuding commented 2 years ago

Satori currently relies on OpenType.js to parse font tables and generate the glyphs. I’m considering switching to Harfbuzz in the future because it supports a couple of more complex scripts and OpenType features. It can also improve the performance a bit as it’s a WASM port.

Pretty low priority at the moment as we need to improve the typography algorithm first.

shuding commented 2 years ago

Looks like the correct way to go in the future:

CleanShot 2022-08-22 at 16 31 43@2x

https://twitter.com/KhaledGhetas/status/1548752758282534913

jlarmstrongiv commented 1 year ago

@shuding how would you workaround the limitations of Harfbuzz, such as line breaking?

devongovett commented 1 year ago

You could also try fontkit, which is a pure JS implementation supporting complex scripts. It powers pdfkit.

There's also textkit for handling higher level text layout (eg line wrapping, font substitution, etc.). That's used by react-pdf.

I'd highly recommend looking into some of these libraries and how they do text layout, because it is extremely complicated (especially with non-English text). Back when react-pdf was investigating this, I wrote this comment explaining the whole text layout process - maybe it's helpful to you. https://github.com/foliojs/pdfkit/issues/783#issuecomment-366893412

shuding commented 1 year ago

Thanks again for the pointers @devongovett! I actually looked into fontkit before picking opentype.js (because it's smaller, seems like a wrong choice lol), and actually read a lot of your comments from everywhere (thank you again!), and I understand the complexibility of this. Hence the first phase of this project is to support only basic text layout and font features.

Anyways, this is definitely our top priority!

LuciNyan commented 1 year ago

@shuding how would you workaround the limitations of Harfbuzz, such as line breaking?

Thank you for sharing this!