Class: Smartware::Driver::Printer::Render

Inherits:
Redcarpet::Render::Base
  • Object
show all
Defined in:
lib/smartware/drivers/printer/esc_pos.rb

Constant Summary collapse

START_PAGE =
[
  0x1B, 0x40,     # Initialize the printer
  0x1B, 0x52, 0x00, # Set characters set: USA
  0x1B, 0x74, 0x17, # Select code code: 866
  0x1B, 0x78, 0x02, # High quality
].pack("C*")
END_PAGE =
[
  0x1C, 0xC0, 0xAA, 0x0F, 0xEE, 0x0B, 0x34, # Total cut and automatic paper moving back
].pack("C*")
ALT_FONT =
1
BOLD =
8
DOUBLEH =
16
DOUBLEW =
32
SCRIPT =
64
UNDERLINE =
128

Instance Method Summary collapse

Instance Method Details



242
243
244
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 242

def autolink(link, type)
  link
end

#block_code(code, language) ⇒ Object



181
182
183
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 181

def block_code(code, language)
  code
end

#block_html(text) ⇒ Object



189
190
191
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 189

def block_html(text)
  text
end

#block_quote(text) ⇒ Object



185
186
187
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 185

def block_quote(text)
  text
end

#codespan(text) ⇒ Object



246
247
248
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 246

def codespan(text)
  text
end


294
295
296
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 294

def doc_footer
  END_PAGE
end

#doc_headerObject



288
289
290
291
292
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 288

def doc_header
  @mode = 0

  START_PAGE + set_mode
end

#double_emphasis(text) ⇒ Object



250
251
252
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 250

def double_emphasis(text)
  styled(BOLD) { text }
end

#emphasis(text) ⇒ Object



254
255
256
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 254

def emphasis(text)
  styled(SCRIPT) { text }
end

#header(text, level) ⇒ Object



193
194
195
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 193

def header(text, level)
  styled(DOUBLEW | DOUBLEH) { text } + "\n"
end

#hruleObject



197
198
199
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 197

def hrule
  "_" * 32 + "\n"
end

#image(link, title, alt) ⇒ Object



258
259
260
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 258

def image(link, title, alt)
  alt
end

#linebreakObject



262
263
264
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 262

def linebreak
  "\n"
end


266
267
268
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 266

def link(link, title, content)
  content
end

#list(text, type) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 201

def list(text, type)
  items = text.split "\x01"
  out = ""

  case type
  when :unordered

    items.each_with_index do |text, index|
      out << "- #{text}\n"
    end

  when :ordered

    items.each_with_index do |text, index|
      out << "#{index + 1}. #{text}\n"
    end
  end

  out
end

#list_item(text, type) ⇒ Object



222
223
224
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 222

def list_item(text, type)
  "#{text}\x01"
end

#normal_text(text, keep_newlines = false) ⇒ Object



278
279
280
281
282
283
284
285
286
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 278

def normal_text(text, keep_newlines = false)
  text.encode!("CP866")

  unless keep_newlines
    text.gsub! "\n", " "
  end

  text
end

#paragraph(text) ⇒ Object



226
227
228
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 226

def paragraph(text)
  text + "\n\n"
end

#raw_html(text) ⇒ Object



270
271
272
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 270

def raw_html(text)
  ""
end

#table(header, body) ⇒ Object



230
231
232
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 230

def table(header, body)
  ""
end

#tablecell(text, align) ⇒ Object



238
239
240
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 238

def tablecell(text, align)
  ""
end

#tablerow(text) ⇒ Object



234
235
236
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 234

def tablerow(text)
  ""
end

#triple_emphasis(text) ⇒ Object



274
275
276
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 274

def triple_emphasis(text)
  styled(UNDERLINE) { text }
end