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

レシピ集 · 第3章 · 見出しと章扉

ヴィネットと梗概で始まる童話の章

1つの見出しスタイルがすべての章を開きます。各見出しはヴィネットとイタリックの梗概を属性で指定し、章扉がそれを描きます。

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

6〜7ページ · 1〜2/5

  • 英語の見本:日本語版はまだありません
  • 仕上がり190 × 240 mm
  • 1段
  • Averia Serif Libre 13/19
  • Fredericka the Great
  • Quicksand
  • 5ページ
  • レベル
  • Postext 1.57.1
  • 組版時間59 ms
  • コード162行

かんたんな説明

イタリアの子ども向け『ピノッキオの冒険』の最初の数ページです。各章は専用のやわらかな水彩の画像と、出来事を短くまとめた文で始まります。

できあがり

コッローディ『ピノッキオの冒険』(『Le avventure di Pinocchio』)のイタリアの子ども向け版の冒頭を、190 × 240 mmのページにAveria Serif Libreの13/19 ptで組みます。偶数ページの扉が第1章と向かい合います。扉にはトスカーナの丘の水彩画があり、ロバの荷車が大工の仕事場へ薪を運んでいて、その下にFredericka the Greatで組んだ書名が入ります。各章は紙に溶け込むように薄れていく水彩のヴィネットの下で始まり(第1章はしゃべる丸太の上に斧を振り上げたMaestro Ciliegia、第2章は黄色いかつらをかぶって丸太を受け取るGeppetto)、続いて章の行と、中央にそろえたイタリックのコッローディの梗概が入ります。4枚の画像はすべて、1つのスタイルのプロンプトとページのパレットから拡散モデルで生成しました。柱は章扉のない8ページと9ページにだけ印刷されます。ノンブルは木の色の円の中に置かれ、第1章はキャプションも番号もない2つのサクランボで閉じます。

このレシピが答える質問

  • 章ごとに異なる写真、色、章扉のバリエーションを与えるには?
  • 番号のないアートワーク(オーナメント、カット、ロゴ)を組むには?
  • 章扉に著者名の行、リード文、ドロップキャップ付きの導入文を加えるには?
  • 章扉や白ページで柱を隠したり、空白の偶数ページを部の色で塗ったりするには?

手短な答え

script.js · 44〜64行コード全体で見る
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's
const opener = { enabled: true,
  // A floor for the height the opener reserves, in whole lines, so the text under chapter I's
  // two-line summary starts on the same grid line as the text under chapter II's three lines.
  minHeight: pt(14 * LEAD),
  slot: { elements: [
    { kind: 'image', id: 'vignette', resourceId: '{attr.vignetta}',
      placement: at('container', 'top', 0, 0,
        { width: mm(VIGNETTE.width), height: mm(VIGNETTE.height) }) },
    // The chapter line 6 mm under the picture's foot, the summary 5 mm under the chapter line.
    text('chapter', '{titleText}', DISPLAY, 24, at('container', 'top-left', 0,
      VIGNETTE.height + 6, { width: mm(MEASURE) }), { ...caps(2.4), lineHeight: 1 }),
    text('summary', '{attr.summary}', TEXT, 12.5, at('#chapter', 'below',
      (MEASURE - SUMMARY) / 2, 5, { width: mm(SUMMARY) }), { italic: true, lineHeight: 1.38 }),
  ] },
};
const chapter = { id: 'capitolo', advancedDesign: opener };

材料

種類
Averia Serif Libre, Fredericka the Great, Quicksand (SIL OFL 1.1)
素材
  • ceppo-1200.jpg
  • ciliegie-600.jpg
  • frontespizio-1400.jpg
  • polenta-1200.jpg
  • The frontispiece: Tuscan hills, a hill village and a donkey cart of firewood on its way to the carpenter’s workshop (Generated With Diffusion Models, オリジナル)
  • Chapter I’s vignette: Maestro Ciliegia, axe raised over the talking log (Generated With Diffusion Models, オリジナル)
  • Chapter II’s vignette: Geppetto in his yellow wig receives the log, beside a pot of polenta (Generated With Diffusion Models, オリジナル)
  • The cherry tailpiece (Generated With Diffusion Models, オリジナル)

作り方

#1 · 見出しスタイルは1つ、ヴィネットは見出しごとに指定

