4 ms·
Nice work! The other day I was doing a SVG renderer for Shiki[0] (a code syntax highlighter), but found no easy way to measure font width/height (SVG needs abso
by octref 6y ago
Nice work! The other day I was doing a SVG renderer for Shiki[0] (a code syntax highlighter), but found no easy way to measure font width/height (SVG needs absolute positioning) in Node.js. The only library that does that records fonts' metadata in the package source[1].
I ended up using puppeteer[2]. Would love to switch to `skia-canvas`, however `ctx.measureFont` doesn't seem to work correctly yet. Measuring cap `M` produces positive `actualBoundingBoxDescent`, although `M` should sit comfortably on top of baseline.
[0]: https://shiki.matsu.io/ https://shiki.matsu.io/
[1]: https://github.com/adambisek/string-pixel-width https://github.com/adambisek/string-pixel-width
[2]: https://github.com/shikijs/shiki/blob/master/packages/renderer-svg/src/measureMonospaceTypeface.ts https://github.com/shikijs/shiki/blob/master/packages/render...