]> source.dussan.org Git - poi.git/commitdiff
more XSLF tests to ensure that poi-ooxml-schemas.jar contains all used classes
authorYegor Kozlov <yegor@apache.org>
Thu, 19 Jan 2012 08:09:26 +0000 (08:09 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 19 Jan 2012 08:09:26 +0000 (08:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1233242 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java

index 44a20bd1a913225d3959e0ced7c29dc83c2212f6..e78acefb8e9394b7a164ee1774d9c4ff6b80c4d3 100644 (file)
@@ -211,6 +211,11 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
         c.setChar(str);\r
     }\r
 \r
+    /**\r
+     *\r
+     * @return the color of bullet characters within a given paragraph.\r
+     * A <code>null</code> value means to use the text font color.\r
+     */\r
     public Color getBulletFontColor(){\r
         final XSLFTheme theme = getParentShape().getSheet().getTheme();\r
         ParagraphPropertyFetcher<Color> fetcher = new ParagraphPropertyFetcher<Color>(getLevel()){\r
@@ -227,6 +232,11 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
         return fetcher.getValue();\r
     }\r
 \r
+    /**\r
+     * Set the color to be used on bullet characters within a given paragraph.\r
+     *\r
+     * @param color the bullet color\r
+     */\r
     public void setBulletFontColor(Color color){\r
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();\r
         CTColor c = pr.isSetBuClr() ? pr.getBuClr() : pr.addNewBuClr();\r
@@ -234,6 +244,16 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
         clr.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});\r
     }\r
 \r
