From 65dfa4d50982f233ae674c1cbb6139abd7da788f Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Wed, 20 Jun 2012 08:46:50 +0000 Subject: [PATCH] more tests to ensure that poi compiles against poi-ooxml-schemas.jar git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1351994 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/XSLFTextParagraph.java | 8 ++++- .../poi/xslf/usermodel/XSLFTextRun.java | 33 +++++++++++++++++ .../poi/xslf/usermodel/TestXSLFColor.java | 21 ++++++++--- .../xslf/usermodel/TestXSLFSimpleShape.java | 14 ++++++-- .../xslf/usermodel/TestXSLFTableStyles.java | 6 ++++ .../xslf/usermodel/TestXSLFTextParagraph.java | 11 ++++++ .../poi/xslf/usermodel/TestXSLFTextRun.java | 11 ++++++ .../poi/xwpf/usermodel/TestXWPFDocument.java | 6 ++++ .../poi/xwpf/usermodel/TestXWPFStyles.java | 36 +++++++++++++++++++ 9 files changed, 137 insertions(+), 9 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 73c2e52d99..a932fb5cd3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -425,7 +425,13 @@ public class XSLFTextParagraph implements Iterable{ } }; fetchParagraphProperty(fetcher); - return fetcher.getValue() == null ? getDefaultTabSize() : fetcher.getValue(); + return fetcher.getValue() == null ? 0. : fetcher.getValue(); + } + + public void addTabStop(double value){ + CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); + CTTextTabStopList tabStops = pr.isSetTabLst() ? pr.getTabLst() : pr.addNewTabLst(); + tabStops.addNewTab().setPos(Units.toEMU(value)); } /** diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java index d7a10c20c8..c6f0591704 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java @@ -352,6 +352,39 @@ public class XSLFTextRun { return fetcher.getValue() == null ? false : fetcher.getValue(); } + /** + * Set the baseline for both the superscript and subscript fonts. + *

+ * The size is specified using a percentage. + * Positive values indicate superscript, negative values indicate subscript. + *

+ * + * @param baselineOffset + */ + public void setBaselineOffset(double baselineOffset){ + getRPr().setBaseline((int) baselineOffset * 1000); + } + + /** + * Set whether the text in this run is formatted as superscript. + * Default base line offset is 30% + * + * @see #setBaselineOffset(double) + */ + public void setSuperscript(boolean flag){ + setBaselineOffset(flag ? 30. : 0.); + } + + /** + * Set whether the text in this run is formatted as subscript. + * Default base line offset is -25%. + * + * @see #setBaselineOffset(double) + */ + public void setSubscript(boolean flag){ + setBaselineOffset(flag ? -25.0 : 0.); + } + /** * @return whether a run of text will be formatted as a superscript text. Default is false. */ diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java index a08faf0e38..b335983d09 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java @@ -17,11 +17,7 @@ package org.apache.poi.xslf.usermodel; import junit.framework.TestCase; -import org.openxmlformats.schemas.drawingml.x2006.main.CTColor; -import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor; -import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor; -import org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal; -import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal; +import org.openxmlformats.schemas.drawingml.x2006.main.*; import java.awt.Color; @@ -149,4 +145,19 @@ public class TestXSLFColor extends TestCase { assertEquals(XSLFColor.presetColors.get(colorName), color.getColor()); } } + + public void testSys() { + CTColor xml = CTColor.Factory.newInstance(); + CTSystemColor sys = xml.addNewSysClr(); + sys.setVal(STSystemColorVal.GRAY_TEXT); + XSLFColor color = new XSLFColor(xml, null, null); + assertEquals(Color.black, color.getColor()); + + xml = CTColor.Factory.newInstance(); + sys = xml.addNewSysClr(); + sys.setLastClr(new byte[]{(byte)0xFF, 0, 0}); + color = new XSLFColor(xml, null, null); + assertEquals(Color.red, color.getColor()); + } + } \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java index f5839fd778..dc00fff69f 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java @@ -19,9 +19,7 @@ package org.apache.poi.xslf.usermodel; import junit.framework.TestCase; import org.apache.poi.util.Units; import org.apache.poi.xslf.XSLFTestDataSamples; -import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor; -import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap; -import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal; +import org.openxmlformats.schemas.drawingml.x2006.main.*; import java.awt.Color; @@ -231,4 +229,14 @@ public class TestXSLFSimpleShape extends TestCase { } + public void testShadowEffects(){ + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide slide = ppt.createSlide(); + CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme(); + CTEffectStyleList lst = styleMatrix.getEffectStyleLst(); + assertNotNull(lst); + for(CTEffectStyleItem ef : lst.getEffectStyleList()){ + CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw(); + } + } } \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java index 0feff27d25..3ce6c3b6d2 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java @@ -17,6 +17,7 @@ package org.apache.poi.xslf.usermodel; import junit.framework.TestCase; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle; /** * @author Yegor Kozlov @@ -30,4 +31,9 @@ public class TestXSLFTableStyles extends TestCase { assertEquals(0, tblStyles.getStyles().size()); } + + public void testStyle(){ + CTTableStyle obj = CTTableStyle.Factory.newInstance(); + XSLFTableStyle style = new XSLFTableStyle(obj); + } } \ 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 2a44c058bb..00b4cbdcce 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java @@ -289,6 +289,17 @@ public class TestXSLFTextParagraph extends TestCase { p.setBullet(false); assertFalse(p.isBullet()); + + p.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_BOTH, 1); + + double tabStop = p.getTabStop(0); + assertEquals(0.0, tabStop); + + p.addTabStop(100.); + assertEquals(100., p.getTabStop(0)); + + assertEquals(72.0, p.getDefaultTabSize()); + } public void testLineBreak(){ diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java index 256c9eaecb..eb7553ecc4 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java @@ -56,5 +56,16 @@ public class TestXSLFTextRun extends TestCase { r.setFontSize(13.0); assertEquals(13.0, r.getFontSize()); + assertEquals(false, r.isSuperscript()); + r.setSuperscript(true); + assertEquals(true, r.isSuperscript()); + r.setSuperscript(false); + assertEquals(false, r.isSuperscript()); + + assertEquals(false, r.isSubscript()); + r.setSubscript(true); + assertEquals(true, r.isSubscript()); + r.setSubscript(false); + assertEquals(false, r.isSubscript()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index 7f87bff921..09c1c1636f 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -337,4 +337,10 @@ public final class TestXWPFDocument extends TestCase { doc.getPackage().revert(); } + + public void testSettings(){ + XWPFSettings settings = new XWPFSettings(); + settings.setZoomPercent(50); + assertEquals(50, settings.getZoomPercent()); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java index 3c13504cdf..5d13185cfc 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java @@ -26,7 +26,11 @@ import junit.framework.TestCase; import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException; public class TestXWPFStyles extends TestCase { @@ -82,4 +86,36 @@ public class TestXWPFStyles extends TestCase { assertNotNull(styles); } + + /** + * YK: tests below don't make much sense, + * they exist only to copy xml beans to pi-ooxml-schemas.jar + */ + public void testLanguages(){ + XWPFDocument docOut = new XWPFDocument(); + XWPFStyles styles = docOut.createStyles(); + styles.setEastAsia("Chinese"); + + styles.setSpellingLanguage("English"); + + CTFonts def = CTFonts.Factory.newInstance(); + styles.setDefaultFonts(def); + } + + public void testType() { + CTStyle ctStyle = CTStyle.Factory.newInstance(); + XWPFStyle style = new XWPFStyle(ctStyle); + + style.setType(STStyleType.PARAGRAPH); + assertEquals(STStyleType.PARAGRAPH, style.getType()); + } + + public void testLatentStyles() { + CTLatentStyles latentStyles = CTLatentStyles.Factory.newInstance(); + CTLsdException ex = latentStyles.addNewLsdException(); + ex.setName("ex1"); + XWPFLatentStyles ls = new XWPFLatentStyles(latentStyles); + assertEquals(true, ls.isLatentStyle("ex1")); + + } } -- 2.39.5