Example #1
0
        public void TestLoad()
        {
            TextObjectRecord record = new TextObjectRecord(TestcaseRecordInputStream.Create(data));
            Assert.AreEqual(HorizontalTextAlignment.Center, record.HorizontalTextAlignment);
            Assert.AreEqual(VerticalTextAlignment.Justify, record.VerticalTextAlignment);
            Assert.AreEqual(true, record.IsTextLocked);
            Assert.AreEqual(TextOrientation.RotRight, record.TextOrientation);


            Assert.AreEqual(49, record.RecordSize);
        }
        public void TestLoad()
        {
            TextObjectRecord record = new TextObjectRecord(TestcaseRecordInputStream.Create(data));
            Assert.AreEqual(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED, record.HorizontalTextAlignment);
            Assert.AreEqual(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY, record.VerticalTextAlignment);
            Assert.AreEqual(true, record.IsTextLocked);
            Assert.AreEqual(TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT, record.TextOrientation);


            Assert.AreEqual(49, record.RecordSize);
        }
Example #3
0
        public void TestRead()
        {

            RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData);
            TextObjectRecord record = new TextObjectRecord(is1);

            Assert.AreEqual(TextObjectRecord.sid, record.Sid);
            Assert.AreEqual(HorizontalAlignment.Left, record.HorizontalTextAlignment);
            Assert.AreEqual(VerticalAlignment.Top, record.VerticalTextAlignment);
            Assert.AreEqual(TextOrientation.None, record.TextOrientation);
            Assert.AreEqual("Hello, World!", record.Str.String);
        }
Example #4
0
        public void TestRead()
        {

            RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData);
            TextObjectRecord record = new TextObjectRecord(is1);

            Assert.AreEqual(TextObjectRecord.sid, record.Sid);
            Assert.AreEqual(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED, record.HorizontalTextAlignment);
            Assert.AreEqual(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP, record.VerticalTextAlignment);
            Assert.AreEqual(TextObjectRecord.TEXT_ORIENTATION_NONE, record.TextOrientation);
            Assert.AreEqual("Hello, World!", record.Str.String);
        }
Example #5
0
        public void TestStore()
        {
            TextObjectRecord record = new TextObjectRecord();
            HSSFRichTextString str = new HSSFRichTextString("AB");
            str.ApplyFont(0, 2, (short)0x0018);
            str.ApplyFont(2, 2, (short)0x0320);

            record.HorizontalTextAlignment = HorizontalTextAlignment.Center;
            record.VerticalTextAlignment = VerticalTextAlignment.Justify;
            record.IsTextLocked = (true);
            record.TextOrientation = TextOrientation.RotRight;
            record.Str = (str);

            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length, data.Length);
            for (int i = 0; i < data.Length; i++)
                Assert.AreEqual(data[i], recordBytes[i], "At offset " + i);
        }
        public void TestStore()
        {
            TextObjectRecord record = new TextObjectRecord();
            HSSFRichTextString str = new HSSFRichTextString("AB");
            str.ApplyFont(0, 2, (short)0x0018);
            str.ApplyFont(2, 2, (short)0x0320);

            record.HorizontalTextAlignment = (TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED);
            record.VerticalTextAlignment = (TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY);
            record.IsTextLocked = (true);
            record.TextOrientation = (TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT);
            record.Str = (str);

            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length, data.Length);
            for (int i = 0; i < data.Length; i++)
                Assert.AreEqual(data[i], recordBytes[i], "At offset " + i);
        }
Example #7
0
        public void TestWrite()
        {
            HSSFRichTextString str = new HSSFRichTextString("Hello, World!");

            TextObjectRecord record = new TextObjectRecord();
            record.Str = (/*setter*/str);
            record.HorizontalTextAlignment = (/*setter*/ TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED);
            record.VerticalTextAlignment = (/*setter*/ TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP);
            record.IsTextLocked = (/*setter*/ true);
            record.TextOrientation = (/*setter*/ TextObjectRecord.TEXT_ORIENTATION_NONE);

            byte[] ser = record.Serialize();
            Assert.AreEqual(ser.Length, simpleData.Length);

            Assert.IsTrue(Arrays.Equals(simpleData, ser));

            //read again
            RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData);
            record = new TextObjectRecord(is1);
        }
