Search in sources :

Example 1 with RecordContainer

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

the class HSLFTextParagraph method updateTextAtom.

/**
     * Set the correct text atom depending on the multibyte usage
     */
private static void updateTextAtom(List<HSLFTextParagraph> paragraphs) {
    final String rawText = toInternalString(getRawText(paragraphs));
    // Will it fit in a 8 bit atom?
    boolean isUnicode = StringUtil.hasMultibyte(rawText);
    // isUnicode = true;
    TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
    TextBytesAtom byteAtom = paragraphs.get(0)._byteAtom;
    TextCharsAtom charAtom = paragraphs.get(0)._charAtom;
    StyleTextPropAtom styleAtom = findStyleAtomPresent(headerAtom, rawText.length());
    // Store in the appropriate record
    Record oldRecord = null, newRecord = null;
    if (isUnicode) {
        if (byteAtom != null || charAtom == null) {
            oldRecord = byteAtom;
            charAtom = new TextCharsAtom();
        }
        newRecord = charAtom;
        charAtom.setText(rawText);
    } else {
        if (charAtom != null || byteAtom == null) {
            oldRecord = charAtom;
            byteAtom = new TextBytesAtom();
        }
        newRecord = byteAtom;
        byte[] byteText = new byte[rawText.length()];
        StringUtil.putCompressedUnicode(rawText, byteText, 0);
        byteAtom.setText(byteText);
    }
    assert (newRecord != null);
    RecordContainer _txtbox = headerAtom.getParentRecord();
    Record[] cr = _txtbox.getChildRecords();
    int /* headerIdx = -1, */
    textIdx = -1, styleIdx = -1;
    for (int i = 0; i < cr.length; i++) {
        Record r = cr[i];
        if (r == headerAtom) {
        // headerIdx = i;
        } else if (r == oldRecord || r == newRecord) {
            textIdx = i;
        } else if (r == styleAtom) {
            styleIdx = i;
        }
    }
    if (textIdx == -1) {
        // the old record was never registered, ignore it
        _txtbox.addChildAfter(newRecord, headerAtom);
    // textIdx = headerIdx + 1;
    } else {
        // swap not appropriated records - noop if unchanged
        cr[textIdx] = newRecord;
    }
    if (styleIdx == -1) {
        // Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom
        _txtbox.addChildAfter(styleAtom, newRecord);
    }
    for (HSLFTextParagraph p : paragraphs) {
        if (newRecord == byteAtom) {
            p._byteAtom = byteAtom;
            p._charAtom = null;
        } else {
            p._byteAtom = null;
            p._charAtom = charAtom;
        }
    }
}
Also used : RecordContainer(org.apache.poi.hslf.record.RecordContainer) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) Record(org.apache.poi.hslf.record.Record) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 2 with RecordContainer

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

the class HSLFSheet method getProgrammableTag.

/**
     * Return programmable tag associated with this sheet, e.g. <code>___PPT12</code>.
     *
     * @return programmable tag associated with this sheet.
     */
public String getProgrammableTag() {
    String tag = null;
    RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType(RecordTypes.ProgTags.typeID);
    if (progTags != null) {
        RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType(RecordTypes.ProgBinaryTag.typeID);
        if (progBinaryTag != null) {
            CString binaryTag = (CString) progBinaryTag.findFirstOfType(RecordTypes.CString.typeID);
            if (binaryTag != null) {
                tag = binaryTag.getText();
            }
        }
    }
    return tag;
}
Also used : RecordContainer(org.apache.poi.hslf.record.RecordContainer) CString(org.apache.poi.hslf.record.CString) CString(org.apache.poi.hslf.record.CString)

Example 3 with RecordContainer

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

the class HSLFSlide method getComments.

/**
     * Get the comment(s) for this slide.
     * Note - for now, only works on PPT 2000 and
     *  PPT 2003 files. Doesn't work for PPT 97
     *  ones, as they do their comments oddly.
     */
