Search in sources :

Example 1 with MasterTextPropAtom

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

the class HSLFTextParagraph method findTextParagraphs.

/**
     * Scans through the supplied record array, looking for
     * a TextHeaderAtom followed by one of a TextBytesAtom or
     * a TextCharsAtom. Builds up TextRuns from these
     *
     * @param records the records to build from
     */
protected static List<List<HSLFTextParagraph>> findTextParagraphs(Record[] records) {
    List<List<HSLFTextParagraph>> paragraphCollection = new ArrayList<List<HSLFTextParagraph>>();
    int[] recordIdx = { 0 };
    for (int slwtIndex = 0; recordIdx[0] < records.length; slwtIndex++) {
        TextHeaderAtom header = null;
        TextBytesAtom tbytes = null;
        TextCharsAtom tchars = null;
        TextRulerAtom ruler = null;
        MasterTextPropAtom indents = null;
        for (Record r : getRecords(records, recordIdx, null)) {
            long rt = r.getRecordType();
            if (RecordTypes.TextHeaderAtom.typeID == rt) {
                header = (TextHeaderAtom) r;
            } else if (RecordTypes.TextBytesAtom.typeID == rt) {
                tbytes = (TextBytesAtom) r;
            } else if (RecordTypes.TextCharsAtom.typeID == rt) {
                tchars = (TextCharsAtom) r;
            } else if (RecordTypes.TextRulerAtom.typeID == rt) {
                ruler = (TextRulerAtom) r;
            } else if (RecordTypes.MasterTextPropAtom.typeID == rt) {
                indents = (MasterTextPropAtom) r;
            }
        // don't search for RecordTypes.StyleTextPropAtom.typeID here ... see findStyleAtomPresent below
        }
        if (header == null) {
            break;
        }
        if (header.getParentRecord() instanceof SlideListWithText) {
            // runs found in PPDrawing are not linked with SlideListWithTexts
            header.setIndex(slwtIndex);
        }
        if (tbytes == null && tchars == null) {
            tbytes = new TextBytesAtom();
            // don't add record yet - set it in storeText
            logger.log(POILogger.INFO, "bytes nor chars atom doesn't exist. Creating dummy record for later saving.");
        }
        String rawText = (tchars != null) ? tchars.getText() : tbytes.getText();
        StyleTextPropAtom styles = findStyleAtomPresent(header, rawText.length());
        List<HSLFTextParagraph> paragraphs = new ArrayList<HSLFTextParagraph>();
        paragraphCollection.add(paragraphs);
        // split, but keep delimiter
        for (String para : rawText.split("(?<=\r)")) {
            HSLFTextParagraph tpara = new HSLFTextParagraph(header, tbytes, tchars, paragraphs);
            paragraphs.add(tpara);
            tpara._ruler = ruler;
            tpara.getParagraphStyle().updateTextSize(para.length());
            HSLFTextRun trun = new HSLFTextRun(tpara);
            tpara.addTextRun(trun);
            trun.setText(para);
        }
        applyCharacterStyles(paragraphs, styles.getCharacterStyles());
        applyParagraphStyles(paragraphs, styles.getParagraphStyles());
        if (indents != null) {
            applyParagraphIndents(paragraphs, indents.getIndents());
        }
    }
    if (paragraphCollection.isEmpty()) {
        logger.log(POILogger.DEBUG, "No text records found.");
    }
    return paragraphCollection;
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) ArrayList(java.util.ArrayList) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) MasterTextPropAtom(org.apache.poi.hslf.record.MasterTextPropAtom) List(java.util.List) ArrayList(java.util.ArrayList) Record(org.apache.poi.hslf.record.Record) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) TextRulerAtom(org.apache.poi.hslf.record.TextRulerAtom)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 MasterTextPropAtom (org.apache.poi.hslf.record.MasterTextPropAtom)1 Record (org.apache.poi.hslf.record.Record)1 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)1 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)1 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)1 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)1 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)1 TextRulerAtom (org.apache.poi.hslf.record.TextRulerAtom)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1