class Languages::Zpl2::Font

Attributes

height[R]
name[R]
rotation[R]
width[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/languages/zpl2/font.rb, line 6
def initialize(opts = {})
  # defaults
  @name     = opts[:name] || "0"
  @rotation = opts.include?(:rotation) ? font_rotation(opts[:rotation]) : font_rotation(:by_0)
  @height   = opts[:height] || 15
  @width    = opts[:width] || 12
  @name, @height, @width = font_size(opts[:size]) if opts.include?(:size)
  @code = "^CF"
end

Public Instance Methods

block!() click to toggle source
# File lib/languages/zpl2/font.rb, line 36
def block!
  @is_block = true
end
font_args(opts={}) click to toggle source
# File lib/languages/zpl2/font.rb, line 16
def font_args(opts={})
  @name = font_size(opts[:size]) if opts.include? :size
end
font_rotation(amount) click to toggle source
# File lib/languages/zpl2/font.rb, line 24
def font_rotation(amount)
@rotation = case(amount)
                    when :by_90
                      "R"
                    when :by_180
                      "I"
                    when :by_270
                      "B"
                    else
                      "N"
                    end
end
font_size(val) click to toggle source
# File lib/languages/zpl2/font.rb, line 20
def font_size(val)
  val.is_a?(Array) ? val : name_size(val)
end
render() click to toggle source
# File lib/languages/zpl2/font.rb, line 40
def render
  "^A#{@name},#{@rotation},#{@height},#{@width}\n#{set_default}"
end

Private Instance Methods

name_size(val) click to toggle source
# File lib/languages/zpl2/font.rb, line 52
def name_size(val)
  case val
  when :normal
    [self.name,25,25]
  when :small
    [self.name,20,20]
  when :large
    [self.name,40,40]
  when :x_large
    [self.name,60,60]
  else
    [self.name,25,25]
  end
end
set_default() click to toggle source
# File lib/languages/zpl2/font.rb, line 45
def set_default
  if @is_block
    "^FW#{@rotation}^CF#{@name},#{@height},#{@width}\n"
  else
    ""
  end
end