Class: RubyEscPos
- Inherits:
-
Object
- Object
- RubyEscPos
- Defined in:
- lib/ruby-escpos.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
Instance Method Summary collapse
- #barcode(code, width = 64, height = 64, bc = BARCODE_UPC_A, pos = BARCODE_TXT_OFF, font = nil) ⇒ Object
- #cut(cut_type = PAPER_FULL_CUT) ⇒ Object
-
#initialize ⇒ RubyEscPos
constructor
A new instance of RubyEscPos.
- #new_line(lines = 1) ⇒ Object
- #set(align = TXT_ALIGN_LT, font = TXT_FONT_A, font_type = FONT_TYPE_NORMAL, width = 1, height = 1, density = nil) ⇒ Object
- #style(style, align) ⇒ Object
- #text(txt, new_lines = 1) ⇒ Object
Constructor Details
#initialize ⇒ RubyEscPos
Returns a new instance of RubyEscPos.
4 5 6 |
# File 'lib/ruby-escpos.rb', line 4 def initialize @buffer = '' end |
Instance Attribute Details
#buffer ⇒ Object
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, width = 64, height = 64, bc = BARCODE_UPC_A, pos = BARCODE_TXT_OFF, font = nil) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/ruby-escpos.rb', line 80 def (code, width = 64, height = 64, bc = BARCODE_UPC_A, pos = BARCODE_TXT_OFF, font = nil) write TXT_ALIGN_CT write pos write font write bc write code end |
#cut(cut_type = PAPER_FULL_CUT) ⇒ Object
96 97 98 99 |
# File 'lib/ruby-escpos.rb', line 96 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby-escpos.rb', line 40 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 |
#style(style, align) ⇒ 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 |
# File 'lib/ruby-escpos.rb', line 12 def style(style, align) if style == :header style = STYLE_HEADER elsif style == :subheader style = STYLE_SUBHEADER elsif style == :normal style = STYLE_NORMAL elsif style == :footer style = STYLE_FOOTER end if align == :left align = TXT_ALIGN_LT elsif align == :center align = TXT_ALIGN_CT elsif align == :right align = TXT_ALIGN_RT end set( align, style[:font], style[:font_type], style[:width], style[:height] ) end |
#text(txt, new_lines = 1) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/ruby-escpos.rb', line 88 def text(txt, new_lines = 1) @buffer += txt if txt (1..new_lines).each do @buffer += "\n" end end |