Class: ZplRender::Barcode::Pdf417
- Inherits:
-
Object
- Object
- ZplRender::Barcode::Pdf417
- Defined in:
- lib/zpl_render/barcode/pdf417.rb
Overview
PDF417 encoder (ISO/IEC 15438) for ZPL ^B7.
Data is encoded with byte compaction (latches 924/901) plus numeric compaction (902) for long digit runs. That always reproduces the input bytes exactly on decode, which is what matters for scanners; a Zebra printer may pick text compaction for the same data, producing a denser but equivalently-decoding symbol.
Defined Under Namespace
Classes: Symbolinfo
Constant Summary collapse
- START =
17 modules
0x1fea8- STOP =
18 modules
0x3fa29- PADDING =
900- LATCH_BYTE_MULTIPLE6 =
924- LATCH_BYTE =
901- LATCH_NUMERIC =
902- MAX_CODE_WORDS =
928
Class Method Summary collapse
-
.encode(data, security: nil, columns: 0, rows: 0, truncated: false) ⇒ Object
Returns Symbolinfo where patterns is an array of rows, each row an array of [pattern_int, module_count] ready to draw left-to-right.
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(data, security, columns, rows, truncated) ⇒ Pdf417
constructor
A new instance of Pdf417.
Constructor Details
#initialize(data, security, columns, rows, truncated) ⇒ Pdf417
Returns a new instance of Pdf417.
31 32 33 34 35 36 37 |
# File 'lib/zpl_render/barcode/pdf417.rb', line 31 def initialize(data, security, columns, rows, truncated) @data = data @security = security @columns = columns.to_i @rows = rows.to_i @truncated = truncated end |
Class Method Details
.encode(data, security: nil, columns: 0, rows: 0, truncated: false) ⇒ Object
Returns Symbolinfo where patterns is an array of rows, each row an array of [pattern_int, module_count] ready to draw left-to-right.
27 28 29 |
# File 'lib/zpl_render/barcode/pdf417.rb', line 27 def self.encode(data, security: nil, columns: 0, rows: 0, truncated: false) new(data.to_s.b, security, columns, rows, truncated).encode end |
Instance Method Details
#encode ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zpl_render/barcode/pdf417.rb', line 39 def encode data_words = compact(@data) level = @security || recommended_level(data_words.length) level = level.clamp(0, 8) ec_count = 2**(level + 1) cols, row_count = geometry(data_words.length, ec_count) pad_count = cols * row_count - (data_words.length + ec_count + 1) descriptor = 1 + data_words.length + pad_count words = [descriptor] + data_words + [PADDING] * pad_count words += error_correction(words, ec_count, level) patterns = words.each_slice(cols).with_index.map do |row_words, row_no| cluster = Pdf417Tables::CLUSTER_PATTERNS[row_no % 3] row = [[START, 17], [cluster[left_indicator(row_no, row_count, cols, level)], 17]] row_words.each { |w| row << [cluster[w], 17] } if @truncated row << [1, 1] # single-module termination bar else row << [cluster[right_indicator(row_no, row_count, cols, level)], 17] row << [STOP, 18] end row end Symbolinfo.new(rows: row_count, cols: cols, patterns: patterns, truncated: @truncated) end |