Saltar al contingut principal
Recepta número 193

Receptari · Capítol 10 · Sortida i integració

Un llibre de cartró de cucut amb forats en registre

Quatre forats troquelats on la pintura següent guarda el que enganya, una finestra que baixa a un forat més petit, cantonades arrodonides i línia de troquel.

En aquesta pàgina
Nivell
Intermedi
Postext
Provada amb Postext 1.84.0
Requereix ≥ 1.84.0 · postext-pdf ≥ 1.84.0
Llicència
Actualitzada el 13 de nov. del 2026
Codi MIT · Text CC BY 4.0
  • Mostra en castellà: encara no hi ha edició en català
  • Format 160 × 160 mm
  • 1 columna
  • Andika 24/31
  • Fredoka
  • Nunito
  • 14 pàgines
  • Nivell
  • Postext 1.84.0
  • Compost en 7 ms
  • 187 línies de codi

En poques paraules

Un llibre de cartró per als més petits. Cada forat d’una pàgina deixa veure un trosset del dibuix següent, el text fa una pregunta i en girar el full es veu què era de debò.

Què compondràs

Cucut! Qui hi ha al jardí?, un llibre de cartró de catorze pàgines en un quadrat de 160 mm amb les quatre cantonades arrodonides. Cada pintura té un forat, i el forat és just on la pintura següent guarda la part que enganya l’ull: el llom ratllat d’un gat adormit que podria ser un tigre, la llana d’una ovella que podria ser un núvol, un fanalet que podria ser la lluna. La finestra de la coberta és més ampla que el forat de darrere, i la primera mirada arriba dues pàgines al fons. El text de l’esquerra pregunta; en girar el full arriba la resposta. El PDF d’impremta porta la línia de troquel en una planxa pròpia.

Aquesta recepta respon a

  • Com troquelo forats a les pàgines d’un llibre perquè cadascun deixi veure part del dibuix següent?
  • Com lliuro al troquelista la línia de troquel en una planxa pròpia del PDF?

La resposta curta

script.js · línies 43–61al codi complet
// Each painting is cut where the next one's telling part lies: the cat's striped flank, the
// sheep's wool, the lantern's glow. The cover's window is wider than the hedge's hole and
// holds it, so from the cover you see the hedge, and through the hedge the cat. A hole cuts
// both sides of its leaf, mirrored on the verso, and the words there run round it.
const circle = (id, name, cx, cy, d) => ({ id, name, shape: 'circle', x: mm(cx - d / 2),
  y: mm(cy - d / 2), width: mm(d), height: mm(d), wrap: { gap: mm(4) } });
const dieCuts = {
  shapes: [
    circle('window', t({ en: 'Cover window', es: 'Ventana de la cubierta' }), 112, 68, 60),
    circle('hedge', t({ en: 'Gap in the hedge', es: 'Hueco del seto' }), 112, 60, 36),
    { id: 'knot', name: t({ en: 'Knothole', es: 'Nudo de la valla' }), shape: 'ellipse',
      x: mm(102), y: mm(48), width: mm(32), height: mm(40), wrap: { gap: mm(4) } },
    circle('peephole', t({ en: 'Barn-door peephole', es: 'Mirilla del granero' }), 91, 29, 20),
  ],
  // By position in the book: page 1 is the cover, 3 the hedge, 7 the fence, 11 the door.
  pages: [{ pages: '1', die: 'window' }, { pages: '3', die: 'hedge' },
    { pages: '7', die: 'knot' }, { pages: '11', die: 'peephole' }],
  corners: { radius: mm(9), edges: 'all' }, // board books are rounded on all four corners
};

Ingredients

Tipografia
Andika, Fredoka, Nunito (SIL OFL 1.1)
Recursos
  • cat.jpg
  • cover.jpg
  • door.jpg
  • fence.jpg
  • hedge.jpg
  • lantern.jpg
  • sheep.jpg
  • Cover painting: a cottage garden, a hedge, hollyhocks and a robin (Generated With Diffusion Models, original)
  • Page 3: the hedge (Generated With Diffusion Models, original)
  • Page 5: the ginger cat asleep (Generated With Diffusion Models, original)
  • Page 7: the wooden fence (Generated With Diffusion Models, original)
  • Page 9: the sheep (Generated With Diffusion Models, original)
  • Page 11: the barn door (Generated With Diffusion Models, original)
  • Page 13: Grandpa and his lantern at dusk (Generated With Diffusion Models, original)