Example #8
0
        public void TestWrite()
        {
            HSSFRichTextString str = new HSSFRichTextString("Hello, World!");

            TextObjectRecord record = new TextObjectRecord();
            record.Str = (/*setter*/str);
            record.HorizontalTextAlignment = (/*setter*/ HorizontalTextAlignment.Left);
            record.VerticalTextAlignment = (/*setter*/ VerticalTextAlignment.Top);
            record.IsTextLocked = (/*setter*/ true);
            record.TextOrientation = (/*setter*/ TextOrientation.None);

            byte[] ser = record.Serialize();
            Assert.AreEqual(ser.Length, simpleData.Length);

            Assert.IsTrue(Arrays.Equals(simpleData, ser));

            //read again
            RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData);
            record = new TextObjectRecord(is1);
        }
Example #9
0
        public override Object Clone()
        {
            TextObjectRecord rec = new TextObjectRecord();

            rec._text = _text;

            rec.field_1_options         = field_1_options;
            rec.field_2_textOrientation = field_2_textOrientation;
            rec.field_3_reserved4       = field_3_reserved4;
            rec.field_4_reserved5       = field_4_reserved5;
            rec.field_5_reserved6       = field_5_reserved6;
            rec.field_8_reserved7       = field_8_reserved7;

            rec._text = _text; // clone needed?

            if (_linkRefPtg != null)
            {
                rec._unknownPreFormulaInt   = _unknownPreFormulaInt;
                rec._linkRefPtg             = _linkRefPtg.Copy();
                rec._unknownPostFormulaByte = _unknownPostFormulaByte;
            }
            return(rec);
        }
Example #10
0
        public void TestLinkFormula()
        {
            RecordInputStream is1 = new RecordInputStream(new MemoryStream(linkData));
            is1.NextRecord();
            TextObjectRecord rec = new TextObjectRecord(is1);

            Ptg ptg = rec.LinkRefPtg;
            Assert.IsNotNull(ptg);
            Assert.AreEqual(typeof(RefPtg), ptg.GetType());
            RefPtg rptg = (RefPtg)ptg;
            Assert.AreEqual("T2", rptg.ToFormulaString());

            byte[] data2 = rec.Serialize();
            Assert.AreEqual(linkData.Length, data2.Length);
            Assert.IsTrue(Arrays.Equals(linkData, data2));
        }
Example #11
0
        public void TestClone()
        {
            String text = "Hello, World";
            HSSFRichTextString str = new HSSFRichTextString(text);

            TextObjectRecord obj = new TextObjectRecord();
            obj.Str = (/*setter*/ str);


            TextObjectRecord Cloned = (TextObjectRecord)obj.Clone();
            Assert.AreEqual(obj.RecordSize, Cloned.RecordSize);
            Assert.AreEqual(obj.HorizontalTextAlignment, Cloned.HorizontalTextAlignment);
            Assert.AreEqual(obj.Str.String, Cloned.Str.String);

            //finally check that the Serialized data is the same
            byte[] src = obj.Serialize();
            byte[] cln = Cloned.Serialize();
            Assert.IsTrue(Arrays.Equals(src, cln));
        }
Example #12
0
        public override Object Clone()
        {

            TextObjectRecord rec = new TextObjectRecord();
            rec._text = _text;

            rec.field_1_options = field_1_options;
            rec.field_2_textOrientation = field_2_textOrientation;
            rec.field_3_reserved4 = field_3_reserved4;
            rec.field_4_reserved5 = field_4_reserved5;
            rec.field_5_reserved6 = field_5_reserved6;
            rec.field_8_reserved7 = field_8_reserved7;

            rec._text = _text; // clone needed?

            if (_linkRefPtg != null)
            {
                rec._unknownPreFormulaInt = _unknownPreFormulaInt;
                rec._linkRefPtg = _linkRefPtg.Copy();
                rec._unknownPostFormulaByte = _unknownPostFormulaByte;
            }
            return rec;
        }
