From 432637b15ab52cd35a84d183e8710ba249600b06 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 19 Mar 2006 17:54:17 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/hslf/data/empty.ppt | Bin 0 -> 10240 bytes .../poi/hslf/model/TestPPGraphics2D.java | 88 ++++++++++++++++++ .../org/apache/poi/hslf/model/TestShapes.java | 80 ++++++++++++++++ .../poi/hslf/record/TestRecordContainer.java | 18 ++-- 4 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.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 index 0000000000000000000000000000000000000000..23e1e94ca8a5d1888d35fd89f307c4b01e57e059 GIT binary patch literal 10240 zcmeHNYiu0V6+Sbw_O9)9cGq@HNJugX0RkkcYllKh3r=GKDcEs|DWxyGc*oAd?vAq$ zJ3*j238hpO5(w&&7M1X-fJzmQN=>0{ETyzijGzyy6qGhqKuV)ZI6w;olI{21yJI%? zE;x?=AaSj4?w$KM_nhyZ`}r48vG$w?9=)T(?~DyG48h%%{1`I^U;TuDbpsF3xlpQJ>U?Q79r zFM3a-?Okp8s z2hISN0%rne z0cQitfaSmn;8Q>o@M)kKXaQCN=Kx%b&P9A4@LAwJJoH-T>f zR|DNZ6u1WH0b+my^a6dr1|Sa5p6d`NfFwYFbb)?gBf#=ZA*K%;PYB5Y>l};w_`fak zJ%T~AF_`#!gVuL#e^W6q#u9{)ACAM;>-0*Up#DIZ6)HDUy6oGk5_ts*VDfxjA^%zpD(L#|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@Ft8e*J<|Bo|7T(2uAD(SJ!Nj@!V7ty_QF&e aQu;?O3{w$QsN?m`_&A!)Sk;en|NjRt)FYw* literal 0 HcmV?d00001 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]); -- 2.39.5