mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(studio): 34 typefaces with real weights and italics, a categorised font picker
The book catalogue grows from 7 families to 34, all self-hosted through @fontsource under the SIL OFL 1.1 or the Apache License 2.0: condensed and poster faces, heavy retro display, elegant display serifs, Montserrat, twelve scripts and DM Mono. Weights run from 100 to 900, each family offering only the weights it ships, and the serifs gain real italics. The catalogue lives in @trek/shared (book-fonts.data.ts) with each family's roles (display, heading, body, script, mono), weights, italics and letter width, so the Studio, the findings, the design engine and the assistant read one list. Page operations and the design engine set a weight a family lacks at its nearest one, describe_book_page names the role and the weight, and font_mix no longer counts scripts and mono faces, warning above three. The Studio gets StudioFontPicker: the current family set in itself, a searchable list grouped by kind with every family in its own face and the book's own families first, and a weight slider over the weights the family has. Faces load only when used; the assistant's page snapshot embeds only the faces a page draws, the service worker installs only the latin files of the original seven families, and the faces of an opened book are cached for offline use. BOOK_SCHEMA_REV goes to 2.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { buildBook, distributeGallery } from '../auto/auto-book';
|
||||
import type { AutoEntry, AutoInput, AutoPhoto } from '../auto/auto-types';
|
||||
import { bookLevelFindings, sortBookFindings } from '../book-findings-design';
|
||||
import { withRealWeight } from '../book-fonts';
|
||||
import { bookElementId } from '../book-ids';
|
||||
import type { BookPhotoInfo } from '../book-ops-core';
|
||||
import type { BookFinding } from '../book-ops.schema';
|
||||
@@ -252,7 +253,9 @@ export function designBook(
|
||||
const repairCtx = { page, photos: input.photos, look, newId };
|
||||
const designed = [...framing, ...inner.spreads, ...closing].map((d): DesignedSpread => {
|
||||
const fixed = repairSpread(d.spread, repairCtx);
|
||||
return { ...d, spread: fixed.spread, findings: fixed.findings };
|
||||
// Every face at a weight its family has: a travel element's bold in a one-weight poster face would be faked.
|
||||
const spread = { ...fixed.spread, elements: fixed.spread.elements.map(withRealWeight) };
|
||||
return { ...d, spread, findings: fixed.findings };
|
||||
});
|
||||
|
||||
const merged = mergeDesign(doc, designed, directives.keep);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AutoEntry, AutoPhoto } from '../auto/auto-types';
|
||||
import { DESIGN_TEXT_HEADROOM, MIN_PRINT_DPI, textHeightNeeded } from '../book-findings';
|
||||
import { nearestBookWeight } from '../book-fonts';
|
||||
import type { BookPhotoInfo } from '../book-ops-core';
|
||||
import { formatBookDate } from '../book-text';
|
||||
import { bookBadgeValue, bookTravelBadge, type BookTravelContext } from '../book-travel';
|
||||
@@ -158,6 +159,7 @@ type TextAt = Pick<BookFrame, 'x' | 'y' | 'w'>;
|
||||
/** A text in the book's look, its frame as tall as its words need. */
|
||||
export function textEl(c: ComposeCtx, at: TextAt, words: string, role: TextRole, opts: TextOpts = {}): BookTextElement {
|
||||
const defaultColour = role === 'caption' || role === 'meta' ? c.look.muted : c.look.ink;
|
||||
const font = role === 'heading' || role === 'sub' ? c.look.heading : c.look.body;
|
||||
const el: BookTextElement = {
|
||||
id: c.newId('t'),
|
||||
kind: 'text',
|
||||
@@ -166,9 +168,10 @@ export function textEl(c: ComposeCtx, at: TextAt, words: string, role: TextRole,
|
||||
opacity: 1,
|
||||
locked: false,
|
||||
text: words,
|
||||
font: role === 'heading' || role === 'sub' ? c.look.heading : c.look.body,
|
||||
font,
|
||||
size: opts.size ?? c.look.sizes[role],
|
||||
weight: WEIGHT[role],
|
||||
// A family that lacks the role's weight is set at its nearest, never at a synthesised one.
|
||||
weight: nearestBookWeight(font, WEIGHT[role]) as BookTextElement['weight'],
|
||||
italic: false,
|
||||
align: opts.align ?? 'left',
|
||||
leading: LEADING[role],
|
||||
@@ -258,7 +261,7 @@ export function titleBlock(
|
||||
if (value) {
|
||||
const chip = frameOf(box.x, y, scaled(c, 24), scaled(c, 7));
|
||||
const badge = bookTravelBadge({ id: c.newId('bd'), frame: chip, variant: 'day', value });
|
||||
els.push({ ...badge, font: c.look.heading, accent: c.look.accent });
|
||||
els.push({ ...badge, font: c.look.figures, accent: c.look.accent });
|
||||
y += chip.h + 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ export function composeSummary(
|
||||
const textSide = mapSide === 'left' ? 'right' : 'left';
|
||||
const els: BookElement[] = [];
|
||||
const map = bookTravelMap(c.travel, stats, { id: c.newId('mp'), frame: liveBox(c, mapSide), scope: 'journey' });
|
||||
els.push({ ...map, style: c.look.mapStyle, font: c.look.heading, color: c.look.ink, accent: c.look.accent });
|
||||
els.push({ ...map, style: c.look.mapStyle, font: c.look.figures, color: c.look.ink, accent: c.look.accent });
|
||||
const head = label(c, words, textSide);
|
||||
els.push(...head.els);
|
||||
const metrics = metricsOf(c, stats);
|
||||
@@ -169,7 +169,7 @@ export function composeSummary(
|
||||
const box = liveBox(c, textSide);
|
||||
const frame = frameOf(box.x, head.bottom, box.w, Math.min(box.h * 0.6, box.y + box.h - head.bottom));
|
||||
const figures = bookTravelStats(stats, { id: c.newId('st'), frame, metrics });
|
||||
els.push({ ...figures, font: c.look.heading, color: c.look.ink, accent: c.look.accent });
|
||||
els.push({ ...figures, font: c.look.figures, color: c.look.ink, accent: c.look.accent });
|
||||
}
|
||||
return els;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ export function composeCountries(c: ComposeCtx, words: string): BookElement[] {
|
||||
const head = label(c, words, 'left');
|
||||
const box = liveBox(c, 'right');
|
||||
const countries = bookTravelCountries(c.travel, { id: c.newId('co'), frame: box });
|
||||
return [...head.els, { ...countries, font: c.look.heading, color: c.look.ink, accent: c.look.accent }];
|
||||
return [...head.els, { ...countries, font: c.look.figures, color: c.look.ink, accent: c.look.accent }];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -146,7 +146,7 @@ function listUnder(c: ComposeCtx, entry: AutoEntry, foot: Foot): BookElement | n
|
||||
if (foot.top + h > foot.bottom) return null;
|
||||
const labels = { pros: c.travel.labels.pros, cons: c.travel.labels.cons };
|
||||
const list = bookTravelList(labels, { id: c.newId('li'), frame: frameOf(foot.x, foot.top, foot.w, h), items });
|
||||
return { ...list, font: c.look.heading, color: c.look.ink, accent: c.look.accent };
|
||||
return { ...list, font: c.look.figures, color: c.look.ink, accent: c.look.accent };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +293,7 @@ function chapterMap(c: ComposeCtx, entry: AutoEntry, box: BookFrame): BookElemen
|
||||
const h = box.h * 0.3;
|
||||
const frame = frameOf(box.x, box.y + box.h - h, box.w, h);
|
||||
const map = bookTravelMap(c.travel, stats, { id: c.newId('mp'), frame, scope: { tripId } });
|
||||
const look = { style: c.look.mapStyle, font: c.look.heading, color: c.look.ink, accent: c.look.accent };
|
||||
const look = { style: c.look.mapStyle, font: c.look.figures, color: c.look.ink, accent: c.look.accent };
|
||||
return { ...map, ...look, pinStyle: 'dot' };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { bookFontHasWeight } from '../book-fonts';
|
||||
import { bookPageSetupSchema, type BookDocument, type BookTextElement } from '../book.schema';
|
||||
import { designBook, type BookDesignInput } from './design-book';
|
||||
import { bookDesignDirectivesSchema, type BookDesignDirectivesInput } from './design-directives.schema';
|
||||
@@ -7,7 +8,7 @@ import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
// BOOKSTY-001 to BOOKSTY-004
|
||||
// BOOKSTY-001 to BOOKSTY-007
|
||||
|
||||
/**
|
||||
* The type scale of a designed book: `type.scale` reaches a poster's sizes,
|
||||
@@ -78,3 +79,29 @@ describe('the cover title', () => {
|
||||
expect((big?.frame.y ?? 0) + (big?.frame.h ?? 0)).toBeLessThanOrEqual(page.pageHeight);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the typefaces by their roles', () => {
|
||||
it('BOOKSTY-005: keeps a body face that sets running text, and falls back to the style for one that does not', () => {
|
||||
expect(lookOf({ style: 'classic', type: { body: 'garamond' } }).body).toBe('garamond');
|
||||
// A poster face and a script are a title's, never a story's.
|
||||
expect(lookOf({ style: 'classic', type: { body: 'anton' } }).body).toBe('sans');
|
||||
expect(lookOf({ style: 'editorial', type: { body: 'caveat' } }).body).toBe('garamond');
|
||||
});
|
||||
|
||||
it('BOOKSTY-006: sets the travel elements in the heading face, unless that is a script or a mono face', () => {
|
||||
expect(lookOf({ style: 'bold' }).figures).toBe('bebas');
|
||||
const script = lookOf({ style: 'journal', type: { heading: 'caveat' } });
|
||||
expect([script.heading, script.figures]).toEqual(['caveat', 'garamond']);
|
||||
expect(lookOf({ style: 'classic', type: { heading: 'mono', body: 'inter' } }).figures).toBe('inter');
|
||||
});
|
||||
|
||||
it('BOOKSTY-007: sets every text and travel element at a weight its family really has', () => {
|
||||
const { doc } = designBook(null, rich(), { style: 'bold', type: { heading: 'anton' } });
|
||||
const typeset = doc.spreads.flatMap((s) => s.elements.filter((e) => 'weight' in e && 'font' in e));
|
||||
expect(typeset.length).toBeGreaterThan(0);
|
||||
for (const el of typeset) {
|
||||
if ('weight' in el && 'font' in el) expect(bookFontHasWeight(el.font, el.weight), el.id).toBe(true);
|
||||
}
|
||||
expect(typeset.some((e) => 'font' in e && e.font === 'anton')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { accentFromPalettes, contrastRatio, parseHex, readPalette, readableInk, toHex } from '../book-colour';
|
||||
import { bookFontCountsInMix, bookFontSuits } from '../book-fonts';
|
||||
import type { BookPhotoInfo } from '../book-ops-core';
|
||||
import type { BookFontFamily, BookPageSetup, BookPhotoElement } from '../book.schema';
|
||||
import type { BookDesignDirectives, BookDesignStyle } from './design-directives.schema';
|
||||
@@ -7,8 +8,12 @@ import type { BookDesignDirectives, BookDesignStyle } from './design-directives.
|
||||
* The look of a designed book: its paper, ink, accent, the two typefaces,
|
||||
* the type sizes and the page grid, from the style and the directives.
|
||||
*
|
||||
* At most two families per book; badges, figures, maps and lists take the
|
||||
* heading face. Sizes are set for a 210 mm page and scale with the page
|
||||
* At most two families per book, read by their roles (book-fonts.data.ts):
|
||||
* the body face has to be one that sets running text, so a poster face or a
|
||||
* script asked for as the body falls back to the style's own. Badges,
|
||||
* figures, maps and lists take the heading face, unless that is a script or
|
||||
* a mono face, which sets a title well and a column of figures badly; then
|
||||
* they take the body face. Sizes are set for a 210 mm page and scale with the page
|
||||
* width, times `type.scale`, never under what a reader can read and never
|
||||
* over what a text element takes. The cover title has a tier of its own,
|
||||
* `display`, the heading size times `type.display`: 1 by default, so a book
|
||||
@@ -31,6 +36,8 @@ export interface BookDesignLook {
|
||||
onScrim: string;
|
||||
heading: BookFontFamily;
|
||||
body: BookFontFamily;
|
||||
/** The face of the travel elements: figures, marks, maps and lists. */
|
||||
figures: BookFontFamily;
|
||||
/** Points. `display` is the cover title's, the heading's unless `type.display` raises it. */
|
||||
sizes: { display: number; heading: number; sub: number; body: number; caption: number; meta: number };
|
||||
/** The frame decoration and the slight turn a scrapbook gives its pictures. */
|
||||
@@ -172,6 +179,8 @@ export function designLook(
|
||||
const size = (role: keyof typeof BASE_SIZES, times = 1) =>
|
||||
Math.min(MAX_PT, Math.max(FLOOR[role], round1(BASE_SIZES[role] * scale * times)));
|
||||
const heading = directives.type?.heading ?? preset.heading;
|
||||
const asked = directives.type?.body;
|
||||
const body = asked && bookFontSuits(asked, 'body') ? asked : preset.body;
|
||||
return {
|
||||
style: directives.style,
|
||||
paper: colours.paper,
|
||||
@@ -182,7 +191,8 @@ export function designLook(
|
||||
scrimOpacity: 0.6,
|
||||
onScrim: '#ffffff',
|
||||
heading,
|
||||
body: directives.type?.body ?? preset.body,
|
||||
body,
|
||||
figures: bookFontCountsInMix(heading) ? heading : body,
|
||||
sizes: {
|
||||
display: size('heading', directives.type?.display ?? 1),
|
||||
heading: size('heading'),
|
||||
|
||||
Reference in New Issue
Block a user