本文へスキップ
レシピ番号74

レシピ集 · 第2章 · 文字と本文

28字×28行のグリッドに組む中国語の小説

魯迅の「故郷」を大32开のページに組みます。1行28字、1ページ28行、GBの禁則処理、开明式の約物、漢字と欧文のあいだのアキ。

このページの内容
出力
Canvas · PDF
レベル
中級
Postext
Postext 1.65.0で検証済み
1.65.0以上が必要 · postext-pdf ≥ 1.65.0
ライセンス
2026年10月31日更新
コードMIT · 本文MIT

70〜71ページ · 1〜2/7

  • 英語の見本:日本語版はまだありません
  • 仕上がり140 × 203 mm
  • 1段
  • Noto Serif SC 10.5/16.5
  • Ma Shan Zheng
  • Noto Sans SC
  • 7ページ
  • レベル
  • Postext 1.65.0
  • 組版時間99 ms
  • コード179行

かんたんな説明

魯迅の短編の冒頭を、中国のペーパーバックのページとして組みます。中国語の約物の規則に従いながら、各行にちょうど28字、各ページにちょうど28行を収める方法を示します。

できあがり

魯迅の「故郷」(故乡、1921年)の冒頭を、最初の作品集の本土版ペーパーバックが組むように組みます。140 × 203mmの大32开のページで、版面は字数で数え、1行28字、1ページ28行、Noto Serif SCの五号(10.5pt)です。段落はどれも2字下げで始まり、多くの本土の本と同じく、コンマや引用符は半字分の幅を取ります。行頭に。や,は来ず、行末に“は来ません。物語は奇数ページから、宋体のブラックウェイトで組んだ題の下で始まります。向かいのページには語り手が思い出す月夜のスイカ畑を描いた口絵があり、それを描写する文章がMa Shan Zhengの筆書きの書体で入ります。スペイン語を両端そろえで組むポケット判の小説は、同じことをラテン文字で行います。

このレシピが答える質問

  • 版面を字数で設定し、1行の字数と1ページの行数を決めるには?
  • 。や,が行頭に来ないようにするには?
  • 中国語の約物を、中国大陸の本のような開明式や半角で組むには?
  • 中国語と欧文の間のスペースを、入力せずに入れるには?

手短な答え

script.js · 37〜53行コード全体で見る
const cjk = {
  // The type area in characters: 28 ems wide, 28 lines of LEAD tall. page.margins become
  // minimums, and the grid centres the type area in the room they leave.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
  // What 'zh-Hans' gives by itself, written out so a reader can compare regions and styles.
  region: 'mainland',
  lineBreak: 'gb', // no 。,、”》 opens a line, no “《( ends one, and no / at either end
  punctuationWidth: 'kaiming', // ,、:; quotes, brackets ½ em; 。?! one em, ½ at a line end
  compressAdjacent: true, // idle under Kaiming (no pair tops 1.5 em); 'fullwidth' needs it
  latinSpacing: em(0.25), // 1921年, 用Noto Serif SC五号: a quarter em, none of it typed
};
const bodyText = {
  fontFamily: SONG, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  textAlign: 'justify', // spread between the characters, never between words
  firstLineIndent: em(2), indentAfterHeading: true, // two characters, every paragraph
};

材料

種類
Noto Serif SC, Noto Sans SC, Ma Shan Zheng (SIL OFL 1.1)
素材
  • plate-1120.jpg
  • The plate: the moonlit melon field of the story, a painting (Generated With Diffusion Models, オリジナル)

作り方

#1 · 字数で数えるページ

コードは上の手短な答えにあります。cjk.gridは行長をbodyText.fontSizeの28em(294pt、103.7mm)、版面の高さをlineHeightの28行(462pt、163mm)とし、それに合わせて余白を動かします。そのため、漢字だけの行にはちょうど28字が入り、満杯のページはどれも同じ行で終わります(文字グリッド)。グリッドの下の5つの設定は、locale: 'zh-Hans'だけで得られる値です。1つずつ変えられるように書き出してありますが、compressAdjacentはpunctuationWidthが'fullwidth'になるまで何も変えません。开明式では、隣り合う約物が合わせて1.5emを超えることがないからです。71ページでは段落の最後の。が行に収まらず、行頭禁則('none'以外のすべてのlineBreakレベル。'gb'はスラッシュを加えます)が、それを行頭に置くことを禁じます。そこで行は事の後ろの。を半字幅にして取り込み(追い込み)、事。宏が詰まって、段落はもう1行に延びずにすみます(約物の幅)。字数の足りない行は単語のあいだではなく文字のあいだに割り振られ、このページでは0.05emを超えません(中国語・日本語・韓国語)。

