You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/01/03 20:30:36 UTC

svn commit: r1649233 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java

Author: centic
Date: Sat Jan  3 19:30:36 2015
New Revision: 1649233

URL: http://svn.apache.org/r1649233
Log:
Fix copy/paste errors in XSSFSimpleShape, allow unset of insets multiple times and add unit tests

Added:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java?rev=1649233&r1=1649232&r2=1649233&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java Sat Jan  3 19:30:36 2015
@@ -321,7 +321,7 @@ public class XSSFSimpleShape extends XSS
         while (value > 0) {
             modulo = (value - 1) % 26;
             alpha = (char)(65 + modulo) + alpha;
-            value = (int)((value - modulo) / 26);
+            value = (value - modulo) / 26;
         }
         return alpha;
     }
@@ -481,7 +481,7 @@ public class XSSFSimpleShape extends XSS
     public void setTextHorizontalOverflow(TextHorizontalOverflow overflow){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-             if(anchor == null) {
+             if(overflow == null) {
                 if(bodyPr.isSetHorzOverflow()) bodyPr.unsetHorzOverflow();
             } else {
                 bodyPr.setHorzOverflow(STTextHorzOverflowType.Enum.forInt(overflow.ordinal() + 1));
@@ -498,7 +498,7 @@ public class XSSFSimpleShape extends XSS
     	CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
     	if(bodyPr != null) {
     		if(bodyPr.isSetHorzOverflow()){
-    			return TextHorizontalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1];
+    			return TextHorizontalOverflow.values()[bodyPr.getHorzOverflow().intValue() - 1];
     		}    			
     	}
     	return TextHorizontalOverflow.OVERFLOW;
@@ -513,7 +513,7 @@ public class XSSFSimpleShape extends XSS
     public void setTextVerticalOverflow(TextVerticalOverflow overflow){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-             if(anchor == null) {
+             if(overflow == null) {
                 if(bodyPr.isSetVertOverflow()) bodyPr.unsetVertOverflow();
             } else {
                 bodyPr.setVertOverflow(STTextVertOverflowType.Enum.forInt(overflow.ordinal() + 1));
@@ -681,8 +681,9 @@ public class XSSFSimpleShape extends XSS
     public void setBottomInset(double margin){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-            if(margin == -1) bodyPr.unsetBIns();
-            else bodyPr.setBIns(Units.toEMU(margin));
+            if(margin == -1) {
+                if(bodyPr.isSetBIns()) bodyPr.unsetBIns();
+            } else bodyPr.setBIns(Units.toEMU(margin));
         }
     }
 
@@ -695,8 +696,9 @@ public class XSSFSimpleShape extends XSS
     public void setLeftInset(double margin){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-            if(margin == -1) bodyPr.unsetLIns();
-            else bodyPr.setLIns(Units.toEMU(margin));
+            if(margin == -1) {
+                if(bodyPr.isSetLIns()) bodyPr.unsetLIns();
+            } else bodyPr.setLIns(Units.toEMU(margin));
         }
     }
 
@@ -709,8 +711,9 @@ public class XSSFSimpleShape extends XSS
     public void setRightInset(double margin){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-            if(margin == -1) bodyPr.unsetRIns();
-            else bodyPr.setRIns(Units.toEMU(margin));
+            if(margin == -1) {
+                if(bodyPr.isSetRIns()) bodyPr.unsetRIns();
+            } else bodyPr.setRIns(Units.toEMU(margin));
         }
     }
 
@@ -723,8 +726,9 @@ public class XSSFSimpleShape extends XSS
     public void setTopInset(double margin){
         CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
         if (bodyPr != null) {
-            if(margin == -1) bodyPr.unsetTIns();
-            else bodyPr.setTIns(Units.toEMU(margin));
+            if(margin == -1) {
+                if(bodyPr.isSetTIns()) bodyPr.unsetTIns();
+            } else bodyPr.setTIns(Units.toEMU(margin));
         }
     }
 

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java?rev=1649233&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java Sat Jan  3 19:30:36 2015
@@ -0,0 +1,172 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+import java.io.IOException;
+
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.junit.Test;
+
+public class TestXSSFSimpleShape {
+    @Test
+    public void testXSSFTextParagraph() throws IOException {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        try {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFDrawing drawing = sheet.createDrawingPatriarch();
+    
+            XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
+            
+            XSSFRichTextString rt = new XSSFRichTextString("Test String");
+            
+            XSSFFont font = wb.createFont();
+            Color color = new Color(0, 255, 255);
+            font.setColor(new XSSFColor(color));
+            font.setFontName("Arial");
+            rt.applyFont(font);
+    
+            shape.setText(rt);
+
+            assertNotNull(shape.getCTShape());
+            assertNotNull(shape.iterator());
+            assertNotNull(XSSFSimpleShape.prototype());
+            
+            for(ListAutoNumber nr : ListAutoNumber.values()) {
+                shape.getTextParagraphs().get(0).setBullet(nr);
+                assertNotNull(shape.getText());
+            }
+            
+            shape.getTextParagraphs().get(0).setBullet(false);
+            assertNotNull(shape.getText());
+
+            shape.setText("testtext");
+            assertEquals("testtext", shape.getText());
+            
+            shape.setText(new XSSFRichTextString());
+            assertEquals("null", shape.getText());
+            
+            shape.addNewTextParagraph();
+            shape.addNewTextParagraph("test-other-text");
+            shape.addNewTextParagraph(new XSSFRichTextString("rtstring"));
+            shape.addNewTextParagraph(new XSSFRichTextString());
+            assertEquals("null\n\ntest-other-text\nrtstring\nnull", shape.getText());
+            
+            assertEquals(TextHorizontalOverflow.OVERFLOW, shape.getTextHorizontalOverflow());
+            shape.setTextHorizontalOverflow(TextHorizontalOverflow.CLIP);
+            assertEquals(TextHorizontalOverflow.CLIP, shape.getTextHorizontalOverflow());
+            shape.setTextHorizontalOverflow(TextHorizontalOverflow.OVERFLOW);
+            assertEquals(TextHorizontalOverflow.OVERFLOW, shape.getTextHorizontalOverflow());
+            shape.setTextHorizontalOverflow(null);
+            assertEquals(TextHorizontalOverflow.OVERFLOW, shape.getTextHorizontalOverflow());
+            shape.setTextHorizontalOverflow(null);
+            assertEquals(TextHorizontalOverflow.OVERFLOW, shape.getTextHorizontalOverflow());
+            
+            assertEquals(TextVerticalOverflow.OVERFLOW, shape.getTextVerticalOverflow());
+            shape.setTextVerticalOverflow(TextVerticalOverflow.CLIP);
+            assertEquals(TextVerticalOverflow.CLIP, shape.getTextVerticalOverflow());
+            shape.setTextVerticalOverflow(TextVerticalOverflow.OVERFLOW);
+            assertEquals(TextVerticalOverflow.OVERFLOW, shape.getTextVerticalOverflow());
+            shape.setTextVerticalOverflow(null);
+            assertEquals(TextVerticalOverflow.OVERFLOW, shape.getTextVerticalOverflow());
+            shape.setTextVerticalOverflow(null);
+            assertEquals(TextVerticalOverflow.OVERFLOW, shape.getTextVerticalOverflow());
+
+            assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+            shape.setVerticalAlignment(VerticalAlignment.BOTTOM);
+            assertEquals(VerticalAlignment.BOTTOM, shape.getVerticalAlignment());
+            shape.setVerticalAlignment(VerticalAlignment.TOP);
+            assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+            shape.setVerticalAlignment(null);
+            assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+            shape.setVerticalAlignment(null);
+            assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+
+            assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+            shape.setTextDirection(TextDirection.STACKED);
+            assertEquals(TextDirection.STACKED, shape.getTextDirection());
+            shape.setTextDirection(TextDirection.HORIZONTAL);
+            assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+            shape.setTextDirection(null);
+            assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+            shape.setTextDirection(null);
+            assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+
+            assertEquals(3.6, shape.getBottomInset(), 0.01);
+            shape.setBottomInset(12.32);
+            assertEquals(12.32, shape.getBottomInset(), 0.01);
+            shape.setBottomInset(-1);
+            assertEquals(3.6, shape.getBottomInset(), 0.01);
+            shape.setBottomInset(-1);
+            assertEquals(3.6, shape.getBottomInset(), 0.01);
+            
+            assertEquals(3.6, shape.getLeftInset(), 0.01);
+            shape.setLeftInset(12.31);
+            assertEquals(12.31, shape.getLeftInset(), 0.01);
+            shape.setLeftInset(-1);
+            assertEquals(3.6, shape.getLeftInset(), 0.01);
+            shape.setLeftInset(-1);
+            assertEquals(3.6, shape.getLeftInset(), 0.01);
+
+            assertEquals(3.6, shape.getRightInset(), 0.01);
+            shape.setRightInset(13.31);
+            assertEquals(13.31, shape.getRightInset(), 0.01);
+            shape.setRightInset(-1);
+            assertEquals(3.6, shape.getRightInset(), 0.01);
+            shape.setRightInset(-1);
+            assertEquals(3.6, shape.getRightInset(), 0.01);
+
+            assertEquals(3.6, shape.getTopInset(), 0.01);
+            shape.setTopInset(23.31);
+            assertEquals(23.31, shape.getTopInset(), 0.01);
+            shape.setTopInset(-1);
+            assertEquals(3.6, shape.getTopInset(), 0.01);
+            shape.setTopInset(-1);
+            assertEquals(3.6, shape.getTopInset(), 0.01);
+            
+            assertTrue(shape.getWordWrap());
+            shape.setWordWrap(false);
+            assertFalse(shape.getWordWrap());
+            shape.setWordWrap(true);
+            assertTrue(shape.getWordWrap());
+
+            assertEquals(TextAutofit.NORMAL, shape.getTextAutofit());
+            shape.setTextAutofit(TextAutofit.NORMAL);
+            assertEquals(TextAutofit.NORMAL, shape.getTextAutofit());
+            shape.setTextAutofit(TextAutofit.SHAPE);
+            assertEquals(TextAutofit.SHAPE, shape.getTextAutofit());
+            shape.setTextAutofit(TextAutofit.NONE);
+            assertEquals(TextAutofit.NONE, shape.getTextAutofit());
+            
+            assertEquals(5, shape.getShapeType());
+            shape.setShapeType(23);
+            assertEquals(23, shape.getShapeType());
+
+            // TODO: should this be supported?
+//            shape.setShapeType(-1);
+//            assertEquals(-1, shape.getShapeType());
+//            shape.setShapeType(-1);
+//            assertEquals(-1, shape.getShapeType());
+            
+            assertNotNull(shape.getShapeProperties());
+        } finally {
+            wb.close();
+        }
+    }
+}



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