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

レシピ集 · 第7章 · 図と画像

図版と向かい合う作品解説の図録

各解説は偶数ページで始まり、本文の最初の文で図版を引用します。図版は向かいの奇数ページへフロートし、スキャンの縦横比のまま版面いっぱいまで縮小して入ります。

このページの内容

4〜5ページ(全8ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり230 × 280 mm
  • 1段半組み, 段間7 mm
  • Ibarra Real Nova 11.5/16
  • Libre Bodoni
  • Sofia Sans Condensed
  • 8ページ
  • レベル
  • Postext 1.57.1
  • 組版時間56 ms
  • コード246行

かんたんな説明

『ドン・キホーテ』の古い挿絵3点を扱う小さな展覧会図録です。作品の解説は左ページに入り、その画像が向かいの右ページいっぱいに載ります。

できあがり

ギュスターヴ・ドレの『ドン・キホーテ』(パリ、1863年)から木口木版3点を選んだ小企画展の図録を、230 × 280 mmのページで作ります。表紙は温かみのある黒地に、枠で囲んだ風車の版画の部分図を置き、その下にDORÉを88 ptのLibre Bodoniで組みます。各解説は左ページで始まり、イタリックの題の横にセピアのカタログ番号、外側の段に作品データ(トゥームストーン)、3行のドロップキャップで始まるリード、そして解説本文が続きます。本文の最初の文が図版を引用し、図版は向かいの右ページの先頭に中央そろえで入り、図版とキャプションとクレジット行で版面が埋まるまで縮小されて、高さは215 mmになります。最後のページは出品リストで、各行の最初のセルにサムネイルがあり、各図版が印刷されるページを示します。

このレシピが答える質問

  • 図録を作るには(左ページに解説、向かいの右ページに図版)?
  • 図の位置を制御するには(ページの上端、2段をまたぐ、まさにこの位置、余白)?
  • 表のセルに画像やアイコンを入れるには?
  • 章扉に著者名の行、リード文、ドロップキャップ付きの導入文を加えるには?

手短な答え

script.js · 38〜60行コード全体で見る
// Each entry breaks to a verso and cites its plate in the commentary's first sentence; a 'top'
// float never lands on its citing page (gotcha: top-float-next-page), so it opens the recto.
const entryLevel = () => ({
  level: 1, span: 'page', numberingTemplate: '{1}', // {number} in the opener: Cat. 1, 2, 3
  breakBefore: { enabled: true, parity: 'even' }, // an entry opens a verso, facing its plate
  marginBottom: pt(LEAD), advancedDesign: entryOpener(),
  dropCap: { lines: 3, fontFamily: DISPLAY, color: col('sepia'), gap: mm(1.6) }, // the lead's
});
const plateType = {
  id: 'plate', name: 'Cat.', shortLabel: 'Cat.', captionPrefix: 'Cat.', // 'Cat. 1. …'
  numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
  // A plate taller than the recto's text block is scaled, proportions kept, until plate, caption
  // and credit line fit it; the caption takes the plate's width, and both are centred.
  defaultPlacement: { position: 'top', span: 'page', align: 'center',
    shrink: 'page', minScale: 0.5, captionMeasure: 'body' },
};
// Under the plate (pt): a caption and a credit line, and their gaps.
const CAPTION = { size: 8.5, gap: 6, note: 7.2, noteGap: 1.5 };
const plate = ({ id, file, caption, altText }, [pxW, pxH]) => ({
  id, typeId: 'plate', kind: 'bitmap', caption, note: CREDIT, altText,
  // The print master's pixels, about 283 dpi at this size (gotcha: bitmap-print-size).
  bitmap: { fileId: file, format: 'jpeg', width: pxW, height: pxH }, createdAt: 0, updatedAt: 0,
});

材料

種類
Ibarra Real Nova, Libre Bodoni, Sofia Sans Condensed (SIL OFL 1.1)
素材
  • library-835.jpg
  • vigil-835.jpg
  • windmills-835.jpg
  • windmills-detail-540.jpg
  • Cat. 1, Don Quixote in His Library (Part I, ch. I), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, パブリックドメイン)
  • Cat. 2, The Vigil of Arms (Part I, ch. III), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, パブリックドメイン)
  • Cat. 3, The Adventure of the Windmills (Part I, ch. VIII), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, パブリックドメイン)
  • The cover’s detail of Cat. 3: a 1,100-px square cut from the same scan and reduced to 540 px (Gustave Doré · Héliodore Pisan, パブリックドメイン)

