示例#1
0
        /**
         * Performs a recursive search for pictures in the given list of escher records.
         *
         * @param escherRecords the escher records.
         * @param pictures the list to populate with the pictures.
         */
        private void SearchForPictures(IList escherRecords, List <Picture> pictures)
        {
            foreach (EscherRecord escherRecord in escherRecords)
            {
                if (escherRecord is EscherBSERecord)
                {
                    EscherBSERecord  bse  = (EscherBSERecord)escherRecord;
                    EscherBlipRecord blip = bse.BlipRecord;
                    if (blip != null)
                    {
                        pictures.Add(new Picture(blip.PictureData));
                    }
                    else if (bse.Offset > 0)
                    {
                        // Blip stored in delay stream, which in a word doc, is the main stream
                        EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                        EscherRecord        record        = recordFactory.CreateRecord(_mainStream, bse.Offset);

                        if (record is EscherBlipRecord)
                        {
                            record.FillFields(_mainStream, bse.Offset, recordFactory);
                            blip = (EscherBlipRecord)record;
                            pictures.Add(new Picture(blip.PictureData));
                        }
                    }
                }

                // Recursive call.
                SearchForPictures(escherRecord.ChildRecords, pictures);
            }
        }
示例#2
0
        private EscherBlipRecord GetBitmapRecord(int bitmapIndex)
        {
            List <EscherContainerRecord> bContainers = _escherRecordHolder
                                                       .GetBStoreContainers();

            if (bContainers == null || bContainers.Count != 1)
            {
                return(null);
            }

            EscherContainerRecord bContainer = bContainers[0];
            IList bitmapRecords = bContainer.ChildRecords;

            if (bitmapRecords.Count < bitmapIndex)
            {
                return(null);
            }

            EscherRecord imageRecord = (EscherRecord)bitmapRecords[bitmapIndex - 1];

            if (imageRecord is EscherBlipRecord)
            {
                return((EscherBlipRecord)imageRecord);
            }

            if (imageRecord is EscherBSERecord)
            {
                EscherBSERecord bseRecord = (EscherBSERecord)imageRecord;

                EscherBlipRecord blip = bseRecord.BlipRecord;
                if (blip != null)
                {
                    return(blip);
                }

                if (bseRecord.Offset > 0)
                {
                    /*
                     * Blip stored in delay stream, which in a word doc, is the main
                     * stream
                     */
                    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                    EscherRecord        record        = recordFactory.CreateRecord(_mainStream,
                                                                                   bseRecord.Offset);

                    if (record is EscherBlipRecord)
                    {
                        record.FillFields(_mainStream, bseRecord.Offset,
                                          recordFactory);
                        return((EscherBlipRecord)record);
                    }
                }
            }

            return(null);
        }
        public void TestFillFields()
        {
            IEscherRecordFactory f = new DefaultEscherRecordFactory();

            byte[]       data = HexRead.ReadFromString("0F 02 11 F1 00 00 00 00");
            EscherRecord r    = f.CreateRecord(data, 0);

            r.FillFields(data, 0, f);
            Assert.IsTrue(r is EscherContainerRecord);
            Assert.AreEqual((short)0x020F, r.Options);
            Assert.AreEqual(unchecked ((short)0xF111), r.RecordId);

            data = HexRead.ReadFromString("0F 02 11 F1 08 00 00 00" +
                                          " 02 00 22 F2 00 00 00 00");
            r = f.CreateRecord(data, 0);
            r.FillFields(data, 0, f);
            EscherRecord c = r.GetChild(0);

            Assert.IsFalse(c is EscherContainerRecord);
            Assert.AreEqual(unchecked ((short)0x0002), c.Options);
            Assert.AreEqual(unchecked ((short)0xF222), c.RecordId);
        }
        private void ConvertToEscherRecords(int offset, int size, byte[] data)
        {
            EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
            int pos = offset;

            while (pos < offset + size)
            {
                EscherRecord r         = recordFactory.CreateRecord(data, pos);
                int          bytesRead = r.FillFields(data, pos, recordFactory);
                escherRecords.Add(r);
                pos += bytesRead;
            }
        }
