aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/shading
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-07-11 18:05:02 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-07-11 18:05:02 +0000
commitdecb63c9dff4fa1dcf65b9cc3faaa4bf54050301 (patch)
tree4782648424c0ee730757d9fffd80423ed8b56902 /src/java/org/apache/fop/render/shading
parentb7b8ba98b4579c9925f6107170799253c65371da (diff)
downloadxmlgraphics-fop-decb63c9dff4fa1dcf65b9cc3faaa4bf54050301.tar.gz
xmlgraphics-fop-decb63c9dff4fa1dcf65b9cc3faaa4bf54050301.zip
Moved content of ShadingPattern into Shading
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609760 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/shading')
-rw-r--r--src/java/org/apache/fop/render/shading/Shading.java167
-rw-r--r--src/java/org/apache/fop/render/shading/ShadingPattern.java270
2 files changed, 167 insertions, 270 deletions
diff --git a/src/java/org/apache/fop/render/shading/Shading.java b/src/java/org/apache/fop/render/shading/Shading.java
index e27b61a7d..89b4added 100644
--- a/src/java/org/apache/fop/render/shading/Shading.java
+++ b/src/java/org/apache/fop/render/shading/Shading.java
@@ -20,10 +20,16 @@ package org.apache.fop.render.shading;
import java.util.List;
import org.apache.fop.pdf.PDFDeviceColorSpace;
+import org.apache.fop.pdf.PDFNumber;
public class Shading {
+ public interface FunctionRenderer {
+
+ void outputFunction(StringBuilder out);
+ }
+
/**
* Required: The Type of shading (1,2,3,4,5,6,7)
*/
@@ -206,4 +212,165 @@ public class Shading {
return verticesPerRow;
}
+ public void output(StringBuilder out, FunctionRenderer functionRenderer) {
+ out.append("<<\n/ShadingType " + shadingType + "\n");
+ if (colorSpace != null) {
+ out.append("/ColorSpace /" + colorSpace.getName() + "\n");
+ }
+
+ if (background != null) {
+ out.append("/Background ");
+ outputDoubles(out, background);
+ out.append("\n");
+ }
+
+ if (bbox != null) {
+ out.append("/BBox");
+ outputDoubles(out, bbox);
+ out.append("\n");
+ }
+
+ if (antiAlias) {
+ out.append("/AntiAlias " + antiAlias + "\n");
+ }
+
+ switch (shadingType) {
+ // Function based shading
+ case 1: outputShadingType1(out, functionRenderer); break;
+ // Axial shading
+ case 2:
+ // Radial shading
+ case 3: outputShadingType2or3(out, functionRenderer); break;
+ // Free-form Gouraud-shaded triangle meshes
+ case 4:
+ // Coons patch meshes
+ case 6:
+ // Tensor product patch meshes
+ case 7: outputShadingType4or6or7(out, functionRenderer); break;
+ // Lattice Free form gouraud-shaded triangle mesh
+ case 5: outputShadingType5(out, functionRenderer); break;
+ default: throw new UnsupportedOperationException("Shading type " + shadingType);
+ }
+
+ out.append(">>");
+ }
+
+ private void outputDoubles(StringBuilder out, List<Double> doubles) {
+ out.append("[ ");
+ for (Double d : doubles) {
+ out.append(PDFNumber.doubleOut(d));
+ out.append(" ");
+ }
+ out.append("]");
+ }
+
+ private void outputShadingType1(StringBuilder out, Shading.FunctionRenderer functionRenderer) {
+ if (domain != null) {
+ out.append("/Domain ");
+ outputDoubles(out, domain);
+ out.append("\n");
+ } else {
+ out.append("/Domain [ 0 1 ] \n");
+ }
+
+ if (matrix != null) {
+ out.append("/Matrix ");
+ outputDoubles(out, matrix);
+ out.append("\n");
+ }
+ outputFunction(out, functionRenderer);
+ }
+
+ private void outputShadingType2or3(StringBuilder out, Shading.FunctionRenderer functionRenderer) {
+ if (coords != null) {
+ out.append("/Coords ");
+ outputDoubles(out, coords);
+ out.append("\n");
+ }
+
+ if (domain != null) {
+ out.append("/Domain ");
+ outputDoubles(out, domain);
+ out.append("\n");
+ } else {
+ out.append("/Domain [ 0 1 ] \n");
+ }
+
+ if (extend != null) {
+ out.append("/Extend [");
+ for (Boolean b : extend) {
+ out.append(b);
+ out.append(" ");
+ }
+ out.append("\n");
+ } else {
+ out.append("/Extend [ true true ] \n");
+ }
+
+ outputFunction(out, functionRenderer);
+ }
+
+ private void outputShadingType4or6or7(StringBuilder out, Shading.FunctionRenderer functionRenderer) {
+ if (bitsPerCoordinate > 0) {
+ out.append("/BitsPerCoordinate " + bitsPerCoordinate + "\n");
+ } else {
+ out.append("/BitsPerCoordinate 1 \n");
+ }
+
+ if (bitsPerComponent > 0) {
+ out.append("/BitsPerComponent " + bitsPerComponent + "\n");
+ } else {
+ out.append("/BitsPerComponent 1 \n");
+ }
+
+ if (bitsPerFlag > 0) {
+ out.append("/BitsPerFlag " + bitsPerFlag + "\n");
+ } else {
+ out.append("/BitsPerFlag 2 \n");
+ }
+
+ if (decode != null) {
+ out.append("/Decode ");
+ outputDoubles(out, decode);
+ out.append("\n");
+ }
+
+ outputFunction(out, functionRenderer);
+ }
+
+ private void outputShadingType5(StringBuilder out, Shading.FunctionRenderer functionRenderer) {
+ if (bitsPerCoordinate > 0) {
+ out.append("/BitsPerCoordinate " + bitsPerCoordinate + "\n");
+ } else {
+ out.append("/BitsPerCoordinate 1 \n");
+ }
+
+ if (bitsPerComponent > 0) {
+ out.append("/BitsPerComponent " + bitsPerComponent + "\n");
+ } else {
+ out.append("/BitsPerComponent 1 \n");
+ }
+
+ if (decode != null) {
+ out.append("/Decode ");
+ outputDoubles(out, decode);
+ out.append("\n");
+ }
+
+ outputFunction(out, functionRenderer);
+
+ if (verticesPerRow > 0) {
+ out.append("/VerticesPerRow " + verticesPerRow + "\n");
+ } else {
+ out.append("/VerticesPerRow 2 \n");
+ }
+ }
+
+ private void outputFunction(StringBuilder out, FunctionRenderer functionRenderer) {
+ if (function != null) {
+ out.append("/Function ");
+ functionRenderer.outputFunction(out);
+ out.append("\n");
+ }
+ }
}
diff --git a/src/java/org/apache/fop/render/shading/ShadingPattern.java b/src/java/org/apache/fop/render/shading/ShadingPattern.java
deleted file mode 100644
index 43e030bc8..000000000
--- a/src/java/org/apache/fop/render/shading/ShadingPattern.java
+++ /dev/null
@@ -1,270 +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.
- */
-
-package org.apache.fop.render.shading;
-
-import java.util.List;
-
-import org.apache.fop.pdf.PDFDeviceColorSpace;
-import org.apache.fop.pdf.PDFNumber;
-
-/**
- * A class for writing shading objects for different output formats
- */
-public class ShadingPattern {
-
- public interface ShadingRenderer {
-
- void outputFunction(StringBuffer out);
- }
-
- private Shading shading;
-
- private final ShadingRenderer shadingRenderer;
-
- /**
- * Constructor
- * @param shading The shading object from which to write the output
- */
- public ShadingPattern(Shading shading, ShadingRenderer shadingRenderer) {
- this.shading = shading;
- this.shadingRenderer = shadingRenderer;
- }
-
- /**
- * Outputs the given shading object to a String
- * @param colorSpace The Colospace (PDF and Postscript)
- * @param shadingType The shading type
- * @param background The background
- * @param bBox The bounding box
- * @param antiAlias Anti-aliasing
- * @return Returns the output string
- */
- public String toString(PDFDeviceColorSpace colorSpace, int shadingType, List background,
- List bBox, boolean antiAlias) {
- StringBuffer p = new StringBuffer(128);
- p.append("<<\n/ShadingType " + shadingType + " \n");
- if (colorSpace != null) {
- p.append("/ColorSpace /"
- + colorSpace.getName() + " \n");
- }
-
- if (background != null) {
- p.append("/Background [ ");
- for (int bgIndex = 0; bgIndex < background.size(); bgIndex++) {
- p.append(PDFNumber.doubleOut((Double)background.get(bgIndex))
- + " ");
- }
- p.append("] \n");
- }
-
- if (bBox
- != null) { // I've never seen an example, so I guess this is right.
- p.append("/BBox [ ");
- for (int bboxIndex = 0; bboxIndex < bBox.size(); bboxIndex++) {
- p.append(PDFNumber.doubleOut((Double)bBox.get(bboxIndex))
- + " ");
- }
- p.append("] \n");
- }
-
- if (antiAlias) {
- p.append("/AntiAlias " + antiAlias + " \n");
- }
-
- // Here's where we differentiate based on what type it is.
- switch (shadingType) {
- //Function based shading
- case 1: p = handleShadingType1(p); break;
- //Axial shading
- case 2:
- //Radial shading
- case 3: p = handleShadingType2or3(p); break;
- //Free-form Gouraud-shaded triangle meshes
- case 4:
- //Coons patch meshes
- case 6:
- //Tensor product patch meshes
- case 7: p = handleShadingType4or6or7(p); break;
- //Lattice Free form gouraud-shaded triangle mesh
- case 5: p = handleShadingType5(p); break;
- default: //Shading pattern outside expecting values
- break;
- }
-
- p.append(">>");
-
- return (p.toString());
- }
-
-
- /**
- * A method to write a type 1 shading object
- * @param p The StringBuffer to write the shading object
- * @return Returns the StringBuffer to which the shading object was written
- */
- public StringBuffer handleShadingType1(StringBuffer p) {
- if (shading.getDomain() != null) {
- p.append("/Domain [ ");
- for (int domainIndex = 0; domainIndex < shading.getDomain().size(); domainIndex++) {
- p.append(PDFNumber.doubleOut((Double)shading.getDomain().get(domainIndex))
- + " ");
- }
- p.append("] \n");
- } else {
- p.append("/Domain [ 0 1 ] \n");
- }
-
- if (shading.getMatrix() != null) {
- p.append("/Matrix [ ");
- for (int matrixIndex = 0; matrixIndex < shading.getMatrix().size(); matrixIndex++) {
- p.append(PDFNumber.doubleOut((Double)shading.getMatrix().get(matrixIndex))
- + " ");
- }
- p.append("] \n");
- }
- shadingRenderer.outputFunction(p);
- return p;
- }
-
- /**
- * A method to write a type 2 or 3 shading object
- * @param p The StringBuffer to write the shading object
- * @return Returns the StringBuffer to which the shading object was written
- */
- public StringBuffer handleShadingType2or3(StringBuffer p) {
- // 3 is radial shading (circular gradient)
- if (shading.getCoords() != null) {
- p.append("/Coords [ ");
- for (int coordIndex = 0; coordIndex < shading.getCoords().size(); coordIndex++) {
- p.append(PDFNumber.doubleOut((Double)shading.getCoords().get(coordIndex))
- + " ");
- }
- p.append("] \n");
- }
-
- // DOMAIN
- if (shading.getDomain() != null) {
- p.append("/Domain [ ");
- for (int domainIndex = 0; domainIndex < shading.getDomain().size(); domainIndex++) {
- p.append(PDFNumber.doubleOut((Double)shading.getDomain().get(domainIndex))
- + " ");
- }
- p.append("] \n");
- } else {
- p.append("/Domain [ 0 1 ] \n");
- }
-
- if (shading.getExtend() != null) {
- p.append("/Extend [ ");
- for (int extendIndex = 0; extendIndex < shading.getExtend().size(); extendIndex++) {
- p.append((shading.getExtend().get(extendIndex)) + " ");
- }
-
- p.append("] \n");
- } else {
- p.append("/Extend [ true true ] \n");
- }
-
- shadingRenderer.outputFunction(p);
-
- return p;
- }
-
- /**
- * A method to write a type 4, 6 or 7 shading object
- * @param p The StringBuffer to write the shading object
- * @return Returns the StringBuffer to which the shading object was written
- */
- public StringBuffer handleShadingType4or6or7(StringBuffer p) {
- // 6:coons patch meshes
- // 7://tensor product patch meshes (which no one ever uses)
- if (shading.getBitsPerCoordinate() > 0) {
- p.append("/BitsPerCoordinate " + shading.getBitsPerCoordinate()
- + " \n");
- } else {
- p.append("/BitsPerCoordinate 1 \n");
- }
-
- if (shading.getBitsPerComponent() > 0) {
- p.append("/BitsPerComponent " + shading.getBitsPerComponent()
- + " \n");
- } else {
- p.append("/BitsPerComponent 1 \n");
- }
-
- if (shading.getBitsPerFlag() > 0) {
- p.append("/BitsPerFlag " + shading.getBitsPerFlag() + " \n");
- } else {
- p.append("/BitsPerFlag 2 \n");
- }
-
- if (shading.getDecode() != null) {
- p.append("/Decode [ ");
- for (int decodeIndex = 0; decodeIndex < shading.getDecode().size(); decodeIndex++) {
- p.append((shading.getDecode().get(decodeIndex)) + " ");
- }
-
- p.append("] \n");
- }
-
- shadingRenderer.outputFunction(p);
-
- return p;
- }
-
- /**
- * A method to write a type 5 shading object
- * @param p The StringBuffer to write the shading object
- * @return Returns the StringBuffer to which the shading object was written
- */
- public StringBuffer handleShadingType5(StringBuffer p) {
- if (shading.getBitsPerCoordinate() > 0) {
- p.append("/BitsPerCoordinate " + shading.getBitsPerCoordinate()
- + " \n");
- } else {
- p.append("/BitsPerCoordinate 1 \n");
- }
-
- if (shading.getBitsPerComponent() > 0) {
- p.append("/BitsPerComponent " + shading.getBitsPerComponent()
- + " \n");
- } else {
- p.append("/BitsPerComponent 1 \n");
- }
-
- if (shading.getDecode() != null) {
- p.append("/Decode [ ");
- for (int decodeIndex = 0; decodeIndex < shading.getDecode().size(); decodeIndex++) {
- p.append((shading.getDecode().get(decodeIndex)) + " ");
- }
-
- p.append("] \n");
- }
-
- shadingRenderer.outputFunction(p);
-
- if (shading.getVerticesPerRow() > 0) {
- p.append("/VerticesPerRow " + shading.getVerticesPerRow() + " \n");
- } else {
- p.append("/VerticesPerRow 2 \n");
- }
-
- return p;
- }
-
-}