poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1831947 - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/sl/usermodel/ trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xslf/ trunk/src/ooxml/testcases/org/apache/po...
Date Sun, 20 May 2018 22:00:15 GMT
Author: kiwiwings
Date: Sun May 20 22:00:14 2018
New Revision: 1831947

URL: http://svn.apache.org/viewvc?rev=1831947&view=rev
Log:
#62051 - Two shapes have the same shapeId within the same slide.

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sun May 20 22:00:14 2018
@@ -68,6 +68,7 @@
         <summary-item>Provide new ooxml-schemas-1.4.jar</summary-item>
       </summary>
       <actions>
+        <action dev="PD" type="fix" fixes-bug="62051" module="XSLF">Two shapes have
the same shapeId within the same slide</action>
         <action dev="PD" type="fix" fixes-bug="61633" module="XSLF">Zero width shapes
aren't rendered</action>
         <action dev="PD" type="add" fixes-bug="62037" module="SL Common">SlideNames
should not be null but have a default as if accessed by VBA</action>
         <action dev="PD" type="fix" fixes-bug="62381" module="SL Common">Fix rendering
of AutoShapes</action>

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/Shape.java Sun May 20 22:00:14 2018
@@ -54,4 +54,18 @@ public interface Shape<
     *   if null, the bounds of the shape are used.
     */
    void draw(Graphics2D graphics, Rectangle2D bounds);
