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



200
201
202
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 200

def autolink(link, type)
  link
end

#block_code(code, language) ⇒ Object



139
140
141
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 139

def block_code(code, language)
  code
end

#block_html(text) ⇒ Object



147
148
149
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 147

def block_html(text)
  text
end

#block_quote(text) ⇒ Object



143
144
145
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 143

def block_quote(text)
  text
end

#codespan(text) ⇒ Object



204
205
206
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 204

def codespan(text)
  text
end


252
253
254
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 252

def doc_footer
  END_PAGE
end

#doc_headerObject



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

def doc_header
  @mode = 0

  START_PAGE + set_mode
end

#double_emphasis(text) ⇒ Object



208
209
210
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 208

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

#emphasis(text) ⇒ Object



212
213
214
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 212

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

#header(text, level) ⇒ Object



151
152
153
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 151

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

#hruleObject



155
156
157
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 155

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

#image(link, title, alt) ⇒ Object



216
217
218
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 216

def image(link, title, alt)
  alt
end

#linebreakObject



220
221
222
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 220

def linebreak
  "\n"
end


224
225
226
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 224

def link(link, title, content)
  content
end

#list(text, type) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 159

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



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

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

#normal_text(text, keep_newlines = false) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 236

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

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

  text
end

#paragraph(text) ⇒ Object



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

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

#raw_html(text) ⇒ Object



228
229
230
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 228

def raw_html(text)
  ""
end

#table(header, body) ⇒ Object



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

def table(header, body)
  ""
end

#tablecell(text, align) ⇒ Object



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

def tablecell(text, align)
  ""
end

#tablerow(text) ⇒ Object



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

def tablerow(text)
  ""
end

#triple_emphasis(text) ⇒ Object



232
233
234
# File 'lib/smartware/drivers/printer/esc_pos.rb', line 232

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