simplified the cropping code and changed the cropping image to a more sophisticated one - interesting enough, it's rendered correct in POI (like in Powerpoint), but malformed in LO

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1634749 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-10-28 00:04:10 +00:00
parent d59c8f47be
commit 5dcf6b1a29
2 changed files with 20 additions and 30 deletions

View File

@ -93,40 +93,30 @@ public class XSLFImageRenderer {
clip = new Insets(0,0,0,0);
}
BufferedImage img;
try {
BufferedImage img = ImageIO.read(data.getPackagePart().getInputStream());
int iw = img.getWidth();
int ih = img.getHeight();
double aw = anchor.getWidth();
double ah = anchor.getHeight();
double ax = anchor.getX();
double ay = anchor.getY();
double cw = (100000-clip.left-clip.right) / 100000.0;
double ch = (100000-clip.top-clip.bottom) / 100000.0;
double sx = aw/(iw*cw);
double sy = ah/(ih*ch);
double tx = anchor.getX()-(iw*sx*clip.left/100000.0);
double ty = anchor.getY()-(ih*sy*clip.top/100000.0);
AffineTransform at = new AffineTransform(sx, 0, 0, sy, tx, ty) ;
if (isClipped) {
Shape clipOld = graphics.getClip();
AffineTransform atClip = new AffineTransform(aw, 0, 0, ah, ax, ay);
Shape clipNew = atClip.createTransformedShape(new Rectangle2D.Double(0, 0, 1, 1));
graphics.setClip(clipNew);
graphics.drawRenderedImage(img, at);
graphics.setClip(clipOld);
} else {
graphics.drawRenderedImage(img, at);
}
return true;
img = ImageIO.read(data.getPackagePart().getInputStream());
} catch (Exception e) {
return false;
}
int iw = img.getWidth();
int ih = img.getHeight();
double cw = (100000-clip.left-clip.right) / 100000.0;
double ch = (100000-clip.top-clip.bottom) / 100000.0;
double sx = anchor.getWidth()/(iw*cw);
double sy = anchor.getHeight()/(ih*ch);
double tx = anchor.getX()-(iw*sx*clip.left/100000.0);
double ty = anchor.getY()-(ih*sy*clip.top/100000.0);
AffineTransform at = new AffineTransform(sx, 0, 0, sy, tx, ty) ;
Shape clipOld = graphics.getClip();
if (isClipped) graphics.clip(anchor.getBounds2D());
graphics.drawRenderedImage(img, at);
graphics.setClip(clipOld);
return true;
}
/**