--- /dev/null
+/* ====================================================================\r
+ Copyright 2002-2004 Apache Software Foundation\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ 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
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.HSLFSlideShow;\r
+\r
+import java.awt.*;\r
+import java.awt.Rectangle;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.ByteArrayInputStream;\r
+\r
+/**\r
+ * Test drawing shapes via Graphics2D\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestPPGraphics2D extends TestCase {\r
+ private SlideShow ppt;\r
+\r
+ protected void setUp() throws Exception {\r
+ String dirname = System.getProperty("HSLF.testdata.path");\r
+ String filename = dirname + "/empty.ppt";\r
+ ppt = new SlideShow(new HSLFSlideShow(filename));\r
+ }\r
+\r
+ public void testGraphics() throws Exception {\r
+ // Starts off empty\r
+ assertEquals(0, ppt.getSlides().length);\r
+ \r
+ // Add a slide\r
+ Slide slide = ppt.createSlide();\r
+ assertEquals(1, ppt.getSlides().length);\r
+\r
+ // Add some stuff into it\r
+ ShapeGroup group = new ShapeGroup();\r
+ Dimension pgsize = ppt.getPageSize();\r
+ java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight());\r
+ group.setAnchor(bounds);\r
+ slide.addShape(group);\r
+\r
+ PPGraphics2D graphics = new PPGraphics2D(group);\r
+ graphics.setColor(Color.blue);\r
+ graphics.draw(new Rectangle(1296, 2544, 1344, 0));\r
+\r
+ graphics.setColor(Color.red);\r
+ graphics.setStroke(new BasicStroke((float)2.5));\r
+ graphics.drawLine(500, 500, 1500, 2500);\r
+\r
+ graphics.setColor(Color.green);\r
+ graphics.setPaint(Color.gray);\r
+ graphics.drawOval(4000, 1000, 1000, 1000);\r
+\r
+ // Write the file out\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ // And read it back in\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertEquals(1, ppt.getSlides().length);\r
+\r
+ slide = ppt.getSlides()[0];\r
+ Shape[] shape = slide.getShapes();\r
+ assertEquals(shape.length, 1); //group shape\r
+\r
+ assertTrue(shape[0] instanceof ShapeGroup); //group shape\r
+\r
+ group = (ShapeGroup)shape[0];\r
+ shape = group.getShapes();\r
+ assertEquals(shape.length, 7);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* ====================================================================\r
+ Copyright 2002-2004 Apache Software Foundation\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ 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
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.HSLFSlideShow;\r
+\r
+import java.awt.*;\r
+import java.awt.Rectangle;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.ByteArrayInputStream;\r
+\r
+/**\r
+ * Test drawing shapes via Graphics2D\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestShapes extends TestCase {\r
+ private SlideShow ppt;\r
+\r
+ protected void setUp() throws Exception {\r
+ String dirname = System.getProperty("HSLF.testdata.path");\r
+ String filename = dirname + "/empty.ppt";\r
+ ppt = new SlideShow(new HSLFSlideShow(filename));\r
+ getClass().getResourceAsStream("");\r
+ }\r
+\r
+ public void testGraphics() throws Exception {\r
+ Slide slide = ppt.createSlide();\r
+\r
+ Line line = new Line();\r
+ line.setAnchor(new Rectangle(1296, 2544, 1344, 528));\r
+ line.setLineWidth(3);\r
+ line.setLineStyle(Line.LineDashSys);\r
+ line.setLineColor(Color.red);\r
+ slide.addShape(line);\r
+\r
+ Ellipse ellipse = new Ellipse();\r
+ ellipse.setAnchor(new Rectangle(4000, 1000, 1000, 1000));\r
+ ellipse.setLineWidth(2);\r
+ ellipse.setLineStyle(Line.LineSolid);\r
+ ellipse.setLineColor(Color.green);\r
+ ellipse.setFillColor(Color.lightGray);\r
+ slide.addShape(ellipse);\r
+\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ //read ppt from byte array\r
+\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertEquals(ppt.getSlides().length, 1);\r
+\r
+ slide = ppt.getSlides()[0];\r
+ Shape[] shape = slide.getShapes();\r
+ assertEquals(shape.length, 2);\r
+\r
+ assertTrue(shape[0] instanceof Line); //group shape\r
+ assertEquals(shape[0].getAnchor(), new Rectangle(1296, 2544, 1344, 528)); //group shape\r
+\r
+ assertTrue(shape[1] instanceof Ellipse); //group shape\r
+ assertEquals(shape[1].getAnchor(), new Rectangle(4000, 1000, 1000, 1000)); //group shape\r
+ }\r
+\r
+}\r
}
public void testAppendChildRecord() {
+ // Grab records for testing with
+ Record r = recordContainer.getChildRecords()[0];
+ Record rb = recordContainer.getChildRecords()[1];
+ Record rc = recordContainer.getChildRecords()[2];
+ Record rd = recordContainer.getChildRecords()[3];
+
// Start with an empty set
Record[] rs = new Record[0];
- Record r = recordContainer.getChildRecords()[0];
- Record[] nrs = recordContainer.appendChildRecord(r, rs);
+ recordContainer._children = rs;
+ recordContainer.appendChildRecord(r);
+ Record[] nrs = recordContainer.getChildRecords();
assertEquals(1, nrs.length);
assertEquals(r, nrs[0]);
// Now start with one with 3 entries
rs = new Record[3];
- Record rb = recordContainer.getChildRecords()[1];
- Record rc = recordContainer.getChildRecords()[2];
- Record rd = recordContainer.getChildRecords()[3];
+ recordContainer._children = rs;
rs[0] = rb;
rs[1] = rc;
rs[2] = rd;
- nrs = recordContainer.appendChildRecord(r, rs);
+ recordContainer.appendChildRecord(r);
+ nrs = recordContainer.getChildRecords();
assertEquals(4, nrs.length);
assertEquals(rb, nrs[0]);