Search in sources :

Example 1 with EscherOptRecord

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

the class HSSFPicture method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer() {
    EscherContainerRecord spContainer = super.createSpContainer();
    EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID);
    opt.removeEscherProperty(EscherProperties.LINESTYLE__LINEDASHING);
    opt.removeEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH);
    spContainer.removeChildRecord(spContainer.getChildById(EscherTextboxRecord.RECORD_ID));
    return spContainer;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord)

Example 2 with EscherOptRecord

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

the class PPDrawing method create.

/**
	 * Create the Escher records associated with a new PPDrawing
	 */
private void create() {
    EscherContainerRecord dgContainer = new EscherContainerRecord();
    dgContainer.setRecordId(EscherContainerRecord.DG_CONTAINER);
    dgContainer.setOptions((short) 15);
    dg = new EscherDgRecord();
    dg.setOptions((short) 16);
    dg.setNumShapes(1);
    dgContainer.addChildRecord(dg);
    EscherContainerRecord spgrContainer = new EscherContainerRecord();
    spgrContainer.setOptions((short) 15);
    spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
    EscherContainerRecord spContainer = new EscherContainerRecord();
    spContainer.setOptions((short) 15);
    spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
    EscherSpgrRecord spgr = new EscherSpgrRecord();
    spgr.setOptions((short) 1);
    spContainer.addChildRecord(spgr);
    EscherSpRecord sp = new EscherSpRecord();
    sp.setOptions((short) ((ShapeType.NOT_PRIMITIVE.nativeId << 4) + 2));
    sp.setFlags(EscherSpRecord.FLAG_PATRIARCH | EscherSpRecord.FLAG_GROUP);
    spContainer.addChildRecord(sp);
    spgrContainer.addChildRecord(spContainer);
    dgContainer.addChildRecord(spgrContainer);
    spContainer = new EscherContainerRecord();
    spContainer.setOptions((short) 15);
    spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
    sp = new EscherSpRecord();
    sp.setOptions((short) ((ShapeType.RECT.nativeId << 4) + 2));
    sp.setFlags(EscherSpRecord.FLAG_BACKGROUND | EscherSpRecord.FLAG_HASSHAPETYPE);
    spContainer.addChildRecord(sp);
    EscherOptRecord opt = new EscherOptRecord();
    opt.setRecordId(EscherOptRecord.RECORD_ID);
    opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 134217728));
    opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLBACKCOLOR, 134217733));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__RECTRIGHT, 10064750));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__RECTBOTTOM, 7778750));
    opt.addEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1179666));
    opt.addEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524288));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHAPE__BLACKANDWHITESETTINGS, 9));
    opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHAPE__BACKGROUNDSHAPE, 65537));
    spContainer.addChildRecord(opt);
    dgContainer.addChildRecord(spContainer);
    childRecords.add(dgContainer);
}
Also used : EscherSpgrRecord(org.apache.poi.ddf.EscherSpgrRecord) EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

Example 3 with EscherOptRecord

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

the class OfficeDrawingsImpl method getOfficeDrawing.

