Exemple #1
0
 /**
  * creates shapes from existing file
  * @param spContainer
  * @param objRecord
  */
 public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord)
 {
     this._escherContainer = spContainer;
     this._objRecord = objRecord;
     this._optRecord = (EscherOptRecord)spContainer.GetChildById(EscherOptRecord.RECORD_ID);
     this.anchor = HSSFAnchor.CreateAnchorFromEscher(spContainer);
 }
Exemple #2
0
        /**
         * Creates the low level OBJ record for this shape.
         */
        //private ObjRecord CreateObjRecord(HSSFSimpleShape shape, int shapeId)
        //{
        //    ObjRecord obj = new ObjRecord();
        //    CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
        //    c.ObjectType = CommonObjectType.COMBO_BOX;
        //    c.ObjectId = shapeId;
        //    c.IsLocked = true;
        //    c.IsPrintable = false;
        //    c.IsAutoFill = true;
        //    c.IsAutoline = false;

        //    FtCblsSubRecord f = new FtCblsSubRecord();

        //    LbsDataSubRecord l = LbsDataSubRecord.CreateAutoFilterInstance();

        //    EndSubRecord e = new EndSubRecord();

        //    obj.AddSubRecord(c);
        //    obj.AddSubRecord(f);
        //    obj.AddSubRecord(l);
        //    obj.AddSubRecord(e);

        //    return obj;
        //}

        /**
         * Generates the escher shape records for this shape.
         */
        private EscherContainerRecord CreateSpContainer(HSSFSimpleShape shape, int shapeId)
        {
            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId=(EscherContainerRecord.SP_CONTAINER);
            spContainer.Options=((short)0x000F);
            sp.RecordId=(EscherSpRecord.RECORD_ID);
            sp.Options=((short)((EscherAggregate.ST_HOSTCONTROL << 4) | 0x2));

            sp.ShapeId=(shapeId);
            sp.Flags=(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
            opt.RecordId=(EscherOptRecord.RECORD_ID);
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 17039620));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x00080008));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));

            HSSFClientAnchor userAnchor = (HSSFClientAnchor)shape.Anchor;
            userAnchor.AnchorType = (AnchorType)1;
            EscherRecord anchor = CreateAnchor(userAnchor);
            clientData.RecordId=(EscherClientDataRecord.RECORD_ID);
            clientData.Options=((short)0x0000);

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
Exemple #3
0
        /**
         * Create a new Shape
         *
         * @param isChild   <code>true</code> if the Line is inside a group, <code>false</code> otherwise
         * @return the record Container which holds this shape
         */
        protected EscherContainerRecord CreateSpContainer(bool IsChild)
        {
            _escherContainer = new EscherContainerRecord();
            _escherContainer.SetRecordId(EscherContainerRecord.SP_CONTAINER);
            _escherContainer.SetOptions((short)15);

            EscherSpRecord sp = new EscherSpRecord();
            int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
            sp.SetFlags(flags);
            _escherContainer.AddChildRecord(sp);

            EscherOptRecord opt = new EscherOptRecord();
            opt.SetRecordId(EscherOptRecord.RECORD_ID);
            _escherContainer.AddChildRecord(opt);

            EscherRecord anchor;
            if (isChild) anchor = new EscherChildAnchorRecord();
            else
            {
                anchor = new EscherClientAnchorRecord();

                //hack. internal variable EscherClientAnchorRecord.shortRecord can be
                //Initialized only in FillFields(). We need to Set shortRecord=false;
                byte[] header = new byte[16];
                LittleEndian.PutUshort(header, 0, 0);
                LittleEndian.PutUshort(header, 2, 0);
                LittleEndian.PutInt(header, 4, 8);
                anchor.FillFields(header, 0, null);
            }
            _escherContainer.AddChildRecord(anchor);

            return _escherContainer;
        }
Exemple #4
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            short shapeType = objTypeToShapeType(hssfShape.ShapeType);
            sp.Options=(short)((shapeType << 4) | 0x2);
            sp.ShapeId=shapeId;
            sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            AddStandardOptions(shape, opt);
            EscherRecord anchor = CreateAnchor(shape.Anchor);
            clientData.RecordId=EscherClientDataRecord.RECORD_ID;
            clientData.Options=(short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
        public void TestToString()
        {
            EscherContainerRecord r = new EscherContainerRecord();
            r.RecordId=EscherContainerRecord.SP_CONTAINER;
            r.Options=(short)0x000F;
            String nl = Environment.NewLine;
            Assert.AreEqual("EscherContainerRecord (SpContainer):" + nl +
                    "  isContainer: True" + nl +
                    "  options: 0x000F" + nl +
                    "  recordId: 0xF004" + nl +
                    "  numchildren: 0" + nl
                    , r.ToString());

            EscherOptRecord r2 = new EscherOptRecord();
            r2.Options = unchecked((short)0x9876) ;
            r2.RecordId=EscherOptRecord.RECORD_ID;

            String expected;
            r.AddChildRecord(r2);
            expected = "EscherContainerRecord (SpContainer):" + nl +
                       "  isContainer: True" + nl +
                       "  options: 0x000F" + nl +
                       "  recordId: 0xF004" + nl +
                       "  numchildren: 1" + nl +
                       "  children: " + nl +
                       "   Child 0:" + nl +
                       "EscherOptRecord:" + nl +
                       "  isContainer: False" + nl +
                       "  options: 0x0003" + nl +
                       "  recordId: 0xF00B" + nl +
                       "  numchildren: 0" + nl +
                       "  properties:" + nl;
            Assert.AreEqual(expected, r.ToString());

            r.AddChildRecord(r2);
            expected = "EscherContainerRecord (SpContainer):" + nl +
                       "  isContainer: True" + nl +
                       "  options: 0x000F" + nl +
                       "  recordId: 0xF004" + nl +
                       "  numchildren: 2" + nl +
                       "  children: " + nl +
                       "   Child 0:" + nl +
                       "EscherOptRecord:" + nl +
                       "  isContainer: False" + nl +
                       "  options: 0x0003" + nl +
                       "  recordId: 0xF00B" + nl +
                       "  numchildren: 0" + nl +
                       "  properties:" + nl +
                       "   Child 1:" + nl +
                       "EscherOptRecord:" + nl +
                       "  isContainer: False" + nl +
                       "  options: 0x0003" + nl +
                       "  recordId: 0xF00B" + nl +
                       "  numchildren: 0" + nl +
                       "  properties:" + nl;
            Assert.AreEqual(expected, r.ToString());
        }
Exemple #6
0
 /// <summary>
 /// Creates the patriarch.
 /// </summary>
 /// <param name="sheet">the sheet this patriarch is stored in.</param>
 /// <param name="boundAggregate">The bound aggregate.</param>
 public HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate)
 {
     _boundAggregate = boundAggregate;
     _sheet = sheet;
     _mainSpgrContainer = _boundAggregate.GetEscherContainer().ChildContainers[0];
     EscherContainerRecord spContainer = (EscherContainerRecord)_boundAggregate.GetEscherContainer()
             .ChildContainers[0].GetChild(0);
     _spgrRecord = (EscherSpgrRecord)spContainer.GetChildById(EscherSpgrRecord.RECORD_ID);
     BuildShapeTree();
 }
