Bug 50458: Fixed missing shapeId in XSSF drawings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1135103 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b2603f7f6
commit
48a5868947
@ -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="add">50458 - Fixed missing shapeId in XSSF drawings </action>
|
||||||
<action dev="poi-developers" type="add">51339 - Fixed arithmetic rounding in formula evaluation </action>
|
<action dev="poi-developers" type="add">51339 - Fixed arithmetic rounding in formula evaluation </action>
|
||||||
<action dev="poi-developers" type="add">51356 - Support autoSizeColumn in SXSSF</action>
|
<action dev="poi-developers" type="add">51356 - Support autoSizeColumn in SXSSF</action>
|
||||||
<action dev="poi-developers" type="add">51335 - Parse picture goal and crop sizes in HWPF</action>
|
<action dev="poi-developers" type="add">51335 - Parse picture goal and crop sizes in HWPF</action>
|
||||||
|
@ -37,6 +37,7 @@ import org.apache.poi.util.Internal;
|
|||||||
import org.apache.poi.xssf.model.CommentsTable;
|
import org.apache.poi.xssf.model.CommentsTable;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape;
|
||||||
@ -141,9 +142,11 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
* @return the newly created textbox.
|
* @return the newly created textbox.
|
||||||
*/
|
*/
|
||||||
public XSSFTextBox createTextbox(XSSFClientAnchor anchor){
|
public XSSFTextBox createTextbox(XSSFClientAnchor anchor){
|
||||||
|
long shapeId = newShapeId();
|
||||||
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
||||||
CTShape ctShape = ctAnchor.addNewSp();
|
CTShape ctShape = ctAnchor.addNewSp();
|
||||||
ctShape.set(XSSFSimpleShape.prototype());
|
ctShape.set(XSSFSimpleShape.prototype());
|
||||||
|
ctShape.getNvSpPr().getCNvPr().setId(shapeId);
|
||||||
XSSFTextBox shape = new XSSFTextBox(this, ctShape);
|
XSSFTextBox shape = new XSSFTextBox(this, ctShape);
|
||||||
shape.anchor = anchor;
|
shape.anchor = anchor;
|
||||||
return shape;
|
return shape;
|
||||||
@ -163,10 +166,13 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
{
|
{
|
||||||
PackageRelationship rel = addPictureReference(pictureIndex);
|
PackageRelationship rel = addPictureReference(pictureIndex);
|
||||||
|
|
||||||
|
long shapeId = newShapeId();
|
||||||
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
||||||
CTPicture ctShape = ctAnchor.addNewPic();
|
CTPicture ctShape = ctAnchor.addNewPic();
|
||||||
ctShape.set(XSSFPicture.prototype());
|
ctShape.set(XSSFPicture.prototype());
|
||||||
|
|
||||||
|
ctShape.getNvPicPr().getCNvPr().setId(shapeId);
|
||||||
|
|
||||||
XSSFPicture shape = new XSSFPicture(this, ctShape);
|
XSSFPicture shape = new XSSFPicture(this, ctShape);
|
||||||
shape.anchor = anchor;
|
shape.anchor = anchor;
|
||||||
shape.setPictureReference(rel);
|
shape.setPictureReference(rel);
|
||||||
@ -227,9 +233,11 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
*/
|
*/
|
||||||
public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor)
|
public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor)
|
||||||
{
|
{
|
||||||
|
long shapeId = newShapeId();
|
||||||
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
||||||
CTShape ctShape = ctAnchor.addNewSp();
|
CTShape ctShape = ctAnchor.addNewSp();
|
||||||
ctShape.set(XSSFSimpleShape.prototype());
|
ctShape.set(XSSFSimpleShape.prototype());
|
||||||
|
ctShape.getNvSpPr().getCNvPr().setId(shapeId);
|
||||||
XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
|
XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
|
||||||
shape.anchor = anchor;
|
shape.anchor = anchor;
|
||||||
return shape;
|
return shape;
|
||||||
@ -354,4 +362,8 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
ctAnchor.setEditAs(aditAs);
|
ctAnchor.setEditAs(aditAs);
|
||||||
return ctAnchor;
|
return ctAnchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long newShapeId(){
|
||||||
|
return drawing.sizeOfTwoCellAnchorArray() + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,4 +69,27 @@ public final class TestXSSFPicture extends BaseTestPicture {
|
|||||||
// STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
|
// STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
|
||||||
assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
|
assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that ShapeId in CTNonVisualDrawingProps is incremented
|
||||||
|
*
|
||||||
|
* See Bugzilla 50458
|
||||||
|
*/
|
||||||
|
public void testShapeId(){
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
|
||||||
|
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
byte[] jpegData = "picture1".getBytes();
|
||||||
|
int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||||
|
|
||||||
|
XSSFPicture shape1 = drawing.createPicture(anchor, jpegIdx);
|
||||||
|
assertEquals(1, shape1.getCTPicture().getNvPicPr().getCNvPr().getId());
|
||||||
|
|
||||||
|
jpegData = "picture2".getBytes();
|
||||||
|
jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||||
|
XSSFPicture shape2 = drawing.createPicture(anchor, jpegIdx);
|
||||||
|
assertEquals(2, shape2.getCTPicture().getNvPicPr().getCNvPr().getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user