Merging in svg back end work. All but save_doc is done.
This commit is contained in:
@@ -12,6 +12,9 @@ describe Squib::Card do
|
||||
allow(Cairo::ImageSurface).to receive(:from_png).and_return(@png)
|
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(@png)
|
||||
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
|
||||
allow(@deck).to receive(:dir).and_return('_output')
|
||||
allow(@deck).to receive(:count_format).and_return('%02d')
|
||||
allow(@deck).to receive(:prefix).and_return('card_')
|
||||
end
|
||||
|
||||
context '#png' do
|
||||
@@ -43,13 +46,10 @@ describe Squib::Card do
|
||||
expect(@svg).to receive(:width).and_return(100).twice
|
||||
expect(@svg).to receive(:height).and_return(100).twice
|
||||
expect(@context).to receive(:save).once
|
||||
expect(@context).to receive(:translate).with(-37, -38).once
|
||||
expect(@context).to receive(:rotate).with(0.0).once
|
||||
expect(@context).to receive(:translate).with(37, 38).once
|
||||
expect(@context).to receive(:scale).with(1.0, 1.0).once
|
||||
expect(@context).to receive(:render_rsvg_handle).with(@svg, 'id').once
|
||||
expect(@context).to receive(:set_source).with(@png, 37, 38).once
|
||||
expect(@context).to receive(:paint).with(0.9).once
|
||||
expect(@context).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
|
||||
@@ -2,21 +2,20 @@ require 'spec_helper'
|
||||
require 'squib'
|
||||
|
||||
describe Squib::Deck, '#save_pdf' do
|
||||
|
||||
def expect_card_place(x, y)
|
||||
expect(@context).to receive(:set_source)
|
||||
.with(instance_of(Cairo::ImageSurface), -37, -37)
|
||||
.once # trim the card
|
||||
expect(@context).to receive(:paint).once # paint trimmed card
|
||||
expect(@context).to receive(:set_source) # place the card
|
||||
.with(instance_of(Cairo::ImageSurface), x, y).once
|
||||
expect(@context).to receive(:paint).once # paint placed card
|
||||
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) }
|
||||
|
||||
before(:each) do
|
||||
@context = double(Cairo::Context)
|
||||
allow(Cairo::PDFSurface).to receive(:new).and_return(nil) #don't create the file
|
||||
end
|
||||
|
||||
@@ -25,7 +24,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||
args = { 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(@context).exactly(num_cards + 1).times
|
||||
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)
|
||||
@@ -36,7 +35,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||
expect_card_place(831, 1131)
|
||||
expect_card_place(1587, 1131)
|
||||
expect_card_place(2343, 1131)
|
||||
expect(@context).to receive(:show_page).once
|
||||
expect(cxt).to receive(:show_page).once
|
||||
expect_card_place(75, 75)
|
||||
|
||||
deck.save_pdf(args)
|
||||
@@ -47,7 +46,7 @@ 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(@context).exactly(4).times
|
||||
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)
|
||||
|
||||
@@ -15,6 +15,9 @@ describe Squib::Card do
|
||||
@deck = double(Squib::Deck)
|
||||
@context = double(Cairo::Context)
|
||||
allow(Cairo::Context).to receive(:new).and_return(@context)
|
||||
allow(@deck).to receive(:dir).and_return('_output')
|
||||
allow(@deck).to receive(:count_format).and_return('%02d')
|
||||
allow(@deck).to receive(:prefix).and_return('card_')
|
||||
end
|
||||
|
||||
context 'rect' do
|
||||
|
||||
@@ -11,6 +11,9 @@ describe Squib::Card, '#text' do
|
||||
|
||||
before(:each) do
|
||||
allow(Cairo::Context).to receive(:new).and_return(context)
|
||||
allow(deck).to receive(:dir).and_return('_output')
|
||||
allow(deck).to receive(:count_format).and_return('%02d')
|
||||
allow(deck).to receive(:prefix).and_return('card_')
|
||||
end
|
||||
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
@@ -39,7 +42,7 @@ describe Squib::Card, '#text' do
|
||||
expect(context).to receive(:show_pango_layout).once
|
||||
expect(context).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
# text(str, font, font_size, color,
|
||||
# x, y, width, height,
|
||||
# markup, justify, wrap, ellipsize,
|
||||
@@ -53,18 +56,22 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
context 'convenience lookups' do
|
||||
let(:deck) { double(Squib::Deck) }
|
||||
let(:context) { double(Cairo::Context).as_null_object }
|
||||
let(:layout) { double(Pango::Layout).as_null_object }
|
||||
let(:extents) { double("extents") }
|
||||
|
||||
before(:each) do
|
||||
@deck = double(Squib::Deck)
|
||||
@context = double(Cairo::Context).as_null_object
|
||||
@layout = double(Pango::Layout).as_null_object
|
||||
@extents = double("extents")
|
||||
allow(Cairo::Context).to receive(:new).and_return(@context)
|
||||
expect(@context).to receive(:create_pango_layout).once.and_return(@layout)
|
||||
allow(Cairo::Context).to receive(:new).and_return(context)
|
||||
expect(context).to receive(:create_pango_layout).once.and_return(layout)
|
||||
allow(deck).to receive(:dir).and_return('_output')
|
||||
allow(deck).to receive(:count_format).and_return('%02d')
|
||||
allow(deck).to receive(:prefix).and_return('card_')
|
||||
end
|
||||
|
||||
it 'aligns right with strings' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, false, false,
|
||||
@@ -72,8 +79,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'aligns center with strings' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, false, false,
|
||||
@@ -81,8 +88,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets wrap to char with string char' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, 'char', false,
|
||||
@@ -90,8 +97,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets wrap to word with word string' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, 'word', false,
|
||||
@@ -99,8 +106,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets wrap to word_char with symbol word_char' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, :word_char, false,
|
||||
@@ -108,8 +115,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets wrap to word_char with true' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, true, false,
|
||||
@@ -117,8 +124,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets ellipsize to start properly' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, true, :start,
|
||||
@@ -126,8 +133,8 @@ describe Squib::Card, '#text' do
|
||||
end
|
||||
|
||||
it 'sets ellipsize to middle properly' do
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
expect(@layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
|
||||
card.text('foo', 'Sans 12', nil, '#abc',
|
||||
10, 15, 20, 50,
|
||||
nil, false, true, 'middle',
|
||||
|
||||
Reference in New Issue
Block a user