Add box, rule and kv blocks, text folding and receipt preview
Phase 1 of docs/plans/formatters.md: single and double CP437 boxes from
one /print element, and a way to see a receipt without using paper.
- receipt: box, rule and kv elements, laid out when the job renders from
the printer profile, size and font (never fixed widths). Boxes take a
title (inline or capped), a footer, padding, fit and columns, and a
body of text or children (text, feed, kv, and rules as dividers joined
to the borders). Glyphs a code page lacks fall back per set: double-h
and double-v to double, then single, then ascii; a missing junction
switches line weight first.
- Validation names nested elements (elements[0].children[3] (qr)),
checks fields per block type, allows one level of children and counts
them toward the 500-element limit. Block fields on the older types are
problems, as they were unknown fields before.
- Text is composed to NFC and characters the code page lacks fold to
look-alikes (curly quotes, dashes, ellipsis, arrows, check marks, euro,
trademark), as the owner approved on 2026-11-29. An emoji sequence
prints as one '?'. Encodable text is untouched.
- escpos: CodePage.CanEncode and Decode, and Interpret, which reads a
command stream back as the printer would print it. It takes the
profile so that it can follow the printer's own wrapping and
alignment; raw spans stay opaque.
- POST /api/v1/preview and `uberbringer preview` show the lines a job
prints, as text or JSON with styles, without fetching images.
- Config: [format] max_lines (default 2000), refused with 422
too_many_lines on preview; printer.box_line_spacing (default 0).
Byte compatibility: testdata/compat fixtures were rendered by 9b91109
before the renderer changed, and still match it and the new renderer.
examples/blocks.json was printed on the TM-T88IV; the owner judged the
border gaps at the default spacing fine (2026-11-30), so
box_line_spacing stays 0, and TestPaperReceipts pins its bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9fdea32b4f
commit
4562f0cebb
109 files changed
+6383
-487
No files matched your search
+34
-6
@@ -48,6 +48,37 @@ client ─HTTPS─▶ nginx ─▶ server ── validate ──▶ printqueue (
|
||||
the owner prints (owner, 2026-11-29). Control characters are stripped, so
|
||||
data can never become a printer command. Only the `raw` element sends bytes
|
||||
as given.
|
||||
- Before wrapping, text is composed to NFC, and characters the code page
|
||||
lacks fold to ASCII look-alikes (curly quotes, dashes, the ellipsis and
|
||||
a few symbols). An emoji sequence prints as one `?` (owner, 2026-11-29).
|
||||
A fold applies only where the code page lacks the character, so cp1252
|
||||
keeps its curly quotes. After this step one rune is one column and one
|
||||
byte, which is what wrap counts.
|
||||
- **Blocks are laid out when the job renders.** `box`, `rule` and `kv` take
|
||||
their width from the profile (or `printer.columns`) and their own size and
|
||||
font, never from fixed numbers, so a job stays printer-neutral. Layout
|
||||
never fails on a valid job: widths clamp, titles and labels are cut with
|
||||
`...`, and a box narrower than its padding gives up the padding. The only
|
||||
render-time failure added is `format.max_lines`. Validation stays
|
||||
structural, because geometry depends on the printer.
|
||||
- Glyphs the code page lacks fall back per glyph set: `double-h` and
|
||||
`double-v` to `double`, then `single`, then `ascii`. A divider junction
|
||||
the page lacks switches to the other line weight first, and a capped
|
||||
title on double lines uses `╣ ╠`, which cp850 has, instead of `╡ ╞`.
|
||||
- Block fields are rejected on the older element types, which otherwise
|
||||
stay lenient, so a block field sent to the wrong type still fails as an
|
||||
unknown field did before blocks existed.
|
||||
- Boxes print at the printer's default line spacing. The small gaps that
|
||||
leaves in vertical borders were judged acceptable on the TM-T88IV
|
||||
(owner, 2026-11-30), so `printer.box_line_spacing` stays 0 by default.
|
||||
The bytes of that calibration receipt, `examples/blocks.json`, are
|
||||
pinned in a receipt test.
|
||||
- **The preview reads the bytes back.** `escpos.Interpret` parses the stream
|
||||
the renderer produced, so the preview and the tests show what the printer
|
||||
receives rather than what the layout meant. It simulates the printer's own
|
||||
wrapping and alignment, which needs the profile. `raw` bytes stay opaque,
|
||||
since arbitrary bytes cannot be parsed reliably, and images are blank
|
||||
placeholders, so a preview never fetches anything.
|
||||
- **Profiles set the layout, and the default is the narrower one.** Columns
|
||||
are the profile's dots per line divided by the glyph width; nothing
|
||||
hard-codes 42 or 512. The first paper test ran the 576-dot `tm-t20`
|
||||
@@ -99,9 +130,9 @@ client ─HTTPS─▶ nginx ─▶ server ── validate ──▶ printqueue (
|
||||
|
||||
## Planned: formatters
|
||||
|
||||
Layout blocks and modules, ntfy among them, that turn plain input into
|
||||
receipts. The plan is `docs/plans/formatters.md`. Decided so far (owner,
|
||||
2026-11-29):
|
||||
Modules, ntfy among them, that turn plain input into receipts built from the
|
||||
blocks. The plan is `docs/plans/formatters.md`; its first phase, the blocks
|
||||
and the preview, is built. Decided so far (owner, 2026-11-29):
|
||||
|
||||
- ntfy is an input: its notifications are printed. The server is
|
||||
self-hosted at a public URL, the subscriber authenticates with a token, and
|
||||
@@ -109,9 +140,6 @@ receipts. The plan is `docs/plans/formatters.md`. Decided so far (owner,
|
||||
private-network exception.
|
||||
- Which priorities print is configurable per subscription. By default every
|
||||
priority prints, and priorities 1 and 2 print in a compact form.
|
||||
- On `/print`, characters the code page lacks fold to ASCII look-alikes
|
||||
(smart quotes, dashes, the ellipsis), and an emoji sequence prints as one
|
||||
`?`. Today each such character prints as `?`.
|
||||
- Labels are in English. The footer's time zone and date format come from
|
||||
the config.
|
||||
|
||||
|
||||
Reference in new issue
Block a user