Elaboració

#1 · Forats on el dibuix següent es delata

El codi és la resposta curta de dalt. Cada forma es col·loca des de la cantonada superior esquerra del tall i dieCuts.pages diu quina pàgina talla, comptant des de la primera del llibre. Mesura el forat sobre la pintura que descobreix, no sobre la pàgina on es talla: la bardissa, la tanca i la porta són textures que admeten un forat a qualsevol lloc; el gat i el fanalet, no.

#2 · Pintures en registre amb els forats

script.js · línies 65–84al codi complet
// Each painting hangs from the trim and runs BLEED past it on every side, so the holes hit it
// in the same place on screen and in print. A picture's section drops the foot margin, so its
// design reaches the foot of the page; the words on the verso behind it, in the same section,
// start TOP down.
const SHEET = { width: mm(TRIM + 2 * BLEED), height: mm(TRIM + 2 * BLEED) }; // trim + bleed
const painting = { kind: 'image', id: 'painting', resourceId: '{attr.picture}', fit: 'cover',
  placement: at('page', 'top-left', -BLEED, -BLEED, SHEET) };
const full = (elements) => ({ enabled: true, minHeight: mm(TRIM - TOP), slot: { elements } });
const flush = { margins: { top: mm(TOP), bottom: mm(0), left: mm(INNER), right: mm(OUTER) } };
const title = { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY,
  fontWeight: 600, fontSize: pt(40), lineHeight: 1, color: col('accent'), align: 'left',
  placement: at('page', 'top-left', 62, 8, { width: mm(88) }) };
const headingStyles = [
  { id: 'cover', numbered: false, toc: false, ...flush, advancedDesign: full([painting, title]) },
  { id: 'picture', numbered: false, ...flush, breakBefore: { enabled: true, parity: 'odd' },
    advancedDesign: full([painting]) },
  // The back cover: the board printed dusk blue (the section's palette), the type in cream.
  { id: 'back', numbered: false, toc: false, breakBefore: { enabled: true, parity: 'even' },
    color: col('cream'), palette: { paper: palette.dusk } },
];

Els forats van en mil·límetres des del tall, de manera que cada pintura penja del tall i el sobrepassa el sagnat pels quatre costats, igual en pantalla que a la impremta. L’estil de les pintures només treu el marge inferior: el disseny arriba al peu de la pàgina, i el text del vers de darrere conserva els 44 mm de marge superior, que el baixen per sota dels forats petits.

#3 · La línia de troquel en la seva planxa

script.js · línies 96–99al codi complet
  // The die line is stroked on a Separation plate of its own ('Die'), overprinting, that the
  // press never inks. PDF/X-4 on coated stock: the board is printed on coated paper.
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

El PDF imprimeix cada pàgina sencera i traça el contorn de cada forat, i de cada full arrodonit, en una separació Die en sobreimpressió que mai no s’entinta. convertImages: false deixa les pintures com a JPEG RGB etiquetats sRGB, que PDF/X-4 admet, i el fitxer continua sent petit.

#4 · El llibre a la mà

script.js · línies 122–128al codi complet
  folio: {
    tilt: 50, yaw: -32,
    paper: { type: 'board', shade: '#fbf5e8' },
    binding: { type: 'hardcover', cover: 'pages', coverMaterial: 'paper' },
    surface: { type: 'oak' },
    lighting: { environment: 'daylight', intensity: 1.05 },
  },

Folio talla els forats a cada full i ensenya les pàgines de sota amb les parets del tall, i la finestra escalonada es llegeix com a profunditat. El cartró passa rígid i les cantonades arrodonides es tallen a tots els fulls.

#5 · Pàgines planes que deixen veure

script.js · línies 242–252al codi complet
// renderPageToCanvas cuts the holes; `beneath` hands it the pages under them, painted here
// at a lower scale (the composite stretches them to the page), each with its own holes.
const under = new Map();
const beneath = (i) => {
  if (!under.has(i) && doc.pages[i]) {
    const canvas = document.createElement('canvas');
    under.set(i, canvas);
    renderPageToCanvas(doc.pages[i], doc, canvas, { scale: 1, beneath });
  }
  return under.get(i);
};

