Class: ZplRenderer::Sanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/zpl_renderer/sanitizer.rb

Overview

Normalizes carrier ZPL quirks before validation/render.

Two repairs are applied:

  1. Invalid field origins such as ^FO464,--^GB2,126,2^FS from carrier ZPL. Invalid numeric params become 0 on printers; for a vertical rule we reuse the last horizontal section-divider Y so the divider lands in the middle band instead of y=0.

  2. Print widths narrower than the requested canvas. The engine draws on a +^PW+-wide canvas and centers it, so fields near the right edge (some templates put rotated text at ^FO791 under ^PW800) are clipped. Widening ^PW to the canvas and shifting ^LH by the same centering offset keeps every field in its original position while leaving nothing cut off.

Defined Under Namespace

Classes: Result

Constant Summary collapse

COMMAND =
/\^(FO|FT)([^,\^]*),([^,\^]*)/i
/\^PW(\d+)/i
LABEL_HOME =
/\^LH(\d+),(\d+)/i
INVERTED_ORIENTATION =
/\^POI/i

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zpl, canvas_dots: nil) ⇒ Sanitizer

Returns a new instance of Sanitizer.



26
27
28
29
30
# File 'lib/zpl_renderer/sanitizer.rb', line 26

def initialize(zpl, canvas_dots: nil)
  @zpl = zpl.to_s
  @canvas_dots = canvas_dots
  @repairs = []
end

Class Method Details

.sanitize(zpl, canvas_dots: nil) ⇒ Object



38
39
40
# File 'lib/zpl_renderer/sanitizer.rb', line 38

def self.sanitize(zpl, canvas_dots: nil)
  new(zpl, canvas_dots: canvas_dots).call
end

Instance Method Details

#callObject



32
33
34
35
36
# File 'lib/zpl_renderer/sanitizer.rb', line 32

def call
  zpl = repair_field_origins(@zpl)
  zpl = expand_print_widths(zpl) if @canvas_dots
  Result.new(zpl: zpl, repairs: @repairs)
end