yeslogic / allsorts

Font parser, shaping engine, and subsetter implemented in Rust
https://yeslogic.com/blog/allsorts-rust-font-shaping-engine/
Apache License 2.0
706 stars 23 forks source link

Provide a mechanism to configure the tables included when subsetting #61

Open wezm opened 2 years ago

wezm commented 2 years ago

The subsetting functionality was originally driven by the needs of embedding fonts in PDFs in Prince. In this context a number of tables are not required due to being handled by the PDF document or by processing that done as part of generating the PDF.

Ideally we'd like the subsetting functionality to be useful outside the PDF context as well. This will necessitate including all tables required by OpenType. At the same time we don't want to unnecessary increase the size of our customers PDFs by including unnecessary tables. So, there needs be a way to control the tables that are included when subsetting fonts in order to support both use cases. I'm imagining this would be implemented along these lines:

  1. The subsetting function accepts a list of tables to include in the output font.
  2. There is a pre-defined list of tables that can be supplied to produce a valid OpenType font. We could define our own predefined list of tables for use with Prince.

E.g.

const MIN_OPENTYPE: &[u32] = [tag::HEAD, tag::MAXP, …];

fn subset(
    provider: &impl FontTableProvider,
    glyph_ids: &[u16],
    tables: &[u32]
) {
    ⋮
}