71ページ、段落の最後の数行。事。宏を詰めて組み、看。が次の行頭に出ずにこの行にとどまっています。

#2 · 天を深くとった大32开のページ

script.js · 57〜62行コード全体で見る
const page = {
  width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
  // 22 + 18 mm leave 163 mm, exactly 28 lines of 16.5 pt; 18 mm a side leave the 103.7 mm
  // measure 0.3 mm to share. A grid that no longer fits is cut down (cjkGridClamped).
  margins: { top: mm(22), bottom: mm(18), left: mm(18), right: mm(18), mirror: true },
};

グリッドを有効にすると、余白は最小値になります。グリッドは余白が残す領域に版面を置き、余った分を割り振ります。22mmと18mmでちょうど163mmが残るので、中国の本と同じく天の余白は地より4mm深いままです。左右の18mmでは、割り振る余りは0.3mmです。収まる以上の字数や行数を求めると、グリッドは収まる分まで減らされ、cjkGridClamped警告が出ます。文字サイズと行送りは書いたとおりのままです。

#3 · 行数の整数倍だけ下げた題

script.js · 66〜84行コード全体で見る
const SINK = 8; // lines of LEAD: a whole number, so the text under it keeps to the grid
const centred = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });
const opener = {
  enabled: true,
  minHeight: pt(SINK * LEAD),
  slot: { elements: [
    // The spacing after the last character is advance, not ink: the title stays centred.
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: SONG, fontWeight: 900,
      fontSize: pt(46), letterSpacing: pt(23), lineHeight: 1.1, color: col('ink'),
      align: 'center', placement: centred(6) },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1.2),
      color: col('night'), placement: { ...centred(30), size: { width: mm(8) } } },
    { kind: 'text', id: 'author', content: '{author}', fontFamily: HEI, fontSize: pt(10.5),
      letterSpacing: pt(5), color: col('ink'), align: 'center', placement: centred(34) },
  ] },
};
// parity 'any': a story opens on the next page, left or right.
const chapter = { level: 1, breakBefore: { enabled: true, parity: 'any' },
  marginTop: pt(0), marginBottom: pt(0), advancedDesign: opener };

minHeightは16.5ptの8行分なので、題の下の本文はグリッドの9行目から始まり、他のすべてのページと同じベースラインに並びます。23ptの字間で、故と乡のあいだに2字の題によくある半字分のアキが入ります。Postextは行を中央にそろえるとき最後の字のあとの字間を除くので、題はページの軸からずれません(見出しスタイル)。

#4 · 偶数ページに書名、奇数ページに作品名

script.js · 88〜107行コード全体で見る
const HEAD_Y = 11; // mm from the top edge to the heads; the hairline 5 mm lower
const label = { fontFamily: HEI, fontSize: pt(8), color: col('muted'), pages: 'body' };
const at = (edge, x, y = HEAD_Y) => ({ anchor: { to: 'page', edge },
  offset: { x: mm(x), y: mm(y) } });
const header = { elements: [
  { kind: 'text', id: 'verso-folio', content: '{pageNumber}', parity: 'even', ...label,
    placement: at('top-left', SIDE) },
  { kind: 'text', id: 'verso-book', content: '{title}', parity: 'even', ...label,
    letterSpacing: pt(4), placement: at('top', 0) },
  { kind: 'text', id: 'recto-story', content: '{chapterTitle}', parity: 'odd', ...label,
    letterSpacing: pt(4), placement: at('top', 0) },
  { kind: 'text', id: 'recto-folio', content: '{pageNumber}', parity: 'odd', ...label,
    placement: at('top-right', -SIDE) },
  { kind: 'rule', id: 'hairline', direction: 'horizontal', thickness: pt(0.5), color: col('rule'),
    pages: 'body', placement: { ...at('top-left', SIDE, HEAD_Y + 5), size: { width: mm(MEASURE) } },
  },
] };
// The opener has no head: its folio drops to the foot, centred under the text.
const footer = { elements: [{ kind: 'text', id: 'drop-folio', content: '{pageNumber}',
  ...label, pages: 'opener', align: 'center', placement: at('bottom', 0, -10) }] };

