Package com.itextpdf.text.pdf.pdfcleanup
Class PdfCleanUpContentOperator
- java.lang.Object
-
- com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpContentOperator
-
- All Implemented Interfaces:
ContentOperator
class PdfCleanUpContentOperator extends java.lang.Object implements ContentOperator
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]cprotected PdfCleanUpRenderListenercleanUpStrategyprivate static java.util.Set<java.lang.String>clippingPathOperatorsprivate static byte[]csprivate static byte[]eoFprivate static java.util.Set<java.lang.String>eoFillOperatorsprivate static byte[]eoWprivate static byte[]fprivate static byte[]hprivate static byte[]lprivate static java.util.Set<java.lang.String>lineStyleOperatorsprivate static byte[]mprivate static byte[]nprivate static java.util.Set<java.lang.String>nwFillOperatorsprotected ContentOperatororiginalContentOperatorprivate static java.util.Set<java.lang.String>pathConstructionOperatorsprivate static java.util.Set<java.lang.String>pathPaintingOperatorsprivate static byte[]qprivate static byte[]Qprivate static byte[]Sprivate static java.util.Set<java.lang.String>strokeColorOperatorsprivate static java.util.Set<java.lang.String>strokeOperatorsprivate static byte[]Tcprivate static byte[]TcTStarprivate static java.util.Set<java.lang.String>textShowingOperatorsprivate static byte[]TJprivate static byte[]TStarprivate static byte[]Twprivate static byte[]W
-
Constructor Summary
Constructors Constructor Description PdfCleanUpContentOperator(PdfCleanUpRenderListener cleanUpStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanallChunksAreVisible(java.util.List<PdfCleanUpContentChunk> chunks)private floatgetUnscaledTextChunkWidth(PdfCleanUpContentChunk.Text chunk, float characterSpacing, float wordSpacing, float fontSize, float horizontalScaling)We get into this method when the current chunk is not visible.voidinvoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral operator, java.util.ArrayList<PdfObject> operands)Invokes a content operator.private booleanisSpace(PdfCleanUpContentChunk.Text chunk)static voidpopulateOperators(PdfContentStreamProcessor contentProcessor, PdfCleanUpRenderListener pdfCleanUpRenderListener)private java.util.Map<java.lang.Integer,java.lang.Float>structureTJarray(PdfArray array)Example.private static voidtoPdf(PdfObject object, PdfWriter writer, java.io.OutputStream os)Overriding standard PdfObject.toPdf because we need sorted PdfDictionaries.private voidupdateImageStream(PRStream imageStream, byte[] newData)private voidwriteBezierCurve(BezierCurve curve, PdfContentByte canvas)private voidwriteLine(Line line, PdfContentByte canvas)private voidwriteMoveTo(Point2D destinationPoint, PdfContentByte canvas)private voidwriteOperands(PdfContentByte canvas, java.util.List<PdfObject> operands)private voidwritePath(Path path, byte[] pathPaintingOperator, PdfContentByte canvas)private voidwritePath(java.lang.String operatorStr, PdfContentByte canvas, PdfName strokeColorSpace)private voidwriteStroke(PdfContentByte canvas, Path path, PdfName strokeColorSpace)private voidwriteTextChunks(java.util.Map<java.lang.Integer,java.lang.Float> structuredTJoperands, java.util.List<PdfCleanUpContentChunk> chunks, PdfContentByte canvas, float characterSpacing, float wordSpacing, float fontSize, float horizontalScaling)Renders parts of text which are visible.
-
-
-
Field Detail
-
TStar
private static final byte[] TStar
-
Tw
private static final byte[] Tw
-
TcTStar
private static final byte[] TcTStar
-
TJ
private static final byte[] TJ
-
Tc
private static final byte[] Tc
-
m
private static final byte[] m
-
l
private static final byte[] l
-
c
private static final byte[] c
-
h
private static final byte[] h
-
S
private static final byte[] S
-
f
private static final byte[] f
-
eoF
private static final byte[] eoF
-
n
private static final byte[] n
-
W
private static final byte[] W
-
eoW
private static final byte[] eoW
-
q
private static final byte[] q
-
Q
private static final byte[] Q
-
cs
private static final byte[] cs
-
textShowingOperators
private static final java.util.Set<java.lang.String> textShowingOperators
-
pathConstructionOperators
private static final java.util.Set<java.lang.String> pathConstructionOperators
-
strokeOperators
private static final java.util.Set<java.lang.String> strokeOperators
-
nwFillOperators
private static final java.util.Set<java.lang.String> nwFillOperators
-
eoFillOperators
private static final java.util.Set<java.lang.String> eoFillOperators
-
pathPaintingOperators
private static final java.util.Set<java.lang.String> pathPaintingOperators
-
clippingPathOperators
private static final java.util.Set<java.lang.String> clippingPathOperators
-
lineStyleOperators
private static final java.util.Set<java.lang.String> lineStyleOperators
-
strokeColorOperators
private static final java.util.Set<java.lang.String> strokeColorOperators
-
cleanUpStrategy
protected PdfCleanUpRenderListener cleanUpStrategy
-
originalContentOperator
protected ContentOperator originalContentOperator
-
-
Constructor Detail
-
PdfCleanUpContentOperator
public PdfCleanUpContentOperator(PdfCleanUpRenderListener cleanUpStrategy)
-
-
Method Detail
-
populateOperators
public static void populateOperators(PdfContentStreamProcessor contentProcessor, PdfCleanUpRenderListener pdfCleanUpRenderListener)
-
invoke
public void invoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral operator, java.util.ArrayList<PdfObject> operands) throws java.lang.Exception
Description copied from interface:ContentOperatorInvokes a content operator.- Specified by:
invokein interfaceContentOperator- Parameters:
pdfContentStreamProcessor- the processor that is dealing with the PDF contentoperator- the literal PDF syntax of the operatoroperands- the operands that come with the operator- Throws:
java.lang.Exception- any exception can be thrown - it will be re-packaged into a runtime exception and re-thrown by thePdfContentStreamProcessor
-
writeOperands
private void writeOperands(PdfContentByte canvas, java.util.List<PdfObject> operands) throws java.io.IOException
- Throws:
java.io.IOException
-
allChunksAreVisible
private boolean allChunksAreVisible(java.util.List<PdfCleanUpContentChunk> chunks)
-
toPdf
private static void toPdf(PdfObject object, PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Overriding standard PdfObject.toPdf because we need sorted PdfDictionaries.- Throws:
java.io.IOException
-
structureTJarray
private java.util.Map<java.lang.Integer,java.lang.Float> structureTJarray(PdfArray array)
Example. TJ = [(h) 3 4 (q) 7 (w) (e)] Result = {0:0, 1:7, 2:7, 3:0, 4:0}- Returns:
- Map whose key is an ordinal number of the string in the TJ array and value is the position adjustment.
-
writeTextChunks
private void writeTextChunks(java.util.Map<java.lang.Integer,java.lang.Float> structuredTJoperands, java.util.List<PdfCleanUpContentChunk> chunks, PdfContentByte canvas, float characterSpacing, float wordSpacing, float fontSize, float horizontalScaling) throws java.io.IOExceptionRenders parts of text which are visible.- Throws:
java.io.IOException
-
getUnscaledTextChunkWidth
private float getUnscaledTextChunkWidth(PdfCleanUpContentChunk.Text chunk, float characterSpacing, float wordSpacing, float fontSize, float horizontalScaling)
We get into this method when the current chunk is not visible. Here we are calculating a piece of the Tj coefficient for a previous visible chunk. For details see PDF spec., Text Space Details, formula for "tx" coefficient and TextRenderInfo class (getUnscaledBaseline)
-
isSpace
private boolean isSpace(PdfCleanUpContentChunk.Text chunk)
-
updateImageStream
private void updateImageStream(PRStream imageStream, byte[] newData) throws BadElementException, java.io.IOException, BadPdfFormatException
- Throws:
BadElementExceptionjava.io.IOExceptionBadPdfFormatException
-
writePath
private void writePath(java.lang.String operatorStr, PdfContentByte canvas, PdfName strokeColorSpace) throws java.io.IOException- Throws:
java.io.IOException
-
writePath
private void writePath(Path path, byte[] pathPaintingOperator, PdfContentByte canvas) throws java.io.IOException
- Throws:
java.io.IOException
-
writeMoveTo
private void writeMoveTo(Point2D destinationPoint, PdfContentByte canvas) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBezierCurve
private void writeBezierCurve(BezierCurve curve, PdfContentByte canvas) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLine
private void writeLine(Line line, PdfContentByte canvas) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStroke
private void writeStroke(PdfContentByte canvas, Path path, PdfName strokeColorSpace) throws java.io.IOException
- Throws:
java.io.IOException
-
-