You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by da...@apache.org on 2009/04/07 19:15:46 UTC
svn commit: r762859 [1/2] - in /incubator/pdfbox/trunk:
src/main/java/org/apache/pdfbox/cos/
src/main/java/org/apache/pdfbox/pdmodel/graphics/color/
src/main/java/org/apache/pdfbox/util/operator/ test/input/rendering/
Author: danielwilson
Date: Tue Apr 7 17:15:45 2009
New Revision: 762859
URL: http://svn.apache.org/viewvc?rev=762859&view=rev
Log:
Got Separation color spaces to render on the non-stroking side.
Along the way, added logging capability to some other classes.
Also including a test case for the Separation work.
Added:
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingSeparation.java
incubator/pdfbox/trunk/test/input/rendering/FANTASTICCMYK.ai
incubator/pdfbox/trunk/test/input/rendering/FANTASTICCMYK.ai-1.png (with props)
Modified:
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java?rev=762859&r1=762858&r2=762859&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java Tue Apr 7 17:15:45 2009
@@ -478,4 +478,16 @@
add( new COSFloat( value[i] ) );
}
}
+
+ /*
+ Return contents of COSArray as a Java List
+ */
+ public List toList()
+ {
+ ArrayList retList = new ArrayList(size());
+ for (int i = 0; i < size(); i++)
+ retList.add(get(i));
+
+ return retList;
+ }
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=762859&r1=762858&r2=762859&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Tue Apr 7 17:15:45 2009
@@ -1313,5 +1313,21 @@
}
return retval;
}
+
+ /*
+ Don't just tell me it's a dictionary -- tell me its contents!
+ */
+ public String toString()
+ {
+ String RetVal = "COSDictionary{";
+ for (int i = 0; i<size(); i++){
+ COSName key = (COSName)keyList().get(i);
+ RetVal = RetVal + "(" + key + ":" + getDictionaryObject(key).toString() + ") ";
+ }
+ RetVal = RetVal + "}";
+
+ return RetVal;
+ }
+
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java?rev=762859&r1=762858&r2=762859&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpaceFactory.java Tue Apr 7 17:15:45 2009
@@ -27,6 +27,7 @@
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.exceptions.LoggingObject;
/**
* This class represents a color space in a pdf document.
@@ -34,7 +35,7 @@
* @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
* @version $Revision: 1.11 $
*/
-public final class PDColorSpaceFactory
+public final class PDColorSpaceFactory extends LoggingObject
{
/**
* Private constructor for utility classes.
@@ -68,10 +69,6 @@
{
retval = new PDCalGray( array );
}
- else if( type.getName().equals( PDDeviceRGB.NAME ) )
- {
- retval = PDDeviceRGB.INSTANCE;
- }
else if( type.getName().equals( PDCalRGB.NAME ) )
{
retval = new PDCalRGB( array );
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=762859&r1=762858&r2=762859&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java Tue Apr 7 17:15:45 2009
@@ -24,6 +24,7 @@
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
/**
@@ -81,7 +82,8 @@
*/
public int getNumberOfComponents() throws IOException
{
- return 1;
+ //return 1;
+ return array.size();
}
/**
@@ -101,18 +103,18 @@
PDColorSpace alt = getAlternateColorSpace();
- //logger().info(alt.toString());
+ logger().info(alt.toString());
ColorSpace CS = alt.createColorSpace();///dwilson 12/15/07
- //logger().info(CS.toString() + " reporting type " + CS.getType() + " and having component count of " + CS.getNumComponents());
+ logger().info(CS.toString() + " reporting type " + CS.getType() + " and having component count of " + CS.getNumComponents());
return CS;
}catch (IOException IOe){
- logger().severe(FullStackTrace(IOe));
+ logger().severe(IOe.toString() + "\n at\n" + FullStackTrace(IOe));
throw IOe;
}catch (Exception e){
- logger().severe(FullStackTrace(e));
+ logger().severe(e.toString() + "\n at\n" +FullStackTrace(e));
throw new IOException("Failed to Create ColorSpace");
}
}
@@ -128,7 +130,6 @@
*/
public ColorModel createColorModel( int bpc ) throws IOException
{
- //throw new IOException( "Not implemented" );
return getAlternateColorSpace().createColorModel(bpc);
}
@@ -206,4 +207,31 @@
{
array.set( 3, tint );
}
+
+
+ /*
+ Don't just tell me it's a Separation -- tell me its contents!
+ */
+ public String toString()
+ {
+
+ String RetVal = NAME + "{ " + array.toString() + " }";
+
+ return RetVal;
+ }
+
+ /*
+ Some of the key values are stored within the COSDictionary, item 3 in the array.
+ I don't necessarily want to expose the entire dictionary publicly (except in toString()),
+ but need access privately in order to expose the color values publicly.
+ */
+ private COSDictionary getDictionary() throws IOException
+ {
+ return (COSDictionary) array.getObject( 3);
+ }
+
+ public COSArray getColorValues() throws IOException
+ {
+ return (COSArray) getDictionary().getDictionaryObject("C1");
+ }
}
Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java?rev=762859&r1=762858&r2=762859&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java Tue Apr 7 17:15:45 2009
@@ -50,8 +50,11 @@
newOperator = new SetNonStrokingCMYKColor();
else if (colorSpace instanceof PDICCBased)
newOperator = new SetNonStrokingICCBasedColor();
- else if (colorSpace instanceof PDCalRGB)
+ else if (colorSpace instanceof PDCalRGB)
newOperator = new SetNonStrokingCalRGBColor();
+ else if (colorSpace instanceof PDSeparation)
+ newOperator = new SetNonStrokingSeparation();
+
if (newOperator != null)
{
newOperator.setContext(getContext());
Added: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingSeparation.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingSeparation.java?rev=762859&view=auto
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingSeparation.java (added)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingSeparation.java Tue Apr 7 17:15:45 2009
@@ -0,0 +1,80 @@
+/*
+ * 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.pdfbox.util.operator;
+
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSNumber;
+import org.apache.pdfbox.pdmodel.graphics.color.*;
+import org.apache.pdfbox.util.PDFOperator;
+import org.apache.pdfbox.pdfviewer.PageDrawer;
+
+import java.io.IOException;
+
+/**
+ *
+ * @author <a href="mailto:WilliamstonConsulting@GMail.com">Daniel Wilson</a>
+ * @version $Revision: 1.0 $
+ */
+public class SetNonStrokingSeparation extends OperatorProcessor
+{
+ /**
+ * scn Set color space for non stroking operations.
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ * @throws IOException If an error occurs while processing the font.
+ */
+ public void process(PDFOperator operator, List arguments) throws IOException
+ {
+ PDColorSpaceInstance colorInstance = context.getGraphicsState().getNonStrokingColorSpace();
+ PDColorSpace colorSpace = colorInstance.getColorSpace() ;//.getAlternateColorSpace();
+ logger().info("handling color space " + colorSpace.toString());
+ logger().info("Arguments: " + arguments.toString());
+ if (colorSpace instanceof PDSeparation){
+ PDSeparation sep = (PDSeparation) colorSpace;
+ colorSpace = sep.getAlternateColorSpace();
+ logger().info("now handling alternate color space " + colorSpace.toString());
+
+ if (colorSpace != null)
+ {
+ OperatorProcessor newOperator = null;
+ if (colorSpace instanceof PDDeviceGray)
+ newOperator = new SetNonStrokingGrayColor();
+ else if (colorSpace instanceof PDDeviceRGB)
+ newOperator = new SetNonStrokingRGBColor();
+ else if (colorSpace instanceof PDDeviceCMYK)
+ newOperator = new SetNonStrokingCMYKColor();
+ else if (colorSpace instanceof PDICCBased)
+ newOperator = new SetNonStrokingICCBasedColor();
+ else if (colorSpace instanceof PDCalRGB)
+ newOperator = new SetNonStrokingCalRGBColor();
+ else if (colorSpace instanceof PDSeparation)
+ newOperator = new SetNonStrokingSeparation();
+
+ if (newOperator != null)
+ {
+ newOperator.setContext(getContext());
+ newOperator.process(operator, sep.getColorValues().toList());
+ }
+ else
+ logger().info("Not supported colorspace "+colorSpace.getName() + " within operator "+operator.getOperation());
+ }
+
+ } else throw new IOException ("Invalid attempt to process colorspace " + colorSpace.toString() + " in SetNonStrokingSeparation");
+
+ }
+}