aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/shading/ShadingPattern.java
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-07-11 18:03:42 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-07-11 18:03:42 +0000
commitb7b8ba98b4579c9925f6107170799253c65371da (patch)
treec94c9765fcdc243617cae2e685e831a1a056e6de /src/java/org/apache/fop/render/shading/ShadingPattern.java
parentfd5c47183ea4a2d9bbee434b5333c539113042d1 (diff)
downloadxmlgraphics-fop-b7b8ba98b4579c9925f6107170799253c65371da.tar.gz
xmlgraphics-fop-b7b8ba98b4579c9925f6107170799253c65371da.zip
Factorized shading code that was common to PDF and PostScript
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609759 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/shading/ShadingPattern.java')
-rw-r--r--src/java/org/apache/fop/render/shading/ShadingPattern.java175
1 files changed, 170 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/render/shading/ShadingPattern.java b/src/java/org/apache/fop/render/shading/ShadingPattern.java
index 6dac65f55..43e030bc8 100644
--- a/src/java/org/apache/fop/render/shading/ShadingPattern.java
+++ b/src/java/org/apache/fop/render/shading/ShadingPattern.java
@@ -27,14 +27,22 @@ import org.apache.fop.pdf.PDFNumber;
*/
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) {
+ public ShadingPattern(Shading shading, ShadingRenderer shadingRenderer) {
this.shading = shading;
+ this.shadingRenderer = shadingRenderer;
}
/**
@@ -81,19 +89,19 @@ public class ShadingPattern {
// Here's where we differentiate based on what type it is.
switch (shadingType) {
//Function based shading
- case 1: p = shading.handleShadingType1(p); break;
+ case 1: p = handleShadingType1(p); break;
//Axial shading
case 2:
//Radial shading
- case 3: p = shading.handleShadingType2or3(p); break;
+ 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 = shading.handleShadingType4or6or7(p); break;
+ case 7: p = handleShadingType4or6or7(p); break;
//Lattice Free form gouraud-shaded triangle mesh
- case 5: p = shading.handleShadingType5(p); break;
+ case 5: p = handleShadingType5(p); break;
default: //Shading pattern outside expecting values
break;
}
@@ -102,4 +110,161 @@ public class ShadingPattern {
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;
+ }
+
}