Exemple #7
0
        /**
         * Generates the shape records for this shape.
         */
        protected override EscherContainerRecord CreateSpContainer()
        {
            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer.Options = ((short)0x000F);
            sp.RecordId = (EscherSpRecord.RECORD_ID);
            sp.Options = ((short)((EscherAggregate.ST_NOT_PRIMATIVE << 4) | 0x2));
            if (Parent == null)
            {
                sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
            }
            else
            {
                sp.Flags = (EscherSpRecord.FLAG_CHILD | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
            }
            opt.RecordId = (EscherOptRecord.RECORD_ID);
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION, false, false, 0));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, false, false, 100));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, false, false, 100));
            opt.SetEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));

            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__FILLOK, false, false, 0x00010001));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINESTARTARROWHEAD, false, false, 0x0));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDARROWHEAD, false, false, 0x0));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, false, false, 0x0));

            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
            opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
            opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1));

            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));

            EscherRecord anchor = Anchor.GetEscherAnchor();
            clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
            clientData.Options = ((short)0x0000);

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
Exemple #8
0
 public static HSSFAnchor CreateAnchorFromEscher(EscherContainerRecord container)
 {
     if (null != container.GetChildById(EscherChildAnchorRecord.RECORD_ID))
     {
         return new HSSFChildAnchor((EscherChildAnchorRecord)container.GetChildById(EscherChildAnchorRecord.RECORD_ID));
     }
     else
     {
         if (null != container.GetChildById(EscherClientAnchorRecord.RECORD_ID))
         {
             return new HSSFClientAnchor((EscherClientAnchorRecord)container.GetChildById(EscherClientAnchorRecord.RECORD_ID));
         }
         return null;
     }
 }
Exemple #9
0
        protected override EscherContainerRecord CreateSpContainer()
        {
            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();
            EscherTextboxRecord escherTextbox = new EscherTextboxRecord();

            spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer.Options = ((short)0x000F);
            sp.RecordId = (EscherSpRecord.RECORD_ID);
            sp.Options = ((short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2));

            sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE);
            opt.RecordId = (EscherOptRecord.RECORD_ID);
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, 0));

            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
            opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
            opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
            opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
            opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));

            EscherRecord anchor = Anchor.GetEscherAnchor();
            clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
            clientData.Options = ((short)0x0000);
            escherTextbox.RecordId = (EscherTextboxRecord.RECORD_ID);
            escherTextbox.Options = ((short)0x0000);

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);
            spContainer.AddChildRecord(escherTextbox);

            return spContainer;
        }
Exemple #10
0
        protected override EscherContainerRecord CreateSpContainer()
        {
            EscherContainerRecord spgrContainer = new EscherContainerRecord();
            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpgrRecord spgr = new EscherSpgrRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherRecord anchor;
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spgrContainer.RecordId = (EscherContainerRecord.SPGR_CONTAINER);
            spgrContainer.Options = ((short)0x000F);
            spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer.Options = (short)0x000F;
            spgr.RecordId = (EscherSpgrRecord.RECORD_ID);
            spgr.Options = (short)0x0001;
            spgr.RectX1 = (0);
            spgr.RectY1 = (0);
            spgr.RectX2 = (1023);
            spgr.RectY2 = (255);
            sp.RecordId = (EscherSpRecord.RECORD_ID);
            sp.Options = (short)0x0002;
            if (this.Anchor is HSSFClientAnchor)
            {
                sp.Flags = (EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR);
            }
            else
            {
                sp.Flags = (EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD);
            }
            opt.RecordId = (EscherOptRecord.RECORD_ID);
            opt.Options = ((short)0x0023);
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

            anchor = Anchor.GetEscherAnchor();
            clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
            clientData.Options = ((short)0x0000);

            spgrContainer.AddChildRecord(spContainer);
            spContainer.AddChildRecord(spgr);
            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);
            return spgrContainer;
        }
 /// <summary>
 /// Recursively find records with the specified record ID
 /// </summary>
 /// <param name="recordId"></param>
 /// <param name="out1">list to store found records</param>
 public void GetRecordsById(short recordId, ref ArrayList out1)
 {
     for (IEnumerator it = ChildRecords.GetEnumerator(); it.MoveNext();)
     {
         Object       er = it.Current;
         EscherRecord r  = (EscherRecord)er;
         if (r is EscherContainerRecord)
         {
             EscherContainerRecord c = (EscherContainerRecord)r;
             c.GetRecordsById(recordId, ref out1);
         }
         else if (r.RecordId == recordId)
         {
             out1.Add(er);
         }
     }
 }