この手順のコードは手短な答えにあります。画像要素のresourceIdはデザインテキストと同じプレースホルダーを受け付けます。そのため'{attr.vignetta}'は、{attr.summary}が梗概を印刷するのと同じように、見出しが指定したリソースを描きます。2つの章はcapitoloスタイルを共有し、見出しの行で画像を指定します。# Capitolo II {style="capitolo" vignetta="polenta" summary="…"}です。3つ目の章に必要なのはリソースと見出しを1つずつ追加することで、スタイルを増やす必要はありません(画像要素)。章の行はコンテナーの上端から位置を決め、ヴィネットの箱の6 mm下に置きます。梗概はその5 mm下に続き、章扉は梗概の最終行までの高さを確保します。minHeightを14行の下限として設定すると、第1章の本文は、梗概が1行長い第2章の本文と同じ行から始まります。設定しなければ、第1章の本文は6.7 mm高い位置から始まります(幅と詳細デザイン)。

#2 · 絵をビットマップのリソースとして読み込む

script.js · 122〜133行コード全体で見る
const PICTURES = { // id: [file, width, height, alt text in the book's language]
  frontespizio: ['frontespizio-1400.jpg', 1400, 1105, 'Colline toscane con cipressi e un borgo; '
    + 'un contadino guida un asinello con un carretto di legna verso la bottega di un falegname.'],
  ceppo: ['ceppo-1200.jpg', 1200, 800, 'Maestro Ciliegia, con la scure alzata sopra un pezzo di '
    + 'legno sul banco, si guarda intorno spaventato.'],
  polenta: ['polenta-1200.jpg', 1200, 800, 'Geppetto, con la parrucca gialla, riceve il pezzo di '
    + 'legno da Maestro Ciliegia; accanto, un paiolo di polenta fumante.'],
  ciliegie: ['ciliegie-600.jpg', 600, 626, 'Due ciliegie rosse su un picciolo, con una foglia.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
  id, typeId: 'fregio', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
  bitmap: { fileId, format: 'jpeg', width: w, height: h } }));

各画像はレシピのassets/フォルダーにあるJPEGで、ピクセルサイズを添えて宣言します。レイアウトが読むのはそのサイズだけで、Canvasはページを描くときに、各ファイルidでloadImage()が登録した画像をそのまま描きます。ヴィネットとサクランボは白地で生成し、紙の色#fffaf0を乗算したので、周囲はページと同じ色で印刷され、画像の縁は見えません。口絵はその領域の形である190:150に切り抜いてあるので、合わせ込んだ画像が紙の帯を残さずに領域を埋めます。風景とヴィネットはデザインの中の画像要素が、サクランボはMarkdownの::resource{id="ciliegie"}が描きます。

#3 · 扉を見出しスタイルにする

script.js · 68〜85行コード全体で見る
const SKY = 150; // mm from the top edge: the foot of the painted field
// # Pinocchio {style="frontespizio" kicker="Le avventure di"}; subtitle and author come from
// the frontmatter. Every element hangs from the page, so the field runs off three edges.
const frontispiece = {
  id: 'frontespizio',
  footer: { elements: [] }, // no folio; the running heads already skip openers
  advancedDesign: { enabled: true, slot: { elements: [ // array order is paint order
    { kind: 'image', id: 'landscape', resourceId: 'frontespizio', // cut to the field's 190:150
      placement: at('page', 'top-left', 0, 0, { width: 'fill', height: mm(SKY) }) },
    text('kicker', '{attr.kicker}', LABEL, 11, at('page', 'top', 0, SKY + 11),
      { ...caps(2.6), fontWeight: 700 }),
    text('title', '{titleText}', DISPLAY, 70, at('page', 'top', 0, SKY + 17),
      { lineHeight: 1, color: col('bark') }),
    text('subtitle', '{subtitle}', TEXT, 15, at('page', 'top', 0, SKY + 44), { italic: true }),
    text('author', '{author}', LABEL, 9, at('page', 'top', 0, SKY + 58),
      { ...caps(2), fontWeight: 600 }),
  ] } },
};

