use of java.awt.geom.Rectangle2D in project poi by apache.
the class DrawBackground method draw.
@SuppressWarnings("rawtypes")
public void draw(Graphics2D graphics) {
Dimension pg = shape.getSheet().getSlideShow().getPageSize();
final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
PlaceableShape<?, ?> ps = new PlaceableShape() {
public ShapeContainer<?, ?> getParent() {
return null;
}
public Rectangle2D getAnchor() {
return anchor;
}
public void setAnchor(Rectangle2D newAnchor) {
}
public double getRotation() {
return 0;
}
public void setRotation(double theta) {
}
public void setFlipHorizontal(boolean flip) {
}
public void setFlipVertical(boolean flip) {
}
public boolean getFlipHorizontal() {
return false;
}
public boolean getFlipVertical() {
return false;
}
public Sheet<?, ?> getSheet() {
return shape.getSheet();
}
};
DrawFactory drawFact = DrawFactory.getInstance(graphics);
DrawPaint dp = drawFact.getPaint(ps);
Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint());
Rectangle2D anchor2 = getAnchor(graphics, anchor);
if (fill != null) {
graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, anchor);
graphics.setPaint(fill);
graphics.fill(anchor2);
}
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class DrawPaint method createRadialGradientPaint.
protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) {
Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
Point2D pCenter = new Point2D.Double(anchor.getX() + anchor.getWidth() / 2, anchor.getY() + anchor.getHeight() / 2);
float radius = (float) Math.max(anchor.getWidth(), anchor.getHeight());
float[] fractions = fill.getGradientFractions();
Color[] colors = new Color[fractions.length];
int i = 0;
for (ColorStyle fc : fill.getGradientColors()) {
colors[i++] = applyColorTransform(fc);
}
return new RadialGradientPaint(pCenter, radius, fractions, colors);
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class DrawPictureShape method resize.
/**
* Resize this picture to the default size.
*
* For PNG and JPEG resizes the image to 100%,
* for other types, if the size can't be determined it will be 200x200 pixels.
*/
public void resize() {
PictureShape<?, ?> ps = getShape();
Dimension dim = ps.getPictureData().getImageDimension();
Rectangle2D origRect = ps.getAnchor();
double x = origRect.getX();
double y = origRect.getY();
double w = dim.getWidth();
double h = dim.getHeight();
ps.setAnchor(new Rectangle2D.Double(x, y, w, h));
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class DrawPictureShape method drawContent.
@Override
public void drawContent(Graphics2D graphics) {
PictureData data = getShape().getPictureData();
if (data == null)
return;
Rectangle2D anchor = getAnchor(graphics, getShape());
Insets insets = getShape().getClipping();
try {
ImageRenderer renderer = getImageRenderer(graphics, data.getContentType());
renderer.loadImage(data.getData(), data.getContentType());
renderer.drawImage(graphics, anchor, insets);
} catch (IOException e) {
LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e);
}
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class DrawGroupShape method draw.
public void draw(Graphics2D graphics) {
// the coordinate system of this group of shape
Rectangle2D interior = getShape().getInteriorAnchor();
// anchor of this group relative to the parent shape
Rectangle2D exterior = getShape().getAnchor();
AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
AffineTransform tx0 = new AffineTransform(tx);
double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth();
double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight();
tx.translate(exterior.getX(), exterior.getY());
tx.scale(scaleX, scaleY);
tx.translate(-interior.getX(), -interior.getY());
DrawFactory drawFact = DrawFactory.getInstance(graphics);
AffineTransform at2 = graphics.getTransform();
for (Shape<?, ?> child : getShape()) {
// remember the initial transform and restore it after we are done with the drawing
AffineTransform at = graphics.getTransform();
graphics.setRenderingHint(Drawable.GSAVE, true);
Drawable draw = drawFact.getDrawable(child);
draw.applyTransform(graphics);
draw.draw(graphics);
// restore the coordinate system
graphics.setTransform(at);
graphics.setRenderingHint(Drawable.GRESTORE, true);
}
graphics.setTransform(at2);
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
}
Aggregations