Skip to content

fix: implement bounding-box ^FR for text and barcode fields#8

Open
roberto976 wants to merge 3 commits into
GOODBOY008:mainfrom
roberto976:fix/fr-field-reverse-bounding-box-v2
Open

fix: implement bounding-box ^FR for text and barcode fields#8
roberto976 wants to merge 3 commits into
GOODBOY008:mainfrom
roberto976:fix/fr-field-reverse-bounding-box-v2

Conversation

@roberto976
Copy link
Copy Markdown
Contributor

Summary

Implements ZPL ^FR (Field Reverse Print) correctly for text and barcode elements, matching Zebra/Labelary output.

Problem: Previous ^FR only XOR-inverted drawn pixels. For text on a white canvas, this produced no visible change (white text on white background, after inversion: black text on white — unchanged). For ^GB (graphic boxes) the XOR was correct because they fill their entire bounding box.

Fix: dual behavior based on element type

  • Text / barcodes (^FR): invert the drawn-pixel bounding box on the canvas (black background), then re-invert where content pixels are (restores original color). Net: white content on black background.
  • Graphic elements (^GB, ^GC, diagonal lines, graphic fields): pixel-level XOR — unchanged, already correct.

Impact: Correos Express labels now show correct white-on-black routing zones. GLS Italy ^FR on ^GB remains correct.

Changes

  • src/images/reverse_print.rs — add use_bounding_box mode; update docstring to clarify drawn-pixel bounds vs full field rect; note O(W×H) scan for future optimization
  • src/drawers/renderer.rs — select mode per element type; update comment to cover all non-text/barcode elements
  • src/barcodes/datamatrix.rs — add enforce_width_in(columns) alongside enforce_height_in(rows) to fully apply ^BX rectangular sizing (Copilot review fix)

Notes

Test plan

  • cargo build — clean
  • cargo test -- golden_amazonshipping — ok
  • cargo test -- datamatrix — 2/2 unit tests pass
  • Full golden suite pass on maintainer CI

roberto976 and others added 3 commits April 13, 2026 17:43
^FR (Field Reverse Print) now correctly inverts the entire field area
for text and barcode elements: black background + white content.

Previously, ^FR only XOR-inverted pixels where the element drew
something (opaque mask pixels). This worked for ^GB (graphic boxes,
which fill their bounding box) but produced no visible change for
text fields on a white canvas.

The fix uses dual behavior:
- Text/barcode ^FR: inverts the bounding box, then re-inverts where
  content pixels are (net: black background + original-color content)
- Graphic box ^FR: uses the original pixel-level XOR (unchanged)

This distinction is necessary because ^GB fills its entire bounding
box — bounding-box inversion would double-invert to no change.

Updated golden: glsdk_return.png (^FR on ^GB, minor pixel diff).

Impact: Correos Express labels now show correct white-on-black routing
zones, matching Labelary reference output.
- datamatrix: add enforce_width_in(columns) alongside enforce_height_in(rows)
  so ^BX rectangular sizing constraints are fully applied
- reverse_print: clarify docstring — bounding box is drawn-pixel bounds,
  not full field layout rect (^FB width / quiet zones not included)
- reverse_print: add note on O(W*H) scan cost per ^FR field (future opt)
- renderer: update comment to cover all non-text/barcode elements
  (^GC, diagonal lines, graphic fields), not only graphic boxes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@GOODBOY008 GOODBOY008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roberto976 The file testdata/glsdk_return.png should remain unchanged, as the PNG files in the top-level testdata directory are generated by Labelary (web).

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.

2 participants