From: Evgeniy Berlog Date: Fri, 6 Jul 2012 17:00:20 +0000 (+0000) Subject: implemented creating shapes in new file using new model X-Git-Tag: 3.10-beta1~161^2~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=06df547a594c30a10d9d25eb82fcd107c2f42ae4;p=poi.git implemented creating shapes in new file using new model git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1358301 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/model/DrawingManager2.java b/src/java/org/apache/poi/hssf/model/DrawingManager2.java index c9993c2418..0d5e34f24d 100644 --- a/src/java/org/apache/poi/hssf/model/DrawingManager2.java +++ b/src/java/org/apache/poi/hssf/model/DrawingManager2.java @@ -112,7 +112,7 @@ public class DrawingManager2 /** * Finds the next available (1 based) drawing group id */ - short findNewDrawingGroupId() + public short findNewDrawingGroupId() { short dgId = 1; while ( drawingGroupExists( dgId ) ) @@ -147,4 +147,7 @@ public class DrawingManager2 return dgg; } + public void incrementDrawingsSaved(){ + dgg.setDrawingsSaved(dgg.getDrawingsSaved()+1); + } } diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index 1e0af24530..09d8e4b803 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -1497,7 +1497,7 @@ public final class InternalSheet { return -1; } - EscherAggregate aggregate = new EscherAggregate( drawingManager ); + EscherAggregate aggregate = new EscherAggregate(); loc = findFirstRecordLocBySid(EscherAggregate.sid); if (loc == -1) { loc = findFirstRecordLocBySid( WindowTwoRecord.sid ); diff --git a/src/java/org/apache/poi/hssf/record/EscherAggregate.java b/src/java/org/apache/poi/hssf/record/EscherAggregate.java index b5bb2121a0..11e2c8d4b0 100644 --- a/src/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/src/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -524,7 +524,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { 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); @@ -613,8 +613,8 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } 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(); ) { @@ -1032,7 +1032,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { 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(); @@ -1044,7 +1044,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { 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); @@ -1059,7 +1059,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { 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); @@ -1069,6 +1069,19 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { 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; @@ -1145,22 +1158,25 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } /** - * * @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 getTailRecords(){ + public List 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); + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java b/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java index add7e32728..3e844516e9 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java @@ -68,6 +68,12 @@ public class HSSFComment extends HSSFTextbox implements Comment { _note = note; } + @Override + void afterInsert(HSSFPatriarch patriarch) { + super.afterInsert(patriarch); + _patriarch._getBoundAggregate().addTailRecord(getNoteRecord()); + } + @Override protected ObjRecord createObjRecord() { ObjRecord obj = new ObjRecord(); @@ -96,7 +102,9 @@ public class HSSFComment extends HSSFTextbox implements Comment { @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); } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java index 675c7d7f86..07fcc4d0d0 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java @@ -38,10 +38,12 @@ import org.apache.poi.ss.usermodel.ClientAnchor; */ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { private final List _shapes = new ArrayList(); - 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. @@ -59,6 +61,18 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { 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(); } /** @@ -234,17 +248,14 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { * 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(); @@ -289,7 +300,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { */ public int getX1() { - return _x1; + return _spgrRecord.getRectX1(); } /** @@ -297,7 +308,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { */ public int getY1() { - return _y1; + return _spgrRecord.getRectY1(); } /** @@ -305,7 +316,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { */ public int getX2() { - return _x2; + return _spgrRecord.getRectX2(); } /** @@ -313,7 +324,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { */ public int getY2() { - return _y2; + return _spgrRecord.getRectY2(); } /** @@ -348,6 +359,9 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { void buildShapeTree(){ EscherContainerRecord dgContainer = _boundAggregate.getEscherContainer(); + if (dgContainer == null){ + return; + } EscherContainerRecord spgrConrainer = dgContainer.getChildContainers().get(0); List spgrChildren = spgrConrainer.getChildContainers(); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java index 8d561a0ff1..44684a6052 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java @@ -69,10 +69,13 @@ public class HSSFPolygon extends HSSFShape { 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); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java index 09bf271fc5..be69ad6354 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java @@ -248,6 +248,11 @@ public abstract class HSSFShape { */ 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)); + } } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java index 1ee53171b6..e65afcb200 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java @@ -119,6 +119,9 @@ public class HSSFShapeFactory { case CommonObjectDataSubRecord.OBJECT_TYPE_RECTANGLE: shape = new HSSFSimpleShape(container, objRecord); break; + case CommonObjectDataSubRecord.OBJECT_TYPE_LINE: + shape = new HSSFSimpleShape(container, objRecord); + break; case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING: EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID); EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java index eb023e0cae..f7fab2bbc8 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java @@ -57,11 +57,7 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { 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 @@ -133,6 +129,8 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { shape.setShapeId(shapeId); _escherContainer.addChildRecord(spContainer); shape.afterInsert(_patriarch); + EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); + sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD); } } @@ -296,7 +294,7 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { 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 diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index cbfb1807d1..aa25061c40 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -1683,7 +1683,8 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { _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; @@ -1738,7 +1739,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { if(agg == null) return null; _patriarch = new HSSFPatriarch(this, agg); - _patriarch.buildShapeTree(); +// _patriarch.buildShapeTree(); //HSSFShapeFactory.createShapeTree(); //agg.setPatriarch(_patriarch); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java index 62b9d6a8e0..bc000b715b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java @@ -65,6 +65,7 @@ public class HSSFSimpleShape extends HSSFShape 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) { @@ -93,10 +94,15 @@ public class HSSFSimpleShape extends HSSFShape 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); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java b/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java index 1ed70f86a6..4e652de5e5 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java @@ -119,11 +119,12 @@ public class HSSFTextbox extends HSSFSimpleShape { 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); diff --git a/src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java b/src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java index 2e2b64eeb4..f386dd1cfe 100644 --- a/src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java +++ b/src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java @@ -1,5 +1,6 @@ package org.apache.poi.hssf.usermodel.drawing; +import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.usermodel.HSSFPicture; import org.apache.poi.hssf.usermodel.HSSFSimpleShape; import org.apache.poi.hssf.usermodel.HSSFTextbox; @@ -13,6 +14,7 @@ public enum HSSFShapeType { RECTANGLE((short)0x1, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_RECTANGLE), PICTURE((short)0x004B, HSSFPicture.class, HSSFSimpleShape.OBJECT_TYPE_PICTURE), LINE((short)0x14, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_LINE), + OVAL(EscherAggregate.ST_ELLIPSE, HSSFSimpleShape.class, HSSFSimpleShape.OBJECT_TYPE_OVAL), TEXT((short)202, HSSFTextbox.class, HSSFTextbox.OBJECT_TYPE_TEXT), ROUND_RECTANGLE((short)0x2, null, null); diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java index 1f058c06da..b497212518 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java +++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java @@ -195,16 +195,35 @@ public class TestDrawingAggregate extends TestCase { } public void testBuildBaseTree(){ - EscherAggregate agg = new EscherAggregate(); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); - - HSSFPatriarch drawing = sheet.createDrawingPatriarch(); - EscherAggregate agg1 = HSSFTestHelper.getEscherAggregate(drawing); + HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); + EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch); + EscherAggregate agg1 = new EscherAggregate(new HSSFTestHelper.MockDrawingManager()); + EscherSpgrRecord spgr = new EscherSpgrRecord(); + spgr.setRectY1(0); + spgr.setRectY2(255); + spgr.setRectX1(0); + spgr.setRectX2(1023); + EscherContainerRecord spContainer = new EscherContainerRecord(); + spContainer.addChildRecord(spgr); + EscherContainerRecord spgrContainer = new EscherContainerRecord(); + spgrContainer.addChildRecord(spContainer); + EscherContainerRecord dgContainer = new EscherContainerRecord(); + dgContainer.addChildRecord(spgrContainer); + agg1.addEscherRecord(dgContainer); + agg1.setPatriarch(HSSFTestHelper.createTestPatriarch(sheet, agg1)); + agg1.clear(); HSSFTestHelper.callConvertPatriarch(agg1); agg1.setPatriarch(null); - + agg.setPatriarch(null); +// + EscherSpRecord sp = (EscherSpRecord) agg.getEscherContainer().getChildContainers().get(0).getChild(0).getChild(1); + sp.setShapeId(1025); + EscherDgRecord dg = (EscherDgRecord) agg.getEscherContainer().getChild(0); + dg.setNumShapes(1); + dg.setOptions((short) (1 << 4)); byte[] aggS = agg.serialize(); byte []agg1S = agg1.serialize(); diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java index 4e120a7cb8..e50aa47adf 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java +++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java @@ -324,4 +324,14 @@ public class TestDrawingShapes extends TestCase { textbox.setLineStyleColor(textbox.getLineStyleColor()); assertEquals(opt1Str, textbox.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID).toXml()); } + + public void testDgRecordNumShapes(){ + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); + + EscherAggregate aggregate = HSSFTestHelper.getEscherAggregate(patriarch); + EscherDgRecord dgRecord = (EscherDgRecord) aggregate.getEscherRecord(0).getChild(0); + assertEquals(dgRecord.getNumShapes(), 1); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java index 214121d940..3aafa04edd 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java @@ -16,9 +16,7 @@ ==================================================================== */ 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; @@ -26,6 +24,7 @@ import org.apache.poi.hssf.record.EscherAggregate; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Map; /** @@ -35,11 +34,7 @@ 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); @@ -47,7 +42,22 @@ public class HSSFTestHelper { @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; } } /** diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java index 91b1a7cb19..376edc32b1 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestComment.java @@ -5,10 +5,7 @@ import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.CommentShape; import org.apache.poi.hssf.model.HSSFTestModelHelper; -import org.apache.poi.hssf.record.CommonObjectDataSubRecord; -import org.apache.poi.hssf.record.NoteRecord; -import org.apache.poi.hssf.record.ObjRecord; -import org.apache.poi.hssf.record.TextObjectRecord; +import org.apache.poi.hssf.record.*; import java.io.IOException; import java.util.Arrays; @@ -29,7 +26,7 @@ public class TestComment extends TestCase { HSSFCell cell = row.createCell(0); cell.setCellComment(comment); - CommentShape commentShape = HSSFTestModelHelper.createCommentShape(0, comment); + CommentShape commentShape = HSSFTestModelHelper.createCommentShape(1025, comment); assertEquals(comment.getEscherContainer().getChildRecords().size(), 5); assertEquals(commentShape.getSpContainer().getChildRecords().size(), 5); @@ -207,12 +204,16 @@ public class TestComment extends TestCase { HSSFSheet sh = wb.createSheet(); HSSFPatriarch patriarch = sh.createDrawingPatriarch(); + EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch); + assertEquals(agg.getTailRecords().size(), 0); + HSSFComment comment = patriarch.createCellComment(new HSSFClientAnchor()); + assertEquals(agg.getTailRecords().size(), 1); HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor()); - //5 properties of HSSFShape + 8 of HSSFTextbox - assertEquals(comment._optRecord.getEscherProperties().size(), 13); + //6 properties of HSSFShape + 8 of HSSFTextbox + assertEquals(comment._optRecord.getEscherProperties().size(), 14); } public void testShapeId(){ @@ -232,10 +233,10 @@ public class TestComment extends TestCase { assertEquals(comment.getShapeId(), 2024); CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) comment.getObjRecord().getSubRecords().get(0); - assertEquals(cod.getObjectId(), 1000); + assertEquals(cod.getObjectId(), 2024); EscherSpRecord spRecord = (EscherSpRecord) comment.getEscherContainer().getChild(0); assertEquals(spRecord.getShapeId(), 2024); assertEquals(comment.getShapeId(), 2024); - assertEquals(comment.getNoteRecord().getShapeId(), 1000); + assertEquals(comment.getNoteRecord().getShapeId(), 2024); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java index bdbf25fc4d..5eb93f6e3e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java @@ -2,9 +2,11 @@ package org.apache.poi.hssf.usermodel; import junit.framework.TestCase; import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.ddf.EscherSpgrRecord; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.record.ObjRecord; +import java.lang.reflect.Field; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -222,4 +224,29 @@ public class TestShapeGroup extends TestCase{ group.getShapeId(); } + + public void testSpgrRecord(){ + HSSFWorkbook wb = new HSSFWorkbook(); + + // create a sheet with a text box + HSSFSheet sheet = wb.createSheet(); + HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); + + HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor()); + assertSame(((EscherContainerRecord)group.getEscherContainer().getChild(0)).getChildById(EscherSpgrRecord.RECORD_ID), getSpgrRecord(group)); + } + + private static EscherSpgrRecord getSpgrRecord(HSSFShapeGroup group) { + Field spgrField = null; + try { + spgrField = group.getClass().getDeclaredField("_spgrRecord"); + spgrField.setAccessible(true); + return (EscherSpgrRecord) spgrField.get(group); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java index 213c5be674..18eefd4786 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestText.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestText.java @@ -21,7 +21,7 @@ public class TestText extends TestCase { HSSFSheet sh = wb.createSheet(); HSSFPatriarch patriarch = sh.createDrawingPatriarch(); HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor()); - TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(0, textbox); + TextboxShape textboxShape = HSSFTestModelHelper.createTextboxShape(1025, textbox); assertEquals(textbox.getEscherContainer().getChildRecords().size(), 5); assertEquals(textboxShape.getSpContainer().getChildRecords().size(), 5); @@ -52,7 +52,6 @@ public class TestText extends TestCase { assertTrue(Arrays.equals(expected, actual)); ObjRecord obj = textbox.getObjRecord(); - ((CommonObjectDataSubRecord) obj.getSubRecords().get(0)).setObjectId(-1024); ObjRecord objShape = textboxShape.getObjRecord(); expected = obj.serialize();