+
+
+   /**
+    * Returns a unique identifier for this shape within the current slide.
+    * This ID may be used to assist in uniquely identifying this object so that it can
+    * be referred to by other parts of the document.
+    * <p>
+    * If multiple objects within the same slide share the same id attribute value,
+    * then the document shall be considered non-conformant.
+    * </p>
+    *
+    * @return unique id of this shape
+    */
+   int getShapeId();
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java Sun May 20 22:00:14
2018
@@ -67,7 +67,7 @@ public class XSLFAutoShape extends XSLFT
         CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("AutoShape " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvSpPr.addNewCNvSpPr();
         nvSpPr.addNewNvPr();
         CTShapeProperties spPr = ct.addNewSpPr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java Sun May
20 22:00:14 2018
@@ -51,7 +51,7 @@ public class XSLFConnectorShape extends
         CTConnectorNonVisual nvSpPr = ct.addNewNvCxnSpPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("Connector " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvSpPr.addNewCNvCxnSpPr();
         nvSpPr.addNewNvPr();
         CTShapeProperties spPr = ct.addNewSpPr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java Sun May 20 22:00:14
2018
@@ -18,26 +18,13 @@ package org.apache.poi.xslf.usermodel;
 
 import java.awt.Color;
 import java.awt.geom.Rectangle2D;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.poi.POIXMLDocumentPart.RelationPart;
-import org.apache.poi.hpsf.ClassID;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
 import org.apache.poi.util.Beta;
 import org.apache.xmlbeans.XmlObject;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTOleObject;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
 
@@ -45,7 +32,6 @@ import org.openxmlformats.schemas.presen
 @Beta
 public class XSLFDrawing {
     private XSLFSheet _sheet;
-    private int _shapeId = 1;
     private CTGroupShape _spTree;
 
     /*package*/ XSLFDrawing(XSLFSheet sheet, CTGroupShape spTree){
@@ -58,14 +44,14 @@ public class XSLFDrawing {
             // ignore them for now
             if (o instanceof CTNonVisualDrawingProps) {
                 CTNonVisualDrawingProps p = (CTNonVisualDrawingProps)o;
-                _shapeId = (int)Math.max(_shapeId, p.getId());
+                sheet.registerShapeId((int)p.getId());
             }
         }
     }
 
     public XSLFAutoShape createAutoShape(){
         CTShape sp = _spTree.addNewSp();
-        sp.set(XSLFAutoShape.prototype(_shapeId++));
+        sp.set(XSLFAutoShape.prototype(_sheet.allocateShapeId()));
         XSLFAutoShape shape = new XSLFAutoShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
@@ -73,7 +59,7 @@ public class XSLFDrawing {
 
     public XSLFFreeformShape createFreeform(){
         CTShape sp = _spTree.addNewSp();
-        sp.set(XSLFFreeformShape.prototype(_shapeId++));
+        sp.set(XSLFFreeformShape.prototype(_sheet.allocateShapeId()));
         XSLFFreeformShape shape = new XSLFFreeformShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
@@ -81,7 +67,7 @@ public class XSLFDrawing {
 
     public XSLFTextBox createTextBox(){
         CTShape sp = _spTree.addNewSp();
-        sp.set(XSLFTextBox.prototype(_shapeId++));
+        sp.set(XSLFTextBox.prototype(_sheet.allocateShapeId()));
         XSLFTextBox shape = new XSLFTextBox(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
@@ -89,7 +75,7 @@ public class XSLFDrawing {
 
     public XSLFConnectorShape createConnector(){
         CTConnector sp = _spTree.addNewCxnSp();
-        sp.set(XSLFConnectorShape.prototype(_shapeId++));
+        sp.set(XSLFConnectorShape.prototype(_sheet.allocateShapeId()));
         XSLFConnectorShape shape = new XSLFConnectorShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         shape.setLineColor(Color.black);
@@ -98,33 +84,33 @@ public class XSLFDrawing {
     }
 
     public XSLFGroupShape createGroup(){
-        CTGroupShape obj = _spTree.addNewGrpSp();
-        obj.set(XSLFGroupShape.prototype(_shapeId++));
-        XSLFGroupShape shape = new XSLFGroupShape(obj, _sheet);
+        CTGroupShape sp = _spTree.addNewGrpSp();
+        sp.set(XSLFGroupShape.prototype(_sheet.allocateShapeId()));
+        XSLFGroupShape shape = new XSLFGroupShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
     }
 
     public XSLFPictureShape createPicture(String rel){
-        CTPicture obj = _spTree.addNewPic();
-        obj.set(XSLFPictureShape.prototype(_shapeId++, rel));
-        XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
+        CTPicture sp = _spTree.addNewPic();
+        sp.set(XSLFPictureShape.prototype(_sheet.allocateShapeId(), rel));
+        XSLFPictureShape shape = new XSLFPictureShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
     }
 
     public XSLFTable createTable(){
-        CTGraphicalObjectFrame obj = _spTree.addNewGraphicFrame();
-        obj.set(XSLFTable.prototype(_shapeId++));
-        XSLFTable shape = new XSLFTable(obj, _sheet);
+        CTGraphicalObjectFrame sp = _spTree.addNewGraphicFrame();
+        sp.set(XSLFTable.prototype(_sheet.allocateShapeId()));
+        XSLFTable shape = new XSLFTable(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
     }
 
     public XSLFObjectShape createOleShape(String pictureRel) {
-        CTGraphicalObjectFrame obj = _spTree.addNewGraphicFrame();
-        obj.set(XSLFObjectShape.prototype(_shapeId++, pictureRel));
-        XSLFObjectShape shape = new XSLFObjectShape(obj, _sheet);
+        CTGraphicalObjectFrame sp = _spTree.addNewGraphicFrame();
+        sp.set(XSLFObjectShape.prototype(_sheet.allocateShapeId(), pictureRel));
+        XSLFObjectShape shape = new XSLFObjectShape(sp, _sheet);
         shape.setAnchor(new Rectangle2D.Double());
         return shape;
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java Sun May
20 22:00:14 2018
@@ -232,7 +232,7 @@ public class XSLFFreeformShape extends X
         CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("Freeform " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvSpPr.addNewCNvSpPr();
         nvSpPr.addNewNvPr();
         CTShapeProperties spPr = ct.addNewSpPr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java Sun May 20
22:00:14 2018
@@ -174,9 +174,12 @@ implements XSLFShapeContainer, GroupShap
     public boolean removeShape(XSLFShape xShape) {
         XmlObject obj = xShape.getXmlObject();
         CTGroupShape grpSp = (CTGroupShape)getXmlObject();
+        getSheet().deregisterShapeId(xShape.getShapeId());
         if(obj instanceof CTShape){
             grpSp.getSpList().remove(obj);
         } else if (obj instanceof CTGroupShape){
+            XSLFGroupShape gs = (XSLFGroupShape)xShape;
+            new ArrayList<>(gs.getShapes()).forEach(gs::removeShape);
             grpSp.getGrpSpList().remove(obj);
         } else if (obj instanceof CTConnector){
             grpSp.getCxnSpList().remove(obj);
@@ -203,7 +206,7 @@ implements XSLFShapeContainer, GroupShap
         CTGroupShapeNonVisual nvSpPr = ct.addNewNvGrpSpPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("Group " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
 
         nvSpPr.addNewCNvGrpSpPr();
         nvSpPr.addNewNvPr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java Sun May 20
22:00:14 2018
@@ -268,8 +268,8 @@ public class XSLFObjectShape extends XSL
         CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr();
         // usually the shape name has its index based on the n-th embeding, but having
         // the prototype separate from the actual updating of the object, we use the shape
id
-        cnv.setName("Object " + (shapeId + 1));
-        cnv.setId(shapeId + 1);
+        cnv.setName("Object " + shapeId);
+        cnv.setId(shapeId);
 
         // add empty property elements otherwise Powerpoint doesn't load the file ...
         nvGr.addNewCNvGraphicFramePr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java Sun May 20
22:00:14 2018
@@ -68,7 +68,7 @@ public class XSLFPictureShape extends XS
         CTPictureNonVisual nvSpPr = ct.addNewNvPicPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("Picture " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvSpPr.addNewCNvPicPr().addNewPicLocks().setNoChangeAspect(true);
         nvSpPr.addNewNvPr();
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java Sun May 20 22:00:14
2018
@@ -102,17 +102,7 @@ public abstract class XSLFShape implemen
         return getCNvPr().getName();
     }
 
-    /**
-     * Returns a unique identifier for this shape within the current document.
-     * This ID may be used to assist in uniquely identifying this object so that it can
-     * be referred to by other parts of the document.
-     * <p>
-     * If multiple objects within the same document share the same id attribute value,
-     * then the document shall be considered non-conformant.
-     * </p>
-     *
-     * @return unique id of this shape
-     */
+    @Override
     public int getShapeId() {
         return (int)getCNvPr().getId();
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Sun May 20 22:00:14
2018
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -79,6 +80,8 @@ implements XSLFShapeContainer, Sheet<XSL
     private Map<Integer, XSLFSimpleShape> _placeholderByIdMap;
     private Map<Integer, XSLFSimpleShape> _placeholderByTypeMap;
 
+    private final BitSet shapeIds = new BitSet();
+
     public XSLFSheet() {
         super();
     }
@@ -105,6 +108,26 @@ implements XSLFShapeContainer, Sheet<XSL
         throw new IllegalStateException("SlideShow was not found");
     }
 
+    protected int allocateShapeId() {
+        final int nextId = shapeIds.nextClearBit(1);
+        shapeIds.set(nextId);
+        return nextId;
+    }
+
+    protected void registerShapeId(final int shapeId) {
+        if (shapeIds.get(shapeId)) {
+            LOG.log(POILogger.WARN, "shape id "+shapeId+" has been already used.");
+        }
+        shapeIds.set(shapeId);
+    }
+
+    protected void deregisterShapeId(final int shapeId) {
+        if (!shapeIds.get(shapeId)) {
+            LOG.log(POILogger.WARN, "shape id "+shapeId+" hasn't been registered.");
+        }
+        shapeIds.clear(shapeId);
+    }
+
     protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFShapeContainer
parent){
         final XSLFSheet sheet = (parent instanceof XSLFSheet) ? (XSLFSheet)parent : ((XSLFShape)parent).getSheet();
 
@@ -328,9 +351,12 @@ implements XSLFShapeContainer, Sheet<XSL
     public boolean removeShape(XSLFShape xShape) {
         XmlObject obj = xShape.getXmlObject();
         CTGroupShape spTree = getSpTree();
+        deregisterShapeId(xShape.getShapeId());
         if(obj instanceof CTShape){
             spTree.getSpList().remove(obj);
         } else if (obj instanceof CTGroupShape) {
+            XSLFGroupShape gs = (XSLFGroupShape)xShape;
+            new ArrayList<>(gs.getShapes()).forEach(gs::removeShape);
             spTree.getGrpSpList().remove(obj);
         } else if (obj instanceof CTConnector) {
             spTree.getCxnSpList().remove(obj);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java Sun May 20 22:00:14
2018
@@ -166,7 +166,7 @@ public class XSLFTable extends XSLFGraph
 
         CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr();
         cnv.setName("Table " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true);
         nvGr.addNewNvPr();
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java Sun May 20 22:00:14
2018
@@ -46,7 +46,7 @@ public class XSLFTextBox extends XSLFAut
         CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
         CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
         cnv.setName("TextBox " + shapeId);
-        cnv.setId(shapeId + 1);
+        cnv.setId(shapeId);
         nvSpPr.addNewCNvSpPr().setTxBox(true);
         nvSpPr.addNewNvPr();
         CTShapeProperties spPr = ct.addNewSpPr();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Sun May 20 22:00:14
2018
@@ -36,8 +36,11 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.Optional;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import javax.imageio.ImageIO;
@@ -56,10 +59,10 @@ import org.apache.poi.sl.usermodel.Paint
 import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
 import org.apache.poi.sl.usermodel.PictureData;
 import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.apache.poi.sl.usermodel.Shape;
 import org.apache.poi.sl.usermodel.ShapeType;
 import org.apache.poi.sl.usermodel.VerticalAlignment;
 import org.apache.poi.util.IOUtils;
-import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
 import org.apache.poi.xslf.usermodel.XMLSlideShow;
 import org.apache.poi.xslf.usermodel.XSLFAutoShape;
 import org.apache.poi.xslf.usermodel.XSLFGroupShape;
@@ -693,13 +696,6 @@ public class TestXSLFBugs {
             assertNotNull(notesSlide);
         }
 
-        /*OutputStream stream = new FileOutputStream("/tmp/test.pptx");
-        try {
-            ppt.write(stream);
-        } finally {
-            stream.close();
-        }*/
-
         ppt.close();
     }
 
@@ -727,4 +723,32 @@ public class TestXSLFBugs {
         }
         ppt.close();
     }
+
+    @Test
+    public void bug62051() throws IOException {
+        final Function<List<XSLFShape>, int[]> ids = (shapes) ->
+            shapes.stream().mapToInt(Shape::getShapeId).toArray();
+
+        try (final XMLSlideShow ppt = new XMLSlideShow()) {
+            final XSLFSlide slide = ppt.createSlide();
+            final List<XSLFShape> shapes = new ArrayList<>();
+            shapes.add(slide.createAutoShape());
+            final XSLFGroupShape g1 = slide.createGroup();
+            shapes.add(g1);
+            final XSLFGroupShape g2 = g1.createGroup();
+            shapes.add(g2);
+            shapes.add(g2.createAutoShape());
+            shapes.add(slide.createAutoShape());
+            shapes.add(g2.createAutoShape());
+            shapes.add(g1.createAutoShape());
+            assertArrayEquals(new int[]{ 2,3,4,5,6,7,8 }, ids.apply(shapes));
+            g1.removeShape(g2);
+            shapes.remove(5);
+            shapes.remove(3);
+            shapes.remove(2);
+            shapes.add(g1.createAutoShape());
+            assertArrayEquals(new int[]{ 2,3,6,8,4 }, ids.apply(shapes));
+
+        }
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java Sun May
20 22:00:14 2018
@@ -94,7 +94,7 @@ public class TestXSLFTable {
         assertNotNull(tbl.getCTTable().getTblGrid());
         assertNotNull(tbl.getCTTable().getTblPr());
         assertTrue(tbl.getXmlObject() instanceof CTGraphicalObjectFrame);
-        assertEquals("Table 1", tbl.getShapeName());
+        assertEquals("Table 2", tbl.getShapeName());
         assertEquals(2, tbl.getShapeId());
         assertEquals(0, tbl.getRows().size());
         assertEquals(0, tbl.getCTTable().sizeOfTrArray());

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java?rev=1831947&r1=1831946&r2=1831947&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java Sun May 20 22:00:14
2018
@@ -538,9 +538,7 @@ public abstract class HSLFShape implemen
         return new Color(r, g, b);
     }
 
-    /**
-     * @return id for the shape.
-     */
+    @Override
     public int getShapeId(){
         EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
         return spRecord == null ? 0 : spRecord.getShapeId();



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


Mime
View raw message