扉はMarkdownの最初の見出し# Pinocchio {style="frontespizio" kicker="Le avventure di"}で、そのスタイルがページ上のすべてを描きます。上端から150 mmの深さの風景、続いて属性から取る肩書き、書名、フロントマターから取る副題と著者です。要素はどれも版面ではなくページを基準に置くので、見出し自体はこの本の1段の中にあっても、画像はページの上端と左右の端まで届きます。空のfooterは章扉が印刷するノンブルの円を取り除き、pages: 'body'がすでに柱をこのページから外しています(見出しスタイル)。

#4 · 本文のページに柱、円の中にノンブル

script.js · 89〜110行コード全体で見る
// The excerpt opens on book page 6, a verso, so the title page faces chapter I.
const continuation = { pageIndexOffset: 5, pageNumbering: { startAt: 6 } };
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre sits off the page's centre
const head = (id, content, parity, x) => text(id, content, LABEL, 8,
  at('page', 'top', x, 12), { ...caps(1.8), fontWeight: 600, parity, pages: 'body' });
const DISC = 7.4; // mm: the folio's disc
// A fixed square with a radius of half its side is a circle; the figures sit in its middle.
// lineHeight 1.17: the baseline falls at 0.8 of the line, 0.94 em down, so Quicksand's
// figures (0.70 em tall) leave 0.23 em above and below them, and 'middle' centres that line.
const disc = (id, parity, pages, edge, x) => text(id, '{pageNumber}', LABEL, 8.5,
  at('page', edge, x, -(BOTTOM - DISC) / 2, { width: mm(DISC), height: mm(DISC) }),
  { fontWeight: 700, color: col('paper'), lineHeight: 1.17, verticalAlign: 'middle', parity,
    pages, box: { backgroundColor: col('wood'), borderRadius: mm(DISC / 2) } });
const header = { elements: [
  head('verso-title', '{title}', 'even', -SHIFT), // the book on the left-hand page
  head('recto-chapter', '{chapterTitle}', 'odd', SHIFT), // the chapter on the right
] };
const footer = { elements: [
  disc('verso-folio', 'even', 'body', 'bottom-left', OUTER),
  disc('recto-folio', 'odd', 'body', 'bottom-right', -OUTER),
  disc('opener-folio', 'all', 'opener', 'bottom', 0), // a chapter opens on either side
] };

continuationは抜粋の番号を本の6ページ、つまり偶数ページから始めるので、扉が第1章と向かい合い、最初に印刷されるノンブルは7になります。pages: 'body'は扉と2つの章扉から柱を外すので、柱は8ページと9ページにだけ、偶数ページには書名、奇数ページには章名が印刷されます(テキスト要素)。ノンブルは7.4 mm四方に固定したデザインテキストで、角の半径を辺の半分にして円にしています。verticalAlign: 'middle'と、コメントで算出した行送りによって、数字が円の中央に収まります。紙の色の数字は、木の色に対して4.98:1のコントラスト比です。トラッキングをかけたラベルに位置の補正は要りません。行を中央にそろえるとき、最後の文字のあとのトラッキングは計算に入らないからです。

#5 · 番号のない章末カットで章を閉じる

script.js · 114〜118行コード全体で見る
// No caption prefix and no caption, so the cherries that close chapter I print with no
// label or number. The pictures the design slots paint are of this type too.
const resourceTypes = [{ id: 'fregio', name: 'Fregio', namePlural: 'Fregi', shortLabel: 'Fregio',
  captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
  defaultPlacement: { position: 'here', width: 0.16, align: 'center' } }];

