Search in sources :

Example 1 with ShapeType

use of org.apache.poi.sl.usermodel.ShapeType in project poi by apache.

the class TestTextShape method read.

/**
     * Verify we can get text from TextShape in the following cases:
     *  - placeholders
     *  - normal TextBox object
     *  - text in auto-shapes
     */
@Test
public void read() throws IOException {
    HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("text_shapes.ppt");
    List<String> lst1 = new ArrayList<String>();
    HSLFSlide slide = ppt.getSlides().get(0);
    for (HSLFShape shape : slide.getShapes()) {
        assertTrue("Expected TextShape but found " + shape.getClass().getName(), shape instanceof HSLFTextShape);
        HSLFTextShape tx = (HSLFTextShape) shape;
        List<HSLFTextParagraph> paras = tx.getTextParagraphs();
        assertNotNull(paras);
        int runType = paras.get(0).getRunType();
        ShapeType type = shape.getShapeType();
        String rawText = HSLFTextParagraph.getRawText(paras);
        switch(type) {
            case TEXT_BOX:
                assertEquals("Text in a TextBox", rawText);
                break;
            case RECT:
                if (runType == TextHeaderAtom.OTHER_TYPE) {
                    assertEquals("Rectangle", rawText);
                } else if (runType == TextHeaderAtom.TITLE_TYPE) {
                    assertEquals("Title Placeholder", rawText);
                }
                break;
            case OCTAGON:
                assertEquals("Octagon", rawText);
                break;
            case ELLIPSE:
                assertEquals("Ellipse", rawText);
                break;
            case ROUND_RECT:
                assertEquals("RoundRectangle", rawText);
                break;
            default:
                fail("Unexpected shape: " + shape.getShapeName());
        }
        lst1.add(rawText);
    }
    List<String> lst2 = new ArrayList<String>();
    for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
        lst2.add(HSLFTextParagraph.getRawText(paras));
    }
    assertTrue(lst1.containsAll(lst2));
    ppt.close();
}
Also used : ShapeType(org.apache.poi.sl.usermodel.ShapeType) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ShapeType

use of org.apache.poi.sl.usermodel.ShapeType in project poi by apache.

the class HSLFSimpleShape method getGeometry.

@Override
public CustomGeometry getGeometry() {
    PresetGeometries dict = PresetGeometries.getInstance();
    ShapeType st = getShapeType();
    String name = (st != null) ? st.getOoxmlName() : null;
    CustomGeometry geom = dict.get(name);
    if (geom == null) {
        if (name == null) {
            name = (st != null) ? st.toString() : "<unknown>";
        }
        LOG.log(POILogger.WARN, "No preset shape definition for shapeType: " + name);
    }
    return geom;
}
Also used : ShapeType(org.apache.poi.sl.usermodel.ShapeType) PresetGeometries(org.apache.poi.sl.draw.geom.PresetGeometries) CustomGeometry(org.apache.poi.sl.draw.geom.CustomGeometry)

Example 3 with ShapeType

use of org.apache.poi.sl.usermodel.ShapeType in project poi by apache.

the class HSLFShapeFactory method createSimpleShape.

public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape, HSLFTextParagraph> parent) {
    HSLFShape shape = null;
    EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
    ShapeType type = ShapeType.forId(spRecord.getShapeType(), false);
    switch(type) {
        case TEXT_BOX:
            shape = new HSLFTextBox(spContainer, parent);
            break;
        case HOST_CONTROL:
        case FRAME:
            shape = createFrame(spContainer, parent);
            break;
        case LINE:
            shape = new HSLFLine(spContainer, parent);
            break;
        case NOT_PRIMITIVE:
            shape = createNonPrimitive(spContainer, parent);
            break;
        default:
            if (parent instanceof HSLFTable) {
                EscherTextboxRecord etr = spContainer.getChildById(EscherTextboxRecord.RECORD_ID);
                if (etr == null) {
                    logger.log(POILogger.WARN, "invalid ppt - add EscherTextboxRecord to cell");
                    etr = new EscherTextboxRecord();
                    etr.setRecordId(EscherTextboxRecord.RECORD_ID);
                    etr.setOptions((short) 15);
                    spContainer.addChildRecord(etr);
                }
                shape = new HSLFTableCell(spContainer, (HSLFTable) parent);
            } else {
                shape = new HSLFAutoShape(spContainer, parent);
            }
            break;
    }
    return shape;
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) ShapeType(org.apache.poi.sl.usermodel.ShapeType) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord)

Example 4 with ShapeType

use of org.apache.poi.sl.usermodel.ShapeType in project poi by apache.

the class TestXSLFAutoShape method testShapeType.

@Test
public void testShapeType() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    XSLFAutoShape shape = slide.createAutoShape();
    assertEquals(ShapeType.RECT, shape.getShapeType());
    shape.setShapeType(ShapeType.TRIANGLE);
    assertEquals(ShapeType.TRIANGLE, shape.getShapeType());
    for (ShapeType tp : ShapeType.values()) {
        if (tp.ooxmlId == -1 || tp == ShapeType.SEAL)
            continue;
        shape.setShapeType(tp);
        assertEquals(tp, shape.getShapeType());
    }
    ppt.close();
}
Also used : ShapeType(org.apache.poi.sl.usermodel.ShapeType) Test(org.junit.Test)

Aggregations

ShapeType (org.apache.poi.sl.usermodel.ShapeType)4 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)1 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)1 CustomGeometry (org.apache.poi.sl.draw.geom.CustomGeometry)1 PresetGeometries (org.apache.poi.sl.draw.geom.PresetGeometries)1