作り方

#1 · 図版は向かいのページを待つ

コードは上の手短な答えにあります。どの解説も偶数ページへ改ページし、topフロートは自分を引用したページには置かれません。そのため解説の最初の文で引用された図版は偶数ページを飛ばし、向かいの奇数ページの先頭に入ります。図版の種類のdefaultPlacementはshrink: 'page'を指定しています。版面の幅いっぱいでは図版の高さが242 mmになり、右ページの版面に収まらないので、Postextは縦横比を保ったまま、図版とキャプションとクレジット行がフロートのアキの上に残る帯に収まるまで縮小します(配置)。minScale: 0.5なら幅の半分まで縮められますが、ここではどの図版も幅の約9割を保ちます。captionMeasure: 'body'でキャプションとクレジット行を図版の幅で組み、align: 'center'で両方をページの中央にそろえます。

#2 · 解説の頭部は見出しから作る

script.js · 81〜113行コード全体で見る
const [KICKER, NUMERAL] = [8.5, { size: 80, y: 7 }]; // pt: labels; the numeral, y in mm
const TITLE = { size: 30, lineHeight: 1.08 }; // pt; a multiple of the size
const HEAD_RULE = NUMERAL.y + NUMERAL.size * PT + 3; // mm: the hairline under the numeral
// mm: the lead, the entry's first paragraph, 5 mm under the hairline on the next grid line;
// the opener ends a line above it (the level's marginBottom), and the tombstone faces it.
const LEAD_Y = Math.ceil((HEAD_RULE + 5) / PT / LEAD) * LEAD * PT;
const [LEADIN, TOMB] = [{ size: 13.5, lead: 19 }, { size: 8.5, lead: 12.5 }]; // pt
const BASE = 0.8; // a line's first baseline stands 0.8 down its line box
// em: Libre Bodoni's capitals, and its figures, which stop short of them ('1': 0.716)
const [CAP_HEIGHT, FIGURE_HEIGHT] = [0.754, 0.716];
const inkTop = (size, lineHeight, height) => (BASE * lineHeight - height) * size; // pt to the ink
// The title's capitals level with the numeral's figures: 1.2 mm below the numeral's top.
const TITLE_Y = NUMERAL.y + (inkTop(NUMERAL.size, 1, FIGURE_HEIGHT)
  - inkTop(TITLE.size, TITLE.lineHeight, CAP_HEIGHT)) * PT;
// Entries open on versos, whose outer column is on the left: the side column is at x = 0.
const head = (label, numeral) => [
  text('label', label, LABEL, KICKER, 'sepia', at('container', 'top-left', 0, 0), caps(KICKER)),
  text('numeral', numeral, DISPLAY, NUMERAL.size, 'sepia',
    at('container', 'top-left', 0, NUMERAL.y, SIDE), { lineHeight: 1 }),
  text('title', '{titleText}', DISPLAY, TITLE.size, 'ink', at('container', 'top-left', MAIN_X,
    TITLE_Y, MAIN), { italic: true, lineHeight: TITLE.lineHeight }),
  { kind: 'rule', id: 'head-rule', direction: 'horizontal', thickness: pt(0.5), color: col('rule'),
    placement: at('container', 'top-left', 0, HEAD_RULE, 'fill') },
];
const entryOpener = () => ({ enabled: true, minHeight: mm(LEAD_Y - LEAD * PT),
  slot: { elements: [...head('Cat.', '{number}'),
  text('chapter', '{attr.chapter}', LABEL, KICKER, 'sepia',
    at('container', 'top-left', MAIN_X, 0, MAIN), caps(KICKER)),
  // Baseline on the lead's; the attribute's \n breaks give its three lines.
  text('tombstone', '{attr.tombstone}', LABEL, TOMB.size, 'muted',
    at('container', 'top-left', 0, LEAD_Y + BASE * (LEADIN.lead - TOMB.lead) * PT, SIDE - 6),
    { lineHeight: TOMB.lead / TOMB.size, reserve: false }), // beside the lead: no room of its own
] } });

