class Rabbit::Renderer::Printer

Constants

A4_HEIGHT
A4_WIDTH

Attributes

filename[W]

Public Class Methods

new(canvas) click to toggle source
Calls superclass method Rabbit::Renderer::Base::new
# File lib/rabbit/renderer/printer.rb, line 36
def initialize(canvas)
  super
  @filename = nil
  init_paper
  init_color
  update_layout
end

Public Instance Methods

clip_slide(x, y, w, h) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 142
def clip_slide(x, y, w, h)
  x, y = from_screen(x, y)
  @context.rectangle(x, y, w, h)
  @context.clip
end
draw_background(x, y, w, h) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 148
def draw_background(x, y, w, h)
  draw_rectangle(true, x, y, w, h, @background)
end
draw_slide(slide, simulation) { || ... } click to toggle source
# File lib/rabbit/renderer/printer.rb, line 108
def draw_slide(slide, simulation)
  if simulation
    yield
  else
    slide_width = @layout.slide_width
    slide_height = @layout.slide_height
    size = Size.new(@base_width,
                    @base_height,
                    slide_width,
                    slide_height,
                    @base_width.to_f / @base_height.to_f)
    x = @layout.normalize_x(0)
    y = @layout.normalize_y(0)
    save_context do
      translate_context(x, y)
      clip_slide(0, 0, slide_width, slide_height)
      draw_background(0, 0, slide_width, slide_height)
      scale_context(*size.logical_scale)
      translate_context(size.logical_margin_left,
                        size.logical_margin_top)
      yield
      if @slides_per_page > 1
        draw_rectangle(false,
                       0,
                       0,
                       size.logical_width,
                       size.logical_height,
                       @black)
      end
    end
    @context.show_page if need_show_page?
  end
end
filename() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 80
def filename
  @filename || default_filename
end
height() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 48
def height
  @base_height
end
page_height() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 56
def page_height
  @page_height - page_margin_top - page_margin_bottom
end
page_width() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 52
def page_width
  @page_width - page_margin_left - page_margin_right
end
paper_height=(value) click to toggle source
Calls superclass method
# File lib/rabbit/renderer/printer.rb, line 65
def paper_height=(value)
  super
  init_paper
end
paper_width=(value) click to toggle source
Calls superclass method
# File lib/rabbit/renderer/printer.rb, line 60
def paper_width=(value)
  super
  init_paper
end
post_apply_theme() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 99
def post_apply_theme
end
post_move(old_index, index) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 102
def post_move(old_index, index)
end
post_move_in_slide(old_index, index) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 105
def post_move_in_slide(old_index, index)
end
post_parse() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 96
def post_parse
end
post_print(canceled) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 88
def post_print(canceled)
  return if canceled
  @context.target.finish
end
pre_parse() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 93
def pre_parse
end
pre_print(slide_size) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 84
def pre_print(slide_size)
  init_context(create_context)
end
printable?() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 76
def printable?
  true
end
slides_per_page=(slides) click to toggle source
Calls superclass method
# File lib/rabbit/renderer/printer.rb, line 70
def slides_per_page=(slides)
  super
  init_paper
  update_layout
end
width() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 44
def width
  @base_width
end

Private Instance Methods

create_context(output=nil) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 196
def create_context(output=nil)
  surface = find_surface(filename, output)
  surface.set_fallback_resolution(@x_dpi, @y_dpi)
  ::Cairo::Context.new(surface)
end
create_pango_context() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 202
def create_pango_context
  context = create_context(StringIO.new).create_pango_layout.context
  set_font_resolution(context)
  context
end
default_filename() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 153
def default_filename
  sanitized_title = Filename.sanitize(@canvas.title)
  Filename.new("#{sanitized_title}.pdf").encode
end
find_surface(filename, output=nil) click to toggle source
# File lib/rabbit/renderer/printer.rb, line 208
def find_surface(filename, output=nil)
  args = [output || filename, @page_width, @page_height]
  case File.extname(filename)
  when /\.ps/i
    ::Cairo::PSSurface.new(*args)
  when /\.pdf/i
    ::Cairo::PDFSurface.new(*args)
  when /\.svg/i
    surface = ::Cairo::SVGSurface.new(*args)
    surface.restrict_to_version(::Cairo::SVG_VERSION_1_2)
    surface
  when /\.cs/i
    args[0] = ::Cairo::ScriptDevice.new(args[0])
    ::Cairo::ScriptSurface.new(*args)
  else
    @canvas.logger.warn(_("can't find printer for %s") % filename)
    args[0] = "default.ps"
    ::Cairo::PSSurface.new(*args)
  end
end
init_color() click to toggle source
Calls superclass method Rabbit::Renderer::Base#init_color
# File lib/rabbit/renderer/printer.rb, line 180
def init_color
  super
  @foreground = make_color("black")
  @background = make_color(@background_color)
end
init_dpi() click to toggle source
Calls superclass method Rabbit::Renderer::Base#init_dpi
# File lib/rabbit/renderer/printer.rb, line 186
def init_dpi
  super
  @x_dpi = 300
  @y_dpi = 300
end
init_paper() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 158
def init_paper
  if @slides_per_page > 1
    @paper_width = A4_WIDTH
    @paper_height = A4_HEIGHT
  end

  default_width_mm = 360
  default_height_mm = 270
  if @paper_width.nil? and @paper_height.nil?
    size = Size.new(@base_width,
                    @base_height,
                    default_width_mm,
                    default_height_mm,
                    @base_width.to_f / @base_height.to_f)
    @page_width = size.real_content_width
    @page_height = size.real_content_height
  else
    @page_width = @paper_width || default_width_mm
    @page_height = @paper_height || default_height_mm
  end
end
need_show_page?() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 229
def need_show_page?
  @slides_per_page == 1 or
    @canvas.last_slide? or
    ((@canvas.current_index + 1) % @slides_per_page).zero?
end
update_layout() click to toggle source
# File lib/rabbit/renderer/printer.rb, line 192
def update_layout
  @layout = PrintLayout.create(self, @canvas)
end