oficina / docs Public

Hold the fonts to the screen in a browser, and fix Inter's kerning

The font browser checks run through the production middleware
(rastrillo.Handler with Docs' ServeOptions) with the font files slowed
down, and sample every frame and every DOM change from before the HTML is
parsed (go test -tags browser -run Font ./internal/docs/):

- text is never visible in a face that has not loaded;
- past the deadline it commits to its fallback, and stays in it when the
  font lands;
- each picker row is drawn in its own loaded preview face;
- a picked font is applied only after it has loaded;
- a collaborator's paragraph in Playfair appears only once Playfair has
  loaded;
- the PDF's lines are the screen's, for long paragraphs in Carlito,
  Caladea and Inter.

Each check went red under a mutation of the thing it guards: the hold
rule removed, a pick applied before its load, the remote wait skipped,
no commit, and a fallback that kept the private name.

The line-break check found a real bug. go-text/typesetting v0.3.5 applied
none of Inter's kerning, so the PDF broke Inter lines a word early.
Pinned at a4cf8f4 (2026-10-20), which kerns as HarfBuzz does.
scripts/harfbuzz-golden.py writes HarfBuzz's own advances for 17 words
in all 62 faces, and TestShapingMatchesHarfBuzz holds the Go shaper to
them to the font unit. That test fails 226 times on v0.3.5 and passes
now.

The picker's preview rule is scoped to the toolbar's combobox, so it
beats `font: inherit` on the closed box. A row's description is set in
the chrome's face, because the preview subset holds only the name's
letters.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 141d612d7950208089d6d1a0c1392a28d4055e9e parent 6985ef8
11 files changed, +1,778 −10
  • fixtures/generate-fragment.mjs +25 −1
  • fixtures/vectors/fragment/linebreaks.bin binary
  • fixtures/vectors/fragment/playfair.bin binary
  • go.mod +1 −1
  • go.sum +4 −4
  • internal/docs/export_test.go +1 −1
  • internal/docs/fonts_browser_test.go +460 −0
  • internal/fonts/fonts.go +8 −3
  • internal/fonts/shape_test.go +46 −0
  • internal/fonts/testdata/harfbuzz.json +1,183 −0
  • scripts/harfbuzz-golden.py +50 −0

CI passed — run details

diff --git a/fixtures/generate-fragment.mjs b/fixtures/generate-fragment.mjs
index b552f78..17f6b36 100644
--- a/fixtures/generate-fragment.mjs
+++ b/fixtures/generate-fragment.mjs
@@ -131,6 +131,30 @@ writeFileSync('vectors/fragment/faces.bin', docWith(f => {
])
}))
+// playfair.bin is a collaborator's change in a family the reader's tab
+// has not loaded: internal/docs's browser test posts it while the tab
+// watches, and holds that the text never paints before Playfair Display
+// has loaded.
+writeFileSync('vectors/fragment/playfair.bin', docWith(f => {
+ f.insert(0, [el('paragraph', null, text('A collaborator wrote this', { font_playfair: {} }))])
+}))
+
+// linebreaks.bin is three long paragraphs, in Carlito (unmarked),
+// Caladea and Inter, set to break where kerning and ligatures decide it,
+// for the browser test that holds the PDF's lines to the screen's.
+const prose = 'AVOWED TOYOTA WAVES: Yolanda typed "Tomorrow, LT. Walton" while Vivian, eyeing the office affidavit, ' +
+ 'filed fifty reflective notes. Every Wednesday the Avalon Toy Workshop yields jolly figures, ' +
+ 'wavy yarns and quirky boxes; Tycho fixed the kerning, Ava efficiently waffled, and nobody officially ' +
+ 'objected to the fluffy waffles that Tom effortlessly offered. Yet Vance, wary of affluent tycoons, ' +
+ 'quietly typed a final paragraph for the Wolverhampton Yacht Society.'
+writeFileSync('vectors/fragment/linebreaks.bin', docWith(f => {
+ f.insert(0, [
+ el('paragraph', null, text(prose)),
+ el('paragraph', null, text(prose, { font_caladea: {} })),
+ el('paragraph', null, text(prose, { font_inter: {} })),
+ ])
+}))
+
// aligned.bin covers the first block-level formatting: a paragraph's
// `align` attribute. Unlike a mark, alignment belongs to the block, so
// it is a real Yjs XML attribute on the element — which is exactly why
@@ -354,4 +378,4 @@ emitTrap('concurrent', (doc) => {
Y.applyUpdate(doc, Y.encodeStateAsUpdate(a))
})
-console.log('wrote 8 fragment vectors + 4 trap-containment vectors')
+console.log('wrote 10 fragment vectors + 4 trap-containment vectors')
diff --git a/fixtures/vectors/fragment/linebreaks.bin b/fixtures/vectors/fragment/linebreaks.bin
new file mode 100644
index 0000000..5aaffaa
Binary files /dev/null and b/fixtures/vectors/fragment/linebreaks.bin differ
diff --git a/fixtures/vectors/fragment/playfair.bin b/fixtures/vectors/fragment/playfair.bin
new file mode 100644
index 0000000..b2c5e85
Binary files /dev/null and b/fixtures/vectors/fragment/playfair.bin differ
diff --git a/go.mod b/go.mod
index 39d694e..9f6ac9d 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
github.com/chromedp/chromedp v0.14.2
github.com/go-chi/chi/v5 v5.3.2
github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2
- github.com/go-text/typesetting v0.3.5
+ github.com/go-text/typesetting v0.3.6-0.20261020210405-a4cf8f401e16
github.com/google/uuid v1.6.0
github.com/keymaildev/signin v0.1.1
github.com/tetratelabs/wazero v1.12.0
diff --git a/go.sum b/go.sum
index e6f1414..8660ade 100644
--- a/go.sum
+++ b/go.sum
@@ -30,10 +30,10 @@ github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 h1:iizUGZ9
github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
-github.com/go-text/typesetting v0.3.5 h1:XZPUooClHY0Vf/rFyUyuPRNEkawARaFzLMQcXLSEyPk=
-github.com/go-text/typesetting v0.3.5/go.mod h1:XZO1hD+nQVyvVa5IicQk7FsCa4PFQaJ2soWAP1f//68=
-github.com/go-text/typesetting-utils v0.0.0-20260419141703-4ffe8874dabc h1:8FGo2It5K75XkavhTiCKExUfVaVDS1feBnLCru5qeoY=
-github.com/go-text/typesetting-utils v0.0.0-20260419141703-4ffe8874dabc/go.mod h1:3/62I4La/HBRX9TcTpBj4eipLiwzf+vhI+7whTc9V7o=
+github.com/go-text/typesetting v0.3.6-0.20261020210405-a4cf8f401e16 h1:Y+spgzS5aYmWDN24nN4UYamN2vFBJ/HzUJRsGcFS2KY=
+github.com/go-text/typesetting v0.3.6-0.20261020210405-a4cf8f401e16/go.mod h1:4xCar1jOQWppRqQHqtLTUghn73m8dsbk9tUFioaHdHU=
+github.com/go-text/typesetting-utils v0.0.0-20260922124329-7d4869a3934e h1:ARqqlg1JI1oiFHTGKXqh08omHnZuPrMcwtrEGELOW/E=
+github.com/go-text/typesetting-utils v0.0.0-20260922124329-7d4869a3934e/go.mod h1:3/62I4La/HBRX9TcTpBj4eipLiwzf+vhI+7whTc9V7o=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
diff --git a/internal/docs/export_test.go b/internal/docs/export_test.go
index 885ffc8..0a2fe44 100644
--- a/internal/docs/export_test.go
+++ b/internal/docs/export_test.go
@@ -769,7 +769,7 @@ func TestEachPickerEntryIsInItsOwnFace(t *testing.T) {
if !strings.HasPrefix(opt[2], f.Name) {
t.Errorf("%s is labelled %q", f.Name, opt[2])
}
- rule := regexp.MustCompile(`\.` + f.PreviewClass() + `\{font-family:"([^"]+)"`).FindStringSubmatch(css)
+ rule := regexp.MustCompile(`\[docs-toolbar\] \[rst-combo\] \.` + f.PreviewClass() + `\{font-family:"([^"]+)"`).FindStringSubmatch(css)
if rule == nil || rule[1] != f.PreviewCSSName() {
t.Errorf("%s: .%s is not drawn in its preview face (%v)", f.Name, f.PreviewClass(), rule)
}
diff --git a/internal/docs/fonts_browser_test.go b/internal/docs/fonts_browser_test.go
new file mode 100644
index 0000000..4d4baab
--- /dev/null
+++ b/internal/docs/fonts_browser_test.go
@@ -0,0 +1,460 @@
+//go:build browser
+
+// The font checks in a real Chromium, through the production middleware
+// (rastrillo.Handler with Docs' own ServeOptions, CSP included), with the
+// font files slowed down on the way out:
+//
+// RASTRILLO_CHROME=… CGO_ENABLED=0 go test -tags browser -run Font ./internal/docs/
+//
+// Paul, 2026-10-24: "never a flash of unstyled text, ever", and the font
+// menu shows each font in its own face. Every check here samples the page
+// on every animation frame and on every DOM change, from before the first
+// byte of HTML is parsed, and fails on any sample where text is visible in
+// a face that has not loaded.
+package docs_test
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "amadan.net/rastrillo/rastrillo"
+ "amadan.net/rastrillo/rastrillo/harness"
+ "github.com/chromedp/cdproto/emulation"
+ "github.com/chromedp/cdproto/network"
+ "github.com/chromedp/cdproto/page"
+ "github.com/chromedp/chromedp"
+
+ "github.com/carlosframework/docs/internal/docs"
+ "github.com/carlosframework/docs/internal/export"
+ "github.com/carlosframework/docs/internal/fonts"
+)
+
+// fontRig is Docs behind its production middleware, with every font
+// file (/static/fonts/*.woff2) held for slow before it is served, and a
+// signed-in browser.
+type fontRig struct {
+ rig *harness.Rig
+ app *docs.App
+ served http.Handler
+ cookies []*http.Cookie
+ // slow is how long a matching font waits, and match picks which
+ // font files wait ("" for all of them).
+ slow atomic.Int64
+ match atomic.Value
+}
+
+func newFontRig(t *testing.T) *fontRig {
+ t.Helper()
+ fr := &fontRig{}
+ fr.match.Store("")
+ fr.rig = harness.New(t, func(origin string) http.Handler {
+ var err error
+ fr.app, err = docs.NewForTestWith(t, docs.Config{Origin: origin})
+ if err != nil {
+ t.Fatalf("NewForTestWith: %v", err)
+ }
+ served, done, err := rastrillo.Handler(docs.ServeOptions(rastrillo.Options{}, fr.app))
+ if err != nil {
+ t.Fatalf("rastrillo.Handler: %v", err)
+ }
+ if done != nil {
+ t.Cleanup(func() { _ = done() })
+ }
+ fr.served = served
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ // The document's faces, not the picker's previews: this server
+ // is HTTP/1.1, whose six connections would queue sixteen
+ // held previews behind each other where a deployed instance's
+ // HTTP/2 fetches them at once.
+ if strings.HasPrefix(r.URL.Path, fonts.PathPrefix) && strings.HasSuffix(r.URL.Path, ".woff2") &&
+ !strings.Contains(r.URL.Path, "/preview-") && strings.Contains(r.URL.Path, fr.match.Load().(string)) {
+ time.Sleep(time.Duration(fr.slow.Load()))
+ }
+ served.ServeHTTP(w, r)
+ })
+ })
+ fr.cookies = signInCookies(t, fr.app, "fonts@example.com")
+ var set []chromedp.Action
+ for _, c := range fr.cookies {
+ set = append(set, network.SetCookie(c.Name, c.Value).WithURL(fr.rig.Origin+"/").
+ WithHTTPOnly(c.HttpOnly).WithSecure(c.Secure).WithSameSite(network.CookieSameSiteLax))
+ }
+ // Wide enough for the whole sheet, so the line-break check measures
+ // the 6.5in column the PDF sets.
+ set = append(set, emulation.SetDeviceMetricsOverride(1280, 1000, 1, false),
+ // No HTTP cache between checks: each one is a first visit, which
+ // is when the fonts have to come over the network.
+ network.SetCacheDisabled(true),
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ _, err := page.AddScriptToEvaluateOnNewDocument(probeJS).Do(ctx)
+ return err
+ }))
+ fr.rig.Run(set...)
+ return fr
+}
+
+// document creates a document holding a fragment vector.
+func (fr *fontRig) document(t *testing.T, title, vector string) string {
+ t.Helper()
+ ctx := context.Background()
+ doc, err := fr.app.Store().Create(ctx, fr.app.TestPerson(t, "fonts@example.com"), title)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if vector != "" {
+ update, err := os.ReadFile("../../fixtures/vectors/fragment/" + vector)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fr.app.Store().ApplyUpdate(ctx, doc, fr.app.TestActorFor(t, doc), update); err != nil {
+ t.Fatal(err)
+ }
+ }
+ return doc.Sqid
+}
+
+// probeJS runs before the page's own HTML. On every frame and every DOM
+// change it looks at every run of document text that is visible, works
+// out which private face it is drawn in, and records a violation if
+// that face has not loaded. A run in a committed fallback names no
+// private face, which is allowed: wrong but stable is not a flash. What
+// is recorded too is every distinct face a run has been seen in, so a
+// test can say a run never changed face.
+const probeJS = `(() => {
+ const log = { violations: [], seen: {}, firstVisible: null, samples: 0 };
+ window.__fontProbe = log;
+ const faceOf = (el) => {
+ const cs = getComputedStyle(el);
+ const m = cs.fontFamily.match(/"(Docs [^"]+)"/);
+ return { family: m ? m[1] : null, stack: cs.fontFamily, weight: cs.fontWeight, style: cs.fontStyle, visible: cs.visibility === 'visible' };
+ };
+ const sample = (why) => {
+ const root = document.querySelector('[docs-text]');
+ if (!root) return;
+ log.samples++;
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
+ if (!n.data.trim()) continue;
+ const el = n.parentElement;
+ const f = faceOf(el);
+ if (!f.visible) continue;
+ if (log.firstVisible === null) log.firstVisible = performance.now();
+ const key = n.data.slice(0, 24);
+ const desc = (f.family || f.stack) + ' ' + f.weight + ' ' + f.style;
+ (log.seen[key] = log.seen[key] || {})[desc] = true;
+ if (!f.family) continue;
+ const css = (f.style === 'italic' ? 'italic ' : '') + f.weight + ' 16px "' + f.family + '"';
+ if (!document.fonts.check(css)) {
+ log.violations.push(Math.round(performance.now()) + 'ms ' + why + ': "' + key + '" visible in ' + css + ' before it loaded');
+ }
+ }
+ };
+ const frame = () => { sample('frame'); requestAnimationFrame(frame); };
+ requestAnimationFrame(frame);
+ new MutationObserver(() => sample('mutation')).observe(document, { subtree: true, childList: true, attributes: true, characterData: true });
+})()`
+
+type probe struct {
+ Violations []string `json:"violations"`
+ Seen map[string]map[string]bool `json:"seen"`
+ FirstVisible *float64 `json:"firstVisible"`
+ Samples int `json:"samples"`
+}
+
+func (fr *fontRig) probe(t *testing.T) probe {
+ t.Helper()
+ var raw string
+ fr.rig.Run(chromedp.Evaluate(`JSON.stringify(window.__fontProbe)`, &raw))
+ var p probe
+ if err := json.Unmarshal([]byte(raw), &p); err != nil {
+ t.Fatalf("probe: %v (%s)", err, raw)
+ }
+ if p.Samples < 10 {
+ t.Fatalf("the probe sampled the page %d times; it cannot see what it is checking", p.Samples)
+ }
+ return p
+}
+
+func (fr *fontRig) open(t *testing.T, sqid string) {
+ t.Helper()
+ fr.rig.Run(chromedp.Navigate(fr.rig.Origin+"/d/"+sqid),
+ chromedp.WaitVisible(`[docs-canvas][data-docs-fonts="ready"] [docs-text]`, chromedp.ByQuery))
+}
+
+func (fr *fontRig) eval(t *testing.T, js string, out any) {
+ t.Helper()
+ fr.rig.Run(chromedp.Evaluate(js, out))
+}
+
+// Text is not painted before its fonts are ready. Every font file is
+// held for a second and a half, well under the gate's deadline, so the
+// right answer is: nothing visible until every face the document uses
+// has loaded, then the text, once, in those faces.
+func TestFontTextIsNotPaintedBeforeItsFontsAreReady(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Faces", "faces.bin")
+ fr.slow.Store(int64(1500 * time.Millisecond))
+ start := time.Now()
+ fr.open(t, sqid)
+ if waited := time.Since(start); waited < 1400*time.Millisecond {
+ t.Fatalf("the sheet was shown %v after navigating, before the fonts could have arrived: the slowdown did not apply", waited)
+ }
+ p := fr.probe(t)
+ for _, v := range p.Violations {
+ t.Error(v)
+ }
+ var fallback string
+ fr.eval(t, `document.documentElement.getAttribute('data-docs-fonts-fallback') || ''`, &fallback)
+ if fallback != "" {
+ t.Errorf("fonts that arrived in time were committed to their fallback: %q", fallback)
+ }
+ for run, faces := range p.Seen {
+ if len(faces) != 1 {
+ t.Errorf("%q was shown in more than one face: %v", run, faces)
+ }
+ }
+ if p.FirstVisible == nil {
+ t.Fatal("no text was ever visible")
+ }
+}
+
+// Past the deadline the gate commits: the text appears in its fallback
+// and stays in it when the font finally arrives, so it is shown once and
+// never swaps. Nothing is visible in a face that has not loaded.
+func TestFontALateFontCommitsToItsFallbackAndNeverSwaps(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Late", "faces.bin")
+ fr.slow.Store(int64(4 * time.Second))
+ fr.open(t, sqid)
+ var fallback string
+ fr.eval(t, `document.documentElement.getAttribute('data-docs-fonts-fallback') || ''`, &fallback)
+ if !strings.Contains(fallback, "carlito") {
+ t.Fatalf("Carlito missed the deadline and was not committed: fallback %q", fallback)
+ }
+ // Let the late fonts land, and keep sampling while they do.
+ fr.rig.Run(chromedp.Sleep(3 * time.Second))
+ var loaded bool
+ fr.eval(t, `document.fonts.check('16px "Docs Carlito"')`, &loaded)
+ if !loaded {
+ t.Fatal("Carlito never arrived, so this cannot show it was not swapped in")
+ }
+ p := fr.probe(t)
+ for _, v := range p.Violations {
+ t.Error(v)
+ }
+ for run, faces := range p.Seen {
+ if len(faces) != 1 {
+ t.Errorf("%q changed face after it was shown: %v", run, faces)
+ }
+ for f := range faces {
+ if strings.Contains(f, "Docs Carlito") {
+ t.Errorf("%q swapped into Carlito after the page committed to its fallback", run)
+ }
+ }
+ }
+ var note bool
+ fr.eval(t, `!document.querySelector('[docs-fonts-note]').hidden`, &note)
+ if !note {
+ t.Error("the page shows substitutes and does not say so")
+ }
+}
+
+// Each entry of the font menu is drawn in its own face, and the menu
+// does not open until those faces are in.
+func TestFontEachPickerEntryRendersInItsOwnFace(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Picker", "")
+ fr.open(t, sqid)
+ fr.rig.Run(
+ chromedp.WaitEnabled(`#docs-select-font-combo`, chromedp.ByQuery),
+ chromedp.Click(`#docs-select-font-combo`, chromedp.ByQuery),
+ chromedp.WaitVisible(`#docs-select-font-listbox [rst-combo-option]`, chromedp.ByQuery),
+ )
+ var rows []struct {
+ Text string `json:"text"`
+ Family string `json:"family"`
+ Loaded bool `json:"loaded"`
+ Desc string `json:"desc"`
+ }
+ fr.eval(t, `[...document.querySelectorAll('#docs-select-font-listbox [rst-combo-option]')].map(li => {
+ const name = li.querySelector('[rst-combo-name]') || li;
+ const fam = getComputedStyle(name).fontFamily;
+ const m = fam.match(/"(Docs Preview \d+)"/);
+ const d = li.querySelector('[rst-combo-desc]');
+ return { text: (li.querySelector('[rst-combo-name]') || li).textContent, family: m ? m[1] : fam,
+ loaded: !!m && document.fonts.check('16px "' + m[1] + '"'), desc: d ? getComputedStyle(d).fontFamily : '' };
+ })`, &rows)
+ if len(rows) != len(fonts.Families) {
+ t.Fatalf("the menu has %d rows, the manifest %d families", len(rows), len(fonts.Families))
+ }
+ for i, f := range fonts.Families {
+ r := rows[i]
+ if r.Text != f.Name {
+ t.Errorf("row %d reads %q, want %q", i, r.Text, f.Name)
+ }
+ if r.Family != f.PreviewCSSName() || !r.Loaded {
+ t.Errorf("%s is drawn in %q (loaded %v), want its own preview face %q", f.Name, r.Family, r.Loaded, f.PreviewCSSName())
+ }
+ if r.Desc != "" && strings.Contains(r.Desc, "Docs Preview") {
+ t.Errorf("%s's description is drawn in the preview subset, which lacks its letters", f.Name)
+ }
+ }
+ // The closed box wears the default's face too.
+ var box string
+ fr.eval(t, `getComputedStyle(document.querySelector('#docs-select-font-combo')).fontFamily`, &box)
+ if !strings.Contains(box, fonts.Default.PreviewCSSName()) {
+ t.Errorf("the closed font box is drawn in %q, not Carlito's preview", box)
+ }
+}
+
+// Picking a font loads it before applying it: with Playfair Display held
+// for a second and a half, no run is in Playfair until it has loaded,
+// and then the selection is.
+func TestFontPickingAFontLoadsItBeforeApplyingIt(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Pick", "simple.bin")
+ fr.open(t, sqid)
+ fr.match.Store("PlayfairDisplay-")
+ fr.slow.Store(int64(1500 * time.Millisecond))
+ var picked bool
+ fr.eval(t, `(() => {
+ const p = document.querySelector('[docs-text] p');
+ const r = document.createRange(); r.selectNodeContents(p);
+ const s = getSelection(); s.removeAllRanges(); s.addRange(r);
+ document.querySelector('[docs-text]').focus();
+ return true })()`, &picked)
+ fr.rig.Run(chromedp.Sleep(200 * time.Millisecond))
+ fr.eval(t, `(() => { const s = document.querySelector('[data-docs-select="font"]'); s.value = 'playfair';
+ s.dispatchEvent(new Event('change', { bubbles: true })); return true })()`, &picked)
+ var early bool
+ fr.rig.Run(chromedp.Sleep(500 * time.Millisecond))
+ fr.eval(t, `!!document.querySelector('[docs-text] .docs-font-playfair')`, &early)
+ if early {
+ t.Error("the mark was applied while Playfair Display was still loading")
+ }
+ fr.rig.Run(chromedp.WaitVisible(`[docs-text] .docs-font-playfair`, chromedp.ByQuery))
+ p := fr.probe(t)
+ for _, v := range p.Violations {
+ t.Error(v)
+ }
+}
+
+// A collaborator's font change waits for that font to load: another
+// person posts a paragraph in Playfair Display, which this tab has never
+// loaded and which is held for a second and a half. It appears once, in
+// Playfair.
+func TestFontACollaboratorsFontChangeWaitsForTheFont(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Together", "")
+ fr.open(t, sqid)
+ // Give the stream a moment to connect.
+ fr.rig.Run(chromedp.Sleep(500 * time.Millisecond))
+ fr.match.Store("PlayfairDisplay-")
+ fr.slow.Store(int64(1500 * time.Millisecond))
+
+ update, err := os.ReadFile("../../fixtures/vectors/fragment/playfair.bin")
+ if err != nil {
+ t.Fatal(err)
+ }
+ req := httptest.NewRequest(http.MethodPost, "/d/"+sqid+"/updates", bytes.NewReader(update))
+ req.Header.Set("Content-Type", "application/octet-stream")
+ req.Header.Set("Sec-Fetch-Site", "same-origin")
+ for _, c := range fr.cookies {
+ req.AddCookie(c)
+ }
+ rec := httptest.NewRecorder()
+ fr.served.ServeHTTP(rec, req)
+ if rec.Code/100 != 2 {
+ t.Fatalf("the collaborator's POST: %d %s", rec.Code, rec.Body.String())
+ }
+ posted := time.Now()
+ fr.rig.Run(chromedp.WaitVisible(`[docs-text] .docs-font-playfair`, chromedp.ByQuery))
+ if waited := time.Since(posted); waited < 1200*time.Millisecond {
+ t.Errorf("the change appeared %v after it was posted, sooner than its font could have loaded", waited)
+ }
+ p := fr.probe(t)
+ for _, v := range p.Violations {
+ t.Error(v)
+ }
+}
+
+// The PDF breaks lines where the screen does, because both shape the
+// same font programs (Paul's default 6). Three long paragraphs, in
+// Carlito, Caladea and Inter, written to kern and ligate; the words on
+// each screen line must be the words on each PDF line.
+func TestFontThePDFsLineBreaksMatchTheScreen(t *testing.T) {
+ fr := newFontRig(t)
+ sqid := fr.document(t, "Lines", "linebreaks.bin")
+ fr.open(t, sqid)
+ var screen []string
+ fr.eval(t, `(() => {
+ const out = [];
+ for (const p of document.querySelectorAll('[docs-text] p')) {
+ const walker = document.createTreeWalker(p, NodeFilter.SHOW_TEXT);
+ let line = [], top = null;
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) {
+ const re = /\S+/g; let m;
+ while ((m = re.exec(n.data))) {
+ const r = document.createRange(); r.setStart(n, m.index); r.setEnd(n, m.index + m[0].length);
+ const y = Math.round(r.getClientRects()[0].top);
+ if (top !== null && y !== top) { out.push(line.join(' ')); line = []; }
+ top = y; line.push(m[0]);
+ }
+ }
+ if (line.length) out.push(line.join(' '));
+ }
+ return out })()`, &screen)
+
+ structureJSON, err := fr.app.Store().JSON(context.Background(), fr.storeDoc(t, sqid))
+ if err != nil {
+ t.Fatal(err)
+ }
+ structure, err := export.Parse("", structureJSON)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var paper []string
+ for _, l := range export.Lines(structure) {
+ paper = append(paper, strings.Join(strings.Fields(l), " "))
+ }
+ if len(screen) < 12 {
+ t.Fatalf("the screen set %d lines; the paragraphs should run to many", len(screen))
+ }
+ if strings.Join(screen, "\n") != strings.Join(paper, "\n") {
+ n := max(len(screen), len(paper))
+ var diff strings.Builder
+ for i := 0; i < n; i++ {
+ s, p := "", ""
+ if i < len(screen) {
+ s = screen[i]
+ }
+ if i < len(paper) {
+ p = paper[i]
+ }
+ mark := " "
+ if s != p {
+ mark = "!="
+ }
+ fmt.Fprintf(&diff, "%s screen: %s\n paper: %s\n", mark, s, p)
+ }
+ t.Errorf("the PDF breaks lines differently from the screen:\n%s", diff.String())
+ }
+}
+
+func (fr *fontRig) storeDoc(t *testing.T, sqid string) *docs.Document {
+ t.Helper()
+ doc, err := fr.app.Store().GetFor(context.Background(), fr.app.TestActorForPerson(t, fr.app.TestPerson(t, "fonts@example.com")), sqid)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return doc
+}
diff --git a/internal/fonts/fonts.go b/internal/fonts/fonts.go
index dcf4342..919bd0e 100644
--- a/internal/fonts/fonts.go
+++ b/internal/fonts/fonts.go
@@ -471,12 +471,17 @@ func stylesheet() []byte {
}
fmt.Fprintf(&b, "%s [docs-text] .%s{font-family:%s}\n", sel, f.Class(), f.FallbackCSS())
}
- // Previews, only once they are loaded, and never after the page has
- // committed them to the system face.
+ // Previews: the font control's rows and its closed box, which
+ // ui/select.js gives the option's data-rst-class. Scoped to the
+ // toolbar's combobox, and heavy enough to beat its `font: inherit`.
+ // Never once the page has committed them to the system face. A
+ // row's description ("Calibri-compatible") is copy, in the chrome's
+ // face: the subset has only the name's letters.
for _, f := range Families {
- fmt.Fprintf(&b, "html:not([data-docs-fonts-fallback~=\"previews\"]) .%s{font-family:%q, var(--rst-font, system-ui), sans-serif}\n",
+ fmt.Fprintf(&b, "html:not([data-docs-fonts-fallback~=\"previews\"]) [docs-toolbar] [rst-combo] .%s{font-family:%q, var(--rst-font, system-ui), sans-serif}\n",
f.PreviewClass(), f.PreviewCSSName())
}
+ b.WriteString("[docs-toolbar] [rst-combo] [class*=\"docs-preview-\"] [rst-combo-desc]{font-family:var(--rst-font, system-ui), sans-serif}\n")
// The hold. The sheet, not just the text, so nothing shows an empty
// page with the words missing from it; and the font control, whose
// closed box is drawn in its own face.
diff --git a/internal/fonts/shape_test.go b/internal/fonts/shape_test.go
index b2e43f7..9461c06 100644
--- a/internal/fonts/shape_test.go
+++ b/internal/fonts/shape_test.go
@@ -1,6 +1,9 @@
package fonts_test
import (
+ "encoding/json"
+ "math"
+ "os"
"testing"
"github.com/carlosframework/docs/internal/fonts"
@@ -56,3 +59,46 @@ func TestShapingLigatesAndKeepsTheText(t *testing.T) {
}
}
}
+
+// The PDF's shaper sets every word the way HarfBuzz, the browser's
+// shaper, does, in every face Docs ships: the advances are equal to the
+// font unit. testdata/harfbuzz.json is HarfBuzz's own answer
+// (scripts/harfbuzz-golden.py). go-text/typesetting v0.3.5 failed this
+// for Inter, applying none of its kerning, so the PDF broke Inter lines
+// a word early.
+func TestShapingMatchesHarfBuzz(t *testing.T) {
+ raw, err := os.ReadFile("testdata/harfbuzz.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var golden struct {
+ Faces map[string]map[string]int `json:"faces"`
+ }
+ if err := json.Unmarshal(raw, &golden); err != nil {
+ t.Fatal(err)
+ }
+ if len(golden.Faces) != len(fonts.All()) {
+ t.Fatalf("the golden file covers %d faces, Docs ships %d: rerun scripts/harfbuzz-golden.py", len(golden.Faces), len(fonts.All()))
+ }
+ sh := fonts.NewShaper()
+ for _, face := range fonts.All() {
+ words, ok := golden.Faces[face.File]
+ if !ok {
+ t.Errorf("%s is not in the golden file", face.File)
+ continue
+ }
+ font, err := face.Parsed()
+ if err != nil {
+ t.Fatal(err)
+ }
+ for w, want := range words {
+ run, err := sh.Shape(face, w)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got := int(math.Round(run.Width * float64(font.UnitsPerEm))); got != want {
+ t.Errorf("%s %q: the PDF sets it %d units wide, HarfBuzz %d", face.File, w, got, want)
+ }
+ }
+ }
+}
diff --git a/internal/fonts/testdata/harfbuzz.json b/internal/fonts/testdata/harfbuzz.json
new file mode 100644
index 0000000..52d2575
--- /dev/null
+++ b/internal/fonts/testdata/harfbuzz.json
@@ -0,0 +1,1183 @@
+{
+ "comment": "Generated by scripts/harfbuzz-golden.py: each word's advance in font units, as HarfBuzz sets it.",
+ "faces": {
+ "caladea/Caladea-Bold.ttf": {
+ "AVOWED": 3939,
+ "Ava": 1631,
+ "LT.": 1161,
+ "TOYOTA": 3479,
+ "Te": 1012,
+ "Tomorrow,": 4781,
+ "Vivian": 2863,
+ "Wolverhampton": 7227,
+ "Yolanda": 3564,
+ "affidavit": 3758,
+ "café": 1823,
+ "efficiently": 4537,
+ "fluffy": 2446,
+ "office": 2465,
+ "to": 881,
+ "waffled,": 3581,
+ "“quoted”": 3928
+ },
+ "caladea/Caladea-BoldItalic.ttf": {
+ "AVOWED": 3870,
+ "Ava": 1623,
+ "LT.": 1100,
+ "TOYOTA": 3435,
+ "Te": 987,
+ "Tomorrow,": 4849,
+ "Vivian": 2812,
+ "Wolverhampton": 7176,
+ "Yolanda": 3605,
+ "affidavit": 3791,
+ "café": 1841,
+ "efficiently": 4404,
+ "fluffy": 2383,
+ "office": 2460,
+ "to": 898,
+ "waffled,": 3540,
+ "“quoted”": 3909
+ },
+ "caladea/Caladea-Italic.ttf": {
+ "AVOWED": 3539,
+ "Ava": 1485,
+ "LT.": 998,
+ "TOYOTA": 3100,
+ "Te": 873,
+ "Tomorrow,": 4280,
+ "Vivian": 2591,
+ "Wolverhampton": 6456,
+ "Yolanda": 3252,
+ "affidavit": 3424,
+ "café": 1651,
+ "efficiently": 3967,
+ "fluffy": 2109,
+ "office": 2188,
+ "to": 816,
+ "waffled,": 3195,
+ "“quoted”": 3547
+ },
+ "caladea/Caladea-Regular.ttf": {
+ "AVOWED": 3681,
+ "Ava": 1477,
+ "LT.": 1087,
+ "TOYOTA": 3290,
+ "Te": 928,
+ "Tomorrow,": 4364,
+ "Vivian": 2630,
+ "Wolverhampton": 6553,
+ "Yolanda": 3238,
+ "affidavit": 3415,
+ "café": 1633,
+ "efficiently": 4099,
+ "fluffy": 2238,
+ "office": 2245,
+ "to": 796,
+ "waffled,": 3234,
+ "“quoted”": 3554
+ },
+ "carlito/Carlito-Bold.ttf": {
+ "AVOWED": 7813,
+ "Ava": 3141,
+ "LT.": 2106,
+ "TOYOTA": 6700,
+ "Te": 1868,
+ "Tomorrow,": 9137,
+ "Vivian": 5296,
+ "Wolverhampton": 13846,
+ "Yolanda": 6723,
+ "affidavit": 6981,
+ "café": 3488,
+ "efficiently": 8388,
+ "fluffy": 4444,
+ "office": 4707,
+ "to": 1791,
+ "waffled,": 6880,
+ "“quoted”": 7816
+ },
+ "carlito/Carlito-BoldItalic.ttf": {
+ "AVOWED": 7765,
+ "Ava": 3211,
+ "LT.": 2099,
+ "TOYOTA": 6724,
+ "Te": 1866,
+ "Tomorrow,": 9136,
+ "Vivian": 5339,
+ "Wolverhampton": 13777,
+ "Yolanda": 6814,
+ "affidavit": 7135,
+ "café": 3537,
+ "efficiently": 8310,
+ "fluffy": 4422,
+ "office": 4633,
+ "to": 1767,
+ "waffled,": 6940,
+ "“quoted”": 7751
+ },
+ "carlito/Carlito-Italic.ttf": {
+ "AVOWED": 7575,
+ "Ava": 3080,
+ "LT.": 2015,
+ "TOYOTA": 6496,
+ "Te": 1803,
+ "Tomorrow,": 8847,
+ "Vivian": 5121,
+ "Wolverhampton": 13387,
+ "Yolanda": 6588,
+ "affidavit": 6882,
+ "café": 3463,
+ "efficiently": 8035,
+ "fluffy": 4260,
+ "office": 4522,
+ "to": 1712,
+ "waffled,": 6713,
+ "“quoted”": 7503
+ },
+ "carlito/Carlito-Regular.ttf": {
+ "AVOWED": 7647,
+ "Ava": 3023,
+ "LT.": 2023,
+ "TOYOTA": 6497,
+ "Te": 1835,
+ "Tomorrow,": 8878,
+ "Vivian": 5084,
+ "Wolverhampton": 13506,
+ "Yolanda": 6509,
+ "affidavit": 6727,
+ "café": 3411,
+ "efficiently": 8150,
+ "fluffy": 4292,
+ "office": 4619,
+ "to": 1746,
+ "waffled,": 6670,
+ "“quoted”": 7612
+ },
+ "caveat/Caveat-Bold.ttf": {
+ "AVOWED": 3280,
+ "Ava": 1273,
+ "LT.": 1042,
+ "TOYOTA": 2841,
+ "Te": 702,
+ "Tomorrow,": 3458,
+ "Vivian": 2101,
+ "Wolverhampton": 5319,
+ "Yolanda": 2674,
+ "affidavit": 2770,
+ "café": 1435,
+ "efficiently": 3191,
+ "fluffy": 1671,
+ "office": 1714,
+ "to": 693,
+ "waffled,": 2567,
+ "“quoted”": 2700
+ },
+ "caveat/Caveat-Regular.ttf": {
+ "AVOWED": 3244,
+ "Ava": 1255,
+ "LT.": 1042,
+ "TOYOTA": 2814,
+ "Te": 693,
+ "Tomorrow,": 3422,
+ "Vivian": 2065,
+ "Wolverhampton": 5256,
+ "Yolanda": 2620,
+ "affidavit": 2734,
+ "café": 1408,
+ "efficiently": 3137,
+ "fluffy": 1671,
+ "office": 1687,
+ "to": 684,
+ "waffled,": 2540,
+ "“quoted”": 2673
+ },
+ "garamond/EBGaramond-Bold.ttf": {
+ "AVOWED": 4337,
+ "Ava": 1540,
+ "LT.": 1296,
+ "TOYOTA": 4095,
+ "Te": 1015,
+ "Tomorrow,": 4644,
+ "Vivian": 2755,
+ "Wolverhampton": 6749,
+ "Yolanda": 3322,
+ "affidavit": 3453,
+ "café": 1586,
+ "efficiently": 4114,
+ "fluffy": 2298,
+ "office": 2222,
+ "to": 878,
+ "waffled,": 3287,
+ "“quoted”": 3749
+ },
+ "garamond/EBGaramond-BoldItalic.ttf": {
+ "AVOWED": 4466,
+ "Ava": 1744,
+ "LT.": 1364,
+ "TOYOTA": 3938,
+ "Te": 998,
+ "Tomorrow,": 4687,
+ "Vivian": 2965,
+ "Wolverhampton": 6917,
+ "Yolanda": 3549,
+ "affidavit": 3769,
+ "café": 1662,
+ "efficiently": 4125,
+ "fluffy": 2459,
+ "office": 2164,
+ "to": 822,
+ "waffled,": 3450,
+ "“quoted”": 3820
+ },
+ "garamond/EBGaramond-Italic.ttf": {
+ "AVOWED": 4310,
+ "Ava": 1559,
+ "LT.": 1360,
+ "TOYOTA": 3685,
+ "Te": 893,
+ "Tomorrow,": 4077,
+ "Vivian": 2654,
+ "Wolverhampton": 6119,
+ "Yolanda": 3161,
+ "affidavit": 3298,
+ "café": 1466,
+ "efficiently": 3563,
+ "fluffy": 2115,
+ "office": 1823,
+ "to": 672,
+ "waffled,": 3041,
+ "“quoted”": 3245
+ },
+ "garamond/EBGaramond-Regular.ttf": {
+ "AVOWED": 4151,
+ "Ava": 1444,
+ "LT.": 1289,
+ "TOYOTA": 3971,
+ "Te": 955,
+ "Tomorrow,": 4326,
+ "Vivian": 2507,
+ "Wolverhampton": 6221,
+ "Yolanda": 3030,
+ "affidavit": 3057,
+ "café": 1474,
+ "efficiently": 3728,
+ "fluffy": 2046,
+ "office": 2048,
+ "to": 809,
+ "waffled,": 2946,
+ "“quoted”": 3509
+ },
+ "inter/Inter-Bold.ttf": {
+ "AVOWED": 9190,
+ "Ava": 3787,
+ "LT.": 2954,
+ "TOYOTA": 8428,
+ "Te": 2427,
+ "Tomorrow,": 10723,
+ "Vivian": 6331,
+ "Wolverhampton": 16017,
+ "Yolanda": 8028,
+ "affidavit": 8284,
+ "café": 4405,
+ "efficiently": 10156,
+ "fluffy": 5423,
+ "office": 5798,
+ "to": 1986,
+ "waffled,": 8220,
+ "“quoted”": 9178
+ },
+ "inter/Inter-BoldItalic.ttf": {
+ "AVOWED": 9201,
+ "Ava": 3873,
+ "LT.": 2955,
+ "TOYOTA": 8432,
+ "Te": 2416,
+ "Tomorrow,": 10729,
+ "Vivian": 6436,
+ "Wolverhampton": 16113,
+ "Yolanda": 8235,
+ "affidavit": 8542,
+ "café": 4499,
+ "efficiently": 10183,
+ "fluffy": 5496,
+ "office": 5835,
+ "to": 1989,
+ "waffled,": 8336,
+ "“quoted”": 9337
+ },
+ "inter/Inter-Italic.ttf": {
+ "AVOWED": 8910,
+ "Ava": 3642,
+ "LT.": 2805,
+ "TOYOTA": 8149,
+ "Te": 2343,
+ "Tomorrow,": 10264,
+ "Vivian": 6026,
+ "Wolverhampton": 15352,
+ "Yolanda": 7938,
+ "affidavit": 8004,
+ "café": 4311,
+ "efficiently": 9511,
+ "fluffy": 5071,
+ "office": 5524,
+ "to": 1881,
+ "waffled,": 7863,
+ "“quoted”": 8668
+ },
+ "inter/Inter-Regular.ttf": {
+ "AVOWED": 8910,
+ "Ava": 3565,
+ "LT.": 2804,
+ "TOYOTA": 8145,
+ "Te": 2356,
+ "Tomorrow,": 10258,
+ "Vivian": 5916,
+ "Wolverhampton": 15253,
+ "Yolanda": 7721,
+ "affidavit": 7773,
+ "café": 4232,
+ "efficiently": 9523,
+ "fluffy": 5052,
+ "office": 5524,
+ "to": 1878,
+ "waffled,": 7796,
+ "“quoted”": 8515
+ },
+ "jetbrains/JetBrainsMono-Bold.ttf": {
+ "AVOWED": 3600,
+ "Ava": 1800,
+ "LT.": 1800,
+ "TOYOTA": 3600,
+ "Te": 1200,
+ "Tomorrow,": 5400,
+ "Vivian": 3600,
+ "Wolverhampton": 7800,
+ "Yolanda": 4200,
+ "affidavit": 5400,
+ "café": 2400,
+ "efficiently": 6600,
+ "fluffy": 3600,
+ "office": 3600,
+ "to": 1200,
+ "waffled,": 4800,
+ "“quoted”": 4800
+ },
+ "jetbrains/JetBrainsMono-BoldItalic.ttf": {
+ "AVOWED": 3600,
+ "Ava": 1800,
+ "LT.": 1800,
+ "TOYOTA": 3600,
+ "Te": 1200,
+ "Tomorrow,": 5400,
+ "Vivian": 3600,
+ "Wolverhampton": 7800,
+ "Yolanda": 4200,
+ "affidavit": 5400,
+ "café": 2400,
+ "efficiently": 6600,
+ "fluffy": 3600,
+ "office": 3600,
+ "to": 1200,
+ "waffled,": 4800,
+ "“quoted”": 4800
+ },
+ "jetbrains/JetBrainsMono-Italic.ttf": {
+ "AVOWED": 3600,
+ "Ava": 1800,
+ "LT.": 1800,
+ "TOYOTA": 3600,
+ "Te": 1200,
+ "Tomorrow,": 5400,
+ "Vivian": 3600,
+ "Wolverhampton": 7800,
+ "Yolanda": 4200,
+ "affidavit": 5400,
+ "café": 2400,
+ "efficiently": 6600,
+ "fluffy": 3600,
+ "office": 3600,
+ "to": 1200,
+ "waffled,": 4800,
+ "“quoted”": 4800
+ },
+ "jetbrains/JetBrainsMono-Regular.ttf": {
+ "AVOWED": 3600,
+ "Ava": 1800,
+ "LT.": 1800,
+ "TOYOTA": 3600,
+ "Te": 1200,
+ "Tomorrow,": 5400,
+ "Vivian": 3600,
+ "Wolverhampton": 7800,
+ "Yolanda": 4200,
+ "affidavit": 5400,
+ "café": 2400,
+ "efficiently": 6600,
+ "fluffy": 3600,
+ "office": 3600,
+ "to": 1200,
+ "waffled,": 4800,
+ "“quoted”": 4800
+ },
+ "liberation/LiberationMono-Bold.ttf": {
+ "AVOWED": 7374,
+ "Ava": 3687,
+ "LT.": 3687,
+ "TOYOTA": 7374,
+ "Te": 2458,
+ "Tomorrow,": 11061,
+ "Vivian": 7374,
+ "Wolverhampton": 15977,
+ "Yolanda": 8603,
+ "affidavit": 11061,
+ "café": 4916,
+ "efficiently": 13519,
+ "fluffy": 7374,
+ "office": 7374,
+ "to": 2458,
+ "waffled,": 9832,
+ "“quoted”": 9832
+ },
+ "liberation/LiberationMono-BoldItalic.ttf": {
+ "AVOWED": 7374,
+ "Ava": 3687,
+ "LT.": 3687,
+ "TOYOTA": 7374,
+ "Te": 2458,
+ "Tomorrow,": 11061,
+ "Vivian": 7374,
+ "Wolverhampton": 15977,
+ "Yolanda": 8603,
+ "affidavit": 11061,
+ "café": 4916,
+ "efficiently": 13519,
+ "fluffy": 7374,
+ "office": 7374,
+ "to": 2458,
+ "waffled,": 9832,
+ "“quoted”": 9832
+ },
+ "liberation/LiberationMono-Italic.ttf": {
+ "AVOWED": 7374,
+ "Ava": 3687,
+ "LT.": 3687,
+ "TOYOTA": 7374,
+ "Te": 2458,
+ "Tomorrow,": 11061,
+ "Vivian": 7374,
+ "Wolverhampton": 15977,
+ "Yolanda": 8603,
+ "affidavit": 11061,
+ "café": 4916,
+ "efficiently": 13519,
+ "fluffy": 7374,
+ "office": 7374,
+ "to": 2458,
+ "waffled,": 9832,
+ "“quoted”": 9832
+ },
+ "liberation/LiberationMono-Regular.ttf": {
+ "AVOWED": 7374,
+ "Ava": 3687,
+ "LT.": 3687,
+ "TOYOTA": 7374,
+ "Te": 2458,
+ "Tomorrow,": 11061,
+ "Vivian": 7374,
+ "Wolverhampton": 15977,
+ "Yolanda": 8603,
+ "affidavit": 11061,
+ "café": 4916,
+ "efficiently": 13519,
+ "fluffy": 7374,
+ "office": 7374,
+ "to": 2458,
+ "waffled,": 9832,
+ "“quoted”": 9832
+ },
+ "liberation/LiberationSans-Bold.ttf": {
+ "AVOWED": 9064,
+ "Ava": 3681,
+ "LT.": 2692,
+ "TOYOTA": 8344,
+ "Te": 2238,
+ "Tomorrow,": 10353,
+ "Vivian": 5996,
+ "Wolverhampton": 15437,
+ "Yolanda": 7814,
+ "affidavit": 7852,
+ "café": 4099,
+ "efficiently": 9560,
+ "fluffy": 5005,
+ "office": 5462,
+ "to": 1933,
+ "waffled,": 7624,
+ "“quoted”": 8873
+ },
+ "liberation/LiberationSans-BoldItalic.ttf": {
+ "AVOWED": 9064,
+ "Ava": 3757,
+ "LT.": 2767,
+ "TOYOTA": 8344,
+ "Te": 2314,
+ "Tomorrow,": 10429,
+ "Vivian": 5957,
+ "Wolverhampton": 15437,
+ "Yolanda": 7890,
+ "affidavit": 7815,
+ "café": 4099,
+ "efficiently": 9523,
+ "fluffy": 4968,
+ "office": 5425,
+ "to": 1933,
+ "waffled,": 7587,
+ "“quoted”": 8873
+ },
+ "liberation/LiberationSans-Italic.ttf": {
+ "AVOWED": 8990,
+ "Ava": 3492,
+ "LT.": 2619,
+ "TOYOTA": 8231,
+ "Te": 2202,
+ "Tomorrow,": 9485,
+ "Vivian": 5541,
+ "Wolverhampton": 14342,
+ "Yolanda": 7403,
+ "affidavit": 7058,
+ "café": 3871,
+ "efficiently": 8537,
+ "fluffy": 4325,
+ "office": 4895,
+ "to": 1708,
+ "waffled,": 7058,
+ "“quoted”": 7628
+ },
+ "liberation/LiberationSans-Regular.ttf": {
+ "AVOWED": 8951,
+ "Ava": 3492,
+ "LT.": 2580,
+ "TOYOTA": 8231,
+ "Te": 2163,
+ "Tomorrow,": 9446,
+ "Vivian": 5541,
+ "Wolverhampton": 14305,
+ "Yolanda": 7328,
+ "affidavit": 7021,
+ "café": 3871,
+ "efficiently": 8500,
+ "fluffy": 4288,
+ "office": 4858,
+ "to": 1708,
+ "waffled,": 7021,
+ "“quoted”": 7628
+ },
+ "liberation/LiberationSerif-Bold.ttf": {
+ "AVOWED": 9139,
+ "Ava": 3375,
+ "LT.": 2904,
+ "TOYOTA": 8687,
+ "Te": 2087,
+ "Tomorrow,": 9615,
+ "Vivian": 5728,
+ "Wolverhampton": 14223,
+ "Yolanda": 7171,
+ "affidavit": 7395,
+ "café": 3524,
+ "efficiently": 8643,
+ "fluffy": 4778,
+ "office": 4775,
+ "to": 1706,
+ "waffled,": 6996,
+ "“quoted”": 8080
+ },
+ "liberation/LiberationSerif-BoldItalic.ttf": {
+ "AVOWED": 8725,
+ "Ava": 3147,
+ "LT.": 2789,
+ "TOYOTA": 7927,
+ "Te": 1972,
+ "Tomorrow,": 9124,
+ "Vivian": 5463,
+ "Wolverhampton": 13389,
+ "Yolanda": 6828,
+ "affidavit": 7015,
+ "café": 3524,
+ "efficiently": 8378,
+ "fluffy": 4626,
+ "office": 4738,
+ "to": 1593,
+ "waffled,": 6731,
+ "“quoted”": 7737
+ },
+ "liberation/LiberationSerif-Italic.ttf": {
+ "AVOWED": 8254,
+ "Ava": 3071,
+ "LT.": 2597,
+ "TOYOTA": 7437,
+ "Te": 1860,
+ "Tomorrow,": 8746,
+ "Vivian": 5194,
+ "Wolverhampton": 12857,
+ "Yolanda": 6640,
+ "affidavit": 6826,
+ "café": 3411,
+ "efficiently": 8074,
+ "fluffy": 4209,
+ "office": 4549,
+ "to": 1593,
+ "waffled,": 6542,
+ "“quoted”": 7852
+ },
+ "liberation/LiberationSerif-Regular.ttf": {
+ "AVOWED": 8836,
+ "Ava": 3260,
+ "LT.": 2674,
+ "TOYOTA": 8217,
+ "Te": 2017,
+ "Tomorrow,": 8995,
+ "Vivian": 5451,
+ "Wolverhampton": 13144,
+ "Yolanda": 6733,
+ "affidavit": 6900,
+ "café": 3409,
+ "efficiently": 8378,
+ "fluffy": 4626,
+ "office": 4738,
+ "to": 1593,
+ "waffled,": 6729,
+ "“quoted”": 7392
+ },
+ "literata/Literata-Bold.ttf": {
+ "AVOWED": 4660,
+ "Ava": 1852,
+ "LT.": 1530,
+ "TOYOTA": 4328,
+ "Te": 1253,
+ "Tomorrow,": 5747,
+ "Vivian": 3338,
+ "Wolverhampton": 8289,
+ "Yolanda": 4111,
+ "affidavit": 4283,
+ "café": 2101,
+ "efficiently": 5187,
+ "fluffy": 2821,
+ "office": 2843,
+ "to": 1053,
+ "waffled,": 4132,
+ "“quoted”": 4559
+ },
+ "literata/Literata-BoldItalic.ttf": {
+ "AVOWED": 4532,
+ "Ava": 1947,
+ "LT.": 1485,
+ "TOYOTA": 4140,
+ "Te": 1136,
+ "Tomorrow,": 5511,
+ "Vivian": 3265,
+ "Wolverhampton": 7911,
+ "Yolanda": 4016,
+ "affidavit": 4237,
+ "café": 2042,
+ "efficiently": 4816,
+ "fluffy": 2619,
+ "office": 2609,
+ "to": 1004,
+ "waffled,": 3996,
+ "“quoted”": 4280
+ },
+ "literata/Literata-Italic.ttf": {
+ "AVOWED": 4308,
+ "Ava": 1846,
+ "LT.": 1368,
+ "TOYOTA": 3889,
+ "Te": 1028,
+ "Tomorrow,": 5064,
+ "Vivian": 3047,
+ "Wolverhampton": 7333,
+ "Yolanda": 3672,
+ "affidavit": 3904,
+ "café": 1871,
+ "efficiently": 4421,
+ "fluffy": 2429,
+ "office": 2412,
+ "to": 925,
+ "waffled,": 3664,
+ "“quoted”": 3902
+ },
+ "literata/Literata-Regular.ttf": {
+ "AVOWED": 4568,
+ "Ava": 1761,
+ "LT.": 1488,
+ "TOYOTA": 4207,
+ "Te": 1187,
+ "Tomorrow,": 5404,
+ "Vivian": 3143,
+ "Wolverhampton": 7794,
+ "Yolanda": 3863,
+ "affidavit": 3946,
+ "café": 1934,
+ "efficiently": 4770,
+ "fluffy": 2578,
+ "office": 2595,
+ "to": 985,
+ "waffled,": 3834,
+ "“quoted”": 4280
+ },
+ "notosans/NotoSans-Bold.ttf": {
+ "AVOWED": 4332,
+ "Ava": 1862,
+ "LT.": 1337,
+ "TOYOTA": 3904,
+ "Te": 1104,
+ "Tomorrow,": 5312,
+ "Vivian": 3068,
+ "Wolverhampton": 8050,
+ "Yolanda": 3979,
+ "affidavit": 4205,
+ "café": 2099,
+ "efficiently": 5033,
+ "fluffy": 2685,
+ "office": 2809,
+ "to": 1059,
+ "waffled,": 4048,
+ "“quoted”": 4400
+ },
+ "notosans/NotoSans-BoldItalic.ttf": {
+ "AVOWED": 4033,
+ "Ava": 1732,
+ "LT.": 1236,
+ "TOYOTA": 3588,
+ "Te": 1019,
+ "Tomorrow,": 4960,
+ "Vivian": 2896,
+ "Wolverhampton": 7544,
+ "Yolanda": 3780,
+ "affidavit": 3999,
+ "café": 2007,
+ "efficiently": 4729,
+ "fluffy": 2506,
+ "office": 2626,
+ "to": 995,
+ "waffled,": 3817,
+ "“quoted”": 4150
+ },
+ "notosans/NotoSans-Italic.ttf": {
+ "AVOWED": 3842,
+ "Ava": 1597,
+ "LT.": 1135,
+ "TOYOTA": 3385,
+ "Te": 930,
+ "Tomorrow,": 4690,
+ "Vivian": 2682,
+ "Wolverhampton": 7096,
+ "Yolanda": 3574,
+ "affidavit": 3668,
+ "café": 1838,
+ "efficiently": 4241,
+ "fluffy": 2260,
+ "office": 2411,
+ "to": 895,
+ "waffled,": 3521,
+ "“quoted”": 3787
+ },
+ "notosans/NotoSans-Regular.ttf": {
+ "AVOWED": 4176,
+ "Ava": 1708,
+ "LT.": 1268,
+ "TOYOTA": 3729,
+ "Te": 1050,
+ "Tomorrow,": 5036,
+ "Vivian": 2803,
+ "Wolverhampton": 7571,
+ "Yolanda": 3734,
+ "affidavit": 3810,
+ "café": 1949,
+ "efficiently": 4559,
+ "fluffy": 2418,
+ "office": 2595,
+ "to": 966,
+ "waffled,": 3740,
+ "“quoted”": 4036
+ },
+ "playfair/PlayfairDisplay-Bold.ttf": {
+ "AVOWED": 4388,
+ "Ava": 1682,
+ "LT.": 1433,
+ "TOYOTA": 4089,
+ "Te": 1131,
+ "Tomorrow,": 5149,
+ "Vivian": 2905,
+ "Wolverhampton": 7354,
+ "Yolanda": 3656,
+ "affidavit": 3786,
+ "café": 1852,
+ "efficiently": 4596,
+ "fluffy": 2458,
+ "office": 2552,
+ "to": 913,
+ "waffled,": 3648,
+ "“quoted”": 4117
+ },
+ "playfair/PlayfairDisplay-BoldItalic.ttf": {
+ "AVOWED": 4388,
+ "Ava": 1736,
+ "LT.": 1445,
+ "TOYOTA": 4215,
+ "Te": 1042,
+ "Tomorrow,": 4909,
+ "Vivian": 2983,
+ "Wolverhampton": 7260,
+ "Yolanda": 3727,
+ "affidavit": 3809,
+ "café": 1831,
+ "efficiently": 4375,
+ "fluffy": 2352,
+ "office": 2375,
+ "to": 882,
+ "waffled,": 3498,
+ "“quoted”": 3990
+ },
+ "playfair/PlayfairDisplay-Italic.ttf": {
+ "AVOWED": 4177,
+ "Ava": 1685,
+ "LT.": 1339,
+ "TOYOTA": 3975,
+ "Te": 968,
+ "Tomorrow,": 4581,
+ "Vivian": 2872,
+ "Wolverhampton": 6828,
+ "Yolanda": 3493,
+ "affidavit": 3624,
+ "café": 1705,
+ "efficiently": 4131,
+ "fluffy": 2246,
+ "office": 2214,
+ "to": 824,
+ "waffled,": 3310,
+ "“quoted”": 3649
+ },
+ "playfair/PlayfairDisplay-Regular.ttf": {
+ "AVOWED": 4160,
+ "Ava": 1611,
+ "LT.": 1338,
+ "TOYOTA": 3858,
+ "Te": 1084,
+ "Tomorrow,": 4961,
+ "Vivian": 2772,
+ "Wolverhampton": 7125,
+ "Yolanda": 3522,
+ "affidavit": 3648,
+ "café": 1805,
+ "efficiently": 4472,
+ "fluffy": 2359,
+ "office": 2480,
+ "to": 902,
+ "waffled,": 3542,
+ "“quoted”": 3950
+ },
+ "plexsans/IBMPlexSans-Bold.ttf": {
+ "AVOWED": 4218,
+ "Ava": 1753,
+ "LT.": 1280,
+ "TOYOTA": 3715,
+ "Te": 1081,
+ "Tomorrow,": 5009,
+ "Vivian": 2925,
+ "Wolverhampton": 7505,
+ "Yolanda": 3798,
+ "affidavit": 3955,
+ "café": 2005,
+ "efficiently": 4749,
+ "fluffy": 2530,
+ "office": 2644,
+ "to": 943,
+ "waffled,": 3905,
+ "“quoted”": 4336
+ },
+ "plexsans/IBMPlexSans-BoldItalic.ttf": {
+ "AVOWED": 4074,
+ "Ava": 1721,
+ "LT.": 1211,
+ "TOYOTA": 3620,
+ "Te": 1019,
+ "Tomorrow,": 4838,
+ "Vivian": 2884,
+ "Wolverhampton": 7241,
+ "Yolanda": 3748,
+ "affidavit": 3896,
+ "café": 1932,
+ "efficiently": 4518,
+ "fluffy": 2441,
+ "office": 2523,
+ "to": 889,
+ "waffled,": 3782,
+ "“quoted”": 4160
+ },
+ "plexsans/IBMPlexSans-Italic.ttf": {
+ "AVOWED": 3933,
+ "Ava": 1663,
+ "LT.": 1170,
+ "TOYOTA": 3527,
+ "Te": 1003,
+ "Tomorrow,": 4673,
+ "Vivian": 2753,
+ "Wolverhampton": 7001,
+ "Yolanda": 3655,
+ "affidavit": 3669,
+ "café": 1878,
+ "efficiently": 4264,
+ "fluffy": 2241,
+ "office": 2397,
+ "to": 865,
+ "waffled,": 3571,
+ "“quoted”": 3988
+ },
+ "plexsans/IBMPlexSans-Regular.ttf": {
+ "AVOWED": 4050,
+ "Ava": 1638,
+ "LT.": 1195,
+ "TOYOTA": 3629,
+ "Te": 1056,
+ "Tomorrow,": 4794,
+ "Vivian": 2703,
+ "Wolverhampton": 7122,
+ "Yolanda": 3591,
+ "affidavit": 3624,
+ "café": 1906,
+ "efficiently": 4422,
+ "fluffy": 2321,
+ "office": 2491,
+ "to": 907,
+ "waffled,": 3614,
+ "“quoted”": 4088
+ },
+ "sourcesans/SourceSans3-Bold.ttf": {
+ "AVOWED": 3781,
+ "Ava": 1587,
+ "LT.": 1138,
+ "TOYOTA": 3444,
+ "Te": 998,
+ "Tomorrow,": 4773,
+ "Vivian": 2730,
+ "Wolverhampton": 7079,
+ "Yolanda": 3510,
+ "affidavit": 3742,
+ "café": 1833,
+ "efficiently": 4469,
+ "fluffy": 2373,
+ "office": 2440,
+ "to": 920,
+ "waffled,": 3627,
+ "“quoted”": 4176
+ },
+ "sourcesans/SourceSans3-BoldIt.ttf": {
+ "AVOWED": 3615,
+ "Ava": 1573,
+ "LT.": 1127,
+ "TOYOTA": 3304,
+ "Te": 964,
+ "Tomorrow,": 4633,
+ "Vivian": 2687,
+ "Wolverhampton": 6870,
+ "Yolanda": 3479,
+ "affidavit": 3671,
+ "café": 1794,
+ "efficiently": 4283,
+ "fluffy": 2270,
+ "office": 2346,
+ "to": 885,
+ "waffled,": 3525,
+ "“quoted”": 4002
+ },
+ "sourcesans/SourceSans3-It.ttf": {
+ "AVOWED": 3442,
+ "Ava": 1477,
+ "LT.": 1027,
+ "TOYOTA": 3102,
+ "Te": 917,
+ "Tomorrow,": 4370,
+ "Vivian": 2480,
+ "Wolverhampton": 6524,
+ "Yolanda": 3323,
+ "affidavit": 3405,
+ "café": 1713,
+ "efficiently": 3964,
+ "fluffy": 2049,
+ "office": 2203,
+ "to": 828,
+ "waffled,": 3294,
+ "“quoted”": 3673
+ },
+ "sourcesans/SourceSans3-Regular.ttf": {
+ "AVOWED": 3621,
+ "Ava": 1488,
+ "LT.": 1045,
+ "TOYOTA": 3298,
+ "Te": 966,
+ "Tomorrow,": 4532,
+ "Vivian": 2525,
+ "Wolverhampton": 6717,
+ "Yolanda": 3342,
+ "affidavit": 3437,
+ "café": 1728,
+ "efficiently": 4124,
+ "fluffy": 2135,
+ "office": 2296,
+ "to": 866,
+ "waffled,": 3345,
+ "“quoted”": 3818
+ },
+ "sourceserif/SourceSerif4-Bold.ttf": {
+ "AVOWED": 4147,
+ "Ava": 1647,
+ "LT.": 1340,
+ "TOYOTA": 3792,
+ "Te": 1078,
+ "Tomorrow,": 5050,
+ "Vivian": 2922,
+ "Wolverhampton": 7410,
+ "Yolanda": 3679,
+ "affidavit": 3768,
+ "café": 1909,
+ "efficiently": 4625,
+ "fluffy": 2471,
+ "office": 2533,
+ "to": 919,
+ "waffled,": 3659,
+ "“quoted”": 4025
+ },
+ "sourceserif/SourceSerif4-BoldIt.ttf": {
+ "AVOWED": 4019,
+ "Ava": 1665,
+ "LT.": 1319,
+ "TOYOTA": 3709,
+ "Te": 1025,
+ "Tomorrow,": 4974,
+ "Vivian": 2900,
+ "Wolverhampton": 7103,
+ "Yolanda": 3644,
+ "affidavit": 3774,
+ "café": 1813,
+ "efficiently": 4387,
+ "fluffy": 2381,
+ "office": 2340,
+ "to": 871,
+ "waffled,": 3588,
+ "“quoted”": 3991
+ },
+ "sourceserif/SourceSerif4-It.ttf": {
+ "AVOWED": 3981,
+ "Ava": 1600,
+ "LT.": 1287,
+ "TOYOTA": 3598,
+ "Te": 936,
+ "Tomorrow,": 4595,
+ "Vivian": 2768,
+ "Wolverhampton": 6620,
+ "Yolanda": 3397,
+ "affidavit": 3493,
+ "café": 1630,
+ "efficiently": 3991,
+ "fluffy": 2182,
+ "office": 2125,
+ "to": 817,
+ "waffled,": 3306,
+ "“quoted”": 3723
+ },
+ "sourceserif/SourceSerif4-Regular.ttf": {
+ "AVOWED": 4121,
+ "Ava": 1602,
+ "LT.": 1340,
+ "TOYOTA": 3740,
+ "Te": 1044,
+ "Tomorrow,": 4891,
+ "Vivian": 2840,
+ "Wolverhampton": 7169,
+ "Yolanda": 3546,
+ "affidavit": 3594,
+ "café": 1846,
+ "efficiently": 4433,
+ "fluffy": 2365,
+ "office": 2458,
+ "to": 874,
+ "waffled,": 3550,
+ "“quoted”": 3822
+ },
+ "zilla/ZillaSlab-Bold.ttf": {
+ "AVOWED": 4223,
+ "Ava": 1665,
+ "LT.": 1341,
+ "TOYOTA": 3939,
+ "Te": 1090,
+ "Tomorrow,": 4866,
+ "Vivian": 2869,
+ "Wolverhampton": 7200,
+ "Yolanda": 3559,
+ "affidavit": 3686,
+ "café": 1797,
+ "efficiently": 4427,
+ "fluffy": 2358,
+ "office": 2376,
+ "to": 921,
+ "waffled,": 3441,
+ "“quoted”": 3890
+ },
+ "zilla/ZillaSlab-BoldItalic.ttf": {
+ "AVOWED": 4057,
+ "Ava": 1614,
+ "LT.": 1291,
+ "TOYOTA": 3780,
+ "Te": 1028,
+ "Tomorrow,": 4469,
+ "Vivian": 2714,
+ "Wolverhampton": 6668,
+ "Yolanda": 3401,
+ "affidavit": 3499,
+ "café": 1710,
+ "efficiently": 4045,
+ "fluffy": 2152,
+ "office": 2183,
+ "to": 843,
+ "waffled,": 3257,
+ "“quoted”": 3631
+ },
+ "zilla/ZillaSlab-Italic.ttf": {
+ "AVOWED": 4030,
+ "Ava": 1562,
+ "LT.": 1238,
+ "TOYOTA": 3735,
+ "Te": 981,
+ "Tomorrow,": 4330,
+ "Vivian": 2614,
+ "Wolverhampton": 6486,
+ "Yolanda": 3283,
+ "affidavit": 3353,
+ "café": 1676,
+ "efficiently": 3899,
+ "fluffy": 2059,
+ "office": 2123,
+ "to": 823,
+ "waffled,": 3129,
+ "“quoted”": 3494
+ },
+ "zilla/ZillaSlab-Regular.ttf": {
+ "AVOWED": 4137,
+ "Ava": 1594,
+ "LT.": 1271,
+ "TOYOTA": 3828,
+ "Te": 1026,
+ "Tomorrow,": 4712,
+ "Vivian": 2740,
+ "Wolverhampton": 6943,
+ "Yolanda": 3403,
+ "affidavit": 3520,
+ "café": 1727,
+ "efficiently": 4256,
+ "fluffy": 2256,
+ "office": 2311,
+ "to": 884,
+ "waffled,": 3334,
+ "“quoted”": 3690
+ }
+ }
+}
diff --git a/scripts/harfbuzz-golden.py b/scripts/harfbuzz-golden.py
new file mode 100644
index 0000000..d11bf0f
--- /dev/null
+++ b/scripts/harfbuzz-golden.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+"""Write internal/fonts/testdata/harfbuzz.json: how HarfBuzz itself, the
+shaper every browser uses, sets a list of words in every face Docs ships.
+
+internal/fonts' TestShapingMatchesHarfBuzz holds the Go shaper (the PDF's)
+to these numbers, so a shaper that kerns or ligates differently from the
+screen fails in CI rather than in someone's PDF. go-text/typesetting
+v0.3.5 did: it applied none of Inter's kerning.
+
+ /tmp/fontvenv/bin/pip install uharfbuzz==0.57.0
+ /tmp/fontvenv/bin/python -I scripts/harfbuzz-golden.py
+"""
+
+import json
+import os
+
+import uharfbuzz as hb
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+FILES = os.path.join(ROOT, "internal", "fonts", "files")
+MANIFEST = os.path.join(ROOT, "internal", "fonts", "fonts.json")
+OUT = os.path.join(ROOT, "internal", "fonts", "testdata", "harfbuzz.json")
+
+WORDS = ["AVOWED", "TOYOTA", "Yolanda", "Tomorrow,", "office", "affidavit", "efficiently", "waffled,",
+ "fluffy", "Wolverhampton", "to", "Ava", "“quoted”", "café", "Te", "LT.", "Vivian"]
+
+
+def main():
+ manifest = json.load(open(MANIFEST, encoding="utf-8"))
+ out = {"comment": "Generated by scripts/harfbuzz-golden.py: each word's advance in font units, as HarfBuzz sets it.", "faces": {}}
+ for fam in manifest["families"]:
+ for style, base in fam["styles"].items():
+ path = os.path.join(FILES, fam["dir"], base + ".ttf")
+ font = hb.Font(hb.Face(hb.Blob.from_file_path(path)))
+ words = {}
+ for w in WORDS:
+ buf = hb.Buffer()
+ buf.add_str(w)
+ buf.guess_segment_properties()
+ buf.language = "en"
+ hb.shape(font, buf, {})
+ words[w] = sum(p.x_advance for p in buf.glyph_positions)
+ out["faces"][fam["dir"] + "/" + base + ".ttf"] = words
+ with open(OUT, "w", encoding="utf-8") as f:
+ json.dump(out, f, indent=1, ensure_ascii=False, sort_keys=True)
+ f.write("\n")
+
+
+if __name__ == "__main__":
+ main()