poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1393992 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/
Date Thu, 04 Oct 2012 11:23:32 GMT
Author: yegor
Date: Thu Oct  4 11:23:32 2012
New Revision: 1393992

URL: http://svn.apache.org/viewvc?rev=1393992&view=rev
Log:
Bugzilla 53568 - Set shapes anchors in XSSF when reading from existing drawings

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.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=1393992&r1=1393991&r2=1393992&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Oct  4 11:23:32 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="fix">53568 - Set shapes anchors in XSSF
when reading from existing drawings</action>
           <action dev="poi-developers" type="add">HSSFOptimiser will now also tidy
away un-used cell styles, in addition to duplicate styles</action>
           <action dev="poi-developers" type="fix">53493 - Fixed memory and temporary
file leak in SXSSF </action>
           <action dev="poi-developers" type="fix">53780 - Fixed memory and temporary
file leak in SXSSF </action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java?rev=1393992&r1=1393991&r2=1393992&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java Thu Oct 
4 11:23:32 2012
@@ -161,8 +161,14 @@ public final class XSSFClientAnchor exte
         if (o == null || !(o instanceof XSSFClientAnchor)) return false;
 
         XSSFClientAnchor anchor = (XSSFClientAnchor) o;
-        return cell1.toString().equals(anchor.getFrom().toString()) &&
-               cell2.toString().equals(anchor.getTo().toString()) ;
+        return  getDx1() == anchor.getDx1() &&
+                getDx2() == anchor.getDx2() &&
+                getDy1() == anchor.getDy1() &&
+                getDy2() == anchor.getDy2() &&
+                getCol1() == anchor.getCol1() &&
+                getCol2() == anchor.getCol2() &&
+                getRow1() == anchor.getRow1() &&
+                getRow2() == anchor.getRow2() ;
 
     }
 

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=1393992&r1=1393991&r2=1393992&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 Thu Oct  4 11:23:32
2012
@@ -35,6 +35,7 @@ import org.apache.poi.ss.usermodel.Clien
 import org.apache.poi.ss.usermodel.Drawing;
 import org.apache.poi.util.Internal;
 import org.apache.poi.xssf.model.CommentsTable;
+import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
@@ -370,12 +371,39 @@ public final class XSSFDrawing extends P
     public List<XSSFShape>  getShapes(){
         List<XSSFShape> lst = new ArrayList<XSSFShape>();
         for(XmlObject obj : drawing.selectPath("./*/*")) {
-            if(obj instanceof CTPicture) lst.add(new XSSFPicture(this, (CTPicture)obj)) ;
-            else if(obj instanceof CTConnector) lst.add(new XSSFConnector(this, (CTConnector)obj))
;
-            else if(obj instanceof CTShape) lst.add(new XSSFSimpleShape(this, (CTShape)obj))
;
-            else if(obj instanceof CTGraphicalObjectFrame) lst.add(new XSSFGraphicFrame(this,
(CTGraphicalObjectFrame)obj)) ;
-            else if(obj instanceof CTGroupShape) lst.add(new XSSFShapeGroup(this, (CTGroupShape)obj))
;
+            XSSFShape shape = null;
+            if(obj instanceof CTPicture) shape = new XSSFPicture(this, (CTPicture)obj) ;
+            else if(obj instanceof CTConnector) shape = new XSSFConnector(this, (CTConnector)obj)
;
+            else if(obj instanceof CTShape) shape = new XSSFSimpleShape(this, (CTShape)obj)
;
+            else if(obj instanceof CTGraphicalObjectFrame) shape = new XSSFGraphicFrame(this,
(CTGraphicalObjectFrame)obj) ;
+            else if(obj instanceof CTGroupShape) shape = new XSSFShapeGroup(this, (CTGroupShape)obj)
;
+
+            if(shape != null){
+                shape.anchor = getAnchorFromParent(obj);
+                lst.add(shape);
+            }
         }
         return lst;
     }
+
+
+    private XSSFAnchor getAnchorFromParent(XmlObject obj){
+        XSSFAnchor anchor = null;
+
+        XmlObject parentXbean = null;
+        XmlCursor cursor = obj.newCursor();
+        if(cursor.toParent()) parentXbean = cursor.getObject();
+        cursor.dispose();
+        if(parentXbean != null){
+            if (parentXbean instanceof CTTwoCellAnchor) {
+                CTTwoCellAnchor ct = (CTTwoCellAnchor)parentXbean;
+                anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo());
+            } else if (parentXbean instanceof CTOneCellAnchor) {
+                CTOneCellAnchor ct = (CTOneCellAnchor)parentXbean;
+                anchor = new XSSFClientAnchor(ct.getFrom(), CTMarker.Factory.newInstance());
+            }
+        }
+        return anchor;
+    }
+
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=1393992&r1=1393991&r2=1393992&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Thu Oct
 4 11:23:32 2012
@@ -62,6 +62,8 @@ public class TestXSSFDrawing extends Tes
         assertTrue(shapes.get(4) instanceof XSSFSimpleShape);
         assertTrue(shapes.get(5) instanceof XSSFPicture);
 
+        for(XSSFShape sh : shapes) assertNotNull(sh.getAnchor());
+
     }
 
     public void testNew() throws Exception {
@@ -212,4 +214,33 @@ public class TestXSSFDrawing extends Tes
                 rPr.getSolidFill().getSrgbClr().getVal()));
 
     }
+
+    /**
+     *  test that anchor is not null when reading shapes from existing drawings
+     */
+    public void testReadAnchors(){
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+        XSSFClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4);
+        XSSFShape shape1 = drawing.createTextbox(anchor1);
+
+        XSSFClientAnchor anchor2 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 5);
+        XSSFShape shape2 = drawing.createTextbox(anchor2);
+
+        int pictureIndex= wb.addPicture(new byte[]{}, XSSFWorkbook.PICTURE_TYPE_PNG);
+        XSSFClientAnchor anchor3 = new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 6);
+        XSSFShape shape3 = drawing.createPicture(anchor3, pictureIndex);
+
+        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        sheet = wb.getSheetAt(0);
+        drawing = sheet.createDrawingPatriarch();
+        List<XSSFShape> shapes = drawing.getShapes();
+        assertEquals(shapes.get(0).getAnchor(), anchor1);
+        assertEquals(shapes.get(1).getAnchor(), anchor2);
+        assertEquals(shapes.get(2).getAnchor(), anchor3);
+
+
+    }
 }



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


Mime
View raw message