aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-11-21 15:54:01 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-11-21 15:54:01 +0000
commit74d58c8bde9a00b9b3695665c3b7b12fe2a262f1 (patch)
tree301ba43b27f2f3a08c0ca004d205cfa55b925644 /src/scratchpad
parent4f2692f87071bc60480e1475246acdb68da02928 (diff)
downloadpoi-74d58c8bde9a00b9b3695665c3b7b12fe2a262f1.tar.gz
poi-74d58c8bde9a00b9b3695665c3b7b12fe2a262f1.zip
In preparation for table rendering, added table row heights and column widths to common sl.
To have better results in rendering switch anchor from java.awt.Rectangle to Rectangle2D. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715540 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java3
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java74
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java6
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java20
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java14
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java91
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java42
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java11
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java4
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java42
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java56
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java43
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java8
13 files changed, 239 insertions, 175 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java
index 0c21c7e8b8..dde778ffcc 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java
@@ -17,7 +17,6 @@
package org.apache.poi.hslf.usermodel;
-import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
@@ -90,7 +89,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
@Override
public int setPath(GeneralPath path) {
- Rectangle bounds = path.getBounds();
+ Rectangle2D bounds = path.getBounds2D();
PathIterator it = path.getPathIterator(new AffineTransform());
List<byte[]> segInfo = new ArrayList<byte[]>();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
index bbfe93f97c..bae325a0f9 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
@@ -17,7 +17,7 @@
package org.apache.poi.hslf.usermodel;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -73,7 +73,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
}
@Override
- public void setAnchor(Rectangle anchor) {
+ public void setAnchor(Rectangle2D anchor) {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
boolean isInitialized = !(clientAnchor.getDx1() == 0 && clientAnchor.getRow1() == 0);
@@ -85,7 +85,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
}
@Override
- public void setInteriorAnchor(Rectangle anchor){
+ public void setInteriorAnchor(Rectangle2D anchor){
EscherSpgrRecord spgr = getEscherChild(EscherSpgrRecord.RECORD_ID);
int x1 = Units.pointsToMaster(anchor.getX());
@@ -100,16 +100,16 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
}
@Override
- public Rectangle getInteriorAnchor(){
+ public Rectangle2D getInteriorAnchor(){
EscherSpgrRecord rec = getEscherChild(EscherSpgrRecord.RECORD_ID);
- int x1 = (int)Units.masterToPoints(rec.getRectX1());
- int y1 = (int)Units.masterToPoints(rec.getRectY1());
- int x2 = (int)Units.masterToPoints(rec.getRectX2());
- int y2 = (int)Units.masterToPoints(rec.getRectY2());
- return new Rectangle(x1,y1,x2-x1,y2-y1);
+ double x1 = Units.masterToPoints(rec.getRectX1());
+ double y1 = Units.masterToPoints(rec.getRectY1());
+ double x2 = Units.masterToPoints(rec.getRectX2());
+ double y2 = Units.masterToPoints(rec.getRectY2());
+ return new Rectangle2D.Double(x1,y1,x2-x1,y2-y1);
}
- protected void setExteriorAnchor(Rectangle anchor) {
+ protected void setExteriorAnchor(Rectangle2D anchor) {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
@@ -121,10 +121,10 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
clientAnchor.fillFields(header, 0, null);
// All coordinates need to be converted to Master units (576 dpi)
- clientAnchor.setFlag((short)Units.pointsToMaster(anchor.y));
- clientAnchor.setCol1((short)Units.pointsToMaster(anchor.x));
- clientAnchor.setDx1((short)Units.pointsToMaster(anchor.width + anchor.x));
- clientAnchor.setRow1((short)Units.pointsToMaster(anchor.height + anchor.y));
+ clientAnchor.setFlag((short)Units.pointsToMaster(anchor.getY()));
+ clientAnchor.setCol1((short)Units.pointsToMaster(anchor.getX()));
+ clientAnchor.setDx1((short)Units.pointsToMaster(anchor.getWidth() + anchor.getX()));
+ clientAnchor.setRow1((short)Units.pointsToMaster(anchor.getHeight() + anchor.getY()));
// TODO: does this make sense?
setInteriorAnchor(anchor);
@@ -177,20 +177,20 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
/**
* Moves and scales this <code>ShapeGroup</code> to the specified anchor.
*/
- protected void moveAndScale(Rectangle anchorDest){
- Rectangle anchorSrc = getAnchor();
- double scaleX = (anchorSrc.width == 0) ? 0 : anchorDest.width / (double)anchorSrc.width;
- double scaleY = (anchorSrc.height == 0) ? 0 : anchorDest.height / (double)anchorSrc.height;
+ protected void moveAndScale(Rectangle2D anchorDest){
+ Rectangle2D anchorSrc = getAnchor();
+ double scaleX = (anchorSrc.getWidth() == 0) ? 0 : anchorDest.getWidth() / anchorSrc.getWidth();
+ double scaleY = (anchorSrc.getHeight() == 0) ? 0 : anchorDest.getHeight() / anchorSrc.getHeight();
setExteriorAnchor(anchorDest);
for (HSLFShape shape : getShapes()) {
- Rectangle chanchor = shape.getAnchor();
- int x = (int)Math.rint(anchorDest.x+(chanchor.x-anchorSrc.x)*scaleX);
- int y = (int)Math.rint(anchorDest.y+(chanchor.y-anchorSrc.y)*scaleY);
- int width = (int)Math.rint(chanchor.width*scaleX);
- int height = (int)Math.rint(chanchor.height*scaleY);
- shape.setAnchor(new Rectangle(x, y, width, height));
+ Rectangle2D chanchor = shape.getAnchor();
+ double x = anchorDest.getX()+(chanchor.getX()-anchorSrc.getX())*scaleX;
+ double y = anchorDest.getY()+(chanchor.getY()-anchorSrc.getY())*scaleY;
+ double width = chanchor.getWidth()*scaleX;
+ double height = chanchor.getHeight()*scaleY;
+ shape.setAnchor(new Rectangle2D.Double(x, y, width, height));
}
}
@@ -200,7 +200,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
*
* @return the anchor of this shape group
*/
- public Rectangle getAnchor(){
+ public Rectangle2D getAnchor(){
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
int x1,y1,x2,y2;
if(clientAnchor == null){
@@ -216,11 +216,11 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
x2 = clientAnchor.getDx1();
y2 = clientAnchor.getRow1();
}
- Rectangle anchor= new Rectangle(
- (int)(x1 == -1 ? -1 : Units.masterToPoints(x1)),
- (int)(y1 == -1 ? -1 : Units.masterToPoints(y1)),
- (int)(x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
- (int)(y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
+ Rectangle2D anchor= new Rectangle2D.Double(
+ (x1 == -1 ? -1 : Units.masterToPoints(x1)),
+ (y1 == -1 ? -1 : Units.masterToPoints(y1)),
+ (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
+ (y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
);
return anchor;
@@ -295,7 +295,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
public HSLFTextBox createTextBox() {
HSLFTextBox s = new HSLFTextBox(this);
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -304,7 +304,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
public HSLFAutoShape createAutoShape() {
HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT, this);
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -313,7 +313,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
public HSLFFreeformShape createFreeform() {
HSLFFreeformShape s = new HSLFFreeformShape(this);
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -321,7 +321,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
@Override
public HSLFConnectorShape createConnector() {
HSLFConnectorShape s = new HSLFConnectorShape(this);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -329,7 +329,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
@Override
public HSLFGroupShape createGroup() {
HSLFGroupShape s = new HSLFGroupShape(this);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -340,7 +340,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
}
HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData, this);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -351,7 +351,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
throw new IllegalArgumentException("numRows and numCols must be greater than 0");
}
HSLFTable s = new HSLFTable(numRows,numCols,this);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
index 713ecad705..81acffa25e 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.usermodel;
import java.awt.Insets;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
@@ -113,6 +113,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS
return _escherContainer;
}
+ @SuppressWarnings("resource")
@Override
public HSLFPictureData getPictureData(){
HSLFSlideShow ppt = getSheet().getSlideShow();
@@ -132,6 +133,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS
return null;
}
+ @SuppressWarnings("resource")
protected EscherBSERecord getEscherBSERecord(){
HSLFSlideShow ppt = getSheet().getSlideShow();
Document doc = ppt.getDocumentRecord();
@@ -184,7 +186,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS
EscherBSERecord bse = getEscherBSERecord();
bse.setRef(bse.getRef() + 1);
- Rectangle anchor = getAnchor();
+ Rectangle2D anchor = getAnchor();
if (anchor.isEmpty()){
new DrawPictureShape(this).resize();
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
index 81679c02df..38483d03a4 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
@@ -19,7 +19,7 @@ package org.apache.poi.hslf.usermodel;
import java.awt.Color;
import java.awt.Graphics2D;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import org.apache.poi.ddf.AbstractEscherOptRecord;
@@ -133,7 +133,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
*
* @return the anchor of this shape
*/
- public Rectangle getAnchor() {
+ public Rectangle2D getAnchor() {
EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
int flags = spRecord.getFlags();
int x1,y1,x2,y2;
@@ -156,11 +156,11 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
}
// TODO: find out where this -1 value comes from at #57820 (link to ms docs?)
- Rectangle anchor = new Rectangle(
- (int)(x1 == -1 ? -1 : Units.masterToPoints(x1)),
- (int)(y1 == -1 ? -1 : Units.masterToPoints(y1)),
- (int)(x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
- (int)(y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
+ Rectangle2D anchor = new Rectangle2D.Double(
+ (x1 == -1 ? -1 : Units.masterToPoints(x1)),
+ (y1 == -1 ? -1 : Units.masterToPoints(y1)),
+ (x2 == -1 ? -1 : Units.masterToPoints(x2-x1)),
+ (y2 == -1 ? -1 : Units.masterToPoints(y2-y1))
);
return anchor;
@@ -172,7 +172,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
*
* @param anchor new anchor
*/
- public void setAnchor(Rectangle anchor){
+ public void setAnchor(Rectangle2D anchor){
int x = Units.pointsToMaster(anchor.getX());
int y = Units.pointsToMaster(anchor.getY());
int w = Units.pointsToMaster(anchor.getWidth() + anchor.getX());
@@ -201,10 +201,10 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
* @param x the x coordinate of the top left corner of the shape
* @param y the y coordinate of the top left corner of the shape
*/
- public final void moveTo(float x, float y) {
+ public final void moveTo(double x, double y) {
// This convenience method should be implemented via setAnchor in subclasses
// see HSLFGroupShape.setAnchor() for a reference
- Rectangle anchor = getAnchor();
+ Rectangle2D anchor = getAnchor();
anchor.setRect(x, y, anchor.getWidth(), anchor.getHeight());
setAnchor(anchor);
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
index 1a46a5e175..35ab5f2043 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.usermodel;
import java.awt.Graphics2D;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -402,7 +402,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
public HSLFTextBox createTextBox() {
HSLFTextBox s = new HSLFTextBox();
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -411,7 +411,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
public HSLFAutoShape createAutoShape() {
HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT);
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -420,7 +420,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
public HSLFFreeformShape createFreeform() {
HSLFFreeformShape s = new HSLFFreeformShape();
s.setHorizontalCentered(true);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -428,7 +428,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
@Override
public HSLFConnectorShape createConnector() {
HSLFConnectorShape s = new HSLFConnectorShape();
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -436,7 +436,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
@Override
public HSLFGroupShape createGroup() {
HSLFGroupShape s = new HSLFGroupShape();
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
@@ -447,7 +447,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
}
HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData);
- s.setAnchor(new Rectangle(0, 0, 100, 100));
+ s.setAnchor(new Rectangle2D.Double(0, 0, 100, 100));
addShape(s);
return s;
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
index 6bbd345f45..814ffe7455 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
@@ -17,7 +17,7 @@
package org.apache.poi.hslf.usermodel;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -76,13 +76,13 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
if(numRows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");
if(numCols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");
- int x=0, y=0, tblWidth=0, tblHeight=0;
+ double x=0, y=0, tblWidth=0, tblHeight=0;
cells = new HSLFTableCell[numRows][numCols];
for (int i = 0; i < cells.length; i++) {
x = 0;
for (int j = 0; j < cells[i].length; j++) {
cells[i][j] = new HSLFTableCell(this);
- Rectangle anchor = new Rectangle(x, y, HSLFTableCell.DEFAULT_WIDTH, HSLFTableCell.DEFAULT_HEIGHT);
+ Rectangle2D anchor = new Rectangle2D.Double(x, y, HSLFTableCell.DEFAULT_WIDTH, HSLFTableCell.DEFAULT_HEIGHT);
cells[i][j].setAnchor(anchor);
x += HSLFTableCell.DEFAULT_WIDTH;
}
@@ -90,7 +90,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
}
tblWidth = x;
tblHeight = y;
- setExteriorAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
+ setExteriorAnchor(new Rectangle2D.Double(0, 0, tblWidth, tblHeight));
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
AbstractEscherOptRecord opt = new EscherOptRecord();
@@ -159,13 +159,18 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
private static class TableCellComparator implements Comparator<HSLFShape> {
public int compare( HSLFShape o1, HSLFShape o2 ) {
- Rectangle anchor1 = o1.getAnchor();
- Rectangle anchor2 = o2.getAnchor();
- int delta = anchor1.y - anchor2.y;
- if (delta == 0) delta = anchor1.x - anchor2.x;
+ Rectangle2D anchor1 = o1.getAnchor();
+ Rectangle2D anchor2 = o2.getAnchor();
+ double delta = anchor1.getY() - anchor2.getY();
+ if (delta == 0) {
+ delta = anchor1.getX() - anchor2.getX();
+ }
// descending size
- if (delta == 0) delta = (anchor2.width*anchor2.height)-(anchor1.width*anchor1.height);
- return delta;
+ if (delta == 0) {
+ delta = (anchor2.getWidth()*anchor2.getHeight())-(anchor1.getWidth()*anchor1.getHeight());
+ }
+
+ return (int)Math.signum(delta);
}
}
@@ -176,7 +181,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
htc.add((HSLFTableCell)h);
}
}
-
+
if (htc.isEmpty()) {
throw new IllegalStateException("HSLFTable without HSLFTableCells");
}
@@ -186,12 +191,12 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
List<HSLFTableCell[]> lst = new ArrayList<HSLFTableCell[]>();
List<HSLFTableCell> row = new ArrayList<HSLFTableCell>();
- int y0 = htc.get(0).getAnchor().y;
+ double y0 = htc.get(0).getAnchor().getY();
for (HSLFTableCell sh : htc) {
- Rectangle anchor = sh.getAnchor();
- boolean isNextRow = (anchor.y > y0);
+ Rectangle2D anchor = sh.getAnchor();
+ boolean isNextRow = (anchor.getY() > y0);
if (isNextRow) {
- y0 = anchor.y;
+ y0 = anchor.getY();
lst.add(row.toArray(new HSLFTableCell[row.size()]));
row.clear();
}
@@ -207,7 +212,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
final double lx1, lx2, ly1, ly2;
LineRect(HSLFLine l) {
this.l = l;
- Rectangle r = l.getAnchor();
+ Rectangle2D r = l.getAnchor();
lx1 = r.getMinX();
lx2 = r.getMaxX();
ly1 = r.getMinY();
@@ -240,7 +245,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
// TODO: this only works for non-rotated tables
for (HSLFTableCell[] tca : cells) {
for (HSLFTableCell tc : tca) {
- final Rectangle cellAnchor = tc.getAnchor();
+ final Rectangle2D cellAnchor = tc.getAnchor();
/**
* x1/y1 --------+
@@ -322,29 +327,53 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
}
@Override
+ public double getRowHeight(int row) {
+ if (row < 0 || row >= cells.length) {
+ throw new IllegalArgumentException("Row index '"+row+"' is not within range [0-"+(cells.length-1)+"]");
+ }
+
+ return cells[row][0].getAnchor().getHeight();
+ }
+
+ @Override
public void setRowHeight(int row, double height) {
+ if (row < 0 || row >= cells.length) {
+ throw new IllegalArgumentException("Row index '"+row+"' is not within range [0-"+(cells.length-1)+"]");
+ }
+
int pxHeight = Units.pointsToPixel(height);
- int currentHeight = cells[row][0].getAnchor().height;
- int dy = pxHeight - currentHeight;
+ double currentHeight = cells[row][0].getAnchor().getHeight();
+ double dy = pxHeight - currentHeight;
for (int i = row; i < cells.length; i++) {
for (int j = 0; j < cells[i].length; j++) {
- Rectangle anchor = cells[i][j].getAnchor();
+ Rectangle2D anchor = cells[i][j].getAnchor();
if(i == row) {
- anchor.height = pxHeight;
+ anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), pxHeight);
} else {
- anchor.y += dy;
+ anchor.setRect(anchor.getX(), anchor.getY()+dy, anchor.getWidth(), pxHeight);
}
cells[i][j].setAnchor(anchor);
}
}
- Rectangle tblanchor = getAnchor();
- tblanchor.height += dy;
+ Rectangle2D tblanchor = getAnchor();
+ tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth(), tblanchor.getHeight() + dy);
setExteriorAnchor(tblanchor);
}
@Override
+ public double getColumnWidth(int col) {
+ if (col < 0 || col >= cells[0].length) {
+ throw new IllegalArgumentException("Column index '"+col+"' is not within range [0-"+(cells[0].length-1)+"]");
+ }
+
+ // TODO: check for merged cols
+ double width = cells[0][col].getAnchor().getWidth();
+ return width;
+ }
+
+ @Override
public void setColumnWidth(int col, final double width){
if (col < 0 || col >= cells[0].length) {
throw new IllegalArgumentException("Column index '"+col+"' is not within range [0-"+(cells[0].length-1)+"]");
@@ -352,20 +381,20 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
double currentWidth = cells[0][col].getAnchor().getWidth();
double dx = width - currentWidth;
for (HSLFTableCell cols[] : cells) {
- Rectangle anchor = cols[col].getAnchor();
- anchor.width = (int)Math.rint(width);
+ Rectangle2D anchor = cols[col].getAnchor();
+ anchor.setRect(anchor.getX(), anchor.getY(), width, anchor.getHeight());
cols[col].setAnchor(anchor);
if (col < cols.length - 1) {
for (int j = col+1; j < cols.length; j++) {
anchor = cols[j].getAnchor();
- anchor.x += dx;
+ anchor.setRect(anchor.getX()+dx, anchor.getY(), anchor.getWidth(), anchor.getHeight());
cols[j].setAnchor(anchor);
}
}
}
- Rectangle tblanchor = getAnchor();
- tblanchor.width += dx;
+ Rectangle2D tblanchor = getAnchor();
+ tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth() + dx, tblanchor.getHeight());
setExteriorAnchor(tblanchor);
}
@@ -393,7 +422,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
}
@Override
- protected void moveAndScale(Rectangle anchorDest){
+ protected void moveAndScale(Rectangle2D anchorDest){
super.moveAndScale(anchorDest);
updateRowHeightsProperty();
}
@@ -403,7 +432,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES);
byte[] val = new byte[4];
for (int rowIdx = 0; rowIdx < cells.length; rowIdx++) {
- int rowHeight = Units.pointsToMaster(cells[rowIdx][0].getAnchor().height);
+ int rowHeight = Units.pointsToMaster(cells[rowIdx][0].getAnchor().getHeight());
LittleEndian.putInt(val, 0, rowHeight);
p.setElement(rowIdx, val);
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java
index 80341aa354..aee8994832 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.usermodel;
import java.awt.Color;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherContainerRecord;
@@ -85,40 +85,40 @@ public final class HSLFTableCell extends HSLFTextBox implements TableCell<HSLFSh
if (line == null) {
return;
}
- Rectangle cellAnchor = getAnchor();
- Rectangle lineAnchor = new Rectangle();
+ Rectangle2D cellAnchor = getAnchor();
+ double x,y,w,h;
switch(edge){
case top:
- lineAnchor.x = cellAnchor.x;
- lineAnchor.y = cellAnchor.y;
- lineAnchor.width = cellAnchor.width;
- lineAnchor.height = 0;
+ x = cellAnchor.getX();
+ y = cellAnchor.getY();
+ w = cellAnchor.getWidth();
+ h = 0;
break;
case right:
- lineAnchor.x = cellAnchor.x + cellAnchor.width;
- lineAnchor.y = cellAnchor.y;
- lineAnchor.width = 0;
- lineAnchor.height = cellAnchor.height;
+ x = cellAnchor.getX() + cellAnchor.getWidth();
+ y = cellAnchor.getY();
+ w = 0;
+ h = cellAnchor.getHeight();
break;
case bottom:
- lineAnchor.x = cellAnchor.x;
- lineAnchor.y = cellAnchor.y + cellAnchor.height;
- lineAnchor.width = cellAnchor.width;
- lineAnchor.height = 0;
+ x = cellAnchor.getX();
+ y = cellAnchor.getY() + cellAnchor.getHeight();
+ w = cellAnchor.getWidth();
+ h = 0;
break;
case left:
- lineAnchor.x = cellAnchor.x;
- lineAnchor.y = cellAnchor.y;
- lineAnchor.width = 0;
- lineAnchor.height = cellAnchor.height;
+ x = cellAnchor.getX();
+ y = cellAnchor.getY();
+ w = 0;
+ h = cellAnchor.getHeight();
break;
default:
throw new IllegalArgumentException();
}
- line.setAnchor(lineAnchor);
+ line.setAnchor(new Rectangle2D.Double(x,y,w,h));
}
- public void setAnchor(Rectangle anchor){
+ public void setAnchor(Rectangle2D anchor){
super.setAnchor(anchor);
anchorBorder(BorderEdge.top, borderTop);
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
index db5dcc1acb..236ab234b1 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
@@ -20,7 +20,6 @@ package org.apache.poi.hslf.usermodel;
import static org.apache.poi.hslf.record.RecordTypes.OEPlaceholderAtom;
import static org.apache.poi.hslf.record.RecordTypes.RoundTripHFPlaceholder12;
-import java.awt.Rectangle;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
@@ -209,7 +208,11 @@ implements TextShape<HSLFShape,HSLFTextParagraph> {
} catch (IOException e){
throw new HSLFException(e);
}
- if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
+ boolean isInitialAnchor = getAnchor().equals(new Rectangle2D.Double());
+ boolean isFilledTxt = !"".equals(getText());
+ if (isInitialAnchor && isFilledTxt) {
+ resizeToFitText();
+ }
}
for (HSLFTextParagraph htp : _paragraphs) {
htp.setShapeId(getShapeId());
@@ -250,10 +253,10 @@ implements TextShape<HSLFShape,HSLFTextParagraph> {
* @return a <code>Rectangle2D</code> that is the bounds of this shape.
*/
public Rectangle2D resizeToFitText(){
- Rectangle anchor = getAnchor();
+ Rectangle2D anchor = getAnchor();
if(anchor.getWidth() == 0.) {
logger.log(POILogger.WARN, "Width of shape wasn't set. Defaulting to 200px");
- anchor.setSize(200, (int)anchor.getHeight());
+ anchor.setRect(anchor.getX(), anchor.getY(), 200., anchor.getHeight());
setAnchor(anchor);
}
double height = getTextHeight();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
index 7b6e762cf6..7e96707d1b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -50,7 +50,7 @@ public final class TestMovieShape {
HSLFPictureData thumbnailData = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
MovieShape shape = new MovieShape(movieIdx, thumbnailData);
- shape.setAnchor(new Rectangle(300,225,120,90));
+ shape.setAnchor(new Rectangle2D.Double(300,225,120,90));
slide.addShape(shape);
assertEquals(path, shape.getPath());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
index 5babd1bf89..e3c739001b 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
@@ -20,10 +20,11 @@ package org.apache.poi.hslf.model;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@@ -50,23 +51,36 @@ public final class TestOleEmbedding {
* @throws Exception if an error occurs.
*/
@Test
- public void testOleEmbedding2003() throws Exception {
+ public void testOleEmbedding2003() throws IOException {
HSLFSlideShowImpl slideShow = new HSLFSlideShowImpl(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
// Placeholder EMFs for clients that don't support the OLE components.
List<HSLFPictureData> pictures = slideShow.getPictureData();
assertEquals("Should be two pictures", 2, pictures.size());
- //assertDigestEquals("Wrong data for picture 1", "8d1fbadf4814f321bb1ccdd056e3c788", pictures[0].getData());
- //assertDigestEquals("Wrong data for picture 2", "987a698e83559cf3d38a0deeba1cc63b", pictures[1].getData());
+
+ long checkSums[] = { 0xD37A4204l, 0x26A62F68l, 0x82853169l, 0xE0E45D2Bl };
+ int checkId = 0;
+
+ // check for checksum to be uptodate
+ for (HSLFPictureData pd : pictures) {
+ long checkEMF = IOUtils.calculateChecksum(pd.getData());
+ assertEquals(checkSums[checkId++], checkEMF);
+ }
// Actual embedded objects.
HSLFObjectData[] objects = slideShow.getEmbeddedObjects();
assertEquals("Should be two objects", 2, objects.length);
- //assertDigestEquals("Wrong data for objecs 1", "0d1fcc61a83de5c4894dc0c88e9a019d", objects[0].getData());
- //assertDigestEquals("Wrong data for object 2", "b323604b2003a7299c77c2693b641495", objects[1].getData());
+ for (HSLFObjectData od : objects) {
+ long checkEMF = IOUtils.calculateChecksum(od.getData());
+ assertEquals(checkSums[checkId++], checkEMF);
+ }
+
+ slideShow.close();
}
+
+
@Test
- public void testOLEShape() throws Exception {
+ public void testOLEShape() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
@@ -97,12 +111,12 @@ public final class TestOleEmbedding {
}
assertEquals("Expected 2 OLE shapes", 2, cnt);
+ ppt.close();
}
@Test
- public void testEmbedding() throws Exception {
- HSLFSlideShowImpl _hslfSlideShow = HSLFSlideShowImpl.create();
- HSLFSlideShow ppt = new HSLFSlideShow(_hslfSlideShow);
+ public void testEmbedding() throws IOException {
+ HSLFSlideShow ppt = new HSLFSlideShow();
File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
HSLFPictureData pictData = ppt.addPicture(pict, PictureType.JPEG);
@@ -117,7 +131,7 @@ public final class TestOleEmbedding {
OLEShape oleShape1 = new OLEShape(pictData);
oleShape1.setObjectID(oleObjectId1);
slide1.addShape(oleShape1);
- oleShape1.setAnchor(new Rectangle(100,100,100,100));
+ oleShape1.setAnchor(new Rectangle2D.Double(100,100,100,100));
// add second slide with different order in object creation
HSLFSlide slide2 = ppt.createSlide();
@@ -131,7 +145,7 @@ public final class TestOleEmbedding {
oleShape2.setObjectID(oleObjectId2);
slide2.addShape(oleShape2);
- oleShape2.setAnchor(new Rectangle(100,100,100,100));
+ oleShape2.setAnchor(new Rectangle2D.Double(100,100,100,100));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt.write(bos);
@@ -148,6 +162,8 @@ public final class TestOleEmbedding {
poiData1.close();
poiData2.close();
-
+ ppt.close();
}
+
+
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
index 3ce7a71b99..bf23bd403c 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -49,7 +49,6 @@ import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSimpleShape;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hslf.usermodel.HSLFTextBox;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.usermodel.HSLFTextRun;
@@ -84,7 +83,7 @@ public final class TestShapes {
}
@Test
- public void graphics() throws Exception {
+ public void graphics() throws IOException {
HSLFSlide slide = ppt.createSlide();
HSLFLine line = new HSLFLine();
@@ -96,7 +95,7 @@ public final class TestShapes {
slide.addShape(line);
HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
- java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
+ Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
ellipse.setAnchor(ellipseAnchor);
ellipse.setLineWidth(2);
ellipse.setLineDash(LineDash.SOLID);
@@ -110,10 +109,10 @@ public final class TestShapes {
//read ppt from byte array
- ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
- assertEquals(1, ppt.getSlides().size());
+ HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
+ assertEquals(1, ppt2.getSlides().size());
- slide = ppt.getSlides().get(0);
+ slide = ppt2.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(2, shape.size());
@@ -122,6 +121,8 @@ public final class TestShapes {
assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
+
+ ppt2.close();
}
/**
@@ -129,7 +130,7 @@ public final class TestShapes {
* @throws Exception
*/
@Test
- public void textBoxRead() throws Exception {
+ public void textBoxRead() throws IOException {
ppt = new HSLFSlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
HSLFSlide sl = ppt.getSlides().get(0);
for (HSLFShape sh : sl.getShapes()) {
@@ -161,7 +162,7 @@ public final class TestShapes {
@SuppressWarnings("unused")
@Test
- public void testParagraphs() throws Exception {
+ public void testParagraphs() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
HSLFTextBox shape = new HSLFTextBox();
@@ -175,7 +176,7 @@ public final class TestShapes {
p2r2.setStrikethrough(true);
// run 3 has same text properties as run 2 and will be merged when saving
HSLFTextRun p2r3 = shape.appendText("para 2 run 3.", false);
- shape.setAnchor(new Rectangle(100,100,100,10));
+ shape.setAnchor(new Rectangle2D.Double(100,100,100,10));
slide.addShape(shape);
shape.resizeToFitText();
@@ -207,7 +208,7 @@ public final class TestShapes {
* and set some of the style attributes
*/
@Test
- public void textBoxWriteBytes() throws Exception {
+ public void textBoxWriteBytes() throws IOException {
ppt = new HSLFSlideShow();
HSLFSlide sl = ppt.createSlide();
HSLFTextRun rt;
@@ -241,8 +242,8 @@ public final class TestShapes {
ppt.write(out);
out.close();
- ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
- sl = ppt.getSlides().get(0);
+ HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
+ sl = ppt2.getSlides().get(0);
txtbox = (HSLFTextBox)sl.getShapes().get(0);
rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
@@ -255,6 +256,8 @@ public final class TestShapes {
assertFalse(rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
assertTrue(sameColor(Color.red, rt.getFontColor()));
+
+ ppt2.close();
}
/**
@@ -276,7 +279,7 @@ public final class TestShapes {
* it must be the same as returned by Slide.getTextRuns().
*/
@Test
- public void textBoxSet() throws Exception {
+ public void textBoxSet() throws IOException {
textBoxSet("with_textbox.ppt");
textBoxSet("basic_test_ppt_file.ppt");
textBoxSet("next_test_ppt_file.ppt");
@@ -285,7 +288,7 @@ public final class TestShapes {
textBoxSet("incorrect_slide_order.ppt");
}
- private void textBoxSet(String filename) throws Exception {
+ private void textBoxSet(String filename) throws IOException {
HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(filename));
for (HSLFSlide sld : ss.getSlides()) {
ArrayList<String> lst1 = new ArrayList<String>();
@@ -311,13 +314,14 @@ public final class TestShapes {
assertTrue(lst1.containsAll(lst2));
assertTrue(lst2.containsAll(lst1));
}
+ ss.close();
}
/**
* Test adding shapes to <code>ShapeGroup</code>
*/
@Test
- public void shapeGroup() throws Exception {
+ public void shapeGroup() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
@@ -325,22 +329,23 @@ public final class TestShapes {
HSLFGroupShape group = new HSLFGroupShape();
- group.setAnchor(new Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight()));
+ group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
slide.addShape(group);
HSLFPictureData data = ss.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
HSLFPictureShape pict = new HSLFPictureShape(data, group);
- pict.setAnchor(new Rectangle(0, 0, 200, 200));
+ pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
group.addShape(pict);
HSLFLine line = new HSLFLine(group);
- line.setAnchor(new Rectangle(300, 300, 500, 0));
+ line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
group.addShape(line);
//serialize and read again.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
+ ss.close();
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
ss = new HSLFSlideShow(is);
@@ -359,10 +364,12 @@ public final class TestShapes {
assertTrue(grshape.get(1) instanceof HSLFLine);
pict = (HSLFPictureShape)grshape.get(0);
- assertEquals(new Rectangle(0, 0, 200, 200), pict.getAnchor());
+ assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
line = (HSLFLine)grshape.get(1);
- assertEquals(new Rectangle(300, 300, 500, 0), line.getAnchor());
+ assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
+
+ ss.close();
}
/**
@@ -387,10 +394,12 @@ public final class TestShapes {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
+ ss.close();
ss = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
sl = ss.getSlides().get(0);
assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().size());
+ ss.close();
}
@Test
@@ -409,7 +418,7 @@ public final class TestShapes {
}
@Test
- public void shapeId() {
+ public void shapeId() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
HSLFShape shape = null;
@@ -456,6 +465,7 @@ public final class TestShapes {
slide.addShape(shape);
}
assertEquals(numClusters + 1, dgg.getNumIdClusters());
+ ss.close();
}
@Test
@@ -482,5 +492,7 @@ public final class TestShapes {
assertEquals("Border width is 5 pt", sh4.getText());
assertEquals(Color.black, sh4.getLineColor());
assertEquals(5.0, sh4.getLineWidth(), 0);
+
+ ss.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
index 9b11555b1a..3c7bc9c9a5 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
@@ -42,8 +43,6 @@ import org.junit.Test;
/**
* Test <code>Table</code> object.
- *
- * @author Yegor Kozlov
*/
public final class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
@@ -52,7 +51,7 @@ public final class TestTable {
* Test that ShapeFactory works properly and returns <code>Table</code>
*/
@Test
- public void testShapeFactory() throws Exception {
+ public void testShapeFactory() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
@@ -72,20 +71,22 @@ public final class TestTable {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
out.close();
-
+ ppt.close();
+
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides().get(0);
assertTrue(slide.getShapes().get(0) instanceof HSLFTable);
HSLFTable tbl3 = (HSLFTable)slide.getShapes().get(0);
assertEquals(tbl.getNumberOfColumns(), tbl3.getNumberOfColumns());
assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows());
+ ppt.close();
}
/**
* Error constructing Table when rownum=1
*/
@Test
- public void test45889(){
+ public void test45889() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
List<HSLFShape> shapes;
@@ -101,24 +102,25 @@ public final class TestTable {
assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns());
assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows());
+ ppt.close();
}
- @Test
- public void testIllegalCOnstruction(){
+ @Test(expected=IllegalArgumentException.class)
+ public void testIllegalRowCnstruction() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
- try {
- slide.createTable(0, 5);
- fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
- } catch (IllegalArgumentException e){
-
- }
- try {
- slide.createTable(5, 0);
- fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
- } catch (IllegalArgumentException e){
+ slide.createTable(0, 5);
+ fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
+ ppt.close();
+ }
- }
+ @Test(expected=IllegalArgumentException.class)
+ public void testIllegalColConstruction() throws IOException {
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+ slide.createTable(5, 0);
+ fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
+ ppt.close();
}
/**
@@ -126,7 +128,7 @@ public final class TestTable {
* when the table is positioned with its top at -1
*/
@Test
- public void test57820() throws Exception {
+ public void test57820() throws IOException {
SlideShow<?,?> ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt"));
List<? extends Slide<?,?>> slides = ppt.getSlides();
@@ -143,7 +145,8 @@ public final class TestTable {
}
assertNotNull(tbl);
-
assertEquals(-1, tbl.getAnchor().getY(), 0);
+
+ ppt.close();
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java
index 7a917fafd5..a151db2ba7 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -58,10 +58,10 @@ public class TestTable {
new DrawTableShape(table).setAllBorders(1.0, Color.black, StrokeStyle.LineDash.DASH_DOT);
- table.setAnchor(new Rectangle(100, 100, 400, 400));
+ table.setAnchor(new Rectangle2D.Double(100, 100, 400, 400));
- Rectangle rectExp = new Rectangle(420,367,80,133);
- Rectangle rectAct = table.getCell(rows-1, cols-1).getAnchor();
+ Rectangle2D rectExp = new Rectangle2D.Double(420,366.625,80,133.375);
+ Rectangle2D rectAct = table.getCell(rows-1, cols-1).getAnchor();
assertEquals(rectExp, rectAct);
ppt.close();
}