Skip to content

feat(printers): gate Arabic and Persian thermal output behind shaping capability - #355

Merged
khaira777 merged 3 commits into
mainfrom
feat/241-i-persian-thermal-fallback
Aug 17, 2026
Merged

khaira777 merged 3 commits into
mainfrom
feat/241-i-persian-thermal-fallback

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Move Persian raw thermal receipt printing beyond the narrow #273 financial-line protection and determine correct supported behavior. Generic ESC/POS firmware does not shape Arabic/Persian, so Persian text must never be emitted as corrupted/unshaped glyphs: gate Arabic-script thermal output behind an explicit per-printer 'arabicShaping' capability flag that defaults to off (safe fallback skips Arabic text with a precise warning while financial lines keep their ASCII currency fallback such as riyal-to-IRR), thread that flag through every raw ESC/POS encoder (receipt, plugin template, KOT) on the backend and mirror the precise warning on the frontend WebUSB path, and add deterministic tests for the Persian path, unsupported Persian path, mixed-script path, financial-line safety, narrow widths, large values, and existing non-Persian behavior. Do not add a large raster-printing subsystem. Meva TP-UN capability cannot be proven without a real hardware print, so mark it needs-human-verification.

What Changed

  • Added an optional arabicShaping capability flag to SupportedPrinterProfile (defaulting to false) and gated Arabic and Persian script raw ESC/POS output behind it across receipt, plugin template, and KOT formatters.
  • Updated backend and frontend printer warning generators to produce specific warning messages when Persian/Arabic text cannot be printed due to missing printer shaping support.
  • Added test coverage in tests/printer.test.ts verifying default skipping with shaping-specific warnings, successful output when arabicShaping is enabled, and mixed-script safeguards.

Risk Assessment

✅ Low: The change safely gates Arabic/Persian thermal printing behind an explicit capability flag defaulting to off, preserves ASCII financial-line fallbacks, provides precise warnings across backend and frontend paths, and includes comprehensive test coverage with zero regressions.

Testing

Exercised the full printer test suite and targeted ESC/POS encoder validations across backend thermal receipts, plugin templates, KOTs, and frontend WebUSB warning paths, verifying that Persian text is safely skipped with precise shaping warnings under generic profiles, rendered cleanly when explicit arabicShaping is enabled, and that large IRR financial amounts and narrow 58mm layouts remain aligned; generated reviewer-visible visual HTML preview and text comparison artifacts with all 313 assertions passing.

Evidence: Persian Thermal Fallback & Arabic Shaping CLI Evidence
================================================================================
PERSIAN RAW THERMAL RECEIPT PRINTING & ARABIC SHAPING CAPABILITY EVIDENCE
================================================================================

--- 1. DEFAULT GENERIC ESC/POS PRINTER (arabicShaping = false) ---
Behavior: Safely skips unshaped Persian script with precise warnings. Financial lines keep ASCII currency (IRR).
Emitted Warnings Count: 6
Warnings:
  • [store name] Store name was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: کافه فلو تهران
  • [receipt line] Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Table: میز ۴
  • [receipt line] Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: چای زعفرانی مخصوص         2        IRR500,000.00
  • [receipt line] Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: + هل اضافه                        IRR50,000.00
  • [receipt line] Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Note: بدون قند و نبات
  • [receipt line] Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: خیابان ولیعصر، پلاک ۱۲۳

Decoded Printable Output:
================================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
------------------------------------------------
Item                      Qty             Amount
------------------------------------------------
Espresso Single           1    IRR500,000,000.00
------------------------------------------------
Subtotal                       IRR500,550,000.00
Discount                           -IRR50,000.00
Tax                                 IRR45,000.00
TOTAL                          IRR500,545,000.00
------------------------------------------------
Cash                           IRR500,545,000.00
================================================
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com

--------------------------------------------------------------------------------
--- 2. PRINTER WITH ARABIC SHAPING CAPABILITY (arabicShaping = true) ---
Behavior: Emits Persian text as UTF-8 bytes to printer firmware that performs shaping. Zero warnings.
Emitted Warnings Count: 0

Decoded Printable Output:
کافه فلو تهران
================================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
Table: میز ۴
------------------------------------------------
Item                      Qty             Amount
------------------------------------------------
چای زعفرانی مخصوص         2        IRR500,000.00
  + هل اضافه                        IRR50,000.00
  Note: بدون قند و نبات
Espresso Single           1    IRR500,000,000.00
------------------------------------------------
Subtotal                       IRR500,550,000.00
Discount                           -IRR50,000.00
Tax                                 IRR45,000.00
TOTAL                          IRR500,545,000.00
------------------------------------------------
Cash                           IRR500,545,000.00
================================================
خیابان ولیعصر، پلاک ۱۲۳
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com