private OfficeDrawing getOfficeDrawing(final FSPA fspa) {
    return new OfficeDrawing() {

        public HorizontalPositioning getHorizontalPositioning() {
            int value = getTertiaryPropertyValue(EscherProperties.GROUPSHAPE__POSH, -1);
            switch(value) {
                case 0:
                    return HorizontalPositioning.ABSOLUTE;
                case 1:
                    return HorizontalPositioning.LEFT;
                case 2:
                    return HorizontalPositioning.CENTER;
                case 3:
                    return HorizontalPositioning.RIGHT;
                case 4:
                    return HorizontalPositioning.INSIDE;
                case 5:
                    return HorizontalPositioning.OUTSIDE;
            }
            return HorizontalPositioning.ABSOLUTE;
        }

        public HorizontalRelativeElement getHorizontalRelative() {
            int value = getTertiaryPropertyValue(EscherProperties.GROUPSHAPE__POSRELH, -1);
            switch(value) {
                case 1:
                    return HorizontalRelativeElement.MARGIN;
                case 2:
                    return HorizontalRelativeElement.PAGE;
                case 3:
                    return HorizontalRelativeElement.TEXT;
                case 4:
                    return HorizontalRelativeElement.CHAR;
            }
            return HorizontalRelativeElement.TEXT;
        }

        public EscherContainerRecord getOfficeArtSpContainer() {
            return getEscherShapeRecordContainer(getShapeId());
        }

        public byte[] getPictureData() {
            EscherContainerRecord shapeDescription = getEscherShapeRecordContainer(getShapeId());
            if (shapeDescription == null)
                return null;
            EscherOptRecord escherOptRecord = shapeDescription.getChildById(EscherOptRecord.RECORD_ID);
            if (escherOptRecord == null)
                return null;
            EscherSimpleProperty escherProperty = escherOptRecord.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
            if (escherProperty == null)
                return null;
            int bitmapIndex = escherProperty.getPropertyValue();
            EscherBlipRecord escherBlipRecord = getBitmapRecord(bitmapIndex);
            if (escherBlipRecord == null)
                return null;
            return escherBlipRecord.getPicturedata();
        }

        public int getRectangleBottom() {
            return fspa.getYaBottom();
        }

        public int getRectangleLeft() {
            return fspa.getXaLeft();
        }

        public int getRectangleRight() {
            return fspa.getXaRight();
        }

        public int getRectangleTop() {
            return fspa.getYaTop();
        }

        public int getShapeId() {
            return fspa.getSpid();
        }

        private int getTertiaryPropertyValue(int propertyId, int defaultValue) {
            EscherContainerRecord shapeDescription = getEscherShapeRecordContainer(getShapeId());
            if (shapeDescription == null)
                return defaultValue;
            EscherTertiaryOptRecord escherTertiaryOptRecord = shapeDescription.getChildById(EscherTertiaryOptRecord.RECORD_ID);
            if (escherTertiaryOptRecord == null)
                return defaultValue;
            EscherSimpleProperty escherProperty = escherTertiaryOptRecord.lookup(propertyId);
            if (escherProperty == null)
                return defaultValue;
            int value = escherProperty.getPropertyValue();
            return value;
        }

        public VerticalPositioning getVerticalPositioning() {
            int value = getTertiaryPropertyValue(EscherProperties.GROUPSHAPE__POSV, -1);
            switch(value) {
                case 0:
                    return VerticalPositioning.ABSOLUTE;
                case 1:
                    return VerticalPositioning.TOP;
                case 2:
                    return VerticalPositioning.CENTER;
                case 3:
                    return VerticalPositioning.BOTTOM;
                case 4:
                    return VerticalPositioning.INSIDE;
                case 5:
                    return VerticalPositioning.OUTSIDE;
            }
            return VerticalPositioning.ABSOLUTE;
        }

        public VerticalRelativeElement getVerticalRelativeElement() {
            int value = getTertiaryPropertyValue(EscherProperties.GROUPSHAPE__POSV, -1);
            switch(value) {
                case 1:
                    return VerticalRelativeElement.MARGIN;
                case 2:
                    return VerticalRelativeElement.PAGE;
                case 3:
                    return VerticalRelativeElement.TEXT;
                case 4:
                    return VerticalRelativeElement.LINE;
            }
            return VerticalRelativeElement.TEXT;
        }

        @Override
        public String toString() {
            return "OfficeDrawingImpl: " + fspa;
        }
    };
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherTertiaryOptRecord(org.apache.poi.ddf.EscherTertiaryOptRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBlipRecord(org.apache.poi.ddf.EscherBlipRecord)

Example 4 with EscherOptRecord

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

the class InternalWorkbook method createDrawingGroup.

/**
     * Creates a primary drawing group record.  If it already
     *  exists then it's modified.
     */
public void createDrawingGroup() {
    if (drawingManager == null) {
        EscherContainerRecord dggContainer = new EscherContainerRecord();
        EscherDggRecord dgg = new EscherDggRecord();
        EscherOptRecord opt = new EscherOptRecord();
        EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();
        dggContainer.setRecordId((short) 0xF000);
        dggContainer.setOptions((short) 0x000F);
        dgg.setRecordId(EscherDggRecord.RECORD_ID);
        dgg.setOptions((short) 0x0000);
        dgg.setShapeIdMax(1024);
        dgg.setNumShapesSaved(0);
        dgg.setDrawingsSaved(0);
        dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {});
        drawingManager = new DrawingManager2(dgg);
        EscherContainerRecord bstoreContainer = null;
        if (!escherBSERecords.isEmpty()) {
            bstoreContainer = new EscherContainerRecord();
            bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
            bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
            for (EscherRecord escherRecord : escherBSERecords) {
                bstoreContainer.addChildRecord(escherRecord);
            }
        }
        opt.setRecordId((short) 0xF00B);
        opt.setOptions((short) 0x0033);
        opt.addEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296));
        opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 0x08000041));
        opt.addEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, 134217792));
        splitMenuColors.setRecordId((short) 0xF11E);
        splitMenuColors.setOptions((short) 0x0040);
        splitMenuColors.setColor1(0x0800000D);
        splitMenuColors.setColor2(0x0800000C);
        splitMenuColors.setColor3(0x08000017);
        splitMenuColors.setColor4(0x100000F7);
        dggContainer.addChildRecord(dgg);
        if (bstoreContainer != null) {
            dggContainer.addChildRecord(bstoreContainer);
        }
        dggContainer.addChildRecord(opt);
        dggContainer.addChildRecord(splitMenuColors);
        int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
        if (dgLoc == -1) {
            DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
            drawingGroup.addEscherRecord(dggContainer);
            int loc = findFirstRecordLocBySid(CountryRecord.sid);
            getRecords().add(loc + 1, drawingGroup);
        } else {
            DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
            drawingGroup.addEscherRecord(dggContainer);
            getRecords().set(dgLoc, drawingGroup);
        }
    }
}
Also used : EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

