--- /dev/null
+/*-- $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.datatypes;
+
+public class ColorSpace {
+ //Ok... so I had some grand purpose for this, but I can't recall.
+ //I'm just writing it
+
+ public static int DEVICE_UNKNOWN = -1;
+ public static int DEVICE_GRAY = 1;
+ //what's the *official* spelling?
+ //public static int DEVICE_GREY = 1;
+ public static int DEVICE_RGB = 2;
+ public static int DEVICE_CMYK = 3;
+
+ //Are there any others?
+
+ protected int currentColorSpace = -1;
+
+ public ColorSpace (int theColorSpace)
+ {
+ this.currentColorSpace = theColorSpace;
+
+ }
+ public int getColorSpace()
+ {
+ return (this.currentColorSpace);
+ }
+ public void setColorSpace(int theColorSpace)
+ {
+ this.currentColorSpace = theColorSpace;
+ }
+
+ public String getColorSpacePDFString()
+ {//this is for PDF Output. Does anyone else need a string representation?
+
+
+ //shouldn't this be a select-case? I can never remember
+ //the syntax for that.
+ if(this.currentColorSpace == this.DEVICE_RGB)
+ {
+ return("DeviceRGB");
+ }
+ else if(this.currentColorSpace == this.DEVICE_CMYK)
+ {
+ return("DeviceCMYK");
+ }
+ else if(this.currentColorSpace== this.DEVICE_GRAY)
+ {
+ return("DeviceGray");
+ }
+ else
+ {//unknown... Error. Tell them it's RGB and hope they don't notice.
+ return("DeviceRGB");
+ }
+ }
+}
\ No newline at end of file
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,
+ 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,
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
+ 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
+ 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" 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
+ 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
+ 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
+ (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
+ 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.util.Vector;
import java.io.IOException;
import java.io.PrintWriter;
+
+//FOP
import org.apache.fop.datatypes.ColorType;
-import java.util.Vector;
+import org.apache.fop.datatypes.ColorSpace;
public class PDFColor extends PDFPathPaint {
-
+ protected static double blackFactor = 2.0;//could be 3.0 as well.
protected double red = -1.0;
protected double green= -1.0;
protected double blue = -1.0;
- protected double cyan = -1.0;
+ protected double cyan = -1.0;
protected double magenta= -1.0;
protected double yellow = -1.0;
- protected double black = -1.0;
+ protected double black = -1.0;
- public PDFColor(int theNumber, org.apache.fop.datatypes.ColorType theColor)
+ public PDFColor(org.apache.fop.datatypes.ColorType theColor)
{
- this.colorspace = 0;
+ this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
//super(theNumber)
this.red = (double)theColor.red();
this.green = (double)theColor.green();
}
- public PDFColor(int theNumber, double theRed, double theGreen, double theBlue) {
+ public PDFColor(double theRed, double theGreen, double theBlue) {
//super(theNumber);
-
- this.colorspace=0;
+ this.colorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
this.red = theRed;
this.green = theGreen;
this.blue = theBlue;
}
- public PDFColor(int theNumber, double theCyan, double theMagenta, double theYellow, double theBlack) {
+ public PDFColor(double theCyan, double theMagenta, double theYellow, double theBlack) {
//super(theNumber);//?
- this.colorspace = 1;
+ this.colorSpace = new ColorSpace(ColorSpace.DEVICE_CMYK);
this.cyan = theCyan;
this.magenta = theMagenta;
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)
+ if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_RGB)
{//RGB
theColorVector.addElement(new Double(this.red));
theColorVector.addElement(new Double(this.green));
theColorVector.addElement(new Double(this.blue));
}
- else
+ else if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_CMYK)
{//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));
-
+ }
+ else
+ {//GRAY
+ theColorVector.addElement(new Double(this.black));
}
return(theColorVector);
}
return(this.black);
}
- public String getColorspaceOut(boolean fillNotStroke)
+ public void setColorSpace(int theColorSpace)
+ {
+ int theOldColorSpace = this.colorSpace.getColorSpace();
+ if(theOldColorSpace!=theColorSpace)
+ {
+ if (theOldColorSpace==ColorSpace.DEVICE_RGB)
+ {
+ if(theColorSpace==ColorSpace.DEVICE_CMYK)
+ {
+ this.convertRGBtoCMYK();
+ }
+ else //convert to Gray?
+ {
+ this.convertRGBtoGRAY();
+ }
+
+ } else if(theOldColorSpace==ColorSpace.DEVICE_CMYK)
+ {
+ if(theColorSpace == ColorSpace.DEVICE_RGB)
+ {
+ this.convertCMYKtoRGB();
+ }
+ else //convert to Gray?
+ {
+ this.convertCMYKtoGRAY();
+ }
+ } else //used to be Gray
+ {
+ if(theColorSpace == ColorSpace.DEVICE_RGB)
+ {
+ this.convertGRAYtoRGB();
+ }
+ else //convert to CMYK?
+ {
+ this.convertGRAYtoCMYK();
+ }
+ }
+ this.colorSpace.setColorSpace(theColorSpace);
+ }
+ }
+
+ 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)
+ if(this.colorSpace.getColorSpace()==ColorSpace.DEVICE_RGB)
{//colorspace is RGB
- if((this.red < 0)
- || (this.green < 0)
- || (this.blue < 0))
- {
- this.convertCMYKtoRGB();
- } //end of convert from CMYK
//output RGB
if(fillNotStroke)
+" RG \n");
}
}//end of output RGB
- else
+ else if (this.colorSpace.getColorSpace() == ColorSpace.DEVICE_CMYK)
{//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
}
}//end of if CMYK
+ else { //means we're in DeviceGray or Unknown.
+ //assume we're in DeviceGray, because otherwise we're screwed.
+
+ if(fillNotStroke)
+ {
+ p.append(this.doubleOut(this.black) + " g \n");
+ }
+ else
+ {
+ p.append(this.doubleOut(this.black) + " G \n");
+ }
+
+ }
return(p.toString());
}
public String doubleOut(double doubleDown)
{
+
StringBuffer p = new StringBuffer();
double trouble = doubleDown % 1;
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;
+ this.red = (this.black / this.blackFactor) + this.red;
+ this.green = (this.black / this.blackFactor) + this.green;
+ this.blue = (this.black / this.blackFactor) + this.blue;
}
protected void convertRGBtoCMYK()
{
//convert RGB to CMYK
- this.cyan = 1.0 - this.red;
+ this.cyan = 1.0 - this.red;
this.magenta= 1.0 - this.green;
this.yellow = 1.0 - this.blue;
if (this.blue < tempDouble)
tempDouble = this.blue;
- this.black = tempDouble / 2.0; // 3.0???
+ this.black = tempDouble / this.blackFactor;
*/
}
+ protected void convertGRAYtoRGB()
+ {
+ this.red = 1.0 - this.black;
+ this.green= 1.0 - this.black;
+ this.blue = 1.0 - this.black;
+ }
-
+ protected void convertGRAYtoCMYK()
+ {
+ this.cyan = this.black;
+ this.magenta= this.black;
+ this.yellow = this.black;
+ //this.black=0.0;//?
+ }
+
+ protected void convertCMYKtoGRAY()
+ {
+ double tempDouble=0.0;
+
+ //pick the lowest color
+ tempDouble = this.cyan;
+
+ if (this.magenta < tempDouble)
+ tempDouble = this.magenta;
+
+ if (this.yellow < tempDouble)
+ tempDouble = this.yellow;
+
+ this.black = (tempDouble / this.blackFactor);
+
+ }
+
+ protected void convertRGBtoGRAY()
+ {
+ double tempDouble=0.0;
+
+ //pick the lowest color
+ tempDouble = this.red;
+
+ if (this.green < tempDouble)
+ tempDouble = this.green;
+
+ if (this.blue < tempDouble)
+ tempDouble = this.blue;
+
+ this.black = 1.0 - (tempDouble / this.blackFactor);
+
+ }
String toPDF()
{
//Java...
import java.util.Vector;
+
+//FOP
+import org.apache.fop.datatypes.ColorSpace;
+
/**
* class representing a PDF Smooth Shading object.
*
protected int shadingType = 3; //Default
/**
- * A String representing the colorspace. "DeviceRGB" is an example.
+ * A ColorSpace representing the colorspace. "DeviceRGB" is an example.
*/
- protected StringBuffer colorSpace = null;
-
+ //protected StringBuffer colorSpace = null;
+ protected ColorSpace colorSpace=null;
/**
* The background color. Since shading is opaque,
* this is very rarely used.
* It's optional, the default is the identity matrix
* @param theFunction The PDF Function that maps an (x,y) location to a color
*/
- public PDFShading(int theNumber, String theShadingName, int theShadingType, StringBuffer theColorSpace,
+ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace,
Vector theBackground, Vector theBBox, boolean theAntiAlias,
Vector theDomain, Vector theMatrix, PDFFunction theFunction)
{
* The default is [false, false]
*/
public PDFShading(int theNumber, String theShadingName,
- int theShadingType, StringBuffer theColorSpace,
+ int theShadingType, ColorSpace theColorSpace,
Vector theBackground, Vector theBBox, boolean theAntiAlias,
Vector theCoords, Vector theDomain, PDFFunction theFunction,
Vector theExtend)
* @param theDecode Vector of Doubles see PDF 1.3 spec pages 303 to 312.
* @param theFunction the PDFFunction
*/
- public PDFShading(int theNumber, String theShadingName, int theShadingType, StringBuffer theColorSpace,
+ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace,
Vector theBackground, Vector theBBox, boolean theAntiAlias,
int theBitsPerCoordinate, int theBitsPerComponent,
int theBitsPerFlag, Vector theDecode, PDFFunction theFunction)
* @param theFunction The PDFFunction that's mapped on to this shape
* @param theNumber the object number of this PDF object.
*/
- public PDFShading(int theNumber, String theShadingName, int theShadingType, StringBuffer theColorSpace,
+ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace,
Vector theBackground, Vector theBBox, boolean theAntiAlias,
int theBitsPerCoordinate, int theBitsPerComponent,
Vector theDecode, int theVerticesPerRow, PDFFunction theFunction)
+ " obj\n<< \n/ShadingType "+this.shadingType+" \n");
if(this.colorSpace != null)
{
- p.append("/ColorSpace /"+this.colorSpace+" \n");
+ p.append("/ColorSpace /"
+ +this.colorSpace.getColorSpacePDFString()+" \n");
}
if(this.background != null)