各#見出しは章と作品データを属性として持ち、扉のデザインスロットがそれらを描きます。大きな番号は、numberingTemplate: '{1}'による見出し自身の{number}です。1つの解説に図版は1点なので、図版のCat.カウンターと歩調をそろえて1、2、3と進みます。リードは解説の最初の段落で、13.5 ptの:::paragraphs{style="lead"}のグループに入っています。レベルのdropCapがこれをセピア色の3行分の頭文字で始め、頭文字の上端は1行目の大文字の高さにそろい、下端は3本目のベースラインに乗ります。どちらのキャップハイトも書体から測ります(ドロップキャップ)。リードは左そろえ(行末不ぞろい)で組みます。この大きさで両端そろえにすると、1行に入る語が少ないため、語間が解説本文で許す1.5倍を超えて開きました。minHeightは、リードが始まるグリッド線LEAD_Yの1行上で扉を終えます。作品データは自分の場所を取らずにリードの1行目と向かい合い(reserve: false)、リードの下の:::spaceによって、解説本文は1行下から字下げなしで始まります。TITLE_Yは題を数字より1.2 mm下げて組み、題の大文字の高さを数字にそろえます。Libre Bodoniでは数字の高さが0.716 em、大文字が0.754 emです。

#3 · 原版を宣言し、小さな複製を描く

script.js · 316〜333行コード全体で見る
// plate() sizes each plate from its master, the Commons scan at 2,400 px tall (MASTER_PX);
// the canvas draws the registered 835-px copy (the block's width on a 1,000-px page) in that box.
async function scan(file) {
  const res = await fetch(asset(file));
  if (!res.ok) throw new Error(`Scan not found (${res.status}): ${file}`);
  return createImageBitmap(await res.blob());
}
async function loadPlates() {
  const [detail, ...scans] = await Promise.all([DETAIL, ...PLATES.map((p) => p.file)].map(scan));
  const resources = [checklist(PLATES), picture('cover-detail', onPaper(detail),
    'Detail of Cat. 3: the knight and his horse caught on the sail.')];
  for (const [i, p] of PLATES.entries()) {
    registerResourceImage(p.file, onPaper(scans[i]));
    resources.push(plate(p, MASTER_PX[p.id]), // and a thumbnail: its own small file and size
      picture(`${p.id}-thumb`, onPaper(await resized(scans[i], THUMB_PX)), p.altText));
  }
  return resources;
}

Postextはビットマップの大きさを、宣言されたピクセル数と文書のdpiから決め、そのピクセル数が許す幅を超えて印刷することはありません。plate()は各図版の原版として、Commonsのスキャンを高さ2,400 pxに縮めたものを宣言します。Cat. 1は1,900 × 2,400 pxで、page.dpi: 150なら322 mmまで広げられます。したがって大きさを決めるのは版面で、高さは215 mm、その高さでは2,400 pxが約283 dpiに相当します。既定の300 dpiだと図版は幅161 mmで止まってしまいます。Canvasはその枠に登録されている画像をそのまま描くので、CodePenのサンプルはassets/にある835 pxの複製3点を取得します。原版の5.8 MBに対して0.97 MBです。2,400 pxの原版から描くと空にモアレの縞が出て、キャプチャー画像が約0.3 MB増え、レシピ集の上限1.4 MBを超えます。

#4 · 見出しのスタイルで作る表紙

script.js · 117〜141行コード全体で見る
const DETAIL = 'windmills-detail-540.jpg'; // a square cut from Cat. 3, at its size on screen
const FRAME = { w: 124, y: 40, pad: 3.5 }; // mm: the picture, its top, the hairline's inset
const FRAME_X = (TRIM.w - FRAME.w) / 2;
const NAME = { size: 88, track: 8, y: 176 }; // pt, pt, mm
const centred = (id, content, family, size, color, y, more) => text(id, content, family,
  size, color, at('page', 'top', 0, y, 'fill'), { align: 'center', ...more });
const coverStyle = () => ({
  id: 'cover', numbered: false, header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [ // painted in this order
    { kind: 'box', id: 'night', style: { backgroundColor: col('night') },
      placement: { ...at('bleed', 'top-left', 0, 0), size: { width: 'fill', height: 'fill' } } },
    { kind: 'box', id: 'frame', style: { borderColor: col('gilt'), borderWidth: pt(0.5) },
      placement: { ...at('page', 'top-left', FRAME_X - FRAME.pad, FRAME.y - FRAME.pad),
        size: { width: mm(FRAME.w + 2 * FRAME.pad), height: mm(FRAME.w + 2 * FRAME.pad) } } },
    { kind: 'image', id: 'detail', resourceId: 'cover-detail',
      placement: at('page', 'top-left', FRAME_X, FRAME.y, FRAME.w) },
    centred('kicker', '{attr.kicker}', LABEL, 8.5, 'gilt', 18, caps(8.5)),
    // Tracked capitals centre on their letters: the tracking after the É is left out.
    centred('name', '{titleText}', DISPLAY, NAME.size, 'paper', NAME.y, { lineHeight: 1,
      textTransform: 'uppercase', letterSpacing: pt(NAME.track) }),
    centred('subtitle', '{attr.subtitle}', DISPLAY, 18, 'paper', NAME.y + NAME.size * PT + 4,
      { italic: true }),
    centred('foot', '{attr.foot}', LABEL, 8.5, 'gilt', 250, caps(8.5)),
  ] } },
});