Example #13
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);
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFComment"/> class.
 /// </summary>
 /// <param name="note">The note.</param>
 /// <param name="txo">The txo.</param>
 public HSSFComment(NoteRecord note, TextObjectRecord txo)
     : this((HSSFShape)null, new HSSFClientAnchor())
 {
     this._note = note;
 }
Example #15
0
 public HSSFSimpleShape(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord)
     : base(spContainer, objRecord)
 {
     this._textObjectRecord = textObjectRecord;
 }
Example #16
0
 private TextObjectRecord GetOrCreateTextObjRecord()
 {
     if (GetTextObjectRecord() == null)
     {
         _textObjectRecord = CreateTextObjRecord();
     }
     EscherTextboxRecord escherTextbox = (EscherTextboxRecord)GetEscherContainer().GetChildById(EscherTextboxRecord.RECORD_ID);
     if (null == escherTextbox)
     {
         escherTextbox = new EscherTextboxRecord();
         escherTextbox.RecordId = (EscherTextboxRecord.RECORD_ID);
         escherTextbox.Options = ((short)0x0000);
         GetEscherContainer().AddChildRecord(escherTextbox);
         Patriarch.getBoundAggregate().AssociateShapeToObjRecord(escherTextbox, _textObjectRecord);
     }
     return _textObjectRecord;
 }
Example #17
0
 protected virtual TextObjectRecord CreateTextObjRecord()
 {
     TextObjectRecord obj = new TextObjectRecord();
     obj.HorizontalTextAlignment = HorizontalAlignment.Center;
     obj.VerticalTextAlignment = VerticalAlignment.Center;
     obj.IsTextLocked = (true);
     obj.TextOrientation = TextOrientation.None;
     obj.Str = (new HSSFRichTextString(""));
     return obj;
 }
Example #18
0
 protected virtual TextObjectRecord CreateTextObjRecord()
 {
     TextObjectRecord obj = new TextObjectRecord();
     obj.HorizontalTextAlignment = (2);
     obj.VerticalTextAlignment = (2);
     obj.IsTextLocked = (true);
     obj.TextOrientation = (TextObjectRecord.TEXT_ORIENTATION_NONE);
     obj.Str = (new HSSFRichTextString(""));
     return obj;
 }
Example #19
0
        public void TestWriteEmpty()
        {
            HSSFRichTextString str = new HSSFRichTextString("");

            TextObjectRecord record = new TextObjectRecord();
            record.Str = (/*setter*/str);

            byte[] ser = record.Serialize();

            int formatDataLen = LittleEndian.GetUShort(ser, 16);
            Assert.AreEqual(0, formatDataLen, "formatDataLength");

            Assert.AreEqual(22, ser.Length); // just the TXO record

            //read again
            RecordInputStream is1 = TestcaseRecordInputStream.Create(ser);
            record = new TextObjectRecord(is1);
            Assert.AreEqual(0, record.Str.Length);
        }
Example #20
0
        //private TextObjectRecord txo = null;
        public HSSFComment(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord _note)
            : base(spContainer, objRecord, textObjectRecord)
        {

            this._note = _note;
        }
Example #21
0
        public HSSFPolygon(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord _textObjectRecord)
            : base(spContainer, objRecord, _textObjectRecord)
        {

        }
