]> source.dussan.org Git - poi.git/commitdiff
Bugzilla 52078 - avoid OutOfMemoryError when rendering groupped pictures in HSLF
authorYegor Kozlov <yegor@apache.org>
Sat, 25 Feb 2012 09:40:16 +0000 (09:40 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 25 Feb 2012 09:40:16 +0000 (09:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1293561 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java

index 57161cd5ae9b0ceb859a3406e95c6986de602cb0..45a875eb1fe06a6d7ef0dae51bbe8296eaabe27b 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">52078 - avoid OutOfMemoryError when rendering groupped pictures in HSLF </action>
            <action dev="poi-developers" type="fix">52745 - fixed XSSFRichtextString.append to preserve leading / trailing spaces </action>
            <action dev="poi-developers" type="fix">52716 - tolerate hyperlinks that have neither location nor relation </action>
            <action dev="poi-developers" type="fix">52599 - avoid duplicate text when rendering slides in HSLF</action>
index b9ba597115a6412a0eaf1cc84e404c9e5310e813..56f1dea44ca69311dd27051d1a7bfd9c1091a5d4 100644 (file)
@@ -40,6 +40,8 @@ import org.apache.poi.util.POILogFactory;
 ==================================================================== */
 import javax.imageio.ImageIO;
 import java.awt.*;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
 
@@ -60,9 +62,9 @@ public final class BitmapPainter implements ImagePainter {
             logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + pict.getType());
             return;
         }
-        Rectangle anchor = parent.getAnchor();
-        Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
-        graphics.drawImage(scaledImg, anchor.x, anchor.y, null);
+
+        Rectangle anchor = parent.getLogicalAnchor2D().getBounds();
+        graphics.drawImage(img, anchor.x, anchor.y, anchor.width, anchor.height, null);
     }
 
 }
index 3f7ce7cb3110cc2934a9422f1c63c6303c9c55e5..672b191aaaa8f95aaec8ac26de50cc6fb54ddc6b 100644 (file)
@@ -22,6 +22,8 @@ import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.poi.ddf.*;
 import org.apache.poi.ddf.EscherSpRecord;
@@ -246,27 +248,37 @@ public abstract class SimpleShape extends Shape {
         setEscherProperty(EscherProperties.TRANSFORM__ROTATION, (theta << 16));
     }
 
+    /**
+     *
+     * @return 'absolute' anchor of this shape relative to the parent sheet
+     */
     public Rectangle2D getLogicalAnchor2D(){
         Rectangle2D anchor = getAnchor2D();
 
         //if it is a groupped shape see if we need to transform the coordinates
         if (_parent != null){
+            List<Shape> lst = new ArrayList<Shape>();
+            lst.add(_parent);
             Shape top = _parent;
-            while(top.getParent() != null) top = top.getParent();
-
-            Rectangle2D clientAnchor = top.getAnchor2D();
-            Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();
-
-            double scalex = spgrAnchor.getWidth()/clientAnchor.getWidth();
-            double scaley = spgrAnchor.getHeight()/clientAnchor.getHeight();
+            while(top.getParent() != null) {
+                top = top.getParent();
+                lst.add(top);
+            }
 
-            double x = clientAnchor.getX() + (anchor.getX() - spgrAnchor.getX())/scalex;
-            double y = clientAnchor.getY() + (anchor.getY() - spgrAnchor.getY())/scaley;
-            double width = anchor.getWidth()/scalex;
-            double height = anchor.getHeight()/scaley;
+            AffineTransform tx = new AffineTransform();
+            for(int i = lst.size() - 1; i >= 0; i--) {
+                ShapeGroup prnt = (ShapeGroup)lst.get(i);
+                Rectangle2D exterior = prnt.getAnchor2D();
+                Rectangle2D interior = prnt.getCoordinates();
 
-            anchor = new Rectangle2D.Double(x, y, width, height);
+                double scaleX =  exterior.getWidth() / interior.getWidth();
+                double scaleY = exterior.getHeight() / interior.getHeight();
 
+                tx.translate(exterior.getX(), exterior.getY());
+                tx.scale(scaleX, scaleY);
+                tx.translate(-interior.getX(), -interior.getY());
+            }
+            anchor = tx.createTransformedShape(anchor).getBounds2D();
         }
 
         int angle = getRotation();