Search in sources :

Example 6 with TextCharsAtom

use of org.apache.poi.hslf.record.TextCharsAtom 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 7 with TextCharsAtom

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

the class HSLFTextShape method createEmptyParagraph.

private void createEmptyParagraph() {
    TextHeaderAtom tha = (TextHeaderAtom) _txtbox.findFirstOfType(TextHeaderAtom._type);
    if (tha == null) {
        tha = new TextHeaderAtom();
        tha.setParentRecord(_txtbox);
        _txtbox.appendChildRecord(tha);
    }
    TextBytesAtom tba = (TextBytesAtom) _txtbox.findFirstOfType(TextBytesAtom._type);
    TextCharsAtom tca = (TextCharsAtom) _txtbox.findFirstOfType(TextCharsAtom._type);
    if (tba == null && tca == null) {
        tba = new TextBytesAtom();
        tba.setText(new byte[0]);
        _txtbox.appendChildRecord(tba);
    }
    final String text = ((tba != null) ? tba.getText() : tca.getText());
    StyleTextPropAtom sta = (StyleTextPropAtom) _txtbox.findFirstOfType(StyleTextPropAtom._type);
    TextPropCollection paraStyle = null, charStyle = null;
    if (sta == null) {
        int parSiz = text.length();
        sta = new StyleTextPropAtom(parSiz + 1);
        if (_paragraphs.isEmpty()) {
            paraStyle = sta.addParagraphTextPropCollection(parSiz + 1);
            charStyle = sta.addCharacterTextPropCollection(parSiz + 1);
        } else {
            for (HSLFTextParagraph htp : _paragraphs) {
                int runsLen = 0;
                for (HSLFTextRun htr : htp.getTextRuns()) {
                    runsLen += htr.getLength();
                    charStyle = sta.addCharacterTextPropCollection(htr.getLength());
                    htr.setCharacterStyle(charStyle);
                }
                paraStyle = sta.addParagraphTextPropCollection(runsLen);
                htp.setParagraphStyle(paraStyle);
            }
            assert (paraStyle != null && charStyle != null);
        }
        _txtbox.appendChildRecord(sta);
    } else {
        paraStyle = sta.getParagraphStyles().get(0);
        charStyle = sta.getCharacterStyles().get(0);
    }
    if (_paragraphs.isEmpty()) {
        HSLFTextParagraph htp = new HSLFTextParagraph(tha, tba, tca, _paragraphs);
        htp.setParagraphStyle(paraStyle);
        htp.setParentShape(this);
        _paragraphs.add(htp);
        HSLFTextRun htr = new HSLFTextRun(htp);
        htr.setCharacterStyle(charStyle);
        htr.setText(text);
        htp.addTextRun(htr);
    }
}
Also used : TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 8 with TextCharsAtom

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

the class TextStyleListing 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 the documents, and then their SLWT
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        if (records[i].getRecordType() == 1000l) {
            Record docRecord = records[i];
            Record[] docChildren = docRecord.getChildRecords();
            for (int j = 0; j < docChildren.length; j++) {
                if (docChildren[j] instanceof SlideListWithText) {
                    Record[] slwtChildren = docChildren[j].getChildRecords();
                    int lastTextLen = -1;
                    for (int k = 0; k < slwtChildren.length; k++) {
                        if (slwtChildren[k] instanceof TextCharsAtom) {
                            lastTextLen = ((TextCharsAtom) slwtChildren[k]).getText().length();
                        }
                        if (slwtChildren[k] instanceof TextBytesAtom) {
                            lastTextLen = ((TextBytesAtom) slwtChildren[k]).getText().length();
                        }
                        if (slwtChildren[k] instanceof StyleTextPropAtom) {
                            StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChildren[k];
                            stpa.setParentTextSize(lastTextLen);
                            showStyleTextPropAtom(stpa);
                        }
                    }
                }
            }
        }
    }
    ss.close();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 9 with TextCharsAtom

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

the class SLWTTextListing 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 the documents, and then their SLWT
    Record[] records = ss.getRecords();
    for (int i = 0; i < records.length; i++) {
        if (records[i] instanceof Document) {
            Record docRecord = records[i];
            Record[] docChildren = docRecord.getChildRecords();
            for (int j = 0; j < docChildren.length; j++) {
                if (docChildren[j] instanceof SlideListWithText) {
                    System.out.println("Found SLWT at pos " + j + " in the Document at " + i);
                    System.out.println("  Has " + docChildren[j].getChildRecords().length + " children");
                    // Grab the SlideAtomSet's, which contain
                    //  a SlidePersistAtom and then a bunch of text
                    //  + related records
                    SlideListWithText slwt = (SlideListWithText) docChildren[j];
                    SlideListWithText.SlideAtomsSet[] thisSets = slwt.getSlideAtomsSets();
                    System.out.println("  Has " + thisSets.length + " AtomSets in it");
                    // Loop over the sets, showing what they contain
                    for (int k = 0; k < thisSets.length; k++) {
                        SlidePersistAtom spa = thisSets[k].getSlidePersistAtom();
                        System.out.println("    " + k + " has slide id " + spa.getSlideIdentifier());
                        System.out.println("    " + k + " has ref id " + spa.getRefID());
                        // Loop over the records, printing the text
                        Record[] slwtc = thisSets[k].getSlideRecords();
                        for (int l = 0; l < slwtc.length; l++) {
                            String text = null;
                            if (slwtc[l] instanceof TextBytesAtom) {
                                TextBytesAtom tba = (TextBytesAtom) slwtc[l];
                                text = tba.getText();
                            }
                            if (slwtc[l] instanceof TextCharsAtom) {
                                TextCharsAtom tca = (TextCharsAtom) slwtc[l];
                                text = tca.getText();
                            }
                            if (text != null) {
                                text = text.replace('\r', '\n');
                                System.out.println("        ''" + text + "''");
                            }
                        }
                    }
                }
            }
        }
    }
    ss.close();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) SlidePersistAtom(org.apache.poi.hslf.record.SlidePersistAtom) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) Document(org.apache.poi.hslf.record.Document) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Aggregations

TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)9 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)9 Record (org.apache.poi.hslf.record.Record)7 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)5 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)4 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)3 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)3 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)1 TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)1 CString (org.apache.poi.hslf.record.CString)1 Document (org.apache.poi.hslf.record.Document)1 MasterTextPropAtom (org.apache.poi.hslf.record.MasterTextPropAtom)1 PPDrawing (org.apache.poi.hslf.record.PPDrawing)1