かんたんな説明
小さな子ども向けの、すべてひらがなで書いた絵本です。言葉のまとまりごとにスペースを入れ、まとまりの途中では行を分けません。どのページにも画像が付きます。
できあがり
このレシピのために書き、10枚の画像を添えた10ページの絵本『かみの ふね』です。雨のあと女の子が赤い紙の舟を折り、舟はカエル、サギ、月のそばを過ぎて川を下り、海へ出ます。いちばん幼い読者向けの日本の本と同じ組み方をしています。ひらがなだけを使い、教科書体を手本にした書体Klee Oneの20 ptで組み、文節の間にスペースを入れる分かち書きにして、子どもが一度にひとまとまりずつ読めるようにします。ページは260 × 200 mmの横長で、縦組み、右綴じです。ページの上部に画像を置き、その下に8字の短い行を並べます。ページをめくるにつれて、舟は左へ進みます。
このレシピが答える質問
- 日本語の絵本を文節で分かち書きし、スペースの位置でだけ改行するには?
- 小書きのかな、ー、閉じかっこが行頭に来てはいけないのはなぜですか?規則の厳しさを選ぶには?
- 画面とPDFで、漢字を日本の字形で表示して日本語を組めるフォントは?
手短な答え
// The story is typed with an ordinary space (U+0020) after each phrase (文節). Japanese
// text may break between any two kana, so the space alone does not keep a phrase whole:
// keep-all drops the breaks between two letters and keeps those at a space, after 、。」
// and before 「. Kinsoku still applies.
const phrases = { wordBreak: 'keep-all' }; // cjk.wordBreak
const bodyText = {
fontFamily: HAND, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
// Ragged: a justified line would stretch its spaces and its kana to fill the tier.
textAlign: 'left', firstLineIndent: em(0),
};
材料
- 機能
- 仮名、漢字、ローマ字縦組み日本語の改行(禁則処理)右綴じの本文字グリッド中国語・日本語・韓国語のフォント1段半組みフロート用の余白段独自のリソースの種類ページデザインの画像表紙、扉、奥付見出しスタイル見出しの属性段落スタイル改ページと改段用紙の色セマンティックカラーパレットPDFの書き出しPDFに埋め込むフォント
- 種類
- Klee One, Zen Maru Gothic (SIL OFL 1.1)
- 素材
bridge-1400.jpgcover-1430.jpgdusk-1400.jpgfrog-1400.jpgheron-1400.jpgnight-1400.jpgrain-1400.jpgsea-1400.jpgstream-1400.jpgwindow-1400.jpg- The cover: a red paper boat on a river through green meadows, a clear sky on the right for the title (Generated With Diffusion Models, オリジナル)
- Mii-chan folding the red paper boat at a low table by the window, after the rain (Generated With Diffusion Models, オリジナル)
- Mii-chan waving goodbye to the boat on the stream (Generated With Diffusion Models, オリジナル)
- A frog on a stone talking to the boat (Generated With Diffusion Models, オリジナル)
- The boat under a wooden footbridge, little fish following it (Generated With Diffusion Models, オリジナル)
- A white heron on the bank watching the boat on the wide river (Generated With Diffusion Models, オリジナル)
- Dusk: a pink sky over the river mouth and the sea beyond (Generated With Diffusion Models, オリジナル)
- Night: the full moon's reflection lighting the boat's way (Generated With Diffusion Models, オリジナル)
- The boat at sea, greeted by seagulls (Generated With Diffusion Models, オリジナル)
- Mii-chan at her window, looking towards the distant sea (Generated With Diffusion Models, オリジナル)
作り方
#1 · 文節をまとめて保つ
コードは前の手短な答えにあります。日本語の文はどの2つのかなの間でも改行できるので、文節の間のスペースは間を空けるだけです。それだけでは、あか|いのように行が文節の途中で終わるのを防げません。cjk.wordBreak: 'keep-all'は、CSSのword-break: keep-allと同じく、スペースの位置と約物の隣、つまり、。」のあとと「の前の改行位置だけを残します。禁則処理はそのまま適用されます(東アジアの組版)。スペースはふつうのU+0020で、Klee Oneでは0.35 em、行末に来れば消えます。U+3000も文節の区切りになりますが、こちらは幅1 emの固定の文字で、行末でも残ります。

