Class: Thermal::Escpos::Writer
- Inherits:
-
WriterBase
show all
- Extended by:
- Forwardable
- Defined in:
- lib/thermal/escpos/writer.rb
Constant Summary
collapse
- DEFAULT_QR_CODE_SIZE =
400
Constants inherited
from WriterBase
WriterBase::ALIGNMENTS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from WriterBase
#align, #bold, #format, #initialize, #underline
Class Method Details
15
16
17
|
# File 'lib/thermal/escpos/writer.rb', line 15
def self.format
'escpos'
end
|
Instance Method Details
#cut ⇒ Object
45
46
47
48
|
# File 'lib/thermal/escpos/writer.rb', line 45
def cut
seq = supports?(:paper_partial_cut) ? ::Escpos::PAPER_PARTIAL_CUT : ::Escpos::PAPER_FULL_CUT
sequence(seq)
end
|
#feed(lines = 1) ⇒ Object
41
42
43
|
# File 'lib/thermal/escpos/writer.rb', line 41
def feed(lines = 1)
write("\n" * lines)
end
|
#hr(style = nil, width: col_width) ⇒ Object
36
37
38
39
|
# File 'lib/thermal/escpos/writer.rb', line 36
def hr(style = nil, width: col_width)
write_text(hr_char(style) * width)
feed
end
|
#image(path, opts = {}) ⇒ Object
50
51
52
|
# File 'lib/thermal/escpos/writer.rb', line 50
def image(path, opts = {})
write(::Escpos::Image.new(path, opts).to_escpos)
end
|
#print(flush: true, output: nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/thermal/escpos/writer.rb', line 19
def print(flush: true, output: nil)
@buffer = nil
super
feed(5)
cut
if output == :byte_array
flush ? buffer.flush : buffer.to_a
else
flush ? buffer.flush_base64 : buffer.to_base64
end
end
|
#qr_code(url, size = DEFAULT_QR_CODE_SIZE) ⇒ Object
54
55
56
|
# File 'lib/thermal/escpos/writer.rb', line 54
def qr_code(url, size = DEFAULT_QR_CODE_SIZE)
image(::RQRCode::QRCode.new(url).as_png(size: size))
end
|
#text(str, feed: true, replace: nil, no_cjk: false, **_kwargs) ⇒ Object
31
32
33
34
|
# File 'lib/thermal/escpos/writer.rb', line 31
def text(str, feed: true, replace: nil, no_cjk: false, **_kwargs)
write_text(str, replace: replace, no_cjk: no_cjk)
self.feed if feed
end
|