Skip to main content
Recipe number 85

Cookbook · Chapter 1 · Page & grid

A woodblock leaf: double frame, rules and centre strip

Zhu Xi's commentary on the Analects set as a woodblock printed it: a leaf to a spread, a double frame, a rule between columns and the centre strip on the fold.

On this page
Output
Canvas · PDF
Postext
Tested with Postext 1.65.0
Needs ≥ 1.25.0 · postext-pdf ≥ 1.25.0
Licence
Updated 10 Oct 2026
Code MIT · Text CC BY 4.0

pp. 2–3 of 7

  • Trim 120.8 × 213.1 mm
  • 1 column
  • Noto Serif TC 20/29
  • LXGW WenKai TC
  • 7 pages
  • Level
  • Postext 1.65.0
  • Laid out in 65 ms
  • 178 lines of code

In short

A classic Chinese book set the way old woodblock prints looked. Each page has a double border and thin lines between the columns, and notes run in small type inside the lines.

What you'll build

Three leaves of Zhu Xi's commentary on the Analects (論語集註), the opening of the book 學而, set as a woodblock printed them, after a title page. Each page is a half-leaf, 121 × 213 mm, and each spread is one whole leaf, read from the right: on each half nine columns of 17 characters in 20 pt Noto Serif TC, a double frame, a hairline between every two columns, and on the fold the centre strip (版心) with the title, a black fish tail, the juan and the leaf's number. Zhu Xi's notes fold into two rows of 10 pt characters inside the column, after the words they explain. The head margin is twice the foot.

This recipe answers

  • How do I lay out a woodblock leaf, with a double frame, a rule between the columns and the centre strip?
  • How do I set the type area in characters, so many to the line and so many lines to the page?
  • How do I set a Chinese book vertically, bound on the right?

The short answer

script.js · lines 46–64in full code
// A block printed both halves of a leaf (葉) at once, the centre strip between them. Each
// page here is a half-leaf. Page 1, the title, is a recto: in a book bound on the right it
// stands alone left of the spine, and every spread after it is one leaf, read from the
// right. The grid sets the block's 9 columns of 17 characters; the text has no
// punctuation, so every column ends on its 17th character.
const page = {
  sizePreset: 'custom', width: pt(W), height: pt(H), dpi: 150,
  backgroundColor: col('paper'),
  // left is the inner margin, the half of the centre strip on this side of the fold
  margins: { top: pt(TOP), bottom: pt(BOTTOM), left: pt(HALF), right: pt(OUTER), mirror: true },
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // bound on the right
const cjk = { grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES } };
// Postext numbers pages, not leaves. Each leaf opens with a hidden level-1 heading, which
// prints nothing and starts a right-hand page; the centre strip prints their count.
const leaf = {
  level: 1, hidden: true, numberingTemplate: '{1:一}', // 一, 二, 三
  breakBefore: { enabled: true, parity: 'even' }, // even pages lie on the right in this binding
};

A half-leaf to a page, so that every spread is one whole leaf

Ingredients