本文は不ぞろいで組みます。両端そろえにすると、短い行は段の地まで届くように、スペースとかなの間を広げてしまいます。絵本では、各行を最後の文節が終わる位置で止めます。
#2 · 絵を本文の上の段に置く
// In vertical text 'left' is the top of the page: the side column is a tier that takes
// the pictures (floats), and the text runs in the tier under it, right to left.
const layout = {
layoutType: 'oneAndHalf', writingMode: 'vertical-rl', sideColumnRole: 'floats',
sideColumnSide: 'left', sideColumnPercent: 58, gutterWidth: pt(2 * BODY),
};
const cjk = { ...phrases, grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES } };
const resourceTypes = [{ id: 'picture', name: 'え', shortLabel: 'え', numberingTemplate: '{n}',
resetOn: 'never', counterFormat: 'decimal', captionPrefix: '' }]; // pictures, no captions
縦組みでは'left'がページの上にあたるので、サイド段を左に置いた1段半組みは上下2つの段になります。画像は上の段(14字ぶんの深さ)にフロートとして入り、本文は下の段(8字)に流れます。各ページは::resource{id="…"}で自分の画像を引用し、:::pagebreakで終わります。画像のタイプにはキャプションの接頭辞がありません。画像は幅が高さの2.186倍で段と同じ形なので、どの画像も段いっぱいに収まります(縦組み)。
#3 · 表紙をページ全体の絵にする
// In the flow frame of a vertical page x runs down the sheet and y leftward from its right
// edge; a box's width runs down the sheet.
const at = (down, across) => ({ anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(down), y: mm(across) } });
const cover = {
id: 'cover', numbered: false, toc: false, span: 'page', header: { elements: [] },
breakBefore: { enabled: true, parity: 'any' },
advancedDesign: { enabled: true, minHeight: mm(TRIM.w - 40), slot: { elements: [
{ kind: 'image', id: 'art', resourceId: 'cover', decorative: true,
placement: { anchor: { to: 'bleed', edge: 'top-left' },
size: { width: mm(TRIM.h), height: mm(TRIM.w) } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: ROUND, fontWeight: 700,
fontSize: pt(60), lineHeight: 1, letterSpacing: pt(6), color: col('boat'),
placement: at(22, 34) },
{ kind: 'text', id: 'latin', content: '{attr.latin}', fontFamily: ROUND, fontWeight: 700,
fontSize: pt(9), lineHeight: 1.4, color: col('ink'), placement: at(22, 62) },
] } },
};
表紙はページ幅の見出しデザインです。画像はページと同じサイズで塗り足しに固定し(縦の流れでは、そのwidthは紙面を縦に走ります)、題名は右側の空に、Zen Maru Gothicの60 ptで縦に組みます。
#4 · 絵をビットマップとして読み込む
// The scenes have the tier's shape, 612 : 280 (ART); the cover has the page's, 260 : 200.
const PICTURES = { // id: [file, width, height, alt text in the book's language]
cover: ['cover-1430.jpg', 1430, 1100, 'あおい かわに あかい かみの ふねが うかんで いる。'],
rain: ['rain-1400.jpg', 1400, 641, 'まどべの ちゃぶだいで、みいちゃんが あかい かみで ふねを おって いる。'],
stream: ['stream-1400.jpg', 1400, 641, 'みいちゃんが おがわに ふねを ながし、てを ふって いる。'],
frog: ['frog-1400.jpg', 1400, 641, 'かわの いしの うえの かえるが、ながれて いく ふねに はなしかけて いる。'],
bridge: ['bridge-1400.jpg', 1400, 641, 'きの はしの したを ふねが くぐり、ちいさな さかなが ついて くる。'],
heron: ['heron-1400.jpg', 1400, 641, 'ひろい かわの きしで、しろい さぎが ふねを みおくって いる。'],
dusk: ['dusk-1400.jpg', 1400, 641, 'ももいろの ゆうやけの かわに ふねが うかび、とおくに うみが みえる。'],
night: ['night-1400.jpg', 1400, 641, 'まんげつが かわに うつり、ひかりの みちの そばを ふねが すすむ。'],
sea: ['sea-1400.jpg', 1400, 641, 'あおい うみに でた ふねの うえを、かもめが とんで いる。'],
window: ['window-1400.jpg', 1400, 641, 'みいちゃんが まどから、まちの むこうの うみを みて いる。'],
};
const pictures = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
id, typeId: 'picture', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
placement: { span: 'side' }, bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
10枚の画像はレシピのassets/にあるJPEGの絵画です。9つの場面は段の形(612 : 280)に、表紙はページの形(260 : 200)に切ってあるので、どれも枠いっぱいに収まり、何も切り落とされません。それぞれをbitmapリソースとしてピクセル寸法で宣言し、本の言語で代替テキストを付け、組版の前にリソースのfileIdでファイルを読み込みます。幅1,400 pxの場面は、段の幅でおよそ165 dpiで印刷されます(リソースの種類)。
レシピの全体
// ═══ Postext Cookbook · Nº 127 · A hiragana picture book, spaced by phrase ══════════
// https://postext.dev/en/cookbook/hiragana-picture-book
// Code: MIT · Story: written for the recipe (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Klee One, Zen Maru Gothic (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A picture book for small readers: hiragana only, a space between phrases, vertical.
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 frame; the story is Japanese in both editions
const RECIPE = 'hiragana-picture-book';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: the paper boat's red, river blues, a warm paper
const palette = {
ink: '#2e2a26', // the text: a soft near-black
boat: '#cf4430', // the boat, the title (4.6:1 on the paper)
river: '#5d93ad',
grass: '#86b665',
muted: '#6e675f', // the colophon
paper: '#fbf6ea',
};
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: 'boat (defaults)', value: { hex: palette.boat, model: 'hex' } },
];
// #endregion
const HAND = 'Klee One'; // 教科書体: the hand a child learns to write kana from
const ROUND = 'Zen Maru Gothic'; // the cover's title
const [BODY, LEAD] = [20, 36]; // pt: large kana, a line gap of 0.8 em
const PT = 25.4 / 72; // mm in a point
const TRIM = { w: 260, h: 200 }; // mm: a landscape picture book (横長)
const [CHARS, PICTURE, LINES] = [8, 14, 17]; // characters: text tier, picture tier; lines
const ART = { w: LINES * LEAD * PT, h: PICTURE * BODY * PT }; // mm: 215.9 × 98.8
// #region answer: わかち書き — a space between phrases, and lines that break only there
// The story is typed with an ordinary space (U+0020) after each phrase (文節). Japanese
// text may break between any two kana, so the space alone does not keep a phrase whole:
// keep-all drops the breaks between two letters and keeps those at a space, after 、。」
// and before 「. Kinsoku still applies.
const phrases = { wordBreak: 'keep-all' }; // cjk.wordBreak
const bodyText = {
fontFamily: HAND, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
// Ragged: a justified line would stretch its spaces and its kana to fill the tier.
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#行を両端そろえにする
両端そろえにすると、どの行も段の地まで届きます。まず文節の間のスペースが0.5 emまで広がり、次にかなの間が広がります(JLReq §3.8)。20 ptのかなの短い行では間が大きく空くので、このレシピは行を不ぞろいのままにしています。
- textAlign: 'left', firstLineIndent: em(0),
+ textAlign: 'justify', firstLineIndent: em(0),よくあるつまずき
つまずき
日本語のテキストのタグは'ja'。zh-HansやLANGにしない
レシピの版はenとesですが、日本語のサンプルはどちらの版でも日本語です。`locale: LANG`では英語やスペイン語とタグ付けされ、中国語のタグでは中国語の規則で組まれます(開明式の約物、小書きの仮名が行頭に来てもよい、図の代わりに图、PDFでは中国の字形)。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、'ja'以外のタグでは日本語の字形ではなく別の字形(中国語のタグでは中国の字形)になり、改行の位置も変わります。'ja'と書いてください。日本の地域(JLReqの改行と約物、ゴマの圏点、ルビの間隔、図と表の表示名)が選ばれ、ハイフネーションが切られます。リントは、zhやkoのタグで仮名を含むテキストをエラーにします。 日本語の改行(禁則処理) →
つまずき
日本語は日本語の書体で組む
Noto Serif SCとTCは仮名を持っていますが、漢字は中国の字形(直、骨、角が異なります)で、仮名も中国のデザインで描きます。本文はNoto Serif JPかShippori Mincho B1、見出しはNoto Sans JPで組み、loadCjkFontsで読み込んでください。Fontsourceの日本語ファイルには変体仮名などの古い仮名(U+1B000–1B16F)がないため、loadCjkFontsはそこで失敗し、PDFには四角が印字されます。現代の仮名で書くか、それを持つ書体をレシピのassetsに同梱してください。Shippori Minchoにはマクロン付きの母音ōとūもないので、ローマ字はラテン文字の書体で組んでください。 仮名、漢字、ローマ字 →
つまずき
中国語の書体はcjkブロックを通じてスライス単位で読み込む
Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →
keep-allは、本文にすでにある改行位置を残すだけです。Postextは文節を見つけないので、スペースは書き手が入力します。行より長い文節は、禁則処理が許す最後の位置で途中から折り返されます。- 中国語は単語の間を空けません。中国語の入門書注音を右に添えた縦組みの国語読本は、代わりに読みを示して幼い読者を助けます。日本語の絵本は漢字を使わないので振り仮名は要らず、文節の間のスペースが読みを助けます。
クレジット
- 本文
- かみの ふね (The Paper Boat), a picture-book story in hiragana written for this recipe · Postext Cookbook · CC BY 4.0
- 画像
- The cover: a red paper boat on a river through green meadows, a clear sky on the right for the title · Generated With Diffusion Models · オリジナル
- Mii-chan folding the red paper boat at a low table by the window, after the rain · Generated With Diffusion Models · オリジナル
- Mii-chan waving goodbye to the boat on the stream · Generated With Diffusion Models · オリジナル
- A frog on a stone talking to the boat · Generated With Diffusion Models · オリジナル
- The boat under a wooden footbridge, little fish following it · Generated With Diffusion Models · オリジナル
- A white heron on the bank watching the boat on the wide river · Generated With Diffusion Models · オリジナル
- Dusk: a pink sky over the river mouth and the sea beyond · Generated With Diffusion Models · オリジナル
- Night: the full moon's reflection lighting the boat's way · Generated With Diffusion Models · オリジナル
- The boat at sea, greeted by seagulls · Generated With Diffusion Models · オリジナル
- Mii-chan at her window, looking towards the distant sea · Generated With Diffusion Models · オリジナル
- フォント
- Klee One (SIL OFL 1.1) · Zen Maru Gothic (SIL OFL 1.1)


