Class: Thermal::Escpos::Buffer
- Inherits:
-
ByteBuffer
- Object
- ByteBuffer
- Thermal::Escpos::Buffer
- Extended by:
- Forwardable
- Defined in:
- lib/thermal/escpos/buffer.rb
Overview
Inspired by mike42/escpos-php github.com/mike42/escpos-php/blob/development/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php
Instance Method Summary collapse
- #current_charset ⇒ Object
- #current_encoding ⇒ Object
-
#initialize(profile) ⇒ Buffer
constructor
A new instance of Buffer.
- #write_text(text, replace: nil, no_cjk: false) ⇒ Object
Methods inherited from ByteBuffer
#<<, #buffer, #flush, #flush_base64, #to_a, #to_base64, #to_s
Constructor Details
#initialize(profile) ⇒ Buffer
Returns a new instance of Buffer.
10 11 12 13 14 15 16 17 |
# File 'lib/thermal/escpos/buffer.rb', line 10 def initialize(profile) super() @profile = profile @codepage = 0 @charset = 0 @cjk = false init_buffer! end |
Instance Method Details
#current_charset ⇒ Object
31 32 33 |
# File 'lib/thermal/escpos/buffer.rb', line 31 def current_charset charsets[@charset] end |
#current_encoding ⇒ Object
27 28 29 |
# File 'lib/thermal/escpos/buffer.rb', line 27 def current_encoding @cjk ? cjk_encoding : codepages[@codepage] end |
#write_text(text, replace: nil, no_cjk: false) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/thermal/escpos/buffer.rb', line 35 def write_text(text, replace: nil, no_cjk: false) text = ::Thermal::Util.normalize_utf8(text, replace: replace) text&.each_codepoint do |u_codepoint| write_u_codepoint(u_codepoint, replace: replace, no_cjk: no_cjk) end end |