跳到主要内容
食谱编号198

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

丛书中的一卷,环衬上印着整套书目

十二卷精装丛书的第十一卷:条形码旁印两个 ISBN,各卷共用一套书壳设计,前后环衬展示整套丛书。

本页内容
输出
Canvas · PDF
难度
高级
Postext
已用Postext 1.92.0测试
需要≥ 1.92.0 · postext-pdf ≥ 1.92.0
许可证
更新于2026年11月23日
代码MIT · 文本CC BY 4.0

页码1 · 第27页,共29页

  • 英文样例:尚无中文版本
  • 成品尺寸120 × 185 mm
  • 1栏
  • Crimson Pro 11/15.2
  • Cormorant Garamond
  • Josefin Sans
  • 29页
  • 难度
  • Postext 1.92.0
  • 排版用时110 ms
  • 238行代码

简单来说

一套十二本精装书中的一本,连同交给印厂的各张印页:印着丛书配色和卷号的书壳,以及书壳内侧的两张环衬,上面是十二本书的封面和书名。

成品一览

塞万提斯十二篇《警世典范小说集》中的第十一篇《骗婚记》,作为一套每篇一册的精装丛书的第十一卷。正文 26 页,以 Crimson Pro 11/15.2 排在 120 × 185 毫米的页面上。buildCover 随后据此为装订厂生成三张印页:印刷书壳,用丛书的深酒红,画外围一道金框,卷号放在金环里;以及前后两张环衬,两张分担整套丛书:第一至六卷在书前,第七至十二卷在书后,每一半都在贴板页上排画、在活页上排编号书目。条形码承载本卷的 ISBN,书壳在它旁边印出全套书的 ISBN。

这道食谱解答

  • 怎样印丛书中的一卷,带上整套书的ISBN,并在环衬上列出其他书目?

简短回答

script.js · 第30–58行在完整代码中
// The collection is data of the book, beside its versions. The volume's barcode carries its
// own ISBN, and the collection's `isbn` prints as a line above the bars. `catalogue` lists
// the twelve titles with their cover pictures, and `volume` names the one this book is: the
// endpapers set the list and the pictures from it (section 4), this volume marked in both.
const collection = {
  name: t({ en: 'Exemplary Novels', es: 'Novelas ejemplares' }),
  isbn: '978-84-0000-200-8',
  catalogue: [
    work('The Little Gipsy Girl', 'La gitanilla', 'gitanilla'),
    work('The Generous Lover', 'El amante liberal', 'amante'),
    work('Rinconete and Cortadillo', 'Rinconete y Cortadillo', 'rinconete'),
    work('The Spanish-English Lady', 'La española inglesa', 'espanola'),
    work('The Licentiate Vidriera', 'El licenciado Vidriera', 'vidriera'),
    work('The Force of Blood', 'La fuerza de la sangre', 'fuerza'),
    work('The Jealous Estremaduran', 'El celoso extremeño', 'celoso'),
    work('The Illustrious Scullery-Maid', 'La ilustre fregona', 'fregona'),
    work('The Two Damsels', 'Las dos doncellas', 'doncellas'),
    work('The Lady Cornelia', 'La señora Cornelia', 'cornelia'),
    work('The Deceitful Marriage', 'El casamiento engañoso', 'casamiento'),
    work('The Dialogue of the Dogs', 'El coloquio de los perros', 'coloquio'),
  ],
};
collection.volume = collection.catalogue[VOLUME - 1].id;
const production = {
  collection,
  // A printed case with a flat spine: the case sheet and two endpapers, no jacket.
  versions: [{ id: 'hardcover', name: t({ en: 'Hardcover', es: 'Tapa dura' }),
    binding: 'case-flat', isbn: '978-84-0000-198-8', isbnAddOn: '90000' }],
};

用料

