Skip to content

fix(print): add Z-report raster print fallback - #1491

Merged
khaira777 merged 5 commits into
mainfrom
fm/flocafe-fix-raster-zreport-printing
Nov 7, 2026
Merged

khaira777 merged 5 commits into
mainfrom
fm/flocafe-fix-raster-zreport-printing

Conversation

@khaira777

@khaira777 khaira777 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Check if raster is supported in all the printing done in the app, and if anything is missing or reported as a failure, fix it. Specifically, a user reported an error involving Turkish characters in the text printed on the Z-report even though the system was set up for the Turkish language, with the error message: "Receipt not printed: A financial row contains unsupported printer text (Turkish text). The printer cannot print these characters as text and no image fallback is available on this path. Nothing was printed, so no amount is missing. Try again or use system/browser printing." Fix this and any other print path missing raster support, and ship the PR through no-mistakes.

Fixes #1480

What Changed

  • Added mixed-mode raster rendering and semantic financial-summary line groups across backend thermal Z-report (printZReport), kitchen ticket (printKOTDetailed), delivery slip (printDeliverySlipDetailed), payment ticket (printPaymentTicket), menu print (printMenu), and test page (renderTestPage) flows so non-CP437 characters (such as Turkish ı, ğ, ş) render as bitmap bands instead of failing closed on financial rows or dropping glyphs.
  • Preserved unrepresentable characters in normalizeThermalText when raster capability is enabled so rasterized labels keep their original glyphs, while retaining native code-page transliteration and safe header fallbacks when raster is disabled or unavailable.
  • Propagated printer capabilities, financial row flags, and raster header/row fallbacks through the frontend WebUSB receipt (receipt-encoder.ts) and KOT (kot-encoder.ts) encoders.

Risk Assessment

✅ Low: The changes cleanly wire capability-gated mixed-mode raster rendering and semantic line groups into Z-reports, payment tickets, printer test pages, and WebUSB receipt/KOT encoders while preserving fail-closed financial refusal and printable header fallbacks when raster rendering fails.

Testing

