Bugzilla 52078 - avoid OutOfMemoryError when rendering groupped pictures in HSLF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1293561 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2774c6717a
commit
715f7d74b4
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
while(top.getParent() != null) {
|
||||
top = top.getParent();
|
||||
lst.add(top);
|
||||
}
|
||||
|
||||
Rectangle2D clientAnchor = top.getAnchor2D();
|
||||
Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();
|
||||
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 = 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);
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user