public Comment[] getComments() {
    // If there are any, they're in
    //  ProgTags -> ProgBinaryTag -> BinaryTagData
    RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType(RecordTypes.ProgTags.typeID);
    if (progTags != null) {
        RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType(RecordTypes.ProgBinaryTag.typeID);
        if (progBinaryTag != null) {
            RecordContainer binaryTags = (RecordContainer) progBinaryTag.findFirstOfType(RecordTypes.BinaryTagData.typeID);
            if (binaryTags != null) {
                // This is where they'll be
                int count = 0;
                for (int i = 0; i < binaryTags.getChildRecords().length; i++) {
                    if (binaryTags.getChildRecords()[i] instanceof Comment2000) {
                        count++;
                    }
                }
                // Now build
                Comment[] comments = new Comment[count];
                count = 0;
                for (int i = 0; i < binaryTags.getChildRecords().length; i++) {
                    if (binaryTags.getChildRecords()[i] instanceof Comment2000) {
                        comments[i] = new Comment((Comment2000) binaryTags.getChildRecords()[i]);
                        count++;
                    }
                }
                return comments;
            }
        }
    }
    // None found
    return new Comment[0];
}
Also used : Comment(org.apache.poi.hslf.model.Comment) RecordContainer(org.apache.poi.hslf.record.RecordContainer) Comment2000(org.apache.poi.hslf.record.Comment2000)

Example 4 with RecordContainer

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

the class HSLFTextParagraph method updateHyperlinks.

private static void updateHyperlinks(List<HSLFTextParagraph> paragraphs) {
    TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
    RecordContainer _txtbox = headerAtom.getParentRecord();
    // remove existing hyperlink records
    for (Record r : _txtbox.getChildRecords()) {
        if (r instanceof InteractiveInfo || r instanceof TxInteractiveInfoAtom) {
            _txtbox.removeChild(r);
        }
    }
    // now go through all the textruns and check for hyperlinks
    HSLFHyperlink lastLink = null;
    for (HSLFTextParagraph para : paragraphs) {
        for (HSLFTextRun run : para) {
            HSLFHyperlink thisLink = run.getHyperlink();
            if (thisLink != null && thisLink == lastLink) {
                // the hyperlink extends over this text run, increase its length
                // TODO: the text run might be longer than the hyperlink
                thisLink.setEndIndex(thisLink.getEndIndex() + run.getLength());
            } else {
                if (lastLink != null) {
                    InteractiveInfo info = lastLink.getInfo();
                    TxInteractiveInfoAtom txinfo = lastLink.getTextRunInfo();
                    assert (info != null && txinfo != null);
                    _txtbox.appendChildRecord(info);
                    _txtbox.appendChildRecord(txinfo);
                }
            }
            lastLink = thisLink;
        }
    }
    if (lastLink != null) {
        InteractiveInfo info = lastLink.getInfo();
        TxInteractiveInfoAtom txinfo = lastLink.getTextRunInfo();
        assert (info != null && txinfo != null);
        _txtbox.appendChildRecord(info);
        _txtbox.appendChildRecord(txinfo);
    }
}
Also used : RecordContainer(org.apache.poi.hslf.record.RecordContainer) TxInteractiveInfoAtom(org.apache.poi.hslf.record.TxInteractiveInfoAtom) Record(org.apache.poi.hslf.record.Record) InteractiveInfo(org.apache.poi.hslf.record.InteractiveInfo) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom)

Example 5 with RecordContainer

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

the class HSLFTextParagraph method refreshRecords.

/**
     * Writes the textbox records back to the document record 
     */
private static void refreshRecords(List<HSLFTextParagraph> paragraphs) {
    TextHeaderAtom headerAtom = paragraphs.get(0)._headerAtom;
    RecordContainer _txtbox = headerAtom.getParentRecord();
    if (_txtbox instanceof EscherTextboxWrapper) {
        try {
            ((EscherTextboxWrapper) _txtbox).writeOut(null);
        } catch (IOException e) {
            throw new HSLFException("failed dummy write", e);
        }
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) RecordContainer(org.apache.poi.hslf.record.RecordContainer) EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper) IOException(java.io.IOException) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom)

Aggregations

RecordContainer (org.apache.poi.hslf.record.RecordContainer)5 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)3 Record (org.apache.poi.hslf.record.Record)2 IOException (java.io.IOException)1 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 Comment (org.apache.poi.hslf.model.Comment)1 CString (org.apache.poi.hslf.record.CString)1 Comment2000 (org.apache.poi.hslf.record.Comment2000)1 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)1 InteractiveInfo (org.apache.poi.hslf.record.InteractiveInfo)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 TxInteractiveInfoAtom (org.apache.poi.hslf.record.TxInteractiveInfoAtom)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1