本土の小説は偶数ページに書名、奇数ページに作品名を中央に置き、ノンブルを小口側に、どちらの下にも細い罫を引きます。pages: 'body'は柱を章扉と口絵から外し、章扉には代わりに地にノンブルが入ります。柱は黑体のNoto Sans SCで8ptです。小さくても、本文の宋体とは違う声として読めます。

#5 · 紙全体を覆う口絵

script.js · 111〜143行コード全体で見る
// The plate, a painting: a JPEG in assets/ cut to the 140 × 203 mm trim, declared at its pixels.
const resources = [{
  id: 'moon', typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
  bitmap: { fileId: 'plate-1120.jpg', format: 'jpeg', width: 1120, height: 1624 },
  altText: t({
    en: 'A golden full moon in a deep blue sky over a strip of sea. On the sand below, among '
      + 'rows of striped watermelons, a boy with a silver collar stabs a steel fork at the '
      + 'sand ahead of him, and the small animal he aimed at runs off between his legs.',
    es: 'Una luna llena dorada en un cielo azul oscuro sobre una franja de mar. En la arena, '
      + 'entre hileras de sandías rayadas, un muchacho con un aro de plata al cuello clava una '
      + 'horquilla de acero en la arena, delante de él, y el animalillo al que apuntaba huye '
      + 'entre sus piernas.',
  }),
}];
const quote = { fontFamily: KAI, fontSize: pt(14), lineHeight: 1.5, color: col('paper') };
// # 月下的瓜地 {style="plate" line1="…" line2="…" line3="…"}: a page with no head or folio.
// 'page' spans the design over the sheet: a heading's design in the column is cut at its foot.
const plate = {
  id: 'plate', span: 'page', runningChapter: false, toc: false, // out of the PDF outline
  breakBefore: { enabled: true, parity: 'any' }, // (gotcha: style-inherits-break)
  header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'image', id: 'picture', resourceId: 'moon', placement: { // the whole trim
      anchor: { to: 'bleed', edge: 'top-left' },
      size: { width: mm(TRIM.width), height: mm(TRIM.height) } } },
    { kind: 'text', id: 'line1', content: '{attr.line1}', ...quote, align: 'left',
      placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(2) } } },
    { kind: 'text', id: 'line2', content: '{attr.line2}', ...quote, align: 'left',
      placement: { anchor: { to: '#line1', edge: 'below' } } },
    { kind: 'text', id: 'line3', content: '{attr.line3}', ...quote, align: 'left',
      placement: { anchor: { to: '#line2', edge: 'below' } } },
  ] } },
};

画像は専用の見出し# 月下的瓜地 {style="plate" …}に属し、そのスタイルがページを描いて柱とノンブルを消します。段の中にとどまる見出しのデザインは段の末尾、つまり仕上がりより18mm手前で切られるので、口絵にはspan: 'page'が必要です。runningChapter: falseとtoc: falseで口絵はPDFのしおりから外れ、しおりは故乡から始まります。引用の3行は、3つの属性と3つのテキスト要素で組みます。デザインのテキストは独自の改行処理を行い、中国語の約物の幅を設定しないからです。手で改行した行は、中国語の表示用の行がふつうそうするように、読点も落としています。

#6 · 中国語の本文の中の欧文と数字

script.js · 147〜153行コード全体で見る
const paragraphStyles = [
  // 小五 (9 pt) nudged to 9.1875 pt: 32 of its characters fill the 28-em measure exactly.
  { id: 'note', fontSize: pt((CHARS * BODY) / 32), lineHeight: pt(LEAD), color: col('ink'),
    firstLineIndent: em(2), marginTop: pt(LEAD) }, // on the grid, a line below the text
  { id: 'colophon', fontFamily: HEI, fontSize: pt(7), lineHeight: pt(11), color: col('muted'),
    textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD / 2) },
];

