ADR-126 — Canvas question types on paper: a closed drawing model, inline SVG, a ruled free frame¶
Status¶
Accepted (2026-11-04, the product owner's decisions on the follow-up of
issue #551). Delivery progress lives in changes/.
Amended 2026-11-04, scope: §8 (code prints, a lines frame like
blocks).
Scope: the printed and exported documents of the diagram, circuit,
logic and blocks question types; the drawing block of the document
tree and its SVG writer; the ruled form of a free answer zone.
Relations: amends ADR-125 §5 and §20
(which types print), §6 (the ruled free zone) and ADR-121 §1 (a new
block kind). Depends on ADR-125 §2 (the compile sandbox), §6 (the answer
zones), §7 (fixed words), §14 (untyped free zones), §19 (leak tests);
ADR-046 (the diagram's server entry has no
React); ADR-123;
ADR-103; invariant 4; 05 §5.7.
Context¶
ADR-125 printed the text types and left diagram and circuit out: their
figure — the canvas a student completes, and often the statement itself —
has no server-side renderer, since packages/diagram and
packages/qt-circuit draw through React only. logic and blocks came
later with the same gap. A paper exam therefore refuses every evaluation
holding one of them (409 not_printable), and the staff "statement with
key" prints a placeholder where the figure belongs.
Two shortcuts are ruled out: rendering the React editors on the server
(react-dom/server in the API breaks ADR-046's split, and the editors
measure a live DOM), and letting a type write SVG or Typst markup into the
tree (a second exit for arbitrary markup beside the escaped text of
ADR-125 §2, unchecked by any renderer).
Decision¶
-
The
drawingblock (amends ADR-121 §1):{ kind: "drawing"; drawing: Drawing; alt: string; widthMm?: number; maxHeightMm?: number }. ADrawingis a closed model inpackages/docexport(src/drawing.ts):{ viewBox: [x, y, w, h]; items: DrawingItem[] }, where an item is apath,rect,ellipse(a circle too),line,text, or a groupg, the one item with an affinematrixtransform and an opacity. Shapes are painted with a closed set of paints —none,ink,grey,faint,paper— a stroke width and a dash array; a text hasx,y,text,anchor(start/middle/end),baseline(alphabetic/middle),size,weight(normal/bold) anditalic. A block never holds markup of a target format: each canvas type writes aDrawingfrom its model through a pure serializer of its own, with no React and no DOM; the diagram's geometry moves frompackages/diagram/src/editor/shapes.tsxinto a pure paint module both the editor and the serializer use. -
One SVG writer,
toSvg, pure, inpackages/docexport. Its output is built element by element from the model, under these rules: - colours are literals (
#000000,#8c8c8c,#d2d2d2,#ffffff), never a CSS variable or a class; - every text carries
font-family="DejaVu Sans Mono", the only monospace font the Typst binary embeds; its four faces (regular, bold, oblique, bold oblique) are embedded, soweightanditalichold under--ignore-system-fonts(verified on Typst 0.15.1); - a text's content is XML-escaped (
& < > " 'as character references, characters XML 1.0 refuses dropped); - no
class,style,href,image,use,foreignObject, script orurl(…): the writer has no way to emit them; - a path's data must match
^[MLHVCSQTAZmlhvcsqtaz0-9 .,eE+-]*$; - every number must be finite and within ±10⁶, each number of a path's data included; widths, sizes and opacities are clamped into range;
- the transforms of nested groups are composed down the tree: a composed coefficient past ±10⁶, or a determinant below 10⁻⁶, refuses the drawing (six nested ×10⁶ scales with an opacity, each within the cap, made Typst 0.15.1's PDF writer panic and fail the whole document);
- a value of the wrong shape (a cast string for an array, an unknown kind or paint) is refused, never thrown;
- caps: 5,000 items, groups 8 deep, 500 characters per text, 20,000 per path, 500,000 for the whole SVG.
A drawing that breaks a rule is refused as a whole, and the document
prints the block's alt text instead. The PDF embeds the SVG inline,
image(bytes(<string literal>), format: "svg"): no asset file, nothing
new in the compile root, no change to the sandbox of ADR-125 §2.
-
The ruled frame. The
freeanswer zone gainsruling?: { kind: "grid" | "lines"; pitchMm: number }andunderlay?: Drawing(namedruling, notpattern:patternis a short answer's key, forbidden in every student payload and searched for in every hand-out). With a ruling, the Typst renderer fills the frame of the zone's height with native Typst — atilingof 0.25 pt lines atluma(205),pitchMmapart (4 mm when not finite, held within 2 to 20 mm): a square grid to draw on, or horizontal ruled lines to write on — still wrapped byzone(), the samefree(…)function as a plain frame. The zone staysfree: its metadata kind, palier B's manifest and ADR-125 §14 (an untyped free zone is proposed at 0,paper_free_zone, graded by hand) apply unchanged. The Markdown hand-out previews it as a plain frame. -
The starter. A diagram's starter is the frame's
underlay, drawn at the frame's top left in grey:toSvgwithgreyedmapsinktogrey, whatever the type wrote. It is printed at a fixed scale, one drawing unit per CSS pixel, never shrunk — the frame clips what passes its edge — so a producer that setspitchMmto its editor's grid timesPX_MM(25.4 / 96) keeps the starter on the printed grid. An underlaytoSvgrefuses is left out; the frame stays. -
Scale. A drawing is printed at
widthMm, else one drawing unit per CSS pixel (1 px ≈ 0.26 mm), never wider than the text column (A4 less both margins, 170 mm), and narrowed to keepmaxHeightMm, itself never more than the page body (257 mm): no figure overflows a page. A circuit or logic box of 40 × 25 cells prints at 4 mm per cell, 160 × 100 mm; a diagram at 1 px ≈ 0.26 mm, shrunk to the column. -
The frame's height never comes from the reference. A hand-out's frame is sized from the student view (the starter, the box, a type's default), never from the reference design: its size would tell the student how large the answer is.
-
Fixed words of a figure follow the reader's language (ADR-125 §7):
Labelscarries its ownlang, and every hook that writes words of its own — a pseudo-code keyword, a figure's caption — receives the reader'sLabels;answerZonegains that parameter when the first type needs it. -
Which types print, and what (amends ADR-125 §5 and §20):
diagram,circuit,logic:answerZonereturns afreeframe with agridruling;statementDocprints the figure the student is given (a circuit's or a logic box's fixed parts, a diagram's starter); the documents that show the key (solutionDoc) print the reference design as adrawing.blocks: the answer zone is afreeframe with alinesruling, for pseudo-code written by hand; the statement prints the visible warehouse maps as drawings, the battery, the toolbox and the starter program as pseudo-code; the key prints the reference program as pseudo-code. A hidden warehouse never reaches a student document (#998). A blocks paper answer is a free zone graded by hand under ADR-125 §14: the teacher does not rebuild the program in Blockly.- The student's own answer drawn in their copy (
studentAnswerDoc) is a later, optional step. -
code(amendment of 2026-11-04): prints likeblocks. The owner chose alinesframe forblocksonly; extending it tocodewas decided by the orchestrator on 2026-11-04, to end the production refusal of every past series holding code, and reported to the owner. The frame is afreezone with alinesruling, to write the program by hand, at least half a page (16 lines of 8 mm), as many lines as the template the student is given has, up to 28; never sized from the reference. The statement prints the template without its marker lines; a hidden case never reaches it (#998). A paper answer is graded by hand (ADR-125 §14). The student's copy prints their own source, rebuilt from the template they were served and their regions. Without it, every programming series refused its hand-out. -
Leak tests (ADR-125 §19, 05 §5.7). Each printable canvas type is tested with a full configuration: the tree, the Typst source and the Markdown are searched for the answer-key values, and the PDF text too — SVG text stays text in the PDF:
pdftotextextracts it (verified on Typst 0.15.1), so a key value written into a figure is caught in all four forms. A key drawn only as shapes, with no text, is caught in the tree and the source. -
Grading of a paper attempt is unchanged. No machine reading of a drawing; a canvas item is graded by hand as any free zone.
-
Sequence, each step its own pull request: (1) this record and the
docexportinfrastructure; (2)circuitandlogic; (3)diagram, with its pure paint module; (4)blocks; (5) optionally, the student's answer drawn in copies.
Consequences¶
- An exam holding a canvas question can be printed; its statement and key documents show the figures instead of a placeholder.
- One more writer of untrusted output, kept small: the model is closed and
toSvgis the only place that turns it into SVG, with refusals tested. - Each canvas type owns a second rendering of its model, beside the editor's; a pure paint module shared by both limits the drift for the diagram, the largest.
- The figure's fonts are monospace only, the one family the binary embeds for every face; a figure's typography may differ from the screen's.
- A large drawing makes a large Typst source; the caps bound it.
Alternatives considered¶
react-dom/serverrendering the editors' SVG in the API: React in the API against ADR-046's split, and editors that measure a live DOM.- A type writing SVG or Typst markup into a block: an unchecked second path for markup beside ADR-125 §2's escaping; the closed model keeps one.
- SVG as an asset file in the compile root: a file per figure for no gain; the inline string literal needs no change to the sandbox.
- The grid as an SVG pattern: a large drawing per frame where Typst's
native
tilingis one line of source. - A new zone kind (
canvas): palier B's manifest and ADR-125 §14 would need a case for what is, on paper, a free frame. - A
lineszone for blocks: a typed zone, so an untranscribed program would be graded as no answer, and the teacher would rebuild each program in Blockly to enter it. - Blockly's own rendering for
blocks: block shapes need the Blockly runtime and a DOM; pseudo-code reads well on paper and is written by hand. - Sizing the frame from the reference design: a leak of the answer's size (point 6).