--------------------------------------------------------------------------------
--- 3. KITCHEN ORDER TICKET (KOT) COMPARISON ---
A) Default (arabicShaping = false) - skips Persian station & items, keeps English items & control structure:
Warnings: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Station: آشپزخانه مرکزی | Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Table: میز ۴ | Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: 2x  چای زعفرانی مخصوص | Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: + هل اضافه | Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: ** بدون قند و نبات **
KITCHEN ORDER TICKET

Order: ORD-IR-2026-001
Time: 6:30:00
================================================

1x  Espresso Single

================================================

B) Shaped (arabicShaping = true) - renders full Persian station & items cleanly without warnings:
Warnings: None (clean)
KITCHEN ORDER TICKET

Station: آشپزخانه مرکزی
Order: ORD-IR-2026-001
Table: میز ۴
Time: 6:30:00
================================================

2x  چای زعفرانی مخصوص
  + هل اضافه
  ** بدون قند و نبات **
1x  Espresso Single

================================================

--------------------------------------------------------------------------------
--- 4. NARROW WIDTH (58mm / 32 cols) & LARGE CURRENCY VALUES ---
Decoded Printable Output:
================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
--------------------------------
Item      Qty             Amount
--------------------------------
Espresso..1    IRR500,000,000.00
--------------------------------
Subtotal       IRR500,550,000.00
Discount           -IRR50,000.00
Tax                 IRR45,000.00
TOTAL          IRR500,545,000.00
--------------------------------
Cash           IRR500,545,000.00
================================
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com
================================================================================
Evidence: Rendered Visual Receipt Simulation & Warnings Preview (HTML)
<!DOCTYPE html>
<html lang=en>
<head>
  <meta charset=UTF-8>
  <title>Persian Thermal Receipt Printing & Arabic Shaping Verification</title>
  <style>
    body { font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0f172a; color: #f8fafc; padding: 2rem; }
    h1 { margin-bottom: 0.5rem; font-size: 1.75rem; color: #38bdf8; }
    p.lead { color: #94a3b8; margin-top: 0; margin-bottom: 2rem; font-size: 0.95rem; line-height: 1.5; }
    .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1.5rem; }
    .card { background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 1.25rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3); }
    .card h2 { font-size: 1.1rem; margin-top: 0; border-bottom: 1px solid #334155; padding-bottom: 0.5rem; color: #e2e8f0; }
    .receipt { background: #090d16; border: 1px dashed #475569; padding: 1rem; font-family: 'SF Mono', Monaco, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.45; white-space: pre; overflow-x: auto; color: #f1f5f9; border-radius: 6px; }
    .badge { display: inline-block; padding: 0.25rem 0.65rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; margin-bottom: 0.75rem; letter-spacing: 0.05em; }
    .badge-default { background: #78350f; color: #fde68a; }
    .badge-shaped { background: #14532d; color: #86efac; }
    .badge-kot { background: #312e81; color: #c7d2fe; }
    .warnings { background: #450a0a; border-left: 4px solid #ef4444; padding: 0.75rem; font-size: 0.85rem; color: #fecaca; margin-bottom: 1rem; border-radius: 0 6px 6px 0; }
    .warnings ul { margin: 0; padding-left: 1.25rem; }
    .clean-box { background: #064e3b; border-left: 4px solid #10b981; padding: 0.75rem; font-size: 0.85rem; color: #a7f3d0; margin-bottom: 1rem; border-radius: 0 6px 6px 0; }
  </style>
</head>
<body>
  <h1>Persian Thermal Receipt Printing & Arabic Shaping Verification</h1>
  <p class="lead">Demonstration of Arabic/Persian script capability gating (<code>arabicShaping</code> flag), safe character fallbacks, precise warnings, and financial-line preservation.</p>
  
  <div class="grid">
    <div class="card">
      <span class="badge badge-default">Default Generic ESC/POS (arabicShaping = false)</span>
      <h2>Safe Fallback with Precise Warnings</h2>
      <div class="warnings">
        <strong>Emitted Driver Warnings:</strong>
        <ul>
          <li><code>store name</code>: Store name was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: کافه فلو تهران</li><li><code>receipt line</code>: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Table: میز ۴</li><li><code>receipt line</code>: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: چای زعفرانی مخصوص         2        IRR500,000.00</li><li><code>receipt line</code>: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: + هل اضافه                        IRR50,000.00</li><li><code>receipt line</code>: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: Note: بدون قند و نبات</li><li><code>receipt line</code>: Receipt line was not printed because it contains Persian/Arabic script and the printer does not declare Arabic shaping support: خیابان ولیعصر، پلاک ۱۲۳</li>
        </ul>
      </div>
      <div class="receipt">================================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
------------------------------------------------
Item                      Qty             Amount
------------------------------------------------
Espresso Single           1    IRR500,000,000.00
------------------------------------------------
Subtotal                       IRR500,550,000.00
Discount                           -IRR50,000.00
Tax                                 IRR45,000.00
TOTAL                          IRR500,545,000.00
------------------------------------------------
Cash                           IRR500,545,000.00
================================================
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com</div>
    </div>

    <div class="card">
      <span class="badge badge-shaped">Hardware Shaped (arabicShaping = true)</span>
      <h2>Persian Script Enabled</h2>
      <div class="clean-box">
        <strong>Firmware Shaping Declared:</strong> Pure Persian lines emitted cleanly as UTF-8 bytes. 0 warnings recorded.
      </div>
      <div class="receipt">کافه فلو تهران
================================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
Table: میز ۴
------------------------------------------------
Item                      Qty             Amount
------------------------------------------------
چای زعفرانی مخصوص         2        IRR500,000.00
  + هل اضافه                        IRR50,000.00
  Note: بدون قند و نبات
Espresso Single           1    IRR500,000,000.00
------------------------------------------------
Subtotal                       IRR500,550,000.00
Discount                           -IRR50,000.00
Tax                                 IRR45,000.00
TOTAL                          IRR500,545,000.00
------------------------------------------------
Cash                           IRR500,545,000.00
================================================
خیابان ولیعصر، پلاک ۱۲۳
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com</div>
    </div>

    <div class="card">
      <span class="badge badge-kot">KOT Ticket (Default vs Shaped)</span>
      <h2>Kitchen Order Ticket Comparison</h2>
      <p style="color: #94a3b8; font-size: 0.85rem;"><strong>Default (unshaped):</strong> skips Persian station & items, keeps English items & control structure</p>
      <div class="receipt">KITCHEN ORDER TICKET

Order: ORD-IR-2026-001
Time: 6:30:00
================================================

1x  Espresso Single

================================================</div>
      <p style="color: #94a3b8; font-size: 0.85rem; margin-top: 1rem;"><strong>Shaped (hardware support):</strong> renders full Persian station & items</p>
      <div class="receipt">KITCHEN ORDER TICKET

Station: آشپزخانه مرکزی
Order: ORD-IR-2026-001
Table: میز ۴
Time: 6:30:00
================================================

2x  چای زعفرانی مخصوص
  + هل اضافه
  ** بدون قند و نبات **
1x  Espresso Single

================================================</div>
    </div>

    <div class="card">
      <span class="badge badge-default">Narrow 58mm (32 Columns)</span>
      <h2>Extreme Currency Values & Column Layout</h2>
      <p style="color: #94a3b8; font-size: 0.85rem;">Preserves large IRR values (e.g. 500,545,000) within 32 columns without column overflow or corruption.</p>
      <div class="receipt">================================
Bill #: INV-IR-2026-001
Date: 1405/5/26 6:30:00
--------------------------------
Item      Qty             Amount
--------------------------------
Espresso..1    IRR500,000,000.00
--------------------------------
Subtotal       IRR500,550,000.00
Discount           -IRR50,000.00
Tax                 IRR45,000.00
TOTAL          IRR500,545,000.00
--------------------------------
Cash           IRR500,545,000.00
================================
Ph: +98 21 1234 5678
Economic Code: IR-TAX-98765
Thank you!
Powered by FloPOS
https://flopos.com</div>
    </div>
  </div>
</body>
</html>

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.

  • npx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts
  • npm run test:printer-api
  • npx ts-node --transpile-only -P tests/tsconfig.json tests/receipt-column-width.test.ts
  • node tests/run-electron-node-test.cjs tests/receipt-printing.test.ts
  • node tests/run-electron-node-test.cjs tests/bills-print-api.test.ts
  • End-to-end receipt and KOT rendering verification comparing default generic ESC/POS printers (arabicShaping: false) against shaped hardware profiles (arabicShaping: true)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

khaira777 and others added 2 commits August 17, 2026 17:17
Add an explicit `arabicShaping` capability flag to printer profiles and
thread it through every raw ESC/POS encoder (receipt, plugin template,
and KOT). Arabic/Persian script is now only emitted when the profile
declares shaping support; otherwise it is skipped with a precise warning
and financial lines keep their ASCII currency fallback (ریال → IRR), so
corrupted or unshaped glyphs can never reach the printer. Defaults to off
(safe) for every existing profile, matching the #273 financial-line
protection.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
@khaira777
khaira777 requested a review from itsbkm as a code owner August 17, 2026 21:34
@khaira777
khaira777 enabled auto-merge (squash) August 17, 2026 21:53
@khaira777
khaira777 merged commit 3b8794b into main Aug 17, 2026
12 checks passed
@khaira777
khaira777 deleted the feat/241-i-persian-thermal-fallback branch August 17, 2026 22:16
@khaira777 khaira777 self-assigned this Aug 19, 2026
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.

1 participant