From b49267763c60c4d9f68a0c7cf762262d159c6c2b Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 18 Jul 2014 13:42:05 +0000 Subject: [PATCH] Cleaned up and re-organized PS gradient test case git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1611648 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 1 + .../fop/render/ps/svg/GradientTestCase.java | 75 +++++++++++++++++++ .../ps/svg/PSSVGGraphics2DTestCase.java | 71 ------------------ .../ps/svg/PSSVGLinearGraphics2DTestCase.java | 70 ----------------- .../render/ps/svg/axial-shading-expected.dat | 26 ------- .../render/ps/svg/expected-linear-gradient.ps | 26 +++++++ .../render/ps/svg/expected-radial-gradient.ps | 44 +++++++++++ .../org/apache/fop/render/ps/svg/expected.ps | 38 ---------- 8 files changed, 146 insertions(+), 205 deletions(-) create mode 100644 test/java/org/apache/fop/render/ps/svg/GradientTestCase.java delete mode 100644 test/java/org/apache/fop/render/ps/svg/PSSVGGraphics2DTestCase.java delete mode 100644 test/java/org/apache/fop/render/ps/svg/PSSVGLinearGraphics2DTestCase.java delete mode 100644 test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat create mode 100644 test/java/org/apache/fop/render/ps/svg/expected-linear-gradient.ps create mode 100644 test/java/org/apache/fop/render/ps/svg/expected-radial-gradient.ps delete mode 100644 test/java/org/apache/fop/render/ps/svg/expected.ps diff --git a/build.xml b/build.xml index ba9f2e09b..b6c7f3706 100644 --- a/build.xml +++ b/build.xml @@ -732,6 +732,7 @@ list of possible build targets. + diff --git a/test/java/org/apache/fop/render/ps/svg/GradientTestCase.java b/test/java/org/apache/fop/render/ps/svg/GradientTestCase.java new file mode 100644 index 000000000..397dbed0f --- /dev/null +++ b/test/java/org/apache/fop/render/ps/svg/GradientTestCase.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.render.ps.svg; + +import java.awt.Color; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +import org.apache.commons.io.IOUtils; + +import org.apache.batik.ext.awt.LinearGradientPaint; +import org.apache.batik.ext.awt.MultipleGradientPaint; +import org.apache.batik.ext.awt.RadialGradientPaint; + +import org.apache.xmlgraphics.java2d.GraphicContext; +import org.apache.xmlgraphics.ps.PSGenerator; + +public class GradientTestCase { + + @Test + public void testLinearGradient() throws IOException { + float[] fractions = {0f, 1f}; + Color[] colors = {new Color(255, 255, 0), new Color(255, 0, 0)}; + LinearGradientPaint gradient = new LinearGradientPaint(115f, 285f, 15f, 15f, fractions, colors); + testGradientRendering(gradient, "expected-linear-gradient.ps"); + } + + @Test + public void testRadialGradient() throws IOException { + float cx = 840f; + float cy = 180f; + float r = 16f; + float[] fractions = {0.2f, 0.6f, 0.8f, 1.0f}; + Color[] colors = { + new Color(255, 255, 255), + new Color(200, 200, 200), + new Color(170, 170, 170), + new Color(140, 140, 140)}; + RadialGradientPaint gradient = new RadialGradientPaint(cx, cy, r, fractions, colors); + testGradientRendering(gradient, "expected-radial-gradient.ps"); + } + + private void testGradientRendering(MultipleGradientPaint gradient, String expectedResourceName) + throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PSSVGGraphics2D svgGraphics2D = new PSSVGGraphics2D(false, new PSGenerator(out)); + svgGraphics2D.setGraphicContext(new GraphicContext()); + svgGraphics2D.applyPaint(gradient, true); + byte[] actual = out.toByteArray(); + byte[] expected = IOUtils.toByteArray(getClass().getResourceAsStream(expectedResourceName)); + assertEquals(new String(expected, "US-ASCII"), new String(actual, "US-ASCII")); + } + +} diff --git a/test/java/org/apache/fop/render/ps/svg/PSSVGGraphics2DTestCase.java b/test/java/org/apache/fop/render/ps/svg/PSSVGGraphics2DTestCase.java deleted file mode 100644 index 29a3a7bd3..000000000 --- a/test/java/org/apache/fop/render/ps/svg/PSSVGGraphics2DTestCase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.render.ps.svg; - -import java.awt.Color; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.geom.Rectangle2D.Float; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.io.FileUtils; - -import org.apache.batik.ext.awt.RadialGradientPaint; - -import org.apache.xmlgraphics.java2d.GraphicContext; -import org.apache.xmlgraphics.ps.PSGenerator; - -public class PSSVGGraphics2DTestCase { - - float cx = 841.891f; - float cy = 178.583f; - float r = 16.4331f; - float[] fractions = {0.2f, 0.6012f, 0.8094f, 1.0f}; - - /** - * Tests a radial gradient generated pattern with certain inputs against - * an expected output. - * @throws IOException - */ - @Test - public void testApplyPaint() throws IOException { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - PSGenerator gen = new PSGenerator(os); - PSSVGGraphics2D svgGraphics2D = new PSSVGGraphics2D(false, gen); - svgGraphics2D.setGraphicContext(new GraphicContext()); - svgGraphics2D.setTransform(new AffineTransform()); - Color[] colors = {new Color(255, 255, 255), new Color(200, 200, 200), - new Color(170, 170, 170), new Color(140, 140, 140)}; - RadialGradientPaint paint = new RadialGradientPaint(cx, cy, r, fractions, colors); - Float s = new Rectangle2D.Float(7.0f, 3.0f, 841.891f, 178.583f); - svgGraphics2D.applyPaint(paint, true); - byte[] test = os.toByteArray(); - - byte[] expected = FileUtils.readFileToByteArray( - new File("test/java/org/apache/fop/render/ps/svg/expected.ps")); - assertEquals(new String(test), new String(expected)); - } -} diff --git a/test/java/org/apache/fop/render/ps/svg/PSSVGLinearGraphics2DTestCase.java b/test/java/org/apache/fop/render/ps/svg/PSSVGLinearGraphics2DTestCase.java deleted file mode 100644 index 3a6db4396..000000000 --- a/test/java/org/apache/fop/render/ps/svg/PSSVGLinearGraphics2DTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.render.ps.svg; - -import java.awt.Color; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.geom.Rectangle2D.Float; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.io.FileUtils; - -import org.apache.batik.ext.awt.LinearGradientPaint; - -import org.apache.xmlgraphics.java2d.GraphicContext; -import org.apache.xmlgraphics.ps.PSGenerator; - -public class PSSVGLinearGraphics2DTestCase { - float startX = 115f; - float endX = 15f; - float startY = 285f; - float endY = 15f; - float[] fractions = {0.0f, 1.0f}; - - /** - * Tests a linear gradient generated pattern with certain inputs against - * an expected output. - * @throws IOException - */ - @Test - public void testApplyPaint() throws IOException { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - PSGenerator gen = new PSGenerator(os); - PSSVGGraphics2D svgGraphics2D = new PSSVGGraphics2D(false, gen); - svgGraphics2D.setGraphicContext(new GraphicContext()); - svgGraphics2D.setTransform(new AffineTransform()); - Color[] colors = {new Color(255, 255, 0), new Color(255, 0, 0)}; - LinearGradientPaint paint = new LinearGradientPaint(startX, startY, endX, endY, fractions, colors); - Float s = new Rectangle2D.Float(115.0f, 15.0f, 170f, 110f); - svgGraphics2D.applyPaint(paint, true); - byte[] test = os.toByteArray(); - - byte[] expected = FileUtils.readFileToByteArray( - new File("test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat")); - assertEquals(new String(test), new String(expected)); - } -} diff --git a/test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat b/test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat deleted file mode 100644 index fdf92cda5..000000000 --- a/test/java/org/apache/fop/render/ps/svg/axial-shading-expected.dat +++ /dev/null @@ -1,26 +0,0 @@ -/Pattern setcolorspace -<< -/Type /Pattern -/PatternType 2 -/Shading << -/ShadingType 2 -/ColorSpace /DeviceRGB - /Coords [ 115 285 15 15 ] - /Domain [ 0 1 ] - /Extend [ true true ] - /Function << -/FunctionType 3 -/Domain [ 0 1 ] -/Functions [ << -/FunctionType 2 -/Domain [ 0 1 ] -/C0 [ 1 1 0 ] -/C1 [ 1 0 0 ] -/N 1 ->> ] -/Encode [ 0 1 ] -/Bounds [ ] ->> ->> ->> -matrix makepattern setcolor diff --git a/test/java/org/apache/fop/render/ps/svg/expected-linear-gradient.ps b/test/java/org/apache/fop/render/ps/svg/expected-linear-gradient.ps new file mode 100644 index 000000000..a81cd7766 --- /dev/null +++ b/test/java/org/apache/fop/render/ps/svg/expected-linear-gradient.ps @@ -0,0 +1,26 @@ +/Pattern setcolorspace +<< +/Type /Pattern +/PatternType 2 +/Shading << +/ShadingType 2 +/ColorSpace /DeviceRGB +/Coords [ 115 285 15 15 ] +/Domain [ 0 1 ] +/Extend [ true true ] +/Function << +/FunctionType 3 +/Domain [ 0 1 ] +/Functions [ << +/FunctionType 2 +/Domain [ 0 1 ] +/C0 [ 1 1 0 ] +/C1 [ 1 0 0 ] +/N 1 +>> ] +/Encode [ 0 1 ] +/Bounds [ ] +>> +>> +>> +[ 1 0 0 1 0 0 ] makepattern setcolor diff --git a/test/java/org/apache/fop/render/ps/svg/expected-radial-gradient.ps b/test/java/org/apache/fop/render/ps/svg/expected-radial-gradient.ps new file mode 100644 index 000000000..e8bbef313 --- /dev/null +++ b/test/java/org/apache/fop/render/ps/svg/expected-radial-gradient.ps @@ -0,0 +1,44 @@ +/Pattern setcolorspace +<< +/Type /Pattern +/PatternType 2 +/Shading << +/ShadingType 3 +/ColorSpace /DeviceRGB +/Coords [ 840 180 0 840 180 16 ] +/Domain [ 0 1 ] +/Extend [ true true ] +/Function << +/FunctionType 3 +/Domain [ 0 1 ] +/Functions [ << +/FunctionType 2 +/Domain [ 0 1 ] +/C0 [ 1 1 1 ] +/C1 [ 1 1 1 ] +/N 1 +>> << +/FunctionType 2 +/Domain [ 0 1 ] +/C0 [ 1 1 1 ] +/C1 [ 0.784 0.784 0.784 ] +/N 1 +>> << +/FunctionType 2 +/Domain [ 0 1 ] +/C0 [ 0.784 0.784 0.784 ] +/C1 [ 0.667 0.667 0.667 ] +/N 1 +>> << +/FunctionType 2 +/Domain [ 0 1 ] +/C0 [ 0.667 0.667 0.667 ] +/C1 [ 0.549 0.549 0.549 ] +/N 1 +>> ] +/Encode [ 0 1 0 1 0 1 0 1 ] +/Bounds [ 0.2 0.6 0.8 ] +>> +>> +>> +[ 1 0 0 1 0 0 ] makepattern setcolor diff --git a/test/java/org/apache/fop/render/ps/svg/expected.ps b/test/java/org/apache/fop/render/ps/svg/expected.ps deleted file mode 100644 index 9977070c3..000000000 --- a/test/java/org/apache/fop/render/ps/svg/expected.ps +++ /dev/null @@ -1,38 +0,0 @@ -/Pattern setcolorspace -<< -/Type /Pattern -/PatternType 2 -/Shading << -/ShadingType 3 -/ColorSpace /DeviceRGB - /Coords [ 841.890991 178.582993 3.28662 841.890991 178.582993 16.4331 ] - /Domain [ 0 1 ] - /Extend [ true true ] - /Function << -/FunctionType 3 -/Domain [ 0 1 ] -/Functions [ << -/FunctionType 2 -/Domain [ 0 1 ] -/C0 [ 1 1 1 ] -/C1 [ 0.784314 0.784314 0.784314 ] -/N 1 ->> << -/FunctionType 2 -/Domain [ 0 1 ] -/C0 [ 0.784314 0.784314 0.784314 ] -/C1 [ 0.666667 0.666667 0.666667 ] -/N 1 ->> << -/FunctionType 2 -/Domain [ 0 1 ] -/C0 [ 0.666667 0.666667 0.666667 ] -/C1 [ 0.54902 0.54902 0.54902 ] -/N 1 ->> ] -/Encode [ 0 1 0 1 0 1 ] -/Bounds [ 0.6012 0.8094 ] ->> ->> ->> -matrix makepattern setcolor -- 2.39.5