コード例 #1
0
            /**
     * 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)
            {
                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.DrawingsSaved = dgg.DrawingsSaved + 1;

                EscherDgRecord dg = null;
                for (IEnumerator it = escherContainer.ChildRecords.GetEnumerator(); it.MoveNext(); )
                {
                    Object er = it.Current;
                    if (er is EscherDgRecord)
                    {
                        dg = (EscherDgRecord)er;
                        //update id of the drawing in the cloned sheet
                        dg.Options = ((short)(dgId << 4));
                    }
                    else if (er is EscherContainerRecord)
                    {
                        //recursively find shape records and re-generate shapeId
                        ArrayList spRecords = new ArrayList();
                        EscherContainerRecord cp = (EscherContainerRecord)er;
                        for (IEnumerator spIt = cp.ChildRecords.GetEnumerator(); spIt.MoveNext(); )
                        {
                            EscherContainerRecord shapeContainer = (EscherContainerRecord)spIt.Current;

                            foreach (EscherRecord shapeChildRecord in shapeContainer.ChildRecords)
                            {
                                int recordId = shapeChildRecord.RecordId;
                                if (recordId == EscherSpRecord.RECORD_ID)
                                {
                                    EscherSpRecord sp = (EscherSpRecord)shapeChildRecord;
                                    int shapeId = drawingManager.AllocateShapeId((short)dgId, dg);
                                    //allocateShapeId increments the number of shapes. roll back to the previous value
                                    dg.NumShapes = (dg.NumShapes - 1);
                                    sp.ShapeId = (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.PropertyValue;
                                        // increment reference count for pictures
                                        EscherBSERecord bse = GetBSERecord(pictureIndex);
                                        bse.Ref = bse.Ref + 1;
                                    }

                                }

                            }
                        }
                    }
                }

            }
        }