TestBackgroundpublic class TestBackground extends TestCase
Methods Summary |
---|
public void | testBackgroundPicture()Create a ppt with various fill effects
SlideShow ppt = new SlideShow();
Slide slide;
Fill fill;
Shape shape;
int idx;
//slide 1
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_PICTURE);
fill.setPictureData(idx);
shape = new AutoShape(ShapeTypes.Rectangle);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(Fill.FILL_SOLID);
slide.addShape(shape);
//slide 2
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_PATTERN);
fill.setPictureData(idx);
fill.setBackgroundColor(Color.green);
fill.setForegroundColor(Color.red);
shape = new AutoShape(ShapeTypes.Rectangle);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(Fill.FILL_BACKGROUND);
slide.addShape(shape);
//slide 3
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
fill.setFillType(Fill.FILL_TEXTURE);
fill.setPictureData(idx);
shape = new AutoShape(ShapeTypes.Rectangle);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(Fill.FILL_PICTURE);
idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/clock.jpg"), Picture.JPEG);
fill.setPictureData(idx);
slide.addShape(shape);
// slide 4
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
fill.setFillType(Fill.FILL_SHADE_CENTER);
fill.setBackgroundColor(Color.white);
fill.setForegroundColor(Color.darkGray);
shape = new AutoShape(ShapeTypes.Rectangle);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(Fill.FILL_SHADE);
fill.setBackgroundColor(Color.red);
fill.setForegroundColor(Color.green);
slide.addShape(shape);
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
out.close();
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
Slide[] slides = ppt.getSlides();
fill = slides[0].getBackground().getFill();
assertEquals(Fill.FILL_PICTURE, fill.getFillType());
shape = slides[0].getShapes()[0];
assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
fill = slides[1].getBackground().getFill();
assertEquals(Fill.FILL_PATTERN, fill.getFillType());
shape = slides[1].getShapes()[0];
assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slides[2].getBackground().getFill();
assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
shape = slides[2].getShapes()[0];
assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
fill = slides[3].getBackground().getFill();
assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
shape = slides[3].getShapes()[0];
assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
| public void | testDefaults()Default background for slide, shape and slide master.
SlideShow ppt = new SlideShow();
assertEquals(Fill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
Slide slide = ppt.createSlide();
assertTrue(slide.getFollowMasterBackground());
assertEquals(Fill.FILL_SOLID, slide.getBackground().getFill().getFillType());
Shape shape = new AutoShape(ShapeTypes.Rectangle);
assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
| public void | testReadBackground()Read fill information from an reference ppt file
SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/backgrounds.ppt"));
Fill fill;
Shape shape;
Slide[] slide = ppt.getSlides();
fill = slide[0].getBackground().getFill();
assertEquals(Fill.FILL_PICTURE, fill.getFillType());
shape = slide[0].getShapes()[0];
assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
fill = slide[1].getBackground().getFill();
assertEquals(Fill.FILL_PATTERN, fill.getFillType());
shape = slide[1].getShapes()[0];
assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slide[2].getBackground().getFill();
assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
shape = slide[2].getShapes()[0];
assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
fill = slide[3].getBackground().getFill();
assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
shape = slide[3].getShapes()[0];
assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
|
|