Search in sources :

Example 1 with OEPlaceholderAtom

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

the class HSLFTextShape method isPlaceholder.

@Override
public boolean isPlaceholder() {
    OEPlaceholderAtom oep = getPlaceholderAtom();
    if (oep != null) {
        return true;
    }
    //special case for files saved in Office 2007
    RoundTripHFPlaceholder12 hldr = getHFPlaceholderAtom();
    if (hldr != null) {
        return true;
    }
    return false;
}
Also used : RoundTripHFPlaceholder12(org.apache.poi.hslf.record.RoundTripHFPlaceholder12) RoundTripHFPlaceholder12(org.apache.poi.hslf.record.RecordTypes.RoundTripHFPlaceholder12) OEPlaceholderAtom(org.apache.poi.hslf.record.OEPlaceholderAtom) OEPlaceholderAtom(org.apache.poi.hslf.record.RecordTypes.OEPlaceholderAtom)

Example 2 with OEPlaceholderAtom

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

the class HSLFSimpleShape method setPlaceholder.

@Override
public void setPlaceholder(Placeholder placeholder) {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flags = spRecord.getFlags();
    if (placeholder == null) {
        flags ^= EscherSpRecord.FLAG_HAVEMASTER;
    } else {
        flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
    }
    spRecord.setFlags(flags);
    // Placeholders can't be grouped
    setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder == null ? -1 : 262144));
    HSLFEscherClientDataRecord clientData = getClientData(false);
    if (placeholder == null) {
        if (clientData != null) {
            clientData.removeChild(OEPlaceholderAtom.class);
            clientData.removeChild(RoundTripHFPlaceholder12.class);
            // remove client data if the placeholder was the only child to be carried
            if (clientData.getChildRecords().isEmpty()) {
                getSpContainer().removeChildRecord(clientData);
            }
        }
        return;
    }
    if (clientData == null) {
        clientData = getClientData(true);
    }
    // OEPlaceholderAtom tells powerpoint that this shape is a placeholder
    OEPlaceholderAtom oep = null;
    RoundTripHFPlaceholder12 rtp = null;
    for (Record r : clientData.getHSLFChildRecords()) {
        if (r instanceof OEPlaceholderAtom) {
            oep = (OEPlaceholderAtom) r;
            break;
        }
        if (r instanceof RoundTripHFPlaceholder12) {
            rtp = (RoundTripHFPlaceholder12) r;
            break;
        }
    }
    /**
         * Extract from MSDN:
         *
         * There is a special case when the placeholder does not have a position in the layout.
         * This occurs when the user has moved the placeholder from its original position.
         * In this case the placeholder ID is -1.
         */
    byte phId;
    HSLFSheet sheet = getSheet();
    // TODO: implement/switch NotesMaster
    if (sheet instanceof HSLFSlideMaster) {
        phId = (byte) placeholder.nativeSlideMasterId;
    } else if (sheet instanceof HSLFNotes) {
        phId = (byte) placeholder.nativeNotesId;
    } else {
        phId = (byte) placeholder.nativeSlideId;
    }
    if (phId == -2) {
        throw new HSLFException("Placeholder " + placeholder.name() + " not supported for this sheet type (" + sheet.getClass() + ")");
    }
    switch(placeholder) {
        case HEADER:
        case FOOTER:
            if (rtp == null) {
                rtp = new RoundTripHFPlaceholder12();
                rtp.setPlaceholderId(phId);
                clientData.addChild(rtp);
            }
            if (oep != null) {
                clientData.removeChild(OEPlaceholderAtom.class);
            }
            break;
        default:
            if (rtp != null) {
                clientData.removeChild(RoundTripHFPlaceholder12.class);
            }
            if (oep == null) {
                oep = new OEPlaceholderAtom();
                oep.setPlaceholderSize((byte) OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
                // TODO: placement id only "SHOULD" be unique ... check other placeholders on sheet for unique id
                oep.setPlacementId(-1);
                oep.setPlaceholderId(phId);
                clientData.addChild(oep);
            }
            break;
    }
}
Also used : RoundTripHFPlaceholder12(org.apache.poi.hslf.record.RoundTripHFPlaceholder12) HSLFException(org.apache.poi.hslf.exceptions.HSLFException) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) Record(org.apache.poi.hslf.record.Record) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) OEPlaceholderAtom(org.apache.poi.hslf.record.OEPlaceholderAtom)

Example 3 with OEPlaceholderAtom

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

the class HSLFSimpleShape method getPlaceholder.

@Override
public Placeholder getPlaceholder() {
    List<? extends Record> clRecords = getClientRecords();
    if (clRecords == null) {
        return null;
    }
    int phSource;
    HSLFSheet sheet = getSheet();
    if (sheet instanceof HSLFSlideMaster) {
        phSource = 1;
    } else if (sheet instanceof HSLFNotes) {
        phSource = 2;
    } else if (sheet instanceof MasterSheet) {
        // notes master aren't yet supported ...
        phSource = 3;
    } else {
        phSource = 0;
    }
    for (Record r : clRecords) {
        int phId;
        if (r instanceof OEPlaceholderAtom) {
            phId = ((OEPlaceholderAtom) r).getPlaceholderId();
        } else if (r instanceof RoundTripHFPlaceholder12) {
            //special case for files saved in Office 2007
            phId = ((RoundTripHFPlaceholder12) r).getPlaceholderId();
        } else {
            continue;
        }
        switch(phSource) {
            case 0:
                return Placeholder.lookupNativeSlide(phId);
            default:
            case 1:
                return Placeholder.lookupNativeSlideMaster(phId);
            case 2:
                return Placeholder.lookupNativeNotes(phId);
            case 3:
                return Placeholder.lookupNativeNotesMaster(phId);
        }
    }
    return null;
}
Also used : RoundTripHFPlaceholder12(org.apache.poi.hslf.record.RoundTripHFPlaceholder12) MasterSheet(org.apache.poi.sl.usermodel.MasterSheet) EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) Record(org.apache.poi.hslf.record.Record) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) OEPlaceholderAtom(org.apache.poi.hslf.record.OEPlaceholderAtom)

Aggregations

OEPlaceholderAtom (org.apache.poi.hslf.record.OEPlaceholderAtom)3 RoundTripHFPlaceholder12 (org.apache.poi.hslf.record.RoundTripHFPlaceholder12)3 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)2 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)2 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)2 EscherRecord (org.apache.poi.ddf.EscherRecord)2 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)2 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)2 Record (org.apache.poi.hslf.record.Record)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 OEPlaceholderAtom (org.apache.poi.hslf.record.RecordTypes.OEPlaceholderAtom)1 RoundTripHFPlaceholder12 (org.apache.poi.hslf.record.RecordTypes.RoundTripHFPlaceholder12)1 MasterSheet (org.apache.poi.sl.usermodel.MasterSheet)1