<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>
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;
+ }
}
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);
{
return _note;
}
+
+ @Override
+ int getCmoObjectId(int shapeId){
+ return shapeId;
+ }
+
}
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);
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;
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 );
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 );
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 );
{
return escherTextbox;
}
+
}
--- /dev/null
+/*
+ * ====================================================================
+ * 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());
+ }
+}