]> source.dussan.org Git - poi.git/commitdiff
implemented creating shapes in new file using new model
authorEvgeniy Berlog <berlog@apache.org>
Fri, 6 Jul 2012 17:00:20 +0000 (17:00 +0000)
committerEvgeniy Berlog <berlog@apache.org>
Fri, 6 Jul 2012 17:00:20 +0000 (17:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1358301 13f79535-47bb-0310-9956-ffa450edef68

19 files changed:
src/java/org/apache/poi/hssf/model/DrawingManager2.java
src/java/org/apache/poi/hssf/model/InternalSheet.java
src/java/org/apache/poi/hssf/record/EscherAggregate.java
src/java/org/apache/poi/hssf/usermodel/HSSFComment.java
src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java
src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java
src/java/org/apache/poi/hssf/usermodel/HSSFShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
src/java/org/apache/poi/hssf/usermodel/drawing/HSSFShapeType.java
src/testcases/org/apache/poi/hssf/model/TestDrawingAggregate.java
src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java
src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
src/testcases/org/apache/poi/hssf/usermodel/TestComment.java
src/testcases/org/apache/poi/hssf/usermodel/TestShapeGroup.java
src/testcases/org/apache/poi/hssf/usermodel/TestText.java

index c9993c2418732b4110fa8e5524ab85a9a76eb639..0d5e34f24d8c9185024792f6bf259754f212f8ae 100644 (file)
@@ -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);
+    }
 }
index 1e0af24530989d367460f7bda6accecdc4aec9a0..09d8e4b80389a4ee3051d9704d25716ac95c9ac6 100644 (file)
@@ -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 );
index b5bb2121a06bcd009f0ddd020680dee766638810..11e2c8d4b098e03390b7cc79f2fa068639445aea 100644 (file)
@@ -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<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);
+    }
 }
index add7e327288b9b31ab855eba85cb22483f2ab972..3e844516e9c0055f734072f396179814acb1b10e 100644 (file)
@@ -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);
     }
 
     /**
index 675c7d7f86a2df009392cf02745a100a8b84ca42..07fcc4d0d08f42fc533fef58b380f5ac08fafc6e 100644 (file)
@@ -38,10 +38,12 @@ import org.apache.poi.ss.usermodel.ClientAnchor;
  */
 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.
@@ -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<EscherContainerRecord> spgrChildren = spgrConrainer.getChildContainers();
 
index 8d561a0ff1253de2cdb98b9f5496ebea3918d911..44684a6052e7dc761d7ea1d96c27f66169a8a5e3 100644 (file)
@@ -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);
index 09bf271fc5c0d59c6fa90612cfe7ad3d35af55b9..be69ad635496bd93b6f2283afa1636dc13b9a021 100644 (file)
@@ -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));
+        }
     }
 
     /**
index 1ee53171b6117238b32f30c9942fafb66f0b388d..e65afcb2003861df6962954e5b887d80eb0cc923 100644 (file)
@@ -119,6 +119,9 @@ public class HSSFShapeFactory {
                 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
index eb023e0cae75eb67fe04ed630fb64a3b663f16af..f7fab2bbc8401648df637090cef8d39266b08641 100644 (file)
@@ -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
index cbfb1807d11312a6ac3d5f6b47981121823aa565..aa25061c40dbc9584b2b9fa4b2a668d5f689cd29 100644 (file)
@@ -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);
index 62b9d6a8e0def364e856b561a62d1792255d2176..bc000b715be9a697ce761e08ddeaaca338535dad 100644 (file)
@@ -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);
index 1ed70f86a675f30ccc00b482796a886f3c75122b..4e652de5e549f06b914d99f57086d86be3d9dfc2 100644 (file)
@@ -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);
index 2e2b64eeb49c27e7d01bfb8add06f2f6684f62d6..f386dd1cfefd6874bac1f8d0c97254cff5b79056 100644 (file)
@@ -1,5 +1,6 @@
 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
@@ -13,6 +14,7 @@ public enum HSSFShapeType {
     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
index 1f058c06daa981295b26e4bb908bb08e839e68ba..b49721251857620e7bf82a3435d01990143ad3ba 100644 (file)
@@ -195,16 +195,35 @@ public class TestDrawingAggregate extends TestCase {
     }\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
index 4e120a7cb83b7e225c0fbd96e0006a44733e27a1..e50aa47adf1d285c3cb29de77ebaedfe29f4b154 100644 (file)
@@ -324,4 +324,14 @@ public class TestDrawingShapes extends TestCase {
         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
index 214121d9402ee9e1e053c11f5873a50cb17fd37e..3aafa04edd3db83474c8f10c699358b1bfd461bb 100644 (file)
@@ -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;
         }
     }
        /**
index 91b1a7cb19fb1971d6ca3353ce1b099e88c32508..376edc32b116b2c16dd132787655c7b91a68dd50 100644 (file)
@@ -5,10 +5,7 @@ import org.apache.poi.ddf.EscherSpRecord;
 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
@@ -29,7 +26,7 @@ public class TestComment extends TestCase {
         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
@@ -207,12 +204,16 @@ public class TestComment extends TestCase {
         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
@@ -232,10 +233,10 @@ public class TestComment extends TestCase {
         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
index bdbf25fc4d5996ac4b5451f90a0ddb895fc6ed3d..5eb93f6e3e586efe6b2539b528168f8977ab2b00 100644 (file)
@@ -2,9 +2,11 @@ package org.apache.poi.hssf.usermodel;
 \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
@@ -222,4 +224,29 @@ public class TestShapeGroup extends TestCase{
 \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
index 213c5be674f487b420f818940fd4428c7aa53331..18eefd4786f507ec287c620f32309d4c9d94a24d 100644 (file)
@@ -21,7 +21,7 @@ public class TestText extends TestCase {
         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
@@ -52,7 +52,6 @@ public class TestText extends TestCase {
         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