use of org.apache.poi.hslf.usermodel.HSLFFill in project poi by apache.
the class TestBackground method backgroundPicture.
/**
* Create a ppt with various fill effects
*/
@Test
public void backgroundPicture() throws IOException {
HSLFSlideShow ppt1 = new HSLFSlideShow();
HSLFSlide slide;
HSLFFill fill;
HSLFShape shape;
HSLFPictureData data;
//slide 1
slide = ppt1.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_PICTURE);
fill.setPictureData(data);
shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(HSLFFill.FILL_SOLID);
slide.addShape(shape);
//slide 2
slide = ppt1.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_PATTERN);
fill.setPictureData(data);
fill.setBackgroundColor(Color.green);
fill.setForegroundColor(Color.red);
shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(HSLFFill.FILL_BACKGROUND);
slide.addShape(shape);
//slide 3
slide = ppt1.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
data = ppt1.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
fill.setFillType(HSLFFill.FILL_TEXTURE);
fill.setPictureData(data);
shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(HSLFFill.FILL_PICTURE);
data = ppt1.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
fill.setPictureData(data);
slide.addShape(shape);
// slide 4
slide = ppt1.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
fill.setFillType(HSLFFill.FILL_SHADE_CENTER);
fill.setBackgroundColor(Color.white);
fill.setForegroundColor(Color.darkGray);
shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
fill.setFillType(HSLFFill.FILL_SHADE);
fill.setBackgroundColor(Color.red);
fill.setForegroundColor(Color.green);
slide.addShape(shape);
//serialize and read again
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
List<HSLFSlide> slides = ppt2.getSlides();
fill = slides.get(0).getBackground().getFill();
assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
assertEquals(3, getFillPictureRefCount(slides.get(0).getBackground(), fill));
shape = slides.get(0).getShapes().get(0);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
fill = slides.get(1).getBackground().getFill();
assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
shape = slides.get(1).getShapes().get(0);
assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slides.get(2).getBackground().getFill();
assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
assertEquals(3, getFillPictureRefCount(slides.get(2).getBackground(), fill));
shape = slides.get(2).getShapes().get(0);
assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
assertEquals(1, getFillPictureRefCount(shape, fill));
fill = slides.get(3).getBackground().getFill();
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slides.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
ppt2.close();
ppt1.close();
}
use of org.apache.poi.hslf.usermodel.HSLFFill in project poi by apache.
the class TestBackground method readBackground.
/**
* Read fill information from an reference ppt file
*/
@Test
public void readBackground() throws IOException {
HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("backgrounds.ppt");
HSLFFill fill;
HSLFShape shape;
List<HSLFSlide> slide = ppt.getSlides();
fill = slide.get(0).getBackground().getFill();
assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
shape = slide.get(0).getShapes().get(0);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
fill = slide.get(1).getBackground().getFill();
assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
shape = slide.get(1).getShapes().get(0);
assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slide.get(2).getBackground().getFill();
assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
shape = slide.get(2).getShapes().get(0);
assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
fill = slide.get(3).getBackground().getFill();
assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slide.get(3).getShapes().get(0);
assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
ppt.close();
}
Aggregations