Exemple #12
0
        public void TestReadPNG()
        {
            //provided in bug-44886
            byte[] data = _samples.ReadFile("Container.dat");

            EscherContainerRecord record = new EscherContainerRecord();
            record.FillFields(data, 0, new DefaultEscherRecordFactory());
            EscherContainerRecord bstore = (EscherContainerRecord)record.ChildRecords[1];
            EscherBSERecord bse1 = (EscherBSERecord)bstore.ChildRecords[0];
            Assert.AreEqual(EscherBSERecord.BT_PNG, bse1.BlipTypeWin32);
            Assert.AreEqual(EscherBSERecord.BT_PNG, bse1.BlipTypeMacOS);
            Assert.IsTrue(Arrays.Equals(new byte[]{
            0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
            0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
        }, bse1.UID));
            Assert.AreEqual(255, bse1.Tag);
            Assert.AreEqual(32308, bse1.Size);

            EscherBitmapBlip blip1 = (EscherBitmapBlip)bse1.BlipRecord;
            Assert.AreEqual(0x6E00, blip1.Options);
            Assert.AreEqual(EscherBitmapBlip.RECORD_ID_PNG, blip1.RecordId);
            Assert.IsTrue(Arrays.Equals(new byte[]{
            0x65, 0x07, 0x4A, (byte)0x8D, 0x3E, 0x42, (byte)0x8B, (byte)0xAC,
            0x1D, (byte)0x89, 0x35, 0x4F, 0x48, (byte)0xFA, 0x37, (byte)0xC2
        }, blip1.UID));

            //Serialize and Read again
            byte[] ser = bse1.Serialize();
            EscherBSERecord bse2 = new EscherBSERecord();
            bse2.FillFields(ser, 0, new DefaultEscherRecordFactory());
            Assert.AreEqual(bse1.RecordId, bse2.RecordId);
            Assert.AreEqual(bse1.BlipTypeWin32, bse2.BlipTypeWin32);
            Assert.AreEqual(bse1.BlipTypeMacOS, bse2.BlipTypeMacOS);
            Assert.IsTrue(Arrays.Equals(bse1.UID, bse2.UID));
            Assert.AreEqual(bse1.Tag, bse2.Tag);
            Assert.AreEqual(bse1.Size, bse2.Size);

            EscherBitmapBlip blip2 = (EscherBitmapBlip)bse1.BlipRecord;
            Assert.AreEqual(blip1.Options, blip2.Options);
            Assert.AreEqual(blip1.RecordId, blip2.RecordId);
            Assert.AreEqual(blip1.UID, blip2.UID);

            Assert.IsTrue(Arrays.Equals(blip1.PictureData, blip1.PictureData));
        }
Exemple #13
0
 public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord)
     : base(spgrContainer, objRecord)
 {
     // read internal and external coordinates from spgrContainer
     EscherContainerRecord spContainer = spgrContainer.ChildContainers[0];
     _spgrRecord = (EscherSpgrRecord)spContainer.GetChild(0);
     foreach (EscherRecord ch in spContainer.ChildRecords)
     {
         switch (ch.RecordId)
         {
             case EscherSpgrRecord.RECORD_ID:
                 break;
             case EscherClientAnchorRecord.RECORD_ID:
                 anchor = new HSSFClientAnchor((EscherClientAnchorRecord)ch);
                 break;
             case EscherChildAnchorRecord.RECORD_ID:
                 anchor = new HSSFChildAnchor((EscherChildAnchorRecord)ch);
                 break;
         }
     }
 }
Exemple #14
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId)
        {
            HSSFPicture shape = (HSSFPicture)hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherRecord anchor;
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            sp.Options=(short)((EscherAggregate.ST_PICTUREFRAME << 4) | 0x2);

            sp.ShapeId=shapeId;
            sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            //        opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00800080 ) ;
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.BLIP__BLIPTODISPLAY, false, true, shape.PictureIndex));
            //        opt.AddEscherProperty( new EscherComplexProperty( EscherProperties.BLIP__BLIPFILENAME, true, new byte[] { (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00 } ) ;
            //        opt.AddEscherProperty( new EscherSimpleProperty( EscherProperties.Fill__FillTYPE, 0x00000003 ) ;
            AddStandardOptions(shape, opt);
            HSSFAnchor userAnchor = shape.Anchor;
            if (userAnchor.IsHorizontallyFlipped)
                sp.Flags=sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ;
            if (userAnchor.IsVerticallyFlipped)
                sp.Flags=sp.Flags | EscherSpRecord.FLAG_FLIPVERT;
            anchor = CreateAnchor(userAnchor);
            clientData.RecordId=EscherClientDataRecord.RECORD_ID;
            clientData.Options=(short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
Exemple #15
0
        /// <summary>
        /// Toes the string.
        /// </summary>
        /// <param name="indent">The indent.</param>
        /// <returns></returns>
        public String ToString(String indent)
        {
            String nl = Environment.NewLine;

            StringBuilder children = new StringBuilder();

            if (ChildRecords.Count > 0)
            {
                children.Append("  children: " + nl);

                int count = 0;
                for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    String newIndent = indent + "   ";

                    EscherRecord record = (EscherRecord)iterator.Current;
                    children.Append(newIndent + "Child " + count + ":" + nl);

                    if (record is EscherContainerRecord)
                    {
                        EscherContainerRecord ecr = (EscherContainerRecord)record;
                        children.Append(ecr.ToString(newIndent));
                    }
                    else
                    {
                        children.Append(record.ToString());
                    }
                    count++;
                }
            }

            return
                (indent + this.GetType().Name + " (" + RecordName + "):" + nl +
                 indent + "  isContainer: " + IsContainerRecord + nl +
                 indent + "  options: 0x" + HexDump.ToHex(Options) + nl +
                 indent + "  recordId: 0x" + HexDump.ToHex(RecordId) + nl +
                 indent + "  numchildren: " + ChildRecords.Count + nl +
                 indent + children.ToString());
        }