+    /**\r
+     * Returns the bullet size that is to be used within a paragraph.\r
+     * This may be specified in two different ways, percentage spacing and font point spacing:\r
+     * <p>\r
+     * If bulletSize >= 0, then bulletSize is a percentage of the font size.\r
+     * If bulletSize < 0, then it specifies the size in points\r
+     * </p>\r
+     *\r
+     * @return the bullet size\r
+     */\r
     public double getBulletFontSize(){\r
         ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){\r
             public boolean fetch(CTTextParagraphProperties props){\r
@@ -252,12 +272,29 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
         return fetcher.getValue() == null ? 100 : fetcher.getValue();\r
     }\r
 \r
-    public void setBulletFontSize(double size){\r
+    /**\r
+     * Sets the bullet size that is to be used within a paragraph.\r
+     * This may be specified in two different ways, percentage spacing and font point spacing:\r
+     * <p>\r
+     * If bulletSize >= 0, then bulletSize is a percentage of the font size.\r
+     * If bulletSize < 0, then it specifies the size in points\r
+     * </p>\r
+     *\r
+     * @return the bullet size\r
+     */\r
+    public void setBulletFontSize(double bulletSize){\r
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();\r
-        CTTextBulletSizePoint pt = pr.isSetBuSzPts() ? pr.getBuSzPts() : pr.addNewBuSzPts();\r
-        pt.setVal((int)(size*1000));\r
-        if(pr.isSetBuSzPct()) pr.unsetBuSzPct();\r
-    }\r
+\r
+        if(bulletSize >= 0) {\r
+            CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();\r
+            pt.setVal((int)(bulletSize*1000));\r
+            if(pr.isSetBuSzPts()) pr.unsetBuSzPts();\r
+        } else {\r
+            CTTextBulletSizePoint pt = pr.isSetBuSzPts() ? pr.getBuSzPts() : pr.addNewBuSzPts();\r
+            pt.setVal((int)(-bulletSize*100));\r
+            if(pr.isSetBuSzPct()) pr.unsetBuSzPct();\r
+        }\r
+   }\r
 \r
     /**\r
      * Specifies the indent size that will be applied to the first line of text in the paragraph.\r
@@ -302,7 +339,12 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
      */\r
     public void setLeftMargin(double value){\r
         CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();\r
-        pr.setMarL(Units.toEMU(value));\r
+        if(value == -1) {\r
+            if(pr.isSetMarL()) pr.unsetMarL();\r
+        } else {\r
+            pr.setMarL(Units.toEMU(value));\r
+        }\r
+\r
     }\r
 \r
     /**\r
@@ -327,7 +369,7 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
 \r
     /**\r
      *\r
-     * @return the default size for a tab character within this paragraph\r
+     * @return the default size for a tab character within this paragraph in points\r
      */\r
     public double getDefaultTabSize(){\r
         ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){\r
index f658e6b555da1c75b467489fcc9fdce335c07002..9bba6c269f811f2b051f343b314a6de69b92b103 100644 (file)
@@ -20,6 +20,7 @@ import junit.framework.TestCase;
 import org.apache.poi.xslf.XSLFTestDataSamples;\r
 \r
 import java.awt.Color;\r
+import java.io.FileInputStream;\r
 import java.util.Arrays;\r
 \r
 /**\r
@@ -159,4 +160,18 @@ public class TestXSLFSlide extends TestCase {
         XSLFPictureShape srcPic = (XSLFPictureShape)src.getSlides()[4].getShapes()[1];\r
         assertTrue(Arrays.equals(sh4.getPictureData().getData(), srcPic.getPictureData().getData()));\r
     }\r
+\r
+    public void testMergeSlides(){\r
+        XMLSlideShow ppt = new XMLSlideShow();\r
+        String[] pptx = {"shapes.pptx", "themes.pptx", "layouts.pptx", "backgrounds.pptx"};\r
+\r
+        for(String arg : pptx){\r
+            XMLSlideShow  src = XSLFTestDataSamples.openSampleDocument(arg);\r
+\r
+            for(XSLFSlide srcSlide : src.getSlides()){\r
+                ppt.createSlide().importContent(srcSlide);\r
+            }\r
+        }\r
+        assertEquals(30, ppt.getSlides().length);\r
+    }    \r
 }
\ No newline at end of file
index 989b237f828d181a6b2f1a0c897f5618a22db275..50d4c812b5c650c7e8ced62256179c8f683a6439 100644 (file)
@@ -219,7 +219,79 @@ public class TestXSLFTextParagraph extends TestCase {
         XSLFTextShape sh3 = (XSLFTextShape)shapes[2];\r
         assertEquals("Foundation", sh3.getText());\r
         assertEquals(TextAlign.CENTER, sh3.getTextParagraphs().get(0).getTextAlign());\r
+    }\r
 \r
+    public void testParagraphProperties(){\r
+        XMLSlideShow ppt = new XMLSlideShow();\r
+        XSLFSlide slide = ppt.createSlide();\r
+        XSLFTextShape sh = slide.createAutoShape();\r
 \r
+        XSLFTextParagraph p = sh.addNewTextParagraph();\r
+        assertFalse(p.isBullet());\r
+        p.setBullet(true);\r
+        assertTrue(p.isBullet());\r
+\r
+        assertEquals("\u2022", p.getBulletCharacter());\r
+        p.setBulletCharacter("*");\r
+        assertEquals("*", p.getBulletCharacter());\r
+\r
+        assertEquals("Arial", p.getBulletFont());\r
+        p.setBulletFont("Calibri");\r
+        assertEquals("Calibri", p.getBulletFont());\r
+\r
+        assertEquals(null, p.getBulletFontColor());\r
+        p.setBulletFontColor(Color.red);\r
+        assertEquals(Color.red, p.getBulletFontColor());\r
+\r
+        assertEquals(100.0, p.getBulletFontSize());\r
+        p.setBulletFontSize(200.);\r
+        assertEquals(200., p.getBulletFontSize());\r
+        p.setBulletFontSize(-20.);\r
+        assertEquals(-20.0, p.getBulletFontSize());\r
+\r
+        assertEquals(72.0, p.getDefaultTabSize());\r
+        \r
+        assertEquals(0.0, p.getIndent());\r
+        p.setIndent(72.0);\r
+        assertEquals(72.0, p.getIndent());\r
+        p.setIndent(-1.0); // the value of -1.0 resets to the defaults\r
+        assertEquals(0.0, p.getIndent());\r
+\r
+        assertEquals(0.0, p.getLeftMargin());\r
+        p.setLeftMargin(72.0);\r
+        assertEquals(72.0, p.getLeftMargin());\r
+        p.setLeftMargin(-1.0); // the value of -1.0 resets to the defaults\r
+        assertEquals(0.0, p.getLeftMargin());\r
+\r
+        assertEquals(0, p.getLevel());\r
+        p.setLevel(1);\r
+        assertEquals(1, p.getLevel());\r
+        p.setLevel(2);\r
+        assertEquals(2, p.getLevel());\r
+\r
+        assertEquals(100., p.getLineSpacing());\r
+        p.setLineSpacing(200.);\r
+        assertEquals(200.0, p.getLineSpacing());\r
+        p.setLineSpacing(-15.);\r
+        assertEquals(-15.0, p.getLineSpacing());\r
+\r
+        assertEquals(0., p.getSpaceAfter());\r
+        p.setSpaceAfter(200.);\r
+        assertEquals(200.0, p.getSpaceAfter());\r
+        p.setSpaceAfter(-15.);\r
+        assertEquals(-15.0, p.getSpaceAfter());\r
+\r
+        assertEquals(0., p.getSpaceBefore());\r
+        p.setSpaceBefore(200.);\r
+        assertEquals(200.0, p.getSpaceBefore());\r
+        p.setSpaceBefore(-15.);\r
+        assertEquals(-15.0, p.getSpaceBefore());\r
+\r
+        assertEquals(TextAlign.LEFT, p.getTextAlign());\r
+        p.setTextAlign(TextAlign.RIGHT);\r
+        assertEquals(TextAlign.RIGHT, p.getTextAlign());\r
+\r
+        p.setBullet(false);\r
+        assertFalse(p.isBullet());\r
     }\r
 }\r