示例#1
0
        /**
         * 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--;
            }
        }
示例#2
0
        /**
         * Writes the drawing group to the output file
         *
         * @param outputFile the file to write to
         * @exception IOException
         */
        public void write(File outputFile)
        {
            if (origin == Origin.WRITE)
            {
                DggContainer dggContainer = new DggContainer();

                Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);

                dgg.addCluster(1, 0);
                dgg.addCluster(numBlips + 1, 0);

                dggContainer.add(dgg);

                int             drawingsAdded = 0;
                BStoreContainer bstoreCont    = new BStoreContainer();

                // Create a blip entry for each drawing
                foreach (object o in drawings)
                {
                    if (o is Drawing)
                    {
                        Drawing        d   = (Drawing)o;
                        BlipStoreEntry bse = new BlipStoreEntry(d);

                        bstoreCont.add(bse);
                        drawingsAdded++;
                    }
                }
                if (drawingsAdded > 0)
                {
                    bstoreCont.setNumBlips(drawingsAdded);
                    dggContainer.add(bstoreCont);
                }

                Opt opt = new Opt();

                dggContainer.add(opt);

                SplitMenuColors splitMenuColors = new SplitMenuColors();
                dggContainer.add(splitMenuColors);

                drawingData = dggContainer.getData();
            }
            else if (origin == Origin.READ_WRITE)
            {
                DggContainer dggContainer = new DggContainer();

                Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);

                dgg.addCluster(1, 0);
                dgg.addCluster(drawingGroupId + numBlips + 1, 0);

                dggContainer.add(dgg);

                BStoreContainer bstoreCont = new BStoreContainer();
                bstoreCont.setNumBlips(numBlips);

                // Create a blip entry for each drawing that was read in
                BStoreContainer readBStoreContainer = getBStoreContainer();

                if (readBStoreContainer != null)
                {
                    EscherRecord[] children = readBStoreContainer.getChildren();
                    for (int i = 0; i < children.Length; i++)
                    {
                        BlipStoreEntry bse = (BlipStoreEntry)children[i];
                        bstoreCont.add(bse);
                    }
                }

                // Create a blip entry for each drawing that has been added
                foreach (DrawingGroupObject dgo in drawings)
                {
                    if (dgo is Drawing)
                    {
                        Drawing d = (Drawing)dgo;
                        if (d.getOrigin() == Origin.WRITE)
                        {
                            BlipStoreEntry bse = new BlipStoreEntry(d);
                            bstoreCont.add(bse);
                        }
                    }
                }

                dggContainer.add(bstoreCont);

                Opt opt = new Opt();

                opt.addProperty(191, false, false, 524296);
                opt.addProperty(385, false, false, 134217737);
                opt.addProperty(448, false, false, 134217792);

                dggContainer.add(opt);

                SplitMenuColors splitMenuColors = new SplitMenuColors();
                dggContainer.add(splitMenuColors);

                drawingData = dggContainer.getData();
            }

            MsoDrawingGroupRecord msodg = new MsoDrawingGroupRecord(drawingData);

            outputFile.write(msodg);
        }
示例#3
0
        /**
         * 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());
            }
        }
示例#4
0
        /**
         * Initialization
         */
        private void initialize()
        {
            int curpos = getPos() + HEADER_LENGTH;
            int endpos = System.Math.Min(getPos() + getLength(), getStreamLength());

            EscherRecord newRecord = null;

            while (curpos < endpos)
            {
                EscherRecordData erd = new EscherRecordData(getEscherStream(), curpos);

                EscherRecordType type = erd.getType();
                if (type == EscherRecordType.DGG)
                {
                    newRecord = new Dgg(erd);
                }
                else if (type == EscherRecordType.DG)
                {
                    newRecord = new Dg(erd);
                }
                else if (type == EscherRecordType.BSTORE_CONTAINER)
                {
                    newRecord = new BStoreContainer(erd);
                }
                else if (type == EscherRecordType.SPGR_CONTAINER)
                {
                    newRecord = new SpgrContainer(erd);
                }
                else if (type == EscherRecordType.SP_CONTAINER)
                {
                    newRecord = new SpContainer(erd);
                }
                else if (type == EscherRecordType.SPGR)
                {
                    newRecord = new Spgr(erd);
                }
                else if (type == EscherRecordType.SP)
                {
                    newRecord = new Sp(erd);
                }
                else if (type == EscherRecordType.CLIENT_ANCHOR)
                {
                    newRecord = new ClientAnchor(erd);
                }
                else if (type == EscherRecordType.CLIENT_DATA)
                {
                    newRecord = new ClientData(erd);
                }
                else if (type == EscherRecordType.BSE)
                {
                    newRecord = new BlipStoreEntry(erd);
                }
                else if (type == EscherRecordType.OPT)
                {
                    newRecord = new Opt(erd);
                }
                else if (type == EscherRecordType.SPLIT_MENU_COLORS)
                {
                    newRecord = new SplitMenuColors(erd);
                }
                else if (type == EscherRecordType.CLIENT_TEXT_BOX)
                {
                    newRecord = new ClientTextBox(erd);
                }
                else
                {
                    newRecord = new EscherAtom(erd);
                }

                children.Add(newRecord);
                curpos += newRecord.getLength();
            }

            initialized = true;
        }