类型
Crimson Pro, Cormorant Garamond, Josefin Sans(SIL OFL 1.1)
素材
  • amante-320.jpg
  • casamiento-1000.jpg
  • casamiento-320.jpg
  • celoso-320.jpg
  • coloquio-320.jpg
  • cornelia-320.jpg
  • doncellas-320.jpg
  • espanola-320.jpg
  • fregona-320.jpg
  • fuerza-320.jpg
  • gitanilla-320.jpg
  • rinconete-320.jpg
  • vidriera-320.jpg
  • The front cover: a pale ensign leaning on his sword at the gate of the hospital of Valladolid, in oils (Generated With Diffusion Models, 原创)
  • The cover painting of volume 1, The Little Gipsy Girl, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 2, The Generous Lover, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 3, Rinconete and Cortadillo, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 4, The Spanish-English Lady, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 5, The Licentiate Vidriera, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 6, The Force of Blood, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 7, The Jealous Estremaduran, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 8, The Illustrious Scullery-Maid, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 9, The Two Damsels, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 10, The Lady Cornelia, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 11, The Deceitful Marriage, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)
  • The cover painting of volume 12, The Dialogue of the Dogs, on the endpapers, painted to match the front cover (Generated With Diffusion Models, 原创)

做法

#1 · 丛书是书的数据

代码就是上面的简短回答。production.collection 保存丛书:名称、ISBN、一个为每卷记下标识、书名和图片的 catalogue,以及 volume,即本书在目录中的那一条的标识。Postext 在条形码旁印出的是丛书的 isbn:条形码上方一行 6.5 磅黑字“全套书 ISBN”,用书的语言。版本若声明了自己的 workIsbn,就印那一个。两个 ISBN 都是 978-84-0000 段里的示例号码,不属于任何一本书。配置检查会报出不在目录里的 volume,以及校验位不对的丛书 ISBN。

#2 · 每卷同一套装帧

script.js · 第63–80行在完整代码中
// Every position is in mm from the top-left corner of its zone (the case's front is
// 116 × 191 mm: the 120 × 185 trim, set back 7 mm at the joint, 3 mm square round it).
const box = (id, zone, x, y, width, height, color, extra) => ({ id, kind: 'box', zone, x, y,
  width, height, color: col(color), ...extra });
const picture = (id, zone, x, y, width, height, resourceId, extra) => ({ id, kind: 'image', zone,
  x, y, width, height, resourceId, fit: 'cover', ...extra });
// `basis`: the spine drawn on; a thicker book stretches the bands and keeps the badge centred.
const spine = { basis: { width: 10, height: 191 } };
const livery = [
  box('frame', 'front', 11.2, 59.2, 93.6, 105.6, 'gold'),
  picture('art', 'front', 12, 60, 92, 104, 'cover-art'),
  picture('badge', 'front', 51.5, 169, 13, 13, 'badge', { fit: 'contain' }),
  box('head-band', 'spine', 0, 13, 10, 0.8, 'gold', spine),
  box('foot-band', 'spine', 0, 160, 10, 0.8, 'gold', spine),
  picture('spine-badge', 'spine', 1, 167, 8, 8, 'badge', { fit: 'contain', ...spine }),
  // A paper label for the barcode, whose caption is set in black.
  box('label', 'back', 53, 147, 61, 40, 'bone'),
];

书壳设计在丛书每一卷里都是同一个对象,只有 VOLUME、画和文字会变。每个元素都相对所在区域定位,所以另一卷页数更多、书脊更厚时,封面会随自己的版块移动。书脊上,basis 记下绘制饰带时所用的 10 毫米书脊宽;书脊为 8.3 毫米或 14 毫米时,饰带随宽度伸缩,圆环保持在中线上。条形码上方那行字是黑色,所以条形码放在浅色标签上。

#3 · 每张环衬各有设计

script.js · 第84–99行在完整代码中
// The case takes the livery; each endpaper names a design in `sheets`. At the front the
// pastedown is the left page, at the back the right one: volumes I–VI open the book,
// VII–XII close it, the pictures always on the pastedown, in the case's colour. A catalogue
// element grids the titles' pictures in its box; `stroke` outlines this volume's.
const shelf = (first, last) => ({ id: `shelf-${first}`, kind: 'catalogue', zone: 'pastedown',
  x: 26.5, y: 18, width: 67, height: 149, columns: 2, gap: 7, first, last,
  stroke: { color: col('gold'), width: 0.8 } });
const endpaper = (first, last) => ({ background: col('endpaper'),
  zones: { pastedown: col('case') }, elements: [shelf(first, last)],
  verticalAlign: { flyleaf: 'middle' } });
