Class: Thermal::Stargraphic::Writer
- Inherits:
-
WriterBase
- Object
- WriterBase
- Thermal::Stargraphic::Writer
- Defined in:
- lib/thermal/stargraphic/writer.rb
Overview
TODO: image buffer TODO: page limit
Constant Summary collapse
- DOT_WIDTH =
576- LINE_HEIGHT =
34- PAGE_LENGTH =
32_000- MAX_BYTES =
Star API allows 500KB max
500_000
Constants inherited from WriterBase
Class Method Summary collapse
-
.font ⇒ Object
Persists font as singleton.
- .format ⇒ Object
Instance Method Summary collapse
- #bold ⇒ Object
- #cut ⇒ Object
- #feed(lines = 1) ⇒ Object
-
#hr(style = nil, width: col_width) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #image(path) ⇒ Object
-
#initialize(profile) ⇒ Writer
constructor
A new instance of Writer.
- #print(flush: true) ⇒ Object
- #qr_code(url) ⇒ Object
- #text(str, feed: true, replace: nil, **_kwargs) ⇒ Object
-
#underline(weight: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Methods inherited from WriterBase
Constructor Details
Class Method Details
.font ⇒ Object
Persists font as singleton
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/thermal/stargraphic/writer.rb', line 199 def font @font ||= if OS.windows? 'Sans' else font_list = begin `fc-list` rescue StandardError '' end case font_list when /NotoSans/ then 'NotoSans' else 'Sans' end end end |
.format ⇒ Object
19 20 21 |
# File 'lib/thermal/stargraphic/writer.rb', line 19 def self.format 'stargraphic' end |
Instance Method Details
#bold ⇒ Object
44 45 46 47 48 |
# File 'lib/thermal/stargraphic/writer.rb', line 44 def bold @bold = true yield @bold = false end |
#cut ⇒ Object
71 72 73 74 |
# File 'lib/thermal/stargraphic/writer.rb', line 71 def cut seq_set_em_mode seq_exec_em end |
#feed(lines = 1) ⇒ Object
56 57 58 |
# File 'lib/thermal/stargraphic/writer.rb', line 56 def feed(lines = 1) feed_rows(lines * LINE_HEIGHT) end |
#hr(style = nil, width: col_width) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
39 40 41 42 |
# File 'lib/thermal/stargraphic/writer.rb', line 39 def hr(style = nil, width: col_width) # rubocop:disable Lint/UnusedMethodArgument append_image(hr_image(style)) # append_raw(hr_seq(style)) end |
#image(path) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/thermal/stargraphic/writer.rb', line 60 def image(path) width, height = ::MiniMagick::Image.open(path).dimensions output, = Open3.capture3("convert #{path} -depth 1 R:-", binmode: true) output = output.chomp append_image([width, height, output]) end |
#print(flush: true) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/thermal/stargraphic/writer.rb', line 23 def print(flush: true) seq_init_raster_mode seq_enter_raster_mode seq_set_page_length super feed(5) cut finalize(flush: flush) end |
#qr_code(url) ⇒ Object
67 68 69 |
# File 'lib/thermal/stargraphic/writer.rb', line 67 def qr_code(url) append_image(qr_code_image(url)) end |
#text(str, feed: true, replace: nil, **_kwargs) ⇒ Object
33 34 35 36 37 |
# File 'lib/thermal/stargraphic/writer.rb', line 33 def text(str, feed: true, replace: nil, **_kwargs) str = ::Thermal::Util.normalize_utf8(str, replace: replace) str = "#{str}\n" if feed append_text(str) if str end |
#underline(weight: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
50 51 52 53 54 |
# File 'lib/thermal/stargraphic/writer.rb', line 50 def underline(weight: nil) # rubocop:disable Lint/UnusedMethodArgument @underline = true yield @underline = false end |