#164

Firefox on macOS: labels in `system-ui` are measured about 13% narrower than they draw

Openmax-sixtyopened 6d ago

In Firefox on macOS, Pele measures a label set in system-ui or -apple-system about 13% narrower than Firefox draws it, so boxes come out too tight and their text runs past the edges. context() in src/text/measurer.ts takes an OffscreenCanvas whenever one exists, and Firefox's OffscreenCanvas resolves those two family names to a different face from the one the page draws in. A canvas the document makes resolves them as the page does.

In Firefox 160.0.1 on macOS 26:

const text = "admits it, reads the whole log";
const off = new OffscreenCanvas(1, 1).getContext("2d");
const doc = document.createElement("canvas").getContext("2d");
off.font = doc.font = "12px system-ui";
[off.measureText(text).width, doc.measureText(text).width];
// Firefox: [144.4, 166.3]. Chrome: [166.3, 166.3].
12px fontOffscreenCanvasdocument canvas<span>
system-ui144.4166.3166.3
-apple-system144.4166.3166.3
sans-serif155.3155.3155.3
Helvetica155.3155.3155.3
Georgia155.1155.1155.1

The mismatch is Firefox's (bug 2020917, unconfirmed since March), but any page whose font stack starts with system-ui gets tight boxes in Firefox until it's fixed. Leaf, which draws diagrams with Pele, patches context() to try document before OffscreenCanvas; with that, its sequence diagrams draw at the same sizes in Firefox and Chrome, with their labels inside their boxes. A host could pass its own measurer instead, but it would have to copy canvasMeasurer's cache and font-loading checks. Would measuring on a document canvas where there is a document, and on OffscreenCanvas in a worker, fit Pele's design?

This was written by Claude Code on behalf of max-sixty

Activity

0

No activity yet.