spec/prawn/svg/elements/gradient_spec.rb in prawn-svg-0.30.0 vs spec/prawn/svg/elements/gradient_spec.rb in prawn-svg-0.31.0
- old
+ new
@@ -7,11 +7,11 @@
before do
allow(element).to receive(:assert_compatible_prawn_version)
element.process
end
- describe "object bounding box" do
+ describe "object bounding box with linear gradient" do
let(:svg) do
<<-SVG
<linearGradient id="flag" x1="0" x2="0.2" y1="0" y2="1">
<stop offset="25%" stop-color="red"/>
<stop offset="50%" stop-color="white"/>
@@ -38,13 +38,41 @@
arguments = element.gradient_arguments(double(bounding_box: nil))
expect(arguments).to be nil
end
end
- describe "user space on use" do
+ describe "object bounding box with radial gradient" do
let(:svg) do
<<-SVG
+ <radialGradient id="flag" cx="0" cy="0.2" fx="0.5" r="0.8">
+ <stop offset="25%" stop-color="red"/>
+ <stop offset="50%" stop-color="white"/>
+ <stop offset="75%" stop-color="blue"/>
+ </radialGradient>
+ SVG
+ end
+
+ it "is stored in the document gradients table" do
+ expect(document.gradients["flag"]).to eq element
+ end
+
+ it "returns correct gradient arguments for an element" do
+ arguments = element.gradient_arguments(double(bounding_box: [100, 100, 200, 0]))
+ expect(arguments).to eq(
+ from: [150, 80],
+ to: [100, 80],
+ r1: 0,
+ r2: Math.sqrt((0.8 * 100) ** 2 + (0.8 * 100) ** 2),
+ stops: [[0, "ff0000"], [0.25, "ff0000"], [0.5, "ffffff"], [0.75, "0000ff"], [1, "0000ff"]],
+ apply_transformations: true,
+ )
+ end
+ end
+
+ describe "user space on use with linear gradient" do
+ let(:svg) do
+ <<-SVG
<linearGradient id="flag" gradientUnits="userSpaceOnUse" x1="100" y1="500" x2="200" y2="600">
<stop offset="0" stop-color="red"/>
<stop offset="1" stop-color="blue"/>
</linearGradient>
SVG
@@ -53,9 +81,32 @@
it "returns correct gradient arguments for an element" do
arguments = element.gradient_arguments(double)
expect(arguments).to eq(
from: [100.0, 100.0],
to: [200.0, 0.0],
+ stops: [[0, "ff0000"], [1, "0000ff"]],
+ apply_transformations: true,
+ )
+ end
+ end
+
+ describe "user space on use with radial gradient" do
+ let(:svg) do
+ <<-SVG
+ <radialGradient id="flag" gradientUnits="userSpaceOnUse" fx="100" fy="500" cx="200" cy="600" r="150">
+ <stop offset="0" stop-color="red"/>
+ <stop offset="1" stop-color="blue"/>
+ </radialGradient>
+ SVG
+ end
+
+ it "returns correct gradient arguments for an element" do
+ arguments = element.gradient_arguments(double)
+ expect(arguments).to eq(
+ from: [100.0, 100.0],
+ to: [200.0, 0.0],
+ r1: 0,
+ r2: 150,
stops: [[0, "ff0000"], [1, "0000ff"]],
apply_transformations: true,
)
end
end