かんたんな説明
香港の子ども向け入門読本のページです。すべての漢字の上に発音をラテン文字で印刷する方法と、書き取り練習用のマス目の作り方がわかります。
できあがり
『蒙學誦讀』という架空の香港の入門読本の見開き2つです。香港の子どもたちは『三字経』を普通話で音読します。各ページは1課で、対句4つを一号(26 pt)の楷書体で組み、すべての漢字の上にピンインの音節を載せます。音節はAndikaで組みます。中国の教科書が印刷する1階建てのaとgを描く書体だからです。淡い帯には赤い課のバッジ、小さな水彩画、初号(42 pt)のタイトルが載り、タイトルにも読みが付きます。本文の下には書き写す漢字を入れた6つの書き取りのマス目(田字格)があり、注記がその句の意味を家庭に説明します。スペイン語で対になるのは音節チップを使う入門読本で、そちらでは音節ごとに、漢字の上の読みではなく色付きのチップを使います。
入門読本は、あえて中国の本の決まりから外れます。子どもは大きな字を少しずつ読むので、1行は26 ptで12字です。本なら10.5 ptで25〜40字を組みます。行送りは、読みを収めるために文字サイズの2倍を少し超えます。対句はそれぞれ独立した行に中央そろえで置き、両端そろえも字下げもしません。本文は筆の運びに沿う楷書体で組みます。子どもが書けるようになる筆画が見えるからです。本なら宋体で組むところです。
このレシピが答える質問
- 漢字の上にピンインを付けるには?
手短な答え
// {人之初|rén zhī chū} gives each character its own syllable (mono ruby): three readings for
// three characters, split on the spaces. The reading sits in the line gap, centred on its
// character; a syllable wider than the character widens that character's box by what the
// reading needs, less the quarter of the reading's size it may lend a neighbour.
const cjk = {
// The type area in characters: 12 per line, 11 lines of 54 pt. The margins grow to centre it.
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 11 },
ruby: {
fontFamily: PINYIN, // one-storey a and g, as a Chinese primer prints them
// 9.9 pt over the text, 16 pt over the title: the widest syllables (xiāng, zhuān) still fit
// over one character, so every couplet is 8 em long and keeps to the grid.
fontSize: em(0.38),
color: col('pinyin'),
},
};
// The line pitch never changes for a reading: the gap between lines (54 − 26 = 28 pt) must
// hold it, or the build warns rubyExceedsLeading.
const text = {
fontFamily: KAI, fontSize: pt(TEXT), lineHeight: pt(LINE),
textAlign: 'center', firstLineIndent: pt(0), // one couplet to a line, centred
};
材料
- 機能
- ルビ:ピンインと注音中国語・日本語・韓国語のフォント文字グリッド中国語の約物の幅本文の書体デザインした章扉見出しの属性ページデザインの画像ページデザインのテキスト・罫・ボックス囲みセマンティックカラーパレット柱とノンブル
- 種類
- LXGW WenKai TC, Noto Sans TC, Andika (SIL OFL 1.1)
- 素材
brush-800.jpgjade-800.jpgshuttle-800.jpgsprout-800.jpg- The writing squares, drawn in code in the page’s palette (Postext Cookbook, CC BY 4.0)
- Lesson 1’s vignette: a seedling, a watercolour (Generated With Diffusion Models, オリジナル)
- Lesson 2’s vignette: the shuttle of a loom, a watercolour (Generated With Diffusion Models, オリジナル)
- Lesson 3’s vignette: a brush and its first stroke, a watercolour (Generated With Diffusion Models, オリジナル)
- Lesson 4’s vignette: a jade disc on a red cord, a watercolour (Generated With Diffusion Models, オリジナル)
作り方
#1 · 漢字1字ごとに音節を1つ
コードは上の手短な答えにあります。{人之初|rén zhī chū}は3字に3つの読みを与え、スペースで区切ります。各音節は自分の漢字の上の中央に置かれ、音節の間では改行できます。読みは自分の場所を取りません。行間に収まり、ここでは54 − 26 = 28 ptです。読みより狭い行間はrubyExceedsLeadingとして報告されます。漢字より幅の広い音節は場所を取ります。その漢字のボックスを広げ、中央そろえの行では後に続く漢字がグリッドからずれます。読みは、ここでいちばん幅の広い音節であるxiāngとzhuānがまだ1字の上に収まる大きさ、0.38 em(9.9 pt)で組んでいます。これで対句はどれも8字分の長さになり、各字が自分のマスを保ちます。0.45 emでは、性相近,習相遠が8字半に伸び、相の前後に隙間が空きます。
#2 · タイトルも読みを保つ
const BAND = 68; // mm from the top edge
// Heading designs ignore parity: a place for the drawing on each side, 14 mm from the outer
// edge, named {left="…"} on a verso and {right="…"} on a recto. A missing attribute draws nothing.
const picture = (side, x) => ({ kind: 'image', id: `picture-${side}`,
resourceId: `{attr.${side}}`, decorative: true, reserve: false,
placement: { anchor: { to: 'page', edge: `top-${side}` }, offset: { x: mm(x), y: mm(14) },
size: { width: mm(42), height: mm(42) } } });
const opener = { enabled: true, slot: { elements: [
{ kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
placement: { anchor: { to: 'page', edge: 'top-left' },
size: { width: mm(184), height: mm(BAND) } } },
picture('left', 14), picture('right', -14),
{ kind: 'text', id: 'lesson', content: '{titleText}', fontFamily: HEI, fontSize: pt(11),
fontWeight: 700, letterSpacing: pt(2), color: col('paper'), align: 'center', overflow: 'wrap',
placement: { anchor: { to: 'container', edge: 'top' } },
box: { backgroundColor: col('red'), borderRadius: mm(3.5),
padding: { top: mm(1.2), right: mm(3.6), bottom: mm(1.2), left: mm(3.6) } } },
] } };
デザインテキストは読みを印刷しないので、タイトルを章扉のデザインから出すことはできません。レベル1見出しの第一課が帯、画像、赤いバッジを描き、タイトルはその下のレベル2見出しです。これは初号の普通の見出しで、本文の組版処理がピンイン付きで組みます。reserve: falseは帯と画像を見出しの高さから外し、span: 'page'はそれらを本文の下に塗ります。
見出しのデザインはparityを無視するので、画像にはページの左右それぞれに要素を用意します。左端から14 mmの{attr.left}と、右端から14 mmの{attr.right}です。偶数ページの課は# 第一課 {left="sprout"}、奇数ページの課は{right="shuttle"}と書くので、どの画像も見開きの外側に来ます。属性のない側の要素は何も描きません。
#3 · 1つの属性から6つのマス目
// Design text prints no readings, so the squares hold the characters alone. A Han character
// is one em wide, so tracking of (pitch − em) sets one in the middle of each square.
const [SQ, GAP, WRITE] = [15, 3.4, 30]; // mm, mm, pt
const ROW = 6 * SQ + 5 * GAP; // mm
const X0 = (MEASURE - ROW) / 2; // the row is centred on the measure
const EM = WRITE * 25.4 / 72; // mm: one character at 30 pt, 10.6 mm wide
const squares = { enabled: true, slot: { elements: [
{ kind: 'text', id: 'label', content: '{titleText}', fontFamily: HEI, fontSize: pt(10),
fontWeight: 700, letterSpacing: pt(1.5), color: col('red'), align: 'left', overflow: 'wrap',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { x: mm(X0) } } },
...Array.from({ length: 6 }, (_, k) => ({ kind: 'image', id: `square${k}`, resourceId: 'tian',
decorative: true, placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(X0 + k * (SQ + GAP)), y: mm(7) },
size: { width: mm(SQ), height: mm(SQ) } } })),
{ kind: 'text', id: 'chars', content: '{attr.write}', fontFamily: KAI, fontSize: pt(WRITE),
lineHeight: 1, letterSpacing: mm(SQ + GAP - EM), color: col('ink'), align: 'left',
verticalAlign: 'middle', overflow: 'clip',
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(X0 + (SQ - EM) / 2), y: mm(7) },
size: { width: mm(ROW + GAP), height: mm(SQ) } } },
] } };
### 我會寫 {write="人之本不相以"}は、デザインに6つの漢字を1つの属性で渡します。LXGW WenKai TCの漢字はどれも1 em幅なので、トラッキングをマス目のピッチから1 emを引いた値(18.4 − 10.6 mm)にすると、漢字がマスからマスへ進み、1つのテキスト要素で1列が埋まります。マス目はコードで描いたSVGで、赤い枠と破線の十字です。
#4 · 書体ごとに自分の文字を読み込む
// Fontsource cuts a Chinese face into about a hundred files by character range
// (gotcha: cjk-fonts-slices). The Kai sets the whole sample; the Hei only the headings'
// labels and the footer's series line, so it fetches a few files.
const labels = (markdown.match(/^#{1,3} [^{\n]*/gm) ?? []).join('') + '蒙學誦讀 第一冊';
await loadFonts(FONTS, markdown); // the latin files, and Andika's latin-ext for ǎ ǐ ǒ ǔ
await Promise.all([loadCjkFonts({ [KAI]: FONTS[KAI] }, markdown),
loadCjkFonts({ [HEI]: FONTS[HEI] }, labels),
loadSvg('tian.svg', tian), ...VIGNETTES.map((fileId) => loadImage(fileId, asset(fileId)))]);
Fontsourceは中国語の書体を、文字の範囲ごとに約100のファイルに分けています。楷書体は見本全体を組むので、その文字を含むファイルを読み込みます。黒体はバッジ、ラベル、フッターだけを組むので、そのテキストを渡され、数ファイルだけを取得します。AndikaはloadFontsから読み込みます。この関数は、テキストにǎやǐのようなLatin-1の範囲を超える文字があると、latin-extのファイルを加えます。
#5 · ロケールで香港の約物にする
// Punctuation at full width, where LXGW WenKai TC centres it as Hong Kong and Taiwan print
// it, and the basic line-breaking rules. Written out, never LANG (gotcha: cjk-locale-tag).
locale: 'zh-HK',
zh-HKは香港の規則を設定します。約物は全角、改行規則は基本のもので、ここの対句はどれも改行規則を必要としません。LXGW WenKai TCは、香港や台湾の印刷と同じく、読点と句点をマスの中央に描きます。この入門読本を香港のものにしたのはそのためです。中国大陸の入門読本も楷書体で組みますが、文字は簡体字で、読点と句点はマスの左下に置きます。しかしFontsourceには簡体字中国語の楷書体の本文用書体がなく、繁体字用の書体ではそれらの約物が次の字に詰まってしまうので、このレシピ集の大陸向けのページは、大陸の小説のページの宋体であるNoto Serif SCを使います。
レシピの全体
// ═══ Postext Cookbook · Nº 076 · A pinyin primer: readings over every character ═══
// https://postext.dev/en/cookbook/pinyin-primer
// Code: MIT · Text: 三字經 (PD); pinyin, notes: CC BY 4.0 · Vignettes: diffusion models
// Fonts: LXGW WenKai TC, Noto Sans TC, Andika (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'pinyin-primer';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a primer's colours, every one linked by id
const palette = {
ink: '#29241f', // the characters: a warm near-black
pinyin: '#355a4d', // the readings, a shade off the ink so the two layers part
red: '#bf3a2b', // lesson badges and the writing squares
jade: '#2f7a5e', // the folio discs
tint: '#edf4ea', // the band behind each lesson's title
cream: '#faf3e4', // the note for families
muted: '#6d665e', // series line, colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the red.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.red })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [KAI, HEI, PINYIN] = ['LXGW WenKai TC', 'Noto Sans TC', 'Andika'];
const TEXT = 26; // pt: 一号, the size of a first reader's text
const LINE = 54; // pt: 2.1 × the size, so a reading fits between two lines
const CHARS = 12; // characters per line: the measure is 12 × 26 pt = 110 mm
const MEASURE = CHARS * TEXT * 25.4 / 72; // mm
// #region answer: one reading per character, in Andika, in a line gap wide enough to hold it
// {人之初|rén zhī chū} gives each character its own syllable (mono ruby): three readings for
// three characters, split on the spaces. The reading sits in the line gap, centred on its
// character; a syllable wider than the character widens that character's box by what the
// reading needs, less the quarter of the reading's size it may lend a neighbour.
const cjk = {
// The type area in characters: 12 per line, 11 lines of 54 pt. The margins grow to centre it.
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 11 },
ruby: {
fontFamily: PINYIN, // one-storey a and g, as a Chinese primer prints them
// 9.9 pt over the text, 16 pt over the title: the widest syllables (xiāng, zhuān) still fit
// over one character, so every couplet is 8 em long and keeps to the grid.
fontSize: em(0.38),
color: col('pinyin'),
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#組んでいる間はグリッドを表示する
show: trueは各行の12個のマスをcanvasに描きます。PDFでは、renderToPdfにcharacterGrid: trueを渡さない限り描かれません。
- grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 11 },
+ grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 11, show: true },#注音を漢字の横に置く
注音符号の読みは各漢字の右に縦に並びます。注音付きの読本は、それを縦組みのページに組んでいます。
よくあるつまずき
つまずき
ルビは本文に出て、デザイン、キャプション、セルには出ない
ルビは段落、見出し、リスト項目、引用、囲みで描かれます。デザインのテキスト要素(章扉、柱、バッジ)、キャプション、脚注、表のセルでは、ルビなしで親文字だけが印字されます。ピンインが必要なタイトルは、独自のデザインを持たない見出しにしてください。その周り(帯や課の番号)は直前の見出しのデザインで描きます。reserve: falseの要素は、span: 'page'の章扉の本文の下に描かれます。 ルビ:ピンインと注音 →
つまずき
各地域の約物はその地域の書体で組む
約物の幅の処理は、各記号の横の空きを、フォントが描く側ではなく、文書の地域が置く側に移します。zh-Hansでは開明式の読点は箱の左半分を残し(簡体字の書体はそこにグリフを描きます)、右半分を手放します。繁体字の書体は,。を箱の中央に描くため、手放す半分にグリフの一部があり、読点が次の文字に食い込みます。Fontsourceで唯一の楷書の本文書体であるLXGW WenKai TCは、簡体字のテキストでこうなります。本土のテキスト、注、引用はNoto Serif SCかNoto Sans SCで組み、TCの書体はzh-Hantに取っておき、簡体字の毛筆書体(Ma Shan Zheng)は表示用の行だけに使ってください。デザインのテキストには約物の幅の処理がかからないためです。LXGW WenKai TCは、本土の規格も台湾の規格も使わない伝承字形も描きます。爲の爫の頭を持つ為や、卩の足を持つ令(冷、領の中も)です。この書体で組むページの文字を確認してください。 中国語の約物の幅 →
つまずき
中国語の書体は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」)。 中国語の改行 →
レイアウト警告 · rubyExceedsLeading
ルビが次の行に接触
原因. 本文の上または下にルビを付けた段落で、行間がルビより狭くなっています。ルビは行間に置かれるため、隣の行に接してしまいます。
対処. 段落の行送りを大きくする(少なくとも文字サイズに`cjk.ruby.fontSize`を加えた値)か、ルビを小さくしてください。 ドキュメント →
-
このレシピにはPDFがありません。キットの
fontsourceProviderは書体のlatinファイルしか埋め込まず、声調付きの文字ā ǎ ǐ ǒ ǔはlatin-extにあるので、PDFではそれらが失われ、postext-pdfがそれぞれをmissingGlyphとして報告します。PDFが必要なら、読みを中国語の書体で組んでください。中国語の書体のファイルは、cjkPdfProviderが1字ずつ選びます。 -
マス目の各字が、その地域の標準字形かどうかを確かめてください。LXGW WenKai TCは為を爲の爫の形の上部で描きます。古い字形で、ここの老何為や為人子のように本文中なら通りますが、香港の子どもが書き写すマス目には向きません。第3課では代わりに幼を練習します。
クレジット
- 本文
- The Three Character Classic (三字經), lines 1–32: the text of the Harvard-Yenching Library’s 新刊三字經 as transcribed on zh.wikisource (revision 10344699), with today’s punctuation and 隣 written 鄰 · Traditionally attributed to Wang Yinglin (13th century); transcription by Wikisource editors · パブリックドメイン
- The pinyin, the notes for families and the translations · Postext Cookbook · CC BY 4.0
- 画像
- The writing squares, drawn in code in the page’s palette · Postext Cookbook · CC BY 4.0
- Lesson 1’s vignette: a seedling, a watercolour · Generated With Diffusion Models · オリジナル
- Lesson 2’s vignette: the shuttle of a loom, a watercolour · Generated With Diffusion Models · オリジナル
- Lesson 3’s vignette: a brush and its first stroke, a watercolour · Generated With Diffusion Models · オリジナル
- Lesson 4’s vignette: a jade disc on a red cord, a watercolour · Generated With Diffusion Models · オリジナル
- フォント
- LXGW WenKai TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · Andika (SIL OFL 1.1)