Al canvas, un forat mostra el que hi hagi darrere del canvas si el renderitzador no rep les pàgines de sota. beneath les retorna per índex, cadascuna pintada amb els seus forats, i així la coberta deixa veure la bardissa i, a través de la bardissa, el gat.

La recepta completa

Sandbox
// ═══ Postext Cookbook · Nº 193 · A peek-a-boo board book with holes in register ════════
// https://postext.dev/en/cookbook/peek-a-boo-board-book
// Code: MIT · Text: original (CC BY 4.0) · Paintings: generated with diffusion models
// Fonts: Andika, Fredoka, Nunito (SIL OFL 1.1) · Needs postext ≥ 1.84.0
//
// A fourteen-page board book for toddlers: on every other recto a hole is cut through the
// painting, and what shows through it is a scrap of the next picture. The words on the left
// make a guess from the scrap; the turned page shows what it really is. The leaves have
// rounded corners, the holes step down from the cover, and the PDF carries the die line.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'peek-a-boo-board-book';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a cream board, a robin red for the title and the guesses, a dusk blue
const palette = {
  ink: '#2a2420', // text: a warm near-black
  accent: '#b8432c', // the cover title and the guesses: the robin's breast
  paper: '#fbf5e8', // the board the words are printed on
  dusk: '#253a63', // the back cover, the blue of the last painting's sky
  cream: '#fff9ec', // type on the cover and the back
  muted: '#7a6f64', // the colophon
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// #endregion
const [TRIM, BLEED] = [160, 3]; // mm: a square board book, and its bleed
const [TOP, FOOT, INNER, OUTER] = [44, 16, 18, 16]; // the words sit low, under the holes' tops
const [TEXT, DISPLAY, LABEL] = ['Andika', 'Fredoka', 'Nunito'];
const LEAD = 31; // pt: 24 pt type on a generous leading, for reading aloud
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });

// #region answer: the dies, and the pages they cut
// Each painting is cut where the next one's telling part lies: the cat's striped flank, the
// sheep's wool, the lantern's glow. The cover's window is wider than the hedge's hole and
// holds it, so from the cover you see the hedge, and through the hedge the cat. A hole cuts
// both sides of its leaf, mirrored on the verso, and the words there run round it.
const circle = (id, name, cx, cy, d) => ({ id, name, shape: 'circle', x: mm(cx - d / 2),
  y: mm(cy - d / 2), width: mm(d), height: mm(d), wrap: { gap: mm(4) } });

L'script.js compost funciona tal com és: enganxa'l com a script de mòdul en qualsevol pàgina o obre la recepta a CodePen. Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)

Variants

#Arrodoneix només les cantonades del tall davanter

Un àlbum il·lustrat arrodoneix les dues cantonades lluny del llom i deixa el llom en escaire.

-  corners: { radius: mm(9), edges: 'all' }, // board books are rounded on all four corners
+  corners: { radius: mm(6), edges: 'fore' },

#Talla cada full amb una forma

Un contorn en unitats de viewBox talla cada full, en mirall als versos; mana sobre les cantonades.

   corners: { radius: mm(9), edges: 'all' }, // board books are rounded on all four corners
+  outline: { d: 'M0 0.35 L0.5 0 L1 0.35 L1 1 L0 1 Z', viewBox: [1, 1] }, // a house

Crèdits

Text
  • The words of the board book · Postext Cookbook · CC BY 4.0
Imatges
  • Cover painting: a cottage garden, a hedge, hollyhocks and a robin · Generated With Diffusion Models · original
  • Page 3: the hedge · Generated With Diffusion Models · original
  • Page 5: the ginger cat asleep · Generated With Diffusion Models · original
  • Page 7: the wooden fence · Generated With Diffusion Models · original
  • Page 9: the sheep · Generated With Diffusion Models · original
  • Page 11: the barn door · Generated With Diffusion Models · original
  • Page 13: Grandpa and his lantern at dusk · Generated With Diffusion Models · original
Fonts
Andika (SIL OFL 1.1) · Fredoka (SIL OFL 1.1) · Nunito (SIL OFL 1.1)
SandboxPDF