]> source.dussan.org Git - poi.git/commitdiff
Bug 51332 - Fixed internal IDs of shapes generated by HSSFPatriarch when there are...
authorYegor Kozlov <yegor@apache.org>
Wed, 22 Jun 2011 13:48:43 +0000 (13:48 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 22 Jun 2011 13:48:43 +0000 (13:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1138465 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/AbstractShape.java
src/java/org/apache/poi/hssf/model/ComboboxShape.java
src/java/org/apache/poi/hssf/model/CommentShape.java
src/java/org/apache/poi/hssf/model/LineShape.java
src/java/org/apache/poi/hssf/model/PictureShape.java
src/java/org/apache/poi/hssf/model/PolygonShape.java
src/java/org/apache/poi/hssf/model/SimpleFilledShape.java
src/java/org/apache/poi/hssf/model/TextboxShape.java
src/testcases/org/apache/poi/hssf/model/TestShapes.java [new file with mode: 0644]

index 00bf4414461f15e781d22c5cabc9c1b8f37d59f1..f1b78a6ba7d819a4035b4df5bfe778e529fa9bbd 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51332 - Fixed internal IDs of shapes generated by HSSFPatriarch when there are more than 1023 drawing objects </action>
            <action dev="poi-developers" type="fix">48408 - Improved documentation for Sheet.setColumnWidth </action>
            <action dev="poi-developers" type="add">51390 - Added handling of additional properties to HWPF ParagraphSprmCompressor</action>
            <action dev="poi-developers" type="add">51389 - Support for sprmPJc paragraph SPRM in HWPF</action>
index 31c1d1d8afbed90fd0b6cba770528004f6cc9ad1..3fd8883d6339edfa32281f712bf7d514dc8ee824 100644 (file)
@@ -150,4 +150,28 @@ public abstract class AbstractShape
         return options;   // # options added
     }
 
+    /**
+     * Generate id for the CommonObjectDataSubRecord that stands behind this shape
+     *
+     * <p>
+     *     Typically objectId starts with 1, is unique among all Obj record within the worksheet stream
+     *     and increments by 1 for every new shape.
+     *     For most shapes there is a straight relationship between shapeId (generated by DDF) and objectId:
+     * </p>
+     * <p>
+     *     shapeId  is unique and starts with 1024, hence objectId can be derived as <code>shapeId-1024</code>.
+     * </p>
+     * <p>
+     *     An exception from this rule is the CellComment shape whose objectId start with 1024.
+     *      See {@link CommentShape#getCmoObjectId(int)}
+     * </p>
+     *
+     *
+     *
+     * @param  shapeId   shape id as generated by drawing manager
+     * @return objectId  object id that will be assigned to the Obj record
+     */
+    int getCmoObjectId(int shapeId){
+        return shapeId - 1024;
+    }
 }
index df697c79f1004b6677633806b128717b0406b019..7032687f786a591317f8589a5e0fe95ebd9f260f 100644 (file)
@@ -50,7 +50,7 @@ public class ComboboxShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType(HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX);
-        c.setObjectId(shapeId);
+        c.setObjectId(  getCmoObjectId(shapeId) );
         c.setLocked(true);
         c.setPrintable(false);
         c.setAutofill(true);
index 23242d56d86803f2fb84aa8a75bbbb25cecfa2d2..f739a44d72970df6e7b2546910ba69acfc485253 100644 (file)
@@ -136,4 +136,10 @@ public final class CommentShape extends TextboxShape {
     {
         return _note;
     }
+
+    @Override
+    int getCmoObjectId(int shapeId){
+        return shapeId;
+    }
+
 }
index 74913b3afcd68c07a5306ec8b7c3096fabee77f6..2480d426067ebeea77d314bba7d9861a1be7ef94 100644 (file)
@@ -97,7 +97,7 @@ public class LineShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
-        c.setObjectId(shapeId);
+        c.setObjectId(  getCmoObjectId(shapeId) );
         c.setLocked(true);
         c.setPrintable(true);
         c.setAutofill(true);