示例#5
0
        private void FillEscherRecords(byte[] data, int offset, int size)
        {
            IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
            int pos = offset;

            while (pos < offset + size)
            {
                EscherRecord r = recordFactory.CreateRecord(data, pos);
                escherRecords.Add(r);
                int bytesRead = r.FillFields(data, pos, recordFactory);
                pos += bytesRead + 1; // There Is an empty byte between each top-level record in a Word doc
            }
        }
示例#6
0
        /**
         * Performs a recursive search for pictures in the given list of escher records.
         *
         * @param escherRecords the escher records.
         * @param pictures the list to populate with the pictures.
         */
        private void SearchForPictures(IList escherRecords, List <Picture> pictures)
        {
            foreach (EscherRecord escherRecord in escherRecords)
            {
                if (escherRecord is EscherBSERecord)
                {
                    EscherBSERecord  bse  = (EscherBSERecord)escherRecord;
                    EscherBlipRecord blip = bse.BlipRecord;
                    if (blip != null)
                    {
                        pictures.Add(new Picture(blip.PictureData));
                    }
                    else if (bse.Offset > 0)
                    {
                        try
                        {
                            // Blip stored in delay stream, which in a word doc, is the main stream
                            IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                            EscherRecord         record        = recordFactory.CreateRecord(_mainStream, bse.Offset);

                            if (record is EscherBlipRecord)
                            {
                                record.FillFields(_mainStream, bse.Offset, recordFactory);
                                blip = (EscherBlipRecord)record;
                                pictures.Add(new Picture(blip.PictureData));
                            }
                        }
                        catch (Exception exc)
                        {
                            logger.Log(
                                POILogger.WARN,
                                "Unable to load picture from BLIB record at offset #",
                                bse.Offset, exc);
                        }
                    }
                }

                // Recursive call.
                SearchForPictures(escherRecord.ChildRecords, pictures);
            }
        }
        /**
         * Collapses the drawing records into an aggregate.
         */
        public static EscherAggregate CreateAggregate(IList records, int locFirstDrawingRecord, DrawingManager2 drawingManager)
        {
            // Keep track of any shape records Created so we can match them back to the object id's.
            // Textbox objects are also treated as shape objects.
            IList shapeRecords = new ArrayList();
            EscherRecordFactory recordFactory = new CustomEscherRecordFactory(ref shapeRecords);

            // Calculate the size of the buffer
            EscherAggregate agg      = new EscherAggregate(drawingManager);
            int             loc      = locFirstDrawingRecord;
            int             dataSize = 0;

            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                dataSize += ((DrawingRecord)records[loc]).Data.Length;
                loc      += 2;
            }

            // Create one big buffer
            byte[] buffer = new byte[dataSize];
            int    offset = 0;

            loc = locFirstDrawingRecord;
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                DrawingRecord drawingRecord = (DrawingRecord)records[loc];
                Array.Copy(drawingRecord.Data, 0, buffer, offset, drawingRecord.Data.Length);
                offset += drawingRecord.Data.Length;
                loc    += 2;
            }

            // Decode the shapes
            //        agg.escherRecords = new ArrayList();
            int pos = 0;

            while (pos < dataSize)
            {
                EscherRecord r         = recordFactory.CreateRecord(buffer, pos);
                int          bytesRead = r.FillFields(buffer, pos, recordFactory);
                agg.AddEscherRecord(r);
                pos += bytesRead;
            }

            // Associate the object records with the shapes
            loc = locFirstDrawingRecord;
            int shapeIndex = 0;

            agg.shapeToObj = new Hashtable();
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                Record objRecord = (Record)records[loc + 1];
                agg.shapeToObj[shapeRecords[shapeIndex++]] = objRecord;
                loc += 2;
            }

            return(agg);
        }