Saltar al contingut principal
Recepta número 194

Receptari · Capítol 10 · Sortida i integració

Una coberta amb finestra que emmarca la portada

Una finestra oval troquelada a la coberta amb dieCuts, mesurada sobre la pintura de la portada perquè la vora caigui a l’or, i la línia de troquel a part.

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 130 × 195 mm
  • 1 columna
  • EB Garamond 10,5/14
  • Cormorant Garamond
  • 10 pàgines
  • Nivell
  • Postext 1.84.0
  • Compost en 14 ms
  • 179 línies de codi

En poques paraules

Un llibret de tapa dura amb un conte de Poe, amb una coberta estampada que té un forat oval. Pel forat es veu la cara del retrat imprès a la portada de sota.

Què compondràs

El retrat oval, el conte d’Edgar Allan Poe de 1842 en el text més breu que va publicar el 1845, com un llibret de tapa dura de deu pàgines en 130 × 195 mm. La coberta és un domàs antic amb una finestra oval troquelada. A sota hi ha la portada, el retrat mateix en el seu marc daurat a la morisca, i la finestra està posada perquè la vora caigui sobre el daurat: tancat, el llibre ensenya el rostre pintat emmarcat dues vegades, per l’or i pel tall. El conte continua en paper crema amb una caplletra, i la contracoberta repeteix el domàs amb el text sobre un plafó fosc. El PDF d’impremta porta el contorn de la finestra en una planxa pròpia.

Aquesta recepta respon a

  • Com troquelo una finestra a la coberta que emmarqui la portada de sota?
  • Com lliuro al troquelista la línia de troquel en una planxa pròpia del PDF?

La resposta curta

script.js · línies 41–48al codi complet
// The window is cut through the first leaf, so the closed book shows page 3 through it.
// Its size is measured on the title-page painting: a little wider than the frame's opening,
// so the cut edge falls on the gilt and the face sits in the middle of the hole.
const dieCuts = {
  shapes: [{ id: 'window', name: t({ en: 'Oval window', es: 'Ventana oval' }),
    shape: 'ellipse', x: mm(26), y: mm(15.7), width: mm(78), height: mm(102) }],
  pages: [{ pages: '1', die: 'window' }], // page 1, the front board
};

Ingredients

Tipografia
EB Garamond, Cormorant Garamond (SIL OFL 1.1)
Recursos
  • damask.jpg
  • portrait.jpg
  • Cover and back: a pomegranate damask (Generated With Diffusion Models, original)
  • Title page: the oval portrait on a velvet wall (Generated With Diffusion Models, original)

Elaboració

#1 · Una finestra en registre amb el marc

El codi és la resposta curta de dalt. La finestra és una ellipse a la pàgina 1, col·locada des de la cantonada superior esquerra del tall. Un forat a la pàgina 1 dona a la pàgina 3, així que es mesura sobre la pintura de la portada: aquí l’obertura del marc i la vora exterior es van llegir en píxels sobre la imatge i es van passar a mil·límetres, i la finestra es va posar a un terç de la banda daurada, perquè dins del tall s’hi vegi un anell fi d’or.

#2 · Pintures penjades del tall

script.js · línies 52–93al codi complet
// Both paintings are placed in trim millimetres, the same frame the die is measured in. The
// portrait is set a little larger than the page so the frame is centred on it (and on the
// window); the cover type sits on a dark cartouche below the window.
const bleed = (x, y, width, height) => ({ kind: 'image', id: 'painting',
  resourceId: '{attr.picture}', fit: 'cover', placement: at('page', 'top-left', x, y,
    { width: mm(width), height: mm(height) }) });
const sheet = bleed(-BLEED, -BLEED, WIDTH + 2 * BLEED, HEIGHT + 2 * BLEED);
const portrait = bleed(-3.6, -BLEED, 140, 210); // its oval centred at x = WIDTH / 2
const box = (id, y, h) => ({ kind: 'box', id, placement: at('page', 'top-left', 17, y,
  { width: mm(WIDTH - 34), height: mm(h) }), style: { backgroundColor: col('plate'),
  borderColor: col('gold'), borderWidth: pt(0.75) } });
