poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1649232 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java
Date Sat, 03 Jan 2015 19:29:51 GMT
Author: centic
Date: Sat Jan  3 19:29:51 2015
New Revision: 1649232

URL: http://svn.apache.org/r1649232
Log:
Fix copy/paste error in XSSFTextParagraph and add unit tests

Added:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java?rev=1649232&r1=1649231&r2=1649232&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java Sat Jan
 3 19:29:51 2015
@@ -172,7 +172,7 @@ public class XSSFTextParagraph implement
     public TextFontAlign getTextFontAlign(){
         ParagraphPropertyFetcher<TextFontAlign> fetcher = new ParagraphPropertyFetcher<TextFontAlign>(getLevel()){
             public boolean fetch(CTTextParagraphProperties props){
-                if(props.isSetAlgn()){
+                if(props.isSetFontAlgn()){
                     TextFontAlign val = TextFontAlign.values()[props.getFontAlgn().intValue()
- 1];
                     setValue(val);
                     return true;
@@ -322,12 +322,16 @@ public class XSSFTextParagraph implement
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
 
         if(bulletSize >= 0) {
+            // percentage
             CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();
             pt.setVal((int)(bulletSize*1000));
+            // unset points if percentage is now set
             if(pr.isSetBuSzPts()) pr.unsetBuSzPts();
         } else {
+            // points
             CTTextBulletSizePoint pt = pr.isSetBuSzPts() ? pr.getBuSzPts() : pr.addNewBuSzPts();
             pt.setVal((int)(-bulletSize*100));
+            // unset percentage if points is now set
             if(pr.isSetBuSzPct()) pr.unsetBuSzPct();
         }
     }
@@ -335,7 +339,7 @@ public class XSSFTextParagraph implement
     /**
      * Specifies the indent size that will be applied to the first line of text in the paragraph.
      *
-     * @param value the indent in points. 
+     * @param value the indent in points, -1 to unset indent and use the default of 0. 
      */
     public void setIndent(double value){
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
@@ -372,7 +376,7 @@ public class XSSFTextParagraph implement
      * inset and applies only to this text paragraph. That is the text body inset and the
LeftMargin
      * attributes are additive with respect to the text position.
      *
-     * @param value the left margin of the paragraph
+     * @param value the left margin of the paragraph, -1 to clear the margin and use the
default of 0.
      */
     public void setLeftMargin(double value){
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
@@ -409,7 +413,7 @@ public class XSSFTextParagraph implement
      * inset and applies only to this text paragraph. That is the text body inset and the
marR
      * attributes are additive with respect to the text position.
      *
-     * @param value the right margin of the paragraph
+     * @param value the right margin of the paragraph, -1 to clear the margin and use the
default of 0.
      */
     public void setRightMargin(double value){
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java?rev=1649232&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java
(added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextParagraph.java
Sat Jan  3 19:29:51 2015
@@ -0,0 +1,198 @@
+/* ====================================================================
+   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 java.util.List;
+
+import org.junit.Test;
+
+public class TestXSSFTextParagraph {
+    @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);
+            
+            List<XSSFTextParagraph> paras = shape.getTextParagraphs();
+            assertEquals(1, paras.size());
+    
+            XSSFTextParagraph text = paras.get(0);
+            assertEquals("Test String", text.getText());
+            
+            assertFalse(text.isBullet());
+            assertNotNull(text.getXmlObject());
+            assertEquals(shape.getCTShape(), text.getParentShape());
+            assertNotNull(text.iterator());
+            assertNotNull(text.addLineBreak());
+
+            assertNotNull(text.getTextRuns());
+            assertEquals(2, text.getTextRuns().size());
+            text.addNewTextRun();
+            assertEquals(3, text.getTextRuns().size());
+            
+            assertEquals(TextAlign.LEFT, text.getTextAlign());
+            text.setTextAlign(null);
+            assertEquals(TextAlign.LEFT, text.getTextAlign());
+            text.setTextAlign(TextAlign.CENTER);
+            assertEquals(TextAlign.CENTER, text.getTextAlign());
+            text.setTextAlign(TextAlign.RIGHT);
+            assertEquals(TextAlign.RIGHT, text.getTextAlign());
+            text.setTextAlign(null);
+            assertEquals(TextAlign.LEFT, text.getTextAlign());
+            
+            text.setTextFontAlign(TextFontAlign.BASELINE);
+            assertEquals(TextFontAlign.BASELINE, text.getTextFontAlign());
+            text.setTextFontAlign(TextFontAlign.BOTTOM);
+            assertEquals(TextFontAlign.BOTTOM, text.getTextFontAlign());
+            text.setTextFontAlign(null);
+            assertEquals(TextFontAlign.BASELINE, text.getTextFontAlign());
+            text.setTextFontAlign(null);
+            assertEquals(TextFontAlign.BASELINE, text.getTextFontAlign());
+            
+            assertNull(text.getBulletFont());
+            text.setBulletFont("Arial");
+            assertEquals("Arial", text.getBulletFont());
+            
+            assertNull(text.getBulletCharacter());
+            text.setBulletCharacter(".");
+            assertEquals(".", text.getBulletCharacter());
+            
+            assertNull(text.getBulletFontColor());
+            text.setBulletFontColor(color);
+            assertEquals(color, text.getBulletFontColor());
+            
+            assertEquals(100.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(1.0);
+            assertEquals(1.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(1.0);
+            assertEquals(1.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(-9.0);
+            assertEquals(-9.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(-9.0);
+            assertEquals(-9.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(1.0);
+            assertEquals(1.0, text.getBulletFontSize(), 0.01);
+            text.setBulletFontSize(-9.0);
+            assertEquals(-9.0, text.getBulletFontSize(), 0.01);
+
+            assertEquals(0.0, text.getIndent(), 0.01);
+            text.setIndent(2.0);
+            assertEquals(2.0, text.getIndent(), 0.01);
+            text.setIndent(-1.0);
+            assertEquals(0.0, text.getIndent(), 0.01);
+            text.setIndent(-1.0);
+            assertEquals(0.0, text.getIndent(), 0.01);
+            
+            assertEquals(0.0, text.getLeftMargin(), 0.01);
+            text.setLeftMargin(3.0);
+            assertEquals(3.0, text.getLeftMargin(), 0.01);
+            text.setLeftMargin(-1.0);
+            assertEquals(0.0, text.getLeftMargin(), 0.01);
+            text.setLeftMargin(-1.0);
+            assertEquals(0.0, text.getLeftMargin(), 0.01);
+            
+            assertEquals(0.0, text.getRightMargin(), 0.01);
+            text.setRightMargin(4.5);
+            assertEquals(4.5, text.getRightMargin(), 0.01);
+            text.setRightMargin(-1.0);
+            assertEquals(0.0, text.getRightMargin(), 0.01);
+            text.setRightMargin(-1.0);
+            assertEquals(0.0, text.getRightMargin(), 0.01);
+            
+            assertEquals(0.0, text.getDefaultTabSize(), 0.01);
+            
+            assertEquals(0.0, text.getTabStop(0), 0.01);
+            text.addTabStop(3.14);
+            assertEquals(3.14, text.getTabStop(0), 0.01);
+            
+            assertEquals(100.0, text.getLineSpacing(), 0.01);
+            text.setLineSpacing(3.15);
+            assertEquals(3.15, text.getLineSpacing(), 0.01);
+            text.setLineSpacing(-2.13);
+            assertEquals(-2.13, text.getLineSpacing(), 0.01);
+
+            assertEquals(0.0, text.getSpaceBefore(), 0.01);
+            text.setSpaceBefore(3.17);
+            assertEquals(3.17, text.getSpaceBefore(), 0.01);
+            text.setSpaceBefore(-4.7);
+            assertEquals(-4.7, text.getSpaceBefore(), 0.01);
+
+            assertEquals(0.0, text.getSpaceAfter(), 0.01);
+            text.setSpaceAfter(6.17);
+            assertEquals(6.17, text.getSpaceAfter(), 0.01);
+            text.setSpaceAfter(-8.17);
+            assertEquals(-8.17, text.getSpaceAfter(), 0.01);
+            
+            assertEquals(0, text.getLevel());
+            text.setLevel(1);
+            assertEquals(1, text.getLevel());
+            text.setLevel(4);
+            assertEquals(4, text.getLevel());
+            
+            assertTrue(text.isBullet());
+            assertFalse(text.isBulletAutoNumber());
+            text.setBullet(false);
+            text.setBullet(false);
+            assertFalse(text.isBullet());
+            assertFalse(text.isBulletAutoNumber());
+            text.setBullet(true);
+            assertTrue(text.isBullet());
+            assertFalse(text.isBulletAutoNumber());
+            assertEquals(0, text.getBulletAutoNumberStart());
+            assertEquals(ListAutoNumber.ARABIC_PLAIN, text.getBulletAutoNumberScheme());
+            
+            text.setBullet(false);
+            assertFalse(text.isBullet());
+            text.setBullet(ListAutoNumber.CIRCLE_NUM_DB_PLAIN);
+            assertTrue(text.isBullet());
+            assertTrue(text.isBulletAutoNumber());
+            assertEquals(0, text.getBulletAutoNumberStart());
+            assertEquals(ListAutoNumber.CIRCLE_NUM_DB_PLAIN, text.getBulletAutoNumberScheme());
+            text.setBullet(false);
+            assertFalse(text.isBullet());
+            assertFalse(text.isBulletAutoNumber());
+            text.setBullet(ListAutoNumber.CIRCLE_NUM_WD_BLACK_PLAIN, 10);
+            assertTrue(text.isBullet());
+            assertTrue(text.isBulletAutoNumber());
+            assertEquals(10, text.getBulletAutoNumberStart());
+            assertEquals(ListAutoNumber.CIRCLE_NUM_WD_BLACK_PLAIN, text.getBulletAutoNumberScheme());
+
+            
+            assertNotNull(text.toString());
+            
+            new XSSFTextParagraph(text.getXmlObject(), shape.getCTShape());
+        } finally {
+            wb.close();
+        }
+    }
+}



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


Mime
View raw message