Exemple #16
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherRecord anchor = new EscherClientAnchorRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            sp.Options=(short)((EscherAggregate.ST_LINE << 4) | 0x2);

            sp.ShapeId=shapeId;
            sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
            opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592));
            AddStandardOptions(shape, opt);
            HSSFAnchor userAnchor = shape.Anchor;
            if (userAnchor.IsHorizontallyFlipped)
                sp.Flags=sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ;
            if (userAnchor.IsVerticallyFlipped)
                sp.Flags=sp.Flags | EscherSpRecord.FLAG_FLIPVERT;
            anchor = CreateAnchor(userAnchor);
            clientData.RecordId=EscherClientDataRecord.RECORD_ID;
            clientData.Options=((short)0x0000);

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
        public void TestRecordSize()
        {
            DrawingGroupRecord r = new DrawingGroupRecord();
            Assert.AreEqual(4, r.RecordSize);

            EscherSpRecord sp = new EscherSpRecord();
            sp.RecordId = (EscherSpRecord.RECORD_ID);
            sp.Options = ((short)0x1111);
            sp.Flags = (-1);
            sp.ShapeId = (-1);
            EscherContainerRecord dggContainer = new EscherContainerRecord();
            dggContainer.Options = ((short)0x000F);
            dggContainer.RecordId = unchecked((short)0xF000);
            dggContainer.AddChildRecord(sp);

            r.AddEscherRecord(dggContainer);
            Assert.AreEqual(28, r.RecordSize);

            byte[] data = new byte[28];
            int size = r.Serialize(0, data);
            Assert.AreEqual("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF]", HexDump.ToHex(data));
            Assert.AreEqual(28, size);

            Assert.AreEqual(24, dggContainer.RecordSize);


            r = new DrawingGroupRecord();
            r.RawData = (new byte[MAX_DATA_SIZE]);
            Assert.AreEqual(MAX_RECORD_SIZE, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE + 1]);
            Assert.AreEqual(MAX_RECORD_SIZE + 5, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE * 2]);
            Assert.AreEqual(MAX_RECORD_SIZE * 2, r.RecordSize);
            r.RawData = (new byte[MAX_DATA_SIZE * 2 + 1]);
            Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, r.RecordSize);
        }
        public int AddBSERecord(EscherBSERecord e)
        {
            CreateDrawingGroup();

            // maybe we don't need that as an instance variable anymore
            escherBSERecords.Add(e);

            int dgLoc = FindFirstRecordLocBySid(DrawingGroupRecord.sid);
            DrawingGroupRecord drawingGroup = (DrawingGroupRecord)Records[dgLoc];

            EscherContainerRecord dggContainer = (EscherContainerRecord)drawingGroup.GetEscherRecord(0);
            EscherContainerRecord bstoreContainer;
            if (dggContainer.GetChild(1).RecordId == EscherContainerRecord.BSTORE_CONTAINER)
            {
                bstoreContainer = (EscherContainerRecord)dggContainer.GetChild(1);
            }
            else
            {
                bstoreContainer = new EscherContainerRecord();
                bstoreContainer.RecordId=EscherContainerRecord.BSTORE_CONTAINER;

                //dggContainer.ChildRecords.Insert(1, bstoreContainer);
                List<EscherRecord> childRecords = dggContainer.ChildRecords;
                childRecords.Insert(1, bstoreContainer);
                dggContainer.ChildRecords = (childRecords);
                
            }
            bstoreContainer.Options=(short)((escherBSERecords.Count << 4) | 0xF);

            bstoreContainer.AddChildRecord(e);

            return escherBSERecords.Count;
        }
        /**
         * Creates a primary drawing Group record.  If it already 
         *  exists then it's modified.
         */
        public void CreateDrawingGroup()
        {
            if (drawingManager == null)
            {
                EscherContainerRecord dggContainer = new EscherContainerRecord();
                EscherDggRecord dgg = new EscherDggRecord();
                EscherOptRecord opt = new EscherOptRecord();
                EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();

                dggContainer.RecordId=unchecked((short)0xF000);
                dggContainer.Options=(short)0x000F;
                dgg.RecordId=EscherDggRecord.RECORD_ID;
                dgg.Options=(short)0x0000;
                dgg.ShapeIdMax=1024;
                dgg.NumShapesSaved=0;
                dgg.DrawingsSaved=0;
                dgg.FileIdClusters=new EscherDggRecord.FileIdCluster[] { };
                drawingManager = new DrawingManager2(dgg);
                EscherContainerRecord bstoreContainer = null;
                if (escherBSERecords.Count > 0)
                {
                    bstoreContainer = new EscherContainerRecord();
                    bstoreContainer.RecordId=EscherContainerRecord.BSTORE_CONTAINER;
                    bstoreContainer.Options=(short)((escherBSERecords.Count << 4) | 0xF);
                    for (IEnumerator iterator = escherBSERecords.GetEnumerator(); iterator.MoveNext(); )
                    {
                        EscherRecord escherRecord = (EscherRecord)iterator.Current;
                        bstoreContainer.AddChildRecord(escherRecord);
                    }
                }
                opt.RecordId=unchecked((short)0xF00B);
                opt.Options=(short)0x0033;
                opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296));
                opt.AddEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 0x08000041));
                opt.AddEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, 134217792));
                splitMenuColors.RecordId=unchecked((short)0xF11E);
                splitMenuColors.Options=(short)0x0040;
                splitMenuColors.Color1=0x0800000D;
                splitMenuColors.Color2=0x0800000C;
                splitMenuColors.Color3=0x08000017;
                splitMenuColors.Color4=0x100000F7;

                dggContainer.AddChildRecord(dgg);
                if (bstoreContainer != null)
                    dggContainer.AddChildRecord(bstoreContainer);
                dggContainer.AddChildRecord(opt);
                dggContainer.AddChildRecord(splitMenuColors);

                int dgLoc = FindFirstRecordLocBySid(DrawingGroupRecord.sid);
                if (dgLoc == -1)
                {
                    DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
                    drawingGroup.AddEscherRecord(dggContainer);
                    int loc = FindFirstRecordLocBySid(CountryRecord.sid);

                    Records.Insert(loc + 1, drawingGroup);
                }
                else
                {
                    DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
                    drawingGroup.AddEscherRecord(dggContainer);
                    Records[dgLoc]= drawingGroup;
                }

            }
        }
