Class: Mireru::Widget::PDF

Inherits:
Gtk::DrawingArea
  • Object
show all
Defined in:
lib/mireru/widget/pdf.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ PDF

Returns a new instance of PDF.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mireru/widget/pdf.rb', line 23

def initialize(file)
  super()
  document = Poppler::Document.new(file)
  @page_index = 0
  @page_max = document.size - 1
  width, height = document.first.size
  set_size_request(width, height)

  signal_connect("draw") do |widget, event|
    context = widget.window.create_cairo_context
    window_width = widget.allocated_width
    window_height = widget.allocated_height
    width_scale = window_width.to_f / width
    height_scale = window_height.to_f / height
    scale = [width_scale, height_scale].min
    begin
      context.scale(scale, scale)
    rescue => e
      $stderr.puts("#{e.class}: #{e.message}")
      $stderr.puts(e.backtrace)
    end
    context.render_poppler_page(document[@page_index])
    context.show_page
    true
  end
end

Instance Method Details

#nextObject



50
51
52
53
54
55
# File 'lib/mireru/widget/pdf.rb', line 50

def next
  @page_index += 1
  @page_index = @page_max if @page_index > @page_max
  hide
  show
end

#prevObject



57
58
59
60
61
62
# File 'lib/mireru/widget/pdf.rb', line 57

def prev
  @page_index -= 1
  @page_index = 0 if @page_index < 0
  hide
  show
end