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 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 16:40:01 -07:00
1 parent e36e758c1c
commit 5dfb50f1a8
5 files changed
+66 -4

No files matched your search

+33
View File
@@ -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));
}
});
+22
View File
@@ -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;
}
+9 -2
View File
@@ -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<Uint8Array> {
@@ -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();
+1 -1
View File
@@ -57,7 +57,7 @@ export function Settings({ onClose }: { onClose: () => void }) {
<button type="submit" class="btn" disabled={busy || !loaded}>Save</button>
<a class="btn" href="/api/calibration.pdf" target="_blank" rel="noopener">Print calibration page</a>
</div>
<p class="help">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.</p>
<p class="help">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.</p>
</form>
</Panel>
);