You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/01/08 20:24:26 UTC
svn commit: r1850792 - in
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox: contentstream/
contentstream/operator/markedcontent/ pdmodel/graphics/optionalcontent/
printing/ rendering/ text/
Author: tilman
Date: Tue Jan 8 20:24:26 2019
New Revision: 1850792
URL: http://svn.apache.org/viewvc?rev=1850792&view=rev
Log:
PDFBOX-4399: consider OCG status when rendering, by Stefan Ziel
Added:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java (with props)
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequence.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequenceWithProperties.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/EndMarkedContentSequence.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawerParameters.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/text/PDFMarkedContentExtractor.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFGraphicsStreamEngine.java Tue Jan 8 20:24:26 2019
@@ -1,305 +1,311 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.contentstream;
-
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
-
-import java.awt.geom.Point2D;
-import java.io.IOException;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColor;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorN;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorSpace;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceCMYKColor;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceGrayColor;
-import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceRGBColor;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingColor;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingColorN;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingColorSpace;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceCMYKColor;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceGrayColor;
-import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceRGBColor;
-import org.apache.pdfbox.contentstream.operator.graphics.AppendRectangleToPath;
-import org.apache.pdfbox.contentstream.operator.graphics.BeginInlineImage;
-import org.apache.pdfbox.contentstream.operator.graphics.ClipEvenOddRule;
-import org.apache.pdfbox.contentstream.operator.graphics.ClipNonZeroRule;
-import org.apache.pdfbox.contentstream.operator.graphics.CloseAndStrokePath;
-import org.apache.pdfbox.contentstream.operator.graphics.CloseFillEvenOddAndStrokePath;
-import org.apache.pdfbox.contentstream.operator.graphics.CloseFillNonZeroAndStrokePath;
-import org.apache.pdfbox.contentstream.operator.graphics.ClosePath;
-import org.apache.pdfbox.contentstream.operator.graphics.CurveTo;
-import org.apache.pdfbox.contentstream.operator.graphics.CurveToReplicateFinalPoint;
-import org.apache.pdfbox.contentstream.operator.graphics.CurveToReplicateInitialPoint;
-import org.apache.pdfbox.contentstream.operator.graphics.DrawObject;
-import org.apache.pdfbox.contentstream.operator.graphics.EndPath;
-import org.apache.pdfbox.contentstream.operator.graphics.FillEvenOddAndStrokePath;
-import org.apache.pdfbox.contentstream.operator.graphics.FillEvenOddRule;
-import org.apache.pdfbox.contentstream.operator.graphics.FillNonZeroAndStrokePath;
-import org.apache.pdfbox.contentstream.operator.graphics.FillNonZeroRule;
-import org.apache.pdfbox.contentstream.operator.graphics.LegacyFillNonZeroRule;
-import org.apache.pdfbox.contentstream.operator.graphics.LineTo;
-import org.apache.pdfbox.contentstream.operator.graphics.MoveTo;
-import org.apache.pdfbox.contentstream.operator.graphics.ShadingFill;
-import org.apache.pdfbox.contentstream.operator.graphics.StrokePath;
-import org.apache.pdfbox.contentstream.operator.state.Concatenate;
-import org.apache.pdfbox.contentstream.operator.state.Restore;
-import org.apache.pdfbox.contentstream.operator.state.Save;
-import org.apache.pdfbox.contentstream.operator.state.SetFlatness;
-import org.apache.pdfbox.contentstream.operator.state.SetGraphicsStateParameters;
-import org.apache.pdfbox.contentstream.operator.state.SetLineCapStyle;
-import org.apache.pdfbox.contentstream.operator.state.SetLineDashPattern;
-import org.apache.pdfbox.contentstream.operator.state.SetLineJoinStyle;
-import org.apache.pdfbox.contentstream.operator.state.SetLineMiterLimit;
-import org.apache.pdfbox.contentstream.operator.state.SetLineWidth;
-import org.apache.pdfbox.contentstream.operator.state.SetMatrix;
-import org.apache.pdfbox.contentstream.operator.state.SetRenderingIntent;
-import org.apache.pdfbox.contentstream.operator.text.BeginText;
-import org.apache.pdfbox.contentstream.operator.text.EndText;
-import org.apache.pdfbox.contentstream.operator.text.SetFontAndSize;
-import org.apache.pdfbox.contentstream.operator.text.SetTextHorizontalScaling;
-import org.apache.pdfbox.contentstream.operator.text.ShowTextAdjusted;
-import org.apache.pdfbox.contentstream.operator.text.ShowTextLine;
-import org.apache.pdfbox.contentstream.operator.text.ShowTextLineAndSpace;
-import org.apache.pdfbox.contentstream.operator.text.MoveText;
-import org.apache.pdfbox.contentstream.operator.text.MoveTextSetLeading;
-import org.apache.pdfbox.contentstream.operator.text.NextLine;
-import org.apache.pdfbox.contentstream.operator.text.SetCharSpacing;
-import org.apache.pdfbox.contentstream.operator.text.SetTextLeading;
-import org.apache.pdfbox.contentstream.operator.text.SetTextRenderingMode;
-import org.apache.pdfbox.contentstream.operator.text.SetTextRise;
-import org.apache.pdfbox.contentstream.operator.text.SetWordSpacing;
-import org.apache.pdfbox.contentstream.operator.text.ShowText;
-
-/**
- * PDFStreamEngine subclass for advanced processing of graphics.
- * This class should be subclassed by end users looking to hook into graphics operations.
- *
- * @author John Hewson
- */
-public abstract class PDFGraphicsStreamEngine extends PDFStreamEngine
-{
- // may be null, for example if the stream is a tiling pattern
- private final PDPage page;
-
- /**
- * Constructor.
- */
- protected PDFGraphicsStreamEngine(PDPage page)
- {
- this.page = page;
-
- addOperator(new CloseFillNonZeroAndStrokePath());
- addOperator(new FillNonZeroAndStrokePath());
- addOperator(new CloseFillEvenOddAndStrokePath());
- addOperator(new FillEvenOddAndStrokePath());
- addOperator(new BeginInlineImage());
- addOperator(new BeginText());
- addOperator(new CurveTo());
- addOperator(new Concatenate());
- addOperator(new SetStrokingColorSpace());
- addOperator(new SetNonStrokingColorSpace());
- addOperator(new SetLineDashPattern());
- addOperator(new DrawObject()); // special graphics version
- addOperator(new EndText());
- addOperator(new FillNonZeroRule());
- addOperator(new LegacyFillNonZeroRule());
- addOperator(new FillEvenOddRule());
- addOperator(new SetStrokingDeviceGrayColor());
- addOperator(new SetNonStrokingDeviceGrayColor());
- addOperator(new SetGraphicsStateParameters());
- addOperator(new ClosePath());
- addOperator(new SetFlatness());
- addOperator(new SetLineJoinStyle());
- addOperator(new SetLineCapStyle());
- addOperator(new SetStrokingDeviceCMYKColor());
- addOperator(new SetNonStrokingDeviceCMYKColor());
- addOperator(new LineTo());
- addOperator(new MoveTo());
- addOperator(new SetLineMiterLimit());
- addOperator(new EndPath());
- addOperator(new Save());
- addOperator(new Restore());
- addOperator(new AppendRectangleToPath());
- addOperator(new SetStrokingDeviceRGBColor());
- addOperator(new SetNonStrokingDeviceRGBColor());
- addOperator(new SetRenderingIntent());
- addOperator(new CloseAndStrokePath());
- addOperator(new StrokePath());
- addOperator(new SetStrokingColor());
- addOperator(new SetNonStrokingColor());
- addOperator(new SetStrokingColorN());
- addOperator(new SetNonStrokingColorN());
- addOperator(new ShadingFill());
- addOperator(new NextLine());
- addOperator(new SetCharSpacing());
- addOperator(new MoveText());
- addOperator(new MoveTextSetLeading());
- addOperator(new SetFontAndSize());
- addOperator(new ShowText());
- addOperator(new ShowTextAdjusted());
- addOperator(new SetTextLeading());
- addOperator(new SetMatrix());
- addOperator(new SetTextRenderingMode());
- addOperator(new SetTextRise());
- addOperator(new SetWordSpacing());
- addOperator(new SetTextHorizontalScaling());
- addOperator(new CurveToReplicateInitialPoint());
- addOperator(new SetLineWidth());
- addOperator(new ClipNonZeroRule());
- addOperator(new ClipEvenOddRule());
- addOperator(new CurveToReplicateFinalPoint());
- addOperator(new ShowTextLine());
- addOperator(new ShowTextLineAndSpace());
- }
-
- /**
- * Returns the page.
- *
- * @return the page.
- *
- */
- protected final PDPage getPage()
- {
- return page;
- }
-
- /**
- * Append a rectangle to the current path.
- *
- * @param p0 point P0 of the rectangle.
- * @param p1 point P1 of the rectangle.
- * @param p2 point P2 of the rectangle.
- * @param p3 point P3 of the rectangle.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void appendRectangle(Point2D p0, Point2D p1,
- Point2D p2, Point2D p3) throws IOException;
-
- /**
- * Draw the image.
- *
- * @param pdImage The image to draw.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void drawImage(PDImage pdImage) throws IOException;
-
- /**
- * Modify the current clipping path by intersecting it with the current path. The clipping path will not be updated
- * until the succeeding painting operator is called.
- *
- * @param windingRule The winding rule which will be used for clipping.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void clip(int windingRule) throws IOException;
-
- /**
- * Starts a new path at (x,y).
- *
- * @param x x-coordinate of the target point.
- * @param y y-coordinate of the target point.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void moveTo(float x, float y) throws IOException;
-
- /**
- * Draws a line from the current point to (x,y).
- *
- * @param x x-coordinate of the end point of the line.
- * @param y y-coordinate of the end point of the line.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void lineTo(float x, float y) throws IOException;
-
- /**
- * Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.
- *
- * @param x1 x-coordinate of the first control point.
- * @param y1 y-coordinate of the first control point.
- * @param x2 x-coordinate of the second control point.
- * @param y2 y-coordinate of the second control point.
- * @param x3 x-coordinate of the end point of the curve.
- * @param y3 y-coordinate of the end point of the curve.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void curveTo(float x1, float y1,
- float x2, float y2,
- float x3, float y3) throws IOException;
-
- /**
- * Returns the current point of the current path.
- *
- * @return the current point.
- *
- * @throws IOException if something went wrong.
- */
- public abstract Point2D getCurrentPoint() throws IOException;
-
- /**
- * Closes the current path.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void closePath() throws IOException;
-
- /**
- * Ends the current path without filling or stroking it. The clipping path is updated here.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void endPath() throws IOException;
-
- /**
- * Stroke the path.
- *
- * @throws IOException If there is an IO error while stroking the path.
- */
- public abstract void strokePath() throws IOException;
-
- /**
- * Fill the path.
- *
- * @param windingRule The winding rule this path will use.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void fillPath(int windingRule) throws IOException;
-
- /**
- * Fills and then strokes the path.
- *
- * @param windingRule The winding rule this path will use.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void fillAndStrokePath(int windingRule) throws IOException;
-
- /**
- * Fill with Shading.
- *
- * @param shadingName The name of the Shading Dictionary to use for this fill instruction.
- *
- * @throws IOException if something went wrong.
- */
- public abstract void shadingFill(COSName shadingName) throws IOException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.contentstream;
+
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
+
+import java.awt.geom.Point2D;
+import java.io.IOException;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColor;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorN;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorSpace;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceCMYKColor;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceGrayColor;
+import org.apache.pdfbox.contentstream.operator.color.SetNonStrokingDeviceRGBColor;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingColor;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingColorN;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingColorSpace;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceCMYKColor;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceGrayColor;
+import org.apache.pdfbox.contentstream.operator.color.SetStrokingDeviceRGBColor;
+import org.apache.pdfbox.contentstream.operator.graphics.AppendRectangleToPath;
+import org.apache.pdfbox.contentstream.operator.graphics.BeginInlineImage;
+import org.apache.pdfbox.contentstream.operator.graphics.ClipEvenOddRule;
+import org.apache.pdfbox.contentstream.operator.graphics.ClipNonZeroRule;
+import org.apache.pdfbox.contentstream.operator.graphics.CloseAndStrokePath;
+import org.apache.pdfbox.contentstream.operator.graphics.CloseFillEvenOddAndStrokePath;
+import org.apache.pdfbox.contentstream.operator.graphics.CloseFillNonZeroAndStrokePath;
+import org.apache.pdfbox.contentstream.operator.graphics.ClosePath;
+import org.apache.pdfbox.contentstream.operator.graphics.CurveTo;
+import org.apache.pdfbox.contentstream.operator.graphics.CurveToReplicateFinalPoint;
+import org.apache.pdfbox.contentstream.operator.graphics.CurveToReplicateInitialPoint;
+import org.apache.pdfbox.contentstream.operator.graphics.DrawObject;
+import org.apache.pdfbox.contentstream.operator.graphics.EndPath;
+import org.apache.pdfbox.contentstream.operator.graphics.FillEvenOddAndStrokePath;
+import org.apache.pdfbox.contentstream.operator.graphics.FillEvenOddRule;
+import org.apache.pdfbox.contentstream.operator.graphics.FillNonZeroAndStrokePath;
+import org.apache.pdfbox.contentstream.operator.graphics.FillNonZeroRule;
+import org.apache.pdfbox.contentstream.operator.graphics.LegacyFillNonZeroRule;
+import org.apache.pdfbox.contentstream.operator.graphics.LineTo;
+import org.apache.pdfbox.contentstream.operator.graphics.MoveTo;
+import org.apache.pdfbox.contentstream.operator.graphics.ShadingFill;
+import org.apache.pdfbox.contentstream.operator.graphics.StrokePath;
+import org.apache.pdfbox.contentstream.operator.markedcontent.BeginMarkedContentSequence;
+import org.apache.pdfbox.contentstream.operator.markedcontent.BeginMarkedContentSequenceWithProperties;
+import org.apache.pdfbox.contentstream.operator.markedcontent.EndMarkedContentSequence;
+import org.apache.pdfbox.contentstream.operator.state.Concatenate;
+import org.apache.pdfbox.contentstream.operator.state.Restore;
+import org.apache.pdfbox.contentstream.operator.state.Save;
+import org.apache.pdfbox.contentstream.operator.state.SetFlatness;
+import org.apache.pdfbox.contentstream.operator.state.SetGraphicsStateParameters;
+import org.apache.pdfbox.contentstream.operator.state.SetLineCapStyle;
+import org.apache.pdfbox.contentstream.operator.state.SetLineDashPattern;
+import org.apache.pdfbox.contentstream.operator.state.SetLineJoinStyle;
+import org.apache.pdfbox.contentstream.operator.state.SetLineMiterLimit;
+import org.apache.pdfbox.contentstream.operator.state.SetLineWidth;
+import org.apache.pdfbox.contentstream.operator.state.SetMatrix;
+import org.apache.pdfbox.contentstream.operator.state.SetRenderingIntent;
+import org.apache.pdfbox.contentstream.operator.text.BeginText;
+import org.apache.pdfbox.contentstream.operator.text.EndText;
+import org.apache.pdfbox.contentstream.operator.text.SetFontAndSize;
+import org.apache.pdfbox.contentstream.operator.text.SetTextHorizontalScaling;
+import org.apache.pdfbox.contentstream.operator.text.ShowTextAdjusted;
+import org.apache.pdfbox.contentstream.operator.text.ShowTextLine;
+import org.apache.pdfbox.contentstream.operator.text.ShowTextLineAndSpace;
+import org.apache.pdfbox.contentstream.operator.text.MoveText;
+import org.apache.pdfbox.contentstream.operator.text.MoveTextSetLeading;
+import org.apache.pdfbox.contentstream.operator.text.NextLine;
+import org.apache.pdfbox.contentstream.operator.text.SetCharSpacing;
+import org.apache.pdfbox.contentstream.operator.text.SetTextLeading;
+import org.apache.pdfbox.contentstream.operator.text.SetTextRenderingMode;
+import org.apache.pdfbox.contentstream.operator.text.SetTextRise;
+import org.apache.pdfbox.contentstream.operator.text.SetWordSpacing;
+import org.apache.pdfbox.contentstream.operator.text.ShowText;
+
+/**
+ * PDFStreamEngine subclass for advanced processing of graphics.
+ * This class should be subclassed by end users looking to hook into graphics operations.
+ *
+ * @author John Hewson
+ */
+public abstract class PDFGraphicsStreamEngine extends PDFStreamEngine
+{
+ // may be null, for example if the stream is a tiling pattern
+ private final PDPage page;
+
+ /**
+ * Constructor.
+ */
+ protected PDFGraphicsStreamEngine(PDPage page)
+ {
+ this.page = page;
+
+ addOperator(new CloseFillNonZeroAndStrokePath());
+ addOperator(new FillNonZeroAndStrokePath());
+ addOperator(new CloseFillEvenOddAndStrokePath());
+ addOperator(new FillEvenOddAndStrokePath());
+ addOperator(new BeginInlineImage());
+ addOperator(new BeginText());
+ addOperator(new CurveTo());
+ addOperator(new Concatenate());
+ addOperator(new SetStrokingColorSpace());
+ addOperator(new SetNonStrokingColorSpace());
+ addOperator(new SetLineDashPattern());
+ addOperator(new DrawObject()); // special graphics version
+ addOperator(new EndText());
+ addOperator(new FillNonZeroRule());
+ addOperator(new LegacyFillNonZeroRule());
+ addOperator(new FillEvenOddRule());
+ addOperator(new SetStrokingDeviceGrayColor());
+ addOperator(new SetNonStrokingDeviceGrayColor());
+ addOperator(new SetGraphicsStateParameters());
+ addOperator(new ClosePath());
+ addOperator(new SetFlatness());
+ addOperator(new SetLineJoinStyle());
+ addOperator(new SetLineCapStyle());
+ addOperator(new SetStrokingDeviceCMYKColor());
+ addOperator(new SetNonStrokingDeviceCMYKColor());
+ addOperator(new LineTo());
+ addOperator(new MoveTo());
+ addOperator(new SetLineMiterLimit());
+ addOperator(new EndPath());
+ addOperator(new Save());
+ addOperator(new Restore());
+ addOperator(new AppendRectangleToPath());
+ addOperator(new SetStrokingDeviceRGBColor());
+ addOperator(new SetNonStrokingDeviceRGBColor());
+ addOperator(new SetRenderingIntent());
+ addOperator(new CloseAndStrokePath());
+ addOperator(new StrokePath());
+ addOperator(new SetStrokingColor());
+ addOperator(new SetNonStrokingColor());
+ addOperator(new SetStrokingColorN());
+ addOperator(new SetNonStrokingColorN());
+ addOperator(new ShadingFill());
+ addOperator(new NextLine());
+ addOperator(new SetCharSpacing());
+ addOperator(new MoveText());
+ addOperator(new MoveTextSetLeading());
+ addOperator(new SetFontAndSize());
+ addOperator(new ShowText());
+ addOperator(new ShowTextAdjusted());
+ addOperator(new SetTextLeading());
+ addOperator(new SetMatrix());
+ addOperator(new SetTextRenderingMode());
+ addOperator(new SetTextRise());
+ addOperator(new SetWordSpacing());
+ addOperator(new SetTextHorizontalScaling());
+ addOperator(new CurveToReplicateInitialPoint());
+ addOperator(new SetLineWidth());
+ addOperator(new ClipNonZeroRule());
+ addOperator(new ClipEvenOddRule());
+ addOperator(new CurveToReplicateFinalPoint());
+ addOperator(new ShowTextLine());
+ addOperator(new ShowTextLineAndSpace());
+ addOperator(new BeginMarkedContentSequence());
+ addOperator(new BeginMarkedContentSequenceWithProperties());
+ addOperator(new EndMarkedContentSequence());
+ }
+
+ /**
+ * Returns the page.
+ *
+ * @return the page.
+ *
+ */
+ protected final PDPage getPage()
+ {
+ return page;
+ }
+
+ /**
+ * Append a rectangle to the current path.
+ *
+ * @param p0 point P0 of the rectangle.
+ * @param p1 point P1 of the rectangle.
+ * @param p2 point P2 of the rectangle.
+ * @param p3 point P3 of the rectangle.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void appendRectangle(Point2D p0, Point2D p1,
+ Point2D p2, Point2D p3) throws IOException;
+
+ /**
+ * Draw the image.
+ *
+ * @param pdImage The image to draw.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void drawImage(PDImage pdImage) throws IOException;
+
+ /**
+ * Modify the current clipping path by intersecting it with the current path. The clipping path will not be updated
+ * until the succeeding painting operator is called.
+ *
+ * @param windingRule The winding rule which will be used for clipping.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void clip(int windingRule) throws IOException;
+
+ /**
+ * Starts a new path at (x,y).
+ *
+ * @param x x-coordinate of the target point.
+ * @param y y-coordinate of the target point.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void moveTo(float x, float y) throws IOException;
+
+ /**
+ * Draws a line from the current point to (x,y).
+ *
+ * @param x x-coordinate of the end point of the line.
+ * @param y y-coordinate of the end point of the line.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void lineTo(float x, float y) throws IOException;
+
+ /**
+ * Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.
+ *
+ * @param x1 x-coordinate of the first control point.
+ * @param y1 y-coordinate of the first control point.
+ * @param x2 x-coordinate of the second control point.
+ * @param y2 y-coordinate of the second control point.
+ * @param x3 x-coordinate of the end point of the curve.
+ * @param y3 y-coordinate of the end point of the curve.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void curveTo(float x1, float y1,
+ float x2, float y2,
+ float x3, float y3) throws IOException;
+
+ /**
+ * Returns the current point of the current path.
+ *
+ * @return the current point.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract Point2D getCurrentPoint() throws IOException;
+
+ /**
+ * Closes the current path.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void closePath() throws IOException;
+
+ /**
+ * Ends the current path without filling or stroking it. The clipping path is updated here.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void endPath() throws IOException;
+
+ /**
+ * Stroke the path.
+ *
+ * @throws IOException If there is an IO error while stroking the path.
+ */
+ public abstract void strokePath() throws IOException;
+
+ /**
+ * Fill the path.
+ *
+ * @param windingRule The winding rule this path will use.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void fillPath(int windingRule) throws IOException;
+
+ /**
+ * Fills and then strokes the path.
+ *
+ * @param windingRule The winding rule this path will use.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void fillAndStrokePath(int windingRule) throws IOException;
+
+ /**
+ * Fill with Shading.
+ *
+ * @param shadingName The name of the Shading Dictionary to use for this fill instruction.
+ *
+ * @throws IOException if something went wrong.
+ */
+ public abstract void shadingFill(COSName shadingName) throws IOException;
+}
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java Tue Jan 8 20:24:26 2019
@@ -34,6 +34,8 @@ import org.apache.pdfbox.contentstream.o
import org.apache.pdfbox.contentstream.operator.state.EmptyGraphicsStackException;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSString;
@@ -817,6 +819,25 @@ public abstract class PDFStreamEngine
}
/**
+ * Called when a marked content group begins
+ *
+ * @param tag content tag
+ * @param properties optional properties
+ */
+ public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
+ {
+ // overridden in subclasses
+ }
+
+ /**
+ * Called when a a marked content group ends
+ */
+ public void endMarkedContentSequence()
+ {
+ // overridden in subclasses
+ }
+
+ /**
* This is used to handle an operation.
*
* @param operation The operation to perform.
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequence.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequence.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequence.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequence.java Tue Jan 8 20:24:26 2019
@@ -1,57 +1,53 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.contentstream.operator.markedcontent;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.text.PDFMarkedContentExtractor;
-import org.apache.pdfbox.contentstream.operator.Operator;
-import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
-
-/**
- * BMC : Begins a marked-content sequence.
- *
- * @author Johannes Koch
- */
-public class BeginMarkedContentSequence extends OperatorProcessor
-{
- @Override
- public void process(Operator operator, List<COSBase> arguments) throws IOException
- {
- COSName tag = null;
- for (COSBase argument : arguments)
- {
- if (argument instanceof COSName)
- {
- tag = (COSName) argument;
- }
- }
- if (this.context instanceof PDFMarkedContentExtractor)
- {
- ((PDFMarkedContentExtractor) this.context).beginMarkedContentSequence(tag, null);
- }
- }
-
- @Override
- public String getName()
- {
- return "BMC";
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.contentstream.operator.markedcontent;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.contentstream.operator.Operator;
+import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
+
+/**
+ * BMC : Begins a marked-content sequence.
+ *
+ * @author Johannes Koch
+ */
+public class BeginMarkedContentSequence extends OperatorProcessor
+{
+ @Override
+ public void process(Operator operator, List<COSBase> arguments) throws IOException
+ {
+ COSName tag = null;
+ for (COSBase argument : arguments)
+ {
+ if (argument instanceof COSName)
+ {
+ tag = (COSName) argument;
+ }
+ }
+ this.context.beginMarkedContentSequence(tag, null);
+ }
+
+ @Override
+ public String getName()
+ {
+ return "BMC";
+ }
+}
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequenceWithProperties.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequenceWithProperties.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequenceWithProperties.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/BeginMarkedContentSequenceWithProperties.java Tue Jan 8 20:24:26 2019
@@ -1,63 +1,59 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.contentstream.operator.markedcontent;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.text.PDFMarkedContentExtractor;
-import org.apache.pdfbox.contentstream.operator.Operator;
-import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
-
-/**
- * BDC : Begins a marked-content sequence with property list.
- *
- * @author Johannes Koch
- */
-public class BeginMarkedContentSequenceWithProperties extends OperatorProcessor
-{
- @Override
- public void process(Operator operator, List<COSBase> arguments) throws IOException
- {
- COSName tag = null;
- COSDictionary properties = null;
- for (COSBase argument : arguments)
- {
- if (argument instanceof COSName)
- {
- tag = (COSName) argument;
- }
- else if (argument instanceof COSDictionary)
- {
- properties = (COSDictionary) argument;
- }
- }
- if (this.context instanceof PDFMarkedContentExtractor)
- {
- ((PDFMarkedContentExtractor) this.context).beginMarkedContentSequence(tag, properties);
- }
- }
-
- @Override
- public String getName()
- {
- return "BDC";
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.contentstream.operator.markedcontent;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.contentstream.operator.Operator;
+import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
+
+/**
+ * BDC : Begins a marked-content sequence with property list.
+ *
+ * @author Johannes Koch
+ */
+public class BeginMarkedContentSequenceWithProperties extends OperatorProcessor
+{
+ @Override
+ public void process(Operator operator, List<COSBase> arguments) throws IOException
+ {
+ COSName tag = null;
+ COSDictionary properties = null;
+ for (COSBase argument : arguments)
+ {
+ if (argument instanceof COSName)
+ {
+ tag = (COSName) argument;
+ }
+ else if (argument instanceof COSDictionary)
+ {
+ properties = (COSDictionary) argument;
+ }
+ }
+ this.context.beginMarkedContentSequence(tag, properties);
+ }
+
+ @Override
+ public String getName()
+ {
+ return "BDC";
+ }
+}
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/EndMarkedContentSequence.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/EndMarkedContentSequence.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/EndMarkedContentSequence.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/EndMarkedContentSequence.java Tue Jan 8 20:24:26 2019
@@ -1,48 +1,44 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pdfbox.contentstream.operator.markedcontent;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.text.PDFMarkedContentExtractor;
-import org.apache.pdfbox.contentstream.operator.Operator;
-import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
-
-/**
- * EMC : Ends a marked-content sequence begun by BMC or BDC.
- *
- * @author Johannes Koch
- */
-public class EndMarkedContentSequence extends OperatorProcessor
-{
- @Override
- public void process(Operator operator, List<COSBase> arguments) throws IOException
- {
- if (this.context instanceof PDFMarkedContentExtractor)
- {
- ((PDFMarkedContentExtractor) this.context).endMarkedContentSequence();
- }
- }
-
- @Override
- public String getName()
- {
- return "EMC";
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.contentstream.operator.markedcontent;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.contentstream.operator.Operator;
+import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
+
+/**
+ * EMC : Ends a marked-content sequence begun by BMC or BDC.
+ *
+ * @author Johannes Koch
+ */
+public class EndMarkedContentSequence extends OperatorProcessor
+{
+ @Override
+ public void process(Operator operator, List<COSBase> arguments) throws IOException
+ {
+ this.context.endMarkedContentSequence();
+ }
+
+ @Override
+ public String getName()
+ {
+ return "EMC";
+ }
+}
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentGroup.java Tue Jan 8 20:24:26 2019
@@ -19,6 +19,7 @@ package org.apache.pdfbox.pdmodel.graphi
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList;
+import org.apache.pdfbox.rendering.RenderDestination;
/**
* An optional content group (OCG).
@@ -48,6 +49,51 @@ public class PDOptionalContentGroup exte
"Provided dictionary is not of type '" + COSName.OCG + "'");
}
}
+
+ /**
+ * Enumeration for the renderState dictionary entry on the "Export", "View"
+ * and "Print" dictionary.
+ */
+ public enum RenderState
+ {
+ /** The "ON" value. */
+ ON(COSName.ON),
+ /** The "OFF" value. */
+ OFF(COSName.OFF);
+
+ private final COSName name;
+
+ private RenderState(COSName value)
+ {
+ this.name = value;
+ }
+
+ /**
+ * Returns the base state represented by the given {@link COSName}.
+ *
+ * @param state the state name
+ * @return the state enum value
+ */
+ public static RenderState valueOf(COSName state)
+ {
+ if (state == null)
+ {
+ return null;
+ }
+
+ return RenderState.valueOf(state.getName().toUpperCase());
+ }
+
+ /**
+ * Returns the PDF name for the state.
+ *
+ * @return the name of the state
+ */
+ public COSName getName()
+ {
+ return this.name;
+ }
+ }
/**
* Returns the name of the optional content group.
@@ -67,7 +113,36 @@ public class PDOptionalContentGroup exte
dict.setString(COSName.NAME, name);
}
- //TODO Add support for "Intent" and "Usage"
+ //TODO Add support for "Intent"
+ /**
+ * @param destination to be rendered
+ * @return state or null if undefined
+ */
+ public RenderState getRenderState(RenderDestination destination)
+ {
+ COSName state = null;
+ COSDictionary usage = (COSDictionary) dict.getDictionaryObject("Usage");
+ if (usage != null)
+ {
+ if (RenderDestination.PRINT.equals(destination))
+ {
+ COSDictionary print = (COSDictionary) usage.getDictionaryObject("Print");
+ state = print == null ? null : (COSName) print.getDictionaryObject("PrintState");
+ }
+ else if (RenderDestination.VIEW.equals(destination))
+ {
+ COSDictionary view = (COSDictionary) usage.getDictionaryObject("View");
+ state = view == null ? null : (COSName) view.getDictionaryObject("ViewState");
+ }
+ // Fallback to export
+ if (state == null)
+ {
+ COSDictionary export = (COSDictionary) usage.getDictionaryObject("Export");
+ state = export == null ? null : (COSName) export.getDictionaryObject("ExportState");
+ }
+ }
+ return state == null ? null : RenderState.valueOf(state);
+ }
@Override
public String toString()
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/printing/PDFPrintable.java Tue Jan 8 20:24:26 2019
@@ -32,6 +32,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.rendering.RenderDestination;
/**
* Prints pages from a PDF document using any page size or scaling mode.
@@ -217,7 +218,7 @@ public final class PDFPrintable implemen
AffineTransform transform = (AffineTransform)graphics2D.getTransform().clone();
graphics2D.setBackground(Color.WHITE);
renderer.setSubsamplingAllowed(subsamplingAllowed);
- renderer.renderPageToGraphics(pageIndex, graphics2D, (float)scale);
+ renderer.renderPageToGraphics(pageIndex, graphics2D, (float)scale, (float)scale, RenderDestination.PRINT);
// draw crop box
if (showPageBorder)
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Tue Jan 8 20:24:26 2019
@@ -31,6 +31,8 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.blend.BlendMode;
+import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup;
+import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties;
import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
import org.apache.pdfbox.pdmodel.interactive.annotation.AnnotationFilter;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
@@ -62,6 +64,8 @@ public class PDFRenderer
private boolean subsamplingAllowed = false;
+ private RenderDestination defaultDestination;
+
private BufferedImage pageImage;
private static boolean kcmsLogged = false;
@@ -80,7 +84,7 @@ public class PDFRenderer
kcmsLogged = true;
}
}
-
+
/**
* Return the AnnotationFilter.
*
@@ -132,6 +136,22 @@ public class PDFRenderer
}
/**
+ * @return the defaultDestination
+ */
+ public RenderDestination getDefaultDestination()
+ {
+ return defaultDestination;
+ }
+
+ /**
+ * @param defaultDestination the defaultDestination to set
+ */
+ public void setDefaultDestination(RenderDestination defaultDestination)
+ {
+ this.defaultDestination = defaultDestination;
+ }
+
+ /**
* Returns the given page as an RGB image at 72 DPI
* @param pageIndex the zero-based index of the page to be converted.
* @return the rendered page image
@@ -192,16 +212,29 @@ public class PDFRenderer
public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType)
throws IOException
{
+ return renderImage(pageIndex, scale, imageType,
+ defaultDestination == null ? RenderDestination.EXPORT : defaultDestination);
+ }
+
+ /**
+ * Returns the given page as an RGB or ARGB image at the given scale.
+ * @param pageIndex the zero-based index of the page to be converted
+ * @param scale the scaling factor, where 1 = 72 DPI
+ * @param imageType the type of image to return
+ * @param destination controlling visibility of optional content groups
+ * @return the rendered page image
+ * @throws IOException if the PDF cannot be read
+ */
+ public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType, RenderDestination destination)
+ throws IOException
+ {
PDPage page = document.getPage(pageIndex);
PDRectangle cropbBox = page.getCropBox();
float widthPt = cropbBox.getWidth();
float heightPt = cropbBox.getHeight();
-
- // PDFBOX-4306 avoid single blank pixel line on the right or on the bottom
- int widthPx = (int) Math.max(Math.floor(widthPt * scale), 1);
- int heightPx = (int) Math.max(Math.floor(heightPt * scale), 1);
-
+ int widthPx = Math.round(widthPt * scale);
+ int heightPx = Math.round(heightPt * scale);
int rotationAngle = page.getRotation();
int bimType = imageType.toBufferedImageType();
@@ -242,7 +275,7 @@ public class PDFRenderer
transform(g, page, scale, scale);
// the end-user may provide a custom PageDrawer
- PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed);
+ PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed, destination);
PageDrawer drawer = createPageDrawer(parameters);
drawer.drawPage(g, page.getCropBox());
@@ -300,6 +333,23 @@ public class PDFRenderer
public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scaleX, float scaleY)
throws IOException
{
+ renderPageToGraphics(pageIndex, graphics, scaleX, scaleY,
+ defaultDestination == null ? RenderDestination.VIEW : defaultDestination);
+ }
+
+ /**
+ * Renders a given page to an AWT Graphics2D instance.
+ *
+ * @param pageIndex the zero-based index of the page to be converted
+ * @param graphics the Graphics2D on which to draw the page
+ * @param scaleX the scale to draw the page at for the x-axis
+ * @param scaleY the scale to draw the page at for the y-axis
+ * @param destination controlling visibility of optional content groups
+ * @throws IOException if the PDF cannot be read
+ */
+ public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float scaleX, float scaleY, RenderDestination destination)
+ throws IOException
+ {
PDPage page = document.getPage(pageIndex);
// TODO need width/wight calculations? should these be in PageDrawer?
@@ -309,11 +359,22 @@ public class PDFRenderer
graphics.clearRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight());
// the end-user may provide a custom PageDrawer
- PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed);
+ PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed, destination);
PageDrawer drawer = createPageDrawer(parameters);
drawer.drawPage(graphics, cropBox);
}
+ /**
+ * Indicates whether an optional content group is enabled.
+ * @param group the group
+ * @return true if the group is enabled
+ */
+ public boolean isGroupEnabled(PDOptionalContentGroup group)
+ {
+ PDOptionalContentProperties ocProperties = document.getDocumentCatalog().getOCProperties();
+ return ocProperties == null || ocProperties.isGroupEnabled(group);
+ }
+
// scale rotate translate
private void transform(Graphics2D graphics, PDPage page, float scaleX, float scaleY)
{
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Tue Jan 8 20:24:26 2019
@@ -57,6 +57,7 @@ import java.util.Stack;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine;
+import org.apache.pdfbox.contentstream.operator.Operator;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
@@ -65,6 +66,7 @@ import org.apache.pdfbox.cos.COSNumber;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
+import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList;
import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
import org.apache.pdfbox.pdmodel.font.PDFont;
@@ -82,6 +84,8 @@ import org.apache.pdfbox.pdmodel.graphic
import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
+import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup;
+import org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup.RenderState;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDShadingPattern;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
@@ -148,6 +152,11 @@ public class PageDrawer extends PDFGraph
private final Stack<TransparencyGroup> transparencyGroupStack = new Stack<TransparencyGroup>();
+ // if greater zero the content is hidden and wil not be rendered
+ private int nestedHiddenOCGCount;
+
+ private final RenderDestination destination;
+
/**
* Default annotations filter, returns all annotations
*/
@@ -171,6 +180,7 @@ public class PageDrawer extends PDFGraph
super(parameters.getPage());
this.renderer = parameters.getRenderer();
this.subsamplingAllowed = parameters.isSubsamplingAllowed();
+ this.destination = parameters.getDestination();
}
/**
@@ -1809,4 +1819,81 @@ public class PageDrawer extends PDFGraph
return false;
}
+
+ /**
+ * Marked content begins
+ *
+ * @param tag name of the content mark
+ * @see
+ * org.apache.pdfbox.contentstream.PDFStreamEngine#beginMarkedContentSequence(org.apache.pdfbox.cos.COSName,
+ * org.apache.pdfbox.cos.COSDictionary)
+ */
+ @Override
+ public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
+ {
+ if (nestedHiddenOCGCount > 0)
+ {
+ nestedHiddenOCGCount++;
+ return;
+ }
+ if (tag == null || getPage().getResources() == null)
+ {
+ return;
+ }
+ PDPropertyList propertyList = getPage().getResources().getProperties(tag);
+ if (propertyList instanceof PDOptionalContentGroup)
+ {
+ PDOptionalContentGroup group = (PDOptionalContentGroup) propertyList;
+ RenderState printState = group.getRenderState(destination);
+ if (printState == null)
+ {
+ if (!getRenderer().isGroupEnabled(group))
+ {
+ nestedHiddenOCGCount = 1;
+ }
+ }
+ else if (RenderState.OFF.equals(printState))
+ {
+ nestedHiddenOCGCount = 1;
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.apache.pdfbox.contentstream.PDFStreamEngine#endMarkedContentSequence()
+ */
+ @Override
+ public void endMarkedContentSequence()
+ {
+ if (nestedHiddenOCGCount > 0)
+ {
+ nestedHiddenOCGCount--;
+ }
+ }
+
+ private boolean isContentMarkOperator(Operator operator)
+ {
+ String name = operator.getName();
+ return "BMC".equals(name) || "BDC".equals(name) || "EMC".equals(name);
+ }
+
+ private boolean isContentRendered()
+ {
+ return nestedHiddenOCGCount <= 0;
+ }
+
+ /**
+ * Handle hidden optional content groups
+ *
+ * @see org.apache.pdfbox.contentstream.PDFStreamEngine#processOperator(Operator, List)
+ */
+ @Override
+ protected void processOperator(Operator operator, List<COSBase> operands) throws IOException
+ {
+ if (isContentRendered() || isContentMarkOperator(operator))
+ {
+ super.processOperator(operator, operands);
+ }
+ }
}
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawerParameters.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawerParameters.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawerParameters.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawerParameters.java Tue Jan 8 20:24:26 2019
@@ -31,15 +31,17 @@ public final class PageDrawerParameters
private final PDFRenderer renderer;
private final PDPage page;
private final boolean subsamplingAllowed;
+ private final RenderDestination destination;
/**
* Package-private constructor.
*/
- PageDrawerParameters(PDFRenderer renderer, PDPage page, boolean subsamplingAllowed)
+ PageDrawerParameters(PDFRenderer renderer, PDPage page, boolean subsamplingAllowed, RenderDestination destination)
{
this.renderer = renderer;
this.page = page;
this.subsamplingAllowed = subsamplingAllowed;
+ this.destination = destination;
}
/**
@@ -65,4 +67,13 @@ public final class PageDrawerParameters
{
return subsamplingAllowed;
}
+
+ /**
+ * @return the destination
+ */
+ public RenderDestination getDestination()
+ {
+ return this.destination;
+ }
+
}
Added: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java?rev=1850792&view=auto
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java (added)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java Tue Jan 8 20:24:26 2019
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.rendering;
+
+/**
+ * Optional content groups are visible depending on the render purpose.
+ */
+public enum RenderDestination
+{
+ /** graphics export */
+ EXPORT,
+ /** viewing */
+ VIEW,
+ /** printing */
+ PRINT
+}
\ No newline at end of file
Propchange: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/RenderDestination.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/text/PDFMarkedContentExtractor.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/text/PDFMarkedContentExtractor.java?rev=1850792&r1=1850791&r2=1850792&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/text/PDFMarkedContentExtractor.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/text/PDFMarkedContentExtractor.java Tue Jan 8 20:24:26 2019
@@ -79,6 +79,7 @@ public class PDFMarkedContentExtractor e
return second > first - variance && second < first + variance;
}
+ @Override
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
{
PDMarkedContent markedContent = PDMarkedContent.create(tag, properties);
@@ -98,6 +99,7 @@ public class PDFMarkedContentExtractor e
this.currentMarkedContents.push(markedContent);
}
+ @Override
public void endMarkedContentSequence()
{
if (!this.currentMarkedContents.isEmpty())