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
This commit is contained in:
parent
a193016805
commit
71eda449e6
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt
Normal file
BIN
src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt
Normal file
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user