Open
Description
Goals
- Accurate font selection: OS APIs don't guarantee a registered font will be used. This finally fixes a huge pain point.
- Ability to register fonts from a buffer: should be possible without Pango
- Performance: This should be faster than going through Pango.
- Reduce dependencies: Pango brings in a lot, and we don't need most of its functionality (e.g. there's no wrapping in canvas).
- Context-aware (make module context-aware #1394): registered fonts will be associated with the module instance.
- Fast and native: this will all be done in C++
- Static build: HarfBuzz and SheenBidi are easy to build, so we could add a
vendor
folder
Non-goals
- Only OpenType will be supported
- Not going to cache shaping results
Changes
- Native
font
parser that can be used byFontFace
: Native font parser #2475 - HarfBuzz-based font stack (see below). This is the biggest part.
- Change API: implement only the relevant parts of CSS Font Loading Module Level 3 (
FontFace
andCanvas.fonts
) - New API:
ctx.fillGlyphs
. This is actually my biggest goal because it will significantly speed up dropflow and libraries like it.
HarfBuzz-based font stack
Without Pango, we need to write a lot:
- Script segmentation: use dropflow's trie writer. Reading it is easy to do in C++. Port the logic from dropflow.
- Bidi segmentation: use SheenBidi and port dropflow's logic.
- Emoji segmentation: could skip for first version if emojis work well enough, but also port from dropflow and add ragel to build.
- System fonts: walk entries in the OS and add to our own db, hopefully avoiding
open()
. Port from Pango and/or use LLMs. - Font selection: port this from dropflow, which implements it as specified by W3C. Use HarfBuzz to read font tables.
- Font shaping: grapheme-based font fallbacks, bidi reordering, format for
cairo_show_glyphs
. Also update metrics functions.