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[]
c
protected PdfCleanUpRenderListener
cleanUpStrategy
private static java.util.Set<java.lang.String>
clippingPathOperators
private static byte[]
cs
private static byte[]
eoF
private static java.util.Set<java.lang.String>
eoFillOperators
private static byte[]
eoW
private static byte[]
f
private static byte[]
h
private static byte[]
l
private static java.util.Set<java.lang.String>
lineStyleOperators
private static byte[]
m
private static byte[]
n
private static java.util.Set<java.lang.String>
nwFillOperators
protected ContentOperator
originalContentOperator
private static java.util.Set<java.lang.String>
pathConstructionOperators
private static java.util.Set<java.lang.String>
pathPaintingOperators
private static byte[]
q
private static byte[]
Q
private static byte[]
S
private static java.util.Set<java.lang.String>
strokeColorOperators
private static java.util.Set<java.lang.String>
strokeOperators
private static byte[]
Tc
private static byte[]
TcTStar
private static java.util.Set<java.lang.String>
textShowingOperators
private static byte[]
TJ
private static byte[]
TStar
private static byte[]
Tw
private 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 boolean
allChunksAreVisible(java.util.List<PdfCleanUpContentChunk> chunks)
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.void
invoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral operator, java.util.ArrayList<PdfObject> operands)
Invokes a content operator.private boolean
isSpace(PdfCleanUpContentChunk.Text chunk)
static void
populateOperators(PdfContentStreamProcessor contentProcessor, PdfCleanUpRenderListener pdfCleanUpRenderListener)
private java.util.Map<java.lang.Integer,java.lang.Float>
structureTJarray(PdfArray array)
Example.private static void
toPdf(PdfObject object, PdfWriter writer, java.io.OutputStream os)
Overriding standard PdfObject.toPdf because we need sorted PdfDictionaries.private void
updateImageStream(PRStream imageStream, byte[] newData)
private void
writeBezierCurve(BezierCurve curve, PdfContentByte canvas)
private void
writeLine(Line line, PdfContentByte canvas)
private void
writeMoveTo(Point2D destinationPoint, PdfContentByte canvas)
private void
writeOperands(PdfContentByte canvas, java.util.List<PdfObject> operands)
private void
writePath(Path path, byte[] pathPaintingOperator, PdfContentByte canvas)
private void
writePath(java.lang.String operatorStr, PdfContentByte canvas, PdfName strokeColorSpace)
private void
writeStroke(PdfContentByte canvas, Path path, PdfName strokeColorSpace)
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)
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:ContentOperator
Invokes a content operator.- Specified by:
invoke
in 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.IOException
Renders 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:
BadElementException
java.io.IOException
BadPdfFormatException
-
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
-
-