use of org.apache.poi.hslf.usermodel.HSLFSlideShow 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.HSLFSlideShow 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();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestHeadersFooters method testRead2007.
/**
* Test extraction of headers / footers from PPTs saved in Office 2007
*/
@Test
public void testRead2007() throws IOException {
InputStream is = _slTests.openResourceAsStream("headers_footers_2007.ppt");
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible());
assertEquals("THE FOOTER TEXT", slideHdd.getFooterText());
assertTrue(slideHdd.isSlideNumberVisible());
assertFalse(slideHdd.isHeaderVisible());
assertNull(slideHdd.getHeaderText());
assertTrue(slideHdd.isUserDateVisible());
assertEquals("Wednesday, August 06, 2008", slideHdd.getDateTimeText());
HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
assertTrue(notesHdd.isFooterVisible());
assertEquals("THE NOTES FOOTER TEXT", notesHdd.getFooterText());
assertTrue(notesHdd.isHeaderVisible());
assertEquals("THE NOTES HEADER TEXT", notesHdd.getHeaderText());
assertTrue(notesHdd.isUserDateVisible());
assertTrue(notesHdd.isDateTimeVisible());
//TODO: depending on the formatId getDateTimeText() should return formatted date
//assertEquals("08/12/08", notesHdd.getDateTimeText());
//per-slide headers / footers
List<HSLFSlide> slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
HeadersFooters hd1 = slide.get(0).getHeadersFooters();
assertTrue(hd1.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd1.getFooterText());
assertTrue(hd1.isSlideNumberVisible());
assertFalse(hd1.isHeaderVisible());
assertNull(hd1.getHeaderText());
assertTrue(hd1.isUserDateVisible());
assertTrue(hd1.isDateTimeVisible());
assertEquals("Wednesday, August 06, 2008", hd1.getDateTimeText());
//the second slide uses custom per-slide headers / footers
HeadersFooters hd2 = slide.get(1).getHeadersFooters();
assertTrue(hd2.isFooterVisible());
assertEquals("THE FOOTER TEXT FOR SLIDE 2", hd2.getFooterText());
assertTrue(hd2.isSlideNumberVisible());
assertFalse(hd2.isHeaderVisible());
assertNull(hd2.getHeaderText());
assertTrue(hd2.isUserDateVisible());
assertTrue(hd2.isDateTimeVisible());
assertEquals("August 06, 2008", hd2.getDateTimeText());
//the third slide uses per-slide headers / footers
HeadersFooters hd3 = slide.get(2).getHeadersFooters();
assertTrue(hd3.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd3.getFooterText());
assertTrue(hd3.isSlideNumberVisible());
assertFalse(hd3.isHeaderVisible());
assertNull(hd3.getHeaderText());
assertTrue(hd3.isUserDateVisible());
assertTrue(hd3.isDateTimeVisible());
assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class HSLFTestDataSamples method writeOutAndReadBack.
/**
* Writes a slideshow to a <tt>ByteArrayOutputStream</tt> and reads it back
* from a <tt>ByteArrayInputStream</tt>.<p/>
* Useful for verifying that the serialisation round trip
*/
public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return new HSLFSlideShow(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestHyperlink method testTextRunHyperlinks.
@Test
public void testTextRunHyperlinks() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
List<HSLFTextParagraph> para = slide.getTextParagraphs().get(1);
String rawText = toExternalString(getRawText(para), para.get(0).getRunType());
String expected = "This page has two links:\n" + "http://jakarta.apache.org/poi/\n" + "\n" + "http://slashdot.org/\n" + "\n" + "In addition, its notes has one link";
assertEquals(expected, rawText);
List<HSLFHyperlink> links = findHyperlinks(para);
assertEquals(2, links.size());
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getLabel());
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getAddress());
assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex() - 1));
assertEquals("http://slashdot.org/", links.get(1).getLabel());
assertEquals("http://slashdot.org/", links.get(1).getAddress());
assertEquals("http://slashdot.org/", rawText.substring(links.get(1).getStartIndex(), links.get(1).getEndIndex() - 1));
slide = ppt.getSlides().get(1);
para = slide.getTextParagraphs().get(1);
rawText = toExternalString(getRawText(para), para.get(0).getRunType());
expected = "I have the one link:\n" + "Jakarta HSSF";
assertEquals(expected, rawText);
links.clear();
links = findHyperlinks(para);
assertNotNull(links);
assertEquals(1, links.size());
assertEquals("Open Jakarta POI HSSF module test ", links.get(0).getLabel());
assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getAddress());
assertEquals("Jakarta HSSF", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex() - 1));
ppt.close();
}
Aggregations