简单来说
一本收录贝克尔两篇传说的小开本平装书,以及送去印厂的整张封面:封底、书脊、封面和两个折进去的勒口连成一片。书脊的宽度就是内页的厚度,所以要从书本身算出来。
成品一览
贝克尔的两篇传说《The Spirits’ Mountain》和《The Emerald Eyes》(西班牙文原题《El monte de las ánimas》《Los ojos verdes》),排成120 × 190毫米、带60毫米勒口的口袋本平装书,另外还有印封面用的整张印张。Postext先排好37页内页:半书名页、书名页、版权页、目录、每篇传说一张标题页,然后是Crimson Pro 11/15.2的正文。接着buildCover拿这些页面拼出印张:后勒口、带简介和条码的封底、书脊、画着蒙卡约山下一座废弃小教堂的封面,以及前勒口。书名、副书名和作者取自书的元数据,勒口上的文字来自单独的一份Markdown。
这道食谱解答
- 怎样做一本带勒口平装书的封面印张,并按页数算出书脊?
简短回答
// The book's own binding profile: PUR perfect binding in 16-page signatures, flaps of
// 60 mm whatever the trim. The spine is written nowhere: buildCover works it out from the
// laid-out pages, rounded up to whole signatures, on the paper of `folio.paper`.
const production = {
bindings: [{ id: 'pur-flaps', name: 'PUR perfect binding, 60 mm flaps', style: 'perfect',
signature: 16, measures: { flapWidth: 60, bleed: 3, spineAllowance: 0.5 } }],
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
};
// 100 g/m² bulky cream wove at a bulk of 2.4: each leaf is 100 × 2.4 = 240 µm thick.
const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
// The design: a night ground over the whole sheet and the painting on the front, into the
// bleed at head and foot and up to the flap's fold. The texts come from the cover Markdown,
// the title, subtitle and author from the book's metadata.
const cover = {
background: col('night'),
elements: [{ id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 118, height: 196,
resourceId: 'moncayo', fit: 'cover' }],
verticalAlign: { back: 'middle' },
};
用料
- 类型
- Crimson Pro, Cormorant Garamond, Josefin Sans(SIL OFL 1.1)
- 素材
moncayo-1100.jpg- The front cover: a ruined chapel under the Moncayo on All Souls’ Night, in oils (Generated With Diffusion Models, 原创)
做法
#1 · 装订决定勒口,纸张决定书脊
代码就是上面的简短回答。装订配置写的是装订厂的做法:PUR胶装,16页一个书帖,勒口60毫米,出血3毫米,书脊再加0.5毫米留给胶。版本里写着ISBN和五位附加码;这个ISBN是示例号码,不属于任何一本书。书脊宽度在哪里都没有写。37页向上取整为三个书帖,也就是48页、24张,每张100 g/m²、松厚度2.4的纸厚240微米:24 × 0.24 + 0.5,书脊为6.3毫米。默认情况下书脊不足6毫米就不印字(spineText.minSpine),所以这本书用的是松厚的纸。
#2 · 先排内页
const [W, H, TOP, FOOT, INNER, OUTER, LEAD] = [120, 190, 20, 22, 18, 15.5, 15.2]; // mm, pt
const at = (to, edge, x, y, size) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
...(size && { size }) });
const text = (id, content, look, place) => ({ kind: 'text', id, content, align: 'center',
overflow: 'wrap', placement: place, ...look });
const face = (fontFamily, size, color, extra) => ({ fontFamily, fontSize: pt(size), color,
...extra });
const label = (size, color = col('muted')) => face('Josefin Sans', size, color, caps(size / 5));
const none = { header: { elements: [] }, footer: { elements: [] }, numbered: false, toc: false };
const design = (minHeight, elements) => ({ enabled: true, minHeight: mm(minHeight),
slot: { elements } });
const page = (parity) => ({ breakBefore: { enabled: true, parity } });
const rule = (id, y, to = 'page') => ({ kind: 'rule', id, direction: 'horizontal',
thickness: pt(0.6), color: col('accent'), placement: at(to, 'top', 0, y, { width: mm(10) }) });
const folioAt = (y, pages) => ({ elements: [text('f', '{pageNumber}',
{ ...face('Crimson Pro', 9, col('ink')), pages }, at('page', 'bottom', 0, y))] });
const serif = (size, extra) => face('Cormorant Garamond', size, col('ink'), extra);
const headingStyles = [
{ ...none, id: 'half-title', advancedDesign: design(60, [
text('t', '{title}', serif(17, { fontWeight: 500 }), at('page', 'top', 0, 62))]) },
{ ...none, ...page('odd'), id: 'title-page', advancedDesign: design(H - TOP - FOOT, [
text('t', '{title}', serif(27, { fontWeight: 600 }), at('page', 'top', 0, 46)),
text('s', '{subtitle}', serif(13, { italic: true }), at('page', 'top', 0, 58)),
rule('r', 67),
text('a', '{author}', label(8, col('accent')), at('page', 'top', 0, 72)),
text('tr', '{attr.translators}', face('Crimson Pro', 9.5, col('muted'), { italic: true }),
at('page', 'top', 0, 118, { width: mm(70) })),
text('i', '{attr.imprint}', label(7), at('page', 'bottom', 0, -26)),
]) },
// The rights at the foot of the verso, under a short rule.
{ ...none, ...page('even'), id: 'rights',
advancedDesign: design(92, [rule('r', 86, 'container')]) },
{ ...none, ...page('odd'), id: 'contents', advancedDesign: design(34, [
text('t', '{titleText}', label(8, col('accent')), at('container', 'top', 0, 14)),
rule('r', 21, 'container')]) },
// Each legend has a title leaf of its own (the contents point to it), then opens on the
// next recto, sunk 40 mm.
{ ...none, ...page('odd'), id: 'tale-title', toc: true, advancedDesign: design(90, [
text('k', '{attr.kicker}', serif(15, { fontWeight: 600, color: col('accent') }),
at('page', 'top', 0, 58)),
text('t', '{titleText}', serif(23, { fontWeight: 500 }), at('page', 'top', 0, 67)),
text('p', '{attr.place}', face('Crimson Pro', 10.5, col('muted'), { italic: true }),
at('page', 'top', 0, 79)),
rule('r', 88)]) },
{ ...page('odd'), id: 'tale', toc: false, advancedDesign: design(40, [
text('t', '{titleText}', serif(15, { fontWeight: 500, italic: true }),
at('container', 'top', 0, 16)),
rule('r', 25, 'container')]) },
{ ...none, ...page('any'), id: 'colophon', advancedDesign: design(70, [
rule('r', 60, 'container')]) },
];
const head = (id, content, parity) => text(id, content, { ...label(6.8), parity, pages: 'body' },
at('page', 'top', 0, 11));
书芯就是一份普通的Postext文档,它的每一页都算进书脊。前置页用标题样式,样式里的设计把书名、线条和出版社名放在页面上固定的高度。每篇传说都有自己的标题页(目录指向的就是它),正文在下一个右页重新开始,往下沉40毫米。改了字号或页边距,页数就会变,书脊在下一次排版时跟着变。
#3 · 封面的样式和书的样式放在一起
const style = (id, fontFamily, size, lead, color, extra) => ({ id, fontFamily, fontSize: pt(size),
lineHeight: pt(lead), color, italicColor: color, firstLineIndent: mm(0), textAlign: 'left',
hyphenation: false, ...extra });
const caps = (tracking) => ({ fontWeight: 600, textTransform: 'uppercase',
letterSpacing: pt(tracking) });
const coverStyles = [
style('cover-title', 'Cormorant Garamond', 40, 40, col('bone'), { fontWeight: 600,
textAlign: 'center', marginTop: mm(12) }),
style('cover-subtitle', 'Cormorant Garamond', 15, 19, col('bone'), { italic: true,
textAlign: 'center' }),
style('cover-author', 'Josefin Sans', 8.5, 11, col('gold'), { ...caps(1.8),
textAlign: 'center', marginTop: pt(16) }),
style('cover-spine', 'Josefin Sans', 7.5, 9, col('bone'), { ...caps(1.2), textAlign: 'center' }),
style('cover-blurb', 'Crimson Pro', 10.5, 14.5, col('bone'), { marginBottom: pt(7) }),
style('cover-note', 'Crimson Pro', 10.5, 14.5, col('gold'), { italic: true }),
style('flap-head', 'Josefin Sans', 7.5, 10, col('gold'), caps(1.4)),
style('flap-text', 'Crimson Pro', 9.6, 13.2, col('bone'), { marginTop: pt(5) }),
];
印张用书的配置来排,所以它的段落样式和版权页、版本记录的样式在同一个列表里。cover-title、cover-subtitle、cover-author和cover-spine是buildCover给它放置的元数据起的名字;cover-blurb、cover-note、flap-head和flap-text则由封面的Markdown指定。在夜色底上,文字左对齐、不断字,用调色板里的骨白和金色。
#4 · 印张由排好的内页生成
const built = buildCover({ config, version: 'paperback', pages: book.pages, markdown: coverText,
metadata: book.metadata, resources });
if (!('config' in built)) throw new Error(built.issues.map((i) => i.kind).join(', '));
// The barcode is the cover's own picture. Its digits name OCR-B, which no font server
// has: they are set in the label face, which the PDF embeds like the rest.
for (const [id, bytes] of Object.entries(built.files)) {
await loadSvg(id, new TextDecoder().decode(bytes)
.replace(/font-family="[^"]*"/g, 'font-family="Josefin Sans"'));
}
const sheet = await buildDocumentWithFonts(built.content, built.config, kitFonts(FONTS));
buildCover接收页面、元数据和封面的Markdown,封底一个:::frame,每个勒口各一个。它返回一份文档,由buildDocumentWithFonts像别的文档一样排版,另外还有一个SVG格式的条码文件。条码的数字要求OCR-B字体,任何字体服务器都没有,所以示例把它们换成Josefin Sans,PDF本来就会嵌入这个字体。PDF里先是37页内页,后面是按自身尺寸输出的印张,印厂要的正是这样的文件。
完整食谱
// ═══ Postext Cookbook · Nº 196 · A paperback cover with flaps, spine from the pages ═══
// https://postext.dev/en/cookbook/paperback-cover-with-flaps
// Code: MIT · Text: Bécquer, tr. C. F. & K. L. Bates (public domain) · Art: diffusion models
// Fonts: Crimson Pro, Cormorant Garamond, Josefin Sans (SIL OFL 1.1) · Needs postext ≥ 1.92.0
//
// Two of Bécquer's legends as a 120 × 190 mm paperback with 60 mm flaps. Postext lays the
// pages out first; buildCover then makes the cover sheet from them, its spine as thick as
// the pages on their paper.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';
import { buildCover } 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 = 'paperback-cover-with-flaps';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#25221e', accent: '#86472a', muted: '#6b645a', paper: '#fbf7ee',
night: '#16242a', gold: '#c99b4e', bone: '#eee5d1' }; // the last three: the cover's
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' } },
];
// #region answer: the paperback: a printer's binding with 60 mm flaps, its ISBN, its paper
// The book's own binding profile: PUR perfect binding in 16-page signatures, flaps of
// 60 mm whatever the trim. The spine is written nowhere: buildCover works it out from the
// laid-out pages, rounded up to whole signatures, on the paper of `folio.paper`.
const production = {
bindings: [{ id: 'pur-flaps', name: 'PUR perfect binding, 60 mm flaps', style: 'perfect',
signature: 16, measures: { flapWidth: 60, bleed: 3, spineAllowance: 0.5 } }],
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
};
// 100 g/m² bulky cream wove at a bulk of 2.4: each leaf is 100 × 2.4 = 240 µm thick.
const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
// The design: a night ground over the whole sheet and the painting on the front, into the
// bleed at head and foot and up to the flap's fold. The texts come from the cover Markdown,
// the title, subtitle and author from the book's metadata.
const cover = {
background: col('night'),
elements: [{ id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 118, height: 196,
resourceId: 'moncayo', fit: 'cover' }],
verticalAlign: { back: 'middle' },
};
// #endregion
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#书脊文字从上往下排
英美的书,书脊文字从上往下读;默认的从下往上是西班牙和欧洲大陆的习惯。
versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur-flaps',
- flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000' }],
+ flaps: true, isbn: '978-84-0000-196-4', isbnAddOn: '90000',
+ spineText: { direction: 'topToBottom' } }],#换用薄一些的纸
80 g/m²、松厚度2.2的纸每张厚176微米,书脊降到4.7毫米,书脊上的字也就没了,因为它需要6毫米。
-const folio = { paper: { type: 'bookWove', grammage: 100, bulk: 2.4, shade: '#f7f1e3' } };
+const folio = { paper: { type: 'bookWove', grammage: 80, bulk: 2.2, shade: '#f7f1e3' } };常见问题
- 在截取的页面列表里,印张排在书的页面后面,所以它的页号是书的页数加一。书多了一页,这个页号就会变。
- 条码的数字如果要求一种PDF找不到的字体,导出就会失败。加载它的SVG时,把
font-family换成示例已经加载的字体。
致谢
- 文本
- The Spirits’ Mountain and The Emerald Eyes, translated by Cornelia Frances Bates and Katharine Lee Bates, from Romantic Legends of Spain (1909), Project Gutenberg eBook #50044 · Gustavo Adolfo Bécquer · 公有领域
- El monte de las ánimas and Los ojos verdes, from the Obras (Madrid, Fernando Fe, 1885) as transcribed on Wikisource, accents modernised · Gustavo Adolfo Bécquer · 公有领域
- 图片
- The front cover: a ruined chapel under the Moncayo on All Souls’ Night, in oils · Generated With Diffusion Models · 原创
- 字体
- Crimson Pro (SIL OFL 1.1) · Cormorant Garamond (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)


