use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestLine method testCreateLines.
@Test
public void testCreateLines() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
slide.addTitle().setText("Lines tester");
HSLFLine line;
/**
* line styles
*/
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 200, 300, 0));
line.setLineCompound(LineCompound.SINGLE);
line.setLineColor(Color.blue);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
line.setLineCompound(LineCompound.DOUBLE);
line.setLineWidth(3.5);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
line.setLineCompound(LineCompound.TRIPLE);
line.setLineWidth(6);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
line.setLineCompound(LineCompound.THICK_THIN);
line.setLineWidth(4.5);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
line.setLineCompound(LineCompound.THIN_THICK);
line.setLineWidth(5.5);
slide.addShape(line);
/**
* line dashing
*/
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
line.setLineDash(LineDash.SOLID);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
line.setLineDash(LineDash.DASH);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
line.setLineDash(LineDash.DOT);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
line.setLineDash(LineDash.DASH_DOT);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
line.setLineDash(LineDash.LG_DASH_DOT_DOT);
slide.addShape(line);
/**
* Combinations
*/
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
line.setLineDash(LineDash.DASH_DOT);
line.setLineCompound(LineCompound.TRIPLE);
line.setLineWidth(5.0);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
line.setLineDash(LineDash.DASH);
line.setLineCompound(LineCompound.THICK_THIN);
line.setLineWidth(4.0);
slide.addShape(line);
line = new HSLFLine();
line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
line.setLineDash(LineDash.DOT);
line.setLineCompound(LineCompound.DOUBLE);
line.setLineWidth(8.0);
slide.addShape(line);
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestOleEmbedding method testEmbedding.
@Test
public void testEmbedding() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
HSLFPictureData pictData = ppt.addPicture(pict, PictureType.JPEG);
InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("Employee.xls");
POIFSFileSystem poiData1 = new POIFSFileSystem(is);
is.close();
int oleObjectId1 = ppt.addEmbed(poiData1);
HSLFSlide slide1 = ppt.createSlide();
OLEShape oleShape1 = new OLEShape(pictData);
oleShape1.setObjectID(oleObjectId1);
slide1.addShape(oleShape1);
oleShape1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
// add second slide with different order in object creation
HSLFSlide slide2 = ppt.createSlide();
OLEShape oleShape2 = new OLEShape(pictData);
is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleWithImages.xls");
POIFSFileSystem poiData2 = new POIFSFileSystem(is);
is.close();
int oleObjectId2 = ppt.addEmbed(poiData2);
oleShape2.setObjectID(oleObjectId2);
slide2.addShape(oleShape2);
oleShape2.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt.write(bos);
ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
OLEShape comp = (OLEShape) ppt.getSlides().get(0).getShapes().get(0);
byte[] compData = IOUtils.toByteArray(comp.getObjectData().getData());
bos.reset();
poiData1.writeFilesystem(bos);
byte[] expData = bos.toByteArray();
assertArrayEquals(expData, compData);
poiData1.close();
poiData2.close();
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestOleEmbedding method testOLEShape.
@Test
public void testOLEShape() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
int cnt = 0;
for (HSLFShape sh : slide.getShapes()) {
if (sh instanceof OLEShape) {
cnt++;
OLEShape ole = (OLEShape) sh;
HSLFObjectData data = ole.getObjectData();
if ("Worksheet".equals(ole.getInstanceName())) {
//Voila! we created a workbook from the embedded OLE data
HSSFWorkbook wb = new HSSFWorkbook(data.getData());
HSSFSheet sheet = wb.getSheetAt(0);
//verify we can access the xls data
assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0);
assertEquals(1, sheet.getRow(1).getCell(0).getNumericCellValue(), 0);
assertEquals(2, sheet.getRow(2).getCell(0).getNumericCellValue(), 0);
assertEquals(3, sheet.getRow(3).getCell(0).getNumericCellValue(), 0);
assertEquals(8, sheet.getRow(5).getCell(0).getNumericCellValue(), 0);
wb.close();
} else if ("Document".equals(ole.getInstanceName())) {
//creating a HWPF document
HWPFDocument doc = new HWPFDocument(data.getData());
String txt = doc.getRange().getParagraph(0).text();
assertEquals("OLE embedding is thoroughly unremarkable.\r", txt);
doc.close();
}
}
}
assertEquals("Expected 2 OLE shapes", 2, cnt);
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSlideMaster method testTitleMasterTextAttributes.
/**
* Test we can read default text attributes for a title master sheet
*/
@Test
public void testTitleMasterTextAttributes() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFTitleMaster> master = ppt.getTitleMasters();
assertEquals(1, master.size());
assertEquals(32, master.get(0).getStyleAttribute(TextHeaderAtom.CENTER_TITLE_TYPE, 0, "font.size", true).getValue());
CharFlagsTextProp prop1 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.CENTER_TITLE_TYPE, 0, "char_flags", true);
assertEquals(true, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
assertEquals(20, master.get(0).getStyleAttribute(TextHeaderAtom.CENTRE_BODY_TYPE, 0, "font.size", true).getValue());
CharFlagsTextProp prop2 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.CENTRE_BODY_TYPE, 0, "char_flags", true);
assertEquals(true, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSlideMaster method testTitleMaster.
/**
* Slide 3 has title layout and follows the TitleMaster. Verify that.
*/
@Test
public void testTitleMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
HSLFSlide slide = ppt.getSlides().get(2);
HSLFMasterSheet masterSheet = slide.getMasterSheet();
assertTrue(masterSheet instanceof HSLFTitleMaster);
for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
switch(txt.get(0).getRunType()) {
case TextHeaderAtom.CENTER_TITLE_TYPE:
assertEquals("Arial", rt.getFontFamily());
assertEquals(32, rt.getFontSize(), 0);
assertEquals(true, rt.isBold());
assertEquals(true, rt.isUnderlined());
break;
case TextHeaderAtom.CENTRE_BODY_TYPE:
assertEquals("Courier New", rt.getFontFamily());
assertEquals(20, rt.getFontSize(), 0);
assertEquals(true, rt.isBold());
assertEquals(false, rt.isUnderlined());
break;
}
}
ppt.close();
}
Aggregations