From: Nick Burch Date: Sun, 19 Mar 2006 17:54:17 +0000 (+0000) Subject: Add Yegor's new slide functionality (see bug 38954), with a bit of refactoring X-Git-Tag: REL_3_0_ALPHA3~155 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=432637b15ab52cd35a84d183e8710ba249600b06;p=poi.git Add Yegor's new slide functionality (see bug 38954), with a bit of refactoring git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@387009 13f79535-47bb-0310-9956-ffa450edef68 --- 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 index 0000000000..23e1e94ca8 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 index 0000000000..2b7d6cc601 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java @@ -0,0 +1,88 @@ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hslf.model; + +import junit.framework.TestCase; +import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.hslf.HSLFSlideShow; + +import java.awt.*; +import java.awt.Rectangle; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; + +/** + * Test drawing shapes via Graphics2D + * + * @author Yegor Kozlov + */ +public class TestPPGraphics2D extends TestCase { + private SlideShow ppt; + + protected void setUp() throws Exception { + String dirname = System.getProperty("HSLF.testdata.path"); + String filename = dirname + "/empty.ppt"; + ppt = new SlideShow(new HSLFSlideShow(filename)); + } + + public void testGraphics() throws Exception { + // Starts off empty + assertEquals(0, ppt.getSlides().length); + + // Add a slide + Slide slide = ppt.createSlide(); + assertEquals(1, ppt.getSlides().length); + + // Add some stuff into it + ShapeGroup group = new ShapeGroup(); + Dimension pgsize = ppt.getPageSize(); + java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight()); + group.setAnchor(bounds); + slide.addShape(group); + + PPGraphics2D graphics = new PPGraphics2D(group); + graphics.setColor(Color.blue); + graphics.draw(new Rectangle(1296, 2544, 1344, 0)); + + graphics.setColor(Color.red); + graphics.setStroke(new BasicStroke((float)2.5)); + graphics.drawLine(500, 500, 1500, 2500); + + graphics.setColor(Color.green); + graphics.setPaint(Color.gray); + graphics.drawOval(4000, 1000, 1000, 1000); + + // Write the file out + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ppt.write(out); + out.close(); + + // And read it back in + ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()))); + assertEquals(1, ppt.getSlides().length); + + slide = ppt.getSlides()[0]; + Shape[] shape = slide.getShapes(); + assertEquals(shape.length, 1); //group shape + + assertTrue(shape[0] instanceof ShapeGroup); //group shape + + group = (ShapeGroup)shape[0]; + shape = group.getShapes(); + assertEquals(shape.length, 7); + } + +} 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 index 0000000000..400a66c6ee --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -0,0 +1,80 @@ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hslf.model; + +import junit.framework.TestCase; +import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.hslf.HSLFSlideShow; + +import java.awt.*; +import java.awt.Rectangle; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; + +/** + * Test drawing shapes via Graphics2D + * + * @author Yegor Kozlov + */ +public class TestShapes extends TestCase { + private SlideShow ppt; + + protected void setUp() throws Exception { + String dirname = System.getProperty("HSLF.testdata.path"); + String filename = dirname + "/empty.ppt"; + ppt = new SlideShow(new HSLFSlideShow(filename)); + getClass().getResourceAsStream(""); + } + + public void testGraphics() throws Exception { + Slide slide = ppt.createSlide(); + + Line line = new Line(); + line.setAnchor(new Rectangle(1296, 2544, 1344, 528)); + line.setLineWidth(3); + line.setLineStyle(Line.LineDashSys); + line.setLineColor(Color.red); + slide.addShape(line); + + Ellipse ellipse = new Ellipse(); + ellipse.setAnchor(new Rectangle(4000, 1000, 1000, 1000)); + ellipse.setLineWidth(2); + ellipse.setLineStyle(Line.LineSolid); + ellipse.setLineColor(Color.green); + ellipse.setFillColor(Color.lightGray); + slide.addShape(ellipse); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ppt.write(out); + out.close(); + + //read ppt from byte array + + ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()))); + assertEquals(ppt.getSlides().length, 1); + + slide = ppt.getSlides()[0]; + Shape[] shape = slide.getShapes(); + assertEquals(shape.length, 2); + + assertTrue(shape[0] instanceof Line); //group shape + assertEquals(shape[0].getAnchor(), new Rectangle(1296, 2544, 1344, 528)); //group shape + + assertTrue(shape[1] instanceof Ellipse); //group shape + assertEquals(shape[1].getAnchor(), new Rectangle(4000, 1000, 1000, 1000)); //group shape + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java index bd11a01beb..a9ed9e41c3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java @@ -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]);