在 web 和 gpui 中实现印刷级别的字体排版精度
前几天看到 @imeoer 大佬用 gpui 写 markdown editor,正好有个老的 web 英文排版项目特别适合移植到 gpui。跟 web 相比,rust 可以读取字体文件的元数据,能做的更多,也更适合。
原理是通过读取字体度量表中的 ascent、descent 与 units-per-em 推导字体的 baseline ratio,计算当前字号的基线的偏移量,然后将文本基线对齐到 vertical rhythm 的网格上,实现印刷排版级别的精度。并且不同字体、不同字号混合排版,drop cap 等等都能轻松处理。

项目地址:[https://github.com/p233/rhythm-gpui](https://github.com/p233/rhythm-gpui)
原 sass 版本也一并做了更新,地址:[https://github.com/p233/rhythm-sass](https://github.com/p233/rhythm-sass)
有写 markdown editor 的一些设想,下周尝试一下,能走通就继续,走不通就放弃。
---
原文链接:[点击查看](https://www.v2ex.com/t/1234685)
原理是通过读取字体度量表中的 ascent、descent 与 units-per-em 推导字体的 baseline ratio,计算当前字号的基线的偏移量,然后将文本基线对齐到 vertical rhythm 的网格上,实现印刷排版级别的精度。并且不同字体、不同字号混合排版,drop cap 等等都能轻松处理。

项目地址:[https://github.com/p233/rhythm-gpui](https://github.com/p233/rhythm-gpui)
原 sass 版本也一并做了更新,地址:[https://github.com/p233/rhythm-sass](https://github.com/p233/rhythm-sass)
有写 markdown editor 的一些设想,下周尝试一下,能走通就继续,走不通就放弃。
---
原文链接:[点击查看](https://www.v2ex.com/t/1234685)
· 0 个赞