Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly position font baseline and line-height (#599)
This patch changes logic how baseline and line-height are calculated, to match what browsers do and tools like Figma. This is especially noticeable on font IBM Plex Sans due to how its metrics are set up. It was less noticeable on Inter, because previous calculations somehow arrived at almost correct numbers. Implementation notes: - `useOS2Table` is removed, because it’s not what browsers/Figma seem to be using - yMax, yMin are not used in text positioning at all - lineHeight is calculated before as a fraction of fontSize, so height just recalculates it back Before: ![Screenshot 2024-03-06 at 19 12 12](https://github.com/vercel/satori/assets/285292/dbe5cacf-4839-4d3b-9c9d-cabd8eb189eb) After: ![Screenshot 2024-03-06 at 19 12 35](https://github.com/vercel/satori/assets/285292/467012bb-16cc-45e5-bc7e-34cc9e59f2fb) Background blue/orange text is a static PNG rendered with Figma, black text is rendered with Satori. Should solve #577 References: https://iamvdo.me/en/blog/css-font-metrics-line-height-and-vertical-align ![Screenshot 2024-03-06 at 19 22 47](https://github.com/vercel/satori/assets/285292/3215bc2f-8bee-4785-a30e-2868255bc63b) And https://www.figma.com/blog/line-height-changes/: ![Screenshot 2024-03-06 at 19 27 16](https://github.com/vercel/satori/assets/285292/92aa7800-74cd-4e08-a167-e3e34ac02abf) Background image (if needed): https://github.com/vercel/satori/assets/285292/3c8d6a75-cdca-4774-b285-7bd64bae51ee
- Loading branch information