From 5dfb50f1a8f07a887090bfbe2fb304cbdadbca44 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Thu, 19 Nov 2026 16:40:01 -0700 Subject: [PATCH] Print crop marks around the cards on every sheet Short ticks in the waste frame point at each card edge and move with the calibration offsets, so alignment with the perforations can be checked by eye. The settings help now says which way each offset moves the print. Co-Authored-By: Claude Fable 5.2 --- README.md | 2 +- src/server/pdf/layout.test.ts | 33 +++++++++++++++++++++++++++++++++ src/server/pdf/layout.ts | 22 ++++++++++++++++++++++ src/server/pdf/render.ts | 11 +++++++++-- src/web/components/Settings.tsx | 2 +- 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 136194e..cdc21d4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The header has **Scan**, **Library (N)** and a gear for settings. **How a number is found.** A number is only ever printed without `~` when it came word for word from a catalogue record (Library of Congress, then Open Library) for this exact ISBN or LCCN, and has at least one cutter. Nothing is generated for those. A record that gives only a bare class (such as `GV199.42`, which in that class needs a place cutter next, not an author) is treated as a hint: the app then looks at other editions of the same book in that class, then at similar books in that class, and borrows from them with `~`. If it finds nothing better it prints the bare class and this edition's year with `~`. Books that share a number are shelved by the first author's surname, then title. **Look up again** ignores every saved answer and asks the catalogues afresh. -**Settings** (the gear) holds the camera picker and printer alignment. If the text sits off-centre on the cards, print the calibration page on plain paper, hold it against a real sheet up to the light, and enter the X and Y offsets in millimetres (limit 10). They are saved and applied to every later PDF. +**Settings** (the gear) holds the camera picker and printer alignment. If the text sits off-centre on the cards, print the calibration page on plain paper, hold it against a real sheet up to the light, and enter the X and Y offsets in millimetres (limit 10). They are saved and applied to every later PDF. Every printed sheet also carries small crop marks outside the cards; they should point exactly at the perforations, so you can check the alignment by eye. ## Where the data lives diff --git a/src/server/pdf/layout.test.ts b/src/server/pdf/layout.test.ts index 1e5a226..b46e9a7 100644 --- a/src/server/pdf/layout.test.ts +++ b/src/server/pdf/layout.test.ts @@ -26,3 +26,36 @@ test('corners map to the sheet rectangles', () => { assert.equal(a * 0 + c * CARD.height + e, 126); } }); + +test('cropMarks: 12 segments at the expected places with zero offsets', async () => { + const { cropMarks } = await import('./layout.ts'); + const m = cropMarks({ offsetXmm: 0, offsetYmm: 0 }); + assert.equal(m.length, 12); + assert.equal(m.filter((s) => s.y1 === s.y2).length, 8); + assert.equal(m.filter((s) => s.x1 === s.x2).length, 4); + const has = (x1: number, y1: number, x2: number, y2: number) => + m.some((s) => s.x1 === x1 && s.y1 === y1 && s.x2 === x2 && s.y2 === y2); + for (const y of [72, 288, 504, 720]) { assert.ok(has(104, y, 122, y)); assert.ok(has(490, y, 508, y)); } + for (const x of [126, 486]) { assert.ok(has(x, 50, x, 68)); assert.ok(has(x, 724, x, 742)); } +}); + +test('cropMarks move with the offsets like the cards, and never enter a card', async () => { + const { cropMarks, cardMatrix } = await import('./layout.ts'); + const s = { offsetXmm: 1.5, offsetYmm: -2.25 }; + const z = cropMarks({ offsetXmm: 0, offsetYmm: 0 }); + const o = cropMarks(s); + const [, , , , ex0, ey0] = cardMatrix(1, { offsetXmm: 0, offsetYmm: 0 }); + const [, , , , ex1, ey1] = cardMatrix(1, s); + z.forEach((a, i) => { + assert.ok(Math.abs(o[i].x1 - a.x1 - (ex1 - ex0)) < 1e-9); + assert.ok(Math.abs(o[i].y1 - a.y1 - (ey1 - ey0)) < 1e-9); + assert.ok(Math.abs(o[i].x2 - a.x2 - (ex1 - ex0)) < 1e-9); + assert.ok(Math.abs(o[i].y2 - a.y2 - (ey1 - ey0)) < 1e-9); + }); + const dx = ex1 - ex0, dy = ey1 - ey0; + for (const m of o) { + const inX = Math.max(m.x1, m.x2) > 126 + dx && Math.min(m.x1, m.x2) < 486 + dx; + const inY = Math.max(m.y1, m.y2) > 72 + dy && Math.min(m.y1, m.y2) < 720 + dy; + assert.ok(!(inX && inY)); + } +}); diff --git a/src/server/pdf/layout.ts b/src/server/pdf/layout.ts index 84cdac8..ecb10ea 100644 --- a/src/server/pdf/layout.ts +++ b/src/server/pdf/layout.ts @@ -14,3 +14,25 @@ export function cardMatrix(position: 1 | 2 | 3, s: Settings): Matrix { const dy = s.offsetYmm * PT_PER_MM; return [0, 1, -1, 0, 486 + dx, Y_BOTTOM[position] - dy]; } + +export interface Segment { x1: number; y1: number; x2: number; y2: number } + +/** + * Crop marks in sheet coordinates, shifted by the calibration offsets exactly like the cards. + * Horizontal ticks sit in the left and right strips at each card boundary; vertical ticks sit in the + * bottom and top strips at each card edge. Every tick is 18 pt long and ends 4 pt short of the card area. + */ +export function cropMarks(s: Settings): Segment[] { + const dx = s.offsetXmm * PT_PER_MM; + const dy = s.offsetYmm * PT_PER_MM; + const out: Segment[] = []; + for (const y of [72, 288, 504, 720]) { + out.push({ x1: 104 + dx, y1: y - dy, x2: 122 + dx, y2: y - dy }); + out.push({ x1: 490 + dx, y1: y - dy, x2: 508 + dx, y2: y - dy }); + } + for (const x of [126, 486]) { + out.push({ x1: x + dx, y1: 50 - dy, x2: x + dx, y2: 68 - dy }); + out.push({ x1: x + dx, y1: 724 - dy, x2: x + dx, y2: 742 - dy }); + } + return out; +} diff --git a/src/server/pdf/render.ts b/src/server/pdf/render.ts index dee5f15..e94adfc 100644 --- a/src/server/pdf/render.ts +++ b/src/server/pdf/render.ts @@ -6,7 +6,7 @@ import type { PDFFont, PDFPage } from 'pdf-lib'; import fontkit from '@pdf-lib/fontkit'; import type { CardData, Settings } from '../../shared/types.ts'; import { layoutCard, MARGIN_X, TEXT_WIDTH } from './card.ts'; -import { SHEET, CARD, cardMatrix } from './layout.ts'; +import { SHEET, CARD, cardMatrix, cropMarks } from './layout.ts'; interface Fonts { regular: PDFFont; bold: PDFFont; has: (cp: number) => boolean } @@ -83,6 +83,13 @@ function drawCard(page: PDFPage, card: CardData, fonts: Fonts) { }); } +/** Small ticks in the waste frame that should point at the card perforations. */ +function drawCropMarks(page: PDFPage, s: Settings) { + for (const m of cropMarks(s)) { + page.drawLine({ start: { x: m.x1, y: m.y1 }, end: { x: m.x2, y: m.y2 }, thickness: 0.4, color: rgb(0, 0, 0) }); + } +} + export async function renderCardsPdf( cards: CardData[], opts: Settings & { startPosition: 1 | 2 | 3 }, ): Promise { @@ -92,7 +99,7 @@ export async function renderCardsPdf( cards.forEach((card, i) => { const slot = opts.startPosition - 1 + i; const pos = ((slot % 3) + 1) as 1 | 2 | 3; - if (!page || pos === 1) page = doc.addPage([SHEET.width, SHEET.height]); + if (!page || pos === 1) { page = doc.addPage([SHEET.width, SHEET.height]); drawCropMarks(page, opts); } inCardSpace(page, cardMatrix(pos, opts), () => drawCard(page!, card, fonts)); }); return doc.save(); diff --git a/src/web/components/Settings.tsx b/src/web/components/Settings.tsx index 25ca035..f18431a 100644 --- a/src/web/components/Settings.tsx +++ b/src/web/components/Settings.tsx @@ -57,7 +57,7 @@ export function Settings({ onClose }: { onClose: () => void }) { Print calibration page -

Print the calibration page on plain paper, hold it over a real sheet up to a light, and enter how far the lines are off, up to 10 mm. Always print at 100% scale ("Actual size"), not "Fit to page"; the calibration page has a 6 inch line to check it.

+

Print the calibration page on plain paper, hold it over a real sheet up to a light, and enter how far the lines are off, up to 10 mm. Always print at 100% scale ("Actual size"), not "Fit to page"; the calibration page has a 6 inch line to check it. A positive Offset X moves everything toward the bottom of the cards (a negative one toward the top, where the call number is). A positive Offset Y moves everything toward the left of the cards, a negative one toward the right. The small marks around the cards on every printed sheet should point exactly at the perforations.

);