Bug 51332 - Fixed internal IDs of shapes generated by HSSFPatriarch when there are more than 1023 drawing objects
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1138465 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b97e745739
commit
3e5e4ee2a3
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta4" date="2011-??-??">
|
<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="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">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>
|
<action dev="poi-developers" type="add">51389 - Support for sprmPJc paragraph SPRM in HWPF</action>
|
||||||
|
@ -150,4 +150,28 @@ public abstract class AbstractShape
|
|||||||
return options; // # options added
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class ComboboxShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType(HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX);
|
c.setObjectType(HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX);
|
||||||
c.setObjectId(shapeId);
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setLocked(true);
|
c.setLocked(true);
|
||||||
c.setPrintable(false);
|
c.setPrintable(false);
|
||||||
c.setAutofill(true);
|
c.setAutofill(true);
|
||||||
|
@ -136,4 +136,10 @@ public final class CommentShape extends TextboxShape {
|
|||||||
{
|
{
|
||||||
return _note;
|
return _note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getCmoObjectId(int shapeId){
|
||||||
|
return shapeId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class LineShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
|
c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
|
||||||
c.setObjectId(shapeId);
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setLocked(true);
|
c.setLocked(true);
|
||||||
c.setPrintable(true);
|
c.setPrintable(true);
|
||||||
c.setAutofill(true);
|
c.setAutofill(true);
|
||||||
|
@ -99,21 +99,15 @@ public class PictureShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
|
c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
|
||||||
// c.setObjectId((short) ( 1 ));
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setObjectId(shapeId);
|
|
||||||
c.setLocked(true);
|
c.setLocked(true);
|
||||||
c.setPrintable(true);
|
c.setPrintable(true);
|
||||||
c.setAutofill(true);
|
c.setAutofill(true);
|
||||||
c.setAutoline(true);
|
c.setAutoline(true);
|
||||||
// c.setReserved2( 0x012C0A84 );
|
|
||||||
c.setReserved2( 0x0 );
|
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();
|
EndSubRecord e = new EndSubRecord();
|
||||||
|
|
||||||
obj.addSubRecord(c);
|
obj.addSubRecord(c);
|
||||||
// obj.addSubRecord( sub1 );
|
|
||||||
// obj.addSubRecord( sub2 );
|
|
||||||
obj.addSubRecord(e);
|
obj.addSubRecord(e);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -134,7 +134,7 @@ public class PolygonShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType( OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING );
|
c.setObjectType( OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING );
|
||||||
c.setObjectId(shapeId);
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setLocked( true );
|
c.setLocked( true );
|
||||||
c.setPrintable( true );
|
c.setPrintable( true );
|
||||||
c.setAutofill( true );
|
c.setAutofill( true );
|
||||||
|
@ -101,7 +101,7 @@ public class SimpleFilledShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
|
c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
|
||||||
c.setObjectId( shapeId );
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setLocked( true );
|
c.setLocked( true );
|
||||||
c.setPrintable( true );
|
c.setPrintable( true );
|
||||||
c.setAutofill( true );
|
c.setAutofill( true );
|
||||||
|
@ -59,7 +59,7 @@ public class TextboxShape
|
|||||||
ObjRecord obj = new ObjRecord();
|
ObjRecord obj = new ObjRecord();
|
||||||
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
|
||||||
c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
|
c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() );
|
||||||
c.setObjectId( shapeId );
|
c.setObjectId( getCmoObjectId(shapeId) );
|
||||||
c.setLocked( true );
|
c.setLocked( true );
|
||||||
c.setPrintable( true );
|
c.setPrintable( true );
|
||||||
c.setAutofill( true );
|
c.setAutofill( true );
|
||||||
@ -166,4 +166,5 @@ public class TextboxShape
|
|||||||
{
|
{
|
||||||
return escherTextbox;
|
return escherTextbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
58
src/testcases/org/apache/poi/hssf/model/TestShapes.java
Normal file
58
src/testcases/org/apache/poi/hssf/model/TestShapes.java
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user