跳到主要内容
食谱编号194

排版食谱 · 第10章 · 输出与集成

开窗封面,框住下面的书名页

用dieCuts在封面上模切一个椭圆窗,按书名页上的画来量,让切口正落在金色画框上,模切线放在单独的色版上。

本页内容
输出
Canvas · PDF · 实时控件
难度
中级
Postext
已用Postext 1.84.0测试
需要≥ 1.84.0 · postext-pdf ≥ 1.84.0
许可证
更新于2026年11月13日
代码MIT · 文本CC BY 4.0
  • 英文样例:尚无中文版本
  • 成品尺寸130 × 195 mm
  • 1栏
  • EB Garamond 10.5/14
  • Cormorant Garamond
  • 10页
  • 难度
  • Postext 1.84.0
  • 排版用时14 ms
  • 179行代码

简单来说

一本收录爱伦·坡短篇的小精装书,花纹封面上开了一个椭圆孔,透过孔能看到下面书名页上肖像的脸。

成品一览

The Oval Portrait(西班牙语版《El retrato oval》),爱伦·坡1842年的短篇,采用他1845年刊出的较短文本,做成130 × 195毫米、十页的小精装书。封面是一块旧锦缎,上面模切出一个椭圆窗。封面下是书名页,也就是那幅装在摩尔式镀金画框里的肖像;窗的位置让切口正好落在金边上:合上书时,画中的脸被框了两次,一次是金框,一次是切口。故事印在米色纸上,以首字下沉开头;封底重复锦缎图案,简介印在深色框里。交给印厂的PDF把窗的轮廓放在单独的色版上。

这道食谱解答

  • 怎样在封面上开一个窗,框住下面的书名页?
  • 怎样在PDF里把模切线放在单独的色版上交给模切版制作者?

简短回答

script.js · 第41–48行在完整代码中
// 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
};

用料

类型
EB Garamond, Cormorant Garamond(SIL OFL 1.1)
素材
  • damask.jpg
  • portrait.jpg
  • Cover and back: a pomegranate damask (Generated With Diffusion Models, 原创)
  • Title page: the oval portrait on a velvet wall (Generated With Diffusion Models, 原创)

做法

#1 · 与画框对准的窗

代码见上方的简短回答。窗是第1页上的一个ellipse,从成品左上角起定位。第1页上的孔看到的是第3页,所以要在书名页的画上量:这里先在图上以像素读出画框的内缘和外缘,再换算成毫米,把窗放在金边宽度的三分之一处,切口里就留下一圈细细的金边。

#2 · 挂在裁切线上的画

script.js · 第52–93行在完整代码中
// 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))] } } },
];

模切以从裁切线量起的毫米表示,画也一样。锦缎在四边各伸出出血;肖像放得比页面宽几毫米,让画框在页面和窗中居中。封面和书名页去掉下边距,各自从frontmatter印出书名和作者。

#3 · 模切线在自己的色版上

script.js · 第105–106行在完整代码中
  print: { standard: 'pdfx4', outputProfile: 'fogra51', convertImages: false,
    dieLine: { output: 'page', ink: 'Die', width: pt(0.5) } },

PDF把封面完整印出,并把窗的轮廓描在一个叠印、从不上墨的Die分色上:做刀模的人从这里读形状,印刷时略过它。convertImages: false让画保持sRGB JPEG,PDF/X-4允许这样做,文件也不到1兆字节。

#4 · 桌上合着的书

script.js · 第128–134行在完整代码中
  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 },
  },

binding.cover: 'pages'把第一页当作前封面,所以Folio显示合着的书,窗里是那张脸,切口的侧壁映着灯光。翻开封面就能看到完整的书名页。

#5 · 平铺的封面也能透视

script.js · 第211–219行在完整代码中
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);
};

在画布上,beneath把第3页交给渲染器去填封面的窗,平铺的封面也会露出那张脸。封面背面下面什么都没有,所以那里的孔显示背景。

完整食谱

沙盒
// ═══ 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 = 'en'; // @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
};

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#按切割机的习惯给色版命名

数码切割台通常寻找名为CutContour的专色,一般是品红,并用极细的线。

-    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) } },

#圆形的窗

圆窗只露出脸;画框藏在封面下,翻开才看得到。

-    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) }],

致谢

文本
  • 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 · 公有领域
  • The Spanish translation, the note on the text and the back-cover copy · Postext Cookbook · CC BY 4.0
图片
  • Cover and back: a pomegranate damask · Generated With Diffusion Models · 原创
  • Title page: the oval portrait on a velvet wall · Generated With Diffusion Models · 原创
字体
EB Garamond (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1)
沙盒PDF