表紙は最初の見出し# Doré {style="cover" …}で、ノンブルのないスタイルが描きます。その画像要素が描くwindmills-detail-540.jpgは、どの段落からも引用されないリソースとして登録されているので、番号もキャプションも付きません。このファイルは風車のスキャンから1,100 px四方を切り出して540 pxに縮めたもので、540 pxは1,000 px幅のページ上での幅です。名前には8 ptのトラッキングがかかっていますが、最後の文字のあとの分は中央そろえの計算に入らないので、4つの大文字はずらさなくてもページの中心線に乗ります。

#5 · 出品リストのセルにサムネイル

script.js · 145〜167行コード全体で見る
const THUMB_PX = 300; // px wide: 25 mm at 300 dpi, about the width the cell prints it
// The entries' head, label and numeral from attributes; the level gives span, break and margin.
const checklistStyle = () => ({ id: 'checklist', numbered: false, dropCap: false, // no initial
  advancedDesign: { enabled: true, slot: { elements: head('{attr.kicker}', '{attr.range}') } } });
const cell = (content, more) => ({ content, verticalAlign: 'middle', ...more });
const checklist = (plates) => ({
  id: 'checklist', typeId: 'list', kind: 'table', placement: { position: 'here' },
  altText: 'Checklist of the three works with thumbnails, titles, chapters and pages.',
  table: { model: { headerRowCount: 1, columnWidths: [26, 9, 70, 11], rows: [
    ['', 'Cat.', 'Work and chapter', 'Page'].map((label, i) =>
      cell(label, { isHeader: true, align: i === 3 ? 'right' : 'left' })),
    ...plates.map((p, i) => [
      { content: '', image: { resourceId: `${p.id}-thumb` } },
      cell(String(i + 1)), cell(`*${p.caption}*. ${p.illustrates}`),
      cell(String(platePage(i + 1)), { align: 'right' }),
    ]),
  ] } },
  createdAt: 0, updatedAt: 0,
});
// The cover is page 1 and entry n opens page 2n, so its plate prints on page 2n + 1.
const platePage = (n) => 2 * n + 1;
const listType = { id: 'list', name: 'List', shortLabel: 'List', captionPrefix: '', // no caption
  numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal' };

セルのimageはビットマップのリソースをセルの内側の幅、ここでは23 mmに合わせます。サムネイルは835 pxの図版を描画時に縮めたものではなく、それぞれ300 pxの専用の複製で、その大きさで宣言しています。表にはキャプションのテキストがなく、その種類のキャプション接頭辞も空なので、キャプションは描かれません。出品リストのスタイルが設定するのはnumbered: falseとそのデザインだけで、ページ幅いっぱいに渡ること、偶数ページへの改ページ、地の余白はレベル1から受け継ぎます。

#6 · 解説がページからあふれたら止める

script.js · 349〜354行コード全体で見る
const astray = doc.pages.find((pg) => pg.role !== 'opener' && !pg.floats?.length);
if (astray) { // text run past its verso, or the blank page that follows it
  const error = new Error(`Page ${astray.pageLabel} holds no plate: shorten the entry before it.`);
  kitFail(error); // the viewer's bar says why
  throw error;
}

偶数ページからあふれた解説も、図版は次のページへ送ります。すると解説の残りは図版のあとに続き、次の解説を偶数ページに置くために白ページが1枚入るので、それ以降の図版はどれも出品リストが示すページより2ページあとに印刷されます。この検査は、扉でも図版のページでもない最初のページでビルドを止め、そのページ番号をビューアーのバーに表示します。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 034 · Catalogue entries facing their plates ══════════════
// https://postext.dev/en/cookbook/catalogue-facing-plates
// Code: MIT · Text: original (CC BY 4.0), Ormsby 1885 (PD) · Plates: Doré and Pisan, 1863 (PD)
// Fonts: Ibarra Real Nova, Libre Bodoni, Sofia Sans Condensed (OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'catalogue-facing-plates';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
  ink: '#1b1918', paper: '#faf7f1', night: '#2a2724', // text; the page and plates; the cover
  sepia: '#8a6a45', gilt: '#c9ad86', // the accent on paper (4.6:1) and on the night (6.9:1)
  rule: '#cfc6b8', muted: '#6c665e', // hairlines; tombstones, credit lines, folios
};
// 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 engine's defaults link to 'main-color': point it at the accent, so nothing prints blue.
  { id: 'main-color', name: 'sepia (defaults)', value: { hex: palette.sepia, model: 'hex' } },
];
const [TEXT, DISPLAY, LABEL] = ['Ibarra Real Nova', 'Libre Bodoni', 'Sofia Sans Condensed'];
const PT = 25.4 / 72; // mm per point
const [SIZE, LEAD, LINES] = [11.5, 16, 41]; // body pt, leading pt; 41 lines make the text block
const TRIM = { w: 230, h: 280 }; // mm: a catalogue trim
const [TOP, INNER, OUTER] = [24, 20, 18]; // margins, mm
const BLOCK_W = TRIM.w - INNER - OUTER; // 192 mm: the text block, and the widest plate
const BLOCK_H = LINES * LEAD * PT; // 231.4 mm
const [SIDE_PC, GUTTER] = [34, 7]; // the outer column: 65.3 mm for numeral and tombstone; mm
const SIDE = (BLOCK_W * SIDE_PC) / 100;
const MAIN_X = SIDE + GUTTER; // mm from the block's outer edge to the text column
const MAIN = BLOCK_W - MAIN_X; // 119.7 mm: the measure, about 71 characters

