示例#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);
            }
        }