Type
Noto Serif TC, LXGW WenKai TC (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · A half-leaf to a page, a leaf to a spread

The code is the short answer above. A block printed a whole leaf (葉) at once, its two halves either side of the centre strip; the printer folded the sheet along the strip, printed side out, and sewed the open edges, so the strip became the book's fore-edge. These pages lie as the leaf came off the block. Each page is a half-leaf. In a book bound on the right page 1 stands alone left of the spine and each later spread pairs an even page on the right with the odd page after it, so with the title on page 1 every spread holds one leaf. The character grid sets the block's 行款, nine columns of 17 characters, and the margins it leaves are exact: the inner one is half the strip.

Postext numbers pages, not leaves. Each leaf opens with a level-1 heading that is hidden: it prints nothing and takes no room, but its breakBefore with parity: 'even' starts a right-hand page, and its number, 一, 二, 三 by numberingTemplate: '{1:一}', is {chapterNumber} for the strip.

#2 · Break the text where each leaf ends

The copyist who wrote out a text for the block cutter fitted it to the block, leaf by leaf. The Markdown does the same: a leaf's heading goes where the previous leaf's ninth column on its left half ends, even inside a sentence or a note. A note cut there is closed and opened again, and since each column folds its own share of a note into two rows, the rows come out as they were:

子曰巧言令色鮮矣仁:warichu[巧好令善也好其言善其色致飾於]
 
# 學而
 
:warichu[外務以悦人則人欲肆而本心之德亡矣…]

The block has no punctuation, so no line-breaking rule moves a character, and every column ends on its 17th: the leaf breaks are counted once and stay put. Zhu Xi's notes are :warichu[…] spans at the default half size, 34 small characters to a row, with a ○ between the reading and the gloss as in the block.

#3 · Draw the block from the grid's numbers

script.js · lines 68–113in full code
// Header elements are placed on the sheet, pt from the page's top left corner. Both halves
// read right to left: a right-hand page (even) from the outer frame to the fold, a
// left-hand page (odd) from the fold to the outer frame.
const at = (x, y) => ({ anchor: { to: 'page', edge: 'top-left' }, offset: { x: pt(x), y: pt(y) } });
// A column of characters stands in the middle of its pitch, so the rules between columns
// fall on whole pitches. The k-th, counted from the right edge of the type area:
const line = (parity, k) =>
  (parity === 'even' ? HALF + LINES * PITCH : W - HALF) - k * PITCH;
const [Y0, Y1] = [TOP - GAP, TOP + CHARS * BODY + GAP]; // the inner frame's top and foot
// A rule is drawn from its x, a box's border inside the box: each is set so that the line
// is centred where it belongs.
const rule = (id, x, parity) => ({ kind: 'rule', id, parity, direction: 'vertical',
  thickness: pt(0.6), color: col('rule'),
  placement: { ...at(x - 0.3, Y0), size: { height: pt(Y1 - Y0) } } });
const frame = (id, [x0, x1], parity) => [[RULES, 1.8], [0, 0.6]].map(([out, t], i) => ({
  kind: 'box', id: `${id}-${i}`, parity, style: { borderColor: col('rule'), borderWidth: pt(t) },
  placement: { ...at(x0 - out - t / 2, Y0 - out - t / 2),
    size: { width: pt(x1 - x0 + 2 * out + t), height: pt(Y1 - Y0 + 2 * out + t) } } }));
// The middle of the strip, where its text stands: the fold, halfway between its two rules.
// Both pages draw the text whole, and each shows its half.
const mid = (parity) => (parity === 'even' ? 0 : W);
const strip = (id, content, parity, y) => ({ kind: 'text', id: `${id}-${parity}`, parity,
  content, writingMode: 'vertical-rl', fontFamily: SONG, fontSize: pt(11), color: col('ink'),
  align: 'left', overflow: 'clip',
  placement: { ...at(mid(parity) - HALF, TOP + y),
    size: { width: pt(2 * HALF), height: pt(CHARS * BODY - y) } } });
// The fish tail (魚尾): a black band with a notch, from one side of the strip to the other.
const FISH = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 18">
  <path d="M0 0H32V13L16 6L0 13Z" fill="${palette.rule}"/></svg>`;
const resources = [{ id: 'fish', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
  svg: { fileId: 'fish.svg', width: 32, height: 18 } }];
const fish = (parity) => ({ kind: 'image', id: `fish-${parity}`, parity, resourceId: 'fish',
  decorative: true, placement: { ...at(mid(parity) - HALF + 0.3, TOP + 3.4 * BODY),
    size: { width: pt(2 * HALF - 0.6), height: 'auto' } } });
const furniture = (parity) => [
  // The frame runs 40 pt past the fold, where the other half of the leaf takes it on.
  ...frame(`frame-${parity}`, parity === 'even' ? [-40, line(parity, 0)]
    : [line(parity, LINES), W + 40], parity),
  // Nine rules: eight between the columns (界行) and the side of the strip.
  ...Array.from({ length: LINES }, (_, i) =>
    rule(`rule-${i}-${parity}`, line(parity, parity === 'even' ? i + 1 : i), parity)),
  strip('book', '{title}', parity, 0.7 * BODY), // 書名, above the fish tail
  fish(parity),
  strip('juan', '卷一', parity, 5.2 * BODY), // 卷次, under it
  strip('leaf', '{chapterNumber}', parity, 11.5 * BODY), // 葉碼, the leaf's number
];

The header is laid out on the sheet, so the frame, the rules and the strip are placed in points from the page's corner with the numbers that set the grid: a rule element every 29 pt across the type area, a box 4.5 pt round the text for the thin line and another 4.5 pt further out for the heavy one. Each column of characters stands in the middle of its pitch, so the rules fall halfway between the columns. The strip's text is set down the page by vertical text elements and the fish tail is an SVG image element, both centred between the strip's two rules, on the fold: each page shows 17 pt of the strip. Each page draws the strip's text and the fish tail whole and shows the part on its side, and side by side the parts meet. The frames run past the fold for the same reason.

#4 · Give the title page a style of its own

script.js · lines 117–143in full code
// A heading style of its own: hidden and unnumbered, so the leaves still count from 一, and
// its header replaces the leaves' furniture on its page. Its attributes hold the byline,
// this edition's note in red and the colophon, the one line that changes with the language.
const CELLS = [0, 2, LINES - 2, LINES]; // the byline, title and note, in pitches from the right
const cell = (i) => [CELLS[i], CELLS[i + 1]];
const column = (id, content, [k0, k1], style) => ({ kind: 'text', id, content,
  writingMode: 'vertical-rl', color: col('ink'), overflow: 'clip', verticalAlign: 'middle',
  placement: { ...at(line('odd', k1), TOP),
    size: { width: pt((k1 - k0) * PITCH), height: pt(CHARS * BODY) } }, ...style });
const titlePage = {
  id: 'title', numbered: false, hidden: true, breakBefore: { enabled: true, parity: 'any' },
  footer: { elements: [] },
  header: { elements: [
    ...frame('title-frame', [line('odd', LINES), line('odd', 0)]),
    rule('title-rule-1', line('odd', CELLS[1])), rule('title-rule-2', line('odd', CELLS[2])),
    column('byline', '{attr.byline}', cell(0), { fontFamily: SONG, fontSize: pt(14),
      align: 'left' }),
    column('book', '{title}', cell(1), { fontFamily: KAI, fontSize: pt(60),
      letterSpacing: pt(20), align: 'center' }),
    column('note', '{attr.note}', cell(2), { fontFamily: KAI, fontSize: pt(11),
      lineHeight: pt(0.6 * PITCH), color: col('vermilion'), align: 'right' }), // 3 in 2 pitches
    { kind: 'text', id: 'colophon', content: '{attr.colophon}', fontFamily: SONG,
      fontSize: pt(6.5), lineHeight: 1.4, color: col('muted'), align: 'left', overflow: 'wrap',
      placement: { ...at(line('odd', LINES) - RULES - 0.9, Y1 + RULES + 16),
        size: { width: pt(LINES * PITCH) } } },
  ] },
};

The title page (內封) is a level-1 heading with a heading style that is hidden and unnumbered, so the leaves still count from 一. A style governs the pages of its section, and its header replaces the document's there: the title page gets a closed frame cut into three columns instead of a half-leaf's furniture. The byline, this edition's note in red Kai and the colophon come from the heading's attributes; the colophon is the one line that changes with the edition's language. \n in an attribute starts a new column.

#5 · Load each face with the characters it sets

script.js · lines 200–205in full code
// Song sets the leaves, the strip and its leaf numbers; Kai only the title page's title
// and note (gotcha: cjk-fonts-slices). No punctuation: no vertical forms to load.
const note = markdown.match(/note="([^"]*)"/)?.[1].replaceAll('\\n', '') ?? '';
await loadFonts(FONTS, markdown); // their Latin files: the colophon
await loadCjkFonts({ [SONG]: FONTS[SONG] }, `${markdown}論語集註卷一二三四五六七八九十`);
await loadCjkFonts({ [KAI]: FONTS[KAI] }, `論語集註${note}`);

Fontsource serves each Chinese face as about a hundred files per weight. Song sets the leaves, the strip and the leaf numbers, so its call gets the sample and those characters; Kai sets only the title and the note. The block has no punctuation, so neither face needs the vertical forms of loadCjkFonts(…, { vertical: true }).

#6 · One ink on a warm paper

script.js · lines 19–30in full code
const palette = {
  ink: '#1f1b17', // the text, as the block printed it
  rule: '#1f1b17', // the frame, the column rules and the fish tail: the same block, same ink
  vermilion: '#a3301f', // 朱: this edition's note, on the title page; 5.9 : 1 on the paper
  muted: '#6d6358', // the colophon
  paper: '#f2ead8',
};
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: 'defaults', value: { hex: palette.ink, model: 'hex' } },
];

The text and the block's lines print in one warm black, 14 : 1 on the paper. They are still two palette entries, ink and rule, so the rules can change colour without the text. The red is kept for what this edition adds.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 085 · A woodblock leaf: double frame, rules and centre strip ═══
// https://postext.dev/en/cookbook/woodblock-leaf
// Code: MIT · Text: 論語集註 卷一, 四庫全書 copy, zh.wikisource (CC BY-SA 4.0) · Pictures: none
// Fonts: Noto Serif TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A title page and three leaves of Zhu Xi's commentary on the Analects, set as a woodblock
// printed them: each spread is one leaf, its two halves either side of the centre strip
// (版心), the text in a double frame with a rule between every two columns, the commentary
// folded into two small rows inside the column.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the colophon; the leaves are Chinese in both
const RECIPE = 'woodblock-leaf';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink on a warm paper, and a red for the editor's note
const palette = {
  ink: '#1f1b17', // the text, as the block printed it
  rule: '#1f1b17', // the frame, the column rules and the fish tail: the same block, same ink
  vermilion: '#a3301f', // 朱: this edition's note, on the title page; 5.9 : 1 on the paper
  muted: '#6d6358', // the colophon
  paper: '#f2ead8',
};
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: 'defaults', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const [SONG, KAI] = ['Noto Serif TC', 'LXGW WenKai TC']; // 宋: the block's face; 楷: the title
// The leaf in points: 半葉九行,行十七字, a 20 pt character on a column pitch of 29 pt.
const [BODY, PITCH, CHARS, LINES] = [20, 29, 17, 9];
const HALF = 17; // half the centre strip, from the fold to the column rule beside it
const GAP = 4.5; // the text to the inner frame line, as a character to a column rule
const RULES = 4.5; // the thin inner frame line to the heavy outer one (文武線)
const [HEAD, FOOT, SIDE] = [164, 82, 60]; // paper outside the frame: 天頭 twice 地腳
const TOP = HEAD + RULES + GAP; // the page's margins
const BOTTOM = FOOT + RULES + GAP;
const OUTER = SIDE + RULES;
const W = HALF + LINES * PITCH + OUTER; // a half-leaf, 121 × 213 mm
const H = TOP + CHARS * BODY + BOTTOM;

// #region answer: a half-leaf to a page, so that every spread is one whole leaf
// A block printed both halves of a leaf (葉) at once, the centre strip between them. Each
// page here is a half-leaf. Page 1, the title, is a recto: in a book bound on the right it
// stands alone left of the spine, and every spread after it is one leaf, read from the

The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)

Variations

#Rule the columns in red

The copies made for the 四庫全書 were written on paper ruled in red (朱絲欄). Change the rule colour; the fish tail follows it.

-  rule: '#1f1b17', // the frame, the column rules and the fish tail: the same block, same ink
+  rule: '#b3412e', // 朱絲欄: red rules under black text

#Cut a different block

Blocks came in many counts, and 半葉十行,行二十字 is one of the commonest. The frames, the strip, the title page's three cells and the byline's indent are all worked out from these numbers, so they follow; the leaf breaks in the Markdown have to be counted again.

-const [BODY, PITCH, CHARS, LINES] = [20, 29, 17, 9];
+const [BODY, PITCH, CHARS, LINES] = [17, 24.5, 20, 10];

#Compare it with a European page on a grid

A book page on a baseline grid builds its type area from a count of lines, as this leaf builds its own from columns and characters; the certificate draws its border in the header of a heading style, as the title page does here.

Pitfalls

Pitfall

Tag the document zh-Hans or zh-Hant, not with LANG

A recipe's editions are en and es, but a Chinese sample is Chinese in both: `locale: LANG` would tag it English or Spanish, hyphenate its Latin words, label its figures Figure or Figura and give the PDF the wrong language. From postext 1.30 the tag is also the language the text is shaped in (measured, painted and embedded), so under an English or Spanish tag a Chinese face sets its digits and the punctuation it shares with Latin text in other forms, and the lines break elsewhere. Write the tag yourself: 'zh-Hans' (mainland conventions: GB line breaking, Kaiming punctuation) or 'zh-Hant' (Taiwan: full-width centred punctuation); 'zh-HK' for Hong Kong. A bare 'zh' reads as Simplified, mainland. A Japanese sample takes 'ja' (gotcha ja-locale-tag). Chinese line breaking →

Pitfall

Chinese faces load by slices, through the cjk block

Fontsource serves a Chinese, Japanese or Korean family as about a hundred files per weight, each covering a range of characters. loadFonts fetches only the latin file, so on screen the Han characters come from a system face and measure wrong, and fontsourceProvider hands the PDF that latin file, which prints them as empty boxes. List the cjk kit block, call loadCjkFonts(FONTS, markdown) after loadFonts (once per voice, with the text it sets, when the book uses several CJK faces) and give renderToPdf fontProvider: cjkPdfProvider: both take the files that hold the text's characters. Chinese, Japanese and Korean fonts →

Pitfall

A right-bound book shows its spreads with showBook

In a book bound on the right (Arabic, Hebrew or Persian text, vertical Chinese, or page.binding 'right') page 1 is still the recto, but it lies on the left of the spine, and the pairs read [3 | 2]. showPages lays every book out left-bound; showBook from the book block (the cjk block carries the same function) reads doc.binding and mirrors the pairs. capture.hero still names a spread in reading order, [verso, recto]: [2, 3]. Books bound on the right →

Pitfall

Traditional transcriptions carry stray Simplified characters

Texts copied from Wikisource or another web edition of a Traditional book sometimes carry a Simplified form (颙 for 顒 in 三國演義, chapter 1), and a TC face such as Noto Serif TC may not have it. loadCjkFonts stops the pen with the character in its message; on a page it would print in a fallback face. Restore the Traditional form in the sample and say so in the credits. Chinese, Japanese and Korean fonts →

  • The leaf breaks live in the Markdown. Change the text, the size or the 行款 and a leaf that runs over pushes the next heading a page further, so the spreads stop matching the leaves; one that runs short leaves blank columns before the fold. Check the last column of every left-hand page.
  • The 四庫全書 transcription types 巳 for 已 and 己 alike; this sample reads each one from its sentence. The page still asks to be proofread against the scans, and it shows: 張敬夫's remark reads 必開其政 where the Analects he repeats have 必聞其政, and two characters come as pictures of the glyph. The sample sets 聞, 傳 and 邦. Check a passage against a second edition before you set it.
  • The same transcription carries forms Noto Serif TC has no glyph for (廹 徳 絶 逺 専 内). Five of them fall inside the range of a Fontsource file, so loadCjkFonts lets them through, and then the canvas draws them from a system face and postext-pdf prints an empty box and warns. 廹 falls in no file's range, and loadCjkFonts stops with an error. The sample sets 迫 德 絕 遠 專 內.

Credits

Text
  • 論語集註 (Collected Commentaries on the Analects), juan 1, the book 學而 from its opening to the end of its tenth section, in the copy made for the 四庫全書 (Siku quanshu, 1773–1782); Wikisource transcription, revision 523110. 巳 is read as 已 or 己 by its sentence; 開 in 張敬夫's 必開其政 is corrected to 聞, as in the words of the Analects he repeats and in Wikisource's other edition (論語集注卷一, revision 2598582); the two characters the transcription gives as glyph images are set as 傳 (以忠信為傳習之本) and 邦 (夫子至於是邦也); and six variant forms Noto Serif TC does not draw (廹 徳 絶 逺 専 内) are set in their standard forms · Zhu Xi (1130–1200); transcription by Wikisource editors · CC BY-SA 4.0
  • The title page, the division into leaves and the note on this edition (據四庫全書本錄文…) · Ignacio Ferro · CC BY 4.0
Fonts
Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
SandboxPDF