Skip to content

feat(fonts): give imported fonts a fallback of their own kind - #1680

Merged
gregpriday merged 6 commits into
developfrom
feature/issue-1490-imported-serif-and-monospace-fonts-fall
Nov 28, 2026
Merged

gregpriday merged 6 commits into
developfrom
feature/issue-1490-imported-serif-and-monospace-fonts-fall

Conversation

@gregpriday

Copy link
Copy Markdown
Member

Resolves #1490

An imported font's stack always ended in system-ui, sans-serif, so a serif display face or a monospace body face fell back to the system sans while its file loaded and for any glyph it lacked. The importer now reads what kind of face the file is, and the stack ends in a fallback of that kind. Where the file doesn't say, the font select lets the author choose.

Changes

  • Reading the kind (src/main/project/media.ts, fontCategory): post.isFixedPitch or a monospaced PANOSE proportion means monospace. Otherwise the OS/2 IBM family class decides serif or sans, then the PANOSE serif style (Latin text only) when the class is 0. Script, ornamental and symbol classes, and all-zero tables (as most Google/Fontsource fonts ship), leave it unknown. The proportion byte is also read when the PANOSE family kind is 0: Fontsource's Roboto Mono sets only that. A short or unreadable post table never refuses a font.
  • Stored per face as FontFace.category (operation schema included). A family's kind is the one kind its faces agree on: an italic that says nothing takes its upright's, and faces that disagree leave it unknown, in any order. Editing a face's family, weight or style keeps its kind.
  • Stacks (src/shared/fonts.ts): serif ends in Georgia, 'Times New Roman', serif and monospace in ui-monospace, 'SF Mono', Menlo, Consolas, monospace (the built-in fonts' own). Sans-serif and unknown keep system-ui, sans-serif. The font select's options, import-and-choose, a bare imported name typed into a style (resolveFontStack), update_site_brand, and the Fonts tab preview all use it.
  • Font select: when the chosen font is imported and of unknown kind, a labelled Fallback select (Sans-serif / Serif / Monospace) appears below it. It reads from the stored stack, shows "Custom fallback" for a tail of the author's own, writes only on a choice, and keeps the stack's own spelling of the family. It stays hidden for a style that follows another and for a bare CSS keyword. The wrapper stays mounted, so the font select keeps focus as the row comes and goes.
  • update_site_brand naming again an imported font of unknown kind that a style already leads with keeps that style's stack, so an author's chosen fallback survives.

Testing

  • Own: tests/unit/media.test.ts (kind detection across WOFF and WOFF2, short tables, conflicting signals), tests/unit/fonts.test.ts (schema, stacks, family agreement, a bare name into generated tokens.css, removal, face edits, fallback read and swap), tests/unit/agent-tools.test.ts (brand tool by kind, a kept author fallback, built-in font restacked), and a new real-browser tests/unit/font-select-browser.test.ts (options by kind, choosing a fallback, custom tail, follows, keyword, focus).
  • Checked against real @fontsource files: IBM Plex Mono, JetBrains Mono and Roboto Mono read as monospace, and Source Serif 4 as serif. Lora, Fraunces, Inter, DM Sans and others read as unknown.
  • Adjacent: 20 test files importing the changed modules, green.
  • Impact: 66 of 654 unit test files (10%), green before and after rebasing onto the current develop.
  • npm run typecheck:changed green.
  • tests/e2e/fonts.mjs was not run or extended.

…, re-imports and the brand tool

- asset.update keeps a category the update omits; a re-imported duplicate gets a missing category alone
- update_site_brand keeps the stack of the font a token already uses
- PANOSE serif style is read only for Latin text; double-quoted fallback tails are recognised
- the font select keeps one wrapper so focus survives the fallback row, and asks nothing for a bare keyword
… backfill

- update_site_brand keeps a style's stack only for an imported font of unknown kind it already leads with
- asset.update keeps the saved kind when the update gives none, even as an explicit undefined
- a re-imported duplicate no longer rewrites its face (pre-release: no backfill of older records)
@gregpriday
gregpriday force-pushed the feature/issue-1490-imported-serif-and-monospace-fonts-fall branch from cf4d5b0 to f2bf9a1 Compare November 28, 2026 10:23
@gregpriday
gregpriday merged commit b6fce24 into develop Nov 28, 2026
1 check failed
@gregpriday
gregpriday deleted the feature/issue-1490-imported-serif-and-monospace-fonts-fall branch November 28, 2026 10:24
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.

Imported serif and monospace fonts fall back to a sans-serif

1 participant