Class: ZplScaler::Scaler

Inherits:
Object
  • Object
show all
Defined in:
lib/zpl-scaler.rb

Overview

TODO: doc It works by parsing ZPL commands, then edit the parameters of specific commands to scale the coordinates to the new dpi

NOTE: Cannot work for embedded images

Constant Summary collapse

COMMANDS_PARAM_INDEXES_TO_SCALE =
{
  # ^MN - Media Tracking
  #
  # Param 0: media being used
  # Param 1: black mark offset in dots (optional)
  "MN" => [1],

  # ^BY - Bar Code Field Default
  #
  # Param 0: module width in dots
  # Param 1: wide bar to narrow bar width ratio (float)
  # Param 2: bar code height in dots
  "BY" => [0, 2],

  # ^FO - Field Origin
  #
  # Param 0: x-axis location in dots
  # Param 1: y-axis location in dots
  # Param 2: justification (enum)
  "FO" => [0, 1],

  # ^B2 - Interleaved 2 of 5 Bar Code
  #
  # Param 0: orientation (enum)
  # Param 1: bar code height in dots
  # Param 2: print interpretation line above code (bool)
  "B2" => [1],

  # ^GB - Graphic Box
  #
  # Param 0: box width in dots
  # Param 1: box height in dots
  # Param 2: border thickness
  # Param 3: line color (enum)
  # Param 4: degree of corner rounding (enum)
  "GB" => [0, 1, 2],

  # ^BC - Code 128 Bar Code (Subsets A, B, and C)
  #
  # Param 0: orientation (enum)
  # Param 1: bar code height in dots
  # Param 2: print interpretation line (bool)
  # Param 3: print interpretation line above code (bool)
  # Param 4: UCC check digit (bool)
  # Param 5: mode (enum)
  "BC" => [1],
}

Class Method Summary collapse

Class Method Details

.ratio_scale(zpl_content, scale_ratio) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/zpl-scaler.rb', line 143

def self.ratio_scale(zpl_content, scale_ratio)
  reader = ZplReader.new zpl_content
  scaled_zpl = StringIO.new

  reader.each_command do |cmd|
    scale_cmd!(cmd, scale_ratio)
    scaled_zpl << cmd.to_zpl_string
  end

  scaled_zpl.string
end