Skip to content

Draw Code 128, EAN, Code 39 and ITF-14 barcodes as vectors - #104

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

Labels carry a Code 128, products an EAN and cartons an ITF-14, but drawing one took another gem plus glue code, and a bitmap scans worse once scaled. This is the second part of #74, after QR codes in #103; DataMatrix comes last.

barcode encodes the data and draws its bars as one path and one fill, in pure Ruby.

  • Five symbologies: Code 128 (sets A, B and C chosen as the text goes, switching to C for runs of digits), EAN-13, EAN-8, Code 39 and ITF-14.
  • Check digits: a missing one is added; a given one is checked, and a wrong one raises with the right digit. Contents a type cannot hold raise too.
  • Sized for scanners: width counts the standard quiet zones, or module_size sets the narrowest bar; height is the bars' height. text: true writes the encoded text under the bars, at text_size.
  • Placed like images: at, or position and vposition, with color and quiet_zone: false. In Gamba's own API, barcode is a box with align.
Proof

test/barcode_test.rb reads every type back with zbar from the page rendered at 150 dpi: fixed contents (all three Code 128 sets, control characters, check digits left out or given) and random ones on a seed, 36 symbols in all. Bar positions and the single fill are checked in the content stream, and the text's glyphs, size and the cursor below them with mutool. An A4 sheet of 24 labels, each with a QR code and an ITF-14, weighs 25.7 KB and renders in 183 ms without JIT. Encoding a 23-character Code 128 takes 0.03 ms. rake test: 1363 runs, 0 failures; RuboCop is clean.


Generated by Claude Code

barcode encodes Code 128 (sets A, B and C chosen as the text goes), EAN-13, EAN-8, Code 39 and ITF-14, adds a missing check digit and checks a given one, and draws the bars as one path and one fill. width counts the quiet zones, module_size sets the narrowest bar, and text: true writes the encoded text under the bars. Gamba's own API takes barcode as a box.

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