かんたんな説明
台湾の学校で使う国語の読本を、上から下へ読む縦の行で印刷します。漢字の一つひとつに小さな読み仮名のような発音記号が付き、子どもはまだ習っていない字も読めます。
できあがり
架空の台湾の小学5年生用読本『國語』第9冊の第12課です。『韓非子』から2つの寓話を採っています。切り株のそばでもう1匹のウサギを待つ宋の農夫と、自分の足より寸法書きを信じる鄭の男の話です。台湾の読本は楷書体の縦組みで、各字の右に注音を1列に添えるので、子どもは字を習う前にその字を読めます。課は右綴じの見開きで始まります。上段には画像、注、作者、新出字を入れ、下段には16ptのIansuiで1行23字の本文が続きます。ラテン文字での対応例は余白に段を設けた教科書で、そのフロート専用のサイド段を90°回したものが、ここでの上段にあたります。
このレシピが答える質問
- 縦組みの中国語のすべての文字の横に注音を付けるには?
- 中国語の本を縦組み・右綴じで組むには?
手短な答え
const layout = {
writingMode: 'vertical-rl', // lines run down the page, read from the right; bound on the right
layoutType: 'oneAndHalf', // two tiers: the text below, pictures and notes above
sideColumnRole: 'floats', sideColumnSide: 'left', // 'left' is the top tier in vertical text
sideColumnPercent: 34,
gutterWidth: pt(2 * SIZE),
};
const cjk = {
// The lower tier: 23 characters down, 13 lines across the page.
grid: { enabled: true, charsPerLine: 23, linesPerPage: 13 },
// Readings at half the text size; zhuyin sets its symbols at 60 % of that, 0.3 em,
// so three symbols fit beside one character, and beside each of two in a row.
ruby: { fontFamily: ZHUYIN, fontSize: em(0.5) },
};
// The line pitch is twice the size: a gap of one em, which the zhuyin and its tone
// marks half fill. clreq asks for 1.5 em; one em keeps 13 lines of 23 on the page.
const LINE = 2 * SIZE;
const bodyText = {
fontFamily: KAI, fontSize: pt(SIZE), lineHeight: pt(LINE), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: em(2), indentAfterHeading: true,
};
材料
- 機能
- ルビ:ピンインと注音縦組み右綴じの本中国語・日本語・韓国語のフォント中国語の約物の幅文字グリッド1段半組みフロート用の余白段欄外の注中国語の漢数字番号付きリスト独自のリソースの種類囲み段落スタイル見出しスタイルページデザインのテキスト・罫・ボックス柱とノンブルPDFの書き出し
- 種類
- Iansui, LXGW WenKai TC, Noto Serif TC, Noto Sans TC (SIL OFL 1.1)
- 素材
plate-1-1500.jpgplate-2-1500.jpg- The farmer waiting by the stump, a brush painting (Generated With Diffusion Models, オリジナル)
- The man of Zheng hurrying home from the shoe stall, a brush painting (Generated With Diffusion Models, オリジナル)
作り方
#1 · 各字の横に注音の列
コードは前に掲げた手短な答えです。{宋人|ㄙㄨㄥˋ|ㄖㄣˊ}は、|で区切った読みを1字ずつ与えます。約物は波括弧の外に置くので、。や,には読みが付きません。縦組みでは、注音符号による読みは行の右に置かれ、記号は縦に積まれます。声調記号は最後の記号の右に、軽声の点は最初の記号の上に付きます。cjk.ruby.fontSizeを本文の半分にすると記号は0.3emで組まれ、3つの記号が1字の横に収まります。就像のように読みが2つ続いても、どちらの字も広げずに記号の4分の1以上の間隔を保ちます。0.6emにすると、ㄇㄧㄥˊは明より背が高くなり、明明の字間が広がります。32ptの行送りでは行間が1em残り、注音とその声調記号がその半分ほどを埋めます。clreqは縦組みの行の間に注音を置くとき1.5emの行間を求めますが、それは行送り40ptで1ページ10行になります。そこでこのページは行間を1emにして23字×13行とし、各読みは隣の行から約8ptの間隔を保っています。
#2 · 上段の絵と注
const resourceTypes = [{ id: 'plate', name: '插圖', shortLabel: '圖', numberingTemplate: '{n}',
resetOn: 'never', counterFormat: 'decimal', captionPrefix: '' }]; // no prefix, no caption
const box = (id, title, body) => ({ id, title, background: col('tint'),
padding: { top: mm(3), right: mm(3), bottom: mm(3), left: mm(3) },
titleStyle: { fontFamily: HEI, fontSize: pt(11), fontWeight: 700, color: col('accent') },
body: { color: col('ink'), firstLineIndent: pt(0), textAlign: 'left', boldColor: col('ink'),
italicColor: col('ink'), ...body } });
// Zhuyin is 0.3 em of the text it reads: at 13 pt the notes' readings are 3.9 pt.
const calloutStyles = [ // fenced :::callout{type="notes" span="side"} in the text
box('notes', '注釋', { fontFamily: MING, fontSize: pt(13), lineHeight: pt(24) }),
box('author', '作者', { fontFamily: MING, fontSize: pt(13), lineHeight: pt(24),
textAlign: 'justify', firstLineIndent: em(2) }),
box('chars', '生字', { fontFamily: KAI, fontSize: pt(22), lineHeight: pt(40),
textAlign: 'center' }),
];
縦組みでは、oneAndHalfレイアウトの段は上下の段になり、sideColumnSide: 'left'でフロート専用の段を上に置きます。本文中の::resource{id="plate-1"}が最初の画像をそこへ送ります。plateタイプにはキャプションの接頭辞がなく、画像にもキャプションがないので、画像の下には何も印刷されません。span="side"で記述した囲みは、記述した行から上段に入り、その文章は上段の中を下へ流れます。2つの寓話の注は1つの囲みにまとめ、課を通して番号を振り、86ページで終わる1つ目の原文の後に記述しています。注は87ページの上段を埋め、どちらの寓話の注も原文と同じ見開きに収まります。注音は読みを付ける文字の0.3emで、cjk.rubyは本全体で1つの設定です。そのため注と作者の囲みは13ptで組み、読みを3.9ptに保ちます。
#3 · 4つの書体、それぞれが自分のテキストだけを読み込む
// {株|ㄓㄨ}: the characters are the text, the readings go to the zhuyin face.
const BOXES = /^:::callout\{type="(?:notes|author)"[^}]*\}\n([\s\S]*?)^:::$/gm;
const bases = (md) => md.replace(/\{([^|{}]+)((?:\|[^|{}]+)+)\}/g, '$1');
const readings = [...markdown.matchAll(/\{[^|{}]+((?:\|[^|{}]+)+)\}/g)].map((m) => m[1]).join('');
await loadFonts(FONTS, markdown);
await loadCjkFonts({ [KAI]: ['400'] }, bases(markdown.replace(BOXES, '')), { vertical: true });
const notesText = [...markdown.matchAll(BOXES)].map((m) => m[1]).join('\n');
await loadCjkFonts({ [MING]: ['400'] }, bases(notesText), { vertical: true });
await loadCjkFonts({ [ZHUYIN]: ['400'] }, readings.replaceAll('|', ''), { vertical: true });
await loadCjkFonts({ [HEI]: ['400', '700'] }, LABELS, { vertical: true });
await Promise.all(Object.values(plates).map((fileId) => loadImage(fileId, asset(fileId))));
// Lesson 12 of a reader: page 86 is a verso, so the lesson opens on a spread.
const continuation = { pageIndexOffset: 1, pageNumbering: { startAt: 86 } };
const doc = await withLoadedFonts(
() => buildDocument({ markdown, resources, continuation }, config()),
{ ...kitFonts(FONTS), text: markdown });
showBook(doc, { title: t({ en: 'A vertical reader with zhuyin',
es: 'Un libro de lectura vertical con zhuyin' }) });
offerPdf(() => renderToPdf(doc, { fontProvider: cjkPdfProvider, resourceBytes: imageBytes }),
`${RECIPE}.pdf`);
課の本文はIansuiで組みます。Klee Oneをもとに、子どもが書き方を習う台湾の標準字体で描かれた楷書体です。読みはLXGW WenKai TCで組み、この書体の軽声の点は4.8ptでも丸いまま保たれます。注はNoto Serif TC、ラベルはNoto Sans TCです。各書体は、自分が組む字を含むファイルだけを読み込みます。読みはその字とは別に分けられ、注の囲みは明朝体だけに回されます。vertical: trueは縦組み用の字形を加えるので、「」や、が行の中で正しい向きに立ちます。pageIndexOffset: 1で86ページを偶数ページにし、課が見開きで始まるようにします。
#4 · 小口側のつめとノンブル
// The verso lies on the right of the spread, so even pages carry both at the right edge.
const tab = (parity, edge) => [
{ kind: 'box', id: `tab-${parity}`, parity, pages: 'all',
placement: { anchor: { to: 'page', edge }, offset: { y: mm(24) },
size: { width: mm(9), height: mm(64) } }, style: { backgroundColor: col('accent') } },
{ kind: 'text', id: `unit-${parity}`, content: '第三單元 寓言故事', parity, pages: 'all',
writingMode: 'vertical-rl', fontFamily: HEI, fontSize: pt(9), fontWeight: 700,
color: col('paper'), align: 'center', verticalAlign: 'middle',
placement: { anchor: { to: `#tab-${parity}`, edge: 'align-top' },
size: { width: mm(9), height: mm(64) } } },
];
const foot = (id, parity, edge, x, content, extra = {}) => ({
kind: 'text', id, content, parity, pages: 'all', fontFamily: HEI, fontSize: pt(8),
color: col('muted'), placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(-9) } },
...extra,
});
const folio = { fontSize: pt(9), fontWeight: 700 };
const header = { elements: [...tab('even', 'top-right'), ...tab('odd', 'top-left')] };
const footer = {
elements: [
foot('folio-even', 'even', 'bottom-right', -16, '{pageNumber}', folio),
foot('book', 'even', 'bottom-right', -26, '國語 第九冊'),
foot('folio-odd', 'odd', 'bottom-left', 16, '{pageNumber}', folio),
foot('lesson', 'odd', 'bottom-left', 26, '{chapterNumber} {chapterTitle}'),
],
};
右綴じの本では偶数ページが見開きの右側に来るので、偶数ページは右端に、奇数ページは左端に単元のつめとノンブルを置きます。つめは箱の上にテキスト要素を重ねたものです。要素にwritingMode: 'vertical-rl'を指定して第三單元 寓言故事をつめの中で縦に組み、ノンブルと地の行は横組みのままにします。課と寓話の番号は見出しのnumberingTemplate(第{1:一}課と{2:一}、numberSeparatorは全角スペース、課の見出しに{startAt=12})で付け、題とは別のスパンになるので、寓の注音は寓だけに付きます。{chapterTitle}は番号を含まないため、奇数ページの地の行は{chapterNumber} {chapterTitle}としています。
レシピの全体
// ═══ Postext Cookbook · Nº 080 · A vertical reader with zhuyin to the right ═════════
// https://postext.dev/en/cookbook/zhuyin-vertical-reader
// Code: MIT · Text: Han Feizi, zh.wikisource (CC BY-SA 4.0) · Pictures: diffusion models
// Fonts: Iansui, LXGW WenKai TC, Noto Serif TC, Noto Sans TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage, loadVerticalAlternates,
} 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 = 'zhuyin-vertical-reader';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
ink: '#2b2520', // text and zhuyin
accent: '#b83f28', // lesson title, labels, the unit's tab (4.9:1 on the tint)
tint: '#f7efdf', // the boxes of the upper tier
muted: '#72675b', // lead, folios, colophon
paper: '#ffffff', // the lettering on the tab
};
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' } },
];
// #endregion
const KAI = 'Iansui'; // 楷: the lesson, drawn to Taiwan's standard forms (為, not 爲)
const ZHUYIN = 'LXGW WenKai TC'; // the readings: a round dot for the neutral tone
const MING = 'Noto Serif TC'; // 明: notes and the author box
const HEI = 'Noto Sans TC'; // 黑: labels, folios, the tab
const SIZE = 16; // the text size (三號)
// #region answer: vertical text with a zhuyin column right of every character
const layout = {
writingMode: 'vertical-rl', // lines run down the page, read from the right; bound on the right
layoutType: 'oneAndHalf', // two tiers: the text below, pictures and notes above
sideColumnRole: 'floats', sideColumnSide: 'left', // 'left' is the top tier in vertical text
sideColumnPercent: 34,
gutterWidth: pt(2 * SIZE),
};
const cjk = {
// The lower tier: 23 characters down, 13 lines across the page.
grid: { enabled: true, charsPerLine: 23, linesPerPage: 13 },
// Readings at half the text size; zhuyin sets its symbols at 60 % of that, 0.3 em,
// so three symbols fit beside one character, and beside each of two in a row.
ruby: { fontFamily: ZHUYIN, fontSize: em(0.5) },
};
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
よくあるつまずき
つまずき
ルビは本文に出て、デザイン、キャプション、セルには出ない
ルビは段落、見出し、リスト項目、引用、囲みで描かれます。デザインのテキスト要素(章扉、柱、バッジ)、キャプション、脚注、表のセルでは、ルビなしで親文字だけが印字されます。ピンインが必要なタイトルは、独自のデザインを持たない見出しにしてください。その周り(帯や課の番号)は直前の見出しのデザインで描きます。reserve: falseの要素は、span: 'page'の章扉の本文の下に描かれます。 ルビ:ピンインと注音 →
つまずき
縦組みのサイド段はページを横切る段になり、'left'は天側
layout.writingModeが'vertical-rl'のとき、ページは横組みのページを90度回したものになるため、oneAndHalfレイアウトのサイド段はページを横切る段になります。sideColumnSide 'left'はそれを天側、頭注(眉批)の位置に置き、'right'は地側に置きます。'outer'と'inner'は'right'と'left'として読まれる(横切る段には小口側の端がない)ため、教科書の余白の段に使う'outer'では注が地側に行きます。sideColumnPercentはページの高さに対する割合です。 フロート用の余白段 →
つまずき
中国語の書体はcjkブロックを通じてスライス単位で読み込む
Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →
つまずき
右綴じの本の見開きはshowBookで表示する
右綴じの本(アラビア語、ヘブライ語、ペルシア語のテキスト、縦組みの中国語、またはpage.binding 'right')でも1ページは奇数ページですが、背の左側に来て、見開きは[3 | 2]と並びます。showPagesはどの本も左綴じとして並べます。bookブロックのshowBook(cjkブロックにも同じ関数があります)はdoc.bindingを読み、見開きを左右反転します。capture.heroでは、見開きは引き続き読む順の[偶数ページ, 奇数ページ]、つまり[2, 3]と指定します。 右綴じの本 →
つまずき
文書のタグは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」)。 中国語の改行 →
-
読みは台湾の辞書から取ってください。pypinyinをはじめ、中国本土の辞書をもとにしたツールは、度をduó、寧をnìng、時候をshíhou、市場をshìchǎngとします。台湾の読本が従う教育部の『重編國語辭典修訂本』(Revised Mandarin Chinese Dictionary)は、ㄉㄨㄛˋ、ㄋㄧㄥˊ、ㄕˊ ㄏㄡˋ、ㄕˋ ㄔㄤˊと読み、故事、家裡、過來の2音節目を軽声にします。moedict.twで1語ずつ引けます。この辞書は一と不を本来の声調のまま示しており、この課もそれに従っています。
-
書体を混ぜる前に、それぞれの書体で何字か組んでみてください。LXGW WenKai TCは伝統的な字形に従い、為(U+70BA)を爲の形で描きます。そのため、この書体で組んだ課では同じ見開きの本文に爲宋國笑、明朝体の注に為宋國笑と印刷されてしまいました。Iansuiは標準字体の為を描きます。
-
Iansuiのウェイトは1つだけです。見出しは大きさで、成語の見出し語は色で目立たせます。
idiomスタイルはboldFontWeight: 400とし、アクセント色をboldColorにしているので、**…**は書体ではなく色を変えます。
クレジット
- 本文
- Han Feizi, chapter 49, “Wu du” (The five vermin): the man of Song who waited by the stump · Han Fei; transcription and punctuation by Wikisource editors (爲 set as 為, the Taiwan standard form) · CC BY-SA 4.0
- Han Feizi, chapter 32, “Wai chu shuo zuo shang”: the man of Zheng who went to buy shoes · Han Fei; transcription and punctuation by Wikisource editors · CC BY-SA 4.0
- The zhuyin (checked against the Ministry of Education's Revised Mandarin Chinese Dictionary), the modern Chinese versions, the notes, the author box, the lead and the exercises, written for this recipe · Postext Cookbook · CC BY 4.0
- 画像
- The farmer waiting by the stump, a brush painting · Generated With Diffusion Models · オリジナル
- The man of Zheng hurrying home from the shoe stall, a brush painting · Generated With Diffusion Models · オリジナル
- フォント
- Iansui (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1) · Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1)


