In short
A small folded magazine about night buses, made for a printing machine that uses only two inks. Colour drawings are turned into shades of one pink ink.
What you'll build
Night Buses is a free zine about a city's night buses: four pages of 120 × 160 mm on one sheet folded once, for a risograph with two drums, blue and fluorescent pink. Every colour in the config is one of the two inks, a 25% screen of the pink or the cream paper. The drawings are made in full colour (a route map in six colours, a moon in greys, an amber destination blind on black) and print from the pink drum as tints of pink, darker colours as denser tints. The map prints in pink, and a small inset lower on its page keeps the six colours as drawn. The cover title is set twice, with the pink copy 0.8 mm right of the blue one and 0.5 mm higher. The pen also builds a colour PDF and a grey proof.
This recipe answers
- How do I recolour every diagram to a single spot ink?
The short answer
// 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 };
Drawings in any colours, printed from the pink drum
Ingredients
- Features
- Single-ink diagramsSemantic colour paletteCMYK and grayscale PDFsPDF exportPages on a canvasInline chipsCaption styleCallout boxesHeading stylesHeading attributesDesigned openersText, rules and boxes in page designsPictures in page designsCovers, title pages and colophonsFigures and tables as resourcesCustom resource typesFigure placementPaper colour
- Also uses
- Citations that place figuresParagraph stylesFonts embedded in the PDFRunning heads per section
- Type
- Epilogue, Anton, Space Mono (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Two drums, and every colour 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' } }));
A risograph prints each ink from its own drum, so a third colour anywhere in the config would need a third drum. screen() mixes a share of an ink with the paper colour, the way a screen prints part of the dots and leaves paper between them. A 25% screen of the pink is #f2c7d3, the ground of the chips and the caption. main-color points at the pink, so any default the config leaves alone prints from that drum and not in the engine's own blue, #295AA3.
#2 · Recolour each drawing once per output
The code is the short answer above. With diagramStyle.singleInk, renderToPdf turns every colour of an SVG into a tint of inkColor whose strength is 1 minus the colour's relative luminance (diagram style), so the navy N12 prints at 84% and the yellow N50 at 24%. The canvas tints a picture the same way when it is registered with singleInk: true, so the kit's loadSvg(fileId, svg, { singleInk: true }) registers each drawing as drawn with that flag and keeps the same markup, which imageBytes hands to resourceBytes. Sampled on the canvas and in the PDF rasterised at 300 dpi, the N12 line is (242, 109, 171), the tint the formula gives for a strength of 0.836. Each output recolours the drawing once: put through the formula twice, the line would lighten to 44%.
#3 · Print the title twice, off register
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) }) }),
] } } };
A risograph prints one drum after the other, and the sheet never lands twice in exactly the same place. twice() returns two copies of a text element, the pink one first, 0.8 mm to the right and 0.5 mm up. Array order is paint order, so the blue copy covers the pink except for a sliver along the top and right edges of each letter. Canvas and PDF paint opaque colour, so the overlap stays blue where a riso would print purple. The design spans the page because the pole runs past the foot of the text block, where a design kept in its column is cut off.
#4 · Keep small type in the dark ink
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) } };
On the cream paper the blue measures 6.4:1 and the fluorescent pink 2.9:1, too faint for type at 8 or 9 pt. Every word the engine sets therefore prints from the blue drum. The chips are blue Space Mono on the 25% screen (4.85:1) inside a pink outline, and the caption is blue Epilogue on the same screen. The pink prints the stripe over the quote, the chip outlines, the bullets, the folio squares and the offset copies of the titles. The lettering inside the drawings belongs to the art and prints pink with it. The speaker's name is the box title, set in bold 7.5 pt Space Mono capitals above the quote.
#5 · Set the inset beside its note
// 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) }) },
] } } };
In one column a float takes the whole width of its band, so a small picture floated there would leave the rest of the band empty. The inset is a heading design instead: ### As drawn {style="drawn" note="…"} prints the picture and, to its right, the heading as a label with the note under it. The picture counts towards the height the design reserves, so the next block starts below it even when the note is shorter. registerSnapshot() draws the same network() map into a PNG, and since single ink recolours only SVG, the inset keeps its six colours on screen and in the PDF.
The whole recipe
// ═══ 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
The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)
Variations
#Load an orange drum
The moon, the map, the blind, the chips, the stripe and the offset copies of both titles turn orange and the type stays blue; the caption, the note and the colophon go on naming the pink drum until you edit them.
-const DRUMS = { ink: '#1d4fb8', spot: '#f0509a' };
+const DRUMS = { ink: '#1d4fb8', spot: '#ff6c2f' };#Print a two-colour textbook
With black type and a blue spot on white paper, the same drawings print as tints of the blue, like the diagrams in a two-colour schoolbook; the caption, the note and the colophon still name the pink drum until you edit them.
-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 fallsPitfalls
Pitfall
A 'top' float goes to the page after its citation unless it may head the citing page
By default a float never goes above its own reference, so a page-wide 'top' float cited on page N opens page N+1. Set placement.citingPage: true on the resource or its type's defaultPlacement (or layout.floatsAtCitingPage for the whole book, since postext 1.25) and it heads page N instead, the text above the reference moving down under it, when it fits within layout.maxTopFraction and the citing line stays on that page. It never heads a chapter's first page or a page after a forced break: there it still opens the next page, and 'auto' or 'bottom' can take the foot of the citing page. Figure placement →
- In the PDF the recolouring rewrites the markup: hex colours,
rgb(),rgba(),hsl()andhsla(), and the keywordswhiteandblack. A shape that namesredor leaves its fill at the default black keeps that colour there, which would need a third drum. Give every fill and stroke a hex value. colorSpace: 'grayscale'greys what postext paints and embeds bitmaps as they are, so the PNG inset stays in colour in the grey proof. Only the pen's second button builds the proof; the pages above are the canvas, and the PDF offered on this page is the colour one.- Column balancing can leave a line of space under a top float, before the rest of a paragraph that continues from the page before;
headings.balancing.stretchAfterFloats: falsekeeps the text right under the float. The text here does not trigger it. After you edit the copy, check the first line under the map, since one extra line can push the inset to a fifth page. - In the pen both buttons read "Build the PDF". The first builds the colour PDF and the second the grey proof; once a file is built, its button gives way to an "Open the PDF ↗" link and a download link with the file's name.
Credits
- Recipe
- Ignacio Ferro
- Text
- Original prose, CC BY 4.0
- Fonts
- Epilogue (SIL OFL 1.1) · Anton (SIL OFL 1.1) · Space Mono (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


