From 2de8e3793566b4e9640012968910fac528020ad9 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 19 Jan 2012 08:09:26 +0000 Subject: [PATCH] more XSLF tests to ensure that poi-ooxml-schemas.jar contains all used classes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1233242 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/XSLFTextParagraph.java | 56 +++++++++++++-- .../poi/xslf/usermodel/TestXSLFSlide.java | 15 ++++ .../xslf/usermodel/TestXSLFTextParagraph.java | 72 +++++++++++++++++++ 3 files changed, 136 insertions(+), 7 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index 44a20bd1a9..e78acefb8e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -211,6 +211,11 @@ public class XSLFTextParagraph implements Iterable{ c.setChar(str); } + /** + * + * @return the color of bullet characters within a given paragraph. + * A null value means to use the text font color. + */ public Color getBulletFontColor(){ final XSLFTheme theme = getParentShape().getSheet().getTheme(); ParagraphPropertyFetcher fetcher = new ParagraphPropertyFetcher(getLevel()){ @@ -227,6 +232,11 @@ public class XSLFTextParagraph implements Iterable{ return fetcher.getValue(); } + /** + * Set the color to be used on bullet characters within a given paragraph. + * + * @param color the bullet color + */ public void setBulletFontColor(Color color){ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); CTColor c = pr.isSetBuClr() ? pr.getBuClr() : pr.addNewBuClr(); @@ -234,6 +244,16 @@ public class XSLFTextParagraph implements Iterable{ clr.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()}); } + /** + * Returns the bullet size that is to be used within a paragraph. + * This may be specified in two different ways, percentage spacing and font point spacing: + *

+ * If bulletSize >= 0, then bulletSize is a percentage of the font size. + * If bulletSize < 0, then it specifies the size in points + *

+ * + * @return the bullet size + */ public double getBulletFontSize(){ ParagraphPropertyFetcher fetcher = new ParagraphPropertyFetcher(getLevel()){ public boolean fetch(CTTextParagraphProperties props){ @@ -252,12 +272,29 @@ public class XSLFTextParagraph implements Iterable{ return fetcher.getValue() == null ? 100 : fetcher.getValue(); } - public void setBulletFontSize(double size){ + /** + * Sets the bullet size that is to be used within a paragraph. + * This may be specified in two different ways, percentage spacing and font point spacing: + *

+ * If bulletSize >= 0, then bulletSize is a percentage of the font size. + * If bulletSize < 0, then it specifies the size in points + *

+ * + * @return the bullet size + */ + public void setBulletFontSize(double bulletSize){ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); - CTTextBulletSizePoint pt = pr.isSetBuSzPts() ? pr.getBuSzPts() : pr.addNewBuSzPts(); - pt.setVal((int)(size*1000)); - if(pr.isSetBuSzPct()) pr.unsetBuSzPct(); - } + + if(bulletSize >= 0) { + CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct(); + pt.setVal((int)(bulletSize*1000)); + if(pr.isSetBuSzPts()) pr.unsetBuSzPts(); + } else { + CTTextBulletSizePoint pt = pr.isSetBuSzPts() ? pr.getBuSzPts() : pr.addNewBuSzPts(); + pt.setVal((int)(-bulletSize*100)); + if(pr.isSetBuSzPct()) pr.unsetBuSzPct(); + } + } /** * Specifies the indent size that will be applied to the first line of text in the paragraph. @@ -302,7 +339,12 @@ public class XSLFTextParagraph implements Iterable{ */ public void setLeftMargin(double value){ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); - pr.setMarL(Units.toEMU(value)); + if(value == -1) { + if(pr.isSetMarL()) pr.unsetMarL(); + } else { + pr.setMarL(Units.toEMU(value)); + } + } /** @@ -327,7 +369,7 @@ public class XSLFTextParagraph implements Iterable{ /** * - * @return the default size for a tab character within this paragraph + * @return the default size for a tab character within this paragraph in points */ public double getDefaultTabSize(){ ParagraphPropertyFetcher fetcher = new ParagraphPropertyFetcher(getLevel()){ diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java index f658e6b555..9bba6c269f 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; import org.apache.poi.xslf.XSLFTestDataSamples; import java.awt.Color; +import java.io.FileInputStream; import java.util.Arrays; /** @@ -159,4 +160,18 @@ public class TestXSLFSlide extends TestCase { XSLFPictureShape srcPic = (XSLFPictureShape)src.getSlides()[4].getShapes()[1]; assertTrue(Arrays.equals(sh4.getPictureData().getData(), srcPic.getPictureData().getData())); } + + public void testMergeSlides(){ + XMLSlideShow ppt = new XMLSlideShow(); + String[] pptx = {"shapes.pptx", "themes.pptx", "layouts.pptx", "backgrounds.pptx"}; + + for(String arg : pptx){ + XMLSlideShow src = XSLFTestDataSamples.openSampleDocument(arg); + + for(XSLFSlide srcSlide : src.getSlides()){ + ppt.createSlide().importContent(srcSlide); + } + } + assertEquals(30, ppt.getSlides().length); + } } \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java index 989b237f82..50d4c812b5 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java @@ -219,7 +219,79 @@ public class TestXSLFTextParagraph extends TestCase { XSLFTextShape sh3 = (XSLFTextShape)shapes[2]; assertEquals("Foundation", sh3.getText()); assertEquals(TextAlign.CENTER, sh3.getTextParagraphs().get(0).getTextAlign()); + } + public void testParagraphProperties(){ + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide slide = ppt.createSlide(); + XSLFTextShape sh = slide.createAutoShape(); + XSLFTextParagraph p = sh.addNewTextParagraph(); + assertFalse(p.isBullet()); + p.setBullet(true); + assertTrue(p.isBullet()); + + assertEquals("\u2022", p.getBulletCharacter()); + p.setBulletCharacter("*"); + assertEquals("*", p.getBulletCharacter()); + + assertEquals("Arial", p.getBulletFont()); + p.setBulletFont("Calibri"); + assertEquals("Calibri", p.getBulletFont()); + + assertEquals(null, p.getBulletFontColor()); + p.setBulletFontColor(Color.red); + assertEquals(Color.red, p.getBulletFontColor()); + + assertEquals(100.0, p.getBulletFontSize()); + p.setBulletFontSize(200.); + assertEquals(200., p.getBulletFontSize()); + p.setBulletFontSize(-20.); + assertEquals(-20.0, p.getBulletFontSize()); + + assertEquals(72.0, p.getDefaultTabSize()); + + assertEquals(0.0, p.getIndent()); + p.setIndent(72.0); + assertEquals(72.0, p.getIndent()); + p.setIndent(-1.0); // the value of -1.0 resets to the defaults + assertEquals(0.0, p.getIndent()); + + assertEquals(0.0, p.getLeftMargin()); + p.setLeftMargin(72.0); + assertEquals(72.0, p.getLeftMargin()); + p.setLeftMargin(-1.0); // the value of -1.0 resets to the defaults + assertEquals(0.0, p.getLeftMargin()); + + assertEquals(0, p.getLevel()); + p.setLevel(1); + assertEquals(1, p.getLevel()); + p.setLevel(2); + assertEquals(2, p.getLevel()); + + assertEquals(100., p.getLineSpacing()); + p.setLineSpacing(200.); + assertEquals(200.0, p.getLineSpacing()); + p.setLineSpacing(-15.); + assertEquals(-15.0, p.getLineSpacing()); + + assertEquals(0., p.getSpaceAfter()); + p.setSpaceAfter(200.); + assertEquals(200.0, p.getSpaceAfter()); + p.setSpaceAfter(-15.); + assertEquals(-15.0, p.getSpaceAfter()); + + assertEquals(0., p.getSpaceBefore()); + p.setSpaceBefore(200.); + assertEquals(200.0, p.getSpaceBefore()); + p.setSpaceBefore(-15.); + assertEquals(-15.0, p.getSpaceBefore()); + + assertEquals(TextAlign.LEFT, p.getTextAlign()); + p.setTextAlign(TextAlign.RIGHT); + assertEquals(TextAlign.RIGHT, p.getTextAlign()); + + p.setBullet(false); + assertFalse(p.isBullet()); } }