Author: danielwilson
Date: Thu Feb 25 16:51:29 2010
New Revision: 916345
URL: http://svn.apache.org/viewvc?rev=916345&view=rev
Log:
Infrastructure for sh operator ... PDFBOX-615
Added:
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDShading.java
pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SHFill.java
Modified:
pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=916345&r1=916344&r2=916345&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java Thu Feb 25
16:51:29 2010
@@ -532,6 +532,9 @@
*/
public static final COSName SEPARATION = new COSName( "Separation" );
+ /** "Shading" */
+ public static final COSName SHADING = new COSName( "Shading" );
+
/** "Size" */
public static final COSName SIZE = new COSName( "Size" );
Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=916345&r1=916344&r2=916345&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
(original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Thu
Feb 25 16:51:29 2010
@@ -36,6 +36,7 @@
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
+import org.apache.pdfbox.pdmodel.graphics.PDShading;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
@@ -44,6 +45,11 @@
import org.apache.pdfbox.util.PDFStreamEngine;
import org.apache.pdfbox.util.ResourceLoader;
import org.apache.pdfbox.util.TextPosition;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSDictionary;
+
/**
* This will paint a page in a PDF document to a graphics context.
@@ -343,5 +349,157 @@
}
getLinePath().reset();
}
+
+ /**
+ * Fill with Shading. Called by SHFill operator.
+ *
+ * @param ShadingName The name of the Shading Dictionary to use for this
fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ public void SHFill(COSName ShadingName) throws IOException
+ {
+ PDShading Shading =FindShadingDictionary(ShadingName);
+ log.info("Shading = " + Shading.toString());
+
+ switch (Shading.getShadingType()){
+ case 1:
+ SHFill_Function(Shading);
+ break;
+ case 2:
+ SHFill_Axial(Shading);
+ break;
+ case 3:
+ SHFill_Radial(Shading);
+ break;
+ case 4:
+ SHFill_FreeGourad(Shading);
+ break;
+ case 5:
+ SHFill_LatticeGourad(Shading);
+ break;
+ case 6:
+ SHFill_CoonsPatch(Shading);
+ break;
+ case 7:
+ SHFill_TensorPatch(Shading);
+ break;
+
+ default:
+ throw new IOException("Invalid ShadingType " +
Shading.getShadingType() + " for Shading " + ShadingName);
+ }
+ }
+
+ /**
+ * Find the appropriate Shading Dictionary. This is its own private
function as it is really not appropriate to override when deriving from
PageDrawer.
+ *
+ * @param ShadingName The name of the Shading Dictionary to use for this
fill instruction.
+ *
+ * @returns The PDShading object
+ * @throws IOException If there is an IO error while attempting to find
the appropriate PDShading object.
+ */
+ private PDShading FindShadingDictionary(COSName ShadingName) throws
IOException
+ {
+
+ PDResources resources = (PDResources)page.getResources();
+
+ COSDictionary AllShadings =
(COSDictionary)(resources.getCOSDictionary().getDictionaryObject(COSName.SHADING));
+
+ PDShading Shading = new PDShading(ShadingName,
(COSDictionary)(AllShadings.getDictionaryObject(ShadingName)));
+
+ return Shading;
+
+ }
+
+ /**
+ * Fill with a Function-based gradient / shading.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_Function(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
+
+ /**
+ * Fill with an Axial Shading.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_Axial(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+
+ }
+ /**
+ * Fill with a Radial gradient / shading.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_Radial(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
+
+ /**
+ * Fill with a Free-form Gourad-shaded triangle mesh.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_FreeGourad(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
+
+ /**
+ * Fill with a Lattice-form Gourad-shaded triangle mesh.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_LatticeGourad(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
+
+ /**
+ * Fill with a Coons patch mesh
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_CoonsPatch(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
+
+ /**
+ * Fill with a Tensor-product patch mesh.
+ * If extending the class, override this and its siblings, not the public
SHFill method.
+ *
+ * @param Shading The Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException If there is an IO error while shade-filling the
path/clipping area.
+ */
+ protected void SHFill_TensorPatch(PDShading Shading) throws IOException
+ {
+ throw new IOException("Not Implemented");
+ }
}
Added:
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDShading.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDShading.java?rev=916345&view=auto
==============================================================================
---
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDShading.java
(added)
+++
pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/PDShading.java
Thu Feb 25 16:51:29 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.pdmodel.graphics;
+
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+
+//import java.awt.color.ColorSpace;
+//import java.awt.image.ColorModel;
+
+import java.io.IOException;
+
+/**
+ * This class represents a Shading Pattern color space.
+ * See section 4.6.3 of the PDF 1.7 specification.
+ *
+ * @author <a href="mailto:[email protected]">Daniel
wilson</a>
+ * @version $Revision: 1.0 $
+ */
+public class PDShading implements COSObjectable
+{
+ private COSDictionary DictShading;
+ private COSName shadingname;
+
+ /**
+ * The name of this object.
+ */
+ public static final String NAME = "Shading";
+
+ /**
+ * Default constructor.
+ */
+ public PDShading()
+ {
+ DictShading = new COSDictionary();
+ //DictShading.add( COSName.getPDFName( NAME ) );
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param shading The shading dictionary.
+ */
+ public PDShading(COSName name, COSDictionary shading)
+ {
+ DictShading = shading;
+ shadingname = name;
+ }
+
+ /**
+ * This will return the name of the object.
+ *
+ * @return The name of the object.
+ */
+ public String getName()
+ {
+ return NAME;
+ }
+
+ /**
+ * Convert this standard java object to a COS object.
+ *
+ * @return The cos object that matches this Java object.
+ */
+ public COSBase getCOSObject()
+ {
+ return COSName.getPDFName( getName() );
+ }
+
+ /**
+ * This will return the name of this particular shading dictionary
+ *
+ * @return The name of the shading dictionary
+ */
+ public COSName getShadingName()
+ {
+ return shadingname;
+ }
+
+ public int getShadingType()
+ {
+ return DictShading.getInt("ShadingType");
+ }
+
+ public PDColorSpace getColorSpace() throws IOException
+ {
+ return
PDColorSpaceFactory.createColorSpace(DictShading.getDictionaryObject("ColorSpace"));
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public String toString()
+ {
+ String sColorSpace;
+ try
+ {
+ sColorSpace = getColorSpace().toString();
+ }catch (IOException e)
+ {
+ sColorSpace = "Failure retrieving ColorSpace: " + e.toString();
+ }
+ String s = "Shading " + shadingname + "\n"
+ + "\tShadingType: " + getShadingType() + "\n"
+ + "\tColorSpace: " + sColorSpace + "\n"
+ + "\tRaw Value:\n" +
+ DictShading.toString();
+
+ return s;
+ }
+
+}
Added:
pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SHFill.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SHFill.java?rev=916345&view=auto
==============================================================================
---
pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SHFill.java
(added)
+++
pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/SHFill.java
Thu Feb 25 16:51:29 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.pagedrawer;
+
+import java.awt.geom.GeneralPath;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdfviewer.PageDrawer;
+import org.apache.pdfbox.util.PDFOperator;
+import org.apache.pdfbox.util.operator.OperatorProcessor;
+
+/**
+ * Implementation of sh operator for page drawer.
+ * See section 4.6.3 of the PDF 1.7 specification.
+ *
+ * @author <a href="mailto:[email protected]">Daniel
Wilson</a>
+ * @version $Revision: 1.0 $
+ */
+public class SHFill extends OperatorProcessor
+{
+
+ /**
+ * Log instance.
+ */
+ private static final Log log = LogFactory.getLog(SHFill.class);
+
+ /**
+ * process : sh : shade fill the path or clipping area.
+ * @param operator The operator that is being executed.
+ * @param arguments List
+ *
+ * @throws IOException if there is an error during execution.
+ */
+ public void process(PDFOperator operator, List<COSBase> arguments) throws
IOException
+ {
+ try
+ {
+ PageDrawer drawer = (PageDrawer)context;
+ //for now, just dump the arg list ...
+ log.info("shfill arguments: " + arguments.toString());
+ drawer.SHFill((COSName)(arguments.get(0)));
+
+ }
+ catch (Exception e)
+ {
+ log.warn(e, e);
+ }
+ }
+}