index 01cebe56d7d6b0cea3c60318663ae0724f3a8aca..fb5041e21b49cae61f247c14b66d0236dfbd859b 100644 (file)
@@ -99,21 +99,15 @@ public class PictureShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
-//        c.setObjectId((short) ( 1 ));
-        c.setObjectId(shapeId);
+        c.setObjectId( getCmoObjectId(shapeId) );
         c.setLocked(true);
         c.setPrintable(true);
         c.setAutofill(true);
         c.setAutoline(true);
-//        c.setReserved2( 0x012C0A84 );
         c.setReserved2( 0x0 );
-//        UnknownRecord sub1 = new UnknownRecord( (short)0x7, (short)0x2, new byte[] { 0x09, 0x00 } );
-//        UnknownRecord sub2 = new UnknownRecord( (short)0x8, (short)0x2, new byte[] { 0x01, 0x00 } );
         EndSubRecord e = new EndSubRecord();
 
         obj.addSubRecord(c);
-//        obj.addSubRecord( sub1 );
-//        obj.addSubRecord( sub2 );
         obj.addSubRecord(e);
 
         return obj;
index eeb18b07182d3c9ad85e6f322c157edfb4713f36..02308bf48c6637b3b5668af92ced06304407119b 100644 (file)
@@ -134,7 +134,7 @@ public class PolygonShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType( OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING );
-        c.setObjectId(shapeId);
+        c.setObjectId( getCmoObjectId(shapeId) );
         c.setLocked( true );
         c.setPrintable( true );
         c.setAutofill( true );
index 8c14b3d39b9e5f1403d04b81ec0f96e87d7fa02c..739e1ce329258c691301259ab7e8f71424872718 100644 (file)
@@ -101,7 +101,7 @@ public class SimpleFilledShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
-        c.setObjectId( shapeId );
+        c.setObjectId(  getCmoObjectId(shapeId) );
         c.setLocked( true );
         c.setPrintable( true );
         c.setAutofill( true );
index 4985ea31d7c0d2bd9db62f35b52d90942725dea6..1ea79d0942f40f2acf35f3c7075a358f79793612 100644 (file)
@@ -59,7 +59,7 @@ public class TextboxShape
         ObjRecord obj = new ObjRecord();
         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
         c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
-        c.setObjectId( shapeId );
+        c.setObjectId( getCmoObjectId(shapeId) );
         c.setLocked( true );
         c.setPrintable( true );
         c.setAutofill( true );
@@ -166,4 +166,5 @@ public class TextboxShape
     {
         return escherTextbox;
     }
+
 }
diff --git a/src/testcases/org/apache/poi/hssf/model/TestShapes.java b/src/testcases/org/apache/poi/hssf/model/TestShapes.java
new file mode 100644 (file)
index 0000000..d17178e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.hssf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFComment;
+import org.apache.poi.hssf.usermodel.HSSFPicture;
+import org.apache.poi.hssf.usermodel.HSSFTextbox;
+
+/**
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestShapes extends TestCase {
+
+    /**
+     * Test generator of ids for the CommonObjectDataSubRecord record.
+     *
+     * See Bug 51332
+     */
+    public void testShapeId(){
+
+        HSSFClientAnchor anchor = new HSSFClientAnchor();
+        AbstractShape shape;
+        CommonObjectDataSubRecord cmo;
+
+        shape = new TextboxShape(new HSSFTextbox(null, anchor), 1025);
+        cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+        assertEquals(1, cmo.getObjectId());
+
+        shape = new PictureShape(new HSSFPicture(null, anchor), 1026);
+        cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+        assertEquals(2, cmo.getObjectId());
+
+        shape = new CommentShape(new HSSFComment(null, anchor), 1027);
+        cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0);
+        assertEquals(1027, cmo.getObjectId());
+    }
+}