Example #22
0
        /// <summary>
        /// Textboxes also have an extra TXO record associated with them that most
        /// other shapes dont have.
        /// </summary>
        /// <param name="hssfShape">The HSSF shape.</param>
        /// <param name="shapeId">The shape id.</param>
        /// <returns></returns>
        private TextObjectRecord CreateTextObjectRecord(HSSFTextbox hssfShape, int shapeId)
        {
            HSSFTextbox shape = hssfShape;

            TextObjectRecord obj = new TextObjectRecord();
            obj.HorizontalTextAlignment=(int)hssfShape.HorizontalAlignment;
            obj.VerticalTextAlignment=(int)hssfShape.VerticalAlignment;
            obj.IsTextLocked=true;
            obj.TextOrientation=TextObjectRecord.TEXT_ORIENTATION_NONE;
            int frLength = (shape.String.NumFormattingRuns + 1) * 8;
            obj.Str=shape.String;

            return obj;
        }
Example #23
0
        public void TestLongRecords()
        {
            int[] length = { 1024, 2048, 4096, 8192, 16384 }; //test against strings of different length
            for (int i = 0; i < length.Length; i++)
            {
                StringBuilder buff = new StringBuilder(length[i]);
                for (int j = 0; j < length[i]; j++)
                {
                    buff.Append("x");
                }
                IRichTextString str = new HSSFRichTextString(buff.ToString());

                TextObjectRecord obj = new TextObjectRecord();
                obj.Str = (/*setter*/str);

                byte[] data = obj.Serialize();
                RecordInputStream is1 = new RecordInputStream(new MemoryStream(data));
                is1.NextRecord();
                TextObjectRecord record = new TextObjectRecord(is1);
                str = record.Str;

                Assert.AreEqual(buff.Length, str.Length);
                Assert.AreEqual(buff.ToString(), str.String);
            }
        }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFSimpleShape"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="anchor">The anchor.</param>
 public HSSFSimpleShape(HSSFShape parent, HSSFAnchor anchor)
     :base(parent, anchor)
 {
     _textObjectRecord = CreateTextObjRecord();
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HSSFComment"/> class.
 /// </summary>
 /// <param name="note">The note.</param>
 /// <param name="txo">The txo.</param>
 public HSSFComment(NoteRecord note, TextObjectRecord txo)
     : this((HSSFShape)null, (HSSFAnchor)null)
 {
     this.txo = txo;
     this.note = note;
 }
Example #26
0
        public void TestCreateAggregate()
        {
            String msoDrawingRecord1 =
                    "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
                    "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" +
                    "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" +
                    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" +
                    "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" +
                    "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" +
                    "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" +
                    "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" +
                    "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" +
                    "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" +
                    "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" +
                    "05 00 94 00 00 00 11 F0 00 00 00 00";

            String msoDrawingRecord2 =
                    "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " +
                    "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " +
                    "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " +
                    "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " +
                    "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " +
                    "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " +
                    "0B 00 0C 00 00 00 11 F0 00 00 00 00";

            DrawingRecord d1 = new DrawingRecord();
            d1.Data = HexRead.ReadFromString(msoDrawingRecord1);

            ObjRecord r1 = new ObjRecord();

            DrawingRecord d2 = new DrawingRecord();
            d2.Data = (HexRead.ReadFromString(msoDrawingRecord2));

            TextObjectRecord r2 = new TextObjectRecord();
            r2.Str = (new HSSFRichTextString("Aggregated"));
            NoteRecord n2 = new NoteRecord();

            List<RecordBase> recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);


            recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(d2);
            recordStream.Add(r2);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);

            recordStream = new List<RecordBase>();
            recordStream.Add(InternalSheet.CreateBOF());
            recordStream.Add(d1);
            recordStream.Add(r1);
            recordStream.Add(d2);
            recordStream.Add(r2);
            recordStream.Add(n2);
            recordStream.Add(CreateWindow2Record());
            recordStream.Add(EOFRecord.instance);

            ConfirmAggregatedRecords(recordStream);
        }
Example #27
0
        public HSSFTextbox(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord)
            : base(spContainer, objRecord, textObjectRecord)
        {

        }