Maintain coordinate system when using gradients
Sample: document this better spec: test this and update past tests Fixes #127dev
parent
064307365f
commit
cf736db067
|
|
@ -37,15 +37,17 @@ module Squib
|
||||||
arg.scan(STOPS).each do |color, offset|
|
arg.scan(STOPS).each do |color, offset|
|
||||||
linear.add_color_stop(offset.to_f, color)
|
linear.add_color_stop(offset.to_f, color)
|
||||||
end
|
end
|
||||||
|
linear.matrix = matrix # match the coordinate systems - see bug 127
|
||||||
@cairo_cxt.set_source(linear)
|
@cairo_cxt.set_source(linear)
|
||||||
elsif match = arg.match(RADIAL_GRADIENT)
|
elsif match = arg.match(RADIAL_GRADIENT)
|
||||||
x1, y1, r1, x2, y2, r2 = match.captures
|
x1, y1, r1, x2, y2, r2 = match.captures
|
||||||
linear = Cairo::RadialPattern.new(x1.to_f, y1.to_f, r1.to_f,
|
radial = Cairo::RadialPattern.new(x1.to_f, y1.to_f, r1.to_f,
|
||||||
x2.to_f, y2.to_f, r2.to_f)
|
x2.to_f, y2.to_f, r2.to_f)
|
||||||
|
radial.matrix = matrix # match the coordinate systems - see bug 127
|
||||||
arg.scan(STOPS).each do |color, offset|
|
arg.scan(STOPS).each do |color, offset|
|
||||||
linear.add_color_stop(offset.to_f, color)
|
radial.add_color_stop(offset.to_f, color)
|
||||||
end
|
end
|
||||||
@cairo_cxt.set_source(linear)
|
@cairo_cxt.set_source(radial)
|
||||||
else
|
else
|
||||||
@cairo_cxt.set_source_color(arg)
|
@cairo_cxt.set_source_color(arg)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 514af49430797daf7a69c31118b6056dc4abaf20
|
Subproject commit 0714a8c2dee388b3f856d2a86d4efb95c5e3cde8
|
||||||
|
|
@ -28,60 +28,71 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
expect { subject.set_source_squibcolor(nil) }.to raise_error('nil is not a valid color')
|
expect { subject.set_source_squibcolor(nil) }.to raise_error('nil is not a valid color')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
context 'regex variations for linear gradients' do
|
||||||
|
before(:each) do
|
||||||
|
dbl = double(Cairo::LinearPattern)
|
||||||
|
mtx = double(Cairo::Matrix)
|
||||||
|
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||||
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
expect(dbl).to receive(:matrix=).with(mtx)
|
||||||
|
expect(cairo).to receive(:set_source).with(dbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2) (3,4) blue@0 red@1') }
|
||||||
context 'regex variations for linear gradients' do
|
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0) (3.0,4.0) blue@0 red@1') }
|
||||||
before(:each) do
|
it('handles no whitespace') { subject.set_source_squibcolor('(1,2)(3,4)blue@0red@1') }
|
||||||
dbl = double(Cairo::LinearPattern)
|
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 ) ( 3 , 4 ) blue@0 red@1 ') }
|
||||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
|
||||||
expect(cairo).to receive(:set_source).with(dbl)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2) (3,4) blue@0 red@1') }
|
context 'regex variations for radial gradients' do
|
||||||
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0) (3.0,4.0) blue@0 red@1') }
|
before(:each) do
|
||||||
it('handles no whitespace') { subject.set_source_squibcolor('(1,2)(3,4)blue@0red@1') }
|
dbl = double(Cairo::RadialPattern)
|
||||||
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 ) ( 3 , 4 ) blue@0 red@1 ') }
|
mtx = double(Cairo::Matrix)
|
||||||
end
|
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||||
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
expect(dbl).to receive(:matrix=).with(mtx)
|
||||||
|
expect(cairo).to receive(:set_source).with(dbl)
|
||||||
|
end
|
||||||
|
|
||||||
context 'regex variations for radial gradients' do
|
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2,5) (3,4,6) blue@0 red@1') }
|
||||||
before(:each) do
|
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0,5.0) (3.0,4.0,6.0) blue@0 red@1') }
|
||||||
dbl = double(Cairo::RadialPattern)
|
it('handles no whitespace') { subject.set_source_squibcolor('(1,2,5)(3,4,6)blue@0red@1') }
|
||||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 , 5 ) ( 3 , 4 , 6 ) blue@0 red@1 ') }
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
|
||||||
expect(cairo).to receive(:set_source).with(dbl)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it('handles no decimals' ) { subject.set_source_squibcolor('(1,2,5) (3,4,6) blue@0 red@1') }
|
context 'regex handles hash notation' do
|
||||||
it('handles decimals' ) { subject.set_source_squibcolor('(1.0,2.0,5.0) (3.0,4.0,6.0) blue@0 red@1') }
|
it 'on radial patterns' do
|
||||||
it('handles no whitespace') { subject.set_source_squibcolor('(1,2,5)(3,4,6)blue@0red@1') }
|
dbl = double(Cairo::RadialPattern)
|
||||||
it('handles whitespace' ) { subject.set_source_squibcolor(' ( 1 , 2 , 5 ) ( 3 , 4 , 6 ) blue@0 red@1 ') }
|
mtx = double(Cairo::Matrix)
|
||||||
end
|
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||||
|
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||||
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
expect(dbl).to receive(:matrix=).with(mtx)
|
||||||
|
expect(cairo).to receive(:set_source).with(dbl)
|
||||||
|
subject.set_source_squibcolor('(1,2,5) (3,4,6) #def@0 #112233@1')
|
||||||
|
end
|
||||||
|
|
||||||
context 'regex handles hash notation' do
|
it 'on linear patterns' do
|
||||||
it 'on radial patterns' do
|
dbl = double(Cairo::LinearPattern)
|
||||||
dbl = double(Cairo::RadialPattern)
|
mtx = double(Cairo::Matrix)
|
||||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||||
expect(cairo).to receive(:set_source).with(dbl)
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
subject.set_source_squibcolor('(1,2,5) (3,4,6) #def@0 #112233@1')
|
expect(dbl).to receive(:matrix=).with(mtx)
|
||||||
|
expect(cairo).to receive(:set_source).with(dbl)
|
||||||
|
subject.set_source_squibcolor('(1,2) (3,4) #def@0 #112233@1')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'on linear patterns' do
|
|
||||||
dbl = double(Cairo::LinearPattern)
|
|
||||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
|
||||||
expect(cairo).to receive(:set_source).with(dbl)
|
|
||||||
subject.set_source_squibcolor('(1,2) (3,4) #def@0 #112233@1')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'flips' do
|
context '#flip' do
|
||||||
it 'in the basic case' do
|
it 'in the basic case' do
|
||||||
dbl = double(Cairo::Matrix)
|
dbl = double(Cairo::Matrix)
|
||||||
expect(Cairo::Matrix).to receive(:new).with(-1.0, 0.0, 0.0, -1.0, 6.0, 8.0).and_return(dbl)
|
expect(Cairo::Matrix).to receive(:new).with(-1.0, 0.0, 0.0, -1.0, 6.0, 8.0).and_return(dbl)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue