poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1135103 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
Date Mon, 13 Jun 2011 11:56:21 GMT
Author: yegor
Date: Mon Jun 13 11:56:21 2011
New Revision: 1135103

URL: http://svn.apache.org/viewvc?rev=1135103&view=rev
Log:
Bug 50458: Fixed missing shapeId in XSSF drawings 

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

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1135103&r1=1135102&r2=1135103&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Jun 13 11:56:21 2011
@@ -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>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=1135103&r1=1135102&r2=1135103&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Mon Jun 13 11:56:21
2011
@@ -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 P
      * @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 P
     {
         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 P
      */
     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 P
         ctAnchor.setEditAs(aditAs);
         return ctAnchor;
     }
+
+    private long newShapeId(){
+        return drawing.sizeOfTwoCellAnchorArray() + 1;
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java?rev=1135103&r1=1135102&r2=1135103&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java Mon Jun
13 11:56:21 2011
@@ -69,4 +69,27 @@ public final class TestXSSFPicture exten
         // 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());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message