Sha256: a5b5d49e15c9d72dd7daf23e5d2d75ed424c81a59c9079357774b1a4367f59a0
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module Rescpos module ReportUtil FONT_NORMAL = "\x00" FONT_BIG = "\x11" ALIGN_C = "\x01" ALIGN_L = "\x00" ALIGN_R = "\x02" def single_splitline text("-" * 42, :font_size => FONT_NORMAL) end def double_splitline text("=" * 42, :font_size => FONT_NORMAL) end def underline(number) text("_" * number, :font_size => FONT_NORMAL) end def chinese(chinese) text = Iconv.iconv("GBK//IGNORE","UTF-8//IGNORE",chinese) text[0] end def text(txt, options = {}) font_size = options[:font_size] || FONT_NORMAL formatted_text = '' formatted_text << fontsize(font_size) formatted_text << grayscale(options[:gray]) if options[:gray] formatted_text << align(options[:align_type]) if options[:align_type] formatted_text << txt if txt end def fontsize(size) "\x1d\x21" << size.to_s end def grayscale(value) "\x1b\x6d" << ascii(value) end def key_value(label, value) "#{label}: #{value}" end def align(type) "\x1b\x61" << type.to_s end def table(data) table = Rescpos::Table.new(data) yield table command = "\x1b\x44" table.positions.each do |position| command << position.chr end command << "\x00" table.data.each do |item| table.keys.each do |key| begin if item[key] command << "#{item[key]}"+"\x09" end rescue command << "#{item.send(key)}"+"\x09" end end command << "\n" end command end def horizontal_tab "\x09" end def ascii(value) value.to_s.unpack('U')[0].to_s(16) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rescpos-0.0.3 | lib/rescpos/report_util.rb |