Skip to content

Refactor barcode object rendering#3

Merged
u8array merged 4 commits intomainfrom
feat/testing-ref
Apr 22, 2026
Merged

Refactor barcode object rendering#3
u8array merged 4 commits intomainfrom
feat/testing-ref

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented Apr 22, 2026

Moves bwip-js related helper functions and constants into separate modules to improve organization and reusability. This includes functions for building bwip options, calculating display sizes, and constants related to ZPL firmware artifacts.

@u8array u8array marked this pull request as draft April 22, 2026 15:26
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the BarcodeObject component by extracting helper functions and constants into dedicated files (bwipHelpers.ts and bwipConstants.ts). It also introduces a suite of integration tests for Labelary synchronization, including new fixtures and scripts. However, the refactoring of barcode logic in bwipHelpers.ts contains several critical regressions and logic errors, such as incorrect check digit calculations, missing barcode-specific options, and broken bcid mappings. Additionally, backup files were accidentally committed, and import statements in BarcodeObject.tsx are misplaced.

Comment thread src/components/Canvas/bwipHelpers.ts Outdated
Comment thread src/components/Canvas/bwipHelpers.ts
Comment thread src/components/Canvas/bwipHelpers.ts Outdated
Comment thread src/components/Canvas/bwipHelpers.ts Outdated
Comment thread src/components/Canvas/bwipHelpers.ts Outdated
Comment thread src/components/Canvas/bwipHelpers.ts
Comment thread src/components/Canvas/BarcodeObject.tsx.bak Outdated
Comment thread src/components/Canvas/BarcodeObject.tsx Outdated
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented Apr 22, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the BarcodeObject component by extracting constants and helper functions into dedicated modules (bwipConstants.ts and bwipHelpers.ts) and centralizing test utilities in a new helpers.ts file. It also introduces an integration test suite to verify ZPL generation and display dimensions against Labelary fixtures, along with a script to fetch these fixtures. Feedback highlights a regression in type safety for the BCID mapping and suggests refactoring a repetitive conditional chain in the new test file to improve maintainability.

Comment thread src/components/Canvas/bwipHelpers.ts Outdated
Comment thread src/test/labelarySync.test.ts
u8array added 4 commits April 22, 2026 19:37
Moves bwip-js related helper functions and constants into separate
modules to improve organization and reusability. This includes functions
for building bwip options, calculating display sizes, and constants
related to ZPL firmware artifacts.
- Restore correct bcid mappings: standard2of5→code2of5, codabar→rationalizedCodabar,
  logmars→code39, gs1databar→databaromni
- Restore 3-param eanCheckDigit(digits, w0, w1) with proper alternating weights
- Restore toCode128BRaw with ^104/^NNN subset-B encoding for Labelary sync
- Restore full buildBwipOptions special-case logic (gs1databar GS1 prefix,
  logmars includecheck, planet padding, pdf417 rowheight/columns/eclevel)
- Restore getDisplaySize with msi/plessey quiet-zone correction (+20 modules)
- Move imports to file top in BarcodeObject.tsx (was after interface definitions)
- Remove .bak files (BarcodeObject.tsx.bak, bwipHelpers.ts.bak, labelarySync.test.ts.bak)
…app tsconfig

- Export BWIP_SCALE from bwipHelpers.ts so BarcodeObject.tsx can import it
- Add BWIP_SCALE to BarcodeObject.tsx import
- Exclude labelarySync.test.ts from tsconfig.app.json — it uses Node.js APIs
  (fs, path, process, Buffer) incompatible with the browser lib target
@u8array u8array marked this pull request as ready for review April 22, 2026 17:38
@u8array u8array merged commit ee72fd4 into main Apr 22, 2026
2 checks passed
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented Apr 22, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors barcode rendering logic by extracting constants and helper functions from BarcodeObject.tsx into dedicated bwipConstants.ts and bwipHelpers.ts modules. It also introduces a robust integration testing suite, including a script to fetch Labelary reference images and a synchronization test to ensure local dimension calculations align with Labelary's output. A regression was identified in the getDisplaySize helper function, where the default case returns raw canvas dimensions instead of applying the necessary coordinate scaling, which could lead to inconsistent rendering for unsupported barcode types.

Comment on lines +270 to +272
default: {
return { w: canvas.width, h: canvas.height };
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The default case in getDisplaySize returns raw canvas dimensions without applying the coordinate system scaling (dotsToPx). This is a regression from the original implementation which returned a scaled placeholder size (200x100 dots). For consistency with other cases and to ensure correct rendering on the Konva stage, the canvas dimensions should be converted from modules to scaled units.

    default: {
      const ratio = dotsToPx(1, scale, dpmm) / BWIP_SCALE;
      return { w: canvas.width * ratio, h: canvas.height * ratio };
    }

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