Search in sources :

Example 1 with PPDrawing

use of org.apache.poi.hslf.record.PPDrawing in project poi by apache.

the class HSLFTextShape method getEscherTextboxWrapper.

protected EscherTextboxWrapper getEscherTextboxWrapper() {
    if (_txtbox != null) {
        return _txtbox;
    }
    EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID);
    if (textRecord == null) {
        return null;
    }
    HSLFSheet sheet = getSheet();
    if (sheet != null) {
        PPDrawing drawing = sheet.getPPDrawing();
        if (drawing != null) {
            EscherTextboxWrapper[] wrappers = drawing.getTextboxWrappers();
            if (wrappers != null) {
                for (EscherTextboxWrapper w : wrappers) {
                    // check for object identity
                    if (textRecord == w.getEscherRecord()) {
                        _txtbox = w;
                        return _txtbox;
                    }
                }
            }
        }
    }
    _txtbox = new EscherTextboxWrapper(textRecord);
    return _txtbox;
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper)

Example 2 with PPDrawing

use of org.apache.poi.hslf.record.PPDrawing in project poi by apache.

the class TestSheet method verify.

private void verify(HSLFSheet sheet) {
    assertNotNull(sheet.getSlideShow());
    ColorSchemeAtom colorscheme = sheet.getColorScheme();
    assertNotNull(colorscheme);
    PPDrawing ppdrawing = sheet.getPPDrawing();
    assertNotNull(ppdrawing);
    HSLFBackground background = sheet.getBackground();
    assertNotNull(background);
    assertTrue(sheet._getSheetNumber() != 0);
    assertTrue(sheet._getSheetRefId() != 0);
    List<List<HSLFTextParagraph>> txt = sheet.getTextParagraphs();
    // backgrounds.ppt has no texts
    for (List<HSLFTextParagraph> t : txt) {
        for (HSLFTextParagraph tp : t) {
            assertNotNull(tp.getSheet());
        }
    }
    List<HSLFShape> shape = sheet.getShapes();
    assertTrue("no shapes", shape != null && !shape.isEmpty());
    for (HSLFShape s : shape) {
        assertNotNull(s.getSpContainer());
        assertNotNull(s.getSheet());
        assertNotNull(s.getShapeName());
        assertNotNull(s.getAnchor());
    }
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) ColorSchemeAtom(org.apache.poi.hslf.record.ColorSchemeAtom) List(java.util.List)

Example 3 with PPDrawing

use of org.apache.poi.hslf.record.PPDrawing in project poi by apache.

the class PPDrawingTextListing method main.

public static void main(String[] args) throws IOException {
    if (args.length < 1) {
        System.err.println("Need to give a filename");
        System.exit(1);
    }
    HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
    // Find PPDrawings at any second level position
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        Record[] children = records[i].getChildRecords();
        if (children != null && children.length != 0) {
            for (int j = 0; j < children.length; j++) {
                if (children[j] instanceof PPDrawing) {
                    System.out.println("Found PPDrawing at " + j + " in top level record " + i + " (" + records[i].getRecordType() + ")");
                    // Look for EscherTextboxWrapper's
                    PPDrawing ppd = (PPDrawing) children[j];
                    EscherTextboxWrapper[] wrappers = ppd.getTextboxWrappers();
                    System.out.println("  Has " + wrappers.length + " textbox wrappers within");
                    // Loop over the wrappers, showing what they contain
                    for (int k = 0; k < wrappers.length; k++) {
                        EscherTextboxWrapper tbw = wrappers[k];
                        System.out.println("    " + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
                        // Loop over the records, printing the text
                        Record[] pptatoms = tbw.getChildRecords();
                        for (int l = 0; l < pptatoms.length; l++) {
                            String text = null;
                            if (pptatoms[l] instanceof TextBytesAtom) {
                                TextBytesAtom tba = (TextBytesAtom) pptatoms[l];
                                text = tba.getText();
                            }
                            if (pptatoms[l] instanceof TextCharsAtom) {
                                TextCharsAtom tca = (TextCharsAtom) pptatoms[l];
                                text = tca.getText();
                            }
                            if (text != null) {
                                text = text.replace('\r', '\n');
                                System.out.println("        ''" + text + "''");
                            }
                        }
                    }
                }
            }
        }
    }
    ss.close();
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 4 with PPDrawing

use of org.apache.poi.hslf.record.PPDrawing in project poi by apache.

the class HSLFSheet method removeShape.

/**
     * Removes the specified shape from this sheet.
     *
     * @param shape shape to be removed from this sheet, if present.
     * @return <tt>true</tt> if the shape was deleted.
     */
@Override
public boolean removeShape(HSLFShape shape) {
    PPDrawing ppdrawing = getPPDrawing();
    EscherContainerRecord dg = ppdrawing.getDgContainer();
    EscherContainerRecord spgr = dg.getChildById(EscherContainerRecord.SPGR_CONTAINER);
    if (spgr == null) {
        return false;
    }
    List<EscherRecord> lst = spgr.getChildRecords();
    boolean result = lst.remove(shape.getSpContainer());
    spgr.setChildRecords(lst);
    return result;
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 5 with PPDrawing

use of org.apache.poi.hslf.record.PPDrawing in project poi by apache.

the class HSLFSheet method addShape.

/**
     * Add a new Shape to this Slide
     *
     * @param shape - the Shape to add
     */
@Override
public void addShape(HSLFShape shape) {
    PPDrawing ppdrawing = getPPDrawing();
    EscherContainerRecord dgContainer = ppdrawing.getDgContainer();
    EscherContainerRecord spgr = (EscherContainerRecord) HSLFShape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER);
    spgr.addChildRecord(shape.getSpContainer());
    shape.setSheet(this);
    shape.setShapeId(allocateShapeId());
    shape.afterInsert(this);
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Aggregations

PPDrawing (org.apache.poi.hslf.record.PPDrawing)8 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)4 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)3 EscherRecord (org.apache.poi.ddf.EscherRecord)2 Rectangle2D (java.awt.geom.Rectangle2D)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)1 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 ColorSchemeAtom (org.apache.poi.hslf.record.ColorSchemeAtom)1 Record (org.apache.poi.hslf.record.Record)1 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)1 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)1 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)1