]> source.dussan.org Git - poi.git/commitdiff
Add Yegor's new slide functionality (see bug 38954), with a bit of refactoring
authorNick Burch <nick@apache.org>
Sun, 19 Mar 2006 17:54:17 +0000 (17:54 +0000)
committerNick Burch <nick@apache.org>
Sun, 19 Mar 2006 17:54:17 +0000 (17:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@387009 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java

diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt
new file mode 100644 (file)
index 0000000..23e1e94
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
new file mode 100644 (file)
index 0000000..2b7d6cc
--- /dev/null
@@ -0,0 +1,88 @@
+/* ====================================================================\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
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
new file mode 100644 (file)
index 0000000..400a66c
--- /dev/null
@@ -0,0 +1,80 @@
+/* ====================================================================\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
index bd11a01beba3d6f2b1fb6dccf6bb0628d15ecf82..a9ed9e41c302f0707651c976f7830affd3cf9baf 100644 (file)
@@ -37,24 +37,30 @@ public class TestRecordContainer extends TestCase {
        }
        
        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]);