Ran focused raster, receipt-column-oracle, thermal-capabilities, cash-closures, and printer-api test suites, then stood up a live Electron + Express + SQLite instance with a disposable TCP thermal printer socket server to drive Turkish Z-report printing (80mm network and 58mm WebUSB), Turkish payment ticket printing, Turkish printer test pages, adversarial fail-closed raster failures, and real Chromium canvas WebUSB KOT/receipt encoding, capturing decoded ESC/POS visual thermal printout screenshots and JSON transcripts as evidence; all checks and scenarios passed.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Operator in a Turkish-configured store prints a Z-report (POST /api/cash-closures/:id/print) containing Turkish headings, tax titles, and staff names to an 80mm TCP network printer and a 58mm WebUSB p… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-z-report-and-payment-ticket.png
Adversarial guard: when the Chromium raster renderer fails on a Turkish Z-report or Turkish Payment Ticket containing unrepresentable financial rows, POST /api/cash-closures/:id/print and POST /api/pr… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/live-validation-report.json
Operator prints a Payment Ticket (POST /api/printers/print-payment-ticket) for an order with Turkish item names and table name on 80mm network and 58mm WebUSB printers, receiving HTTP 200 with two-col… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-z-report-and-payment-ticket.png
Operator triggers a Printer Test Page in a Turkish store via POST /api/printers/:id/test (with rasterProbe) and POST /api/printers/test-active, receiving HTTP 200 with Turkish test-page strings ("Flo… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-test-page-and-webusb-tickets.png
Browser/WebUSB receipt and KOT encoders (buildClassicReceiptBytes, buildCompactReceiptBytes, buildDetailedReceiptBytes, buildKotBytes) running in a real Chromium DOM canvas rasterize Turkish reprint/o… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-test-page-and-webusb-tickets.png

Decoded ESC/POS thermal printout of Turkish 80mm Z-Report and 58mm Payment Ticket from live Electron Chromium raster renderer
Decoded ESC/POS thermal printout of Turkish 80mm Printer Test Page and WebUSB KOT + Compact Receipt from live Chromium HTML5 Canvas

Evidence: Live Electron + Express + TCP thermal printer validation report

{ "zReportTurkish": { "network80mm": { "status": 200, "tcpBytesReceived": 42755, "rasterBandCount": 18, "widthDots": 576, "hasDrawerPulse": true }, "webusb58mm": { "status": 200, "webusb": true, "isReprint": true, "bytesLength": 34956, "rasterBandCount": 19, "widthDots": 384, "hasDrawerPulse": true } }, "paymentTicketTurkish": { "network80mm": { "status": 200, "tcpBytesReceived": 9953, "rasterBandCount": 3 }, "webusb58mm": { "status": 200, "webusb": true, "bytesLength": 9889, "rasterBandCount": 3 } }, "printerTestPageTurkish": { "printerByIdWithProbe": { "status": 200, "tcpBytesReceived": 23101, "rasterBandCount": 9 }, "testActive": { "status": 200, "tcpBytesReceived": 14437, "rasterBandCount": 6 } }, "adversarialFailClosed": { "zReportRefusal": { "status": 502, "tcpBytesSent": 0 }, "paymentTicketRefusal": { "status": 502, "tcpBytesSent": 0 } }, "webusbBrowserChromiumCanvas": { "compactReceipt": { "bytesLength": 14326, "rasterBandCount": 7 }, "detailedReceipt": { "bytesLength": 8352, "rasterBandCount": 4 }, "kotTicket": { "bytesLength": 11018, "rasterBandCount": 7 } } }

{
  "scenarios": {
    "zReportTurkish": {
      "network80mm": {
        "status": 200,
        "response": {
          "success": true,
          "isReprint": false,
          "warnings": []
        },
        "tcpBytesReceived": 42755,
        "rasterBandCount": 18,
        "widthDots": 576,
        "hasDrawerPulse": true
      },
      "webusb58mm": {
        "status": 200,
        "webusb": true,
        "isReprint": true,
        "bytesLength": 34956,
        "rasterBandCount": 19,
        "widthDots": 384,
        "hasDrawerPulse": true
      }
    },
    "paymentTicketTurkish": {
      "network80mm": {
        "status": 200,
        "response": {
          "success": true,
          "warnings": []
        },
        "tcpBytesReceived": 9953,
        "rasterBandCount": 3
      },
      "webusb58mm": {
        "status": 200,
        "webusb": true,
        "bytesLength": 9889,
        "rasterBandCount": 3
      }
    },
    "printerTestPageTurkish": {
      "printerByIdWithProbe": {
        "status": 200,
        "tcpBytesReceived": 23101,
        "rasterBandCount": 9
      },
      "testActive": {
        "status": 200,
        "tcpBytesReceived": 14437,
        "rasterBandCount": 6
      }
    },
    "adversarialFailClosed": {
      "zReportRefusal": {
        "status": 502,
        "error": "Receipt not printed: a financial row contains unsupported printer text: Acılış kasası. The printer cannot print these characters as text, and printing them as an image failed (Raster rendering failed (render-failed): Simulated Chromium raster failure). Nothing was printed, so no amount is missing. Try again, or use system/browser printing.",
        "tcpBytesSent": 0
      },
      "paymentTicketRefusal": {
        "status": 502,
        "error": "Receipt not printed: a financial row contains unsupported printer text: 2x Kuenefe & Şoebiyet Porsiyon   TRY350,00. The printer cannot print these characters as text, and printing them as an image failed (Raster rendering failed (render-failed): Simulated Chromium raster failure). Nothing was printed, so no amount is missing. Try again, or use system/browser printing.",
        "tcpBytesSent": 0
      }
    },
    "webusbBrowserChromiumCanvas": {
      "compactReceipt": {
        "bytesLength": 14326,
        "warningsCount": 2,
        "rasterBandCount": 7
      },
      "detailedReceipt": {
        "bytesLength": 8352,
        "warningsCount": 1,
        "rasterBandCount": 4
      },
      "kotTicket": {
        "bytesLength": 11018,
        "warningsCount": 0,
        "rasterBandCount": 7
      }
    }
  }
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Operator in a Turkish-configured store prints a Z-report (POST /api/cash-closures/:id/print) containing Turkish headings, tax titles, and staff names to an 80mm TCP network printer and a 58mm WebUSB p… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-z-report-and-payment-ticket.png
Adversarial guard: when the Chromium raster renderer fails on a Turkish Z-report or Turkish Payment Ticket containing unrepresentable financial rows, POST /api/cash-closures/:id/print and POST /api/pr… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/live-validation-report.json
Operator prints a Payment Ticket (POST /api/printers/print-payment-ticket) for an order with Turkish item names and table name on 80mm network and 58mm WebUSB printers, receiving HTTP 200 with two-col… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-z-report-and-payment-ticket.png
Operator triggers a Printer Test Page in a Turkish store via POST /api/printers/:id/test (with rasterProbe) and POST /api/printers/test-active, receiving HTTP 200 with Turkish test-page strings ("Flo… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-test-page-and-webusb-tickets.png
Browser/WebUSB receipt and KOT encoders (buildClassicReceiptBytes, buildCompactReceiptBytes, buildDetailedReceiptBytes, buildKotBytes) running in a real Chromium DOM canvas rasterize Turkish reprint/o… ✅ pass live ~/.no-mistakes/evidence/01M6T7MRQ7GTS5YZBKJ0R1VEQV/turkish-test-page-and-webusb-tickets.png
  • npm run test:raster
  • npm run test:receipt-column-oracle
  • npm run test:thermal-capabilities
  • node tests/run-electron-node-test.cjs tests/cash-closures.test.ts
  • npm run test:printer-api
  • Live Electron + Express + SQLite + TCP thermal printer validation (POST /api/cash-closures/1/print, POST /api/printers/print-payment-ticket, POST /api/printers/:id/test, POST /api/printers/test-active, and Chromium HTML5 Canvas WebUSB KOT/receipt encoding)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add raster fallback to Z-reports and remaining thermal print paths

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Rasterize unsupported text in Z-reports, payment tickets, and printer test pages instead of losing
 Turkish glyphs.
• Extend WebUSB fallback to receipt banners, detailed financial rows, and KOT headers.
• Preserve wrapped-row layouts and refuse financial prints when raster rendering fails.
Diagram

graph TD
  Backend["Backend documents"] --> Gate{"Raster needed?"} --> Chromium["Chromium raster"] --> Output["ESC/POS output"]
  WebUSB["WebUSB encoders"] --> Gate
  Gate -->|browser| Canvas["Canvas raster"] --> Output
  Gate -->|native text| Output
  Chromium -->|financial failure| Refusal["Print refusal"]
  Canvas -->|financial failure| Refusal
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Rasterize entire documents
  • ➕ Avoids per-row representability decisions and semantic grouping.
  • ➖ Requires whole-receipt opt-in, rasterizes printable text unnecessarily, and changes established mixed-mode output.
2. Unify all print paths under one document renderer
  • ➕ Could reduce duplication between backend and WebUSB fallback logic over time.
  • ➖ Requires a substantially broader migration of existing encoders and print contracts.

Recommendation: Keep the capability-gated mixed-mode approach for this fix: it preserves native output where supported while retaining financial-row refusal guarantees. A unified renderer is a possible separate architectural project, not a prerequisite for restoring these print paths.

Files changed (11) +1237 / -226

Bug fix (8) +756 / -217
kot-encoder.tsPreserve raster-eligible KOT header text +6/-4

Preserve raster-eligible KOT header text

• Keeps unsupported Unicode in KOT headers when raster is enabled, allowing station, table, and customer names to reach the canvas fallback instead of being replaced.

frontend/src/lib/printer/kot-encoder.ts

receipt-encoder.tsRoute banners and detailed amounts through safe printing +124/-51

Route banners and detailed amounts through safe printing

• Passes language and capabilities into reprint and online-order banners. Sends detailed receipt item, tax, subtotal, total, and payment rows through capability-aware printing, marking financial rows for fail-closed handling.

frontend/src/lib/printer/receipt-encoder.ts

warnings.tsRasterize stacked financial rows with right-aligned values +11/-1

Rasterize stacked financial rows with right-aligned values

• Recognizes two-line label-and-amount rows as a two-column raster layout. Preserves their newline during sanitization so narrow WebUSB rows retain the amount alignment.

frontend/src/lib/printer/warnings.ts

formatting-helpers.tsKeep native ESC/POS fallback text normalized +6/-1

Keep native ESC/POS fallback text normalized

• Applies native-text normalization during ESC/POS construction even for raster-enabled profiles, preserving a usable native fallback without changing the raster document's source text.

main/printers/formatting-helpers.ts

raster-renderer.tsCarry financial status and layouts into raster groups +13/-3

Carry financial status and layouts into raster groups

• Recognizes financial markers on individual and uncovered lines, including wrapped groups. Passes source layouts to raster requests for non-financial as well as financial rows.

main/printers/raster-renderer.ts

thermal.tsAdd mixed-mode fallback to Z-reports, tickets, and test pages +573/-147

Add mixed-mode fallback to Z-reports, tickets, and test pages

• Builds semantic line groups for Z-report and payment-ticket rows, then selects capability-gated raster output or native fallback while refusing unsafe financial prints. Adds asynchronous test-page rendering and starts Chromium raster rendering only when an unsupported line needs it.

main/printers/thermal.ts

printers.tsUse raster-aware test-page rendering in printer routes +10/-4

Use raster-aware test-page rendering in printer routes

• Both test-page routes now resolve printer capabilities and await the raster-aware renderer; the diagnostic route retains its explicit raster-probe option.

main/routes/printers.ts

thermal-capabilities.tsPreserve unsupported Unicode when raster is available +13/-6

Preserve unsupported Unicode when raster is available

• Leaves unrepresentable text intact for raster-enabled profiles while keeping transliteration in code-page selection and representability checks.

shared/print/thermal-capabilities.ts

Tests (1) +472 / -1
raster-printing.test.tsCover Turkish raster output and financial failure paths +472/-1

Cover Turkish raster output and financial failure paths

• Adds WebUSB receipt and KOT cases, backend Z-report, ticket, and test-page raster checks, and wrapped-layout assertions. Verifies that renderer or canvas failures still refuse affected financial prints.

tests/raster-printing.test.ts

Documentation (2) +9 / -8
printing.mdDocument mixed-mode coverage across backend print paths +4/-3

Document mixed-mode coverage across backend print paths

• Expands the raster-printing architecture description to include Z-reports, tickets, slips, menu prints, and test pages.

docs/architecture/printing.md

printers.mdLink printer profiles to raster architecture guidance +5/-5

Link printer profiles to raster architecture guidance

• Replaces the local list of supported templates with a link to the authoritative raster-printing documentation while retaining the financial failure guidance.

docs/printers.md

@qodo-code-review

qodo-code-review Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Kitchen headers vanish if raster fails ✓ Resolved

Resolving commit: 4548581

Resolution reason
Introduced writeKotHeaderText, which keeps the printable fallback and writes it when the raster
attempt for the header fails, so KOT header lines no longer print blank. thermalSafeHeaderText now
applies thermalTextFallback to the merged capabilities instead of returning the raw value.
Description
thermalSafeHeaderText returns unsupported header text whenever raster is enabled, replacing the
printable fallback before safePrinterText attempts to render it. If canvas rendering is
unavailable or fails, safePrinterText emits only a warning, so station, order, table, and customer
headers can print as blank lines.

2. Z-report can print in USD/UTC on errors ✓ Resolved

Resolving commit: 4548581

Resolution reason
Removed the silent try/catch defaulting to US/USD/UTC in printPaymentTicket (regional snapshot now
resolved directly, errors propagate), and buildZReportDocumentLines now uses an explicit optional
printer.settings with no catch-based defaults; the test asserts unconfigured regional settings fail
closed.
Description
buildZReportDocumentLines now wraps the settings query in a bare catch and substitutes
z.__country || 'US', z.__currency || 'USD', z.__timezone || 'UTC', but no production caller
sets those __ fields (only the new raster test does). Any settings-read failure in production
therefore silently produces a day-close financial report with the wrong currency prefix, fraction
digits, and business-date timezone instead of failing the print; printPaymentTicket added the same
silent catch around getSettingValue.

Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #34
  🌐 PR #39
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
  Explored: repo: FreeOpenSourcePOS/FloCafe-Plugins (sha: 19dcb656) — View relationship
✅ Context preparation
  Description: summarized; full text retained for this review
✅ REVIEW.md
Review mode: Auto: 🧠 Deep: Financial print paths, 63 hunks across many files, shared normalization changes, prior regressions.

Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread frontend/src/lib/printer/kot-encoder.ts Resolved
Comment thread main/printers/thermal.ts Resolved
@khaira777 khaira777 changed the title fix: add raster fallback to Z-reports and remaining thermal print paths fix(print): add Z-report raster print fallback Nov 7, 2026
Wire mixed-mode raster rendering and financial-summary semantic line groups into printZReport, printPaymentTicket, and renderTestPage so Turkish and other non-CP437 thermal print jobs rasterize cleanly instead of failing closed with an unsupported financial row refusal. Preserve unrepresentable strings intact in normalizeThermalText when raster is enabled so Turkish labels retain all original glyphs when rasterized, and propagate printer capabilities and financial row flags across WebUSB receipt banners and detailed receipt rows.

Fixes #1480
@khaira777
khaira777 force-pushed the fm/flocafe-fix-raster-zreport-printing branch from cbf114e to 4548581 Compare November 7, 2026 06:05
@khaira777 khaira777 changed the title fix(print): add Z-report raster print fallback fix(print): add raster fallback across Z-report and thermal print paths Nov 7, 2026
@khaira777 khaira777 changed the title fix(print): add raster fallback across Z-report and thermal print paths fix(print): add Z-report raster print fallback Nov 7, 2026
@khaira777
khaira777 merged commit 784d10f into main Nov 7, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-fix-raster-zreport-printing branch November 7, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(print): support raster fallback and Turkish characters across Z-report and all print paths

1 participant