/** * Add a counter-clockwise rotation to this transformation * * @param angle angle in radians to rotate over */ public void rotate(double angle) { concatenate(AffineTransform.getRotateInstance(angle)); }
/** * Add a counter-clockwise rotation to this transformation, * using the passed point as the center of rotation * @param angle angle in radians to rotate over * @param px x-coordinate of center of rotation * @param py y-coordinate of center of rotation */ public void rotate(double angle, double px, double py) { concatenate(AffineTransform.getRotateInstance(angle, px, py)); }
public void translate(double mx, double my) { concatenate(AffineTransform.getTranslateInstance(mx, my)); }
public void scale(double scx, double scy) { concatenate(AffineTransform.getScaleInstance(scx, scy)); }
public void shear(double shx, double shy) { concatenate(AffineTransform.getShearInstance(shx, shy)); }
AffineTransform calculateTransformation(SvgDrawContext context){ Rectangle viewPort = context.getCurrentViewPort(); float horizontal = viewPort.getX(); float vertical = viewPort.getY() + viewPort.getHeight(); // flip coordinate space vertically and translate on the y axis with the viewport height AffineTransform transform = AffineTransform.getTranslateInstance(0,0); //Identity-transform transform.concatenate(AffineTransform.getTranslateInstance(horizontal,vertical)); transform.concatenate(new AffineTransform(1,0,0,-1,0,0)); return transform; }
/** * Converts a string containing a transform declaration into an AffineTransform object. * This class only supports the transformations as described in the SVG specification: * - matrix * - translate * - skewx * - skewy * - rotate * - scale * * @param transform value to be parsed * @return the AffineTransform object */ public static AffineTransform parseTransform(String transform) { if (transform == null) { throw new SvgProcessingException(SvgLogMessageConstant.TRANSFORM_NULL); } if (transform.isEmpty()) { throw new SvgProcessingException(SvgLogMessageConstant.TRANSFORM_EMPTY); } AffineTransform matrix = new AffineTransform(); List<String> listWithTransformations = splitString(transform); for (String transformation : listWithTransformations) { AffineTransform newMatrix = transformationStringToMatrix(transformation); if (newMatrix != null) { matrix.concatenate(newMatrix); } } return matrix; }
@Override public void drawBackground(DrawContext drawContext) { PdfCanvas canvas = drawContext.getCanvas(); Matrix ctm = canvas.getGraphicsState().getCtm(); // Avoid rotation Float angle = this.getPropertyAsFloat(Property.ROTATION_ANGLE); boolean avoidRotation = null != angle && hasProperty(Property.BACKGROUND); boolean restoreRotation = hasOwnProperty(Property.ROTATION_ANGLE); if (avoidRotation) { AffineTransform transform = new AffineTransform(ctm.get(0), ctm.get(1), ctm.get(3), ctm.get(4), ctm.get(6), ctm.get(7)); try { transform = transform.createInverse(); } catch (NoninvertibleTransformException e) { throw new RuntimeException(e.getMessage(), e); } transform.concatenate(new AffineTransform()); canvas.concatMatrix(transform); setProperty(Property.ROTATION_ANGLE, null); } super.drawBackground(drawContext); // restore concat matrix and rotation angle if (avoidRotation) { if (restoreRotation) { setProperty(Property.ROTATION_ANGLE, angle); } else { deleteOwnProperty(Property.ROTATION_ANGLE); } canvas.concatMatrix(new AffineTransform(ctm.get(0), ctm.get(1), ctm.get(3), ctm.get(4), ctm.get(6), ctm.get(7))); } }
@Override public void drawBackground(DrawContext drawContext) { PdfCanvas canvas = drawContext.getCanvas(); Matrix ctm = canvas.getGraphicsState().getCtm(); // Avoid rotation Float angle = this.getPropertyAsFloat(Property.ROTATION_ANGLE); boolean avoidRotation = null != angle && hasProperty(Property.BACKGROUND); boolean restoreRotation = hasOwnProperty(Property.ROTATION_ANGLE); if (avoidRotation) { AffineTransform transform = new AffineTransform(ctm.get(0), ctm.get(1), ctm.get(3), ctm.get(4), ctm.get(6), ctm.get(7)); try { transform = transform.createInverse(); } catch (NoninvertibleTransformException e) { throw new RuntimeException(e.getMessage(), e); } transform.concatenate(new AffineTransform()); canvas.concatMatrix(transform); setProperty(Property.ROTATION_ANGLE, null); } super.drawBackground(drawContext); // restore concat matrix and rotation angle if (avoidRotation) { if (restoreRotation) { setProperty(Property.ROTATION_ANGLE, angle); } else { deleteOwnProperty(Property.ROTATION_ANGLE); } canvas.concatMatrix(new AffineTransform(ctm.get(0), ctm.get(1), ctm.get(3), ctm.get(4), ctm.get(6), ctm.get(7))); } }