Search in sources :

Example 6 with InteractiveInfo

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

Aggregations

InteractiveInfo (org.apache.poi.hslf.record.InteractiveInfo)6 ExHyperlink (org.apache.poi.hslf.record.ExHyperlink)3 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)3 TxInteractiveInfoAtom (org.apache.poi.hslf.record.TxInteractiveInfoAtom)3 ExHyperlinkAtom (org.apache.poi.hslf.record.ExHyperlinkAtom)2 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)2 InteractiveInfoAtom (org.apache.poi.hslf.record.InteractiveInfoAtom)2 Record (org.apache.poi.hslf.record.Record)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)1 MovieShape (org.apache.poi.hslf.model.MovieShape)1 OLEShape (org.apache.poi.hslf.model.OLEShape)1 AnimationInfo (org.apache.poi.hslf.record.AnimationInfo)1 AnimationInfoAtom (org.apache.poi.hslf.record.AnimationInfoAtom)1 RecordContainer (org.apache.poi.hslf.record.RecordContainer)1 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)1