かんたんな説明
深夜バスを取り上げた、折りたたみの小さな冊子です。2色のインキしか使えない印刷機向けに作り、カラーの画像を1色のピンクインキの濃淡に変えます。
できあがり
『Night Buses』は、ある町の深夜バスを取り上げた無料のZineです。120 × 160 mmの4ページで、1枚の紙を一度折って作ります。青と蛍光ピンクの2ドラムのリソグラフで刷ります。設定の色はどれも2色のインキのどちらか、ピンクの25%の網、またはクリーム色の紙のどれかです。線画はフルカラーで描かれています(6色の路線図、グレーの月、黒地に琥珀色の行先表示幕)が、ピンクのドラムからピンクの濃淡で印刷され、暗い色ほど濃い網になります。地図はピンクで印刷され、同じページの下の小さな挿図は描いたとおりの6色を保ちます。表紙の表題は2回組み、ピンクの複製を青より0.8 mm右、0.5 mm上に置きます。CodePenのサンプルは、カラーのPDFとグレーの校正刷りも生成します。
このレシピが答える質問
- すべての図表を1色の特色インキに色替えするには?
手短な答え
// renderToPdf reads the ink from the config and recolours every SVG it is handed; the canvas
// does the same to a picture registered with singleInk: true. Both get the drawing as drawn.
const diagramStyle = { singleInk: true, inkColor: col('spot') };
// The kit's loadSvg hands the flag to registerResourceImage, so the canvas tints the drawing
// as it paints, and keeps the markup for imageBytes: the PDF recolours those bytes.
const loadArt = (map) => Promise.all([
loadSvg('network.svg', map, { singleInk: true }),
loadSvg('moon.svg', moon(), { singleInk: true }),
loadSvg('blind.svg', blind(), { singleInk: true }),
]);
const pdfOptions = { fontProvider: fontsourceProvider, resourceBytes: imageBytes };
材料
- 機能
- 単色刷りのダイアグラムセマンティックカラーパレットCMYKとグレースケールのPDFPDFの書き出しキャンバス上のページインラインのチップキャプションのスタイル囲み見出しスタイル見出しの属性デザインした章扉ページデザインのテキスト・罫・ボックスページデザインの画像表紙、扉、奥付リソースとしての図と表独自のリソースの種類図の配置用紙の色
- 種類
- Epilogue, Anton, Space Mono (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 2つのドラムと、そのどちらかに属するすべての色
// The two drums: the blue for the type and the furniture, the fluorescent pink for the art.
const DRUMS = { ink: '#1d4fb8', spot: '#f0509a' };
const PAPER = '#f3efe6'; // cream stock: where no ink falls
// A screen prints a share of an ink's dots and lets the paper show between them.
const screen = (hex, share) => `#${[1, 3, 5].map((i) => Math.round(share
* parseInt(hex.slice(i, i + 2), 16) + (1 - share) * parseInt(PAPER.slice(i, i + 2), 16))
.toString(16).padStart(2, '0')).join('')}`;
const palette = { ...DRUMS, 'spot-25': screen(DRUMS.spot, 0.25), paper: PAPER };
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to main-color: aimed at the spot, none of them adds a third ink.
const colorPalette = [...Object.entries(palette), ['main-color', DRUMS.spot]]
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
リソグラフはインキごとに別のドラムで刷るので、設定のどこかに3色目があれば3つ目のドラムが必要になります。screen()はインキの一定割合を紙の色と混ぜます。網が点の一部だけを刷り、そのあいだに紙を残すのと同じ考え方です。ピンクの25%の網は#f2c7d3で、チップとキャプションの地色です。main-colorはピンクを指すので、設定で触れていない既定値もエンジン本来の青#295AA3ではなく、このドラムから印刷されます。
#2 · 出力ごとに一度だけ線画の色を置き換える
コードは前出の手短な答えにあります。diagramStyle.singleInkを指定すると、renderToPdfはSVGのすべての色をinkColorの濃淡に変えます。濃度は1からその色の相対輝度を引いた値です(ダイアグラムスタイル)。そのため濃紺のN12は84%、黄色のN50は24%で印刷されます。Canvasも、singleInk: trueを付けて登録した画像を同じように置き換えます。そこでキットのloadSvg(fileId, svg, { singleInk: true })が元の線画をその指定付きで登録し、同じSVGを残しておきます。resourceBytesにはそれをimageBytesが渡します。Canvasと、300 dpiでラスタライズしたPDFで色を採取すると、N12の線は(242, 109, 171)で、濃度0.836に対して式が与える濃淡と一致します。どの出力でも置き換えは一度だけです。式を二度通すと、この線は44%まで薄くなります。
#3 · 表題を見当をずらして2回刷る
const OFF = { x: 0.8, y: -0.5 }; // mm: where the pink drum lands against the blue one
// Array order is paint order: the pink copy goes down first and the blue covers all but a
// sliver. Canvas and PDF paint opaque colour, so the overlap stays blue, not riso purple.
const twice = (id, { placement: { offset: { x, y }, ...rest }, ...element }) => [
{ ...element, id: `${id}-spot`, color: col('spot'),
placement: { ...rest, offset: { x: mm(x.value + OFF.x), y: mm(y.value + OFF.y) } } },
{ ...element, id, color: col('ink'), placement: { ...rest, offset: { x, y } } }];
const rule = (id, direction, x, y, size) => ({ kind: 'rule', id, direction, color: col('ink'),
thickness: pt(id === 'pole' ? 3 : 0.8), placement: at('page', 'top-left', x, y, size) });
// span: 'page' lets the design run past the text block's foot: kept in the column, the
// pole would be cut off there.
const cover = { id: 'cover', span: 'page', header: { elements: [] }, footer: { elements: [] },
advancedDesign: { enabled: true, slot: { elements: [
{ kind: 'image', id: 'moon', resourceId: 'moon',
placement: at('page', 'top-left', 28, 14, { width: mm(92), height: mm(92) }) },
rule('wire-1', 'horizontal', 0, 30, { width: mm(TRIM.width) }),
rule('wire-2', 'horizontal', 0, 34.5, { width: mm(TRIM.width) }),
rule('pole', 'vertical', 98, 62, { height: mm(TRIM.height - 62) }), // off the foot
{ kind: 'box', id: 'flag', style: { backgroundColor: col('ink'), borderRadius: mm(1) },
placement: at('page', 'top-left', 89, 62, { width: mm(18), height: mm(21) }) },
// One word a line: the box is narrower than two of them.
{ kind: 'text', id: 'stops', content: '{attr.stops}', ...mono, fontSize: pt(9),
lineHeight: 1.25, align: 'center', color: col('paper'), overflow: 'wrap',
placement: at('#flag', 'top-left', 3, 2.5, { width: mm(12) }) },
{ kind: 'text', id: 'issue', content: '{attr.issue}', ...mono,
placement: at('page', 'top-left', MARGIN.inner, 8) },
{ kind: 'text', id: 'line', content: '{attr.line}', fontFamily: 'Epilogue', fontWeight: 700,
fontSize: pt(9), color: col('ink'), align: 'left', overflow: 'wrap',
placement: at('page', 'top-left', MARGIN.inner, 13, { width: mm(46) }) },
...twice('title', { kind: 'text', content: '{titleText}', fontFamily: 'Anton', fontSize: pt(86),
lineHeight: 0.9,
textTransform: 'uppercase', align: 'left',
overflow: 'wrap', placement: at('page', 'top-left', MARGIN.inner, 94, { width: mm(76) }) }),
] } } };
リソグラフはドラムを1つずつ順に刷り、紙が二度とまったく同じ位置に来ることはありません。twice()はテキスト要素の複製を2つ返し、ピンクを先にして、0.8 mm右、0.5 mm上に置きます。配列の順が描画の順なので、青の複製がピンクを覆い、各文字の上辺と右辺に沿った細い縁だけが残ります。CanvasとPDFは不透明な色で描くため、リソなら紫に刷られる重なりの部分も青のままです。ポールは版面の下端より下まで伸びるので、デザインはページ全体に広げます。段の中に置いたデザインは、段の下端で切り取られるからです。
#4 · 小さな文字は濃いインクで刷る
const opener = { enabled: true, slot: { elements: [
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', ...mono,
placement: at('container', 'top-left', 0, 0.5) },
...twice('title', { kind: 'text', content: '{titleText}', fontFamily: 'Anton',
fontSize: pt(34), lineHeight: 0.95, textTransform: 'uppercase', align: 'left',
overflow: 'wrap', placement: at('#kicker', 'below', 0, 2.5, { width: mm(MEASURE) }) }),
] } };
const route = { id: 'route', background: col('spot-25'), borderColor: col('spot'),
borderWidth: pt(0.75), borderRadius: pt(1.2), fontFamily: 'Space Mono', bold: true,
fontSize: em(0.86), color: col('ink') };
const captionStyle = { fontFamily: 'Epilogue', fontSize: pt(8), color: col('ink'),
backgroundEnabled: true, background: col('spot-25'), padding: mm(1.6) };
const quote = { id: 'quote', backgroundEnabled: false, marginTop: pt(LEAD), marginBottom: pt(4),
stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('spot') },
padding: { top: mm(2.6), right: pt(0), bottom: pt(0), left: pt(0) },
titleStyle: { ...label, gap: mm(1.2) }, // the speaker, above the words
body: { fontFamily: 'Anton', fontSize: pt(14), lineHeight: pt(17), color: col('ink'),
textAlign: 'left', firstLineIndent: pt(0) } };
クリーム色の紙の上では、青のコントラスト比は6.4:1、蛍光ピンクは2.9:1で、8 ptや9 ptの文字には薄すぎます。そこでエンジンが組む語はすべて青のドラムから印刷します。チップは25%の網(4.85:1)の上に青のSpace Monoを置き、ピンクの輪郭で囲みます。キャプションも同じ網の上の青のEpilogueです。ピンクで刷るのは、引用の上の帯、チップの輪郭、行頭記号、ノンブルの正方形、表題のずらした複製です。線画の中の文字は画像の一部なので、画像と一緒にピンクで刷られます。話者の名前は囲みの見出しで、引用の上に7.5 ptの太字のSpace Monoの大文字で組みます。
#5 · 挿図を注記の横に置く
// The inset keeps the map's own colours. Single ink touches SVG only, so the map goes in
// as a PNG snapshot, which neither the canvas nor the PDF recolours.
async function registerSnapshot(fileId, svg, width, height) {
const canvas = new OffscreenCanvas(width, height);
canvas.getContext('2d').drawImage(await decodeSvgImage(svg), 0, 0, width, height);
const png = URL.createObjectURL(await canvas.convertToBlob());
await loadImage(fileId, png); // the kit registers the PNG and keeps its bytes for the PDF
URL.revokeObjectURL(png);
}
const INSET = 30; // mm: the snapshot's width; its height follows the map's 100 × 69.5
const drawn = { id: 'drawn', marginTop: pt(LEAD), advancedDesign: { enabled: true,
slot: { elements: [
{ kind: 'image', id: 'inset', resourceId: 'as-drawn',
placement: at('container', 'top-left', 0, 0.5, { width: mm(INSET), height: 'auto' }) },
{ kind: 'text', id: 'label', content: '{titleText}', ...mono,
placement: at('#inset', 'right-of', 5, 0) },
{ kind: 'text', id: 'note', content: '{attr.note}', fontFamily: 'Epilogue',
fontSize: pt(8.5), lineHeight: 1.4, color: col('ink'), align: 'left', overflow: 'wrap',
placement: at('#label', 'below', 0, 1.5, { width: mm(MEASURE - INSET - 5) }) },
] } } };
1段組みではフロートはその帯の幅全体を占めるので、小さな画像をそこにフロートとして配置すると帯の残りが空いてしまいます。そこで挿図は見出しのデザインにします。### As drawn {style="drawn" note="…"}は画像を印刷し、その右に見出しをラベルとして、その下に注記を置きます。画像はデザインが確保する高さに数えられるので、注記が短くなっても、次のブロックは画像の下から始まります。registerSnapshot()は同じnetwork()の地図をPNGに描きます。単色化はSVGの色しか置き換えないので、挿図は画面でもPDFでも6色を保ちます。
レシピの全体
// ═══ Postext Cookbook · Nº 051 · Two-ink riso zine: art in one spot colour ═════════
// https://postext.dev/en/cookbook/riso-zine-single-ink
// Code: MIT · Text: original (CC BY 4.0) · Pictures: drawn in code (CC BY 4.0)
// Fonts: Epilogue, Anton, Space Mono (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A four-page zine for a risograph with a blue drum and a fluorescent pink one. The drawings
// are made in full colour and printed from the pink drum as tints of pink.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, decodeSvgImage,
} 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 = 'riso-zine-single-ink';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region inks: two drums and the paper; every colour in the config links to one of them
// The two drums: the blue for the type and the furniture, the fluorescent pink for the art.
const DRUMS = { ink: '#1d4fb8', spot: '#f0509a' };
const PAPER = '#f3efe6'; // cream stock: where no ink falls
// A screen prints a share of an ink's dots and lets the paper show between them.
const screen = (hex, share) => `#${[1, 3, 5].map((i) => Math.round(share
* parseInt(hex.slice(i, i + 2), 16) + (1 - share) * parseInt(PAPER.slice(i, i + 2), 16))
.toString(16).padStart(2, '0')).join('')}`;
const palette = { ...DRUMS, 'spot-25': screen(DRUMS.spot, 0.25), paper: PAPER };
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to main-color: aimed at the spot, none of them adds a third ink.
const colorPalette = [...Object.entries(palette), ['main-color', DRUMS.spot]]
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
// #region answer: drawings in any colours, printed from the pink drum
// renderToPdf reads the ink from the config and recolours every SVG it is handed; the canvas
// does the same to a picture registered with singleInk: true. Both get the drawing as drawn.
const diagramStyle = { singleInk: true, inkColor: col('spot') };
// The kit's loadSvg hands the flag to registerResourceImage, so the canvas tints the drawing
// as it paints, and keeps the markup for imageBytes: the PDF recolours those bytes.
const loadArt = (map) => Promise.all([
loadSvg('network.svg', map, { singleInk: true }),
loadSvg('moon.svg', moon(), { singleInk: true }),
loadSvg('blind.svg', blind(), { singleInk: true }),
]);
const pdfOptions = { fontProvider: fontsourceProvider, resourceBytes: imageBytes };
// #endregion
const TRIM = { width: 120, height: 160 }; // mm: a 240 × 160 sheet folded once
const MARGIN = { top: 13, bottom: 16, inner: 12, outer: 10 }; // mm
const MEASURE = TRIM.width - MARGIN.inner - MARGIN.outer; // 98 mm, about 65 characters
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#オレンジのドラムを入れる
月、地図、表示幕、チップ、帯、2つの表題のずらした複製がオレンジになり、文字は青のままです。キャプション、注記、奥付は、書き換えるまでピンクのドラムの名前を挙げたままです。
-const DRUMS = { ink: '#1d4fb8', spot: '#f0509a' };
+const DRUMS = { ink: '#1d4fb8', spot: '#ff6c2f' };#2色刷りの教科書を刷る
白い紙に黒の文字と青の特色を使うと、同じ線画が2色刷りの教科書の図のように青の濃淡で印刷されます。キャプション、注記、奥付は、書き換えるまでピンクのドラムの名前を挙げたままです。
-const DRUMS = { ink: '#1d4fb8', spot: '#f0509a' };
-const PAPER = '#f3efe6'; // cream stock: where no ink falls
+const DRUMS = { ink: '#1f1f1f', spot: '#0078bf' };
+const PAPER = '#ffffff'; // white stock: where no ink fallsよくあるつまずき
つまずき
'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる
既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →
- PDFでの置き換えはSVGのマークアップを書き換えます。対象は16進の色、
rgb()、rgba()、hsl()、hsla()と、キーワードのwhiteとblackです。redと指定した図形や、塗りを既定の黒のままにした図形はPDFでその色を保ち、3つ目のドラムが必要になります。塗りと線にはすべて16進値を指定してください。 colorSpace: 'grayscale'はpostextが描くものをグレーにし、ビットマップはそのまま埋め込むので、PNGの挿図はグレーの校正刷りでもカラーのままです。校正刷りを生成するのはCodePenのサンプルの2つ目のボタンだけです。上のページはCanvasで、このページで提供しているPDFはカラーのほうです。- 段末そろえは、上部のフロートの下で、前のページから続く段落の残りの前に1行分のアキを残すことがあります。
headings.balancing.stretchAfterFloats: falseを指定すると、本文はフロートのすぐ下に付きます。ここの本文ではそれが起きません。本文を書き換えたら地図の下の最初の行を確かめてください。1行増えるだけで挿図が5ページ目に押し出されることがあります。 - CodePenのサンプルでは、どちらのボタンにも「Build the PDF」と書かれています。1つ目がカラーのPDFを、2つ目がグレーの校正刷りを生成します。ファイルができると、そのボタンは「Open the PDF ↗」リンクと、ファイル名の付いたダウンロードリンクに置き換わります。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- フォント
- Epilogue (SIL OFL 1.1) · Anton (SIL OFL 1.1) · Space Mono (SIL OFL 1.1)