76ページの注記と奥付は、数字や欧文の名前が漢字と出会う場所です。latinSpacingは、両者が接するところに4分アキを入れます。注記の1921年や奥付の用Noto Serif SC五号のように、スペースをまったく入れずに入力したところです(和欧間のアキ)。両端そろえの行ではこのアキが最初に広がり、最大で半字まで伸びます。注記は小五の9ptではなく9.1875ptで組み、32字で行長がちょうど埋まるようにしています。9ptでは各行に2/3字分の余りが出て、漢字と欧文のアキがそれを吸収していました。Markdownではフォント名をノーブレークスペース(U+00A0)でつないでいます。漢字と欧文のアキはこれに手を付けません。通常のスペースでは、奥付の行末不ぞろいの行がNoto Sans / SCで改行されていました。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 074 · A Chinese novel page on a 28 × 28 grid ════════════
// https://postext.dev/en/cookbook/chinese-novel-horizontal
// Code: MIT · Text: Lu Xun, 故乡 (1921), public domain, zh.wikisource · Plate: diffusion models
// Fonts: Noto Serif SC, Noto Sans SC, Ma Shan Zheng (SIL OFL 1.1) · Needs postext ≥ 1.65.0
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 sample document ('en' | 'es')
const RECIPE = 'chinese-novel-horizontal';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// The night of the story's memory, and ink on a cream paper.
const palette = {
  ink: '#1f1c19', // text: a warm near-black
  night: '#1d3150', // the accent: the deep blue of the plate's sky, the opener's rule
  rule: '#c9c1b2', // the hairline under the running heads
  muted: '#6a645b', // running heads, folios, the colophon
  paper: '#fbf8f1', // a cream book paper
};
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: 'night (defaults)', value: { hex: palette.night, model: 'hex' } },
];
const SONG = 'Noto Serif SC'; // 宋: the text, and the title in its black weight
const HEI = 'Noto Sans SC'; // 黑: running heads, folios, the author, the colophon
const KAI = 'Ma Shan Zheng'; // 楷: a brush regular script for the plate's quotation
const [BODY, LEAD] = [10.5, 16.5]; // pt: 五号 on a 6 pt line gap, the grid's pitch
const [CHARS, LINES] = [28, 28];
const TRIM = { width: 140, height: 203 }; // mm: 大32开
const MEASURE = (CHARS * BODY * 25.4) / 72; // 103.7 mm: 28 ems of 五号
const SIDE = (TRIM.width - MEASURE) / 2; // 18.1 mm: the grid centres the measure

// #region answer: 28 characters × 28 lines of 五号, mainland line breaks and Kaiming marks
const cjk = {
  // The type area in characters: 28 ems wide, 28 lines of LEAD tall. page.margins become
  // minimums, and the grid centres the type area in the room they leave.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
  // What 'zh-Hans' gives by itself, written out so a reader can compare regions and styles.
  region: 'mainland',
  lineBreak: 'gb', // no 。,、”》 opens a line, no “《( ends one, and no / at either end
  punctuationWidth: 'kaiming', // ,、:; quotes, brackets ½ em; 。?! one em, ½ at a line end
  compressAdjacent: true, // idle under Kaiming (no pair tops 1.5 em); 'fullwidth' needs it
  latinSpacing: em(0.25), // 1921年, 用Noto Serif SC五号: a quarter em, none of it typed
};
const bodyText = {

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#すべての約物を全角にする(全角式)

コンマ(,)、読点(、)、引用符が1字分を取り、。”は2字分を取るので、各行に入る本文の字数が減ります。

-  punctuationWidth: 'kaiming', // ,、:; quotes, brackets ½ em; 。?! one em, ½ at a line end
-  compressAdjacent: true, // idle under Kaiming (no pair tops 1.5 em); 'fullwidth' needs it
+  punctuationWidth: 'fullwidth',
+  compressAdjacent: false,

#ページを組むあいだグリッドを表示する

Canvasは各行のすべての字の位置に薄い灰色の正方形を描きます(稿纸)。PDFでは、renderToPdfにcharacterGrid: trueを渡さないかぎり描かれません。

-  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
+  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES, show: true },

よくあるつまずき

つまずき

中国語の書体はcjkブロックを通じてスライス単位で読み込む

Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →

つまずき

文書のタグはLANGではなくzh-Hansかzh-Hantにする

レシピの版はenとesですが、中国語のサンプルはどちらの版でも中国語です。`locale: LANG`では英語やスペイン語とタグ付けされ、ラテン文字の語がハイフネーションされ、図にFigureやFiguraの表示名が付き、PDFの言語も誤ります。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、英語やスペイン語のタグでは、中国語のフォントの数字と、ラテン文字のテキストと共通の約物が別の字形になり、改行の位置も変わります。タグは自分で書いてください。'zh-Hans'(中国本土の慣習:GBの改行規則、開明式の約物)または'zh-Hant'(台湾:全角で中央に置く約物)、香港なら'zh-HK'です。単なる'zh'は簡体字、本土として読まれます。日本語のサンプルには'ja'を使います(つまずき「ja-locale-tag」)。 中国語の改行 →

