]> source.dussan.org Git - poi.git/commitdiff
Fix copy/paste errors in XSSFSimpleShape, allow unset of insets multiple times and...
authorDominik Stadler <centic@apache.org>
Sat, 3 Jan 2015 19:30:36 +0000 (19:30 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 3 Jan 2015 19:30:36 +0000 (19:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649233 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java [new file with mode: 0644]

index 7ce8c4e0df918573965976f1cf28ab63be0f8534..03754e8218d891acc917fb0351e3e2abd7d2aa6d 100644 (file)
@@ -321,7 +321,7 @@ public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParag
         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 XSSFShape implements Iterable<XSSFTextParag
     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 XSSFShape implements Iterable<XSSFTextParag
        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 XSSFShape implements Iterable<XSSFTextParag
     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 XSSFShape implements Iterable<XSSFTextParag
     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 XSSFShape implements Iterable<XSSFTextParag
     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 XSSFShape implements Iterable<XSSFTextParag
     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 XSSFShape implements Iterable<XSSFTextParag
     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));
         }
     }
 
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSimpleShape.java
new file mode 100644 (file)
index 0000000..e9eebe6
--- /dev/null
@@ -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();
+        }
+    }
+}