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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations