From de36e85d6f4d716818ef0981d67ea16904a9e112 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 8 Jul 2010 08:48:02 +0000 Subject: [PATCH] Cleanup of PDFColor, removing unused functionality. PDFColor is only used for transparent color of bitmap images in which case only sRGB and Gray are needed. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Color@961638 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFColor.java | 103 +++------------------- 1 file changed, 10 insertions(+), 93 deletions(-) diff --git a/src/java/org/apache/fop/pdf/PDFColor.java b/src/java/org/apache/fop/pdf/PDFColor.java index 37ccd62b9..781012cfa 100644 --- a/src/java/org/apache/fop/pdf/PDFColor.java +++ b/src/java/org/apache/fop/pdf/PDFColor.java @@ -24,12 +24,14 @@ import java.awt.color.ColorSpace; import java.util.ArrayList; import java.util.List; -import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; /** - * PDF Color object. - * This is used to output color to a PDF content stream. + * PDF Color object. It is currently only used to hold the transparent color of a masked bitmap + * image. And in this context, only RGB and Gray values are used. + *

+ * Use of this class is discouraged. {@link PDFColorHandler} is now used for in-content color + * selection. For masked bitmaps, it may be wiser to switch to {@link Color} in the long run. */ public class PDFColor extends PDFPathPaint { // could be 3.0 as well. @@ -43,14 +45,8 @@ public class PDFColor extends PDFPathPaint { private double yellow = -1.0; private double black = -1.0; - // TODO - It would probably be better to reorganize PDFPathPaint/PDFColor/PDFColorSpace - // class hierarchy. However, at this early stages of my FOP understanding, I can - // not really oversee the consequences of such a switch (nor whether it would be - // appropriate). - private ColorWithAlternatives colorExt = null; - /** - * Create a PDF color with double values ranging from 0 to 1 + * Create a PDF color with double values ranging from 0 to 1. * * @param theRed the red double value * @param theGreen the green double value @@ -65,83 +61,28 @@ public class PDFColor extends PDFPathPaint { this.blue = theBlue; } - /** - * Create PDFColor for the given document and based on the java.awt.Color object - * - * In case the java.awt.Color is an instance of the ColorExt class a PDFICCStream is added to - * the PDFDocument that is being created - * - * @param pdfDoc PDFDocument that is being created - * @param col Color object from which to create this PDFColor - */ - public PDFColor(PDFDocument pdfDoc, Color col) { - this(col); - // TODO - 1) There is a potential conflict when FOP and Batik elements use the same color - // profile name for different profiles. - // 2) In case the same color profile is used with different names it will be - // included multiple times in the PDF - // - /* - if (colorExt != null - && pdfDoc.getResources().getColorSpace(colorExt.getIccProfileName()) == null) { - PDFICCStream pdfIccStream = new PDFICCStream(); - ColorSpace ceCs = colorExt.getOrigColorSpace(); - try { - pdfIccStream.setColorSpace(((ICC_ColorSpace)ceCs).getProfile(), null); - pdfIccStream.setData( - ((ICC_ColorSpace)colorExt.getColorSpace()).getProfile().getData()); - } catch (IOException ioe) { - log.error("Failed to set profile data for " + colorExt.getIccProfileName()); - } - pdfDoc.registerObject(pdfIccStream); - pdfDoc.getFactory().makeICCBasedColorSpace( - null, colorExt.getIccProfileName(), pdfIccStream); - if (log.isInfoEnabled()) { - log.info("Adding PDFICCStream " + colorExt.getIccProfileName() - + " for " + colorExt.getIccProfileSrc()); - } - }*/ - } - /** * Create a PDF color from a java.awt.Color object. * * Different Color objects are handled differently. Cases recognized are. * * 1. CMYK color - * 2. ColorExt color - * 3. 'Normal' java.awt.Color (RGB case assumed) + * 3. 'Normal' java.awt.Color (RGB case assumed or implicit conversion to sRGB) * * @param col the java.awt.Color object for which to create a PDFColor object */ public PDFColor(java.awt.Color col) { ColorSpace cs = col.getColorSpace(); - ColorWithAlternatives ce = null; - if (col instanceof ColorWithAlternatives) { - ce = (ColorWithAlternatives)col; - //cs = ce.getOrigColorSpace(); - } if (cs != null && cs instanceof DeviceCMYKColorSpace) { // CMYK case this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_CMYK); - float[] cmyk = (ce == null - ? col.getColorComponents(null) - : col.getColorComponents(null)/*ce.getOriginalColorComponents()*/); + float[] cmyk = col.getColorComponents(null); this.cyan = cmyk[0]; this.magenta = cmyk[1]; this.yellow = cmyk[2]; this.black = cmyk[3]; - } else if (ce != null) { - // ColorExt (ICC) case - this.colorExt = ce; - float[] rgb = col.getRGBColorComponents(null); - this.red = rgb[0]; - this.green = rgb[1]; - this.blue = rgb[2]; - // TODO - See earlier todo - this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); } else { - // Default (RGB) Color + // Default (RGB) Color (ICC Colors are converted to sRGB, too) this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); float[] comps = new float[3]; comps = col.getColorComponents(comps); @@ -161,7 +102,6 @@ public class PDFColor extends PDFPathPaint { public PDFColor(int theRed, int theGreen, int theBlue) { this(((double)theRed) / 255d, ((double)theGreen) / 255d, ((double)theBlue) / 255d); - } /** @@ -174,8 +114,6 @@ public class PDFColor extends PDFPathPaint { */ public PDFColor(double theCyan, double theMagenta, double theYellow, double theBlack) { - // super(theNumber);//? - this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_CMYK); this.cyan = theCyan; @@ -349,28 +287,7 @@ public class PDFColor extends PDFPathPaint { public String getColorSpaceOut(boolean fillNotStroke) { StringBuffer p = new StringBuffer(""); - if (false && this.colorExt != null) { - /* - if (fillNotStroke) { - p.append("/" + this.colorExt.getIccProfileName() + " cs "); - } else { - p.append("/" + this.colorExt.getIccProfileName() + " CS "); - } - float[] colorArgs; - colorArgs = this.colorExt.getOriginalColorComponents(); - if (colorArgs == null) { - colorArgs = this.colorExt.getColorComponents(null); - } - for (int ix = 0; ix < colorArgs.length; ix++) { - p.append(colorArgs[ix] + " "); - } - if (fillNotStroke) { - p.append("sc\n"); - } else { - p.append("SC\n"); - } - */ - } else if (this.colorSpace.getColorSpace() + if (this.colorSpace.getColorSpace() == PDFDeviceColorSpace.DEVICE_RGB) { // colorspace is RGB // according to pdfspec 12.1 p.399 // if the colors are the same then just use the g or G operator -- 2.39.5