const cover = {
  background: col('case'),
  elements: livery,
  verticalAlign: { back: 'top' },
  sheets: { endpaperFront: endpaper(1, 6), endpaperBack: endpaper(7, 12) },
};

cover.sheets 为某张印页指定一套设计,代替封面的设计:这里是 endpaperFront 和 endpaperBack,各有自己的底色(贴板页用书壳的颜色)和一个 catalogue 元素。这个元素是某个区域里的一个框,引擎把目录中从 first 到 last 的书的图片排进去,分 columns 列,间距 gap 毫米,每幅图片铺满自己的格子。标识等于 collection.volume 的那一卷,用元素的 stroke 描边;在这两张环衬上就是第十一卷的金框。书壳的装帧不会出现在环衬上,因为每张印页只画自己的设计。从书前打开,贴板页在左;到书后,贴板页在右,所以画总是落在纸板上。

书名来自封面 Markdown,它供所有印页使用。写明印页的文本框只出现在那些印页上:

:::frame{slot="flyleaf" sheet="endpaperBack"}
:::paragraphs{style="ad-head"}
Exemplary Novels
:::
 
::catalogue{numbers="I" first=7 last=12}
:::

::catalogue 会换成目录中的书名,每卷一段:按 numbers 指定的编号样式写出序号,接一个半角空(en space),再接书名。这些行用段落样式 cover-catalogue,本卷那一行用 cover-catalogue-current;代码重新定义了两者,用 Crimson Pro 居中,本卷用深红色。封底的文本框写明 case jacket,所以环衬上不会出现它。

#4 · 一本书,三张印页

script.js · 第421–432行在完整代码中
const sheet = async (kind) => {
  const built = buildCover({ config, version: 'hardcover', pages: book.pages,
    markdown: coverText, metadata: book.metadata, resources, sheet: kind });
  if (!('config' in built)) throw new Error(built.issues.map((i) => i.kind).join(', '));
  // The barcode's digits name OCR-B, which no font server has: the label face sets them.
  for (const [id, bytes] of Object.entries(built.files)) {
    await loadSvg(id, new TextDecoder().decode(bytes)
      .replace(/font-family="[^"]*"/g, 'font-family="Josefin Sans"'));
  }
  return { built, doc: await buildDocumentWithFonts(built.content, built.config, kitFonts(FONTS)) };
};
const sheets = [await sheet('cover'), await sheet('endpaperFront'), await sheet('endpaperBack')];

同一个调用分别传入 sheet: 'cover'、'endpaperFront' 和 'endpaperBack',生成书壳和两张环衬,各是一个按自身尺寸的单页文档。26 页向上取整为两个 16 页的书帖,共 16 张 240 微米的纸;加 0.5 毫米余量,书芯厚 4.3 毫米,再加两块 2 毫米纸板,书壳书脊为 8.3 毫米。书脊文字按书壳的书脊检查,超过 6 毫米的下限。PDF 先是 26 页正文,然后是书壳和两张环衬。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 198 · A volume of a collection, its endpapers the series ═══
// https://postext.dev/en/cookbook/collection-volume-endpapers
// Code: MIT · Text: Cervantes, tr. W. K. Kelly (public domain) · Art: diffusion models
// Fonts: Crimson Pro, Cormorant Garamond, Josefin Sans (SIL OFL 1.1) · Needs postext ≥ 1.92.0
//
// Volume XI of the twelve Exemplary Novels, one novella per hardcover: the series livery on
// the case, two ISBNs by the barcode, the twelve titles of the collection on the endpapers.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';
import { buildCover, workIsbnCaption } from 'https://esm.sh/postext/production';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'collection-volume-endpapers';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#2a211c', accent: '#7a2a22', muted: '#6c6258', paper: '#fbf7ee',
  case: '#5e1c1a', gold: '#d2ae6a', bone: '#f1e8d4', endpaper: '#ece0c6' };
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' } },
];
const VOLUME = 11; // this book's place in the collection
const roman = (n) => 'I II III IV V VI VII VIII IX X XI XII'.split(' ')[n - 1];
const work = (en, es, id) => ({ id, title: t({ en, es }), resource: `cat-${id}` });

