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
|