Support png scaling, but warns on use.
This commit is contained in:
@@ -7,7 +7,7 @@ describe Squib::Deck, 'images' do
|
||||
it 'calls Card#png, Dir, and progress bar' do
|
||||
card = instance_double(Squib::Card)
|
||||
progress = double(Squib::Progress)
|
||||
expect(card).to receive(:png).with('foo', 0, 1, 0.5, :overlay, 0.75).once
|
||||
expect(card).to receive(:png).with('foo', 0, 1, :native, :native, 0.5, :overlay, 0.75).once
|
||||
expect(Dir).to receive(:chdir).with('.').and_yield.once
|
||||
expect(progress).to receive(:start).and_yield(progress).once
|
||||
expect(progress).to receive(:increment).once
|
||||
|
||||
@@ -36,6 +36,14 @@ cairo: translate([-50, -50])
|
||||
cairo: set_source([MockDouble, 50, 50])
|
||||
cairo: paint([1.0])
|
||||
cairo: restore([])
|
||||
cairo: save([])
|
||||
cairo: translate([305, 50])
|
||||
cairo: scale([1.953125, 1.953125])
|
||||
cairo: rotate([0])
|
||||
cairo: translate([-305, -50])
|
||||
cairo: set_source([ImageSurface, 305, 50])
|
||||
cairo: paint([1.0])
|
||||
cairo: restore([])
|
||||
cairo: scale([0.5859375, 0.5859375])
|
||||
cairo: render_rsvg_handle([RSVG::Handle, "#backdrop"])
|
||||
cairo: save([])
|
||||
|
||||
@@ -3,14 +3,15 @@ require 'squib'
|
||||
|
||||
describe Squib::Card do
|
||||
|
||||
before(:each) do
|
||||
@deck = double(Squib::Deck)
|
||||
@context = double(Cairo::Context)
|
||||
@svg = double(RSVG::Handle)
|
||||
allow(Cairo::Context).to receive(:new).and_return(@context)
|
||||
allow(Cairo::ImageSurface).to receive(:from_png).and_return(nil)
|
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(nil)
|
||||
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
|
||||
before(:example) do
|
||||
@deck = double(Squib::Deck)
|
||||
@context = double(Cairo::Context)
|
||||
@svg = double(RSVG::Handle)
|
||||
@png = double(Cairo::ImageSurface)
|
||||
allow(Cairo::Context).to receive(:new).and_return(@context)
|
||||
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)
|
||||
end
|
||||
|
||||
context '#png' do
|
||||
@@ -19,13 +20,13 @@ describe Squib::Card do
|
||||
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(:set_source).with(nil, 37, 38).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)
|
||||
# png(file, x, y, alpha, blend, angle)
|
||||
card.png('foo.png', 37, 38, 0.9, :none, 0.0)
|
||||
card.png('foo.png', 37, 38, :native, :native, 0.9, :none, 0.0)
|
||||
end
|
||||
|
||||
it 'sets blend when needed' do
|
||||
@@ -33,8 +34,9 @@ describe Squib::Card do
|
||||
expect(@context).to receive(:operator=).with(:overlay).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
card.png('foo.png', 37, 38, 0.9, :overlay, 0.0)
|
||||
card.png('foo.png', 37, 38, :native, :native, 0.9, :overlay, 0.0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#svg' do
|
||||
@@ -47,7 +49,7 @@ describe Squib::Card do
|
||||
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(nil, 37, 38).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
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ describe "Squib samples" do
|
||||
end
|
||||
|
||||
it 'should execute with no errors' do
|
||||
allow(Squib.logger).to receive(:warn) {}
|
||||
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
||||
Dir["#{samples_dir}/**/*.rb"].each do |sample|
|
||||
load sample
|
||||
|
||||
@@ -54,6 +54,7 @@ def mock_cairo(strio)
|
||||
cxt = double(Cairo::Context)
|
||||
surface = double(Cairo::ImageSurface)
|
||||
pango = double(Pango::Layout)
|
||||
allow(Squib.logger).to receive(:warn) {}
|
||||
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
||||
allow(surface).to receive(:width).and_return(100)
|
||||
|
||||
Reference in New Issue
Block a user