Fix PDF scaling issue
Properly compute the size of the PDF based on DPI and PDF-specific resolution (i.e. 72dpi). Closes #62dev
parent
a47e26535d
commit
4a0c5e78b6
|
|
@ -22,7 +22,8 @@ module Squib
|
|||
paper_width = p[:width]
|
||||
paper_height = p[:height]
|
||||
file = "#{p[:dir]}/#{p[:file]}"
|
||||
cc = Cairo::Context.new(Cairo::PDFSurface.new(file, paper_width, paper_height))
|
||||
cc = Cairo::Context.new(Cairo::PDFSurface.new(file, paper_width * 72.0 / @dpi, paper_height * 72.0 / @dpi))
|
||||
cc.scale(72.0 / @dpi, 72.0 / @dpi) # for bug #62
|
||||
x, y = p[:margin], p[:margin]
|
||||
card_width = @width - 2 * p[:trim]
|
||||
card_height = @height - 2 * p[:trim]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
require 'squib'
|
||||
puts "Using Squib #{Squib::VERSION}"
|
||||
|
||||
Squib::Deck.new(cards: 3, dpi: 600) do
|
||||
background color: :gray
|
||||
text str: %w(Hello fine world!)
|
||||
save_pdf file: 'foo.pdf', gap: 5, width: '11in', height: '8.5in'
|
||||
end
|
||||
|
|
@ -35,6 +35,7 @@ cairo: scale([1.0, 1.0])
|
|||
cairo: render_rsvg_handle([RSVG::Handle, nil])
|
||||
cairo: restore([])
|
||||
surface: write_to_png(["_output/custom-config_00.png"])
|
||||
cairo: scale([0.24, 0.24])
|
||||
cairo: translate([75, 75])
|
||||
cairo: rectangle([0, 0, 825, 1125])
|
||||
cairo: clip([])
|
||||
|
|
|
|||
|
|
@ -494,6 +494,7 @@ cairo: move_to([0, 0])
|
|||
cairo: update_pango_layout([MockDouble])
|
||||
cairo: show_pango_layout([MockDouble])
|
||||
cairo: restore([])
|
||||
cairo: scale([0.24, 0.24])
|
||||
cairo: translate([75, 75])
|
||||
cairo: rectangle([37, 37, 751, 1051])
|
||||
cairo: clip([])
|
||||
|
|
@ -608,6 +609,7 @@ cairo: paint([])
|
|||
cairo: reset_clip([])
|
||||
cairo: translate([-2343, -1131])
|
||||
cairo: show_page([])
|
||||
cairo: scale([0.24, 0.24])
|
||||
cairo: translate([75, 75])
|
||||
cairo: rectangle([0, 0, 825, 1125])
|
||||
cairo: clip([])
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ describe Squib::Deck, '#save_pdf' do
|
|||
deck = Squib::Deck.new(cards: 9, width: 825, height: 1125)
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(cxt).to receive(:scale).with(0.24, 0.24)
|
||||
|
||||
expect_card_place(75, 75)
|
||||
expect_card_place(831, 75)
|
||||
|
|
@ -50,6 +51,7 @@ describe Squib::Deck, '#save_pdf' do
|
|||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
expect(cxt).to receive(:scale).with(0.24, 0.24)
|
||||
|
||||
expect_card_place(75, 75)
|
||||
expect_card_place(831, 75)
|
||||
|
|
|
|||
Loading…
Reference in New Issue