Class: Languages::Zpl2

Inherits:
Object
  • Object
show all
Defined in:
lib/languages/zpl2.rb,
lib/languages/zpl2/font.rb,
lib/languages/zpl2/text.rb,
lib/languages/zpl2/speed.rb,
lib/languages/zpl2/barcode.rb,
lib/languages/zpl2/document.rb,
lib/languages/zpl2/position.rb,
lib/languages/zpl2/merge_font.rb

Defined Under Namespace

Classes: Barcode1D, Barcode2D, BarcodeFactory, Document, Font, MergeFont, Position, Speed, Text

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Zpl2

Returns a new instance of Zpl2.



11
12
13
14
15
16
17
18
19
# File 'lib/languages/zpl2.rb', line 11

def initialize(data=nil)
  @data = data
  @document = Zpl2::Document.new
  @font = Zpl2::Font.new
  @merge_font = MergeFont.new
  @position = Zpl2::Position[0,0]
  @document << @position
  @document << @merge_font.add({:name => 'B', :height => 15, :width => 15})
end

Instance Method Details

#barcode(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/languages/zpl2.rb', line 55

def barcode(*args)
  opts = args.extract_options!
  code,text = args.pop 2

  opts = opts.merge({:font => @font,:text => text})

  if opts.include? :at
    @document << (@position + Zpl2::Position.from_array(opts[:at]))
  end

  @document << Zpl2::BarcodeFactory.create_barcode(code, opts)
end

#dataObject



85
86
87
# File 'lib/languages/zpl2.rb', line 85

def data
  @data
end

#documentObject



89
90
91
# File 'lib/languages/zpl2.rb', line 89

def document
  @document.render
end

#font(opts = {}, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/languages/zpl2.rb', line 42

def font(opts={},&block)
  if block_given?
    @font = @merge_font.add(opts)
    @document << @font
    self.instance_eval &block
    @font = @merge_font.remove
    @document << @font
  else
    @font = Zpl2::Font.new(opts)
    @document << @font
  end
end

#position(x, y, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/languages/zpl2.rb', line 68

def position(x,y,&block)
  if block_given?
    save = @position
    @position = Zpl2::Position[x,y]
    @document << @position
    self.instance_eval(&block)
    @position = save
  else
    @position = Zpl2::Position[x,y]
  end
  @document << @position
end

#rotate(amount, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/languages/zpl2.rb', line 29

def rotate(amount, &block)
  if block_given?
    @font = @merge_font.add({:rotation => amount})
    @document << @font
    self.instance_eval &block
    @font = @merge_font.remove
    @document << @font
  else
    @font.font_rotation amount
    @document << @font
  end
end

#speed(amount) ⇒ Object



81
82
83
# File 'lib/languages/zpl2.rb', line 81

def speed(amount)
  @document << Zpl2::Speed.new(amount)
end

#text(text, opts = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/languages/zpl2.rb', line 21

def text(text,opts={})
  if opts.include? :at
    @document << (@position + Zpl2::Position.from_array(opts[:at]))
  end
  @document << Zpl2::Text.new(text)
  @document << @position if opts.include?(:at)
end