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"); } NPOI.SS.UserModel.RichTextString str = new HSSFRichTextString(buff.ToString()); TextObjectRecord obj = new TextObjectRecord(); obj.Str = (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); } }
protected virtual TextObjectRecord CreateTextObjRecord() { TextObjectRecord obj = new TextObjectRecord(); obj.HorizontalTextAlignment = HorizontalTextAlignment.Center; obj.VerticalTextAlignment = VerticalTextAlignment.Center; obj.IsTextLocked = (true); obj.TextOrientation = TextOrientation.None; obj.Str = (new HSSFRichTextString("")); return(obj); }
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)); }
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); }
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); }
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); }
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)); }
public void TestLoad() { TextObjectRecord record = new TextObjectRecord(TestcaseRecordInputStream.Create(data)); Assert.AreEqual(HorizontalAlignment.Center, record.HorizontalTextAlignment); Assert.AreEqual(VerticalAlignment.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); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; TextboxShape textboxShape = HSSFTestModelHelper.CreateTextboxShape(1025, textbox); Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); Assert.AreEqual(textboxShape.SpContainer.ChildRecords.Count, 5); //sp record byte[] expected = textboxShape.SpContainer.GetChild(0).Serialize(); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(2).Serialize(); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(3).Serialize(); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(4).Serialize(); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = textbox.GetObjRecord(); ObjRecord objShape = textboxShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); TextObjectRecord tor = textbox.GetTextObjectRecord(); TextObjectRecord torShape = textboxShape.TextObjectRecord; expected = tor.Serialize(); actual = torShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); }
internal override HSSFShape CloneShape() { TextObjectRecord txo = null; EscherContainerRecord spContainer = new EscherContainerRecord(); byte[] inSp = GetEscherContainer().Serialize(); spContainer.FillFields(inSp, 0, new DefaultEscherRecordFactory()); ObjRecord obj = (ObjRecord)GetObjRecord().CloneViaReserialise(); if (GetTextObjectRecord() != null && this.String != null && null != this.String.String) { txo = (TextObjectRecord)GetTextObjectRecord().CloneViaReserialise(); } return(new HSSFSimpleShape(spContainer, obj, txo)); }
/// <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 = hssfShape.HorizontalAlignment; obj.VerticalTextAlignment = hssfShape.VerticalAlignment; obj.IsTextLocked = true; obj.TextOrientation = TextOrientation.None; int frLength = (shape.String.NumFormattingRuns + 1) * 8; obj.Str = shape.String; return(obj); }
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); }
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)); }
public void TestResultEqualsToNonExistingAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA="); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual) CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA="); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); ObjRecord obj = textbox.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); TextObjectRecord tor = textbox.GetTextObjectRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA=="); actual = tor.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); wb.Close(); }
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); } }
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 = HorizontalAlignment.Center; record.VerticalTextAlignment = VerticalAlignment.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 TestClone() { String text = "Hello, World"; HSSFRichTextString str = new HSSFRichTextString(text); TextObjectRecord obj = new TextObjectRecord(); obj.Str = (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(NPOI.Util.Arrays.Equals(src, cln)); }
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); }
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); }
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); }
public void TestWrite() { HSSFRichTextString str = new HSSFRichTextString("Hello, World!"); TextObjectRecord record = new TextObjectRecord(); record.Str = (str); record.HorizontalTextAlignment = (TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED); record.VerticalTextAlignment = (TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP); record.IsTextLocked = (true); record.TextOrientation = (TextObjectRecord.TEXT_ORIENTATION_NONE); byte[] ser = record.Serialize(); //Assert.AreEqual(ser.Length , data.Length); //Assert.IsTrue(Arrays.Equals(data, ser)); //Read again RecordInputStream is1 = new RecordInputStream(new MemoryStream(data)); is1.NextRecord(); record = new TextObjectRecord(is1); }
public void TestWriteEmpty() { HSSFRichTextString str = new HSSFRichTextString(""); TextObjectRecord record = new TextObjectRecord(); record.Str = (str); byte[] ser = record.Serialize(); int formatDataLen = NPOI.Util.LittleEndian.GetUShort(ser, 16); Assert.AreEqual(0, formatDataLen, "formatDataLength"); Assert.AreEqual(22, ser.Length); // just the TXO record //read again RecordInputStream is1 = new RecordInputStream(new MemoryStream(ser)); is1.NextRecord(); record = new TextObjectRecord(is1); Assert.AreEqual(0, record.Str.Length); }
public HSSFPolygon(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord _textObjectRecord) : base(spContainer, objRecord, _textObjectRecord) { }
public HSSFTextbox(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord) : base(spContainer, objRecord, textObjectRecord) { }
/// <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); }
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); }
/// <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; }
/// <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; }
//private TextObjectRecord txo = null; public HSSFComment(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord textObjectRecord, NoteRecord _note) : base(spContainer, objRecord, textObjectRecord) { this._note = _note; }