Search in sources :

Example 1 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project poi by apache.

the class HeadersFooters method getPlaceholderText.

private String getPlaceholderText(Placeholder ph, CString cs) {
    String text;
    if (_ppt2007) {
        HSLFSimpleShape ss = _sheet.getPlaceholder(ph);
        text = (ss instanceof HSLFTextShape) ? ((HSLFTextShape) ss).getText() : null;
        // default text in master placeholders is not visible
        if ("*".equals(text)) {
            text = null;
        }
    } else {
        text = (cs == null) ? null : cs.getText();
    }
    return text;
}
Also used : HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSimpleShape(org.apache.poi.hslf.usermodel.HSLFSimpleShape) CString(org.apache.poi.hslf.record.CString)

Example 2 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project tika by apache.

the class HSLFExtractor method extractMaster.

private void extractMaster(XHTMLContentHandler xhtml, HSLFMasterSheet master) throws SAXException {
    if (master == null) {
        return;
    }
    List<HSLFShape> shapes = master.getShapes();
    if (shapes == null || shapes.isEmpty()) {
        return;
    }
    xhtml.startElement("div", "class", "slide-master-content");
    for (HSLFShape shape : shapes) {
        if (shape != null && !HSLFMasterSheet.isPlaceholder(shape)) {
            if (shape instanceof HSLFTextShape) {
                HSLFTextShape tsh = (HSLFTextShape) shape;
                String text = tsh.getText();
                if (text != null) {
                    xhtml.element("p", text);
                }
            }
        }
    }
    xhtml.endElement("div");
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape)

Example 3 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project poi by apache.

the class TestXSLFTextShape method metroBlob.

@Test
public void metroBlob() throws IOException {
    assumeFalse(xslfOnly);
    File f = POIDataSamples.getSlideShowInstance().getFile("bug52297.ppt");
    SlideShow<?, ?> ppt = SlideShowFactory.create(f);
    HSLFTextShape sh = (HSLFTextShape) ppt.getSlides().get(1).getShapes().get(3);
    XSLFAutoShape xsh = (XSLFAutoShape) sh.getMetroShape();
    String textExp = " ___ ___ ___ ________ __  _______ ___  ___________  __________ __ _____ ___ ___ ___ _______ ____ ______ ___________  _____________ ___ _______ ______  ____ ______ __ ___________  __________ ___ _________  _____ ________ __________  ___ _______ __________ ";
    String textAct = xsh.getText();
    ppt.close();
    assertEquals(textExp, textAct);
}
Also used : HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) File(java.io.File) Test(org.junit.Test)

Example 4 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project poi by apache.

the class TestShapes method lineColor.

@Test
public void lineColor() throws IOException {
    HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream("51731.ppt"));
    List<HSLFShape> shape = ss.getSlides().get(0).getShapes();
    assertEquals(4, shape.size());
    HSLFTextShape sh1 = (HSLFTextShape) shape.get(0);
    assertEquals("Hello Apache POI", sh1.getText());
    assertNull(sh1.getLineColor());
    HSLFTextShape sh2 = (HSLFTextShape) shape.get(1);
    assertEquals("Why are you showing this border?", sh2.getText());
    assertNull(sh2.getLineColor());
    HSLFTextShape sh3 = (HSLFTextShape) shape.get(2);
    assertEquals("Text in a black border", sh3.getText());
    assertEquals(Color.black, sh3.getLineColor());
    assertEquals(0.75, sh3.getLineWidth(), 0);
    HSLFTextShape sh4 = (HSLFTextShape) shape.get(3);
    assertEquals("Border width is 5 pt", sh4.getText());
    assertEquals(Color.black, sh4.getLineColor());
    assertEquals(5.0, sh4.getLineWidth(), 0);
    ss.close();
}
Also used : HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Example 5 with HSLFTextShape

use of org.apache.poi.hslf.usermodel.HSLFTextShape in project poi by apache.

the class TestShapes method textBoxSet.

private void textBoxSet(String filename) throws IOException {
    HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(filename));
    for (HSLFSlide sld : ss.getSlides()) {
        ArrayList<String> lst1 = new ArrayList<String>();
        for (List<HSLFTextParagraph> txt : sld.getTextParagraphs()) {
            for (HSLFTextParagraph p : txt) {
                for (HSLFTextRun r : p) {
                    lst1.add(r.getRawText());
                }
            }
        }
        ArrayList<String> lst2 = new ArrayList<String>();
        for (HSLFShape sh : sld.getShapes()) {
            if (sh instanceof HSLFTextShape) {
                HSLFTextShape tbox = (HSLFTextShape) sh;
                for (HSLFTextParagraph p : tbox.getTextParagraphs()) {
                    for (HSLFTextRun r : p) {
                        lst2.add(r.getRawText());
                    }
                }
            }
        }
        assertTrue(lst1.containsAll(lst2));
        assertTrue(lst2.containsAll(lst1));
    }
    ss.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFShape(org.apache.poi.hslf.usermodel.HSLFShape) HSLFTextParagraph(org.apache.poi.hslf.usermodel.HSLFTextParagraph) ArrayList(java.util.ArrayList) HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide)

Aggregations

HSLFTextShape (org.apache.poi.hslf.usermodel.HSLFTextShape)7 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)4 HSLFSimpleShape (org.apache.poi.hslf.usermodel.HSLFSimpleShape)2 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Comment (org.apache.poi.hslf.model.Comment)1 HeadersFooters (org.apache.poi.hslf.model.HeadersFooters)1 CString (org.apache.poi.hslf.record.CString)1 HSLFNotes (org.apache.poi.hslf.usermodel.HSLFNotes)1 HSLFSlideMaster (org.apache.poi.hslf.usermodel.HSLFSlideMaster)1 HSLFTable (org.apache.poi.hslf.usermodel.HSLFTable)1 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)1 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)1