This repository includes a Typst layout package and a Crystal harness to produce
bit-exact PNG fixtures for MSG_320x240 message-window rendering.
Files
- Typst package:
typst/social-badge/layout.typ - Case manifest:
testdata/typst/layout_cases.json - Crystal runner:
scripts/check_typst_layouts.cr - Render outputs:
testdata/typst/out/*.typandtestdata/typst/out/*.png
Typst package API
Use render-message-window(...) from typst/social-badge/layout.typ.
Parameters:
bodycontent block containing Typst-authored message layout.- Optional
font_id(nsm,ns,ser,atk,ibm).
The package renders only the message window (320x240) with a fixed 8px inset
content box (304x224).
Built-in helpers exported by the package:
#place(loc)[content]for alignment within the message window content box.#qr("https://...")for real QR symbol rendering (glyph only, no caption text).
#qr(...) is backed by the vendored local tiaoma package at
typst/vendor/tiaoma, so Typst fixture rendering does not depend on network
package downloads.
Example:
#import "../../../typst/social-badge/layout.typ": render-message-window, place, qr
#render-message-window(font_id: "nsm")[
#place(bottom + right)[#qr("https://bbb.io/badge")]
]
Running checks
Run comparison against expected hashes:
crystal run scripts/check_typst_layouts.cr
Update expected hashes after intentional layout changes:
crystal run scripts/check_typst_layouts.cr -- --update
Run one case only:
crystal run scripts/check_typst_layouts.cr -- --case qr_only_right
Bit-exact behavior
- The runner compiles each case with
typst compile --format png --ppi 96. - It computes SHA-256 for each PNG.
- It compares each hash to
expected_sha256in the case manifest. - In
--updatemode, it rewritesexpected_sha256values.
If hashes mismatch, the process exits non-zero for CI or local gate checks.