Class: ZplRender::Barcode::Qr
- Inherits:
-
Object
- Object
- ZplRender::Barcode::Qr
- Defined in:
- lib/zpl_render/barcode/qr.rb
Overview
QR Code (ZPL ^BQ) backed by rqrcode_core, which implements the full ISO/IEC 18004 encoder (mode detection, Reed-Solomon ECC, mask scoring).
ZPL packs the error-correction level and data-input mode into the ^FD data as a prefix:
^FD<H|Q|M|L><A|M>,data e.g. ^FDQA,https://example.com
Automatic mode (A) treats everything after the comma as data. Manual mode (M) prefixes the data with a character-mode indicator (N / A / Bxxxx / K) which we strip; rqrcode_core re-detects the optimal mode itself, producing an equivalent, scannable symbol. If no valid prefix is present the whole field is encoded using the ECC level from the ^BQ command (newer-firmware behavior).
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ECC_LEVELS =
{ "H" => :h, "Q" => :q, "M" => :m, "L" => :l }.freeze
Class Method Summary collapse
Class Method Details
.encode(field_data, default_ecc: "Q") ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/zpl_render/barcode/qr.rb', line 24 def self.encode(field_data, default_ecc: "Q") data = field_data.to_s ecc = ECC_LEVELS[default_ecc.to_s.upcase] || :q if (m = data.match(/\A([HQML])([AM]),/)) ecc = ECC_LEVELS.fetch(m[1]) rest = data[m[0].length..] || "" data = m[2] == "M" ? strip_manual_mode(rest) : rest end qr = RQRCodeCore::QRCode.new(data, level: ecc) Result.new(modules: qr.modules) end |
.strip_manual_mode(rest) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zpl_render/barcode/qr.rb', line 38 def self.strip_manual_mode(rest) case rest[0] when "N", "A", "K" then rest[1..] || "" when "B" # B is followed by a 4-digit byte count rest[5..] || "" else rest end end |