Skip to content

fix(glyph): let bake pass options to a technique - #118

Merged
thejustinwalsh merged 2 commits into
mainfrom
fix/bake-technique-options
Aug 26, 2026
Merged

fix(glyph): let bake pass options to a technique#118
thejustinwalsh merged 2 commits into
mainfrom
fix/bake-technique-options

Conversation

@thejustinwalsh

@thejustinwalsh thejustinwalsh commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

glyph bake hard-codes options: undefined for every technique except Bitmap, so a technique's own bake parameters are unreachable from the CLI. The bakers accept them; the CLI never passes any.

if (options.msdf) {
  const { msdfBaker } = await import('../bakers/msdf.js');
  rasters.push({ baker: msdfBaker, packaging, options: undefined });   // <-
}

Bitmap is the only technique whose parameter arrives, and only because --bitmap 16,32 encodes it positionally. --help documents --msdf as "Embed the default MSDF raster" — the default being the only thing on offer.

What this changes

--msdf now takes optional settings, in the same shape as --bitmap's strike list. A bare --msdf still means the defaults, so nothing existing changes behaviour.

glyph bake --input Inter-Regular.ttf --output inter.font.glb --msdf em-size=32
glyph bake --input Inter-Regular.ttf --output inter.font.glb --msdf em-size=32,pixel-range=6

Slug is untouched: SlugBakerOptions is undefined, so it genuinely has none of its own.

Why it matters

emSize defaults to 64 atlas texels per em, and atlas cost is area, so a face set for small copy pays several times over with no way to say so. Measured on the same six Telugu glyphs:

artifact
--msdf (em-size 64) 606,604 bytes
--msdf em-size=32 153,692 bytes
--msdf em-size=24,pixel-range=6 95,304 bytes

Quadrupling the atlas area quadruples the artifact, exactly as expected — and 64 was more than twice what a page setting at 28 css px can show. Across a 20-face multi-script set the difference was 4.64 MB → 1.33 MB.

Note for consumers

Raster options are part of the raster identity. A runtime request naming different options than the artifact was baked with derives a different rasterKey, finds no matching raster, falls back to runtime generation, and fails with RASTER_SOURCE_UNAVAILABLE. Both sides have to name the same values — worth a line in the docs.

Design discussion in #117.

directRasterPlans hard-coded options: undefined for MSDF and Slug, so a
technique's own parameters were unreachable from the CLI. Bitmap was the
only one whose parameter arrived, and only because --bitmap encodes its
strike list positionally.

--msdf now takes em-size and pixel-range, parsed and passed to the baker,
and a bare --msdf still means the defaults. Slug takes none of its own
(SlugBakerOptions is undefined), so it is unchanged.

The default em size is 64 atlas texels, and atlas cost is area, so a face
set for small copy pays several times over with no way to say so: one
multi-script set of 161 code points came to 4.64 MB, where a Telugu face
shipped 592 KB for six glyphs. At em-size=32 the same set is 1.33 MB.
@thejustinwalsh thejustinwalsh changed the title fix/bake technique options fix(glyph): let bake pass options to a technique Aug 25, 2026
@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
Core JS (gzip) 22.55 KB (0%)
Shaper Wasm (gzip) 431.37 KB (0%)
Three.js adapter JS (gzip) 89.23 KB (0%)
Inter font · Bitmap (gzip) 545.27 KB (0%)
Inter font · MTSDF (gzip) 6.48 MB (0%)
Inter font · Slug (gzip) 604.06 KB (0%)
Font Awesome icons · Bitmap (gzip) 439.53 KB (0%)
Font Awesome icons · MTSDF (gzip) 6.89 MB (0%)
Font Awesome icons · Slug (gzip) 642.64 KB (0%)
Font validator JS (gzip) 134.24 KB (0%)
Runtime bake host JS (gzip) 5.41 KB (0%)
Runtime bake Worker JS (gzip) 142.47 KB (0%)
Font baker JS (gzip) 2.41 KB (0%)
Font baker Wasm (gzip) 379.63 KB (0%)
Bitmap baker JS (gzip) 4.66 KB (0%)
Bitmap baker Wasm (gzip) 228.34 KB (0%)
MTSDF baker JS (gzip) 5.39 KB (0%)
MTSDF baker Wasm (gzip) 209.22 KB (0%)
Slug baker JS (gzip) 4.01 KB (0%)
Slug baker Wasm (gzip) 181.26 KB (0%)

@thejustinwalsh
thejustinwalsh marked this pull request as ready for review August 26, 2026 02:36
@thejustinwalsh
thejustinwalsh merged commit f08a90c into main Aug 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant