use of org.apache.poi.hslf.usermodel.HSLFAutoShape in project poi by apache.
the class TestShapes method lineWidth.
@Test
public void lineWidth() {
HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE);
AbstractEscherOptRecord opt = sh.getEscherOptRecord();
EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNull(prop);
assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);
sh.setLineWidth(1.0);
prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNotNull(prop);
assertEquals(1.0, sh.getLineWidth(), 0);
}
use of org.apache.poi.hslf.usermodel.HSLFAutoShape 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.HSLFAutoShape in project poi by apache.
the class TestShapes method graphics.
@Test
public void graphics() throws IOException {
HSLFSlide slide = ppt.createSlide();
HSLFLine line = new HSLFLine();
java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
line.setAnchor(lineAnchor);
line.setLineWidth(3);
line.setLineDash(LineDash.DASH);
line.setLineColor(Color.red);
slide.addShape(line);
HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
ellipse.setAnchor(ellipseAnchor);
ellipse.setLineWidth(2);
ellipse.setLineDash(LineDash.SOLID);
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
HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
assertEquals(1, ppt2.getSlides().size());
slide = ppt2.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(2, shape.size());
//group shape
assertTrue(shape.get(0) instanceof HSLFLine);
//group shape
assertEquals(lineAnchor, shape.get(0).getAnchor());
//group shape
assertTrue(shape.get(1) instanceof HSLFAutoShape);
//group shape
assertEquals(ellipseAnchor, shape.get(1).getAnchor());
ppt2.close();
}
use of org.apache.poi.hslf.usermodel.HSLFAutoShape in project poi by apache.
the class TestBackground method defaults.
/**
* Default background for slide, shape and slide master.
*/
@Test
public void defaults() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(HSLFFill.FILL_SOLID, ppt.getSlideMasters().get(0).getBackground().getFill().getFillType());
HSLFSlide slide = ppt.createSlide();
assertTrue(slide.getFollowMasterBackground());
assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType());
HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
ppt.close();
}
Aggregations