@Override public Matrix getFontMatrix() { if (fontMatrix == null) { // 1000 upem, this is not strictly true fontMatrix = new Matrix(0.001f, 0, 0, 0.001f, 0, 0); } return fontMatrix; }
@Override public Matrix getMatrix() { // todo: take into account user-space unit redefinition as scale? return new Matrix(); }
/** * Convenience method to create a translating instance. * * @param tx The x translating operator. * @param ty The y translating operator. * @return A new matrix with just the x/y translating. */ public static Matrix getTranslateInstance(float tx, float ty) { Matrix matrix = new Matrix(); matrix.single[6] = tx; matrix.single[7] = ty; return matrix; }
/** * Convenience method to create a scaled instance. * * @param sx The xscale operator. * @param sy The yscale operator. * @return A new matrix with just the x/y scaling */ public static Matrix getScaleInstance(float sx, float sy) { Matrix matrix = new Matrix(); matrix.single[0] = sx; matrix.single[4] = sy; return matrix; }
/** * Clones this object. * @return cloned matrix as an object. */ @Override public Matrix clone() { Matrix clone = new Matrix(); System.arraycopy( single, 0, clone.single, 0, 9 ); return clone; }
/** * Create a new matrix with just the scaling operators. * * @return A new matrix with just the scaling operators. * @deprecated This method is due to be removed, please contact us if you make use of it. */ @Deprecated public Matrix extractScaling() { Matrix matrix = new Matrix(); matrix.single[0] = this.single[0]; matrix.single[4] = this.single[4]; return matrix; }
/** * Create a new matrix with just the translating operators. * * @return A new matrix with just the translating operators. * @deprecated This method is due to be removed, please contact us if you make use of it. */ @Deprecated public Matrix extractTranslating() { Matrix matrix = new Matrix(); matrix.single[6] = this.single[6]; matrix.single[7] = this.single[7]; return matrix; }
/** * The Tm operator. Sets the text matrix to the given values. * A current text matrix will be replaced with the new one. * @param matrix the transformation matrix * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #setTextMatrix(Matrix)} instead. */ @Deprecated public void setTextMatrix(AffineTransform matrix) throws IOException { setTextMatrix(new Matrix(matrix)); }
/** * The cm operator. Concatenates the current transformation matrix with the given * {@link AffineTransform}. * @param at the transformation matrix * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #transform} instead. */ @Deprecated public void concatenate2CTM(AffineTransform at) throws IOException { transform(new Matrix(at)); }
/** * This will take the current matrix and multiply it with a matrix that is passed in. * * @param b The matrix to multiply by. * * @return The result of the two multiplied matrices. */ public Matrix multiply( Matrix b ) { return this.multiply(b, new Matrix()); }
/** * The Tm operator. Sets the text matrix to the given scaling and translation values. * A current text matrix will be replaced with the new one. * @param sx The scaling factor in x-direction. * @param sy The scaling factor in y-direction. * @param tx The translation value in x-direction. * @param ty The translation value in y-direction. * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #setTextMatrix(Matrix)} instead. */ @Deprecated public void setTextScaling(double sx, double sy, double tx, double ty) throws IOException { setTextMatrix(new Matrix((float) sx, 0f, 0f, (float) sy, (float) tx, (float) ty)); }
/** * The cm operator. Concatenates the current transformation matrix with the given values. * @param a The a value of the matrix. * @param b The b value of the matrix. * @param c The c value of the matrix. * @param d The d value of the matrix. * @param e The e value of the matrix. * @param f The f value of the matrix. * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #transform} instead. */ @Deprecated public void concatenate2CTM(double a, double b, double c, double d, double e, double f) throws IOException { transform(new Matrix((float) a, (float) b, (float) c, (float) d, (float) e, (float) f)); }
/** * The Tm operator. Sets the text matrix to the given values. * A current text matrix will be replaced with the new one. * @param a The a value of the matrix. * @param b The b value of the matrix. * @param c The c value of the matrix. * @param d The d value of the matrix. * @param e The e value of the matrix. * @param f The f value of the matrix. * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #setTextMatrix(Matrix)} instead. */ @Deprecated public void setTextMatrix(double a, double b, double c, double d, double e, double f) throws IOException { setTextMatrix(new Matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f)); }
private void adjustRectangle(Rectangle2D r) { Matrix m = new Matrix(xform); double scaleX = Math.abs(m.getScalingFactorX()); double scaleY = Math.abs(m.getScalingFactorY()); AffineTransform adjustedTransform = new AffineTransform(xform); adjustedTransform.scale(1.0 / scaleX, 1.0 / scaleY); r.setRect(adjustedTransform.createTransformedShape(r).getBounds2D()); }
private BufferedImage adjustImage(BufferedImage gray) throws IOException { AffineTransform at = new AffineTransform(xform); Matrix m = new Matrix(at); at.scale(1.0 / Math.abs(m.getScalingFactorX()), 1.0 / Math.abs(m.getScalingFactorY())); Rectangle originalBounds = new Rectangle(gray.getWidth(), gray.getHeight()); Rectangle2D transformedBounds = at.createTransformedShape(originalBounds).getBounds2D(); at.preConcatenate(AffineTransform.getTranslateInstance(-transformedBounds.getMinX(), -transformedBounds.getMinY())); int width = (int) Math.ceil(transformedBounds.getWidth()); int height = (int) Math.ceil(transformedBounds.getHeight()); BufferedImage transformedGray = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2 = (Graphics2D) transformedGray.getGraphics(); g2.drawImage(gray, at, null); g2.dispose(); return transformedGray; }
public Rectangle2D getBounds() { Point2D size = new Point2D.Double(pageSize.getWidth(), pageSize.getHeight()); // apply the underlying Graphics2D device's DPI transform and y-axis flip Matrix m = new Matrix(xform); AffineTransform dpiTransform = AffineTransform.getScaleInstance(Math.abs(m.getScalingFactorX()), Math.abs(m.getScalingFactorY())); size = dpiTransform.transform(size, size); // Flip y return new Rectangle2D.Double(minX - pageSize.getLowerLeftX() * Math.abs(m.getScalingFactorX()), size.getY() - minY - height + pageSize.getLowerLeftY() * Math.abs(m.getScalingFactorY()), width, height); } }
@Override public Matrix getFontMatrix() { if (fontMatrix == null) { COSBase base = dict.getDictionaryObject(COSName.FONT_MATRIX); if (base instanceof COSArray) { fontMatrix = new Matrix((COSArray) base); } else { return super.getFontMatrix(); } } return fontMatrix; }
@Override public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException { if (arguments.size() < 6) { throw new MissingOperandException(operator, arguments); } if (!checkArrayTypesClass(arguments, COSNumber.class)) { return; } 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 ); Matrix matrix = new Matrix(a.floatValue(), b.floatValue(), c.floatValue(), d.floatValue(), e.floatValue(), f.floatValue()); context.setTextMatrix(matrix); context.setTextLineMatrix(matrix.clone()); }
/** * Draw an image at the origin with the given transformation matrix. * * @param image The image to draw. * @param matrix The transformation matrix to apply to the image. * * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was called within a text block. */ public void drawImage(PDImageXObject image, Matrix matrix) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawImage is not allowed within a text block."); } saveGraphicsState(); AffineTransform transform = matrix.createAffineTransform(); transform(new Matrix(transform)); writeOperand(resources.add(image)); writeOperator("Do"); restoreGraphicsState(); }