Example 5 with EscherOptRecord

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

the class InternalWorkbook method cloneDrawings.

/**
     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
     * re-generate shape IDs
     *
     * @param sheet the cloned sheet
     */
public void cloneDrawings(InternalSheet sheet) {
    findDrawingGroup();
    if (drawingManager == null) {
        //this workbook does not have drawings
        return;
    }
    //check if the cloned sheet has drawings
    int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
    if (aggLoc == -1) {
        return;
    }
    EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
    EscherContainerRecord escherContainer = agg.getEscherContainer();
    if (escherContainer == null) {
        return;
    }
    EscherDggRecord dgg = drawingManager.getDgg();
    //register a new drawing group for the cloned sheet
    int dgId = drawingManager.findNewDrawingGroupId();
    dgg.addCluster(dgId, 0);
    dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
    EscherDgRecord dg = null;
    for (EscherRecord er : escherContainer) {
        if (er instanceof EscherDgRecord) {
            dg = (EscherDgRecord) er;
            //update id of the drawing in the cloned sheet
            dg.setOptions((short) (dgId << 4));
        } else if (er instanceof EscherContainerRecord) {
            // iterate over shapes and re-generate shapeId
            for (EscherRecord er2 : (EscherContainerRecord) er) {
                for (EscherRecord shapeChildRecord : (EscherContainerRecord) er2) {
                    int recordId = shapeChildRecord.getRecordId();
                    if (recordId == EscherSpRecord.RECORD_ID) {
                        if (dg == null) {
                            throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
                        }
                        EscherSpRecord sp = (EscherSpRecord) shapeChildRecord;
                        int shapeId = drawingManager.allocateShapeId((short) dgId, dg);
                        //allocateShapeId increments the number of shapes. roll back to the previous value
                        dg.setNumShapes(dg.getNumShapes() - 1);
                        sp.setShapeId(shapeId);
                    } else if (recordId == EscherOptRecord.RECORD_ID) {
                        EscherOptRecord opt = (EscherOptRecord) shapeChildRecord;
                        EscherSimpleProperty prop = (EscherSimpleProperty) opt.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null) {
                            int pictureIndex = prop.getPropertyValue();
                            // increment reference count for pictures
                            EscherBSERecord bse = getBSERecord(pictureIndex);
                            bse.setRef(bse.getRef() + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.util.RecordFormatException) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Aggregations

EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)12 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)10 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)5 EscherRecord (org.apache.poi.ddf.EscherRecord)4 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)4 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)3 EscherComplexProperty (org.apache.poi.ddf.EscherComplexProperty)3 EscherProperty (org.apache.poi.ddf.EscherProperty)3 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)3 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)2 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 RecordFormatException (org.apache.poi.util.RecordFormatException)2 Map (java.util.Map)1 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)1 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)1 EscherShapePathProperty (org.apache.poi.ddf.EscherShapePathProperty)1