Search in sources :

Example 1 with TxInteractiveInfoAtom

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

the class HSLFHyperlink method createHyperlink.

/**
     * Creates a new Hyperlink for a textrun.
     * This is only a helper method - use {@link HSLFTextRun#createHyperlink()} instead!
     *
     * @param run the run which receives the hyperlink
     * @return the new hyperlink
     * 
     * @see HSLFTextRun#createHyperlink()
     */
/* package */
static HSLFHyperlink createHyperlink(HSLFTextRun run) {
    // TODO: check if a hyperlink already exists
    ExHyperlink exHyper = new ExHyperlink();
    int linkId = run.getTextParagraph().getSheet().getSlideShow().addToObjListAtom(exHyper);
    ExHyperlinkAtom obj = exHyper.getExHyperlinkAtom();
    obj.setNumber(linkId);
    InteractiveInfo info = new InteractiveInfo();
    info.getInteractiveInfoAtom().setHyperlinkID(linkId);
    // don't add the hyperlink now to text paragraph records
    // this will be done, when the paragraph is saved
    HSLFHyperlink hyper = new HSLFHyperlink(exHyper, info);
    hyper.linkToNextSlide();
    TxInteractiveInfoAtom txinfo = new TxInteractiveInfoAtom();
    int startIdx = run.getTextParagraph().getStartIdxOfTextRun(run);
    int endIdx = startIdx + run.getLength();
    txinfo.setStartIndex(startIdx);
    txinfo.setEndIndex(endIdx);
    hyper.setTextRunInfo(txinfo);
    run.setHyperlink(hyper);
    return hyper;
}
Also used : ExHyperlinkAtom(org.apache.poi.hslf.record.ExHyperlinkAtom) ExHyperlink(org.apache.poi.hslf.record.ExHyperlink) TxInteractiveInfoAtom(org.apache.poi.hslf.record.TxInteractiveInfoAtom) InteractiveInfo(org.apache.poi.hslf.record.InteractiveInfo)

Example 2 with TxInteractiveInfoAtom

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

the class HSLFHyperlink method find.

private static void find(List<? extends Record> records, ExObjList exobj, List<HSLFHyperlink> out) {
    ListIterator<? extends Record> iter = records.listIterator();
    while (iter.hasNext()) {
        Record r = iter.next();
        // see if we have InteractiveInfo in the textrun's records
        if (!(r instanceof InteractiveInfo)) {
            continue;
        }
        InteractiveInfo hldr = (InteractiveInfo) r;
        InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
        if (info == null) {
            continue;
        }
        int id = info.getHyperlinkID();
        ExHyperlink exHyper = exobj.get(id);
        if (exHyper == null) {
            continue;
        }
        HSLFHyperlink link = new HSLFHyperlink(exHyper, hldr);
        out.add(link);
        if (iter.hasNext()) {
            r = iter.next();
            if (!(r instanceof TxInteractiveInfoAtom)) {
                iter.previous();
                continue;
            }
            link.setTextRunInfo((TxInteractiveInfoAtom) r);
        }
    }
}
Also used : InteractiveInfoAtom(org.apache.poi.hslf.record.InteractiveInfoAtom) TxInteractiveInfoAtom(org.apache.poi.hslf.record.TxInteractiveInfoAtom) ExHyperlink(org.apache.poi.hslf.record.ExHyperlink) TxInteractiveInfoAtom(org.apache.poi.hslf.record.TxInteractiveInfoAtom) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) Record(org.apache.poi.hslf.record.Record) InteractiveInfo(org.apache.poi.hslf.record.InteractiveInfo)

Example 3 with TxInteractiveInfoAtom

use of org.apache.poi.hslf.record.TxInteractiveInfoAtom 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)3 TxInteractiveInfoAtom (org.apache.poi.hslf.record.TxInteractiveInfoAtom)3 ExHyperlink (org.apache.poi.hslf.record.ExHyperlink)2 Record (org.apache.poi.hslf.record.Record)2 ExHyperlinkAtom (org.apache.poi.hslf.record.ExHyperlinkAtom)1 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)1 InteractiveInfoAtom (org.apache.poi.hslf.record.InteractiveInfoAtom)1 RecordContainer (org.apache.poi.hslf.record.RecordContainer)1 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)1