Class: Rapicco::PDF::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rapicco/pdf/renderer.rb

Constant Summary collapse

BLOCK_CHARS =
{
  "\u2588" => :full,
  "\u2580" => :upper,
  "\u2584" => :lower,
  " " => :empty
}

Instance Method Summary collapse

Constructor Details

#initialize(char_width: 10, char_height: 20) ⇒ Renderer

Returns a new instance of Renderer.



13
14
15
16
# File 'lib/rapicco/pdf/renderer.rb', line 13

def initialize(char_width: 10, char_height: 20)
  @char_width = char_width
  @char_height = char_height
end

Instance Method Details

#render(pages, output_path, parser_cols: 80, parser_rows: 24) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rapicco/pdf/renderer.rb', line 18

def render(pages, output_path, parser_cols: 80, parser_rows: 24)
  width = parser_cols * @char_width
  height = parser_rows * @char_height

  Cairo::PDFSurface.new(output_path, width, height) do |surface|
    pages.each do |page_data|
      context = Cairo::Context.new(surface)
      render_page(page_data, context)
      context.show_page
    end
  end
end