// #region answer: the volume and its collection: two ISBNs and the series' catalogue
// The collection is data of the book, beside its versions. The volume's barcode carries its
// own ISBN, and the collection's `isbn` prints as a line above the bars. `catalogue` lists
// the twelve titles with their cover pictures, and `volume` names the one this book is: the
// endpapers set the list and the pictures from it (section 4), this volume marked in both.
const collection = {
  name: t({ en: 'Exemplary Novels', es: 'Novelas ejemplares' }),
  isbn: '978-84-0000-200-8',
  catalogue: [
    work('The Little Gipsy Girl', 'La gitanilla', 'gitanilla'),
    work('The Generous Lover', 'El amante liberal', 'amante'),
    work('Rinconete and Cortadillo', 'Rinconete y Cortadillo', 'rinconete'),
    work('The Spanish-English Lady', 'La española inglesa', 'espanola'),
    work('The Licentiate Vidriera', 'El licenciado Vidriera', 'vidriera'),
    work('The Force of Blood', 'La fuerza de la sangre', 'fuerza'),
    work('The Jealous Estremaduran', 'El celoso extremeño', 'celoso'),
    work('The Illustrious Scullery-Maid', 'La ilustre fregona', 'fregona'),
    work('The Two Damsels', 'Las dos doncellas', 'doncellas'),
    work('The Lady Cornelia', 'La señora Cornelia', 'cornelia'),
    work('The Deceitful Marriage', 'El casamiento engañoso', 'casamiento'),

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

变化

#给书壳加一张护封

在精装书上,flaps 会加一张护封,即带有自己勒口的第四张印页。条形码和全套书 ISBN 移到它的封底,文本框写明了 jacket 的封底文案也随之过去。

   versions: [{ id: 'hardcover', name: t({ en: 'Hardcover', es: 'Tapa dura' }),
-    binding: 'case-flat', isbn: '978-84-0000-198-8', isbnAddOn: '90000' }],
+    binding: 'case-flat', isbn: '978-84-0000-198-8', isbnAddOn: '90000', flaps: true }],

#排下一卷

第十二卷的设计保持不变:VOLUME 决定 collection.volume 指向目录中的哪一条,卷号环、环衬上的金框和突出显示的书名都随之改变。封面 Markdown、画和 ISBN 换成那一卷的。

-const VOLUME = 11; // this book's place in the collection
+const VOLUME = 12; // this book's place in the collection

常见问题

  • 在截取的页面列表里,各张印页排在书页之后:书壳是第 27 页,即书的页数加一。给书增加一页的改动会使它们后移。
  • 菜谱集的 contentInConfig 检查把 buildCover 印在条形码上方的那行字当成存放在设计里的文字。代码把它写进 checks.contentInConfig.allow,措辞取自引擎所用的函数 workIsbnCaption。
  • catalogue 元素只画图片。书目是 Markdown 里的 ::catalogue,所以缺了这一行的印页只有画,下面没有书名。
  • 条形码数字指定 OCR-B 字体,而没有字体服务器提供它。加载条形码时请换成代码已加载的 font-family,否则 PDF 会失败。

致谢

文本
  • The Deceitful Marriage, translated by Walter K. Kelly, from The Exemplary Novels of Cervantes (London, Bohn’s Standard Library, 1846; 1881 reprint), Project Gutenberg eBook #14420 · Miguel de Cervantes · 公有领域
  • El casamiento engañoso, from the Novelas ejemplares in the 1825 edition as transcribed on Wikisource · Miguel de Cervantes · 公有领域
图片
  • The front cover: a pale ensign leaning on his sword at the gate of the hospital of Valladolid, in oils · Generated With Diffusion Models · 原创
  • The cover painting of volume 1, The Little Gipsy Girl, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 2, The Generous Lover, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 3, Rinconete and Cortadillo, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 4, The Spanish-English Lady, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 5, The Licentiate Vidriera, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 6, The Force of Blood, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 7, The Jealous Estremaduran, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 8, The Illustrious Scullery-Maid, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 9, The Two Damsels, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 10, The Lady Cornelia, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 11, The Deceitful Marriage, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
  • The cover painting of volume 12, The Dialogue of the Dogs, on the endpapers, painted to match the front cover · Generated With Diffusion Models · 原创
字体
Crimson Pro (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)
沙盒PDF