]> source.dussan.org Git - poi.git/commitdiff
Bug 50458: Fixed missing shapeId in XSSF drawings
authorYegor Kozlov <yegor@apache.org>
Mon, 13 Jun 2011 11:56:21 +0000 (11:56 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 13 Jun 2011 11:56:21 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1135103 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java

index 087d6eb22ebb06d4ac72f70224df16034516142e..afff84bf6022c6a98ee702cd0c2d4754643ea3c9 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <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">51356 - Support autoSizeColumn in SXSSF</action>
            <action dev="poi-developers" type="add">51335 - Parse picture goal and crop sizes in HWPF</action>
index 5c449473e8097db556c1a3a42c66597ac3172c7b..446e0ecea760f9b3203c8c5c08edae1a0951853d 100644 (file)
@@ -37,6 +37,7 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.xmlbeans.XmlException;
 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.CTDrawing;
 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.
      */
     public XSSFTextBox createTextbox(XSSFClientAnchor anchor){
+        long shapeId = newShapeId();
         CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
         CTShape ctShape = ctAnchor.addNewSp();
         ctShape.set(XSSFSimpleShape.prototype());
+        ctShape.getNvSpPr().getCNvPr().setId(shapeId);
         XSSFTextBox shape = new XSSFTextBox(this, ctShape);
         shape.anchor = anchor;
         return shape;
@@ -163,10 +166,13 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
     {
         PackageRelationship rel = addPictureReference(pictureIndex);
 
+        long shapeId = newShapeId();
         CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
         CTPicture ctShape = ctAnchor.addNewPic();
         ctShape.set(XSSFPicture.prototype());
 
+        ctShape.getNvPicPr().getCNvPr().setId(shapeId);
+
         XSSFPicture shape = new XSSFPicture(this, ctShape);
         shape.anchor = anchor;
         shape.setPictureReference(rel);
@@ -227,9 +233,11 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
      */
     public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor)
     {
+        long shapeId = newShapeId();
         CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
         CTShape ctShape = ctAnchor.addNewSp();
         ctShape.set(XSSFSimpleShape.prototype());
+        ctShape.getNvSpPr().getCNvPr().setId(shapeId);
         XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
         shape.anchor = anchor;
         return shape;
@@ -354,4 +362,8 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
         ctAnchor.setEditAs(aditAs);
         return ctAnchor;
     }
+
+    private long newShapeId(){
+        return drawing.sizeOfTwoCellAnchorArray() + 1;
+    }
 }
index aea0bca8ed0182f2ac6b56d9786486a6628d2557..2d0575d80f9eeb2595152c3c51dcfebdf3c47e69 100644 (file)
@@ -69,4 +69,27 @@ public final class TestXSSFPicture extends BaseTestPicture {
         // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
         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());
+    }
 }