Class: ZplRender::Renderer
- Inherits:
-
Object
- Object
- ZplRender::Renderer
- Defined in:
- lib/zpl_render/renderer.rb
Overview
Executes a parsed ZPL command stream and paints labels onto Canvases. One Canvas is produced per ^XA...^XZ format.
Constant Summary collapse
- DEFAULT_MODULE_WIDTH =
2- DEFAULT_RATIO =
3.0- DEFAULT_BARCODE_HEIGHT =
10
Instance Attribute Summary collapse
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false) ⇒ Renderer
constructor
strict: false (default) records recoverable problems in #warnings and keeps rendering; true raises ZplRender::Error on the first problem (bad field data, unsupported command).
- #render(zpl) ⇒ Object
Constructor Details
#initialize(dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false) ⇒ Renderer
strict: false (default) records recoverable problems in #warnings and keeps rendering; true raises ZplRender::Error on the first problem (bad field data, unsupported command).
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zpl_render/renderer.rb', line 16 def initialize(dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false) raise Error, "dpmm must be a positive number (got #{dpmm.inspect})" unless dpmm.is_a?(Numeric) && dpmm.positive? unless width_in.is_a?(Numeric) && width_in.positive? && height_in.is_a?(Numeric) && height_in.positive? raise Error, "label dimensions must be positive numbers (got #{width_in.inspect} x #{height_in.inspect})" end @dpmm = dpmm @strict = strict dpi = (25.4 * dpmm).round # printers advertise 203/300/600 dpi nominal @default_width = (width_in * dpi).floor @default_height = (height_in * dpi).floor @warnings = [] @images = {} # ~DG store, keyed by "R:NAME.GRF" end |
Instance Attribute Details
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/zpl_render/renderer.rb', line 11 def warnings @warnings end |
Instance Method Details
#render(zpl) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zpl_render/renderer.rb', line 31 def render(zpl) commands = Parser.parse(zpl) labels = [] reset_label_state commands.each do |cmd| case cmd.name when "XA" reset_label_state when "XZ" flush_field labels << @canvas if @canvas @canvas = nil else execute(cmd) end end labels << @canvas if @canvas && dirty? # tolerate missing ^XZ labels end |