fix(print): center the out-of-window slip barcode again

The previous width fix also forced ALIGN_LEFT inside code128(), which moved the
slip's barcode to the left. But the no-print bug was the barcode WIDTH (too wide
to fit the head at module width 3), not the centering — at width 2 it fits and
centers fine. So code128() no longer touches alignment; the caller controls it.
The out-of-window slip block is ALIGN_CENTER, so the Code128 + QR center as they
did before, just narrow enough (width 2, ~510 dots) to actually print. The
voucher receipt barcode likewise centers as it originally did.

Verified: alignment-in-effect at the barcode = CENTER, module width = 2, QR
present; build+lint 14/14.

Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
2026-06-21 13:52:42 +02:00
parent 663bf0e925
commit 31f116a068
+9 -13
View File
@@ -123,14 +123,13 @@ function line(text = ""): Buffer {
* `moduleWidth` (narrow-bar dots, 1–6) trades scan-tolerance for total width: at ~11
* modules/char a 13-char id fits 80mm (576 printable dots) at width 3, but a ~20-char
* id needs width 2 or it OVERFLOWS the head and the firmware silently aborts the
* barcode (prints nothing). Keep the symbol LEFT-aligned — centering shifts the start
* point right and makes a wide barcode overflow even sooner. */
* barcode (prints nothing). It does NOT set alignment — the caller does (a barcode that
* FITS the head centers fine; the no-print bug was width, not centering). */
function code128(data: string, moduleWidth = 3): Buffer {
// Code128 code set B (printable ASCII) — prefix the data with the {B selector.
const payload = Buffer.from(`{B${data}`, "ascii");
const w = Math.max(1, Math.min(6, moduleWidth));
return Buffer.concat([
ALIGN_LEFT, // a wide barcode must start at the left margin to fit the 80mm head
Buffer.from([GS, 0x68, 0x64]), // GS h 100 — barcode height = 100 dots (taller = tolerant of scan angle)
Buffer.from([GS, 0x77, w]), // GS w n — module (narrow-bar) width in dots
Buffer.from([GS, 0x48, 0x00]), // GS H 0 — HRI text off (we print the id ourselves)
@@ -425,12 +424,10 @@ export function renderReceipt(data: ReceiptData): Buffer {
];
if (data.voucher) {
// The same ticket id, scannable at the exit reader, + the grace emphasis. code128
// forces ALIGN_LEFT (a wide barcode must hug the margin); restore centering for the
// human-readable id + grace lines that follow.
// The same ticket id, scannable at the exit reader, + the grace emphasis. The block
// is ALIGN_CENTER (set at the amount above), so the barcode + id center as before.
parts.push(
code128(data.ticketId),
ALIGN_CENTER,
line(),
line(data.ticketId),
line(),
@@ -466,14 +463,13 @@ export function renderWindowChargeNotice(data: WindowChargeNoticeData): Buffer {
line(STR.windowTitle),
BOLD_OFF,
line(),
// The occurrence id, scannable two ways. Code128 for a 1D laser scanner FIRST —
// module width 2 + left-aligned (code128 forces ALIGN_LEFT) because the ~20-char
// occurrence id is too wide to fit the 80mm head at width 3 (the firmware would
// abort it). Then the QR for the booth's combo reader. Either pulls the occurrence
// up in the pay modal.
// The occurrence id, scannable two ways, both CENTERED (the surrounding block is
// ALIGN_CENTER). Code128 for a 1D laser scanner FIRST — module width 2 because the
// ~20-char occurrence id is too wide to fit the 80mm head at width 3 (the firmware
// would abort it); at width 2 (~510 dots) it fits and centers fine. Then the QR for
// the booth's combo reader. Either pulls the occurrence up in the pay modal.
code128(data.occurrenceId, 2),
line(),
ALIGN_CENTER,
qrCode(data.occurrenceId),
line(),
// The id in text, as the hand-key fallback if neither scans.