Search in sources :

Example 21 with EscherSpRecord

use of org.apache.poi.ddf.EscherSpRecord 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 22 with EscherSpRecord

use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.

the class HSLFSimpleShape method createSpContainer.

/**
     * Create a new Shape
     *
     * @param isChild   <code>true</code> if the Line is inside a group, <code>false</code> otherwise
     * @return the record container which holds this shape
     */
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    ecr.setRecordId(EscherContainerRecord.SP_CONTAINER);
    EscherSpRecord sp = new EscherSpRecord();
    int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
    if (isChild) {
        flags |= EscherSpRecord.FLAG_CHILD;
    }
    sp.setFlags(flags);
    ecr.addChildRecord(sp);
    AbstractEscherOptRecord opt = new EscherOptRecord();
    opt.setRecordId(EscherOptRecord.RECORD_ID);
    ecr.addChildRecord(opt);
    EscherRecord anchor;
    if (isChild) {
        anchor = new EscherChildAnchorRecord();
    } else {
        anchor = new EscherClientAnchorRecord();
        //hack. internal variable EscherClientAnchorRecord.shortRecord can be
        //initialized only in fillFields(). We need to set shortRecord=false;
        byte[] header = new byte[16];
        LittleEndian.putUShort(header, 0, 0);
        LittleEndian.putUShort(header, 2, 0);
        LittleEndian.putInt(header, 4, 8);
        anchor.fillFields(header, 0, null);
    }
    ecr.addChildRecord(anchor);
    return ecr;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord)

Example 23 with EscherSpRecord

use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.

the class HSLFLine method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    setShapeType(ShapeType.LINE);
    EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
    short type = (short) ((ShapeType.LINE.nativeId << 4) | 0x2);
    spRecord.setOptions(type);
    //set default properties for a line
    AbstractEscherOptRecord opt = getEscherOptRecord();
    //default line properties
    setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
    setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);
    setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
    setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
    setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
    setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
    return ecr;
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 24 with EscherSpRecord

use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.

the class HSLFPictureShape method createSpContainer.

/**
     * Create a new Picture and populate the inital structure of the <code>EscherSp</code> record which holds information about this picture.

     * @param idx the index of the picture which refers to <code>EscherBSE</code> container.
     * @return the create Picture object
     */
protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
    spRecord.setOptions((short) ((ShapeType.FRAME.nativeId << 4) | 0x2));
    //set default properties for a picture
    AbstractEscherOptRecord opt = getEscherOptRecord();
    setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
    //another weird feature of powerpoint: for picture id we must add 0x4000.
    setEscherProperty(opt, (short) (EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
    return ecr;
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 25 with EscherSpRecord

use of org.apache.poi.ddf.EscherSpRecord in project poi by apache.

the class TestCloneSheet method testCloneSheetWithEmptyDrawingAggregate.

@Test
public void testCloneSheetWithEmptyDrawingAggregate() {
    HSSFWorkbook b = new HSSFWorkbook();
    HSSFSheet s = b.createSheet("Test");
    HSSFPatriarch patriarch = s.createDrawingPatriarch();
    EscherAggregate agg1 = patriarch.getBoundAggregate();
    HSSFSheet s2 = s.cloneSheet(b);
    patriarch = s2.getDrawingPatriarch();
    EscherAggregate agg2 = patriarch.getBoundAggregate();
    EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
    EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
    assertEquals(sp1.getShapeId(), 1024);
    assertEquals(sp2.getShapeId(), 2048);
    EscherDgRecord dg = (EscherDgRecord) agg2.getEscherContainer().getChild(0);
    assertEquals(dg.getLastMSOSPID(), 2048);
    assertEquals(dg.getInstance(), 0x2);
    //everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same
    sp2.setShapeId(1024);
    dg.setLastMSOSPID(1024);
    dg.setInstance((short) 0x1);
    assertEquals(agg1.serialize().length, agg2.serialize().length);
    assertEquals(agg1.toXml(""), agg2.toXml(""));
    assertArrayEquals(agg1.serialize(), agg2.serialize());
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) Test(org.junit.Test)

Aggregations

EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)31 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)17 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)5 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)5 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)5 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)5 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)4 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)4 EscherRecord (org.apache.poi.ddf.EscherRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Test (org.junit.Test)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)2 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)2 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)2 Record (org.apache.poi.hslf.record.Record)2