Class: RubyEscPos

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-escpos.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRubyEscPos

Returns a new instance of RubyEscPos.



4
5
6
# File 'lib/ruby-escpos.rb', line 4

def initialize
  @buffer = ''
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



2
3
4
# File 'lib/ruby-escpos.rb', line 2

def buffer
  @buffer
end

Instance Method Details

#barcode(code, bc = BARCODE_UPC_A, pos = BARCODE_TXT_BLW, font = BARCODE_FONT_A, width, height) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/ruby-escpos.rb', line 52

def barcode(code, bc = BARCODE_UPC_A, pos = BARCODE_TXT_BLW, font = BARCODE_FONT_A, width, height)
  write TXT_ALIGN_CT
  write pos
  write font
  write bc
  write code
end

#cut(cut_type = PAPER_FULL_CUT) ⇒ Object



68
69
70
71
# File 'lib/ruby-escpos.rb', line 68

def cut(cut_type = PAPER_FULL_CUT)
  write "\n\n\n\n\n\n"
  write cut_type
end

#new_line(lines = 1) ⇒ Object



8
9
10
# File 'lib/ruby-escpos.rb', line 8

def new_line(lines = 1)
  text nil, lines
end

#set(align = TXT_ALIGN_LT, font = TXT_FONT_A, font_type = FONT_TYPE_NORMAL, width = 1, height = 1, density = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby-escpos.rb', line 12

def set(align = TXT_ALIGN_LT, font = TXT_FONT_A, font_type = FONT_TYPE_NORMAL, width = 1, height = 1, density = nil)
  write align

  if height == 2 && width == 2
    write TXT_NORMAL
    write TXT_4SQUARE
  elsif height == 2 && width != 2
    write TXT_NORMAL
    write TXT_2HEIGHT
  elsif width == 2 && height != 2
    write TXT_NORMAL
    write TXT_2WIDTH
  else
    write TXT_NORMAL
  end

  if font_type == FONT_TYPE_BOLD
    write TXT_BOLD_ON
    write TXT_UNDERL_OFF
  elsif font_type == FONT_TYPE_UNDERLINE
    write TXT_BOLD_OFF
    write TXT_UNDERL_ON
  elsif font_type == FONT_TYPE_UNDERLINE_2
    write TXT_BOLD_OFF
    write TXT_UNDERL2_ON
  elsif font_type == FONT_TYPE_BOLD_UNDERLINE
    write TXT_BOLD_ON
    write TXT_UNDERL_ON
  elsif font_type == FONT_TYPE_BOLD_UNDERLINE_2
    write TXT_BOLD_ON
    write TXT_UNDERL2_ON
  else
    write TXT_BOLD_OFF
    write TXT_UNDERL_OFF
  end

  write font
  write density if density
end

#text(txt, new_lines = 1) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/ruby-escpos.rb', line 60

def text(txt, new_lines = 1)
  @buffer += txt if txt

  (1..new_lines).each do
    @buffer += "\n"
  end
end