Example usage for java.awt.geom AffineTransform rotate

List of usage examples for java.awt.geom AffineTransform rotate

Introduction

In this page you can find the example usage for java.awt.geom AffineTransform rotate.

Prototype

public void rotate(double theta, double anchorx, double anchory) 

Source Link

Document

Concatenates this transform with a transform that rotates coordinates around an anchor point.

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

/**
 *
 *//*from   w  w  w  . ja va 2 s.c o  m*/
public void exportText(JRPrintText text) throws DocumentException {
    AbstractPdfTextRenderer textRenderer = text.getLeadingOffset() == 0
            ? new PdfTextRenderer(jasperReportsContext,
                    getPropertiesUtil().getBooleanProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT))
            : new SimplePdfTextRenderer(jasperReportsContext,
                    getPropertiesUtil().getBooleanProperty(JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT)//FIXMECONTEXT replace with getPropertiesUtil in all exporters
            );//FIXMETAB optimize this

    textRenderer.initialize(this, pdfContentByte, text, getOffsetX(), getOffsetY());

    JRStyledText styledText = textRenderer.getStyledText();

    if (styledText == null) {
        return;
    }

    double angle = 0;

    switch (text.getRotationValue()) {
    case LEFT: {
        angle = Math.PI / 2;
        break;
    }
    case RIGHT: {
        angle = -Math.PI / 2;
        break;
    }
    case UPSIDE_DOWN: {
        angle = Math.PI;
        break;
    }
    case NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, textRenderer.getX(), jasperPrint.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    if (text.getModeValue() == ModeEnum.OPAQUE) {
        Color backcolor = text.getBackcolor();
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.rectangle(textRenderer.getX(), jasperPrint.getPageHeight() - textRenderer.getY(),
                textRenderer.getWidth(), -textRenderer.getHeight());
        pdfContentByte.fill();
    }

    if (styledText.length() > 0) {
        //tagHelper.startText();

        /*   */
        textRenderer.render();

        //tagHelper.endText();
    }

    atrans = new AffineTransform();
    atrans.rotate(-angle, textRenderer.getX(), jasperPrint.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    /*   */
    exportBox(text.getLineBox(), text);
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

/**
 *
 *//* ww w .j a  v a  2  s .com*/
public void exportText(JRPrintText text) throws DocumentException {
    JRStyledText styledText = styledTextUtil.getProcessedStyledText(text, noBackcolorSelector, null);

    if (styledText == null) {
        return;
    }

    AbstractPdfTextRenderer textRenderer = getTextRenderer(text, styledText);
    textRenderer.initialize(this, pdfContentByte, text, styledText, getOffsetX(), getOffsetY());

    double angle = 0;

    switch (text.getRotationValue()) {
    case LEFT: {
        angle = Math.PI / 2;
        break;
    }
    case RIGHT: {
        angle = -Math.PI / 2;
        break;
    }
    case UPSIDE_DOWN: {
        angle = Math.PI;
        break;
    }
    case NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    if (text.getModeValue() == ModeEnum.OPAQUE) {
        Color backcolor = text.getBackcolor();
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.rectangle(textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY(),
                textRenderer.getWidth(), -textRenderer.getHeight());
        pdfContentByte.fill();
    }

    if (glyphRendererAddActualText && textRenderer instanceof PdfGlyphRenderer) {
        tagHelper.startText(styledText.getText(), text.getLinkType() != null);
    } else {
        tagHelper.startText(text.getLinkType() != null);
    }

    /* rendering only non empty texts  */
    if (styledText.length() > 0) {
        textRenderer.render();
    }
    tagHelper.endText();

    atrans = new AffineTransform();
    atrans.rotate(-angle, textRenderer.getX(), pageFormat.getPageHeight() - textRenderer.getY());
    pdfContentByte.transform(atrans);

    /*   */
    exportBox(text.getLineBox(), text);
}

From source file:org.jcurl.model.PathSegmentTest.java

public void testTrafo() throws NoninvertibleTransformException {
    final Point2D x0 = new Point2D.Double(1.5, 2.5);
    // final Point2D x0 = new Point2D.Double(0, 0);
    final Point2D v0 = new Point2D.Double(2, 1);
    // build the trafo
    final AffineTransform rc2wc = new AffineTransform();
    {//from  w ww .  jav a  2s  . c o  m
        rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / v0.distance(0, 0)), x0.getX(), x0.getY());
        rc2wc.translate(x0.getX(), x0.getY());
    }
    // check some points.
    // wc(x0) -> rc(0,0)
    Point2D tmp = rc2wc.inverseTransform(x0, null);
    assertEquals("", 0, tmp.getX(), 1e-9);
    assertEquals("", 0, tmp.getY(), 1e-9);

    // rc(0,1) -> wc(x0)
    tmp = rc2wc.transform(new Point2D.Double(0, 1), null);
    assertEquals("", x0.getX() + 0.8944271909999, tmp.getX(), 1e-6);
    assertEquals("", x0.getY() + 0.4472135954999, tmp.getY(), 1e-6);
}