/** * {@inheritDoc} */ public void invoke(PdfCanvasProcessor processor, PdfLiteral operator, List<PdfObject> operands) { processor.textMatrix = new Matrix(); processor.textLineMatrix = processor.textMatrix; processor.beginText(); } }
/** * Subtracts a matrix from this matrix and returns the results * @param arg the matrix to subtract from this matrix * @return a Matrix object */ public Matrix subtract(Matrix arg){ Matrix rslt = new Matrix(); float[] a = vals; float[] b = arg.vals; float[] c = rslt.vals; c[I11] = a[I11]-b[I11]; c[I12] = a[I12]-b[I12]; c[I13] = a[I13]-b[I13]; c[I21] = a[I21]-b[I21]; c[I22] = a[I22]-b[I22]; c[I23] = a[I23]-b[I23]; c[I31] = a[I31]-b[I31]; c[I32] = a[I32]-b[I32]; c[I33] = a[I33]-b[I33]; return rslt; }
/** * adds a matrix from this matrix and returns the results * @param arg the matrix to subtract from this matrix * @return a Matrix object */ public Matrix add(Matrix arg){ Matrix rslt = new Matrix(); float[] a = vals; float[] b = arg.vals; float[] c = rslt.vals; c[I11] = a[I11]+b[I11]; c[I12] = a[I12]+b[I12]; c[I13] = a[I13]+b[I13]; c[I21] = a[I21]+b[I21]; c[I22] = a[I22]+b[I22]; c[I23] = a[I23]+b[I23]; c[I31] = a[I31]+b[I31]; c[I32] = a[I32]+b[I32]; c[I33] = a[I33]+b[I33]; return rslt; }
/** * multiplies this matrix by 'b' and returns the result * See http://en.wikipedia.org/wiki/Matrix_multiplication * @param by The matrix to multiply by * @return the resulting matrix */ public Matrix multiply(Matrix by){ Matrix rslt = new Matrix(); float[] a = vals; float[] b = by.vals; float[] c = rslt.vals; c[I11] = a[I11]*b[I11] + a[I12]*b[I21] + a[I13]*b[I31]; c[I12] = a[I11]*b[I12] + a[I12]*b[I22] + a[I13]*b[I32]; c[I13] = a[I11]*b[I13] + a[I12]*b[I23] + a[I13]*b[I33]; c[I21] = a[I21]*b[I11] + a[I22]*b[I21] + a[I23]*b[I31]; c[I22] = a[I21]*b[I12] + a[I22]*b[I22] + a[I23]*b[I32]; c[I23] = a[I21]*b[I13] + a[I22]*b[I23] + a[I23]*b[I33]; c[I31] = a[I31]*b[I11] + a[I32]*b[I21] + a[I33]*b[I31]; c[I32] = a[I31]*b[I12] + a[I32]*b[I22] + a[I33]*b[I32]; c[I33] = a[I31]*b[I13] + a[I32]*b[I23] + a[I33]*b[I33]; return rslt; }
/** * Updates current transformation matrix. */ public void updateCtm(float a, float b, float c, float d, float e, float f) { updateCtm(new Matrix(a, b, c, d, e, f)); }
/** * {@inheritDoc} */ public void invoke(PdfCanvasProcessor processor, PdfLiteral operator, List<PdfObject> operands) { float tx = ((PdfNumber) operands.get(0)).floatValue(); float ty = ((PdfNumber) operands.get(1)).floatValue(); Matrix translationMatrix = new Matrix(tx, ty); processor.textMatrix = translationMatrix.multiply(processor.textLineMatrix); processor.textLineMatrix = processor.textMatrix; } }
/** * {@inheritDoc} */ public void invoke(PdfCanvasProcessor processor, PdfLiteral operator, List<PdfObject> operands) { float a = ((PdfNumber) operands.get(0)).floatValue(); float b = ((PdfNumber) operands.get(1)).floatValue(); float c = ((PdfNumber) operands.get(2)).floatValue(); float d = ((PdfNumber) operands.get(3)).floatValue(); float e = ((PdfNumber) operands.get(4)).floatValue(); float f = ((PdfNumber) operands.get(5)).floatValue(); processor.textLineMatrix = new Matrix(a, b, c, d, e, f); processor.textMatrix = processor.textLineMatrix; } }
/** * {@inheritDoc} */ public void invoke(PdfCanvasProcessor processor, PdfLiteral operator, List<PdfObject> operands) { float a = ((PdfNumber) operands.get(0)).floatValue(); float b = ((PdfNumber) operands.get(1)).floatValue(); float c = ((PdfNumber) operands.get(2)).floatValue(); float d = ((PdfNumber) operands.get(3)).floatValue(); float e = ((PdfNumber) operands.get(4)).floatValue(); float f = ((PdfNumber) operands.get(5)).floatValue(); Matrix matrix = new Matrix(a, b, c, d, e, f); processor.getGraphicsState().updateCtm(matrix); } }
/** * Used for creating sub-TextRenderInfos for each individual character * * @param parent the parent TextRenderInfo * @param str the content of a TextRenderInfo * @param horizontalOffset the unscaled horizontal offset of the character that this TextRenderInfo represents */ private TextRenderInfo(TextRenderInfo parent, PdfString str, float horizontalOffset) { super(parent.gs); this.string = str; Matrix offsetMatrix = new Matrix(horizontalOffset, 0); this.textToUserSpaceTransformMatrix = offsetMatrix.multiply(parent.textToUserSpaceTransformMatrix); this.textMatrix = offsetMatrix.multiply(parent.textMatrix); this.canvasTagHierarchy = parent.canvasTagHierarchy; this.fontMatrix = parent.gs.getFont().getFontMatrix(); }
/** * Adjusts the text matrix for the specified adjustment value (see TJ operator in the PDF spec for information) * * @param tj the text adjustment */ private void applyTextAdjust(float tj) { float adjustBy = -tj / 1000f * getGraphicsState().getFontSize() * (getGraphicsState().getHorizontalScaling() / 100f); textMatrix = new Matrix(adjustBy, 0).multiply(textMatrix); }
/** * Displays text. * * @param string the text to display */ private void displayPdfString(PdfString string) { TextRenderInfo renderInfo = new TextRenderInfo(string, getGraphicsState(), textMatrix, markedContentStack); textMatrix = new Matrix(renderInfo.getUnscaledWidth(), 0).multiply(textMatrix); eventOccurred(renderInfo, EventType.RENDER_TEXT); }
if (renderInfo.getRise() != 0) { Matrix riseOffsetTransform = new Matrix(0, -renderInfo.getRise()); segment = segment.transformBy(riseOffsetTransform);
public void handleXObject(PdfCanvasProcessor processor, Stack<CanvasTag> canvasTagHierarchy, PdfStream xObjectStream, PdfName xObjectName) { PdfDictionary resourcesDic = xObjectStream.getAsDictionary(PdfName.Resources); PdfResources resources; if (resourcesDic == null) { resources = processor.getResources(); } else { resources = new PdfResources(resourcesDic); } // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted // this is probably not necessary (if we fail on this, probably the entire content stream processing // operation should be rejected byte[] contentBytes; contentBytes = xObjectStream.getBytes(); final PdfArray matrix = xObjectStream.getAsArray(PdfName.Matrix); new PushGraphicsStateOperator().invoke(processor, null, null); if (matrix != null) { float a = matrix.getAsNumber(0).floatValue(); float b = matrix.getAsNumber(1).floatValue(); float c = matrix.getAsNumber(2).floatValue(); float d = matrix.getAsNumber(3).floatValue(); float e = matrix.getAsNumber(4).floatValue(); float f = matrix.getAsNumber(5).floatValue(); Matrix formMatrix = new Matrix(a, b, c, d, e, f); processor.getGraphicsState().updateCtm(formMatrix); } processor.processContent(contentBytes, resources); new PopGraphicsStateOperator().invoke(processor, null, null); } }
Matrix currentMatrix = new Matrix(matrix.getAsNumber(0).floatValue(), matrix.getAsNumber(1).floatValue(), matrix.getAsNumber(2).floatValue(), matrix.getAsNumber(3).floatValue(), matrix.getAsNumber(4).floatValue(), matrix.getAsNumber(5).floatValue()); Matrix toConcatenate = new Matrix((float) Math.cos(angle), (float) (-Math.sin(angle)), (float) (Math.sin(angle)), (float) (Math.cos(angle)), (float) translationWidth, (float) translationHeight); currentMatrix = currentMatrix.multiply(toConcatenate); matrix = new PdfArray(new float[]{currentMatrix.get(0), currentMatrix.get(1), currentMatrix.get(3), currentMatrix.get(4), currentMatrix.get(6), currentMatrix.get(7)});
Matrix currentMatrix = new Matrix(matrix.getAsNumber(0).floatValue(), matrix.getAsNumber(1).floatValue(), matrix.getAsNumber(2).floatValue(), matrix.getAsNumber(3).floatValue(), matrix.getAsNumber(4).floatValue(), matrix.getAsNumber(5).floatValue()); Matrix toConcatenate = new Matrix((float) Math.cos(angle), (float) (-Math.sin(angle)), (float) (Math.sin(angle)), (float) (Math.cos(angle)), (float) translationWidth, (float) translationHeight); currentMatrix = currentMatrix.multiply(toConcatenate); matrix = new PdfArray(new float[]{currentMatrix.get(0), currentMatrix.get(1), currentMatrix.get(3), currentMatrix.get(4), currentMatrix.get(6), currentMatrix.get(7)});