Automattic / Automattic/node-canvas

Font stack rewrite

Open
#2,476 0 comments 1 reaction 0 assignees View on GitHub
Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

### Goals

1. **Accurate font selection**: OS APIs don't guarantee a registered font will be used. This finally fixes a huge pain point.
2. **Ability to register fonts from a buffer**: should be possible without Pango
3. **Performance**: This should be faster than going through Pango.
4. **Reduce dependencies**: Pango brings in a lot, and we don't need most of its functionality (e.g. there's no wrapping in canvas).
5. **Context-aware** (#1394): registered fonts will be associated with the module instance.
6. **Fast and native**: this will all be done in C++
7. **Static build**: since we rid ourselves of so many system deps, this is the time to move to `zig build`
### Non-goals

1. Only OpenType will be supported
2. Not going to cache shaping results
3. We're going to have to drop SVG support, at least for the short-term

### Changes

1. [x] Native `font` parser that can be used by `FontFace`: #2475
2. [x] HarfBuzz-based font stack (see below). This is the biggest part.
3. [x] Change API: implement only the relevant parts of [CSS Font Loading Module Level 3](https://www.w3.org/TR/css-font-loading/) (`FontFace` and `Canvas.fonts`)
4. [ ] 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:

1. [x] **Script segmentation**: use dropflow's trie writer. Reading it is easy to do in C++. Port the logic from dropflow.
2. [x] **Bidi segmentation**: use SheenBidi and port dropflow's logic.
3. [x] **Emoji segmentation**: could skip for first version if emojis work well enough, but also port from dropflow and add ragel to build.
4. [x] **System fonts**: walk entries in the OS and add to our own db, hopefully avoiding `open()`. Port from Pango and/or use LLMs.
5. [x] **Font selection**: port this from dropflow, which implements it as specified by W3C. Use HarfBuzz to read font tables.
6. [x] **Font shaping**: grapheme-based font fallbacks, bidi reordering, format for `cairo_show_glyphs`. Also update metrics functions.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.