const type = (id, content, y, size, extra = {}) => ({ kind: 'text', id, content,
  fontFamily: DISPLAY, fontSize: pt(size), lineHeight: 1.1, color: col('gold'),
  align: 'center', placement: at('page', 'top-left', 17, y, { width: mm(WIDTH - 34) }),
  ...extra });
const caps = { fontWeight: 600, textTransform: 'uppercase', letterSpacing: pt(2.2) };
const full = (elements) => ({ enabled: true, minHeight: mm(HEIGHT - TOP),
  slot: { elements } });
const bare = { numbered: false, toc: false, header: { elements: [] },
  footer: { elements: [] } };
// A plate's section drops the foot margin, so its design reaches the foot of the page.
const flush = (top = TOP, side = 0) => ({ margins: { top: mm(top), bottom: mm(0),
  left: mm(INNER + side), right: mm(OUTER + side) } });
const dark = { palette: { paper: palette.velvet }, marginTop: pt(0), marginBottom: pt(0) };
const behind = (el) => ({ ...el, reserve: false }); // painted under the section's text
const headingStyles = [
  { id: 'cover', ...bare, ...dark, ...flush(), advancedDesign: full([sheet,
    box('plate', 130, 44), type('title', '{title}', 138, 27, { italic: true, fontWeight: 500 }),
    type('author', '{author}', 159, 9.5, caps)]) },
  { id: 'titlepage', ...bare, ...dark, ...flush(), breakBefore: { enabled: true, parity: 'odd' },
    advancedDesign: full([portrait, type('title', '{title}', 146, 30,
      { italic: true, fontWeight: 500 }), type('author', '{author}', 166, 10, caps)]) },
  { id: 'colophon', ...bare, hidden: true, ...flush(132), breakBefore: { parity: 'any' },
    bodyStyle: { fontSize: pt(9), lineHeight: pt(12.5), color: col('muted'), textAlign: 'left' } },
  { id: 'tale', numbered: false, toc: true, breakBefore: { enabled: true, parity: 'odd' },
    marginTop: mm(30), marginBottom: pt(28),
    dropCap: { lines: 3, fontFamily: DISPLAY, color: col('ink'), gap: mm(1.2) } },
  // The back: the damask again, and the copy set in gold on a cartouche.
  { id: 'back', ...bare, ...dark, ...flush(74, 10), breakBefore: { enabled: true,
    parity: 'even' }, advancedDesign: { enabled: true, slot: { elements: [behind(sheet),
      behind(box('plate', 62, 78))] } } },
];

El troquel es mesura en mil·límetres des del tall, i les pintures també. El domàs sobrepassa el tall en tot el sagnat; el retrat va uns mil·límetres més ample, perquè el marc del quadre quedi centrat a la pàgina i a la finestra. La coberta i la portada treuen el marge inferior, i cadascuna imprimeix títol i autor des del frontmatter.

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

script.js · línies 105–106al codi complet
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

El PDF imprimeix la coberta sencera i traça el contorn de la finestra en una separació Die en sobreimpressió que mai no s’entinta: el troquelador hi llegeix la forma i la màquina l’omet. convertImages: false deixa les pintures com a JPEG sRGB, que PDF/X-4 admet, i el fitxer queda per sota del megabyte.

#4 · El llibre tancat a la taula

script.js · línies 128–134al codi complet
  folio: {
    tilt: 34, yaw: 0,
    paper: { type: 'bookWove', shade: '#f6efe2' },
    binding: { type: 'hardcover', cover: 'pages', coverMaterial: 'paper' },
    surface: { type: 'walnut' },
    lighting: { environment: 'lamp', intensity: 1.15 },
  },

