git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1611648 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -732,6 +732,7 @@ list of possible build targets. | |||
<include name="**/*.fo"/> | |||
<include name="**/BidiTestData*.ser"/> | |||
<include name="**/*.afp"/> | |||
<include name="**/*.ps"/> | |||
<include name="**/*.xsl"/> | |||
</fileset> | |||
<fileset dir="${build.dir}/test-gensrc"> |
@@ -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")); | |||
} | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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)); | |||
} | |||
} |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |