aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/pdf
diff options
context:
space:
mode:
authorSteve Coffman <gears@apache.org>2000-04-21 16:43:19 +0000
committerSteve Coffman <gears@apache.org>2000-04-21 16:43:19 +0000
commitce7cd8445a41ce5f81cc11eddf4daa076932642d (patch)
treed14fa71e5e090dd225f57a6fbf2f53c9fd9e5696 /src/org/apache/fop/pdf
parentc6eaf23f85c8a3ba35ae89b11ed46ead1bd2f0a0 (diff)
downloadxmlgraphics-fop-ce7cd8445a41ce5f81cc11eddf4daa076932642d.tar.gz
xmlgraphics-fop-ce7cd8445a41ce5f81cc11eddf4daa076932642d.zip
This adds colorspace (RGB + CMYK) support to PDF output, and the ability
to switch colorspaces. I need to make a colorspace datatype before I'll patch the render code. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193335 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/pdf')
-rw-r--r--src/org/apache/fop/pdf/PDFColor.java296
-rw-r--r--src/org/apache/fop/pdf/PDFFunction.java49
-rw-r--r--src/org/apache/fop/pdf/PDFPathPaint.java81
-rw-r--r--src/org/apache/fop/pdf/PDFPattern.java14
-rw-r--r--src/org/apache/fop/pdf/PDFShading.java46
5 files changed, 452 insertions, 34 deletions
diff --git a/src/org/apache/fop/pdf/PDFColor.java b/src/org/apache/fop/pdf/PDFColor.java
new file mode 100644
index 000000000..589959c51
--- /dev/null
+++ b/src/org/apache/fop/pdf/PDFColor.java
@@ -0,0 +1,296 @@
+/*-- $Id$ --
+
+ ============================================================================
+ The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+ include the following acknowledgment: "This product includes software
+ developed by the Apache Software Foundation (http://www.apache.org/)."
+ Alternately, this acknowledgment may appear in the software itself, if
+ and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Fop" and "Apache Software Foundation" must not be used to
+ endorse or promote products derived from this software without prior
+ written permission. For written permission, please contact
+ apache@apache.org.
+
+ 5. Products derived from this software may not be called "Apache", nor may
+ "Apache" appear in their name, without prior written permission of the
+ Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many individuals
+ on behalf of the Apache Software Foundation and was originally created by
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ Software Foundation, please see <http://www.apache.org/>.
+
+ */
+package org.apache.fop.pdf;
+
+// Java
+import java.io.IOException;
+import java.io.PrintWriter;
+import org.apache.fop.datatypes.ColorType;
+import java.util.Vector;
+
+public class PDFColor extends PDFPathPaint {
+
+ protected double red = -1.0;
+ protected double green= -1.0;
+ protected double blue = -1.0;
+
+ protected double cyan = -1.0;
+ protected double magenta= -1.0;
+ protected double yellow = -1.0;
+ protected double black = -1.0;
+
+
+ public PDFColor(int theNumber, org.apache.fop.datatypes.ColorType theColor)
+ {
+ this.colorspace = 0;
+ //super(theNumber)
+ this.red = (double)theColor.red();
+ this.green = (double)theColor.green();
+ this.blue = (double)theColor.blue();
+
+ }
+
+ public PDFColor(int theNumber, double theRed, double theGreen, double theBlue) {
+ //super(theNumber);
+
+ this.colorspace=0;
+
+ this.red = theRed;
+ this.green = theGreen;
+ this.blue = theBlue;
+ }
+
+ public PDFColor(int theNumber, double theCyan, double theMagenta, double theYellow, double theBlack) {
+ //super(theNumber);//?
+
+ this.colorspace = 1;
+
+ this.cyan = theCyan;
+ this.magenta = theMagenta;
+ this.yellow = theYellow;
+ this.black = theBlack;
+ }
+
+ public int setColorspace()
+ {
+ return(this.colorspace);
+ }
+
+ public Vector getVector()
+ {//return a vector representation of the color
+ //in the appropriate colorspace.
+ Vector theColorVector= new Vector();
+ if (this.colorspace == 0)
+ {//RGB
+ theColorVector.addElement(new Double(this.red));
+ theColorVector.addElement(new Double(this.green));
+ theColorVector.addElement(new Double(this.blue));
+ }
+ else
+ {//CMYK
+ theColorVector.addElement(new Double(this.cyan));
+ theColorVector.addElement(new Double(this.magenta));
+ theColorVector.addElement(new Double(this.yellow));
+ theColorVector.addElement(new Double(this.black));
+
+ }
+ return(theColorVector);
+ }
+
+ public double red()
+ {
+ return(this.red);
+ }
+ public double green()
+ {
+ return(this.green);
+ }
+ public double blue()
+ {
+ return(this.blue);
+ }
+ public double cyan()
+ {
+ return(this.cyan);
+ }
+ public double magenta()
+ {
+ return(this.magenta);
+ }
+ public double yellow()
+ {
+ return(this.yellow);
+ }
+ public double black()
+ {
+ return(this.black);
+ }
+
+ public String getColorspaceOut(boolean fillNotStroke)
+ {
+ StringBuffer p = new StringBuffer("");
+
+ double tempDouble;
+
+ //if the color was constructed in a different colorspace,
+ //then we need to convert it.
+
+ if(this.colorspace==0)
+ {//colorspace is RGB
+ if((this.red < 0)
+ || (this.green < 0)
+ || (this.blue < 0))
+ {
+ this.convertCMYKtoRGB();
+ } //end of convert from CMYK
+
+ //output RGB
+ if(fillNotStroke)
+ { //fill
+ p.append(this.doubleOut(this.red)+" "
+ +this.doubleOut(this.green)+" "
+ +this.doubleOut(this.blue)+" "
+ +" rg \n");
+ }
+ else
+ {//stroke/border
+ p.append(this.doubleOut(this.red)+" "
+ +this.doubleOut(this.green)+" "
+ +this.doubleOut(this.blue)+" "
+ +" RG \n");
+ }
+ }//end of output RGB
+ else
+ {//colorspace is CMYK
+ if((this.cyan < 0)
+ || (this.magenta < 0)
+ || (this.yellow < 0)
+ || (this.black < 0))
+ {
+ this.convertRGBtoCMYK();
+ }//end of if convert from RGB
+
+ if(fillNotStroke)
+ { //fill
+ p.append(this.doubleOut(this.cyan) + " "
+ + this.doubleOut(this.magenta) + " "
+ + this.doubleOut(this.yellow) + " "
+ + this.doubleOut(this.black) + " k \n");
+ }
+ else
+ { //fill
+ p.append(this.doubleOut(this.cyan) + " "
+ + this.doubleOut(this.magenta) + " "
+ + this.doubleOut(this.yellow) + " "
+ + this.doubleOut(this.black) + " K \n");
+ }
+
+ }//end of if CMYK
+ return(p.toString());
+ }
+
+
+
+ public String doubleOut(double doubleDown)
+ {
+ StringBuffer p = new StringBuffer();
+ double trouble = doubleDown % 1;
+
+ if(trouble > 0.950)
+ {
+ p.append((int)doubleDown+1);
+ }
+ else if (trouble < 0.050)
+ {
+ p.append((int)doubleDown);
+ }
+ else
+ {
+ String doubleString = new String(doubleDown+"");
+ int decimal = doubleString.indexOf(".");
+ p.append(doubleString.substring(0, decimal));
+
+ if ((doubleString.length() - decimal) > 6)
+ {
+ p.append(doubleString.substring(decimal,decimal+6));
+ }
+ else
+ {
+ p.append(doubleString.substring(decimal));
+ }
+ }
+ return(p.toString());
+ }
+
+ protected void convertCMYKtoRGB()
+ {
+ //convert CMYK to RGB
+ this.red = 1.0 - this.cyan;
+ this.green = 1.0 - this.green;
+ this.blue= 1.0 - this.yellow;
+
+ this.red = (this.black / 2.0)+ this.red;
+ this.green = (this.black / 2.0)+ this.green;
+ this.blue = (this.blue / 2.0) + this.blue;
+
+ }
+
+ protected void convertRGBtoCMYK()
+ {
+ //convert RGB to CMYK
+ this.cyan = 1.0 - this.red;
+ this.magenta= 1.0 - this.green;
+ this.yellow = 1.0 - this.blue;
+
+ this.black = 0.0;
+ /* If you want to calculate black, uncomment this
+ //pick the lowest color
+ tempDouble = this.red;
+
+ if (this.green < tempDouble)
+ tempDouble = this.green;
+
+ if (this.blue < tempDouble)
+ tempDouble = this.blue;
+
+ this.black = tempDouble / 2.0; // 3.0???
+ */
+ }
+
+
+
+
+ String toPDF()
+ {
+ return ("");
+
+ } //end of toPDF
+}
diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java
index 973c660d1..0e4b44222 100644
--- a/src/org/apache/fop/pdf/PDFFunction.java
+++ b/src/org/apache/fop/pdf/PDFFunction.java
@@ -208,7 +208,6 @@ public class PDFFunction extends PDFObject {
super(theNumber);
this.functionType = 0; //dang well better be 0;
-
this.size = theSize;
this.bitsPerSample = theBitsPerSample;
this.order = theOrder; //int
@@ -403,6 +402,8 @@ public class PDFFunction extends PDFObject {
}
return(p.toString());
}
+
+
/**
* represent as PDF. Whatever the FunctionType is, the correct
@@ -440,7 +441,11 @@ public class PDFFunction extends PDFObject {
p.append("] \n");
}
-
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
+
//SIZE
if(this.size != null)
{
@@ -465,6 +470,17 @@ public class PDFFunction extends PDFObject {
}
p.append("] \n");
}
+ else
+ {
+ p.append("/Encode [ ");
+ vectorSize = this.functions.size();
+ for(tempInt=0; tempInt < vectorSize; tempInt++)
+ {
+ p.append("0 1 ");
+ }
+ p.append("] \n");
+
+ }
//BITSPERSAMPLE
p.append("/BitsPerSample "+this.bitsPerSample);
@@ -555,6 +571,11 @@ public class PDFFunction extends PDFObject {
p.append("] \n");
}
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
+
//RANGE
if(this.range != null)
@@ -621,7 +642,11 @@ public class PDFFunction extends PDFObject {
}
p.append("] \n");
}
-
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
+
//RANGE
if(this.range != null)
{
@@ -663,6 +688,18 @@ public class PDFFunction extends PDFObject {
p.append("] \n");
}
+ else
+ {
+ p.append("/Encode [ ");
+ vectorSize = this.functions.size();
+ for(tempInt=0; tempInt < vectorSize; tempInt++)
+ {
+ p.append("0 1 ");
+ }
+ p.append("] \n");
+
+ }
+
//BOUNDS, required, but can be empty
p.append("/Bounds [ ");
@@ -720,7 +757,11 @@ public class PDFFunction extends PDFObject {
p.append("] \n");
}
-
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
+
//RANGE
if(this.range != null)
{
diff --git a/src/org/apache/fop/pdf/PDFPathPaint.java b/src/org/apache/fop/pdf/PDFPathPaint.java
new file mode 100644
index 000000000..894bd5457
--- /dev/null
+++ b/src/org/apache/fop/pdf/PDFPathPaint.java
@@ -0,0 +1,81 @@
+/*-- $Id$ --
+
+ ============================================================================
+ The Apache Software License, Version 1.1
+ ============================================================================
+
+ Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modifica-
+ tion, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. The end-user documentation included with the redistribution, if any, must
+ include the following acknowledgment: "This product includes software
+ developed by the Apache Software Foundation (http://www.apache.org/)."
+ Alternately, this acknowledgment may appear in the software itself, if
+ and wherever such third-party acknowledgments normally appear.
+
+ 4. The names "Fop" and "Apache Software Foundation" must not be used to
+ endorse or promote products derived from this software without prior
+ written permission. For written permission, please contact
+ apache@apache.org.
+
+ 5. Products derived from this software may not be called "Apache", nor may
+ "Apache" appear in their name, without prior written permission of the
+ Apache Software Foundation.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many individuals
+ on behalf of the Apache Software Foundation and was originally created by
+ James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ Software Foundation, please see <http://www.apache.org/>.
+
+ */
+package org.apache.fop.pdf;
+
+public abstract class PDFPathPaint extends PDFObject
+{
+
+ protected int colorspace = 0; //default is 0:RGB, not 1:CMYK
+
+ public PDFPathPaint(int theNumber) {
+ super(theNumber);
+
+ }
+
+ public PDFPathPaint(){
+ //do nothing
+ }
+
+ abstract String getColorspaceOut(boolean fillNotStroke);
+
+
+ public void setColorspace(int theColorspace)
+ {
+ this.colorspace = theColorspace;
+ }
+
+ public int getColorspace()
+ {
+ return(this.colorspace);
+ }
+
+}
+
diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java
index 620452a61..40085a3f4 100644
--- a/src/org/apache/fop/pdf/PDFPattern.java
+++ b/src/org/apache/fop/pdf/PDFPattern.java
@@ -64,7 +64,7 @@ import java.util.Vector;
*
* All PDF Functions have a FunctionType (0,2,3, or 4), a Domain, and a Range.
*/
-public class PDFPattern extends PDFObject {
+public class PDFPattern extends PDFPathPaint {
/**
* The resources associated with this pattern
@@ -214,6 +214,18 @@ public class PDFPattern extends PDFObject {
return (this.patternName);
}
+
+ public String getColorspaceOut(boolean fillNotStroke)
+ {
+ if(fillNotStroke)
+ { //fill but no stroke
+ return("/Pattern cs /"+this.getName()+" scn \n");
+ }
+ else
+ { //stroke (or border)
+ return("/Pattern CS /"+this.getName()+" SCN \n");
+ }
+ }
/**
* Output a Double prettily as a string
*
diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java
index 27fa6402c..6ba18f9a2 100644
--- a/src/org/apache/fop/pdf/PDFShading.java
+++ b/src/org/apache/fop/pdf/PDFShading.java
@@ -220,7 +220,8 @@ public class PDFShading extends PDFObject {
* @param theExtend Vector of Booleans of whether to extend teh start and end colors past the start and end points
* The default is [false, false]
*/
- public PDFShading(int theNumber, String theShadingName, int theShadingType, StringBuffer theColorSpace,
+ public PDFShading(int theNumber, String theShadingName,
+ int theShadingType, StringBuffer theColorSpace,
Vector theBackground, Vector theBBox, boolean theAntiAlias,
Vector theCoords, Vector theDomain, PDFFunction theFunction,
Vector theExtend)
@@ -330,6 +331,7 @@ public class PDFShading extends PDFObject {
public String getName() {
return (this.shadingName);
}
+
public String doubleOut(Double doubleDown)
{
StringBuffer p = new StringBuffer();
@@ -425,6 +427,10 @@ public class PDFShading extends PDFObject {
}
p.append("] \n");
}
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
if(this.matrix != null)
{
@@ -460,6 +466,7 @@ public class PDFShading extends PDFObject {
p.append("] \n");
}
+ //DOMAIN
if(this.domain != null)
{
p.append("/Domain [ ");
@@ -471,7 +478,11 @@ public class PDFShading extends PDFObject {
}
p.append("] \n");
}
-
+ else
+ {
+ p.append("/Domain [ 0 1 ] \n");
+ }
+
if(this.extend != null)
{
p.append("/Extend [ ");
@@ -483,6 +494,10 @@ public class PDFShading extends PDFObject {
p.append("] \n");
}
+ else
+ {
+ p.append("/Extend [ true true ] \n");
+ }
if(this.function != null)
@@ -490,33 +505,6 @@ public class PDFShading extends PDFObject {
p.append("/Function ");
p.append(this.function.referencePDF()+" \n");
}
- else if(true)
- {
-
- //FunctionType 2 /Domain [ 0 1 ] /N 1.048 /C0 [ 0.929 0.357 1 0.298 ] /C1 [ 0.631 0.278 1 0.027 ] >> \n"
- //+"<< /FunctionType 2 /Domain [ 0 1 ] /N 1.374 /C0 [ 0.929 0.357 1 0.298 ] /C1 [ 0.941 0.4 1 0.102 ]
-
- p.append("/Function << /FunctionType 3 /Domain [ 0 1 ] /Functions [ << /FunctionType 2 /Domain [ 0 1 ] /C0 [ 0 0 0 0 ] /C1 [ 0.506 0.306 0 0 ] /N 1 >> ] /Encode [ 0 1 ] /Bounds [ ] >> \n");
- }
- else if(true)
- {//RGB function
- p.append("/Function << /FunctionType 3 /Domain [ 0 1 ] /Encode [ 1 0 1 0 ] /Functions [ << /FunctionType 2 /Domain [ 0 1 ] /N 1.49834 /C0 [ 0 0.73332 0.98038 ] \n"
-+"/C1 [ 0 0.38039 0.50587 ] >> \n"
-+"<< /FunctionType 2 /Domain [ 0 1 ] /N 1 /C0 [ 0.37254 0.8196 0.96861 ] \n"
-+"/C1 [ 0 0.73332 0.98038 ] >> \n"
-+"] \n"
-+"/Bounds [ 0.61581 ] >> ");
-
- }
- else
- {
-
- p.append("/Function << /FunctionType 3 /Domain [ 0 1 ] /Encode [ 1 0 ] /Functions [ << /FunctionType 2 /Domain [ 0 1 ] /N 1 /C0 [ 0.81175 0 0 ] /C1 [ 1 1 1 ] >> \n"
- +"] \n"
- +"/Bounds [ ] >> \n");
- }
-
-
}