/** * Interface method to remove a drawing from the group * * @param d the drawing to remove */ public void remove(DrawingGroupObject d) { // Unless there are real images or some such, it is possible that // a BStoreContainer will not be present. In that case simply return if (getBStoreContainer() == null) { return; } if (origin == Origin.READ) { origin = Origin.READ_WRITE; numBlips = getBStoreContainer().getNumBlips(); Dgg dgg = (Dgg)escherData.getChildren()[0]; drawingGroupId = dgg.getCluster(1).drawingGroupId - numBlips - 1; } // Get the blip EscherRecord[] children = getBStoreContainer().getChildren(); BlipStoreEntry bse = (BlipStoreEntry)children[d.getBlipId() - 1]; bse.dereference(); if (bse.getReferenceCount() == 0) { // Remove the blip getBStoreContainer().remove(bse); // Adjust blipId on the other blips foreach (DrawingGroupObject drawing in drawings) { if (drawing.getBlipId() > d.getBlipId()) { drawing.setObjectId(drawing.getObjectId(), drawing.getBlipId() - 1, drawing.getShapeId()); } } numBlips--; } }
/** * Adds a drawing from the public, writable interface * * @param d the drawing to add */ public void add(DrawingGroupObject d) { if (origin == Origin.READ) { origin = Origin.READ_WRITE; BStoreContainer bsc = getBStoreContainer(); // force initialization Dgg dgg = (Dgg)escherData.getChildren()[0]; drawingGroupId = dgg.getCluster(1).drawingGroupId - numBlips - 1; numBlips = bsc != null?bsc.getNumBlips() : 0; if (bsc != null) { Assert.verify(numBlips == bsc.getNumBlips()); } } if (!(d is Drawing)) { // Assign a new object id and add it to the list // drawings.add(d); maxobjectId++; maxShapeId++; d.setDrawingGroup(this); d.setObjectId(maxobjectId, numBlips + 1, maxShapeId); if (drawings.Count > maxobjectId) { //logger.warn("drawings length " + drawings.Count + // " exceeds the max object id " + maxobjectId); } // numBlips++; return; } Drawing drawing = (Drawing)d; // See if this is referenced elsewhere Drawing refImage = null; if (imageFiles.ContainsKey(d.getImageFilePath())) { refImage = imageFiles[d.getImageFilePath()]; } if (refImage == null) { // There are no other references to this drawing, so assign // a new object id and put it on the hash map maxobjectId++; maxShapeId++; drawings.Add(drawing); drawing.setDrawingGroup(this); drawing.setObjectId(maxobjectId, numBlips + 1, maxShapeId); numBlips++; imageFiles.Add(drawing.getImageFilePath(), drawing); } else { // This drawing is used elsewhere in the workbook. Increment the // reference count on the drawing, and set the object id of the drawing // passed in refImage.setReferenceCount(refImage.getReferenceCount() + 1); drawing.setDrawingGroup(this); drawing.setObjectId(refImage.getObjectId(), refImage.getBlipId(), refImage.getShapeId()); } }