// #region answer: a Plate type that floats to the head of the facing recto, sized to fill it
// Each entry breaks to a verso and cites its plate in the commentary's first sentence; a 'top'
// float never lands on its citing page (gotcha: top-float-next-page), so it opens the recto.
const entryLevel = () => ({
  level: 1, span: 'page', numberingTemplate: '{1}', // {number} in the opener: Cat. 1, 2, 3
  breakBefore: { enabled: true, parity: 'even' }, // an entry opens a verso, facing its plate
  marginBottom: pt(LEAD), advancedDesign: entryOpener(),
  dropCap: { lines: 3, fontFamily: DISPLAY, color: col('sepia'), gap: mm(1.6) }, // the lead's
});
const plateType = {
  id: 'plate', name: 'Cat.', shortLabel: 'Cat.', captionPrefix: 'Cat.', // 'Cat. 1. …'
  numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',

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

アレンジ

#図版の下に余白を残す

幅の比率でフロートそのものを狭めます。版面の幅の78%にすると、どの図版も高さ約188 mmで中央そろえになり、クレジット行の下に約27 mmの版面の空きが残り、縮小は要りません。

-  defaultPlacement: { position: 'top', span: 'page', align: 'center',
-    shrink: 'page', minScale: 0.5, captionMeasure: 'body' },
+  defaultPlacement: { position: 'top', span: 'page', align: 'center', width: 0.78 },

#図を外側の段に置く

図や注釈を、それを引用する段落の横にある、フロート専用の外側の段に積み重ねるには、余白に段を設けた教科書を参照してください。

よくあるつまずき

つまずき

'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる

既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →

つまずき

ビットマップの印刷サイズは解像度で決まる。印刷用のピクセル数を計算せず、解像度を宣言する

解像度のないビットマップは、文書のdpiで1ピクセルを1レイアウトピクセルとして置かれるため、2400 pxの写真は150 dpiのページで幅406 mmになります。ファイルの実際のピクセル数を宣言し、画像に解像度を与える(bitmap.resolution: 300)か、すべてのビットマップにlayout.bitmapResolutionを設定します。値はppi、またはファイルが記す解像度を読む'file'です。段の幅は引き続き画像の上限になります。 リソースとしての図と表 →

Sandboxの検査 · bitmapTooSmall

低解像度の画像

原因. ビットマップがピクセル数の1.5倍を超える幅で描画されるため、印刷するとぼやけて見えます。

対処. 印刷サイズで約300dpiの画像を用意し、ビットマップの実際の幅と高さを宣言してください。 ドキュメント →

クレジット

レシピ
Ignacio Ferro
本文
画像
フォント
Ibarra Real Nova (SIL OFL 1.1) · Libre Bodoni (SIL OFL 1.1) · Sofia Sans Condensed (SIL OFL 1.1)
Sandbox