You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(print): receipt logo raster & universal upload - #1437
Implement the receipt logo upload and thermal printing fixes (tracked in #1428):
Fix [Logo] text overwriting the logo bitmap on non-Latin / RTL receipts and emit logo on compact receipts (main/printers/document-classic.ts, main/printers/raster-renderer.ts, main/printers/document-compact.ts):
In main/printers/document-classic.ts: in case 'business-header', emit {RAW_BYTES:...} into segment.main without pushing '[Logo]' into segment.sourceLines.main or segment.sourceControlLines.main. In emit(), exclude leading {RAW_BYTES:...} lines from the options.rasterGroups range (adjusting lineIndex and lineCount to cover only the text lines in segment[part], and skipping options.rasterGroups.push if a segment part has only {RAW_BYTES:...} lines and no text lines) so non-Latin store headers (such as Persian/Farsi) rasterize only the text lines and leave the GS v 0 logo bitmap intact.
In main/printers/raster-renderer.ts: guard stripRasterControlTokens() and requestForRasterLine() to skip {RAW_BYTES:...} lines just like {INIT} / {CUT} / {FEED} so a raw-bytes command line is never classified as unrepresentable text or sent to Chromium for text rendering.
In main/printers/document-compact.ts: emit header?.logoRaster{RAW_BYTES:...} before headerStart so Compact receipts also print the store logo on backend thermal printers while keeping markGroup('business-header', headerStart, ...) scoped strictly to header?.name.
Fix the 5 MB vs. 250 KB limit and support all image formats automatically (frontend/src/lib/printer/logo-processor.ts, shared/print/image-raster.ts):
Accept all browser-decodable image formats (image/*, including PNG, JPEG, WebP, BMP, GIF, SVG, AVIF, ICO).
Automatically trim surrounding transparent/white margins (leaving a small 4px breathing margin), apply auto-contrast normalization before 1-bit Floyd-Steinberg dithering, and cap height (240 dots max) alongside width (384/576 dots) so any logo (including square images with large white margins like 576x576) converts cleanly without external tools.
Stop duplicating originalDataUrl inside receipt_logo_raster JSON (originalDataUrl: '' in ReceiptLogoData, while parseReceiptLogoData() continues to accept both empty and populated originalDataUrl for backward compatibility) and adaptively compress originalDataUrl (PNG first, falling back to WebP/JPEG at decreasing quality 0.85, 0.7, 0.5 if > 200_000 chars) so any image up to 5 MB stays well below the 250 KB database cap.
Settings UI and UX (frontend/src/components/settings/GeneralSettingsTab.tsx, frontend/src/app/(dashboard)/settings/page.tsx):
Change file input accept in GeneralSettingsTab.tsx to "image/*,.bmp,.svg,.webp,.png,.jpg,.jpeg,.gif,.avif".
Show the 1-bit thermal preview alongside the uploaded logo in GeneralSettingsTab.tsx and automatically enable billShowLogo (bill_show_logo) when a logo is uploaded and saved in saveBusinessInfo so merchants do not have to hunt for a separate toggle in the Printers tab.
Exclude {RAW_BYTES:...} logo lines from business-header raster groups and text rasterization requests in main/printers/document-classic.ts and main/printers/raster-renderer.ts so non-Latin store headers do not overwrite GS v 0 logo bitmaps, and emit header.logoRaster before headerStart on compact receipts in main/printers/document-compact.ts.
Trim transparent/white logo margins (findLogoContentBounds()), normalize grayscale contrast (normalizeGrayscaleContrast()), cap thermal variants at 240 dots tall, omit duplicate originalDataUrl from receipt_logo_raster, and adaptively compress receipt_logo data URLs below the 250 KB storage limit across shared/print/image-raster.ts and frontend/src/lib/printer/logo-processor.ts.
Accept all browser-decodable image formats (image/*), render the 1-bit thermal preview alongside the uploaded logo in GeneralSettingsTab.tsx, and automatically enable bill_show_logo when saving a newly uploaded logo unless the merchant toggled logo visibility in the session (shouldAutoEnableBillShowLogo()).
Risk Assessment
✅ Low: The changes cleanly isolate thermal logo raw-byte bands from non-Latin/RTL text rasterization, add bounded logo preprocessing and payload compression within existing settings limits, and cover all new paths with behavioral tests.
Testing
Ran npm run build, npm run build:frontend, npm run test:print-document, npm run test:raster, and node scripts/docs/check-docs.cjs --links --index --policy && git diff --check, then drove all 5 scenarios live against an isolated Electron app instance and a disposable TCP thermal printer server with UI screenshots and ESC/POS byte verification; all checks and scenarios passed and all temporary build/test artifacts inside the worktree were cleaned up.
Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario
Result
Live
Evidence
Merchant uploads an SVG logo in Settings > Store Details: file input accepts all supported formats, trims padding, caps height at <= 240 dots, renders the 1-bit dithered thermal preview alongside the…
Uploading and saving a store logo in Store Details automatically enables the Store Logo switch (bill_show_logo) on the Printers tab, while preserving an explicit merchant toggle OFF override before sa…
Adversarial large noisy image upload (> 2 MB PNG) is adaptively compressed into a WebP/JPEG data URL under the 200 KB threshold and accepted by PUT /api/settings/business without triggering the 250 KB…
Printing a Classic bill with non-Latin/RTL (Persian) business details to a thermal network printer emits the exact GS v 0 logo bitmap bytes in the header followed by rasterized RTL text bands without…
Printing a Compact bill with non-Latin/RTL (Persian) business details to a thermal network printer emits the exact GS v 0 logo bitmap bytes at the top of the compact receipt followed by rasterized RTL…
Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario
Result
Live
Evidence
Merchant uploads an SVG logo in Settings > Store Details: file input accepts all supported formats, trims padding, caps height at <= 240 dots, renders the 1-bit dithered thermal preview alongside the…
Uploading and saving a store logo in Store Details automatically enables the Store Logo switch (bill_show_logo) on the Printers tab, while preserving an explicit merchant toggle OFF override before sa…
Adversarial large noisy image upload (> 2 MB PNG) is adaptively compressed into a WebP/JPEG data URL under the 200 KB threshold and accepted by PUT /api/settings/business without triggering the 250 KB…
Printing a Classic bill with non-Latin/RTL (Persian) business details to a thermal network printer emits the exact GS v 0 logo bitmap bytes in the header followed by rasterized RTL text bands without…
Printing a Compact bill with non-Latin/RTL (Persian) business details to a thermal network printer emits the exact GS v 0 logo bitmap bytes at the top of the compact receipt followed by rasterized RTL…
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.
• Preserve logo bitmaps beside non-Latin headers and print logos on compact receipts.
• Trim and compress uploaded images to fit settings limits and improve thermal output.
• Preview the thermal logo and enable bill logos when a new upload is saved.
The following are alternative approaches to this PR:
1. Process logos on the server
➕ Would make image conversion consistent across browsers.
➕ Could centralize upload-size enforcement and thermal variant generation.
➖ Requires a new upload pipeline and server-side image decoder.
➖ Moves source-image transfer and processing into the backend.
Recommendation: Keep browser-side processing for this fix: it fits the existing settings flow and avoids adding a backend image pipeline. Shared pure raster helpers keep the thermal transformations independently testable.
Files changed (10) +656 / -55
Enhancement (3) +122 / -5
page.tsxEnable bill logos when a new upload is saved+16/-2
Enable bill logos when a new upload is saved
• Sends bill_show_logo with changed logo settings and synchronizes the printing form and receipt settings after save. An upload callback enables the local printing toggle immediately.
GeneralSettingsTab.tsxShow a thermal preview beside uploaded logos+20/-3
Show a thermal preview beside uploaded logos
• Displays a preview reconstructed from the stored raster variant, broadens the file picker to image formats, and notifies the settings page after a successful upload.
logo-processor.tsTrim, rasterize, and compress uploaded logos+123/-26
Trim, rasterize, and compress uploaded logos
• Crops white margins, caps thermal dimensions, normalizes contrast, and generates 384- and 576-dot variants. Adaptively encodes a smaller display data URL without duplicating it in raster JSON, and can reconstruct a thermal preview.
receipt-logo-printing.test.tsCover logo preservation and decoupled raster storage+363/-7
Cover logo preservation and decoupled raster storage
• Tests crop and contrast helpers, empty originalDataUrl compatibility, compact logo output, and preservation of exact logo bytes beside Persian headers. Also verifies that business settings accept and return the decoupled raster payload and enabled bill-logo flag.
printing.mdDocument the revised receipt-logo pipeline+12/-6
Document the revised receipt-logo pipeline
• Describes trimming, contrast normalization, size limits, separate stored image and raster payloads, and logo emission on classic and compact receipts.
1. Uploading a logo turns on bill logos before save✓ Resolved
Description
onLogoUploaded immediately sets posSettings.billShowLogo in the persisted POS store and marks
printingForm.billShowLogo true, although the replacement logo is still only in the unsaved form.
If the merchant prints before saving, abandons or resets the upload, or the business PUT fails,
bills can use the previously stored logo, and a later printing save can write bill_show_logo: true
without the merchant choosing it.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The upload callback updates the form’s logo fields but also changes the live visibility flag before
a save succeeds. The POS store persists that flag separately from the previously stored logo, and
the printer hook reads both from the store. The business save handler already enables logo printing
after a successful PUT through enableLogoOnSave, making the upload-time store mutation
unnecessary.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`onLogoUploaded` enables logo printing in the persisted POS store and dirties the printing form before the replacement logo is saved. An unsaved or failed upload can therefore expose the previously stored logo and cause a later printing save to persist the enabled flag.
## Fix Focus Areas
- frontend/src/app/(dashboard)/settings/page.tsx[4097-4101]
- frontend/src/app/(dashboard)/settings/page.tsx[3649-3662]
## Recommended Fix
Remove the `posSettings.setBillShowLogo(true)` and `setPrintingForm` calls from `onLogoUploaded`; keep at most a UI hint during upload. Rely on the existing `enableLogoOnSave` path after a successful business PUT to update `printingForm`, `savedPrinting`, and `hydrateReceiptSettings`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Saving a logo overrides a visibility choice✓ Resolved
Description
saveBusinessInfo sends bill_show_logo: true whenever the logo changed, without checking whether
the merchant subsequently turned Store Logo off. If they upload a logo, disable its visibility in
Bill Content, and then save Store settings, the request and success handler turn that setting back
on.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The Bill Content toggle allows the merchant to set printingForm.billShowLogo to false, but the new
business-save condition depends only on the logo values and then writes true to the server and local
printing state.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Saving an uploaded logo unconditionally re-enables Store Logo, even if the merchant explicitly turned it off after uploading.
## Fix Focus Areas
- frontend/src/app/(dashboard)/settings/page.tsx[3581-3584]
- frontend/src/app/(dashboard)/settings/page.tsx[3601-3605]
- frontend/src/app/(dashboard)/settings/page.tsx[3649-3661]
## Recommended Fix
Track whether visibility was explicitly changed after upload, and only auto-enable it on save when that choice has not been overridden. Keep the request, local printing form, saved form, and POS store consistent.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
khaira777
changed the title
fix(printers): fix receipt logo thermal raster and upload processing
fix(print): receipt logo raster & universal upload
Nov 3, 2026
khaira777
changed the title
fix(print): receipt logo raster & universal upload
fix(printers): fix receipt logo thermal rendering and upload processing
Nov 3, 2026
khaira777
changed the title
fix(printers): fix receipt logo thermal rendering and upload processing
fix(print): receipt logo raster & universal upload
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Implement the receipt logo upload and thermal printing fixes (tracked in #1428):
[Logo]text overwriting the logo bitmap on non-Latin / RTL receipts and emit logo on compact receipts (main/printers/document-classic.ts,main/printers/raster-renderer.ts,main/printers/document-compact.ts):main/printers/document-classic.ts: incase 'business-header', emit{RAW_BYTES:...}intosegment.mainwithout pushing'[Logo]'intosegment.sourceLines.mainorsegment.sourceControlLines.main. Inemit(), exclude leading{RAW_BYTES:...}lines from theoptions.rasterGroupsrange (adjustinglineIndexandlineCountto cover only the text lines insegment[part], and skippingoptions.rasterGroups.pushif a segment part has only{RAW_BYTES:...}lines and no text lines) so non-Latin store headers (such as Persian/Farsi) rasterize only the text lines and leave theGS v 0logo bitmap intact.main/printers/raster-renderer.ts: guardstripRasterControlTokens()andrequestForRasterLine()to skip{RAW_BYTES:...}lines just like{INIT}/{CUT}/{FEED}so a raw-bytes command line is never classified as unrepresentable text or sent to Chromium for text rendering.main/printers/document-compact.ts: emitheader?.logoRaster{RAW_BYTES:...}beforeheaderStartso Compact receipts also print the store logo on backend thermal printers while keepingmarkGroup('business-header', headerStart, ...)scoped strictly toheader?.name.frontend/src/lib/printer/logo-processor.ts,shared/print/image-raster.ts):image/*, including PNG, JPEG, WebP, BMP, GIF, SVG, AVIF, ICO).240dots max) alongside width (384/576dots) so any logo (including square images with large white margins like576x576) converts cleanly without external tools.originalDataUrlinsidereceipt_logo_rasterJSON (originalDataUrl: ''inReceiptLogoData, whileparseReceiptLogoData()continues to accept both empty and populatedoriginalDataUrlfor backward compatibility) and adaptively compressoriginalDataUrl(PNG first, falling back to WebP/JPEG at decreasing quality0.85,0.7,0.5if >200_000chars) so any image up to 5 MB stays well below the 250 KB database cap.frontend/src/components/settings/GeneralSettingsTab.tsx,frontend/src/app/(dashboard)/settings/page.tsx):acceptinGeneralSettingsTab.tsxto"image/*,.bmp,.svg,.webp,.png,.jpg,.jpeg,.gif,.avif".GeneralSettingsTab.tsxand automatically enablebillShowLogo(bill_show_logo) when a logo is uploaded and saved insaveBusinessInfoso merchants do not have to hunt for a separate toggle in the Printers tab.What Changed
Fixes #1428
{RAW_BYTES:...}logo lines frombusiness-headerraster groups and text rasterization requests inmain/printers/document-classic.tsandmain/printers/raster-renderer.tsso non-Latin store headers do not overwriteGS v 0logo bitmaps, and emitheader.logoRasterbeforeheaderStarton compact receipts inmain/printers/document-compact.ts.findLogoContentBounds()), normalize grayscale contrast (normalizeGrayscaleContrast()), cap thermal variants at240dots tall, omit duplicateoriginalDataUrlfromreceipt_logo_raster, and adaptively compressreceipt_logodata URLs below the 250 KB storage limit acrossshared/print/image-raster.tsandfrontend/src/lib/printer/logo-processor.ts.image/*), render the 1-bit thermal preview alongside the uploaded logo inGeneralSettingsTab.tsx, and automatically enablebill_show_logowhen saving a newly uploaded logo unless the merchant toggled logo visibility in the session (shouldAutoEnableBillShowLogo()).Risk Assessment
✅ Low: The changes cleanly isolate thermal logo raw-byte bands from non-Latin/RTL text rasterization, add bounded logo preprocessing and payload compression within existing settings limits, and cover all new paths with behavioral tests.
Testing
Ran
npm run build,npm run build:frontend,npm run test:print-document,npm run test:raster, andnode scripts/docs/check-docs.cjs --links --index --policy && git diff --check, then drove all 5 scenarios live against an isolated Electron app instance and a disposable TCP thermal printer server with UI screenshots and ESC/POS byte verification; all checks and scenarios passed and all temporary build/test artifacts inside the worktree were cleaned up.Evidence: Live Electron + TCP printer verification report (JSON)
{ "acceptAttribute": "image/*,.bmp,.svg,.webp,.png,.jpg,.jpeg,.gif,.avif", "svgUpload": { "autoEnabledBillShowLogo": true, "decoupledOriginalDataUrl": "", "variant384": { "width": 300, "height": 220 }, "variant576": { "width": 300, "height": 220 } }, "noisyLargeImageUpload": { "inputFileBytes": 2023391, "compressedDataUrlLength": 65251, "compressedMimePrefix": "data:image/webp;base64,Ukl", "billShowLogoRespectsMerchantOverrideOff": false }, "liveThermalPrintClassicPersian": { "httpStatus": 200, "totalEscPosBytes": 17246, "gsV0BandCount": 5, "logoGsV0PreservedExact": true, "firstBand": { "widthDots": 384, "heightDots": 200, "inkPixels": 36586 }, "secondBand": { "widthDots": 384, "heightDots": 20, "inkPixels": 3941 } }, "liveThermalPrintCompactPersian": { "httpStatus": 200, "totalEscPosBytes": 14225, "gsV0BandCount": 4, "logoGsV0PreservedExact": true, "firstBand": { "widthDots": 384, "heightDots": 200, "inkPixels": 36586 }, "secondBand": { "widthDots": 384, "heightDots": 20, "inkPixels": 3941 } } }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.
npm run build && npm run build:frontendnpm run test:print-document (tests/print-document.test.ts + tests/receipt-logo-printing.test.ts under Electron Node)npm run test:raster (tests/raster-printing.test.ts + tests/raster-renderer-electron.test.cjs under Electron)node scripts/docs/check-docs.cjs --links --index --policy && git diff --checkLive isolated Electron app + Playwright + disposable TCP thermal printer verification covering SVG logo upload, 1-bit preview UI, automatic bill_show_logo activation, merchant toggle override, >2 MB noisy PNG adaptive compression, and Classic + Compact Persian thermal receipt printing✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.