From 6025b6016517c6d898d8957d1d7e03ba71431912 Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 1 Dec 2006 12:20:24 +0000 Subject: Initial import of release 2.2. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@4 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/org/pdfbox/util/operator/BeginText.java | 68 ++++++++ .../java/org/pdfbox/util/operator/Concatenate.java | 106 ++++++++++++ .../java/org/pdfbox/util/operator/EndText.java | 67 ++++++++ .../java/org/pdfbox/util/operator/GRestore.java | 67 ++++++++ src/main/java/org/pdfbox/util/operator/GSave.java | 66 ++++++++ src/main/java/org/pdfbox/util/operator/Invoke.java | 113 +++++++++++++ .../java/org/pdfbox/util/operator/MoveAndShow.java | 75 +++++++++ .../java/org/pdfbox/util/operator/MoveText.java | 76 +++++++++ .../pdfbox/util/operator/MoveTextSetLeading.java | 80 +++++++++ .../java/org/pdfbox/util/operator/NextLine.java | 82 ++++++++++ .../pdfbox/util/operator/OperatorProcessor.java | 93 +++++++++++ .../org/pdfbox/util/operator/SetCharSpacing.java | 79 +++++++++ .../util/operator/SetGraphicsStateParameters.java | 72 +++++++++ .../util/operator/SetHorizontalTextScaling.java | 64 ++++++++ .../org/pdfbox/util/operator/SetLineWidth.java | 64 ++++++++ .../java/org/pdfbox/util/operator/SetMatrix.java | 90 +++++++++++ .../org/pdfbox/util/operator/SetMoveAndShow.java | 80 +++++++++ .../util/operator/SetNonStrokingCMYKColor.java | 69 ++++++++ .../util/operator/SetNonStrokingColorSpace.java | 86 ++++++++++ .../util/operator/SetNonStrokingRGBColor.java | 69 ++++++++ .../pdfbox/util/operator/SetStrokingCMYKColor.java | 71 ++++++++ .../util/operator/SetStrokingColorSpace.java | 89 ++++++++++ .../pdfbox/util/operator/SetStrokingRGBColor.java | 71 ++++++++ .../java/org/pdfbox/util/operator/SetTextFont.java | 96 +++++++++++ .../org/pdfbox/util/operator/SetTextLeading.java | 69 ++++++++ .../pdfbox/util/operator/SetTextRenderingMode.java | 64 ++++++++ .../java/org/pdfbox/util/operator/SetTextRise.java | 64 ++++++++ .../org/pdfbox/util/operator/SetWordSpacing.java | 68 ++++++++ .../java/org/pdfbox/util/operator/ShowText.java | 73 +++++++++ .../org/pdfbox/util/operator/ShowTextGlyph.java | 99 ++++++++++++ .../java/org/pdfbox/util/operator/package.html | 9 ++ .../operator/pagedrawer/AppendRectangleToPath.java | 77 +++++++++ .../util/operator/pagedrawer/BeginInlineImage.java | 114 +++++++++++++ .../pdfbox/util/operator/pagedrawer/ClosePath.java | 59 +++++++ .../pdfbox/util/operator/pagedrawer/CurveTo.java | 73 +++++++++ .../pagedrawer/CurveToReplicateFinalPoint.java | 69 ++++++++ .../pagedrawer/CurveToReplicateInitialPoint.java | 76 +++++++++ .../util/operator/pagedrawer/FillEvenOddRule.java | 71 ++++++++ .../util/operator/pagedrawer/FillNonZeroRule.java | 71 ++++++++ .../pdfbox/util/operator/pagedrawer/Invoke.java | 180 +++++++++++++++++++++ .../pdfbox/util/operator/pagedrawer/LineTo.java | 65 ++++++++ .../pdfbox/util/operator/pagedrawer/MoveTo.java | 68 ++++++++ .../util/operator/pagedrawer/SetLineWidth.java | 65 ++++++++ .../pagedrawer/SetNonStrokingCMYKColor.java | 64 ++++++++ .../pagedrawer/SetNonStrokingColorSpace.java | 71 ++++++++ .../pagedrawer/SetNonStrokingRGBColor.java | 65 ++++++++ .../operator/pagedrawer/SetStrokingCMYKColor.java | 64 ++++++++ .../operator/pagedrawer/SetStrokingColorSpace.java | 70 ++++++++ .../operator/pagedrawer/SetStrokingRGBColor.java | 65 ++++++++ .../util/operator/pagedrawer/StrokePath.java | 73 +++++++++ .../pdfbox/util/operator/pagedrawer/package.html | 9 ++ 51 files changed, 3808 insertions(+) create mode 100644 src/main/java/org/pdfbox/util/operator/BeginText.java create mode 100644 src/main/java/org/pdfbox/util/operator/Concatenate.java create mode 100644 src/main/java/org/pdfbox/util/operator/EndText.java create mode 100644 src/main/java/org/pdfbox/util/operator/GRestore.java create mode 100644 src/main/java/org/pdfbox/util/operator/GSave.java create mode 100644 src/main/java/org/pdfbox/util/operator/Invoke.java create mode 100644 src/main/java/org/pdfbox/util/operator/MoveAndShow.java create mode 100644 src/main/java/org/pdfbox/util/operator/MoveText.java create mode 100644 src/main/java/org/pdfbox/util/operator/MoveTextSetLeading.java create mode 100644 src/main/java/org/pdfbox/util/operator/NextLine.java create mode 100644 src/main/java/org/pdfbox/util/operator/OperatorProcessor.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetCharSpacing.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetGraphicsStateParameters.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetHorizontalTextScaling.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetLineWidth.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetMatrix.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetMoveAndShow.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetNonStrokingCMYKColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetNonStrokingColorSpace.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetNonStrokingRGBColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetStrokingCMYKColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetStrokingColorSpace.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetStrokingRGBColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetTextFont.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetTextLeading.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetTextRenderingMode.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetTextRise.java create mode 100644 src/main/java/org/pdfbox/util/operator/SetWordSpacing.java create mode 100644 src/main/java/org/pdfbox/util/operator/ShowText.java create mode 100644 src/main/java/org/pdfbox/util/operator/ShowTextGlyph.java create mode 100644 src/main/java/org/pdfbox/util/operator/package.html create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/AppendRectangleToPath.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/BeginInlineImage.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/ClosePath.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/CurveTo.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateFinalPoint.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateInitialPoint.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/FillEvenOddRule.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/FillNonZeroRule.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/Invoke.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/LineTo.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/MoveTo.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetLineWidth.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingCMYKColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingColorSpace.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingRGBColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingCMYKColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingColorSpace.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingRGBColor.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/StrokePath.java create mode 100644 src/main/java/org/pdfbox/util/operator/pagedrawer/package.html (limited to 'src/main/java/org/pdfbox/util/operator') diff --git a/src/main/java/org/pdfbox/util/operator/BeginText.java b/src/main/java/org/pdfbox/util/operator/BeginText.java new file mode 100644 index 0000000..2b6af60 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/BeginText.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : +* the long sequence of conditions in processOperator is remplaced +* by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ +public class BeginText extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(BeginText.class); + + /** + * process : BT : Begin text object. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + if( LOG.isDebugEnabled() ) + { + LOG.debug(" " + this.toString()+ " from " + context.toString()); + } + context.setTextMatrix( new Matrix()); + context.setTextLineMatrix( new Matrix() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/Concatenate.java b/src/main/java/org/pdfbox/util/operator/Concatenate.java new file mode 100644 index 0000000..7fc986c --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/Concatenate.java @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.pdfbox.cos.COSNumber; +import org.apache.log4j.Logger; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : +* the long sequence of conditions in processOperator is remplaced by +* this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class Concatenate extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(Concatenate.class); + + /** + * process : cm : Concatenate matrix to current transformation matrix. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + + //concatenate matrix to current transformation matrix + COSNumber a = (COSNumber) arguments.get(0); + COSNumber b = (COSNumber) arguments.get(1); + COSNumber c = (COSNumber) arguments.get(2); + COSNumber d = (COSNumber) arguments.get(3); + COSNumber e = (COSNumber) arguments.get(4); + COSNumber f = (COSNumber) arguments.get(5); + + if( LOG.isDebugEnabled() ) + { + LOG.debug(" " + + this.toString() + " from " + context.toString()); + } + + Matrix newMatrix = new Matrix(); + newMatrix.setValue(0, 0, a.floatValue()); + newMatrix.setValue(0, 1, b.floatValue()); + newMatrix.setValue(1, 0, c.floatValue()); + newMatrix.setValue(1, 1, d.floatValue()); + newMatrix.setValue(2, 0, e.floatValue()); + newMatrix.setValue(2, 1, f.floatValue()); + + // wprinz: BUG Fix: + // In PDF, matrices have to be multiplied from left to right + // (the new matrix is left, the old one(s) are right) + + Matrix old_ctm = context.getGraphicsState().getCurrentTransformationMatrix(); + Matrix matrix_to_concat = newMatrix; + Matrix new_ctm = matrix_to_concat.multiply(old_ctm); + context.getGraphicsState().setCurrentTransformationMatrix( + new_ctm ); + + // :wprinz + + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/EndText.java b/src/main/java/org/pdfbox/util/operator/EndText.java new file mode 100644 index 0000000..2794ccf --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/EndText.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.util.PDFOperator; +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the +* long sequence of conditions in processOperator is remplaced by +* this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ +public class EndText extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(EndText.class); + + /** + * process : ET : End text object. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + if( LOG.isDebugEnabled() ) + { + LOG.debug(" "+ this.toString()); + } + context.setTextMatrix( null); + context.setTextLineMatrix( null); + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/GRestore.java b/src/main/java/org/pdfbox/util/operator/GRestore.java new file mode 100644 index 0000000..c07b8d8 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/GRestore.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import org.apache.log4j.Logger; +import java.util.List; + +import org.pdfbox.pdmodel.graphics.PDGraphicsState; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of + * conditions in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ +public class GRestore extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(GRestore.class); + + + /** + * process : Q : Restore graphics state. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + if( LOG.isDebugEnabled() ) + { + LOG.debug(" - restore state" + this.toString()); + } + context.setGraphicsState( (PDGraphicsState)context.getGraphicsStack().pop() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/GSave.java b/src/main/java/org/pdfbox/util/operator/GSave.java new file mode 100644 index 0000000..6a754b6 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/GSave.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of + * conditions in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class GSave extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(GSave.class); + + /** + * process : q : Save graphics state. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + if( LOG.isDebugEnabled() ) + { + LOG.debug(" - save state " + this.toString()); + } + context.getGraphicsStack().push( context.getGraphicsState().clone() ); + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/Invoke.java b/src/main/java/org/pdfbox/util/operator/Invoke.java new file mode 100644 index 0000000..2f8f789 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/Invoke.java @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSName; +import org.pdfbox.cos.COSStream; +import org.pdfbox.pdmodel.PDPage; +import org.pdfbox.pdmodel.PDResources; +import org.pdfbox.pdmodel.graphics.xobject.PDXObject; +import org.pdfbox.pdmodel.graphics.xobject.PDXObjectForm; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.Map; + +/** + * Invoke named XObject. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @author Mario Ivankovits + * + * @version $Revision: 1.6 $ + */ +public class Invoke extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(Invoke.class); + + private Set inProcess = new TreeSet(); + + /** + * process : Do - Invoke a named xobject. + * @param operator The operator that is being executed. + * @param arguments List + * + * @throws IOException If there is an error processing this operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + COSName name = (COSName) arguments.get( 0 ); + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + + // wprinz: allow recursive processing so that nested xobject forms are correctly dealt with +// if (inProcess.contains(name)) +// { +// // avoid recursive loop +// return; +// } + // /wprinz + + inProcess.add(name); + + try + { + //PDResources res = context.getResources(); + + Map xobjects = context.getXObjects(); + PDXObject xobject = (PDXObject) xobjects.get(name.getName()); + + if(xobject instanceof PDXObjectForm) + { + PDXObjectForm form = (PDXObjectForm)xobject; + COSStream invoke = (COSStream)form.getCOSObject(); + PDResources pdResources = form.getResources(); + PDPage page = context.getCurrentPage(); + if(pdResources == null) + { + pdResources = page.findResources(); + } + + getContext().processSubStream( page, pdResources, invoke ); + } + } + finally + { + inProcess.remove(name); + } + } +} diff --git a/src/main/java/org/pdfbox/util/operator/MoveAndShow.java b/src/main/java/org/pdfbox/util/operator/MoveAndShow.java new file mode 100644 index 0000000..ca3a3f9 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/MoveAndShow.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSString; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : +* the long sequence of conditions in processOperator is remplaced by +* this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ +public class MoveAndShow extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(MoveAndShow.class); + + /** + * ' Move to next line and show text. + * @param arguments List + * @param operator The operator that is being executed. + * @throws IOException If there is an error processing the operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + // Move to start of next text line, and show text + // + if( LOG.isDebugEnabled()) + { + COSString string = (COSString)arguments.get( 0 ); + LOG.debug("<' string=\"" + string.getString() + "\">"); + } + + context.processOperator("T*", null); + context.processOperator("Tj", arguments); + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/MoveText.java b/src/main/java/org/pdfbox/util/operator/MoveText.java new file mode 100644 index 0000000..10360bb --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/MoveText.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ +public class MoveText extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(MoveText.class); + + + /** + * process : Td : Move text position. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + COSNumber x = (COSNumber)arguments.get( 0 ); + COSNumber y = (COSNumber)arguments.get( 1 ); + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + Matrix td = new Matrix(); + td.setValue( 2, 0, x.floatValue() );//.* textMatrix.getValue(0,0) ); + td.setValue( 2, 1, y.floatValue() );//* textMatrix.getValue(1,1) ); + //log.debug( "textLineMatrix before " + textLineMatrix ); + context.setTextLineMatrix( td.multiply( context.getTextLineMatrix() ) ); //textLineMatrix.multiply( td ); + //log.debug( "textLineMatrix after " + textLineMatrix ); + context.setTextMatrix( context.getTextLineMatrix().copy() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/MoveTextSetLeading.java b/src/main/java/org/pdfbox/util/operator/MoveTextSetLeading.java new file mode 100644 index 0000000..e68a1d1 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/MoveTextSetLeading.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSFloat; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ +public class MoveTextSetLeading extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(MoveTextSetLeading.class); + + /** + * process : TD Move text position and set leading. + * @param operator The operator that is being executed. + * @param arguments List + * + * @throws IOException If there is an error during processing. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + //move text position and set leading + COSNumber y = (COSNumber)arguments.get( 1 ); + if (LOG.isDebugEnabled()) + { + COSNumber x = (COSNumber)arguments.get( 0 ); + LOG.debug(""); + } + + ArrayList args = new ArrayList(); + args.add(new COSFloat(-1*y.floatValue())); + context.processOperator("TL", args); + context.processOperator("Td", arguments); + + } +} diff --git a/src/main/java/org/pdfbox/util/operator/NextLine.java b/src/main/java/org/pdfbox/util/operator/NextLine.java new file mode 100644 index 0000000..daa35eb --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/NextLine.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.pdfbox.cos.COSFloat; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of + * conditions in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ +public class NextLine extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(NextLine.class); + + /** + * process : T* Move to start of next text line. + * @param operator The operator that is being executed. + * @param arguments List + * + * @throws IOException If there is an error during processing. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + //move to start of next text line + ArrayList args = new ArrayList(); + args.add(new COSFloat(0.0f)); + // this must be -leading instead of just leading as written in the + // specification (p.369) the acrobat reader seems to implement it the same way + args.add(new COSFloat(-1*context.getGraphicsState().getTextState().getLeading())); + // use Td instead of repeating code + context.processOperator("Td", args); + + } +} diff --git a/src/main/java/org/pdfbox/util/operator/OperatorProcessor.java b/src/main/java/org/pdfbox/util/operator/OperatorProcessor.java new file mode 100644 index 0000000..27c21b9 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/OperatorProcessor.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.PDFStreamEngine; +import java.util.List; +import java.io.IOException; + +/** + * + *

Titre : OperatorProcessor

+ *

Description : This class is the strategy abstract class + * in the strategy GOF pattern. After instancated, you must ever call +* the setContext method to initiamise OPeratorProcessor

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ +public abstract class OperatorProcessor +{ + + /** + * The stream engine processing context. + */ + protected PDFStreamEngine context = null; + + /** + * Constructor. + * + */ + protected OperatorProcessor() + { + } + + /** + * Get the context for processing. + * + * @return The processing context. + */ + protected PDFStreamEngine getContext() + { + return context; + } + + /** + * Set the processing context. + * + * @param ctx The context for processing. + */ + public void setContext(PDFStreamEngine ctx) + { + context = ctx; + } + + /** + * process the operator. + * @param operator The operator that is being processed. + * @param arguments arguments needed by this operator. + * + * @throws IOException If there is an error processing the operator. + */ + public abstract void process(PDFOperator operator, List arguments) throws IOException; +} diff --git a/src/main/java/org/pdfbox/util/operator/SetCharSpacing.java b/src/main/java/org/pdfbox/util/operator/SetCharSpacing.java new file mode 100644 index 0000000..6813dce --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetCharSpacing.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +/** + * + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ +public class SetCharSpacing extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(SetCharSpacing.class); + + /** + * process : Tc Set character spacing. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + //set character spacing + if( arguments.size() > 0 ) + { + //There are some documents which are incorrectly structured, and have + //a wrong number of arguments to this, so we will assume the last argument + //in the list + Object charSpacing = arguments.get( arguments.size()-1 ); + if( charSpacing instanceof COSNumber ) + { + COSNumber characterSpacing = (COSNumber)charSpacing; + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + context.getGraphicsState().getTextState().setCharacterSpacing( characterSpacing.floatValue() ); + } + } + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetGraphicsStateParameters.java b/src/main/java/org/pdfbox/util/operator/SetGraphicsStateParameters.java new file mode 100644 index 0000000..e72e05d --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetGraphicsStateParameters.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSName; +import org.pdfbox.pdmodel.graphics.PDExtendedGraphicsState; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetGraphicsStateParameters extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * gs Set parameters from graphics state parameter dictionary. + * @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 + { + //set parameters from graphics state parameter dictionary + COSName graphicsName = (COSName)arguments.get( 0 ); + + if (LOG.isDebugEnabled()) + { + LOG.debug("" ); + } + PDExtendedGraphicsState gs = (PDExtendedGraphicsState)context.getGraphicsStates().get( graphicsName.getName() ); + gs.copyIntoGraphicsState( context.getGraphicsState() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetHorizontalTextScaling.java b/src/main/java/org/pdfbox/util/operator/SetHorizontalTextScaling.java new file mode 100644 index 0000000..bfb9ebe --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetHorizontalTextScaling.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetHorizontalTextScaling extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * Tz Set horizontal text scaling. + * @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 + { + COSNumber scaling = (COSNumber)arguments.get(0); + context.getGraphicsState().getTextState().setHorizontalScalingPercent( scaling.floatValue() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetLineWidth.java b/src/main/java/org/pdfbox/util/operator/SetLineWidth.java new file mode 100644 index 0000000..de0576d --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetLineWidth.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetLineWidth extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * w Set line width. + * @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 + { + COSNumber width = (COSNumber)arguments.get( 0 ); + context.getGraphicsState().setLineWidth( width.doubleValue() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetMatrix.java b/src/main/java/org/pdfbox/util/operator/SetMatrix.java new file mode 100644 index 0000000..5d5f1f5 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetMatrix.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of conditions + * in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class SetMatrix extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(SetMatrix.class); + + /** + * Tm Set text matrix and text line matrix. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + //Set text matrix and text line matrix + COSNumber a = (COSNumber)arguments.get( 0 ); + COSNumber b = (COSNumber)arguments.get( 1 ); + COSNumber c = (COSNumber)arguments.get( 2 ); + COSNumber d = (COSNumber)arguments.get( 3 ); + COSNumber e = (COSNumber)arguments.get( 4 ); + COSNumber f = (COSNumber)arguments.get( 5 ); + + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + + Matrix textMatrix = new Matrix(); + textMatrix.setValue( 0, 0, a.floatValue() ); + textMatrix.setValue( 0, 1, b.floatValue() ); + textMatrix.setValue( 1, 0, c.floatValue() ); + textMatrix.setValue( 1, 1, d.floatValue() ); + textMatrix.setValue( 2, 0, e.floatValue() ); + textMatrix.setValue( 2, 1, f.floatValue() ); + context.setTextMatrix( textMatrix ); + context.setTextLineMatrix( textMatrix.copy() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetMoveAndShow.java b/src/main/java/org/pdfbox/util/operator/SetMoveAndShow.java new file mode 100644 index 0000000..b49206d --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetMoveAndShow.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.cos.COSString; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of conditions + * in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.5 $ + */ + +public class SetMoveAndShow extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(SetMoveAndShow.class); + + /** + * " Set word and character spacing, move to next line, and show text. + * @param operator The operator that is being executed. + * @param arguments List. + * @throws IOException If there is an error processing the operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + //Set word and character spacing, move to next line, and show text + // + if (LOG.isDebugEnabled()) + { + COSNumber wordSpacing = (COSNumber)arguments.get( 0 ); + COSNumber characterSpacing = (COSNumber)arguments.get( 1 ); + COSString string = (COSString)arguments.get( 2 ); + LOG.debug("<\" wordSpacing=\"" + wordSpacing + + "\", characterSpacing=\"" + characterSpacing + + "\", string=\"" + string.getString() + "\">"); + } + + context.processOperator("Tw", arguments.subList(0,1)); + context.processOperator("Tc", arguments.subList(1,2)); + context.processOperator("'", arguments.subList(2,3)); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetNonStrokingCMYKColor.java b/src/main/java/org/pdfbox/util/operator/SetNonStrokingCMYKColor.java new file mode 100644 index 0000000..941fcd6 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetNonStrokingCMYKColor.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdmodel.graphics.color.PDColorSpace; +import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; +import org.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Set the non stroking color space.

+ * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.2 $ + */ +public class SetNonStrokingCMYKColor extends OperatorProcessor +{ + /** + * cs 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 + { + PDColorSpace cs = PDDeviceCMYK.INSTANCE; + PDColorSpaceInstance colorInstance = context.getGraphicsState().getNonStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + float[] values = new float[4]; + for( int i=0; iSet the non stroking color space.

+ * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.2 $ + */ +public class SetNonStrokingColorSpace extends OperatorProcessor +{ + private static final float[] EMPTY_FLOAT_ARRAY = new float[0]; + + /** + * cs 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 + { +// (PDF 1.1) Set color space for stroking operations + COSName name = (COSName)arguments.get( 0 ); + PDColorSpace cs = (PDColorSpace)context.getColorSpaces().get( name.getName() ); + if( cs == null ) + { + cs = PDColorSpaceFactory.createColorSpace( name ); + } + PDColorSpaceInstance colorInstance = context.getGraphicsState().getNonStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + int numComponents = cs.getNumberOfComponents(); + float[] values = EMPTY_FLOAT_ARRAY; + if( numComponents >= 0 ) + { + values = new float[numComponents]; + for( int i=0; iSet the non stroking color space.

+ * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.2 $ + */ +public class SetNonStrokingRGBColor extends OperatorProcessor +{ + /** + * rg 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 + { + PDColorSpace cs = PDDeviceRGB.INSTANCE; + PDColorSpaceInstance colorInstance = context.getGraphicsState().getNonStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + float[] values = new float[3]; + for( int i=0; iStructal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.2 $ + */ +public class SetStrokingCMYKColor extends OperatorProcessor +{ + /** + * CS Set color space for 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 + { + PDColorSpace cs = PDDeviceCMYK.INSTANCE; + PDColorSpaceInstance colorInstance = context.getGraphicsState().getStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + float[] values = new float[4]; + for( int i=0; iStructal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetStrokingColorSpace extends OperatorProcessor +{ + private static final float[] EMPTY_FLOAT_ARRAY = new float[0]; + + /** + * CS Set color space for 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 + { + //(PDF 1.1) Set color space for stroking operations + COSName name = (COSName)arguments.get( 0 ); + PDColorSpace cs = (PDColorSpace)context.getColorSpaces().get( name.getName() ); + if( cs == null ) + { + cs = PDColorSpaceFactory.createColorSpace( name ); + } + PDColorSpaceInstance colorInstance = context.getGraphicsState().getStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + int numComponents = cs.getNumberOfComponents(); + float[] values = EMPTY_FLOAT_ARRAY; + if( numComponents >= 0 ) + { + values = new float[numComponents]; + for( int i=0; iStructal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.2 $ + */ +public class SetStrokingRGBColor extends OperatorProcessor +{ + /** + * RG Set color space for 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 + { + PDColorSpace cs = PDDeviceRGB.INSTANCE; + PDColorSpaceInstance colorInstance = context.getGraphicsState().getStrokingColorSpace(); + colorInstance.setColorSpace( cs ); + float[] values = new float[3]; + for( int i=0; iTitre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.4 $ + */ + +public class SetTextFont extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * Tf selectfont Set text font and size. + * @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 + { + //there are some documents that are incorrectly structured and + //arguments are in the wrong spot, so we will silently ignore them + //if there are no arguments + if( arguments.size() >= 2 ) + { + //set font and size + COSName fontName = (COSName)arguments.get( 0 ); + float fontSize = ((COSNumber)arguments.get( 1 ) ).floatValue(); + context.getGraphicsState().getTextState().setFontSize( fontSize ); + + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + + //old way + //graphicsState.getTextState().getFont() = (COSObject)stream.getDictionaryObject( fontName ); + //if( graphicsState.getTextState().getFont() == null ) + //{ + // graphicsState.getTextState().getFont() = (COSObject)graphicsState.getTextState().getFont() + // Dictionary.getItem( fontName ); + //} + context.getGraphicsState().getTextState().setFont( (PDFont)context.getFonts().get( fontName.getName() ) ); + if( context.getGraphicsState().getTextState().getFont() == null ) + { + throw new IOException( "Error: Could not find font(" + fontName + ") in map=" + context.getFonts() ); + } + } + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/SetTextLeading.java b/src/main/java/org/pdfbox/util/operator/SetTextLeading.java new file mode 100644 index 0000000..928172b --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetTextLeading.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : +* the long sequence of conditions in processOperator is remplaced +* by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class SetTextLeading extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(SetTextLeading.class); + + /** + * TL Set text leading. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + COSNumber leading = (COSNumber)arguments.get( 0 ); + context.getGraphicsState().getTextState().setLeading( leading.floatValue() ); + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/SetTextRenderingMode.java b/src/main/java/org/pdfbox/util/operator/SetTextRenderingMode.java new file mode 100644 index 0000000..19da1e2 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetTextRenderingMode.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetTextRenderingMode extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * Tr Set text rendering mode. + * @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 + { + COSNumber mode = (COSNumber)arguments.get( 0 ); + context.getGraphicsState().getTextState().setRenderingMode( mode.intValue() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetTextRise.java b/src/main/java/org/pdfbox/util/operator/SetTextRise.java new file mode 100644 index 0000000..0d1e884 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetTextRise.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator is remplaced by + * this strategy pattern.

+ * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ + +public class SetTextRise extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetTextFont.class); + + /** + * Ts Set text rise. + * @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 + { + COSNumber rise = (COSNumber)arguments.get(0); + context.getGraphicsState().getTextState().setRise( rise.floatValue() ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/SetWordSpacing.java b/src/main/java/org/pdfbox/util/operator/SetWordSpacing.java new file mode 100644 index 0000000..3a1e176 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/SetWordSpacing.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSNumber; +import org.pdfbox.util.PDFOperator; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of + * conditions in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class SetWordSpacing extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(SetWordSpacing.class); + + /** + * Tw Set word spacing. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + //set word spacing + COSNumber wordSpacing = (COSNumber)arguments.get( 0 ); + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + context.getGraphicsState().getTextState().setWordSpacing( wordSpacing.floatValue() ); + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/ShowText.java b/src/main/java/org/pdfbox/util/operator/ShowText.java new file mode 100644 index 0000000..1889259 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/ShowText.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSString; +import org.pdfbox.util.PDFOperator; + +import java.io.IOException; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : + * the long sequence of conditions in processOperator + * is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.3 $ + */ + +public class ShowText extends OperatorProcessor +{ + + private static final Logger LOG = Logger.getLogger(ShowText.class); + + /** + * Tj show Show text. + * @param operator The operator that is being executed. + * @param arguments List + * + * @throws IOException If there is an error processing this operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + COSString string = (COSString)arguments.get( 0 ); + context.showString( string.getBytes() ); + if (LOG.isDebugEnabled()) + { + LOG.debug(""); + } + } + +} diff --git a/src/main/java/org/pdfbox/util/operator/ShowTextGlyph.java b/src/main/java/org/pdfbox/util/operator/ShowTextGlyph.java new file mode 100644 index 0000000..cf22e11 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/ShowTextGlyph.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator; + +import java.util.List; +import org.apache.log4j.Logger; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.cos.COSArray; +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSNumber; +import java.io.IOException; +import org.pdfbox.cos.COSString; + +/** + *

Titre : PDFEngine Modification.

+ *

Description : Structal modification of the PDFEngine class : the long sequence of + * conditions in processOperator is remplaced by this strategy pattern

+ *

Copyright : Copyright (c) 2004

+ *

Société : DBGS

+ * @author Huault : huault@free.fr + * @version $Revision: 1.5 $ + */ + +public class ShowTextGlyph extends OperatorProcessor +{ + private static final Logger LOG = Logger.getLogger(ShowTextGlyph.class); + + /** + * TJ Show text, allowing individual glyph positioning. + * @param operator The operator that is being executed. + * @param arguments List + * @throws IOException If there is an error processing this operator. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + COSArray array = (COSArray)arguments.get( 0 ); + float adjustment=0; + for( int i=0; i + + + + + +This package contains implementations of all of the PDF operators. + + diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/AppendRectangleToPath.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/AppendRectangleToPath.java new file mode 100644 index 0000000..7d2d49f --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/AppendRectangleToPath.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.geom.Rectangle2D; +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class AppendRectangleToPath extends OperatorProcessor +{ + + + /** + * process : re : append rectangle to path. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + COSNumber x = (COSNumber)arguments.get( 0 ); + COSNumber y = (COSNumber)arguments.get( 1 ); + COSNumber w = (COSNumber)arguments.get( 2 ); + COSNumber h = (COSNumber)arguments.get( 3 ); + Rectangle2D rect = new Rectangle2D.Double( + x.doubleValue(), + drawer.fixY( x.doubleValue(), y.doubleValue())-h.doubleValue(), + w.doubleValue()+1, + h.doubleValue()+1); + drawer.getLinePath().reset(); + + drawer.getLinePath().append( rect, false ); + //graphics.drawRect((int)x.doubleValue(), (int)(pageSize.getHeight() - y.doubleValue()), + // (int)w.doubleValue(),(int)h.doubleValue() ); + //System.out.println( "" ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/BeginInlineImage.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/BeginInlineImage.java new file mode 100644 index 0000000..9031345 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/BeginInlineImage.java @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.graphics.xobject.PDInlinedImage; +import org.pdfbox.util.ImageParameters; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class BeginInlineImage extends OperatorProcessor +{ + + + /** + * process : BI : begin inline image. + * @param operator The operator that is being executed. + * @param arguments List + * @throws IOException If there is an error displaying the inline image. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + PageDrawer drawer = (PageDrawer)context; + Graphics2D graphics = drawer.getGraphics(); + //begin inline image object + ImageParameters params = operator.getImageParameters(); + PDInlinedImage image = new PDInlinedImage(); + image.setImageParameters( params ); + image.setImageData( operator.getImageData() ); + BufferedImage awtImage = image.createImage(); + + Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); + + int width = awtImage.getWidth(); + int height = awtImage.getHeight(); + + + AffineTransform at = new AffineTransform( + ctm.getValue(0,0)/width, + ctm.getValue(0,1), + ctm.getValue(1,0), + ctm.getValue(1,1)/height, + ctm.getValue(2,0), + ctm.getValue(2,1) + ); + //at.setToRotation((double)page.getRotation()); + + + // The transformation should be done + // 1 - Translation + // 2 - Rotation + // 3 - Scale or Skew + //AffineTransform at = new AffineTransform(); + + // Translation + //at = new AffineTransform(); + //at.setToTranslation((double)ctm.getValue(0,0), + // (double)ctm.getValue(0,1)); + + // Rotation + //AffineTransform toAdd = new AffineTransform(); + //toAdd.setToRotation(1.5705); + //toAdd.setToRotation(ctm.getValue(2,0)*(Math.PI/180)); + //at.concatenate(toAdd); + + // Scale / Skew? + //toAdd.setToScale(width, height); + //at.concatenate(toAdd); + //at.setToScale( width, height ); + graphics.drawImage( awtImage, at, null ); + //graphics.drawImage( awtImage,0,0, width,height,null); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/ClosePath.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/ClosePath.java new file mode 100644 index 0000000..418af6d --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/ClosePath.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class ClosePath extends OperatorProcessor +{ + + + /** + * process : h : Close path. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + drawer.getLinePath().closePath(); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveTo.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveTo.java new file mode 100644 index 0000000..c056b91 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveTo.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class CurveTo extends OperatorProcessor +{ + + + /** + * process : c : Append curved segment to path. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + COSNumber x1 = (COSNumber)arguments.get( 0 ); + COSNumber y1 = (COSNumber)arguments.get( 1 ); + COSNumber x2 = (COSNumber)arguments.get( 2 ); + COSNumber y2 = (COSNumber)arguments.get( 3 ); + COSNumber x3 = (COSNumber)arguments.get( 4 ); + COSNumber y3 = (COSNumber)arguments.get( 5 ); + float x1f = x1.floatValue(); + float y1f = (float)drawer.fixY( x1f, y1.floatValue() ); + float x2f = x2.floatValue(); + float y2f = (float)drawer.fixY( x2f, y2.floatValue() ); + float x3f = x3.floatValue(); + float y3f = (float)drawer.fixY( x3f, y3.floatValue() ); + drawer.getLinePath().curveTo(x1f,y1f,x2f,y2f,x3f,y3f); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateFinalPoint.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateFinalPoint.java new file mode 100644 index 0000000..670cdb3 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateFinalPoint.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class CurveToReplicateFinalPoint extends OperatorProcessor +{ + + + /** + * process : y : Append curved segment to path (final point replicated). + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + COSNumber x1 = (COSNumber)arguments.get( 0 ); + COSNumber y1 = (COSNumber)arguments.get( 1 ); + COSNumber x3 = (COSNumber)arguments.get( 2 ); + COSNumber y3 = (COSNumber)arguments.get( 3 ); + float x1f = x1.floatValue(); + float y1f = (float)drawer.fixY( x1f, y1.floatValue() ); + float x3f = x3.floatValue(); + float y3f = (float)drawer.fixY( x3f, y3.floatValue() ); + drawer.getLinePath().curveTo(x1f,y1f,x3f,y3f,x3f,y3f); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateInitialPoint.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateInitialPoint.java new file mode 100644 index 0000000..ff354d0 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/CurveToReplicateInitialPoint.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class CurveToReplicateInitialPoint extends OperatorProcessor +{ + + + /** + * process : v : Append curved segment to path (initial point replicated). + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + COSNumber x2 = (COSNumber)arguments.get( 0 ); + COSNumber y2 = (COSNumber)arguments.get( 1 ); + COSNumber x3 = (COSNumber)arguments.get( 2 ); + COSNumber y3 = (COSNumber)arguments.get( 3 ); + float x2f = x2.floatValue(); + float y2f = (float)drawer.fixY( x2f, y2.floatValue() ); + float x3f = x3.floatValue(); + float y3f = (float)drawer.fixY( x3f, y3.floatValue() ); + + GeneralPath path = drawer.getLinePath(); + Point2D currentPoint = path.getCurrentPoint(); + float currentX = (float)currentPoint.getX(); + float currentY = (float)currentPoint.getY(); + drawer.getLinePath().curveTo(currentX,currentY,x2f,y2f,x3f,y3f); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/FillEvenOddRule.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/FillEvenOddRule.java new file mode 100644 index 0000000..da9e834 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/FillEvenOddRule.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.geom.GeneralPath; +import java.util.List; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class FillEvenOddRule extends OperatorProcessor +{ + + + /** + * process : f* : fill path using even odd rule. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { +// NOTE:changes here should probably also be made to FillNonZeroRule + PageDrawer drawer = (PageDrawer)context; + Graphics2D graphics = drawer.getGraphics(); + //linePath.closePath(); + graphics.setColor( drawer.getNonStrokingColor() ); + drawer.getLinePath().setWindingRule( GeneralPath.WIND_EVEN_ODD ); + graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF ); + //else + //{ + graphics.fill( drawer.getLinePath() ); + //} + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/FillNonZeroRule.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/FillNonZeroRule.java new file mode 100644 index 0000000..56efa33 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/FillNonZeroRule.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.geom.GeneralPath; +import java.util.List; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class FillNonZeroRule extends OperatorProcessor +{ + + + /** + * process : F/f : fill path using non zero winding rule. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + //NOTE:changes here should probably also be made to FillEvenOddRule + PageDrawer drawer = (PageDrawer)context; + Graphics2D graphics = drawer.getGraphics(); + //linePath.closePath(); + graphics.setColor( drawer.getNonStrokingColor() ); + drawer.getLinePath().setWindingRule( GeneralPath.WIND_NON_ZERO ); + graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF ); + //else + //{ + graphics.fill( drawer.getLinePath() ); + //} + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/Invoke.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/Invoke.java new file mode 100644 index 0000000..3d99b74 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/Invoke.java @@ -0,0 +1,180 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.pdfbox.cos.COSName; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.PDPage; +import org.pdfbox.pdmodel.graphics.xobject.PDXObject; +import org.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; +import org.pdfbox.util.Matrix; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class Invoke extends OperatorProcessor +{ + private static Logger log = Logger.getLogger( Invoke.class ); + + /** + * process : re : append rectangle to path. + * @param operator The operator that is being executed. + * @param arguments List + * @throws IOException If there is an error invoking the sub object. + */ + public void process(PDFOperator operator, List arguments) throws IOException + { + PageDrawer drawer = (PageDrawer)context; + PDPage page = drawer.getPage(); + Dimension pageSize = drawer.getPageSize(); + Graphics2D graphics = drawer.getGraphics(); + COSName objectName = (COSName)arguments.get( 0 ); + Map xobjects = drawer.getResources().getXObjects(); + PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() ); + if( xobject instanceof PDXObjectImage ) + { + PDXObjectImage image = (PDXObjectImage)xobject; + try + { + BufferedImage awtImage = image.getRGBImage(); + Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); + + int width = awtImage.getWidth(); + int height = awtImage.getHeight(); + + double rotationInRadians =(page.findRotation() * Math.PI)/180; + + + AffineTransform rotation = new AffineTransform(); + rotation.setToRotation( rotationInRadians ); + AffineTransform rotationInverse = rotation.createInverse(); + Matrix rotationInverseMatrix = new Matrix(); + rotationInverseMatrix.setFromAffineTransform( rotationInverse ); + Matrix rotationMatrix = new Matrix(); + rotationMatrix.setFromAffineTransform( rotation ); + + Matrix unrotatedCTM = ctm.multiply( rotationInverseMatrix ); + + Matrix scalingParams = unrotatedCTM.extractScaling(); + Matrix scalingMatrix = Matrix.getScaleInstance(1f/width,1f/height); + scalingParams = scalingParams.multiply( scalingMatrix ); + + Matrix translationParams = unrotatedCTM.extractTranslating(); + Matrix translationMatrix = null; + int pageRotation = page.findRotation(); + if( pageRotation == 0 ) + { + translationParams.setValue(2,1, -translationParams.getValue( 2,1 )); + translationMatrix = Matrix.getTranslatingInstance( + 0, (float)pageSize.getHeight()-height*scalingParams.getYScale() ); + } + else if( pageRotation == 90 ) + { + translationMatrix = Matrix.getTranslatingInstance( 0, (float)pageSize.getHeight() ); + } + else + { + //TODO need to figure out other cases + } + translationParams = translationParams.multiply( translationMatrix ); + + AffineTransform at = new AffineTransform( + scalingParams.getValue( 0,0), 0, + 0, scalingParams.getValue( 1, 1), + translationParams.getValue(2,0), translationParams.getValue( 2,1 ) + ); + + + + + //at.setToTranslation( pageSize.getHeight()-ctm.getValue(2,0),ctm.getValue(2,1) ); + //at.setToScale( ctm.getValue(0,0)/width, ctm.getValue(1,1)/height); + //at.setToRotation( (page.findRotation() * Math.PI)/180 ); + + + + //AffineTransform rotation = new AffineTransform(); + //rotation.rotate( (90*Math.PI)/180); + + /* + + // The transformation should be done + // 1 - Translation + // 2 - Rotation + // 3 - Scale or Skew + AffineTransform at = new AffineTransform(); + + // Translation + at = new AffineTransform(); + //at.setToTranslation((double)ctm.getValue(0,0), + // (double)ctm.getValue(0,1)); + + // Rotation + //AffineTransform toAdd = new AffineTransform(); + toAdd.setToRotation(1.5705); + toAdd.setToRotation(ctm.getValue(2,0)*(Math.PI/180)); + at.concatenate(toAdd); + */ + + // Scale / Skew? + //toAdd.setToScale(1, 1); + //at.concatenate(toAdd); + + graphics.drawImage( awtImage, at, null ); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } + else + { + log.warn( "Unknown xobject type:" + xobject ); + } + + + //invoke named object. + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/LineTo.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/LineTo.java new file mode 100644 index 0000000..a70099b --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/LineTo.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class LineTo extends OperatorProcessor +{ + + + /** + * process : l : Append straight line segment to path. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + //append straight line segment from the current point to the point. + COSNumber x = (COSNumber)arguments.get( 0 ); + COSNumber y = (COSNumber)arguments.get( 1 ); + + drawer.getLinePath().lineTo( x.floatValue(), (float)drawer.fixY( x.doubleValue(), y.doubleValue()) ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/MoveTo.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/MoveTo.java new file mode 100644 index 0000000..e1c8f1e --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/MoveTo.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.awt.geom.GeneralPath; +import java.util.List; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; +import org.pdfbox.util.operator.OperatorProcessor; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class MoveTo extends OperatorProcessor +{ + + + /** + * process : m : Begin new subpath. + * @param operator The operator that is being executed. + * @param arguments List + */ + public void process(PDFOperator operator, List arguments) + { + PageDrawer drawer = (PageDrawer)context; + + COSNumber x = (COSNumber)arguments.get( 0 ); + COSNumber y = (COSNumber)arguments.get( 1 ); + + drawer.getLineSubPaths().add( drawer.getLinePath() ); + GeneralPath newPath = new GeneralPath(); + newPath.moveTo( x.floatValue(), (float)drawer.fixY( x.doubleValue(), y.doubleValue()) ); + drawer.setLinePath( newPath ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetLineWidth.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetLineWidth.java new file mode 100644 index 0000000..4217451 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetLineWidth.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; + +import java.awt.BasicStroke; +import java.io.IOException; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetLineWidth extends org.pdfbox.util.operator.SetLineWidth +{ + + /** + * w Set line width. + * @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 + { + super.process( operator, arguments ); + float lineWidth = (float)context.getGraphicsState().getLineWidth(); + if( lineWidth == 0 ) + { + lineWidth = 1; + } + ((PageDrawer)context).getGraphics().setStroke( new BasicStroke( lineWidth ) ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingCMYKColor.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingCMYKColor.java new file mode 100644 index 0000000..d1c37fe --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingCMYKColor.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import java.awt.Color; +import java.io.IOException; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; +import org.pdfbox.util.PDFOperator; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetNonStrokingCMYKColor extends org.pdfbox.util.operator.SetNonStrokingCMYKColor +{ + /** + * k 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 + { + super.process( operator, arguments ); + PageDrawer drawer = (PageDrawer)context; + PDColorSpaceInstance colorInstance = drawer.getGraphicsState().getNonStrokingColorSpace(); + Color color = colorInstance.createColor(); + drawer.setNonStrokingColor( color ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingColorSpace.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingColorSpace.java new file mode 100644 index 0000000..e5abae8 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingColorSpace.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; +import org.pdfbox.util.PDFOperator; + + +import java.awt.Color; +import java.io.IOException; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetNonStrokingColorSpace extends org.pdfbox.util.operator.SetNonStrokingColorSpace +{ + /** + * cs 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 + { + try + { + super.process( operator, arguments ); + PageDrawer drawer = (PageDrawer)context; + PDColorSpaceInstance colorInstance = drawer.getGraphicsState().getNonStrokingColorSpace(); + Color color = colorInstance.createColor(); + drawer.setNonStrokingColor( color ); + } + catch( IOException e ) + { + //ignore for now and continue drawing + } + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingRGBColor.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingRGBColor.java new file mode 100644 index 0000000..f816d1f --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetNonStrokingRGBColor.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import java.awt.Color; +import java.io.IOException; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetNonStrokingRGBColor extends org.pdfbox.util.operator.SetNonStrokingRGBColor +{ + /** + * rg 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 + { + super.process( operator, arguments ); + PageDrawer drawer = (PageDrawer)context; + COSNumber r = (COSNumber)arguments.get( 0 ); + COSNumber g = (COSNumber)arguments.get( 1 ); + COSNumber b = (COSNumber)arguments.get( 2 ); + drawer.setNonStrokingColor( new Color( r.floatValue(), g.floatValue(), b.floatValue() ) ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingCMYKColor.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingCMYKColor.java new file mode 100644 index 0000000..81fcef3 --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingCMYKColor.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import java.awt.Color; +import java.io.IOException; + +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; +import org.pdfbox.util.PDFOperator; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetStrokingCMYKColor extends org.pdfbox.util.operator.SetStrokingCMYKColor +{ + /** + * CS Set color space for 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 + { + super.process( operator, arguments ); + PageDrawer drawer = (PageDrawer)context; + PDColorSpaceInstance colorInstance = drawer.getGraphicsState().getNonStrokingColorSpace(); + Color color = colorInstance.createColor(); + drawer.setStrokingColor( color ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingColorSpace.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingColorSpace.java new file mode 100644 index 0000000..22c9c5c --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingColorSpace.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; +import org.pdfbox.util.PDFOperator; + +import java.awt.Color; +import java.io.IOException; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetStrokingColorSpace extends org.pdfbox.util.operator.SetNonStrokingColorSpace +{ + /** + * CS Set color space for 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 + { + super.process( operator, arguments ); + try + { + PageDrawer drawer = (PageDrawer)context; + PDColorSpaceInstance colorInstance = drawer.getGraphicsState().getNonStrokingColorSpace(); + Color color = colorInstance.createColor(); + drawer.setStrokingColor( color ); + } + catch( IOException e ) + { + //ignore for now and continue drawing + } + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingRGBColor.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingRGBColor.java new file mode 100644 index 0000000..8d7099e --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/SetStrokingRGBColor.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; + +import java.awt.Color; +import java.io.IOException; + +import org.pdfbox.cos.COSNumber; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class SetStrokingRGBColor extends org.pdfbox.util.operator.SetStrokingRGBColor +{ + /** + * RG Set color space for 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 + { + super.process( operator, arguments ); + PageDrawer drawer = (PageDrawer)context; + COSNumber r = (COSNumber)arguments.get( 0 ); + COSNumber g = (COSNumber)arguments.get( 1 ); + COSNumber b = (COSNumber)arguments.get( 2 ); + drawer.setStrokingColor( new Color( r.floatValue(), g.floatValue(), b.floatValue() ) ); + } +} diff --git a/src/main/java/org/pdfbox/util/operator/pagedrawer/StrokePath.java b/src/main/java/org/pdfbox/util/operator/pagedrawer/StrokePath.java new file mode 100644 index 0000000..31a489c --- /dev/null +++ b/src/main/java/org/pdfbox/util/operator/pagedrawer/StrokePath.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2005, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, 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. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, 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. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.util.operator.pagedrawer; + +import java.util.List; +import org.pdfbox.pdfviewer.PageDrawer; +import org.pdfbox.util.PDFOperator; + +import java.awt.Graphics2D; +import java.awt.geom.GeneralPath; +import java.io.IOException; + +/** + * Implementation of content stream operator for page drawer. + * + * @author Ben Litchfield (ben@benlitchfield.com) + * @version $Revision: 1.1 $ + */ +public class StrokePath extends org.pdfbox.util.operator.SetLineWidth +{ + + /** + * S stroke the path. + * @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 + { + PageDrawer drawer = (PageDrawer)context; + Graphics2D graphics = ((PageDrawer)context).getGraphics(); + graphics.setColor( drawer.getStrokingColor() ); + List subPaths = drawer.getLineSubPaths(); + for( int i=0; i + + + + + +This package contains implementations of all of the PDF operators. + + -- cgit v1.2.3