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:
parent
d59c8f47be
commit
5dcf6b1a29
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user