リソースの種類は、キャプションの前にcaptionPrefixと番号を印刷します。接頭辞が空でキャプションもなければ、サクランボの下には何も印刷されません。captionPrefix: 'Fregio'にすると、同じリソースの下に「Fregio 1.」と印刷され、10 mm高くなります(リソースの種類)。この種類のdefaultPlacementは、各リソースを::resourceの行がある位置に、行長の6分の1の幅で中央にそろえて置くので、Markdownには章の最後の段落のあとに::resource{id="ciliegie"}と書くだけで足ります。ほかの画像も同じ種類ですが、:refや::resourceで指定されていないので、配置されることも数えられることもありません。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 066 · Storybook chapters with vignettes and summaries ═══
// https://postext.dev/en/cookbook/storybook-chapter-vignettes
// Code: MIT · Text: C. Collodi, 1883 (PD, Gutenberg #52484) · Pictures: diffusion models
// Fonts: Averia Serif Libre, Fredericka the Great, Quicksand (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document (the sample is Italian in both)
const RECIPE = 'storybook-chapter-vignettes';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config comes from here; the pictures were painted to it
  ink: '#2b2118', // text: a brown near-black
  paper: '#fffaf0', // a warm book paper, which the vignettes' margins were tinted to
  bark: '#6b4224', // chapter lines, running heads, the title
  wood: '#9a5f30', // the folio discs
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
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' } })),
  // The defaults linked to main-color, bold among them, print in bark instead of blue.
  { id: 'main-color', name: 'bark (defaults)', value: { hex: palette.bark, model: 'hex' } },
];
// Text and summaries; the book's title and the chapter lines; running heads and folios.
const [TEXT, DISPLAY, LABEL] = ['Averia Serif Libre', 'Fredericka the Great', 'Quicksand'];
const TRIM = { width: 190, height: 240 }; // mm
const [TOP, INNER, OUTER] = [22, 22, 20]; // mm; mirrored, so the spine margin swaps sides
const MEASURE = TRIM.width - INNER - OUTER; // 148 mm
const [BODY, LEAD, LINES] = [13, 19, 29]; // pt, pt, and whole lines in the text block
const BOTTOM = TRIM.height - TOP - (LINES * LEAD * 25.4) / 72; // mm: 23.6
// Design-slot shorthands: a placement from an anchor's edge (mm), and a design text.
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const text = (id, content, fontFamily, size, placement, extra = {}) => ({ kind: 'text', id,
  content, fontFamily, fontSize: pt(size), color: col('ink'), align: 'center',
  overflow: 'wrap', // a long line wraps in every slot, the running heads too
  placement, ...extra });
const caps = (tracking) => ({ textTransform: 'uppercase', letterSpacing: pt(tracking),
  color: col('bark') });

// #region answer: one opener for every chapter: the vignette the heading names, then its summary
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's

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

アレンジ

#どの章も奇数ページで始める

'odd'にすると、第2章は11ページへ移り、10ページは白ページになります。扉は自分の改ページを無効にします。そうしないと階層の改ページ設定を受け継ぎ、6ページを白ページにして7ページへ移ってしまうからです。

@@ the frontispiece style @@
   id: 'frontespizio',
+  breakBefore: { enabled: false },
@@ headings, in config() @@
-    levels: [{ level: 1, breakBefore: { enabled: true, parity: 'any' } }],
+    levels: [{ level: 1, breakBefore: { enabled: true, parity: 'odd' } }],

よくあるつまずき

つまずき

属性値には{も}も書けない。"を含む値は一重引用符で囲む

属性値は閉じ波かっこで終わるため、{や}を含められません。二重引用符を含む値は一重引用符で囲みます。ドル記号は問題ありません。 見出しの属性 →

  • Markdownでは、ノーブレークスペース(U+00A0)がコッローディの会話のダッシュをそれぞれの語に結びつけているので、閉じのダッシュが行頭に来ることはありません。さらに2か所で、段落末の「di legno」と「in piedi」を分かれないようにしています。太字やイタリックのある段落でも、この結びつきは保たれます。9ページの「ohi」を含む段落がその例で、4か所あります。

クレジット

レシピ
Ignacio Ferro
本文
  • Le avventure di Pinocchio (1883): chapter I and the opening of chapter II with Collodi’s chapter summaries, from the 1902 Bemporad edition, with typographic apostrophes, dashes and ellipses; chapter I’s summary has the comma after “falegname” that the edition’s table of contents prints and its chapter head leaves out · Carlo Collodi · パブリックドメイン
画像
  • The frontispiece: Tuscan hills, a hill village and a donkey cart of firewood on its way to the carpenter’s workshop · Generated With Diffusion Models · オリジナル
  • Chapter I’s vignette: Maestro Ciliegia, axe raised over the talking log · Generated With Diffusion Models · オリジナル
  • Chapter II’s vignette: Geppetto in his yellow wig receives the log, beside a pot of polenta · Generated With Diffusion Models · オリジナル
  • The cherry tailpiece · Generated With Diffusion Models · オリジナル
フォント
Averia Serif Libre (SIL OFL 1.1) · Fredericka the Great (SIL OFL 1.1) · Quicksand (SIL OFL 1.1)
Sandbox