import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
table1.setRowHeight(1, 80);
Dimension dim = ppt.getPageSize();
- Rectangle oldAnchor = table1.getAnchor();
- table1.setAnchor(new Rectangle((dim.width-450)/2, 100, oldAnchor.width, oldAnchor.height));
+ Rectangle2D oldAnchor = table1.getAnchor();
+ table1.setAnchor(new Rectangle2D.Double((dim.width-450)/2, 100, oldAnchor.getWidth(), oldAnchor.getHeight()));
TextBox<?,?> box1 = slide.createTextBox();
box1.setHorizontalCentered(true);
table1.setColumnWidth(1, 150);
int pgWidth = ppt.getPageSize().width;
- table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);
+ table1.moveTo((pgWidth - table1.getAnchor().getWidth())/2., 100.);
//test data for the second taable
String[][] txt2 = {
ppt.write(out);
out.close();
+ ppt.close();
}
}
import java.awt.Dimension;\r
import java.awt.Graphics2D;\r
import java.awt.Paint;\r
-import java.awt.Rectangle;\r
import java.awt.geom.Rectangle2D;\r
\r
import org.apache.poi.sl.usermodel.Background;\r
@SuppressWarnings("rawtypes")\r
public void draw(Graphics2D graphics) {\r
Dimension pg = shape.getSheet().getSlideShow().getPageSize();\r
- final Rectangle anchor = new Rectangle(0, 0, (int)pg.getWidth(), (int)pg.getHeight());\r
+ final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());\r
\r
PlaceableShape<?,?> ps = new PlaceableShape(){\r
public ShapeContainer<?,?> getParent() { return null; }\r
- public Rectangle getAnchor() { return anchor; }\r
- public void setAnchor(Rectangle newAnchor) {}\r
+ public Rectangle2D getAnchor() { return anchor; }\r
+ public void setAnchor(Rectangle2D newAnchor) {}\r
public double getRotation() { return 0; }\r
public void setRotation(double theta) {}\r
public void setFlipHorizontal(boolean flip) {}\r
import java.awt.Dimension;\r
import java.awt.Graphics2D;\r
import java.awt.Insets;\r
-import java.awt.Rectangle;\r
import java.awt.geom.Rectangle2D;\r
import java.io.IOException;\r
\r
PictureShape<?,?> ps = getShape();\r
Dimension dim = ps.getPictureData().getImageDimension();\r
\r
- Rectangle origRect = ps.getAnchor();\r
- int x = (int)origRect.getX();\r
- int y = (int)origRect.getY();\r
- int w = (int)dim.getWidth();\r
- int h = (int)dim.getHeight();\r
- ps.setAnchor(new Rectangle(x, y, w, h));\r
+ Rectangle2D origRect = ps.getAnchor();\r
+ double x = origRect.getX();\r
+ double y = origRect.getY();\r
+ double w = dim.getWidth();\r
+ double h = dim.getHeight();\r
+ ps.setAnchor(new Rectangle2D.Double(x, y, w, h));\r
}\r
\r
\r
*\r
* @param target The target rectangle\r
*/\r
- public void resize(Rectangle target) {\r
+ public void resize(Rectangle2D target) {\r
resize(target, RectAlign.CENTER);\r
}\r
\r
* The alignment within the target rectangle when resizing.\r
* A null value corresponds to RectAlign.CENTER\r
*/\r
- public void resize(Rectangle target, RectAlign align) {\r
+ public void resize(Rectangle2D target, RectAlign align) {\r
PictureShape<?,?> ps = getShape();\r
Dimension dim = ps.getPictureData().getImageDimension();\r
if (dim.width <= 0 || dim.height <= 0) {\r
break;\r
}\r
\r
- ps.setAnchor(new Rectangle((int)x, (int)y, (int)w, (int)h));\r
+ ps.setAnchor(new Rectangle2D.Double(x, y, w, h));\r
}\r
}\r
\r
import java.awt.Graphics2D;\r
import java.awt.Paint;\r
-import java.awt.Rectangle;\r
import java.awt.font.FontRenderContext;\r
import java.awt.font.LineBreakMeasurer;\r
import java.awt.font.TextAttribute;\r
private PlaceableShape<?,?> getParagraphShape() {\r
PlaceableShape<?,?> ps = new PlaceableShape(){\r
public ShapeContainer<?,?> getParent() { return null; }\r
- public Rectangle getAnchor() { return paragraph.getParentShape().getAnchor(); }\r
- public void setAnchor(Rectangle anchor) {}\r
+ public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }\r
+ public void setAnchor(Rectangle2D anchor) {}\r
public double getRotation() { return 0; }\r
public void setRotation(double theta) {}\r
public void setFlipHorizontal(boolean flip) {}\r
package org.apache.poi.sl.usermodel;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
public interface GroupShape<
S extends Shape<S,P>,
*
* @return the coordinate space of this group
*/
- Rectangle getInteriorAnchor();
+ Rectangle2D getInteriorAnchor();
/**
* Sets the coordinate space of this group. All children are constrained
*
* @param anchor the coordinate space of this group
*/
- void setInteriorAnchor(Rectangle anchor);
+ void setInteriorAnchor(Rectangle2D anchor);
}
\r
package org.apache.poi.sl.usermodel;\r
\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
public interface PlaceableShape<\r
S extends Shape<S,P>,\r
* @return the position of this shape within the drawing canvas.\r
* The coordinates are expressed in points\r
*/\r
- Rectangle getAnchor();\r
+ Rectangle2D getAnchor();\r
\r
/**\r
* @param anchor the position of this shape within the drawing canvas.\r
* The coordinates are expressed in points\r
*/\r
- void setAnchor(Rectangle anchor);\r
+ void setAnchor(Rectangle2D anchor);\r
\r
/**\r
* Rotation angle in degrees\r
package org.apache.poi.sl.usermodel;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
public interface Shape<
S extends Shape<S,P>,
*
* @return the anchor of this shape
*/
- Rectangle getAnchor();
+ Rectangle2D getAnchor();
}
\r
TableCell<S,P> getCell(int row, int col);\r
\r
+ /**\r
+ * Gets the width (in points) of the n-th column\r
+ *\r
+ * @param idx the column index (0-based)\r
+ * @return the width (in points)\r
+ */\r
+ double getColumnWidth(int idx);\r
+ \r
/**\r
* Sets the width (in points) of the n-th column\r
*\r
*/\r
void setColumnWidth(int idx, double width);\r
\r
+ /**\r
+ * Gets the row height\r
+ *\r
+ * @param row the row index (0-based)\r
+ * @return the height (in points)\r
+ */\r
+ double getRowHeight(int row);\r
+ \r
/**\r
* Sets the row height.\r
*\r
* @return emus\r
*/\r
public static int toEMU(double points){\r
- return (int)Math.round(EMU_PER_POINT*points);\r
+ return (int)Math.rint(EMU_PER_POINT*points);\r
}\r
\r
/**\r
public static int pointsToMaster(double points) {\r
points *= MASTER_DPI;\r
points /= POINT_DPI;\r
- return (int)points;\r
+ return (int)Math.rint(points);\r
}\r
\r
public static int pointsToPixel(double points) {\r
points *= PIXEL_DPI;\r
points /= POINT_DPI;\r
- return (int)points;\r
+ return (int)Math.rint(points);\r
}\r
\r
public static double pixelToPoints(int pixel) {\r
\r
import java.awt.Color;\r
import java.awt.Dimension;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import org.apache.poi.sl.draw.DrawPaint;\r
import org.apache.poi.sl.usermodel.Background;\r
}\r
\r
@Override\r
- public Rectangle getAnchor(){\r
+ public Rectangle2D getAnchor(){\r
Dimension pg = getSheet().getSlideShow().getPageSize();\r
- return new Rectangle(0, 0, (int)pg.getWidth(), (int)pg.getHeight());\r
+ return new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());\r
}\r
\r
@Override\r
==================================================================== */\r
package org.apache.poi.xslf.usermodel;\r
\r
+import java.awt.Color;\r
+import java.awt.geom.Rectangle2D;\r
+\r
import org.apache.poi.util.Beta;\r
import org.apache.xmlbeans.XmlObject;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;\r
\r
-import java.awt.Color;\r
-import java.awt.Rectangle;\r
-\r
\r
/**\r
* @author Yegor Kozlov\r
CTShape sp = _spTree.addNewSp();\r
sp.set(XSLFAutoShape.prototype(_shapeId++));\r
XSLFAutoShape shape = new XSLFAutoShape(sp, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
\r
CTShape sp = _spTree.addNewSp();\r
sp.set(XSLFFreeformShape.prototype(_shapeId++));\r
XSLFFreeformShape shape = new XSLFFreeformShape(sp, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
\r
CTShape sp = _spTree.addNewSp();\r
sp.set(XSLFTextBox.prototype(_shapeId++));\r
XSLFTextBox shape = new XSLFTextBox(sp, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
\r
CTConnector sp = _spTree.addNewCxnSp();\r
sp.set(XSLFConnectorShape.prototype(_shapeId++));\r
XSLFConnectorShape shape = new XSLFConnectorShape(sp, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
shape.setLineColor(Color.black);\r
shape.setLineWidth(0.75);\r
return shape;\r
CTGroupShape obj = _spTree.addNewGrpSp();\r
obj.set(XSLFGroupShape.prototype(_shapeId++));\r
XSLFGroupShape shape = new XSLFGroupShape(obj, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
\r
CTPicture obj = _spTree.addNewPic();\r
obj.set(XSLFPictureShape.prototype(_shapeId++, rel));\r
XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
\r
CTGraphicalObjectFrame obj = _spTree.addNewGraphicFrame();\r
obj.set(XSLFTable.prototype(_shapeId++));\r
XSLFTable shape = new XSLFTable(obj, _sheet);\r
- shape.setAnchor(new Rectangle());\r
+ shape.setAnchor(new Rectangle2D.Double());\r
return shape;\r
}\r
}\r
\r
package org.apache.poi.xslf.usermodel;\r
\r
-import java.awt.Rectangle;\r
import java.awt.geom.AffineTransform;\r
import java.awt.geom.GeneralPath;\r
import java.awt.geom.PathIterator;\r
public int setPath(GeneralPath path) {\r
CTPath2D ctPath = CTPath2D.Factory.newInstance();\r
\r
- Rectangle bounds = path.getBounds();\r
+ Rectangle2D bounds = path.getBounds2D();\r
int x0 = Units.toEMU(bounds.getX());\r
int y0 = Units.toEMU(bounds.getY());\r
PathIterator it = path.getPathIterator(new AffineTransform());\r
\r
package org.apache.poi.xslf.usermodel;\r
\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import javax.xml.namespace.QName;\r
\r
import org.apache.poi.openxml4j.opc.PackagePart;\r
import org.apache.poi.openxml4j.opc.PackageRelationship;\r
import org.apache.poi.sl.draw.DrawNotImplemented;\r
+import org.apache.poi.sl.usermodel.PlaceableShape;\r
import org.apache.poi.sl.usermodel.ShapeType;\r
import org.apache.poi.util.Beta;\r
import org.apache.poi.util.Units;\r
*/\r
@Beta\r
@DrawNotImplemented\r
-public class XSLFGraphicFrame extends XSLFShape {\r
+public class XSLFGraphicFrame extends XSLFShape implements PlaceableShape<XSLFShape, XSLFTextParagraph> {\r
/*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){\r
super(shape,sheet);\r
}\r
}\r
\r
@Override\r
- public Rectangle getAnchor(){\r
+ public Rectangle2D getAnchor(){\r
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();\r
CTPoint2D off = xfrm.getOff();\r
- int x = (int)Units.toPoints(off.getX());\r
- int y = (int)Units.toPoints(off.getY());\r
+ double x = Units.toPoints(off.getX());\r
+ double y = Units.toPoints(off.getY());\r
CTPositiveSize2D ext = xfrm.getExt();\r
- int cx = (int)Units.toPoints(ext.getCx());\r
- int cy = (int)Units.toPoints(ext.getCy());\r
- return new Rectangle(x, y, cx, cy);\r
+ double cx = Units.toPoints(ext.getCx());\r
+ double cy = Units.toPoints(ext.getCy());\r
+ return new Rectangle2D.Double(x, y, cx, cy);\r
}\r
\r
- public void setAnchor(Rectangle anchor){\r
+ @Override\r
+ public void setAnchor(Rectangle2D anchor){\r
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();\r
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();\r
long x = Units.toEMU(anchor.getX());\r
\r
package org.apache.poi.xslf.usermodel;\r
\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
import java.util.ArrayList;\r
import java.util.Iterator;\r
import java.util.List;\r
}\r
\r
@Override\r
- public Rectangle getAnchor(){\r
+ public Rectangle2D getAnchor(){\r
CTGroupTransform2D xfrm = getXfrm();\r
CTPoint2D off = xfrm.getOff();\r
- int x = (int)Units.toPoints(off.getX());\r
- int y = (int)Units.toPoints(off.getY());\r
+ double x = Units.toPoints(off.getX());\r
+ double y = Units.toPoints(off.getY());\r
CTPositiveSize2D ext = xfrm.getExt();\r
- int cx = (int)Units.toPoints(ext.getCx());\r
- int cy = (int)Units.toPoints(ext.getCy());\r
- return new Rectangle(x,y,cx,cy);\r
+ double cx = Units.toPoints(ext.getCx());\r
+ double cy = Units.toPoints(ext.getCy());\r
+ return new Rectangle2D.Double(x,y,cx,cy);\r
}\r
\r
@Override\r
- public void setAnchor(Rectangle anchor){\r
+ public void setAnchor(Rectangle2D anchor){\r
CTGroupTransform2D xfrm = getSafeXfrm();\r
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();\r
long x = Units.toEMU(anchor.getX());\r
* used for calculations of grouping, scaling, and rotation\r
* behavior of shapes placed within a group.\r
*/\r
- public Rectangle getInteriorAnchor(){\r
+ @Override\r
+ public Rectangle2D getInteriorAnchor(){\r
CTGroupTransform2D xfrm = getXfrm();\r
CTPoint2D off = xfrm.getChOff();\r
- int x = (int)Units.toPoints(off.getX());\r
- int y = (int)Units.toPoints(off.getY());\r
+ double x = Units.toPoints(off.getX());\r
+ double y = Units.toPoints(off.getY());\r
CTPositiveSize2D ext = xfrm.getChExt();\r
- int cx = (int)Units.toPoints(ext.getCx());\r
- int cy = (int)Units.toPoints(ext.getCy());\r
- return new Rectangle(x, y, cx, cy);\r
+ double cx = Units.toPoints(ext.getCx());\r
+ double cy = Units.toPoints(ext.getCy());\r
+ return new Rectangle2D.Double(x, y, cx, cy);\r
}\r
\r
/**\r
* used for calculations of grouping, scaling, and rotation\r
* behavior of shapes placed within a group.\r
*/\r
- public void setInteriorAnchor(Rectangle anchor) {\r
+ @Override\r
+ public void setInteriorAnchor(Rectangle2D anchor) {\r
CTGroupTransform2D xfrm = getSafeXfrm();\r
CTPoint2D off = xfrm.isSetChOff() ? xfrm.getChOff() : xfrm.addNewChOff();\r
long x = Units.toEMU(anchor.getX());\r
package org.apache.poi.xslf.usermodel;\r
\r
import java.awt.Color;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import org.apache.poi.sl.draw.DrawPaint;\r
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;\r
}\r
\r
@Override\r
- public Rectangle getAnchor(){\r
+ public Rectangle2D getAnchor(){\r
return _parent.getAnchor();\r
}\r
\r
- public void setAnchor(Rectangle anchor){\r
+ public void setAnchor(Rectangle2D anchor){\r
throw new IllegalStateException("You can't set anchor of a shadow");\r
}\r
\r
package org.apache.poi.xslf.usermodel;\r
\r
import java.awt.Color;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import javax.xml.stream.XMLStreamException;\r
import javax.xml.stream.XMLStreamReader;\r
}\r
\r
@Override\r
- public Rectangle getAnchor() {\r
+ public Rectangle2D getAnchor() {\r
\r
CTTransform2D xfrm = getXfrm();\r
\r
CTPoint2D off = xfrm.getOff();\r
- int x = (int)Units.toPoints(off.getX());\r
- int y = (int)Units.toPoints(off.getY());\r
+ double x = Units.toPoints(off.getX());\r
+ double y = Units.toPoints(off.getY());\r
CTPositiveSize2D ext = xfrm.getExt();\r
- int cx = (int)Units.toPoints(ext.getCx());\r
- int cy = (int)Units.toPoints(ext.getCy());\r
- return new Rectangle(x, y, cx, cy);\r
+ double cx = Units.toPoints(ext.getCx());\r
+ double cy = Units.toPoints(ext.getCy());\r
+ return new Rectangle2D.Double(x, y, cx, cy);\r
}\r
\r
@Override\r
- public void setAnchor(Rectangle anchor) {\r
+ public void setAnchor(Rectangle2D anchor) {\r
CTTransform2D xfrm = getSafeXfrm();\r
CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();\r
long x = Units.toEMU(anchor.getX());\r
return _table.sizeOfTrArray();\r
}\r
\r
+ @Override\r
public double getColumnWidth(int idx){\r
return Units.toPoints(\r
_table.getTblGrid().getGridColArray(idx).getW());\r
_table.getTblGrid().getGridColArray(idx).setW(Units.toEMU(width));\r
}\r
\r
+ @Override\r
+ public double getRowHeight(int row) {\r
+ return Units.toPoints(_table.getTrArray(row).getH());\r
+ }\r
+ \r
@Override\r
public void setRowHeight(int row, double height) {\r
_table.getTrArray(row).setH(Units.toEMU(height));\r
package org.apache.poi.xslf.usermodel;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
*
* @return a <code>Rectangle2D</code> that is the bounds of this shape.
*/
- public Rectangle resizeToFitText(){
- Rectangle anchor = getAnchor();
+ public Rectangle2D resizeToFitText(){
+ Rectangle2D anchor = getAnchor();
if(anchor.getWidth() == 0.) throw new POIXMLException(
"Anchor of the shape was not set.");
double height = getTextHeight();
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.sl;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import java.io.IOException;\r
+\r
+import org.apache.poi.POIDataSamples;\r
+import org.apache.poi.sl.usermodel.SlideShow;\r
+import org.apache.poi.sl.usermodel.SlideShowFactory;\r
+import org.apache.poi.sl.usermodel.TableShape;\r
+import org.junit.Test;\r
+\r
+public class TestTable {\r
+ private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();\r
+ \r
+ @Test\r
+ public void testColWidthRowHeight() throws IOException {\r
+ // Test of table dimensions of same slideshow saved as ppt/x\r
+ // to check if both return similar (points) value\r
+ SlideShow<?,?> ppt = SlideShowFactory.create(_slTests.getFile("table_test.ppt"));\r
+ TableShape<?,?> ts = (TableShape<?,?>)ppt.getSlides().get(0).getShapes().get(0);\r
+ int cols = ts.getNumberOfColumns();\r
+ int rows = ts.getNumberOfRows();\r
+\r
+ SlideShow<?,?> pptx = SlideShowFactory.create(_slTests.getFile("table_test.pptx"));\r
+ TableShape<?,?> tsx = (TableShape<?,?>)pptx.getSlides().get(0).getShapes().get(0);\r
+ int colsx = tsx.getNumberOfColumns();\r
+ int rowsx = tsx.getNumberOfRows();\r
+ \r
+ assertEquals(cols, colsx);\r
+ assertEquals(rows, rowsx);\r
+ \r
+ for (int i=0; i<cols; i++) {\r
+ assertEquals(ts.getColumnWidth(i), tsx.getColumnWidth(i), 0.2);\r
+ }\r
+\r
+ for (int i=0; i<rows; i++) {\r
+ assertEquals(ts.getRowHeight(i), tsx.getRowHeight(i), 0.3);\r
+ }\r
+\r
+ pptx.close();\r
+ ppt.close();\r
+ }\r
+\r
+}\r
import static org.junit.Assert.assertNotNull;
import java.awt.Dimension;
-import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
import org.apache.poi.POIDataSamples;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
+import org.apache.poi.util.Units;
import org.junit.Test;
public class TestDrawPictureShape {
PictureData pd = picShape.getPictureData();
Dimension dimPd = pd.getImageDimension();
new DrawPictureShape(picShape).resize();
- Dimension dimShape = picShape.getAnchor().getSize();
+ Dimension dimShape = new Dimension(
+ (int)picShape.getAnchor().getWidth(),
+ (int)picShape.getAnchor().getHeight()
+ );
assertEquals(dimPd, dimShape);
- int newWidth = (int)(dimPd.getWidth()*(100d/dimPd.getHeight()));
+ double newWidth = (dimPd.getWidth()*(100d/dimPd.getHeight()));
// ... -1 is a rounding error
- Rectangle expRect = new Rectangle(50+300-newWidth-1, 50, newWidth, 100);
- Rectangle target = new Rectangle(50,50,300,100);
+ Rectangle2D expRect = new Rectangle2D.Double(rbf(50+300-newWidth, picShape), 50, rbf(newWidth, picShape), 100);
+ Rectangle2D target = new Rectangle2D.Double(50,50,300,100);
new DrawPictureShape(picShape).resize(target, RectAlign.BOTTOM_RIGHT);
- Rectangle actRect = picShape.getAnchor();
- assertEquals(expRect, actRect);
+ Rectangle2D actRect = picShape.getAnchor();
+ assertEquals(expRect.getX(), actRect.getX(), .0001);
+ assertEquals(expRect.getY(), actRect.getY(), .0001);
+ assertEquals(expRect.getWidth(), actRect.getWidth(), .0001);
+ assertEquals(expRect.getHeight(), actRect.getHeight(), .0001);
+ ss.close();
}
}
-
+ // round back and forth - points -> master -> points
+ static double rbf(double val, PictureShape<?,?> picShape) {
+ if (picShape.getClass().getName().contains("HSLF")) {
+ return Units.masterToPoints(Units.pointsToMaster(val));
+ } else {
+ return val;
+ }
+ }
}
import static org.junit.Assert.assertFalse;\r
\r
import java.awt.Color;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;\r
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;\r
-import org.apache.poi.sl.usermodel.*;\r
+import org.apache.poi.sl.usermodel.ShapeType;\r
import org.junit.Test;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTConnection;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualConnectorProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;\r
\r
/**\r
\r
XSLFAutoShape rect1 = slide.createAutoShape();\r
rect1.setShapeType(ShapeType.RECT);\r
- rect1.setAnchor(new Rectangle(100, 100, 100, 100));\r
+ rect1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));\r
rect1.setFillColor(Color.blue);\r
\r
XSLFAutoShape rect2 = slide.createAutoShape();\r
rect2.setShapeType(ShapeType.RECT);\r
- rect2.setAnchor(new Rectangle(300, 300, 100, 100));\r
+ rect2.setAnchor(new Rectangle2D.Double(300, 300, 100, 100));\r
rect2.setFillColor(Color.red);\r
\r
\r
XSLFConnectorShape connector1 = slide.createConnector();\r
- connector1.setAnchor(new Rectangle(200, 150, 100, 200));\r
+ connector1.setAnchor(new Rectangle2D.Double(200, 150, 100, 200));\r
\r
CTConnector ctConnector = (CTConnector)connector1.getXmlObject();\r
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.BENT_CONNECTOR_3);\r
==================================================================== */\r
package org.apache.poi.xslf.usermodel;\r
\r
-import static org.junit.Assert.*;\r
+import static org.junit.Assert.assertEquals;\r
\r
-import java.awt.Rectangle;\r
import java.awt.geom.Ellipse2D;\r
import java.awt.geom.GeneralPath;\r
+import java.awt.geom.Rectangle2D;\r
\r
import org.junit.Test;\r
\r
XSLFSlide slide = ppt.createSlide();\r
XSLFFreeformShape shape1 = slide.createFreeform();\r
// comples path consisting of a rectangle and an ellipse inside it\r
- GeneralPath path1 = new GeneralPath(new Rectangle(150, 150, 300, 300));\r
+ GeneralPath path1 = new GeneralPath(new Rectangle2D.Double(150, 150, 300, 300));\r
path1.append(new Ellipse2D.Double(200, 200, 100, 50), false);\r
shape1.setPath(path1);\r
\r
import static org.junit.Assert.assertTrue;\r
\r
import java.awt.Dimension;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
\r
import org.junit.Test;\r
\r
XSLFGroupShape group = slide.createGroup();\r
assertEquals(1, slide.getShapes().size());\r
\r
- Rectangle interior = new Rectangle(-10, -10, 20, 20);\r
+ Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);\r
group.setInteriorAnchor(interior);\r
assertEquals(interior, group.getInteriorAnchor());\r
\r
- Rectangle anchor = new Rectangle(0, 0, 792, 612);\r
+ Rectangle2D anchor = new Rectangle2D.Double(0, 0, 792, 612);\r
group.setAnchor(anchor);\r
assertEquals(anchor, group.getAnchor());\r
\r
\r
import java.awt.Color;\r
import java.awt.Graphics2D;\r
-import java.awt.Rectangle;\r
+import java.awt.geom.Rectangle2D;\r
import java.awt.image.BufferedImage;\r
import java.io.IOException;\r
import java.util.List;\r
"of text within a shape. Properties here apply to all text " +\r
"residing within the corresponding paragraph.");\r
\r
- Rectangle anchor = new Rectangle(50, 50, 300, 200);\r
+ Rectangle2D anchor = new Rectangle2D.Double(50, 50, 300, 200);\r
sh.setAnchor(anchor);\r
\r
DrawTextParagraphProxy dtp = new DrawTextParagraphProxy(p);\r
"of text within a shape. Properties here apply to all text " +\r
"residing within the corresponding paragraph.");\r
\r
- sh.setAnchor(new Rectangle(50, 50, 300, 200));\r
+ sh.setAnchor(new Rectangle2D.Double(50, 50, 300, 200));\r
DrawTextParagraphProxy dtp = new DrawTextParagraphProxy(p);\r
\r
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);\r
assertEquals(4, lines.size());\r
\r
// decrease the shape width from 300 pt to 100 pt\r
- sh.setAnchor(new Rectangle(50, 50, 100, 200));\r
+ sh.setAnchor(new Rectangle2D.Double(50, 50, 100, 200));\r
dtp.breakText(graphics);\r
lines = dtp.getLines();\r
assertEquals(12, lines.size());\r
\r
// decrease the shape width from 300 pt to 100 pt\r
- sh.setAnchor(new Rectangle(50, 50, 600, 200));\r
+ sh.setAnchor(new Rectangle2D.Double(50, 50, 600, 200));\r
dtp.breakText(graphics);\r
lines = dtp.getLines();\r
assertEquals(2, lines.size());\r
assertEquals("POI", lines.get(1).getString());\r
\r
XSLFAutoShape sh2 = slide.createAutoShape();\r
- sh2.setAnchor(new Rectangle(50, 50, 300, 200));\r
+ sh2.setAnchor(new Rectangle2D.Double(50, 50, 300, 200));\r
XSLFTextParagraph p2 = sh2.addNewTextParagraph();\r
XSLFTextRun r2 = p2.addNewTextRun();\r
r2.setFontFamily("serif"); // this should always be available\r
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;
@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[]>();
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;
}
@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);
}
@Override
- public void setInteriorAnchor(Rectangle anchor){
+ public void setInteriorAnchor(Rectangle2D anchor){
EscherSpgrRecord spgr = getEscherChild(EscherSpgrRecord.RECORD_ID);
int x1 = Units.pointsToMaster(anchor.getX());
}
@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
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);
/**
* 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));
}
}
*
* @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){
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;
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;
}
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;
}
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;
}
@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;
}
@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;
}
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;
}
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;
}
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;
return _escherContainer;
}
+ @SuppressWarnings("resource")
@Override
public HSLFPictureData getPictureData(){
HSLFSlideShow ppt = getSheet().getSlideShow();
return null;
}
+ @SuppressWarnings("resource")
protected EscherBSERecord getEscherBSERecord(){
HSLFSlideShow ppt = getSheet().getSlideShow();
Document doc = ppt.getDocumentRecord();
EscherBSERecord bse = getEscherBSERecord();
bse.setRef(bse.getRef() + 1);
- Rectangle anchor = getAnchor();
+ Rectangle2D anchor = getAnchor();
if (anchor.isEmpty()){
new DrawPictureShape(this).resize();
}
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;
*
* @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;
}
// 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;
*
* @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());
* @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);
}
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;
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;
}
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;
}
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;
}
@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;
}
@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;
}
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;
}
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;
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;
}
}
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();
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);
}
}
htc.add((HSLFTableCell)h);
}
}
-
+
if (htc.isEmpty()) {
throw new IllegalStateException("HSLFTable without HSLFTableCells");
}
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();
}
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();
// 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 --------+
}
}
+ @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) {
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);
}
}
@Override
- protected void moveAndScale(Rectangle anchorDest){
+ protected void moveAndScale(Rectangle2D anchorDest){
super.moveAndScale(anchorDest);
updateRowHeightsProperty();
}
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);
}
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;
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);
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;
} 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());
* @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();
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;
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());
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;
* @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);
}
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);
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();
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);
poiData1.close();
poiData2.close();
-
+ ppt.close();
}
+
+
}
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;
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;
}
@Test
- public void graphics() throws Exception {
+ public void graphics() throws IOException {
HSLFSlide slide = ppt.createSlide();
HSLFLine line = new HSLFLine();
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);
//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());
assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
+
+ ppt2.close();
}
/**
* @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()) {
@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();
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();
* 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;
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);
assertFalse(rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
assertTrue(sameColor(Color.red, rt.getFontColor()));
+
+ ppt2.close();
}
/**
* 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");
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>();
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();
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);
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();
}
/**
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
}
@Test
- public void shapeId() {
+ public void shapeId() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
HSLFShape shape = null;
slide.addShape(shape);
}
assertEquals(numClusters + 1, dgg.getNumIdClusters());
+ ss.close();
}
@Test
assertEquals("Border width is 5 pt", sh4.getText());
assertEquals(Color.black, sh4.getLineColor());
assertEquals(5.0, sh4.getLineWidth(), 0);
+
+ ss.close();
}
}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
/**
* Test <code>Table</code> object.
- *
- * @author Yegor Kozlov
*/
public final class TestTable {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
* 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();
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;
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();
}
/**
* 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();
}
assertNotNull(tbl);
-
assertEquals(-1, tbl.getAnchor().getY(), 0);
+
+ ppt.close();
}
}
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;
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();
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.awt.Rectangle;
import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
for(String name : shapes.keySet()) {
CustomGeometry geom = shapes.get(name);
- Context ctx = new Context(geom, new Rectangle(0, 0, 100, 100), new IAdjustableShape() {
+ Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {
public Guide getAdjustValue(String presetName) {
return null;
}