SVG backend: PDF implemented, tests passing
Wrapping up the svg backend work Still some bugs to stamp out, but this is getting close to release ready.
This commit is contained in:
@@ -2,29 +2,30 @@ require 'spec_helper'
|
||||
require 'squib'
|
||||
|
||||
describe Squib::Deck, '#save_pdf' do
|
||||
def expect_card_place(x, y)
|
||||
expect(cxt).to receive(:set_source)
|
||||
.with(instance_of(Cairo::ImageSurface), -37, -37)
|
||||
.once # trim the card
|
||||
expect(cxt).to receive(:paint).once # paint trimmed card
|
||||
expect(cxt).to receive(:set_source) # place the card
|
||||
.with(instance_of(Cairo::ImageSurface), x, y).at_least(1).times
|
||||
expect(cxt).to receive(:paint).once # paint placed card
|
||||
end
|
||||
|
||||
context 'typical inputs' do
|
||||
let(:cxt) { double(Cairo::Context) }
|
||||
|
||||
def expect_card_place(x, y)
|
||||
expect(cxt).to receive(:translate).with(x, y).once
|
||||
expect(cxt).to receive(:rectangle).once
|
||||
expect(cxt).to receive(:clip).once
|
||||
expect(cxt).to receive(:set_source) # place the card
|
||||
.with(instance_of(Cairo::ImageSurface), 0, 0).once
|
||||
expect(cxt).to receive(:paint).once # paint placed card
|
||||
expect(cxt).to receive(:translate).with(-x,-y).once
|
||||
expect(cxt).to receive(:reset_clip).once
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Cairo::PDFSurface).to receive(:new).and_return(nil) #don't create the file
|
||||
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
||||
end
|
||||
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
num_cards = 9
|
||||
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||
deck = Squib::Deck.new(cards: 9, width: 825, height: 1125)
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(Cairo::Context).to receive(:new).and_return(cxt).at_least(num_cards + 1).times
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
|
||||
expect_card_place(75, 75)
|
||||
@@ -38,6 +39,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||
expect(cxt).to receive(:show_page).once
|
||||
expect_card_place(75, 75)
|
||||
|
||||
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||
deck.save_pdf(args)
|
||||
end
|
||||
|
||||
@@ -46,7 +48,6 @@ describe Squib::Deck, '#save_pdf' do
|
||||
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
||||
expect(Squib.logger).to receive(:debug).at_least(:once)
|
||||
expect(Cairo::Context).to receive(:new).and_return(cxt).exactly(4).times
|
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
||||
|
||||
expect_card_place(75, 75)
|
||||
|
||||
@@ -37,7 +37,7 @@ describe Squib::Card do
|
||||
context 'circle' do
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
expect(@context).to receive(:save).once
|
||||
expect(@context).to receive(:move_to).with(37, 38)
|
||||
expect(@context).to receive(:move_to).with(137, 38)
|
||||
expect(@context).to receive(:circle).with(37, 38, 100).twice
|
||||
expect_stroke('#fff', '#f00', 2.0)
|
||||
expect(@context).to receive(:restore).once
|
||||
|
||||
Reference in New Issue
Block a user