Amb binding.cover: 'pages' la primera pàgina és la tapa davantera, i Folio ensenya el llibre tancat, amb el rostre a la finestra i les parets del tall agafant la llum del llum. Passa la coberta per veure la portada sencera.

#5 · La coberta plana que deixa veure

script.js · línies 211–219al codi complet
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, beneath dona al renderitzador la pàgina 3 per a la finestra de la coberta, i la coberta plana també ensenya el rostre. L’interior de la coberta no té res a sota, i el seu forat mostra el fons.

La recepta completa

Sandbox
// ═══ Postext Cookbook · Nº 194 · A window cover that frames the title page ═══════════════
// https://postext.dev/en/cookbook/die-cut-window-cover
// Code: MIT · Text: Poe (PD) · Translation: CC BY 4.0 · Paintings: diffusion models
// Fonts: EB Garamond, Cormorant Garamond (SIL OFL 1.1) · Needs postext ≥ 1.84.0
//
// Poe's tale of a portrait in an oval frame, as a small hardback whose damask cover has an
// oval window cut through it. Closed, the book shows the face of the portrait on the title
// page through the window; the window's edge falls on the gilt of the painted frame.
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 = 'die-cut-window-cover';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink on cream inside; gold on a near-black for the cover and its plates
const palette = {
  ink: '#2b2320', // the text
  paper: '#f6efe2', // a cream book wove
  velvet: '#2a0d10', // the wall behind the portrait, and the endpapers
  plate: '#160c0b', // the cartouches on the damask
  gold: '#d9b36c', // the title type, the colour of the painted frame
  muted: '#6f6158', // the note on the text
};
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: 'gold (defaults)', value: { hex: palette.gold, model: 'hex' } },
];
// #endregion
const [WIDTH, HEIGHT, BLEED] = [130, 195, 3]; // mm: a small hardback, and its bleed
const [TOP, FOOT, INNER, OUTER] = [18, 24, 16, 19];
const [TEXT, DISPLAY] = ['EB Garamond', 'Cormorant Garamond'];
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });

// #region answer: one oval die through the cover, in register with the frame beneath
// The window is cut through the first leaf, so the closed book shows page 3 through it.
// Its size is measured on the title-page painting: a little wider than the frame's opening,
// so the cut edge falls on the gilt and the face sits in the middle of the hole.
const dieCuts = {
  shapes: [{ id: 'window', name: t({ en: 'Oval window', es: 'Ventana oval' }),
    shape: 'ellipse', x: mm(26), y: mm(15.7), width: mm(78), height: mm(102) }],
  pages: [{ pages: '1', die: 'window' }], // page 1, the front board
};

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

#Anomena la planxa com l’espera la màquina de tall

Les taules de tall digital busquen una tinta plana anomenada CutContour, gairebé sempre magenta, i un traç molt fi.

-    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },
+    dieLine: { output: 'page', ink: 'CutContour', cmyk: { c: 0, m: 100, y: 0, k: 0 },
+      width: pt(0.25) } },

#Una finestra rodona

Un cercle ensenya només el rostre; el marc queda amagat sota la coberta fins que es passa.

-    shape: 'ellipse', x: mm(26), y: mm(15.7), width: mm(78), height: mm(102) }],
+    shape: 'circle', x: mm(32), y: mm(24), width: mm(66), height: mm(66) }],

Crèdits

Text
  • The Oval Portrait, in the text of the Broadway Journal (1845), from Project Gutenberg eBook 2147, with Poe’s “rarely” for the eBook’s “merely” · Edgar Allan Poe · domini públic
  • The Spanish translation, the note on the text and the back-cover copy · Postext Cookbook · CC BY 4.0
Imatges
  • Cover and back: a pomegranate damask · Generated With Diffusion Models · original
  • Title page: the oval portrait on a velvet wall · Generated With Diffusion Models · original
Fonts
EB Garamond (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1)
SandboxPDF