つまずき

各地域の約物はその地域の書体で組む

約物の幅の処理は、各記号の横の空きを、フォントが描く側ではなく、文書の地域が置く側に移します。zh-Hansでは開明式の読点は箱の左半分を残し(簡体字の書体はそこにグリフを描きます)、右半分を手放します。繁体字の書体は,。を箱の中央に描くため、手放す半分にグリフの一部があり、読点が次の文字に食い込みます。Fontsourceで唯一の楷書の本文書体であるLXGW WenKai TCは、簡体字のテキストでこうなります。本土のテキスト、注、引用はNoto Serif SCかNoto Sans SCで組み、TCの書体はzh-Hantに取っておき、簡体字の毛筆書体(Ma Shan Zheng)は表示用の行だけに使ってください。デザインのテキストには約物の幅の処理がかからないためです。LXGW WenKai TCは、本土の規格も台湾の規格も使わない伝承字形も描きます。爲の爫の頭を持つ為や、卩の足を持つ令(冷、領の中も)です。この書体で組むページの文字を確認してください。 中国語の約物の幅 →

つまずき

中国語にはイタリックがない

CJKのファミリーにはイタリックがなく、中国語の組版では強調を傾きではなく、文字の横の圏点で示します。中国語とタグ付けした文書では、*…*は中に含む漢字に圏点を付け、ラテン文字の語にはイタリックを使います(cjk.emphasis: 'dots'、中国語の既定)。:dots[…]はどこでも圏点を付けます。cjk.emphasis: 'italic'の場合や、enやesとタグ付けした文書では、*…*によってCanvasが立体のグリフを傾けます。中国語の組版では使わない擬似斜体です(PDFでは立体にフォールバックします)。中国語のタグを保つか、段落スタイルやチップスタイルで強調を太字や楷書体(LXGW WenKai)にしてください。 中国語・日本語・韓国語のフォント →

つまずき

見出しスタイルはその階層の改ページを受け継ぐ

headingStylesの項目は、指定しなかったフィールドをすべて見出しの階層から受け継ぎ、breakBeforeも例外ではありません。:::pagebreakのあとのH1に付けた目次や奥付のスタイルはparity 'odd'を受け継ぎ、白ページの後ろに置かれます。こうしたスタイルにはbreakBefore: { enabled: false }を指定してください。 見出しスタイル →

レイアウト警告 · cjkGridClamped

大きすぎる文字グリッド

原因. `cjk.grid`が求める1行の字数またはページあたりの行数が、本文のサイズと行送りではページの余白の内側に収まらないため、収まる最大の値でグリッドを組みます。

対処. `charsPerLine`または`linesPerPage`を下げる、余白を狭める(余白は最小値です)、または`bodyText.fontSize`や`lineHeight`を小さくしてください。 ドキュメント →

  • 口絵は見出しで、見出しにはPDFのしおりが付きます。口絵のスタイルにrunningChapter: falseとtoc: falseがなければ、しおりは故乡より前に置かれた第1レベルのしおり、月下的瓜地から始まります。どちらか一方の設定だけでも口絵はしおりから外れます。タグ付きPDFでは、口絵の題はH1として残ります。
  • デザインがすべての題を描く場合でも、見出し自体の書体はFONTSが読み込むものにしてください。既定のウェイト700では、キットはレイアウトの中にNoto Serif SC 700を見つけ、そのラテン文字のファイルを警告付きで読み込みました。headings.fontWeight: 400で、見出しブロックは本文の書体のままになります。

クレジット

レシピ
Ignacio Ferro
本文
  • “My Old Home” (故乡, 1921), the first half, from the 1948 Complete Works, in simplified characters · Lu Xun (鲁迅) · パブリックドメイン
  • The editor’s note and the colophon · Postext Cookbook · オリジナル
画像
  • The plate: the moonlit melon field of the story, a painting · Generated With Diffusion Models · オリジナル
フォント
Noto Serif SC (SIL OFL 1.1) · Noto Sans SC (SIL OFL 1.1) · Ma Shan Zheng (SIL OFL 1.1)
SandboxPDF