poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1293561 - in /poi/trunk/src: documentation/content/xdocs/status.xml scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
Date Sat, 25 Feb 2012 09:40:16 GMT
Author: yegor
Date: Sat Feb 25 09:40:16 2012
New Revision: 1293561

URL: http://svn.apache.org/viewvc?rev=1293561&view=rev
Log:
Bugzilla 52078 - avoid OutOfMemoryError when rendering groupped pictures in HSLF 

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

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1293561&r1=1293560&r2=1293561&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sat Feb 25 09:40:16 2012
@@ -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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java?rev=1293561&r1=1293560&r2=1293561&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java Sat Feb 25 09:40:16
2012
@@ -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 impleme
             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);
     }
 
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java?rev=1293561&r1=1293560&r2=1293561&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java Sat Feb 25 09:40:16
2012
@@ -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 extend
         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();
-
-            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;
-
-            anchor = new Rectangle2D.Double(x, y, width, height);
+            while(top.getParent() != null) {
+                top = top.getParent();
+                lst.add(top);
+            }
 
+            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();
+
+                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();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message