Exemple #20
0
        //private TextObjectRecord txo = null;
        public HSSFComment(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord _note)
            : base(spContainer, objRecord, textObjectRecord)
        {

            this._note = _note;
        }
Exemple #21
0
 internal override HSSFShape CloneShape()
 {
     TextObjectRecord txo = (TextObjectRecord)GetTextObjectRecord().CloneViaReserialise();
     EscherContainerRecord spContainer = new EscherContainerRecord();
     byte[] inSp = GetEscherContainer().Serialize();
     spContainer.FillFields(inSp, 0, new DefaultEscherRecordFactory());
     ObjRecord obj = (ObjRecord)GetObjRecord().CloneViaReserialise();
     NoteRecord note = (NoteRecord)NoteRecord.CloneViaReserialise();
     return new HSSFComment(spContainer, obj, txo, note);
 }
Exemple #22
0
        /**
         * Converts the Records into UserModel
         *  objects on the bound HSSFPatriarch
         */
        //public void ConvertRecordsToUserModel()
        //{
        //    if (patriarch == null)
        //    {
        //        throw new InvalidOperationException("Must call SetPatriarch() first");
        //    }

        //    // The top level container ought to have
        //    //  the DgRecord and the container of one container
        //    //  per shape Group (patriach overall first)
        //    EscherContainerRecord topContainer =
        //        (EscherContainerRecord)GetEscherContainer();
        //    if (topContainer == null)
        //    {
        //        return;
        //    }
        //    topContainer = (EscherContainerRecord)
        //        topContainer.ChildContainers[0];

        //    IList<EscherContainerRecord> tcc = topContainer.ChildContainers;
        //    if (tcc.Count == 0)
        //    {
        //        throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
        //    }

        //    // First up, Get the patriach position
        //    // This Is in the first EscherSpgrRecord, in
        //    //  the first container, with a EscherSRecord too
        //    EscherContainerRecord patriachContainer =
        //        (EscherContainerRecord)tcc[0];
        //    EscherSpgrRecord spgr = null;
        //    for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext(); )
        //    {
        //        EscherRecord r = (EscherRecord)it.Current;
        //        if (r is EscherSpgrRecord)
        //        {
        //            spgr = (EscherSpgrRecord)r;
        //            break;
        //        }
        //    }
        //    if (spgr != null)
        //    {
        //        patriarch.SetCoordinates(
        //                spgr.RectX1, spgr.RectY1,
        //                spgr.RectX2, spgr.RectY2
        //        );
        //    }

        //    // Now Process the containers for each Group
        //    //  and objects
        //    for (int i = 1; i < tcc.Count; i++)
        //    {
        //        EscherContainerRecord shapeContainer =
        //            (EscherContainerRecord)tcc[i];
        //        //Console.Error.WriteLine("\n\n*****\n\n");
        //        //Console.Error.WriteLine(shapeContainer);

        //        // Could be a Group, or a base object
        //        if (shapeContainer.RecordId == EscherContainerRecord.SPGR_CONTAINER)
        //        {
        //            if(shapeContainer.ChildRecords.Count>0)
        //            {
        //                // Group
        //                HSSFShapeGroup group =
        //                    new HSSFShapeGroup(null, new HSSFClientAnchor());
        //                patriarch.Children.Add(group);

        //                EscherContainerRecord groupContainer =
        //                    (EscherContainerRecord)shapeContainer.GetChild(0);
        //                ConvertRecordsToUserModel(groupContainer, group);
        //            }
        //        }
        //        else if (shapeContainer.RecordId == EscherContainerRecord.SP_CONTAINER)
        //        {
        //            EscherSpRecord spRecord = (EscherSpRecord)shapeContainer.GetChildById(EscherSpRecord.RECORD_ID);
        //            int type = spRecord.ShapeType;

        //            switch (type)
        //            {
        //                case ST_TEXTBOX:
        //                    HSSFSimpleShape box;

        //                    TextObjectRecord textrec = (TextObjectRecord)shapeToObj[GetEscherChild(shapeContainer, EscherTextboxRecord.RECORD_ID)];
        //                     EscherClientAnchorRecord anchorRecord1 = (EscherClientAnchorRecord)GetEscherChild(shapeContainer, EscherClientAnchorRecord.RECORD_ID);
        //                        HSSFClientAnchor anchor1 = new HSSFClientAnchor();
        //                        anchor1.Col1 = anchorRecord1.Col1;
        //                        anchor1.Col2 = anchorRecord1.Col2;
        //                        anchor1.Dx1 = anchorRecord1.Dx1;
        //                        anchor1.Dx2 = anchorRecord1.Dx2;
        //                        anchor1.Dy1 = anchorRecord1.Dy1;
        //                        anchor1.Dy2 = anchorRecord1.Dy2;
        //                        anchor1.Row1 = anchorRecord1.Row1;
        //                        anchor1.Row2 = anchorRecord1.Row2;
        //                    if (tailRec.Count>=i && tailRec[i-1] is NoteRecord)
        //                    {
        //                        NoteRecord noterec=(NoteRecord)tailRec[i - 1];
                                
        //                        // comment
        //                        box =
        //                            new HSSFComment(null, anchor1);
        //                        HSSFComment comment=(HSSFComment)box;
        //                        comment.Author = noterec.Author;
        //                        comment.Row = noterec.Row;
        //                        comment.Column = noterec.Column;
        //                        comment.Visible = (noterec.Flags == NoteRecord.NOTE_VISIBLE);
        //                        comment.String = textrec.Str;                                
        //                    }
        //                    else
        //                    {
        //                        // TextBox
        //                        box =
        //                            new HSSFTextbox(null, anchor1);
        //                        ((HSSFTextbox)box).String = textrec.Str;  
        //                    }
        //                    patriarch.AddShape(box);
        //                    ConvertRecordsToUserModel(shapeContainer, box);
        //                    break;
        //                case ST_PICTUREFRAME:
        //                    // Duplicated from
        //                    // org.apache.poi.hslf.model.Picture.getPictureIndex()
        //                    EscherOptRecord opt = (EscherOptRecord)GetEscherChild(shapeContainer, EscherOptRecord.RECORD_ID);
        //                    EscherSimpleProperty prop = (EscherSimpleProperty)opt.Lookup(EscherProperties.BLIP__BLIPTODISPLAY);
        //                    if (prop != null)
        //                    {
        //                        int pictureIndex = prop.PropertyValue;
        //                        EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord)GetEscherChild(shapeContainer, EscherClientAnchorRecord.RECORD_ID);
        //                        HSSFClientAnchor anchor = new HSSFClientAnchor();
        //                        anchor.Col1 = anchorRecord.Col1;
        //                        anchor.Col2 = anchorRecord.Col2;
        //                        anchor.Dx1 = anchorRecord.Dx1;
        //                        anchor.Dx2 = anchorRecord.Dx2;
        //                        anchor.Dy1 = anchorRecord.Dy1;
        //                        anchor.Dy2 = anchorRecord.Dy2;
        //                        anchor.Row1 = anchorRecord.Row1;
        //                        anchor.Row2 = anchorRecord.Row2;
        //                        HSSFPicture picture = new HSSFPicture(null, anchor);
        //                        picture.PictureIndex = pictureIndex;
        //                        patriarch.AddShape(picture);

        //                    }
        //                    break;
        //            }


        //        }
        //        else
        //        {
        //            // Base level
        //            ConvertRecordsToUserModel(shapeContainer, patriarch);
        //        }
        //    }

        //    // Now, clear any trace of what records make up
        //    //  the patriarch
        //    // Otherwise, everything will go horribly wrong
        //    //  when we try to Write out again....
        //    //    	clearEscherRecords();
        //    drawingManager.GetDgg().FileIdClusters=new EscherDggRecord.FileIdCluster[0];

        //    // TODO: Support Converting our records
        //    //  back into shapes
        //    log.Log(POILogger.WARN, "Not Processing objects into Patriarch!");
        //}

        private EscherRecord GetEscherChild(EscherContainerRecord owner, int recordId)
        {
            for (IEnumerator iterator = owner.ChildRecords.GetEnumerator(); iterator.MoveNext(); )
            {
                EscherRecord escherRecord = (EscherRecord)iterator.Current;
                if (escherRecord.RecordId == recordId)
                    return escherRecord;
            }
            return null;
        }
Exemple #23
0
        /**
         * create base tree with such structure:
         * EscherDgContainer
         * -EscherSpgrContainer
         * --EscherSpContainer
         * ---EscherSpRecord
         * ---EscherSpgrRecord
         * ---EscherSpRecord
         * -EscherDgRecord
         *
         * id of DgRecord and SpRecord are empty and must be set later by HSSFPatriarch
         */
        private void BuildBaseTree()
        {
            EscherContainerRecord dgContainer = new EscherContainerRecord();
            EscherContainerRecord spgrContainer = new EscherContainerRecord();
            EscherContainerRecord spContainer1 = new EscherContainerRecord();
            EscherSpgrRecord spgr = new EscherSpgrRecord();
            EscherSpRecord sp1 = new EscherSpRecord();
            dgContainer.RecordId = (EscherContainerRecord.DG_CONTAINER);
            dgContainer.Options = ((short)0x000F);
            EscherDgRecord dg = new EscherDgRecord();
            dg.RecordId = EscherDgRecord.RECORD_ID;
            short dgId = 1;
            dg.Options = ((short)(dgId << 4));
            dg.NumShapes = (0);
            dg.LastMSOSPID=(1024);
            spgrContainer.RecordId=(EscherContainerRecord.SPGR_CONTAINER);
            spgrContainer.Options=((short)0x000F);
            spContainer1.RecordId=(EscherContainerRecord.SP_CONTAINER);
            spContainer1.Options=((short)0x000F);
            spgr.RecordId=(EscherSpgrRecord.RECORD_ID);
            spgr.Options=((short)0x0001);    // version
            spgr.RectX1=(0);
            spgr.RectY1=(0);
            spgr.RectX2=(1023);
            spgr.RectY2=(255);
            sp1.RecordId=(EscherSpRecord.RECORD_ID);

            sp1.Options=((short)0x0002);
            sp1.Version=((short)0x2);
            sp1.ShapeId=(-1);
            sp1.Flags=(EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH);
            dgContainer.AddChildRecord(dg);
            dgContainer.AddChildRecord(spgrContainer);
            spgrContainer.AddChildRecord(spContainer1);
            spContainer1.AddChildRecord(spgr);
            spContainer1.AddChildRecord(sp1);
            AddEscherRecord(dgContainer);
        }
Exemple #24
0
        public void TestSerialize()
        {

            EscherContainerRecord container1 = new EscherContainerRecord();
            EscherContainerRecord spContainer1 = new EscherContainerRecord();
            EscherContainerRecord spContainer2 = new EscherContainerRecord();
            EscherContainerRecord spContainer3 = new EscherContainerRecord();
            EscherSpRecord sp1 = new EscherSpRecord();
            EscherSpRecord sp2 = new EscherSpRecord();
            EscherSpRecord sp3 = new EscherSpRecord();
            EscherClientDataRecord d2 = new EscherClientDataRecord();
            EscherClientDataRecord d3 = new EscherClientDataRecord();

            container1.Options = ((short)0x000F);
            spContainer1.Options = ((short)0x000F);
            spContainer1.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer2.Options = ((short)0x000F);
            spContainer2.RecordId = (EscherContainerRecord.SP_CONTAINER);
            spContainer3.Options = ((short)0x000F);
            spContainer3.RecordId = (EscherContainerRecord.SP_CONTAINER);
            d2.RecordId = (EscherClientDataRecord.RECORD_ID);
            d2.RemainingData = (new byte[0]);
            d3.RecordId = (EscherClientDataRecord.RECORD_ID);
            d3.RemainingData = (new byte[0]);
            container1.AddChildRecord(spContainer1);
            container1.AddChildRecord(spContainer2);
            container1.AddChildRecord(spContainer3);
            spContainer1.AddChildRecord(sp1);
            spContainer2.AddChildRecord(sp2);
            spContainer3.AddChildRecord(sp3);
            spContainer2.AddChildRecord(d2);
            spContainer3.AddChildRecord(d3);

            EscherAggregate aggregate = new EscherAggregate(null);
            aggregate.AddEscherRecord(container1);
            aggregate.AssoicateShapeToObjRecord(d2, new ObjRecord());
            aggregate.AssoicateShapeToObjRecord(d3, new ObjRecord());

            byte[] data = new byte[112];
            int bytesWritten = aggregate.Serialize(0, data);
            Assert.AreEqual(112, bytesWritten);
            Assert.AreEqual("[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, ]",
                    HexDump.ToHex(data));
        }
        /// <summary>
        /// Generates an escher record including the any children contained under that record.
        /// An exception is thrown if the record could not be generated.
        /// </summary>
        /// <param name="data">The byte array containing the records</param>
        /// <param name="offset">The starting offset into the byte array</param>
        /// <returns>The generated escher record</returns>
        public virtual EscherRecord CreateRecord(byte[] data, int offset)
        {
            short options = LittleEndian.GetShort(data, offset);
            short recordId = LittleEndian.GetShort(data, offset + 2);

            // int remainingBytes = LittleEndian.getInt( data, offset + 4 );
            // Options of 0x000F means container record
            // However, EscherTextboxRecord are containers of records for the
            //  host application, not of other Escher records, so treat them
            //  differently
            if (IsContainer(options, recordId))
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = recordId;
                r.Options = options;
                return r;
            }
            if (recordId >= EscherBlipRecord.RECORD_ID_START && recordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (recordId == EscherBitmapBlip.RECORD_ID_DIB ||
                        recordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                        recordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                else if (recordId == EscherMetafileBlip.RECORD_ID_EMF ||
                        recordId == EscherMetafileBlip.RECORD_ID_WMF ||
                        recordId == EscherMetafileBlip.RECORD_ID_PICT)
                {
                    r = new EscherMetafileBlip();
                }
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = recordId;
                r.Options = options;
                return r;
            }

            //ConstructorInfo recordConstructor = (ConstructorInfo) recordsMap[header.RecordId];
            ConstructorInfo recordConstructor = null;
            if (recordsMap.ContainsKey(recordId))
                recordConstructor = recordsMap[recordId];

            EscherRecord escherRecord = null;
            if (recordConstructor == null)
            {
                return new UnknownEscherRecord();
            }

            try
            {
                escherRecord = (EscherRecord)recordConstructor.Invoke(new object[] { });
                //escherRecord = (EscherRecord)Activator.CreateInstance(recordConstructor);
            }
            catch (Exception)
            {
                return new UnknownEscherRecord();
            }
            escherRecord.RecordId = recordId;
            escherRecord.Options = options;
            return escherRecord;

        }
Exemple #26
0
 /**
  * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
  *
  * @param escherRecord       <code>EscherSpContainer</code> Container which holds information about this shape
  * @param parent             the parent of this Shape
  */
 protected Shape(EscherContainerRecord escherRecord, Shape parent)
 {
     _escherContainer = escherRecord;
     _parent = parent;
 }
Exemple #27
0
 /// <summary>
 /// Creates the low evel records for an polygon.
 /// </summary>
 /// <param name="hssfShape">The highlevel shape.</param>
 /// <param name="shapeId">The shape id to use for this shape.</param>
 public PolygonShape(HSSFPolygon hssfShape, int shapeId)
 {
     spContainer = CreateSpContainer(hssfShape, shapeId);
     objRecord = CreateObjRecord(hssfShape, shapeId);
 }
Exemple #28
0
 /// <summary>
 /// Creates the low evel records for a textbox.
 /// </summary>
 /// <param name="hssfShape">The highlevel shape.</param>
 /// <param name="shapeId">The shape id to use for this shape.</param>
 public TextboxShape(HSSFTextbox hssfShape, int shapeId)
 {
     spContainer = CreateSpContainer(hssfShape, shapeId);
     objRecord = CreateObjRecord(hssfShape, shapeId);
     textObjectRecord = CreateTextObjectRecord(hssfShape, shapeId);
 }
Exemple #29
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherRecord anchor = new EscherClientAnchorRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();
            escherTextbox = new EscherTextboxRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            sp.Options=(short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2);

            sp.ShapeId=shapeId;
            sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            //        opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144 ) );
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, shape.MarginLeft));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, shape.MarginRight));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, shape.MarginBottom));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, shape.MarginTop));

            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

            AddStandardOptions(shape, opt);
            HSSFAnchor userAnchor = shape.Anchor;
            //        if (userAnchor.IsHorizontallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
            //        if (userAnchor.IsVerticallyFlipped())
            //            sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
            anchor = CreateAnchor(userAnchor);
            clientData.RecordId=EscherClientDataRecord.RECORD_ID;
            clientData.Options=(short)0x0000;
            escherTextbox.RecordId=EscherTextboxRecord.RECORD_ID;
            escherTextbox.Options=(short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);
            spContainer.AddChildRecord(escherTextbox);

            return spContainer;
        }
Exemple #30
0
        /// <summary>
        /// Generates an escher record including the any children contained under that record.
        /// An exception is thrown if the record could not be generated.
        /// </summary>
        /// <param name="data">The byte array containing the records</param>
        /// <param name="offset">The starting offset into the byte array</param>
        /// <returns>The generated escher record</returns>
        public virtual EscherRecord CreateRecord(byte[] data, int offset)
        {
            EscherRecord.EscherRecordHeader header = EscherRecord.EscherRecordHeader.ReadHeader(data, offset);

            // Options of 0x000F means container record
            // However, EscherTextboxRecord are containers of records for the
            //  host application, not of other Escher records, so treat them
            //  differently
            if ((header.Options & (short)0x000F) == (short)0x000F &&
                header.RecordId != EscherTextboxRecord.RECORD_ID)
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }
            else if (header.RecordId >= EscherBlipRecord.RECORD_ID_START && header.RecordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (header.RecordId == EscherBitmapBlip.RECORD_ID_DIB ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                else if (header.RecordId == EscherMetafileBlip.RECORD_ID_EMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_WMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_PICT)
                {
                    r = new EscherMetafileBlip();
                }
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }
            else
            {
                //ConstructorInfo recordConstructor = (ConstructorInfo) recordsMap[header.RecordId];
                Type         record       = (Type)recordsMap[header.RecordId];
                EscherRecord escherRecord = null;
                //if ( recordConstructor != null )
                if (record != null)
                {
                    try
                    {
                        escherRecord          = (EscherRecord)Activator.CreateInstance(record);
                        escherRecord.RecordId = header.RecordId;
                        escherRecord.Options  = header.Options;
                    }
                    catch (Exception)
                    {
                        escherRecord = null;
                    }
                }
                return(escherRecord == null ? new UnknownEscherRecord() : escherRecord);
            }
        }
Exemple #31
0
 /**
  * Helper method to return escher child by record ID
  *
  * @return escher record or <code>null</code> if not found.
  */
 public static EscherRecord GetEscherChild(EscherContainerRecord owner, int recordId)
 {
     for (List<EscherRecord>.Enumerator iterator = owner.GetChildIterator(); iterator.MoveNext(); )
     {
         EscherRecord escherRecord = iterator.Current;
         if (escherRecord.RecordId == recordId)
             return escherRecord;
     }
     return null;
 }
Exemple #32
0
        public HSSFTextbox(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord)
            : base(spContainer, objRecord, textObjectRecord)
        {

        }
Exemple #33
0
        /// <summary>
        /// Creates the lowerlevel escher records for this shape.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private EscherContainerRecord CreateSpContainer(HSSFPolygon hssfShape, int shapeId)
        {
            HSSFShape shape = hssfShape;

            EscherContainerRecord spContainer = new EscherContainerRecord();
            EscherSpRecord sp = new EscherSpRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherClientDataRecord clientData = new EscherClientDataRecord();

            spContainer.RecordId=EscherContainerRecord.SP_CONTAINER;
            spContainer.Options=(short)0x000F;
            sp.RecordId=EscherSpRecord.RECORD_ID;
            sp.Options = (short)((EscherAggregate.ST_NOT_PRIMATIVE << 4) | 0x2);
            sp.ShapeId=shapeId;
            if (hssfShape.Parent == null)
                sp.Flags=EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            else
                sp.Flags=EscherSpRecord.FLAG_CHILD | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
            opt.RecordId=EscherOptRecord.RECORD_ID;
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION, false, false, 0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, false, false, hssfShape.DrawAreaWidth));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, false, false, hssfShape.DrawAreaHeight));
            opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX));
            EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0]);
            verticesProp.NumberOfElementsInArray=(hssfShape.XPoints.Length + 1);
            verticesProp.NumberOfElementsInMemory=(hssfShape.XPoints.Length + 1);
            verticesProp.SizeOfElements=unchecked((short)0xFFF0);
            for (int i = 0; i < hssfShape.XPoints.Length; i++)
            {
                byte[] data = new byte[4];
                LittleEndian.PutShort(data, 0, (short)hssfShape.XPoints[i]);
                LittleEndian.PutShort(data, 2, (short)hssfShape.YPoints[i]);
                verticesProp.SetElement(i, data);
            }
            int point = hssfShape.XPoints.Length;
            byte[] data1 = new byte[4];
            LittleEndian.PutShort(data1, 0, (short)hssfShape.XPoints[0]);
            LittleEndian.PutShort(data1, 2, (short)hssfShape.YPoints[0]);
            verticesProp.SetElement(point, data1);
            opt.AddEscherProperty(verticesProp);
            EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null);
            segmentsProp.SizeOfElements=(0x0002);
            segmentsProp.NumberOfElementsInArray=(hssfShape.XPoints.Length * 2 + 4);
            segmentsProp.NumberOfElementsInMemory=(hssfShape.XPoints.Length * 2 + 4);
            segmentsProp.SetElement(0, new byte[] { (byte)0x00, (byte)0x40 });
            segmentsProp.SetElement(1, new byte[] { (byte)0x00, (byte)0xAC });
            for (int i = 0; i < hssfShape.XPoints.Length; i++)
            {
                segmentsProp.SetElement(2 + i * 2, new byte[] { (byte)0x01, (byte)0x00 });
                segmentsProp.SetElement(3 + i * 2, new byte[] { (byte)0x00, (byte)0xAC });
            }
            segmentsProp.SetElement(segmentsProp.NumberOfElementsInArray - 2, new byte[] { (byte)0x01, (byte)0x60 });
            segmentsProp.SetElement(segmentsProp.NumberOfElementsInArray - 1, new byte[] { (byte)0x00, (byte)0x80 });
            opt.AddEscherProperty(segmentsProp);
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__FILLOK, false, false, 0x00010001));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINESTARTARROWHEAD, false, false, 0x0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDARROWHEAD, false, false, 0x0));
            opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, false, false, 0x0));

            AddStandardOptions(shape, opt);

            EscherRecord anchor = CreateAnchor(shape.Anchor);
            clientData.RecordId=(EscherClientDataRecord.RECORD_ID);
            clientData.Options=(short)0x0000;

            spContainer.AddChildRecord(sp);
            spContainer.AddChildRecord(opt);
            spContainer.AddChildRecord(anchor);
            spContainer.AddChildRecord(clientData);

            return spContainer;
        }
Exemple #34
0
 internal override HSSFShape CloneShape()
 {
     TextObjectRecord txo = GetTextObjectRecord() == null ? null : (TextObjectRecord)GetTextObjectRecord().CloneViaReserialise();
     EscherContainerRecord spContainer = new EscherContainerRecord();
     byte[] inSp = GetEscherContainer().Serialize();
     spContainer.FillFields(inSp, 0, new DefaultEscherRecordFactory());
     ObjRecord obj = (ObjRecord)GetObjRecord().CloneViaReserialise();
     return new HSSFTextbox(spContainer, obj, txo);
 }