Skip to content

Draw DataMatrix codes as vectors, encoded in pure Ruby - #105

Merged
czj merged 1 commit into
mainfrom
claude/confident-pasteur-jz0fj6
Nov 13, 2026
Merged

czj merged 1 commit into
mainfrom
claude/confident-pasteur-jz0fj6

Conversation

@czj

@czj czj commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Carriers ask for a DataMatrix on parcel labels, and Gamba drew QR codes and linear barcodes but not that. This is the last part of #74, after QR codes in #103 and linear barcodes in #104. Closes #74.

data_matrix encodes the data as a square ECC 200 symbol and draws it as vector rectangles, with one path and one fill and no dependency.

  • All square sizes: the smallest of the 24, from 10×10 to 144×144, that holds the data; larger sizes get several data regions and interleaved Reed-Solomon blocks. Data past 1558 codewords raises.
  • Compact digits: ASCII encodation puts digits two to a codeword; bytes past 127 go behind an upper shift.
  • Same options as QR codes: size (with its one-module quiet zone), module_size, at, position, vposition, quiet_zone and color. There is no level: error correction is fixed by the size.
  • One drawing for both: QR codes and DataMatrix share draw_matrix_code and, in Gamba's own API, one box.
  • Read back in CI: CI installs dmtx-utils, whose dmtxread reads every test symbol back from the rendered page.
Proof

test/data_matrix_test.rb reads 11 symbols back with dmtxread from pages rendered at 150 dpi: a letter, digits, a URL, UTF-8 bytes, and random ASCII of 10 to 1500 characters on a seed, from 10×10 to 144×144. Sizes are pinned (6 digits fill a 10×10, 3116 fill a 144×144, 3117 raise), along with the one fill and the solid bottom edge's position in the content stream, and a box in Gamba's own API. In a scratch run, all 15 symbols I drew decoded, from one character to the largest size. The QR and barcode tests still pass. rake test: 1369 runs, 0 failures; RuboCop is clean.


Generated by Claude Code

data_matrix encodes the data in ASCII encodation, digits two to a codeword, in the smallest of the 24 square ECC 200 sizes that holds it, with Reed-Solomon blocks interleaved as the larger sizes need, and draws it as one path and one fill with a one-module quiet zone. QR codes and DataMatrix share their drawing and, in Gamba's own API, one box.

CI installs dmtx-utils, whose dmtxread reads every symbol the tests draw back from the rendered page.

Assisted-by: Claude [Claude Code]
@czj
czj merged commit 2595729 into main Nov 13, 2026
8 checks passed
@czj
czj deleted the claude/confident-pasteur-jz0fj6 branch November 13, 2026 09:39
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.

No QR codes or barcodes, though invoices and labels need them

2 participants