Search in sources :

Example 66 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class PPGraphics2D method getFontRenderContext.

/**
     * Get the rendering context of the <code>Font</code> within this
     * <code>Graphics2D</code> context.
     * The {@link FontRenderContext}
     * encapsulates application hints such as anti-aliasing and
     * fractional metrics, as well as target device specific information
     * such as dots-per-inch.  This information should be provided by the
     * application when using objects that perform typographical
     * formatting, such as <code>Font</code> and
     * <code>TextLayout</code>.  This information should also be provided
     * by applications that perform their own layout and need accurate
     * measurements of various characteristics of glyphs such as advance
     * and line height when various rendering hints have been applied to
     * the text rendering.
     *
     * @return a reference to an instance of FontRenderContext.
     * @see java.awt.font.FontRenderContext
     * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
     * @see java.awt.font.TextLayout
     * @since     JDK1.2
     */
public FontRenderContext getFontRenderContext() {
    boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
    boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));
    return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext)

Example 67 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class EscherGraphics2d method drawImage.

public boolean drawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver) {
    AffineTransform affinetransform1 = (AffineTransform) getTrans().clone();
    getTrans().concatenate(affinetransform);
    drawImage(image, 0, 0, imageobserver);
    setTrans(affinetransform1);
    return true;
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 68 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class EscherGraphics2d method drawImage.

public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y) {
    BufferedImage img = op.filter(bufferedimage, null);
    drawImage(img, new AffineTransform(1.0F, 0.0F, 0.0F, 1.0F, x, y), null);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

Example 69 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class DrawTextShape method drawContent.

@Override
public void drawContent(Graphics2D graphics) {
    DrawFactory.getInstance(graphics).fixFonts(graphics);
    TextShape<?, ?> s = getShape();
    Rectangle2D anchor = DrawShape.getAnchor(graphics, s);
    Insets2D insets = s.getInsets();
    double x = anchor.getX() + insets.left;
    double y = anchor.getY();
    // remember the initial transform
    AffineTransform tx = graphics.getTransform();
    // Transform of text in flipped shapes is special.
    // At this point the flip and rotation transform is already applied
    // (see DrawShape#applyTransform ), but we need to restore it to avoid painting "upside down".
    // See Bugzilla 54210.
    boolean vertFlip = s.getFlipVertical();
    boolean horzFlip = s.getFlipHorizontal();
    ShapeContainer<?, ?> sc = s.getParent();
    while (sc instanceof PlaceableShape) {
        PlaceableShape<?, ?> ps = (PlaceableShape<?, ?>) sc;
        vertFlip ^= ps.getFlipVertical();
        horzFlip ^= ps.getFlipHorizontal();
        sc = ps.getParent();
    }
    // Applying flip second time restores the original not-flipped transform
    if (horzFlip ^ vertFlip) {
        final double ax = anchor.getX();
        final double ay = anchor.getY();
        graphics.translate(ax + anchor.getWidth(), ay);
        graphics.scale(-1, 1);
        graphics.translate(-ax, -ay);
    }
    Double textRot = s.getTextRotation();
    if (textRot != null && textRot != 0) {
        final double cx = anchor.getCenterX();
        final double cy = anchor.getCenterY();
        graphics.translate(cx, cy);
        graphics.rotate(Math.toRadians(textRot));
        graphics.translate(-cx, -cy);
    }
    // first dry-run to calculate the total height of the text
    double textHeight;
    switch(s.getVerticalAlignment()) {
        default:
        case TOP:
            y += insets.top;
            break;
        case BOTTOM:
            textHeight = getTextHeight(graphics);
            y += anchor.getHeight() - textHeight - insets.bottom;
            break;
        case MIDDLE:
            textHeight = getTextHeight(graphics);
            double delta = anchor.getHeight() - textHeight - insets.top - insets.bottom;
            y += insets.top + delta / 2;
            break;
    }
    TextDirection textDir = s.getTextDirection();
    if (textDir == TextDirection.VERTICAL || textDir == TextDirection.VERTICAL_270) {
        final double deg = (textDir == TextDirection.VERTICAL) ? 90 : 270;
        final double cx = anchor.getCenterX();
        final double cy = anchor.getCenterY();
        graphics.translate(cx, cy);
        graphics.rotate(Math.toRadians(deg));
        graphics.translate(-cx, -cy);
        // old top/left edge is now bottom/left or top/right - as we operate on the already
        // rotated drawing context, both verticals can be moved in the same direction
        final double w = anchor.getWidth();
        final double h = anchor.getHeight();
        final double dx = (w - h) / 2d;
        graphics.translate(dx, -dx);
    }
    drawParagraphs(graphics, x, y);
    // restore the transform
    graphics.setTransform(tx);
}
Also used : TextDirection(org.apache.poi.sl.usermodel.TextShape.TextDirection) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) Insets2D(org.apache.poi.sl.usermodel.Insets2D) PlaceableShape(org.apache.poi.sl.usermodel.PlaceableShape)

Example 70 with AffineTransform

use of java.awt.geom.AffineTransform in project poi by apache.

the class SLGraphics method getFontRenderContext.

/**
     * Get the rendering context of the <code>Font</code> within this
     * <code>Graphics2D</code> context.
     * The {@link FontRenderContext}
     * encapsulates application hints such as anti-aliasing and
     * fractional metrics, as well as target device specific information
     * such as dots-per-inch.  This information should be provided by the
     * application when using objects that perform typographical
     * formatting, such as <code>Font</code> and
     * <code>TextLayout</code>.  This information should also be provided
     * by applications that perform their own layout and need accurate
     * measurements of various characteristics of glyphs such as advance
     * and line height when various rendering hints have been applied to
     * the text rendering.
     *
     * @return a reference to an instance of FontRenderContext.
     * @see java.awt.font.FontRenderContext
     * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
     * @see java.awt.font.TextLayout
     * @since     JDK1.2
     */
public FontRenderContext getFontRenderContext() {
    boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING));
    boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS));
    return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13