From: Andreas Beeker Date: Tue, 28 Oct 2014 00:04:10 +0000 (+0000) Subject: simplified the cropping code and changed the cropping image to a more sophisticated... X-Git-Tag: REL_3_11_BETA3~32 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1d8756bf3c75f6baeb166bd40f7f8e7f68f930d9;p=poi.git 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 --- diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRenderer.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRenderer.java index b67c9fe419..6e2633515a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRenderer.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRenderer.java @@ -93,40 +93,30 @@ public class XSLFImageRenderer { clip = new Insets(0,0,0,0); } - try { - BufferedImage img = ImageIO.read(data.getPackagePart().getInputStream()); - int iw = img.getWidth(); - int ih = img.getHeight(); + BufferedImage img; + try { + img = ImageIO.read(data.getPackagePart().getInputStream()); + } catch (Exception e) { + return false; + } - 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) ; + int iw = img.getWidth(); + int ih = img.getHeight(); - 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); - } + 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) ; - return true; - } catch (Exception e) { - return false; - } + Shape clipOld = graphics.getClip(); + if (isClipped) graphics.clip(anchor.getBounds2D()); + graphics.drawRenderedImage(img, at); + graphics.setClip(clipOld); + return true; } /** diff --git a/test-data/slideshow/54542_cropped_bitmap.pptx b/test-data/slideshow/54542_cropped_bitmap.pptx index eb3e2339a3..b8d960c005 100644 Binary files a/test-data/slideshow/54542_cropped_bitmap.pptx and b/test-data/slideshow/54542_cropped_bitmap.pptx differ