Hi Daniel, great achievement. I've already tried to implement these operators some time ago, but I got stuck somewhere in the middle of it...
Thanks!! [email protected] schrieb: > Author: danielwilson > Date: Wed Apr 29 20:32:11 2009 > New Revision: 769915 > > URL: http://svn.apache.org/viewvc?rev=769915&view=rev > Log: > Implemented operators W and W* (PDF section 4.4.3) > > Added: > > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipEvenOddRule.java > > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipNonZeroRule.java > Modified: > > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java > > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/SetNonStrokingColor.java > incubator/pdfbox/trunk/src/main/resources/Resources/PageDrawer.properties > incubator/pdfbox/trunk/test/input/rendering/HOTRODCMYK.ai-1.png > > Modified: > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java > URL: > http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=769915&r1=769914&r2=769915&view=diff > ============================================================================== > --- > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java > (original) > +++ > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java > Wed Apr 29 20:32:11 2009 > @@ -381,4 +381,31 @@ > scaleY = at.getScaleY(); > return ScaledPoint(x, y, scaleX, scaleY); > } > + > + > + /** > + * > + * Fill the path > + * > + * @param windingRule The winding rule this path will use. > + */ > + public void SetClippingPath(int windingRule) throws IOException{ > + > + graphics.setColor( > getGraphicsState().getNonStrokingColorSpace().createColor() ); > + > + getLinePath().setWindingRule(windingRule); > + > + graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, > RenderingHints.VALUE_ANTIALIAS_OFF ); > + List subPaths = getLineSubPaths(); > + for( int i=0; i<subPaths.size(); i++ ) > + { > + GeneralPath subPath = (GeneralPath)subPaths.get( i ); > + if (subPath.getCurrentPoint() != null){ > + subPath.closePath(); > + } > + } > + > + graphics.setClip( getLinePath() ); > + getLinePath().reset(); > + } > } > > 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=769915&r1=769914&r2=769915&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 > Wed Apr 29 20:32:11 2009 > @@ -41,6 +41,8 @@ > PDColorSpace colorSpace = > context.getGraphicsState().getNonStrokingColorSpace().getColorSpace(); > if (colorSpace != null) > { > + //logger().info("Setting NonStroking colorspace to " + > colorSpace); > + > OperatorProcessor newOperator = null; > if (colorSpace instanceof PDDeviceGray) > newOperator = new SetNonStrokingGrayColor(); > @@ -61,9 +63,9 @@ > newOperator.process(operator, arguments); > } > else > - logger().info("Not supported colorspace > "+colorSpace.getName() + " within operator "+operator.getOperation()); > - } > - else > - logger().warning("Colorspace not found in > "+getClass().getName()+".process!!"); > + logger().warning("Not supported colorspace > "+colorSpace.getName() + " within operator "+operator.getOperation()); > + } > + else > + logger().warning("Colorspace not found in > "+getClass().getName()+".process!!"); > } > } > > Added: > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipEvenOddRule.java > URL: > http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipEvenOddRule.java?rev=769915&view=auto > ============================================================================== > --- > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipEvenOddRule.java > (added) > +++ > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipEvenOddRule.java > Wed Apr 29 20:32:11 2009 > @@ -0,0 +1,56 @@ > +/* > + * 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.Graphics2D; > +import java.awt.RenderingHints; > +import java.awt.geom.GeneralPath; > +import java.io.IOException; > +import java.util.List; > + > +import org.apache.pdfbox.pdfviewer.PageDrawer; > +import org.apache.pdfbox.util.PDFOperator; > +import org.apache.pdfbox.util.operator.OperatorProcessor; > + > +/** > + * Implementation of content stream operator for page drawer. > + * > + * @author <a href="mailto:[email protected]">Daniel > Wilson</a> > + * @version $Revision: 1.1 $ > + */ > +public class ClipEvenOddRule extends OperatorProcessor > +{ > + > + > + /** > + * process : W* : set clipping path using even odd rule. > + * @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 arguments) throws > IOException > + { > + > + try { > + PageDrawer drawer = (PageDrawer)context; > + drawer.SetClippingPath(GeneralPath.WIND_EVEN_ODD); > + } catch (Exception e) { > + logger().warning(e.getMessage() + "\n at\n" + > FullStackTrace(e)); > + } > + } > +} > > Added: > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipNonZeroRule.java > URL: > http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipNonZeroRule.java?rev=769915&view=auto > ============================================================================== > --- > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipNonZeroRule.java > (added) > +++ > incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/ClipNonZeroRule.java > Wed Apr 29 20:32:11 2009 > @@ -0,0 +1,56 @@ > +/* > + * 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.Graphics2D; > +import java.awt.RenderingHints; > +import java.awt.geom.GeneralPath; > +import java.io.IOException; > +import java.util.List; > + > +import org.apache.pdfbox.pdfviewer.PageDrawer; > +import org.apache.pdfbox.util.PDFOperator; > +import org.apache.pdfbox.util.operator.OperatorProcessor; > + > +/** > + * Implementation of content stream operator for page drawer. > + * > + * @author <a href="mailto:[email protected]">Daniel > Wilson</a> > + * @version $Revision: 1.1 $ > + */ > +public class ClipNonZeroRule extends OperatorProcessor > +{ > + > + > + /** > + * process : W : Set the clipping path using non zero winding rule. > + * @param operator The operator that is being executed. > + * @param arguments List > + * > + * @throws IOException If there is an error during the processing. > + */ > + public void process(PDFOperator operator, List arguments) throws > IOException > + { > + > + try { > + PageDrawer drawer = (PageDrawer)context; > + drawer.SetClippingPath(GeneralPath.WIND_NON_ZERO); > + } catch (Exception e) { > + logger().warning(e.getMessage() + "\n at\n" + > FullStackTrace(e)); > + } > + } > +} > > Modified: > incubator/pdfbox/trunk/src/main/resources/Resources/PageDrawer.properties > URL: > http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/resources/Resources/PageDrawer.properties?rev=769915&r1=769914&r2=769915&view=diff > ============================================================================== > --- incubator/pdfbox/trunk/src/main/resources/Resources/PageDrawer.properties > (original) > +++ incubator/pdfbox/trunk/src/main/resources/Resources/PageDrawer.properties > Wed Apr 29 20:32:11 2009 > @@ -70,8 +70,8 @@ > Tz=org.apache.pdfbox.util.operator.SetHorizontalTextScaling > v=org.apache.pdfbox.util.operator.pagedrawer.CurveToReplicateInitialPoint > w=org.apache.pdfbox.util.operator.pagedrawer.SetLineWidth > -#W org.apache.pdfbox.util.operator.NotImplemented ##clipping path operator, > nonzero rule, section 4.4.3 > -#W* org.apache.pdfbox.util.operator.NotImplemented ##clipping path operator, > even-odd rule, section 4.4.3 > +W org.apache.pdfbox.util.operator.pagedrawer.ClipNonZeroRule > +W* org.apache.pdfbox.util.operator.pagedrawer.ClipEvenOddRule > y=org.apache.pdfbox.util.operator.pagedrawer.CurveToReplicateFinalPoint > \'=org.apache.pdfbox.util.operator.MoveAndShow > \"=org.apache.pdfbox.util.operator.SetMoveAndShow > > Modified: incubator/pdfbox/trunk/test/input/rendering/HOTRODCMYK.ai-1.png > URL: > http://svn.apache.org/viewvc/incubator/pdfbox/trunk/test/input/rendering/HOTRODCMYK.ai-1.png?rev=769915&r1=769914&r2=769915&view=diff > ============================================================================== > Binary files - no diff available. > >
