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 4364b1621d
commit 1d8756bf3c
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); clip = new Insets(0,0,0,0);
} }
try { BufferedImage img;
BufferedImage img = ImageIO.read(data.getPackagePart().getInputStream()); try {
int iw = img.getWidth(); img = ImageIO.read(data.getPackagePart().getInputStream());
int ih = img.getHeight(); } catch (Exception e) {
return false;
}
double aw = anchor.getWidth(); int iw = img.getWidth();
double ah = anchor.getHeight(); int ih = img.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) { double cw = (100000-clip.left-clip.right) / 100000.0;
Shape clipOld = graphics.getClip(); double ch = (100000-clip.top-clip.bottom) / 100000.0;
AffineTransform atClip = new AffineTransform(aw, 0, 0, ah, ax, ay); double sx = anchor.getWidth()/(iw*cw);
Shape clipNew = atClip.createTransformedShape(new Rectangle2D.Double(0, 0, 1, 1)); double sy = anchor.getHeight()/(ih*ch);
graphics.setClip(clipNew); double tx = anchor.getX()-(iw*sx*clip.left/100000.0);
graphics.drawRenderedImage(img, at); double ty = anchor.getY()-(ih*sy*clip.top/100000.0);
graphics.setClip(clipOld); AffineTransform at = new AffineTransform(sx, 0, 0, sy, tx, ty) ;
} else {
graphics.drawRenderedImage(img, at);
}
return true; Shape clipOld = graphics.getClip();
} catch (Exception e) { if (isClipped) graphics.clip(anchor.getBounds2D());
return false; graphics.drawRenderedImage(img, at);
} graphics.setClip(clipOld);
return true;
} }
/** /**