Class: BrotherEscp::Document
- Inherits:
-
Object
- Object
- BrotherEscp::Document
- Defined in:
- lib/brother_escp/document.rb
Overview
Main class to manage document Instanciate one for each printing
Instance Method Summary collapse
-
#image(file_name:, density: :single_density) ⇒ Object
Add an image to the document This will only work for PNG files, the alpha layer will be ignored.
-
#initialize(log_level: Logger::INFO) ⇒ Document
constructor
A new instance of Document.
-
#inspect ⇒ String
Inspect the data.
-
#line_feed_size=(n) ⇒ Object
Helper method to set the line feed size.
-
#page_length=(n) ⇒ Object
Helper method to set the page length.
-
#sequence(value) ⇒ Object
Add a pre-defined sequence to the document.
-
#to_base64 ⇒ String
Return base64 encoded data.
-
#to_escp ⇒ String
Return the raw data.
-
#write(data) ⇒ Object
Write data to the document.
Constructor Details
#initialize(log_level: Logger::INFO) ⇒ Document
Returns a new instance of Document.
12 13 14 15 16 17 18 |
# File 'lib/brother_escp/document.rb', line 12 def initialize(log_level: Logger::INFO) @data = String.new('') sequence(:HW_SET_ESCP_MODE) sequence(:HW_INIT) BrotherEscp.logger.level = log_level end |
Instance Method Details
#image(file_name:, density: :single_density) ⇒ Object
Add an image to the document This will only work for PNG files, the alpha layer will be ignored
30 31 32 33 |
# File 'lib/brother_escp/document.rb', line 30 def image(file_name:, density: :single_density) img = BrotherEscp::Image.new(file_name: file_name, converter: density) write(img.convert.to_escp) end |
#inspect ⇒ String
Inspect the data
55 56 57 |
# File 'lib/brother_escp/document.rb', line 55 def inspect to_escp.chars.map { |c| "0x#{c.unpack('H*').first}" }.join(' ') end |
#line_feed_size=(n) ⇒ Object
Helper method to set the line feed size
43 44 45 |
# File 'lib/brother_escp/document.rb', line 43 def line_feed_size=(n) write(BrotherEscp::Sequence.line_feed_size(n)) end |
#page_length=(n) ⇒ Object
Helper method to set the page length
49 50 51 |
# File 'lib/brother_escp/document.rb', line 49 def page_length=(n) write(BrotherEscp::Sequence.page_length(n)) end |
#sequence(value) ⇒ Object
Add a pre-defined sequence to the document
37 38 39 |
# File 'lib/brother_escp/document.rb', line 37 def sequence(value) write(BrotherEscp::Sequence.sequence(value)) end |
#to_base64 ⇒ String
Return base64 encoded data
67 68 69 |
# File 'lib/brother_escp/document.rb', line 67 def to_base64 Base64.strict_encode64 to_escp end |
#to_escp ⇒ String
Return the raw data
61 62 63 |
# File 'lib/brother_escp/document.rb', line 61 def to_escp @data end |
#write(data) ⇒ Object
Write data to the document
22 23 24 |
# File 'lib/brother_escp/document.rb', line 22 def write(data) @data << data end |