use of org.apache.poi.hssf.record.TextObjectRecord in project poi by apache.
the class HSSFComment method cloneShape.
@Override
protected 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) getNoteRecord().cloneViaReserialise();
return new HSSFComment(spContainer, obj, txo, note);
}
use of org.apache.poi.hssf.record.TextObjectRecord in project poi by apache.
the class HSSFSimpleShape method createTextObjRecord.
protected TextObjectRecord createTextObjRecord() {
TextObjectRecord obj = new TextObjectRecord();
obj.setHorizontalTextAlignment(2);
obj.setVerticalTextAlignment(2);
obj.setTextLocked(true);
obj.setTextOrientation(TextObjectRecord.TEXT_ORIENTATION_NONE);
obj.setStr(new HSSFRichTextString(""));
return obj;
}
use of org.apache.poi.hssf.record.TextObjectRecord in project poi by apache.
the class TestSheet method testCreateAggregate.
@Test
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.setData(HexRead.readFromString(msoDrawingRecord1));
ObjRecord r1 = new ObjRecord();
DrawingRecord d2 = new DrawingRecord();
d2.setData(HexRead.readFromString(msoDrawingRecord2));
TextObjectRecord r2 = new TextObjectRecord();
r2.setStr(new HSSFRichTextString("Aggregated"));
NoteRecord n2 = new NoteRecord();
List<Record> recordStream = new ArrayList<Record>();
recordStream.add(InternalSheet.createBOF());
recordStream.add(d1);
recordStream.add(r1);
recordStream.add(createWindow2Record());
recordStream.add(EOFRecord.instance);
confirmAggregatedRecords(recordStream);
recordStream = new ArrayList<Record>();
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 ArrayList<Record>();
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);
}
use of org.apache.poi.hssf.record.TextObjectRecord in project poi by apache.
the class TestText method testResultEqualsToNonExistingAbstractShape.
@Test
public void testResultEqualsToNonExistingAbstractShape() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sh = wb.createSheet();
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
assertEquals(textbox.getEscherContainer().getChildRecords().size(), 5);
//sp record
byte[] expected = decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA=");
byte[] actual = textbox.getEscherContainer().getChild(0).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
expected = decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA==");
actual = textbox.getEscherContainer().getChild(2).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
expected = decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA=");
actual = textbox.getEscherContainer().getChild(3).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
expected = decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA=");
actual = textbox.getEscherContainer().getChild(4).serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
ObjRecord obj = textbox.getObjRecord();
expected = decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA");
actual = obj.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
TextObjectRecord tor = textbox.getTextObjectRecord();
expected = decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA==");
actual = tor.serialize();
assertEquals(expected.length, actual.length);
assertArrayEquals(expected, actual);
wb.close();
}
use of org.apache.poi.hssf.record.TextObjectRecord in project poi by apache.
the class TestDrawingAggregate method testSerializeDrawingBigger8k.
/**
* Try to check file with such record sequence
* ...
* DrawingRecord
* ContinueRecord
* ObjRecord | TextObjRecord
* ...
*/
@Test
public void testSerializeDrawingBigger8k() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 32, records.size());
// the last record before the drawing block
assertTrue("records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(), records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 26);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
assertTrue(sid == DrawingRecord.sid || sid == ContinueRecord.sid || sid == ObjRecord.sid || sid == NoteRecord.sid || sid == TextObjectRecord.sid);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue("records.get(26) is expected to be Window2", records.get(26) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 26, records.size());
assertTrue("records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(), records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(), records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(), records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertTrue("drawing data before and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
wb.close();
}
Aggregations