Skip to content

Font stack rewrite #2476

Open
Open
@chearon

Description

@chearon

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 (make module 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: HarfBuzz and SheenBidi are easy to build, so we could add a vendor folder

Non-goals

  1. Only OpenType will be supported
  2. Not going to cache shaping results

Changes

  1. Native font parser that can be used by FontFace: Native font parser #2475
  2. HarfBuzz-based font stack (see below). This is the biggest part.
  3. Change API: implement only the relevant parts of CSS Font Loading Module Level 3 (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. Script segmentation: use dropflow's trie writer. Reading it is easy to do in C++. Port the logic from dropflow.
  2. Bidi segmentation: use SheenBidi and port dropflow's logic.
  3. Emoji segmentation: could skip for first version if emojis work well enough, but also port from dropflow and add ragel to build.
  4. System fonts: walk entries in the OS and add to our own db, hopefully avoiding open(). Port from Pango and/or use LLMs.
  5. Font selection: port this from dropflow, which implements it as specified by W3C. Use HarfBuzz to read font tables.
  6. Font shaping: grapheme-based font fallbacks, bidi reordering, format for cairo_show_glyphs. Also update metrics functions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions