Beispiel #1
0
        /// <summary>
        /// Creates the anchor.
        /// </summary>
        /// <param name="userAnchor">The user anchor.</param>
        /// <returns></returns>
        public static EscherRecord CreateAnchor(HSSFAnchor userAnchor)
        {
            if (userAnchor is HSSFClientAnchor)
            {
                HSSFClientAnchor a = (HSSFClientAnchor)userAnchor;

                EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
                anchor.RecordId=EscherClientAnchorRecord.RECORD_ID;
                anchor.Options=(short)0x0000;
                anchor.Flag=(short)a.AnchorType;
                anchor.Col1=(short)Math.Min(a.Col1, a.Col2);
                anchor.Dx1=(short)a.Dx1;
                anchor.Row1=(short)Math.Min(a.Row1, a.Row2);
                anchor.Dy1=(short)a.Dy1;

                anchor.Col2=(short)Math.Max(a.Col1, a.Col2);
                anchor.Dx2=(short)a.Dx2;
                anchor.Row2=(short)Math.Max(a.Row1, a.Row2);
                anchor.Dy2=(short)a.Dy2;
                return anchor;
            }
            else
            {
                HSSFChildAnchor a = (HSSFChildAnchor)userAnchor;
                EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
                anchor.RecordId=EscherChildAnchorRecord.RECORD_ID;
                anchor.Options=(short)0x0000;
                anchor.Dx1=(short)Math.Min(a.Dx1, a.Dx2);
                anchor.Dy1=(short)Math.Min(a.Dy1, a.Dy2);
                anchor.Dx2=(short)Math.Max(a.Dx2, a.Dx1);
                anchor.Dy2=(short)Math.Max(a.Dy2, a.Dy1);
                return anchor;
            }
        }
Beispiel #2
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;
        }
        public void TestFillFields()
        {
            String hexData = "01 00 " +
                    "0F F0 " +
                    "10 00 00 00 " +
                    "01 00 00 00 " +
                    "02 00 00 00 " +
                    "03 00 00 00 " +
                    "04 00 00 00 ";

            byte[] data = HexRead.ReadFromString(hexData);
            EscherChildAnchorRecord r = new EscherChildAnchorRecord();
            int bytesWritten = r.FillFields(data, new DefaultEscherRecordFactory());

            Assert.AreEqual(24, bytesWritten);
            Assert.AreEqual(1, r.Dx1);
            Assert.AreEqual(2, r.Dy1);
            Assert.AreEqual(3, r.Dx2);
            Assert.AreEqual(4, r.Dy2);
            Assert.AreEqual((short)0x0001, r.Options);
        }
Beispiel #4
0
 public HSSFChildAnchor()
 {
     _escherChildAnchor = new EscherChildAnchorRecord();
 }
Beispiel #5
0
 public HSSFChildAnchor(EscherChildAnchorRecord escherChildAnchorRecord)
 {
     this._escherChildAnchor = escherChildAnchorRecord;
 }
Beispiel #6
0
 protected override void CreateEscherAnchor()
 {
     _escherChildAnchor = new EscherChildAnchorRecord();
 }
 private EscherChildAnchorRecord CreateRecord()
 {
     EscherChildAnchorRecord r = new EscherChildAnchorRecord();
     r.RecordId=EscherChildAnchorRecord.RECORD_ID;
     r.Options=(short)0x0001;
     r.Dx1=1;
     r.Dy1=2;
     r.Dx2=3;
     r.Dy2=4;
     return r;
 }
Beispiel #8
0
        public void TestChildAnchorFromEscher()
        {
            EscherChildAnchorRecord escher = new EscherChildAnchorRecord();
            escher.Dx1=((short)15);
            escher.Dx2=((short)16);
            escher.Dy1=((short)17);
            escher.Dy2=((short)18);

            HSSFChildAnchor anchor = new HSSFChildAnchor(escher);
            Assert.AreEqual(anchor.Dx1, 15);
            Assert.AreEqual(escher.Dx1, 15);
            Assert.AreEqual(anchor.Dx2, 16);
            Assert.AreEqual(escher.Dx2, 16);
            Assert.AreEqual(anchor.Dy1, 17);
            Assert.AreEqual(escher.Dy1, 17);
            Assert.AreEqual(anchor.Dy2, 18);
            Assert.AreEqual(escher.Dy2, 18);
        }
Beispiel #9
0
        public void TestCreateChildAnchorFromContainer()
        {
            EscherContainerRecord container = new EscherContainerRecord();
            EscherChildAnchorRecord escher = new EscherChildAnchorRecord();
            escher.Dx1=((short)15);
            escher.Dx2=((short)16);
            escher.Dy1=((short)17);
            escher.Dy2=((short)18);
            container.AddChildRecord(escher);

            HSSFChildAnchor anchor = (HSSFChildAnchor)HSSFAnchor.CreateAnchorFromEscher(container);
            Assert.AreEqual(anchor.Dx1, 15);
            Assert.AreEqual(escher.Dx1, 15);
            Assert.AreEqual(anchor.Dx2, 16);
            Assert.AreEqual(escher.Dx2, 16);
            Assert.AreEqual(anchor.Dy1, 17);
            Assert.AreEqual(escher.Dy1, 17);
            Assert.AreEqual(anchor.Dy2, 18);
            Assert.AreEqual(escher.Dy2, 18);
        }