use of org.apache.poi.hslf.usermodel.HSLFTextParagraph in project poi by apache.
the class BulletsDemo method main.
public static void main(String[] args) throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
try {
HSLFSlide slide = ppt.createSlide();
HSLFTextBox shape = new HSLFTextBox();
HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
rt.getTextRuns().get(0).setFontSize(42d);
rt.setBullet(true);
//bullet offset
rt.setIndent(0d);
//text offset (should be greater than bullet offset)
rt.setLeftMargin(50d);
//bullet character
rt.setBulletChar('☺');
shape.setText("January\r" + "February\r" + "March\r" + "April");
slide.addShape(shape);
//position of the text box in the slide
shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));
slide.addShape(shape);
FileOutputStream out = new FileOutputStream("bullets.ppt");
ppt.write(out);
out.close();
} finally {
ppt.close();
}
}
use of org.apache.poi.hslf.usermodel.HSLFTextParagraph in project poi by apache.
the class TestSlideMaster method testIndentation.
/**
* Varify we can read attrubutes for different identtation levels.
* (typical for the "bullted body" placeholder)
*/
@Test
public void testIndentation() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
int[] indents = { 32, 28, 24 };
for (HSLFTextRun rt : tpara.getTextRuns()) {
int indent = tpara.getIndentLevel();
assertEquals(indents[indent], rt.getFontSize(), 0);
}
}
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFTextParagraph in project poi by apache.
the class TestSlideMaster method testMasterAttributes.
/**
* If a style attribute is not set ensure it is read from the master
*/
@Test
public void testMasterAttributes() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFSlide> slide = ppt.getSlides();
assertEquals(3, slide.size());
for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
assertEquals(32, rt.getFontSize(), 0);
assertEquals("Arial", rt.getFontFamily());
tpara = tparas.get(1);
rt = tpara.getTextRuns().get(0);
assertEquals(1, tpara.getIndentLevel());
assertEquals(28, rt.getFontSize(), 0);
assertEquals("Arial", rt.getFontFamily());
}
}
for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(48, rt.getFontSize(), 0);
assertEquals(true, rt.isItalic());
assertEquals("Georgia", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
HSLFTextRun rt;
rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
assertEquals(32, rt.getFontSize(), 0);
assertEquals("Courier New", rt.getFontFamily());
}
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFTextParagraph in project poi by apache.
the class TestTextRunReWrite method testWritesOutTheSameNonRich.
@Test
public void testWritesOutTheSameNonRich() throws IOException {
// Ensure the text lengths are as we'd expect to start with
assertEquals(1, ss.getSlides().size());
assertEquals(2, ss.getSlides().get(0).getTextParagraphs().size());
// Grab the first text run on the first sheet
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
List<HSLFTextParagraph> tr2 = ss.getSlides().get(0).getTextParagraphs().get(1);
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
assertEquals(1, tr1.size());
assertEquals(30, HSLFTextParagraph.getText(tr1).length());
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
// Set the text to be as it is now
HSLFTextParagraph.setText(tr1, HSLFTextParagraph.getRawText(tr1));
tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
// Check the text lengths are still right
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(179, HSLFTextParagraph.getRawText(tr2).length());
assertEquals(1, tr1.size());
assertEquals(30, HSLFTextParagraph.getText(tr1).length());
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(31, tr1.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
// Write the slideshow out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ss.write(baos);
// Build an input stream of it
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// Use POIFS to query that lot
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
DocumentEntry oProps = (DocumentEntry) oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
assertArrayEquals(_oData, _nData);
npfs.close();
}
use of org.apache.poi.hslf.usermodel.HSLFTextParagraph in project poi by apache.
the class TestTextRunReWrite method testWritesOutTheSameRich.
@Test
public void testWritesOutTheSameRich() throws IOException {
// Grab the first text run on the first sheet
List<HSLFTextParagraph> tr1 = ss.getSlides().get(0).getTextParagraphs().get(0);
// Get the first rich text run
HSLFTextRun rtr1 = tr1.get(0).getTextRuns().get(0);
// Check that the text sizes are as expected
assertEquals(1, tr1.get(0).getTextRuns().size());
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(30, rtr1.getLength());
assertEquals(30, rtr1.getRawText().length());
assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
// Set the text to be as it is now
rtr1.setText(rtr1.getRawText());
rtr1 = tr1.get(0).getTextRuns().get(0);
// Check that the text sizes are still as expected
assertEquals(1, tr1.get(0).getTextRuns().size());
assertEquals(30, HSLFTextParagraph.getRawText(tr1).length());
assertEquals(30, tr1.get(0).getTextRuns().get(0).getRawText().length());
assertEquals(30, rtr1.getLength());
assertEquals(30, rtr1.getRawText().length());
assertEquals(31, rtr1.getCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.get(0).getParagraphStyle().getCharactersCovered());
// Write the slideshow out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ss.write(baos);
// Build an input stream of it
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// Use POIFS to query that lot
POIFSFileSystem npfs = new POIFSFileSystem(bais);
// Check that the "PowerPoint Document" sections have the same size
DirectoryNode oDir = ss.getSlideShowImpl().getDirectory();
DocumentEntry oProps = (DocumentEntry) oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
// Check that they contain the same data
byte[] _oData = new byte[oProps.getSize()];
byte[] _nData = new byte[nProps.getSize()];
oDir.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_oData);
npfs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT).read(_nData);
assertArrayEquals(_oData, _nData);
npfs.close();
}
Aggregations