/**
* Finds the next available (1 based) drawing group id
*/
- short findNewDrawingGroupId()
+ public short findNewDrawingGroupId()
{
short dgId = 1;
while ( drawingGroupExists( dgId ) )
return dgg;
}
+ public void incrementDrawingsSaved(){
+ dgg.setDrawingsSaved(dgg.getDrawingsSaved()+1);
+ }
}
return -1;
}
- EscherAggregate aggregate = new EscherAggregate( drawingManager );
+ EscherAggregate aggregate = new EscherAggregate();
loc = findFirstRecordLocBySid(EscherAggregate.sid);
if (loc == -1) {
loc = findFirstRecordLocBySid( WindowTwoRecord.sid );
pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i);
}
}
- if ((pos - offset) < buffer.length-1){
+ if ((pos - offset) < buffer.length - 1) {
byte[] drawingData = new byte[buffer.length - (pos - offset)];
System.arraycopy(buffer, (pos - offset), drawingData, 0, drawingData.length);
pos += writeDataIntoDrawingRecord(0, drawingData, writtenEscherBytes, pos, data, i);
}
int drawingRecordSize = rawEscherSize + (shapeToObj.size()) * 4;
- if (rawEscherSize != 0 && spEndingOffsets.size()==1/**EMPTY**/){
- continueRecordsHeadersSize +=4;
+ if (rawEscherSize != 0 && spEndingOffsets.size() == 1/**EMPTY**/) {
+ continueRecordsHeadersSize += 4;
}
int objRecordSize = 0;
for (Iterator iterator = shapeToObj.values().iterator(); iterator.hasNext(); ) {
throw new IllegalArgumentException("Can not find client data record");
}
- private void buildBaseTree(){
+ private void buildBaseTree() {
EscherContainerRecord dgContainer = new EscherContainerRecord();
EscherContainerRecord spgrContainer = new EscherContainerRecord();
EscherContainerRecord spContainer1 = new EscherContainerRecord();
dg.setRecordId( EscherDgRecord.RECORD_ID );
short dgId = 1;
dg.setOptions((short) (dgId << 4));
- dg.setNumShapes(1);
+ dg.setNumShapes(0);
dg.setLastMSOSPID(1024);
drawingGroupId = dg.getDrawingGroupId();
spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
spgr.setRectY2(255);
sp1.setRecordId(EscherSpRecord.RECORD_ID);
sp1.setOptions((short) 0x0002);
- sp1.setShapeId(1024);
+ sp1.setShapeId(-1);
sp1.setFlags(EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH);
dgContainer.addChildRecord(dg);
dgContainer.addChildRecord(spgrContainer);
addEscherRecord(dgContainer);
}
+ public void setDgId(short dgId) {
+ EscherContainerRecord dgContainer = getEscherContainer();
+ EscherDgRecord dg = dgContainer.getChildById(EscherDgRecord.RECORD_ID);
+ dg.setOptions((short) (dgId << 4));
+ }
+
+ public void setMainSpRecordId(int shapeId){
+ EscherContainerRecord dgContainer = getEscherContainer();
+ EscherContainerRecord spContainer = (EscherContainerRecord) dgContainer.getChildById(EscherContainerRecord.SPGR_CONTAINER).getChild(0);
+ EscherSpRecord sp = (EscherSpRecord) spContainer.getChildById(EscherSpRecord.RECORD_ID);
+ sp.setShapeId(shapeId);
+ }
+
private void convertPatriarch(HSSFPatriarch patriarch) {
EscherContainerRecord dgContainer = new EscherContainerRecord();
EscherDgRecord dg;
}
/**
- *
* @return tails records. We need to access them when building shapes.
- * Every HSSFComment shape has a link to a NoteRecord from the tailRec collection.
+ * Every HSSFComment shape has a link to a NoteRecord from the tailRec collection.
*/
- public List<Record> getTailRecords(){
+ public List<Record> getTailRecords() {
return Collections.unmodifiableList(tailRec);
}
- public NoteRecord getNoteRecordByObj(ObjRecord obj){
- for (Record rec: tailRec){
+ public NoteRecord getNoteRecordByObj(ObjRecord obj) {
+ for (Record rec : tailRec) {
NoteRecord note = (NoteRecord) rec;
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) obj.getSubRecords().get(0);
- if (note.getShapeId() == cod.getObjectId()){
+ if (note.getShapeId() == cod.getObjectId()) {
return note;
}
}
return null;
}
+
+ public void addTailRecord(NoteRecord note){
+ tailRec.add(note);
+ }
}
_note = note;
}
+ @Override
+ void afterInsert(HSSFPatriarch patriarch) {
+ super.afterInsert(patriarch);
+ _patriarch._getBoundAggregate().addTailRecord(getNoteRecord());
+ }
+
@Override
protected ObjRecord createObjRecord() {
ObjRecord obj = new ObjRecord();
@Override
void setShapeId(int shapeId) {
super.setShapeId(shapeId);
- _note.setShapeId(shapeId-1024);
+ CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0);
+ cod.setObjectId((short) (shapeId));
+ _note.setShapeId(shapeId);
}
/**
*/
public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
private final List<HSSFShape> _shapes = new ArrayList<HSSFShape>();
- private int _x1 = 0;
- private int _y1 = 0 ;
- private int _x2 = 1023;
- private int _y2 = 255;
+// private int _x1 = 0;
+// private int _y1 = 0 ;
+// private int _x2 = 1023;
+// private int _y2 = 255;
+
+ private final EscherSpgrRecord _spgrRecord;
/**
* The EscherAggregate we have been bound to.
HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate){
_sheet = sheet;
_boundAggregate = boundAggregate;
+ EscherContainerRecord spContainer = (EscherContainerRecord) _boundAggregate.getEscherContainer()
+ .getChildContainers().get(0).getChild(0);
+ _spgrRecord = spContainer.getChildById(EscherSpgrRecord.RECORD_ID);
+ buildShapeTree();
+ }
+
+ public void afterCreate(){
+ DrawingManager2 drawingManager = _sheet.getWorkbook().getWorkbook().getDrawingManager();
+ short dgId = drawingManager.findNewDrawingGroupId();
+ _boundAggregate.setDgId(dgId);
+ _boundAggregate.setMainSpRecordId(newShapeId());
+ drawingManager.incrementDrawingsSaved();
}
/**
* to these coordinates.
*/
public void setCoordinates(int x1, int y1, int x2, int y2){
- _x1 = x1;
- _y1 = y1;
- _x2 = x2;
- _y2 = y2;
+ _spgrRecord.setRectY1(y1);
+ _spgrRecord.setRectY2(y2);
+ _spgrRecord.setRectX1(x1);
+ _spgrRecord.setRectX2(x2);
}
int newShapeId() {
- if (_boundAggregate.getEscherContainer() == null){
- throw new IllegalStateException("We can use this method for only existing files");
- }
- DrawingManager2 dm = _boundAggregate.getDrawingManager();
+ DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager();
EscherDgRecord dg =
_boundAggregate.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
short drawingGroupId = dg.getDrawingGroupId();
*/
public int getX1()
{
- return _x1;
+ return _spgrRecord.getRectX1();
}
/**
*/
public int getY1()
{
- return _y1;
+ return _spgrRecord.getRectY1();
}
/**
*/
public int getX2()
{
- return _x2;
+ return _spgrRecord.getRectX2();
}
/**
*/
public int getY2()
{
- return _y2;
+ return _spgrRecord.getRectY2();
}
/**
void buildShapeTree(){
EscherContainerRecord dgContainer = _boundAggregate.getEscherContainer();
+ if (dgContainer == null){
+ return;
+ }
EscherContainerRecord spgrConrainer = dgContainer.getChildContainers().get(0);
List<EscherContainerRecord> spgrChildren = spgrConrainer.getChildContainers();
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, 0x0));
+ opt.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1));
+
+ opt.setEscherProperty(new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000));
EscherRecord anchor = getAnchor().getEscherAnchor();
clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
*/
public void setLineStyle(int lineStyle) {
setPropertyValue(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, lineStyle));
+ if (getLineStyle() == HSSFShape.LINESTYLE_NONE){
+ setPropertyValue(new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
+ } else {
+ setPropertyValue( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
+ }
}
/**
case CommonObjectDataSubRecord.OBJECT_TYPE_RECTANGLE:\r
shape = new HSSFSimpleShape(container, objRecord);\r
break;\r
+ case CommonObjectDataSubRecord.OBJECT_TYPE_LINE:\r
+ shape = new HSSFSimpleShape(container, objRecord);\r
+ break;\r
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:\r
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);\r
EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);\r
public HSSFShapeGroup(HSSFShape parent, HSSFAnchor anchor) {
super(parent, anchor);
- _spgrRecord = new EscherSpgrRecord();
- _spgrRecord.setRectX1(0);
- _spgrRecord.setRectX2(1023);
- _spgrRecord.setRectY1(0);
- _spgrRecord.setRectY2(255);
+ _spgrRecord = ((EscherContainerRecord)_escherContainer.getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID);
}
@Override
shape.setShapeId(shapeId);
_escherContainer.addChildRecord(spContainer);
shape.afterInsert(_patriarch);
+ EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
+ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD);
}
}
EscherSpRecord spRecord = containerRecord.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setShapeId(shapeId);
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0);
- cod.setObjectId((short) (shapeId-1024));
+ cod.setObjectId((short) (shapeId));
}
@Override
_sheet.aggregateDrawingRecords(_book.getDrawingManager(), true);
EscherAggregate agg = (EscherAggregate) _sheet.findFirstRecordBySid(EscherAggregate.sid);
_patriarch = new HSSFPatriarch(this, agg);
- agg.setPatriarch(_patriarch);
+ _patriarch.afterCreate();
+// agg.setPatriarch(_patriarch);
}
}
return _patriarch;
if(agg == null) return null;
_patriarch = new HSSFPatriarch(this, agg);
- _patriarch.buildShapeTree();
+// _patriarch.buildShapeTree();
//HSSFShapeFactory.createShapeTree();
//agg.setPatriarch(_patriarch);
objTypeToShapeType.put(OBJECT_TYPE_RECTANGLE, HSSFShapeType.RECTANGLE.getType());
objTypeToShapeType.put(OBJECT_TYPE_PICTURE, HSSFShapeType.PICTURE.getType());
objTypeToShapeType.put(OBJECT_TYPE_LINE, HSSFShapeType.LINE.getType());
+ objTypeToShapeType.put(OBJECT_TYPE_OVAL, HSSFShapeType.OVAL.getType());
}
public HSSFSimpleShape(EscherContainerRecord spContainer, ObjRecord objRecord) {
EscherOptRecord optRecord = new EscherOptRecord();
optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID));
- optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
+ optRecord.setEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
+// optRecord.setEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT));
optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT));
optRecord.setEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT));
- optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x0));
+ optRecord.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0));
+ optRecord.setEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
+
+ optRecord.setEscherProperty( new EscherShapePathProperty( EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX ) );
+ optRecord.setEscherProperty(new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000));
optRecord.setRecordId( EscherOptRecord.RECORD_ID );
spContainer.addChildRecord(sp);
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, 0x0));
-
+ opt.setEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1));
+ opt.setEscherProperty(new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000));
EscherRecord anchor = getAnchor().getEscherAnchor();
clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
package org.apache.poi.hssf.usermodel.drawing;\r
\r
+import org.apache.poi.hssf.record.EscherAggregate;\r
import org.apache.poi.hssf.usermodel.HSSFPicture;\r
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;\r
import org.apache.poi.hssf.usermodel.HSSFTextbox;\r
RECTANGLE((short)0x1, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_RECTANGLE),\r
PICTURE((short)0x004B, HSSFPicture.class, HSSFSimpleShape.OBJECT_TYPE_PICTURE),\r
LINE((short)0x14, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_LINE),\r
+ OVAL(EscherAggregate.ST_ELLIPSE, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_OVAL),\r
TEXT((short)202, HSSFTextbox.class, HSSFTextbox.OBJECT_TYPE_TEXT),\r
ROUND_RECTANGLE((short)0x2, null, null);\r
\r
}\r
\r
public void testBuildBaseTree(){\r
- EscherAggregate agg = new EscherAggregate();\r
HSSFWorkbook wb = new HSSFWorkbook();\r
HSSFSheet sheet = wb.createSheet();\r
-\r
- HSSFPatriarch drawing = sheet.createDrawingPatriarch();\r
- EscherAggregate agg1 = HSSFTestHelper.getEscherAggregate(drawing);\r
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+ EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);\r
+ EscherAggregate agg1 = new EscherAggregate(new HSSFTestHelper.MockDrawingManager());\r
+ EscherSpgrRecord spgr = new EscherSpgrRecord();\r
+ spgr.setRectY1(0);\r
+ spgr.setRectY2(255);\r
+ spgr.setRectX1(0);\r
+ spgr.setRectX2(1023);\r
+ EscherContainerRecord spContainer = new EscherContainerRecord();\r
+ spContainer.addChildRecord(spgr);\r
+ EscherContainerRecord spgrContainer = new EscherContainerRecord();\r
+ spgrContainer.addChildRecord(spContainer);\r
+ EscherContainerRecord dgContainer = new EscherContainerRecord();\r
+ dgContainer.addChildRecord(spgrContainer);\r
+ agg1.addEscherRecord(dgContainer);\r
+ agg1.setPatriarch(HSSFTestHelper.createTestPatriarch(sheet, agg1));\r
+ agg1.clear();\r
HSSFTestHelper.callConvertPatriarch(agg1);\r
agg1.setPatriarch(null);\r
- \r
+\r
agg.setPatriarch(null);\r
+//\r
+ EscherSpRecord sp = (EscherSpRecord) agg.getEscherContainer().getChildContainers().get(0).getChild(0).getChild(1);\r
+ sp.setShapeId(1025);\r
+ EscherDgRecord dg = (EscherDgRecord) agg.getEscherContainer().getChild(0);\r
+ dg.setNumShapes(1);\r
+ dg.setOptions((short) (1 << 4));\r
\r
byte[] aggS = agg.serialize();\r
byte []agg1S = agg1.serialize();\r
textbox.setLineStyleColor(textbox.getLineStyleColor());\r
assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml());\r
}\r
+\r
+ public void testDgRecordNumShapes(){\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+ HSSFSheet sheet = wb.createSheet();\r
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+ EscherAggregate aggregate = HSSFTestHelper.getEscherAggregate(patriarch);\r
+ EscherDgRecord dgRecord = (EscherDgRecord) aggregate.getEscherRecord(0).getChild(0);\r
+ assertEquals(dgRecord.getNumShapes(), 1);\r
+ }\r
}\r
==================================================================== */
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherDggRecord;
-import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.*;
import org.apache.poi.hssf.model.DrawingManager2;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Map;
/**
*/
public class HSSFTestHelper {
- private static class MockDrawingManager extends DrawingManager2 {
-//
-// public MockDrawingManager(EscherDggRecord dgg) {
-// super(dgg);
-// }
+ public static class MockDrawingManager extends DrawingManager2 {
public MockDrawingManager (){
super(null);
@Override
public int allocateShapeId(short drawingGroupId) {
- return 0; //Mock value
+ return 1025; //Mock value
+ }
+
+ @Override
+ public int allocateShapeId(short drawingGroupId, EscherDgRecord dg) {
+ return 1025;
+ }
+
+ public EscherDgRecord createDgRecord()
+ {
+ EscherDgRecord dg = new EscherDgRecord();
+ dg.setRecordId( EscherDgRecord.RECORD_ID );
+ dg.setOptions( (short) (16) );
+ dg.setNumShapes( 1 );
+ dg.setLastMSOSPID( 1024 );
+ return dg;
}
}
/**
import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.hssf.model.CommentShape;\r
import org.apache.poi.hssf.model.HSSFTestModelHelper;\r
-import org.apache.poi.hssf.record.CommonObjectDataSubRecord;\r
-import org.apache.poi.hssf.record.NoteRecord;\r
-import org.apache.poi.hssf.record.ObjRecord;\r
-import org.apache.poi.hssf.record.TextObjectRecord;\r
+import org.apache.poi.hssf.record.*;\r
\r
import java.io.IOException;\r
import java.util.Arrays;\r
HSSFCell cell = row.createCell(0);\r
cell.setCellComment(comment);\r
\r
- CommentShape commentShape = HSSFTestModelHelper.createCommentShape(0, comment);\r
+ CommentShape commentShape = HSSFTestModelHelper.createCommentShape(1025, comment);\r
\r
assertEquals(comment.getEscherContainer().getChildRecords().size(), 5);\r
assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5);\r
HSSFSheet sh = wb.createSheet();\r
HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
\r
+ EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);\r
+ assertEquals(agg.getTailRecords().size(), 0);\r
+\r
HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor());\r
+ assertEquals(agg.getTailRecords().size(), 1);\r
\r
HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());\r
\r
- //5 properties of HSSFShape + 8 of HSSFTextbox\r
- assertEquals(comment._optRecord.getEscherProperties().size(), 13);\r
+ //6 properties of HSSFShape + 8 of HSSFTextbox\r
+ assertEquals(comment._optRecord.getEscherProperties().size(), 14);\r
}\r
\r
public void testShapeId(){\r
assertEquals(comment.getShapeId(), 2024);\r
\r
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) comment.getObjRecord().getSubRecords().get(0);\r
- assertEquals(cod.getObjectId(), 1000);\r
+ assertEquals(cod.getObjectId(), 2024);\r
EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0);\r
assertEquals(spRecord.getShapeId(), 2024);\r
assertEquals(comment.getShapeId(), 2024);\r
- assertEquals(comment.getNoteRecord().getShapeId(), 1000);\r
+ assertEquals(comment.getNoteRecord().getShapeId(), 2024);\r
}\r
}\r
\r
import junit.framework.TestCase;\r
import org.apache.poi.ddf.EscherContainerRecord;\r
+import org.apache.poi.ddf.EscherSpgrRecord;\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.hssf.record.ObjRecord;\r
\r
+import java.lang.reflect.Field;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
group.getShapeId();\r
}\r
+\r
+ public void testSpgrRecord(){\r
+ HSSFWorkbook wb = new HSSFWorkbook();\r
+\r
+ // create a sheet with a text box\r
+ HSSFSheet sheet = wb.createSheet();\r
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();\r
+\r
+ HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor());\r
+ assertSame(((EscherContainerRecord)group.getEscherContainer().getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID), getSpgrRecord(group));\r
+ }\r
+\r
+ private static EscherSpgrRecord getSpgrRecord(HSSFShapeGroup group) {\r
+ Field spgrField = null;\r
+ try {\r
+ spgrField = group.getClass().getDeclaredField("_spgrRecord");\r
+ spgrField.setAccessible(true);\r
+ return (EscherSpgrRecord) spgrField.get(group);\r
+ } catch (NoSuchFieldException e) {\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
}\r
HSSFSheet sh = wb.createSheet();\r
HSSFPatriarch patriarch = sh.createDrawingPatriarch();\r
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());\r
- TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(0, textbox);\r
+ TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(1025, textbox);\r
\r
assertEquals(textbox.getEscherContainer().getChildRecords().size(), 5);\r
assertEquals(textboxShape.getSpContainer().getChildRecords().size(), 5);\r
assertTrue(Arrays.equals(expected, actual));\r
\r
ObjRecord obj = textbox.getObjRecord();\r
- ((CommonObjectDataSubRecord) obj.getSubRecords().get(0)).setObjectId(-1024);\r
ObjRecord objShape = textboxShape.getObjRecord();\r
\r
expected = obj.serialize();\r