Author: nick Date: Sun Mar 19 09:54:17 2006 New Revision: 387009 URL: http://svn.apache.org/viewcvs?rev=387009&view=rev Log: Add Yegor's new slide functionality (see bug 38954), with a bit of refactoring
Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt (with props) jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt?rev=387009&view=auto ============================================================================== Binary file - no diff available. Propchange: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java?rev=387009&view=auto ============================================================================== --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java (added) +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java Sun Mar 19 09:54:17 2006 @@ -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); + } + +} Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java?rev=387009&view=auto ============================================================================== --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java (added) +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java Sun Mar 19 09:54:17 2006 @@ -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 + } + +} Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java?rev=387009&r1=387008&r2=387009&view=diff ============================================================================== --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java (original) +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java Sun Mar 19 09:54:17 2006 @@ -37,24 +37,30 @@ } 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]); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta POI Project: http://jakarta.apache.org/poi/