You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/08/11 10:38:20 UTC
svn commit: r1156539 [3/3] - in /poi/trunk: src/documentation/content/xdocs/
src/examples/src/org/apache/poi/xslf/
src/examples/src/org/apache/poi/xslf/usermodel/
src/ooxml/java/org/apache/poi/util/ src/ooxml/java/org/apache/poi/xslf/
src/ooxml/java/or...
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,334 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Represents a paragraph of text within the containing text body.
+ * The paragraph is the highest level text separation mechanism.
+ *
+ * @author Yegor Kozlov
+ * @since POI-3.8
+ */
+@Beta
+public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
+ private final CTTextParagraph _p;
+ private final List<XSLFTextRun> _runs;
+
+ XSLFTextParagraph(CTTextParagraph p){
+ _p = p;
+ _runs = new ArrayList<XSLFTextRun>();
+ for (CTRegularTextRun r : _p.getRList()) {
+ _runs.add(new XSLFTextRun(r));
+ }
+ }
+
+ public String getText(){
+ StringBuilder out = new StringBuilder();
+ for (CTRegularTextRun r : _p.getRList()) {
+ out.append(r.getT());
+ }
+ return out.toString();
+ }
+
+ @Internal
+ public CTTextParagraph getXmlObject(){
+ return _p;
+ }
+
+ public List<XSLFTextRun> getTextRuns(){
+ return _runs;
+ }
+
+ public Iterator<XSLFTextRun> iterator(){
+ return _runs.iterator();
+ }
+
+ public XSLFTextRun addNewTextRun(){
+ CTRegularTextRun r = _p.addNewR();
+ XSLFTextRun run = new XSLFTextRun(r);
+ _runs.add(run);
+ return run;
+ }
+
+ public void addLineBreak(){
+ _p.addNewBr();
+ }
+
+ /**
+ * Returns the alignment that is applied to the paragraph.
+ *
+ * If this attribute is omitted, then a value of left is implied.
+ * @return ??? alignment that is applied to the paragraph
+ */
+ public TextAlign getTextAlign(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetAlgn()) return TextAlign.LEFT;
+
+ return TextAlign.values()[pr.getAlgn().intValue() - 1];
+ }
+
+ /**
+ * Specifies the alignment that is to be applied to the paragraph.
+ * Possible values for this include left, right, centered, justified and distributed,
+ * see {@link org.apache.poi.xslf.usermodel.TextAlign}.
+ *
+ * @param align text align
+ */
+ public void setTextAlign(TextAlign align){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ if(align == null) {
+ if(pr.isSetAlgn()) pr.unsetAlgn();
+ } else {
+ pr.setAlgn(STTextAlignType.Enum.forInt(align.ordinal() + 1));
+ }
+ }
+
+ /**
+ * Specifies the indent size that will be applied to the first line of text in the paragraph.
+ *
+ * @param value the indent in points. The value of -1 unsets the indent attribute
+ * from the underlying xml bean.
+ */
+ public void setIndent(double value){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ if(value == -1) {
+ if(pr.isSetIndent()) pr.unsetIndent();
+ } else {
+ pr.setIndent(Units.toEMU(value));
+ }
+ }
+
+ /**
+ *
+ * @return the indent applied to the first line of text in the paragraph.
+ */
+ public double getIndent(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetIndent()) return 0;
+
+ return Units.toPoints(pr.getIndent());
+ }
+
+ /**
+ * Specifies the left margin of the paragraph. This is specified in addition to the text body
+ * 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
+ */
+ public void setLeftMargin(double value){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ pr.setMarL(Units.toEMU(value));
+ }
+
+ /**
+ *
+ * @return the left margin of the paragraph
+ */
+ public double getLeftMargin(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetMarL()) return 0;
+
+ return Units.toPoints(pr.getMarL());
+ }
+
+ /**
+ * This element specifies the vertical line spacing that is to be used within a paragraph.
+ * This may be specified in two different ways, percentage spacing and font point spacing:
+ * <p>
+ * If linespacing >= 0, then linespacing is a percentage of normal line height
+ * If linespacing < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ * Examples:
+ * <pre><code>
+ * // spacing will be 120% of the size of the largest text on each line
+ * paragraph.setLineSpacing(120);
+ *
+ * // spacing will be 200% of the size of the largest text on each line
+ * paragraph.setLineSpacing(200);
+ *
+ * // spacing will be 48 points
+ * paragraph.setLineSpacing(-48.0);
+ * </code></pre>
+ *
+ * @param linespacing the vertical line spacing
+ */
+ public void setLineSpacing(double linespacing){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
+ if(linespacing >= 0) spc.addNewSpcPct().setVal((int)(linespacing*1000));
+ else spc.addNewSpcPts().setVal((int)(-linespacing*100));
+ pr.setLnSpc(spc);
+ }
+
+ /**
+ * Returns the vertical line spacing that is to be used within a paragraph.
+ * This may be specified in two different ways, percentage spacing and font point spacing:
+ * <p>
+ * If linespacing >= 0, then linespacing is a percentage of normal line height.
+ * If linespacing < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ *
+ * @return the vertical line spacing.
+ */
+ public double getLineSpacing(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetLnSpc()) return 100; // TODO fetch from master
+
+ CTTextSpacing spc = pr.getLnSpc();
+ if(spc.isSetSpcPct()) return spc.getSpcPct().getVal()*0.001;
+ else if (spc.isSetSpcPts()) return -spc.getSpcPts().getVal()*0.01;
+ else return 100;
+ }
+
+ /**
+ * Set the amount of vertical white space that will be present before the paragraph.
+ * This space is specified in either percentage or points:
+ * <p>
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ * Examples:
+ * <pre><code>
+ * // The paragraph will be formatted to have a spacing before the paragraph text.
+ * // The spacing will be 200% of the size of the largest text on each line
+ * paragraph.setSpaceBefore(200);
+ *
+ * // The spacing will be a size of 48 points
+ * paragraph.setSpaceBefore(-48.0);
+ * </code></pre>
+ *
+ * @param spaceBefore the vertical white space before the paragraph.
+ */
+ public void setSpaceBefore(double spaceBefore){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
+ if(spaceBefore >= 0) spc.addNewSpcPct().setVal((int)(spaceBefore*1000));
+ else spc.addNewSpcPts().setVal((int)(-spaceBefore*100));
+ pr.setSpcBef(spc);
+ }
+
+ /**
+ * The amount of vertical white space before the paragraph
+ * This may be specified in two different ways, percentage spacing and font point spacing:
+ * <p>
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ *
+ * @return the vertical white space before the paragraph
+ */
+ public double getSpaceBefore(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetSpcBef()) return 0; // TODO fetch from master
+
+ CTTextSpacing spc = pr.getSpcBef();
+ if(spc.isSetSpcPct()) return spc.getSpcPct().getVal()*0.001;
+ else if (spc.isSetSpcPts()) return -spc.getSpcPts().getVal()*0.01;
+ else return 0;
+ }
+
+ /**
+ * Set the amount of vertical white space that will be present after the paragraph.
+ * This space is specified in either percentage or points:
+ * <p>
+ * If spaceAfter >= 0, then space is a percentage of normal line height.
+ * If spaceAfter < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ * Examples:
+ * <pre><code>
+ * // The paragraph will be formatted to have a spacing after the paragraph text.
+ * // The spacing will be 200% of the size of the largest text on each line
+ * paragraph.setSpaceAfter(200);
+ *
+ * // The spacing will be a size of 48 points
+ * paragraph.setSpaceAfter(-48.0);
+ * </code></pre>
+ *
+ * @param spaceAfter the vertical white space after the paragraph.
+ */
+ public void setSpaceAfter(double spaceAfter){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
+ if(spaceAfter >= 0) spc.addNewSpcPct().setVal((int)(spaceAfter*1000));
+ else spc.addNewSpcPts().setVal((int)(-spaceAfter*100));
+ pr.setSpcAft(spc);
+ }
+
+ /**
+ * The amount of vertical white space after the paragraph
+ * This may be specified in two different ways, percentage spacing and font point spacing:
+ * <p>
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * </p>
+ *
+ * @return the vertical white space after the paragraph
+ */
+ public double getSpaceAfter(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null || !pr.isSetSpcAft()) return 0; // TODO fetch from master
+
+ CTTextSpacing spc = pr.getSpcAft();
+ if(spc.isSetSpcPct()) return spc.getSpcPct().getVal()*0.001;
+ else if (spc.isSetSpcPts()) return -spc.getSpcPts().getVal()*0.01;
+ else return 0;
+ }
+
+ /**
+ * Specifies the particular level text properties that this paragraph will follow.
+ * The value for this attribute formats the text according to the corresponding level
+ * paragraph properties defined in the SlideMaster.
+ *
+ * @param level the level (0 ... 4)
+ */
+ public void setLevel(int level){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+
+ pr.setLvl(level);
+ }
+
+ /**
+ *
+ * @return the text level of this paragraph. Default is 0.
+ */
+ public int getLevel(){
+ CTTextParagraphProperties pr = _p.getPPr();
+ if(pr == null) return 0;
+
+ return pr.getLvl();
+
+ }
+
+ @Override
+ public String toString(){
+ return "[" + getClass() + "]" + getText();
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,202 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
+
+import java.awt.*;
+
+/**
+ * Represents a run of text within the containing text body. The run element is the
+ * lowest level text separation mechanism within a text body.
+ *
+ * @author Yegor Kozlov
+ */
+@Beta
+public class XSLFTextRun {
+ private final CTRegularTextRun _r;
+
+ XSLFTextRun(CTRegularTextRun r){
+ _r = r;
+ }
+
+ public String getText(){
+ return _r.getT();
+ }
+
+ public void setText(String text){
+ _r.setT(text);
+ }
+
+ public CTRegularTextRun getXmlObject(){
+ return _r;
+ }
+
+ public void setFontColor(Color color){
+ CTTextCharacterProperties rPr = getRpR();
+ CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
+ CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
+ clr.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});
+ }
+
+ /**
+ *
+ * @param fontSize font size in points.
+ * The value of <code>-1</code> unsets the Sz attribyte from the underlying xml bean
+ */
+ public void setFontSize(double fontSize){
+ CTTextCharacterProperties rPr = getRpR();
+ if(fontSize == -1.0) {
+ if(rPr.isSetSz()) rPr.unsetSz();
+ } else {
+ rPr.setSz((int)(100*fontSize));
+ }
+ }
+
+ /**
+ * @return font size in points or -1 if font size is not set.
+ */
+ public double getFontSize(){
+ if(!_r.isSetRPr()) return -1;
+
+ return _r.getRPr().getSz()*0.01;
+ }
+
+ /**
+ * Specifies the typeface, or name of the font that is to be used for this text run.
+ *
+ * @param typeface the font to apply to this text run.
+ * The value of <code>null</code> unsets the Typeface attrubute from the underlying xml.
+ */
+ public void setFontFamily(String typeface){
+ setFontFamily(typeface, (byte)-1, (byte)-1, false);
+ }
+
+ public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol){
+ CTTextCharacterProperties rPr = getRpR();
+
+ if(typeface == null){
+ if(rPr.isSetLatin()) rPr.unsetLatin();
+ if(rPr.isSetCs()) rPr.unsetCs();
+ if(rPr.isSetSym()) rPr.unsetSym();
+ } else {
+ if(isSymbol){
+ CTTextFont font = rPr.isSetSym() ? rPr.getSym() : rPr.addNewSym();
+ font.setTypeface(typeface);
+ } else {
+ CTTextFont latin = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin();
+ latin.setTypeface(typeface);
+ if(charset != -1) latin.setCharset(charset);
+ if(pictAndFamily != -1) latin.setPitchFamily(pictAndFamily);
+ }
+ }
+ }
+
+ /**
+ * @return font family or null if niot set
+ */
+ public String getFontFamily(){
+ if(!_r.isSetRPr() || !_r.getRPr().isSetLatin()) return null;
+
+ return _r.getRPr().getLatin().getTypeface();
+ }
+
+ /**
+ * Specifies whether a run of text will be formatted as strikethrough text.
+ *
+ * @param strike whether a run of text will be formatted as strikethrough text.
+ */
+ public void setStrikethrough(boolean strike){
+ getRpR().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);
+ }
+
+ /**
+ * @return whether a run of text will be formatted as strikethrough text. Default is false.
+ */
+ public boolean isStrikethrough(){
+ if(!_r.isSetRPr()) return false;
+
+ return _r.getRPr().getStrike() == STTextStrikeType.SNG_STRIKE;
+ }
+
+ /**
+ * Specifies whether this run of text will be formatted as bold text
+ *
+ * @param bold whether this run of text will be formatted as bold text
+ */
+ public void setBold(boolean bold){
+ getRpR().setB(bold);
+ }
+
+ /**
+ * @return whether this run of text is formatted as bold text
+ */
+ public boolean isBold(){
+ if(!_r.isSetRPr()) return false;
+
+ return _r.getRPr().getB();
+ }
+
+ /**
+ * @param italic whether this run of text is formatted as italic text
+ */
+ public void setItalic(boolean italic){
+ getRpR().setI(italic);
+ }
+
+ /**
+ * @return whether this run of text is formatted as italic text
+ */
+ public boolean isItalic(){
+ if(!_r.isSetRPr()) return false;
+
+ return _r.getRPr().getI();
+ }
+
+ /**
+ * @param underline whether this run of text is formatted as underlined text
+ */
+ public void setUnderline(boolean underline){
+ getRpR().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);
+ }
+
+ /**
+ * @return whether this run of text is formatted as underlined text
+ */
+ public boolean isUnderline(){
+ if(!_r.isSetRPr() || !_r.getRPr().isSetU()) return false;
+
+ return _r.getRPr().getU() != STTextUnderlineType.NONE;
+ }
+
+ protected CTTextCharacterProperties getRpR(){
+ return _r.isSetRPr() ? _r.getRPr() : _r.addNewRPr();
+ }
+
+ @Override
+ public String toString(){
+ return "[" + getClass() + "]" + getText();
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
------------------------------------------------------------------------------
svn:executable = *
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java Thu Aug 11 08:38:19 2011
@@ -41,7 +41,7 @@ public class XSLFTestDataSamples {
public static XMLSlideShow writeOutAndReadBack(XMLSlideShow doc) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
- doc._getXSLFSlideShow().write(baos);
+ doc.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return new XMLSlideShow(OPCPackage.open(bais));
} catch (Exception e) {
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,267 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFAutoShape extends TestCase {
+ public void testTextBodyProperies() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFAutoShape shape = slide.createAutoShape();
+ shape.addNewTextParagraph().addNewTextRun().setText("POI");
+
+ // margins
+ assertEquals(-1., shape.getMarginBottom());
+ assertEquals(-1., shape.getMarginTop());
+ assertEquals(-1., shape.getMarginLeft());
+ assertEquals(-1., shape.getMarginRight());
+
+ shape.setMarginBottom(1.0);
+ assertEquals(1.0, shape.getMarginBottom());
+ shape.setMarginTop(2.0);
+ assertEquals(2.0, shape.getMarginTop());
+ shape.setMarginLeft(3.0);
+ assertEquals(3.0, shape.getMarginLeft());
+ shape.setMarginRight(4.0);
+ assertEquals(4.0, shape.getMarginRight());
+
+ shape.setMarginBottom(0.0);
+ assertEquals(0.0, shape.getMarginBottom());
+ shape.setMarginTop(0.0);
+ assertEquals(0.0, shape.getMarginTop());
+ shape.setMarginLeft(0.0);
+ assertEquals(0.0, shape.getMarginLeft());
+ shape.setMarginRight(0.0);
+ assertEquals(0.0, shape.getMarginRight());
+
+ shape.setMarginBottom(-1);
+ assertEquals(-1., shape.getMarginBottom());
+ shape.setMarginTop(-1);
+ assertEquals(-1.0, shape.getMarginTop());
+ shape.setMarginLeft(-1);
+ assertEquals(-1.0, shape.getMarginLeft());
+ shape.setMarginRight(-1);
+ assertEquals(-1.0, shape.getMarginRight());
+
+ // shape
+ assertFalse(shape.getWordWrap());
+ shape.setWordWrap(true);
+ assertTrue(shape.getWordWrap());
+ shape.setWordWrap(false);
+ assertFalse(shape.getWordWrap());
+
+ // shape
+ assertEquals(TextAutofit.NORMAL, shape.getTextAutofit());
+ shape.setTextAutofit(TextAutofit.NONE);
+ assertEquals(TextAutofit.NONE, shape.getTextAutofit());
+ shape.setTextAutofit(TextAutofit.SHAPE);
+ assertEquals(TextAutofit.SHAPE, shape.getTextAutofit());
+ shape.setTextAutofit(TextAutofit.NORMAL);
+ assertEquals(TextAutofit.NORMAL, shape.getTextAutofit());
+
+ assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+ shape.setVerticalAlignment(VerticalAlignment.BOTTOM);
+ assertEquals(VerticalAlignment.BOTTOM, shape.getVerticalAlignment());
+ shape.setVerticalAlignment(VerticalAlignment.MIDDLE);
+ assertEquals(VerticalAlignment.MIDDLE, shape.getVerticalAlignment());
+ shape.setVerticalAlignment(null);
+ assertEquals(VerticalAlignment.TOP, shape.getVerticalAlignment());
+
+ assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+ shape.setTextDirection(TextDirection.VERTICAL);
+ assertEquals(TextDirection.VERTICAL, shape.getTextDirection());
+ shape.setTextDirection(null);
+ assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
+ }
+
+ public void testTextParagraph() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+ assertEquals(0, slide.getShapes().length);
+
+ XSLFAutoShape shape = slide.createAutoShape();
+ assertEquals(0, shape.getTextParagraphs().size());
+ XSLFTextParagraph p = shape.addNewTextParagraph();
+ assertEquals(1, shape.getTextParagraphs().size());
+
+ assertEquals(0., p.getIndent());
+ assertEquals(0., p.getLeftMargin());
+ assertEquals(100., p.getLineSpacing());
+ assertEquals(0., p.getSpaceAfter());
+ assertEquals(0., p.getSpaceBefore());
+ assertEquals(0, p.getLevel());
+
+ p.setIndent(2.0);
+ assertEquals(2.0, p.getIndent());
+ assertTrue(p.getXmlObject().getPPr().isSetIndent());
+ p.setIndent(-1);
+ assertEquals(0.0, p.getIndent());
+ assertFalse(p.getXmlObject().getPPr().isSetIndent());
+ p.setIndent(10.0);
+ assertEquals(10., p.getIndent());
+ assertTrue(p.getXmlObject().getPPr().isSetIndent());
+
+
+ assertFalse(p.getXmlObject().getPPr().isSetLvl());
+ p.setLevel(1);
+ assertEquals(1, p.getLevel());
+ assertTrue(p.getXmlObject().getPPr().isSetLvl());
+ p.setLevel(2);
+ assertEquals(2, p.getLevel());
+
+ p.setLeftMargin(2.0);
+ assertEquals(2.0, p.getLeftMargin());
+ assertTrue(p.getXmlObject().getPPr().isSetMarL());
+ p.setLeftMargin(10.0);
+ assertEquals(10., p.getLeftMargin());
+ assertEquals(Units.toEMU(10), p.getXmlObject().getPPr().getMarL());
+
+
+ assertFalse(p.getXmlObject().getPPr().isSetSpcAft());
+ p.setSpaceAfter(200);
+ assertEquals(200000, p.getXmlObject().getPPr().getSpcAft().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPts());
+ p.setSpaceAfter(100);
+ assertEquals(100000, p.getXmlObject().getPPr().getSpcAft().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPts());
+ p.setSpaceAfter(-20);
+ assertEquals(2000, p.getXmlObject().getPPr().getSpcAft().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPct());
+ p.setSpaceAfter(-10);
+ assertEquals(1000, p.getXmlObject().getPPr().getSpcAft().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcAft().isSetSpcPct());
+
+ assertFalse(p.getXmlObject().getPPr().isSetSpcBef());
+ p.setSpaceBefore(200);
+ assertEquals(200000, p.getXmlObject().getPPr().getSpcBef().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPts());
+ p.setSpaceBefore(100);
+ assertEquals(100000, p.getXmlObject().getPPr().getSpcBef().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPts());
+ p.setSpaceBefore(-20);
+ assertEquals(2000, p.getXmlObject().getPPr().getSpcBef().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPct());
+ p.setSpaceBefore(-10);
+ assertEquals(1000, p.getXmlObject().getPPr().getSpcBef().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getSpcBef().isSetSpcPct());
+
+ assertFalse(p.getXmlObject().getPPr().isSetLnSpc());
+ p.setLineSpacing(200);
+ assertEquals(200000, p.getXmlObject().getPPr().getLnSpc().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPts());
+ p.setLineSpacing(100);
+ assertEquals(100000, p.getXmlObject().getPPr().getLnSpc().getSpcPct().getVal());
+ assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPts());
+ p.setLineSpacing(-20);
+ assertEquals(2000, p.getXmlObject().getPPr().getLnSpc().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPct());
+ p.setLineSpacing(-10);
+ assertEquals(1000, p.getXmlObject().getPPr().getLnSpc().getSpcPts().getVal());
+ assertFalse(p.getXmlObject().getPPr().getLnSpc().isSetSpcPct());
+
+ assertFalse(p.getXmlObject().getPPr().isSetAlgn());
+ assertEquals(TextAlign.LEFT, p.getTextAlign());
+ p.setTextAlign(TextAlign.LEFT);
+ assertTrue(p.getXmlObject().getPPr().isSetAlgn());
+ assertEquals(TextAlign.LEFT, p.getTextAlign());
+ p.setTextAlign(TextAlign.RIGHT);
+ assertEquals(TextAlign.RIGHT, p.getTextAlign());
+ p.setTextAlign(TextAlign.JUSTIFY);
+ assertEquals(TextAlign.JUSTIFY, p.getTextAlign());
+ p.setTextAlign(null);
+ assertEquals(TextAlign.LEFT, p.getTextAlign());
+ assertFalse(p.getXmlObject().getPPr().isSetAlgn());
+ }
+
+ public void testTextRun() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFAutoShape shape = slide.createAutoShape();
+ assertEquals(0, shape.getTextParagraphs().size());
+ XSLFTextParagraph p = shape.addNewTextParagraph();
+ assertEquals(1, shape.getTextParagraphs().size());
+ assertEquals(0, p.getTextRuns().size());
+ XSLFTextRun r = p.addNewTextRun();
+ assertEquals(1, p.getTextRuns().size());
+ assertSame(r, p.getTextRuns().get(0));
+
+ assertEquals(-1.0, r.getFontSize());
+ assertFalse(r.getXmlObject().isSetRPr());
+ r.setFontSize(10.0);
+ assertTrue(r.getXmlObject().isSetRPr());
+ assertEquals(1000, r.getXmlObject().getRPr().getSz());
+ r.setFontSize(12.5);
+ assertEquals(1250, r.getXmlObject().getRPr().getSz());
+ r.setFontSize(-1);
+ assertFalse(r.getXmlObject().getRPr().isSetSz());
+
+ assertFalse(r.getXmlObject().getRPr().isSetLatin());
+ assertNull(r.getFontFamily());
+ r.setFontFamily(null);
+ assertNull(r.getFontFamily());
+ r.setFontFamily("Arial");
+ assertEquals("Arial", r.getFontFamily());
+ assertEquals("Arial", r.getXmlObject().getRPr().getLatin().getTypeface());
+ r.setFontFamily("Symbol");
+ assertEquals("Symbol", r.getFontFamily());
+ assertEquals("Symbol", r.getXmlObject().getRPr().getLatin().getTypeface());
+ r.setFontFamily(null);
+ assertNull(r.getFontFamily());
+ assertFalse(r.getXmlObject().getRPr().isSetLatin());
+
+ assertFalse(r.isStrikethrough());
+ assertFalse(r.getXmlObject().getRPr().isSetStrike());
+ r.setStrikethrough(true);
+ assertTrue(r.isStrikethrough());
+ assertEquals(STTextStrikeType.SNG_STRIKE, r.getXmlObject().getRPr().getStrike());
+
+ assertFalse(r.isBold());
+ assertFalse(r.getXmlObject().getRPr().isSetB());
+ r.setBold(true);
+ assertTrue(r.isBold());
+ assertEquals(true, r.getXmlObject().getRPr().getB());
+
+ assertFalse(r.isItalic());
+ assertFalse(r.getXmlObject().getRPr().isSetI());
+ r.setItalic(true);
+ assertTrue(r.isItalic());
+ assertEquals(true, r.getXmlObject().getRPr().getI());
+
+ assertFalse(r.isUnderline());
+ assertFalse(r.getXmlObject().getRPr().isSetU());
+ r.setUnderline(true);
+ assertTrue(r.isUnderline());
+ assertEquals(STTextUnderlineType.SNG, r.getXmlObject().getRPr().getU());
+
+ r.setText("Apache");
+ assertEquals("Apache", r.getText());
+ r.setText("POI");
+ assertEquals("POI", r.getText());
+ r.setText(null);
+ assertNull(r.getText());
+ }
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,117 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.util.Units;
+import org.apache.poi.xslf.usermodel.LineCap;
+import org.apache.poi.xslf.usermodel.LineDash;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;
+
+import java.awt.*;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFConnectorShape extends TestCase {
+
+ public void testLineDecorations() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFConnectorShape shape = slide.createConnector();
+ assertEquals(1, slide.getShapes().length);
+
+ assertFalse(shape.getSpPr().getLn().isSetHeadEnd());
+ assertFalse(shape.getSpPr().getLn().isSetTailEnd());
+
+ // line decorations
+ assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
+ assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
+ shape.setLineHeadDecoration(null);
+ shape.setLineTailDecoration(null);
+ assertEquals(LineDecoration.NONE, shape.getLineHeadDecoration());
+ assertEquals(LineDecoration.NONE, shape.getLineTailDecoration());
+ assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetType());
+ assertFalse(shape.getSpPr().getLn().getTailEnd().isSetType());
+
+ shape.setLineHeadDecoration(LineDecoration.ARROW);
+ shape.setLineTailDecoration(LineDecoration.DIAMOND);
+ assertEquals(LineDecoration.ARROW, shape.getLineHeadDecoration());
+ assertEquals(LineDecoration.DIAMOND, shape.getLineTailDecoration());
+ assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getHeadEnd().getType());
+ assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getTailEnd().getType());
+
+ shape.setLineHeadDecoration(LineDecoration.DIAMOND);
+ shape.setLineTailDecoration(LineDecoration.ARROW);
+ assertEquals(LineDecoration.DIAMOND, shape.getLineHeadDecoration());
+ assertEquals(LineDecoration.ARROW, shape.getLineTailDecoration());
+ assertEquals(STLineEndType.DIAMOND, shape.getSpPr().getLn().getHeadEnd().getType());
+ assertEquals(STLineEndType.ARROW, shape.getSpPr().getLn().getTailEnd().getType());
+
+ // line end width
+ assertEquals(null, shape.getLineHeadWidth());
+ assertEquals(null, shape.getLineTailWidth());
+ shape.setLineHeadWidth(null);
+ shape.setLineHeadWidth(null);
+ assertEquals(null, shape.getLineHeadWidth());
+ assertEquals(null, shape.getLineTailWidth());
+ assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetW());
+ assertFalse(shape.getSpPr().getLn().getTailEnd().isSetW());
+ shape.setLineHeadWidth(LineEndWidth.LARGE);
+ shape.setLineTailWidth(LineEndWidth.MEDIUM);
+ assertEquals(LineEndWidth.LARGE, shape.getLineHeadWidth());
+ assertEquals(LineEndWidth.MEDIUM, shape.getLineTailWidth());
+ assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getHeadEnd().getW());
+ assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getTailEnd().getW());
+ shape.setLineHeadWidth(LineEndWidth.MEDIUM);
+ shape.setLineTailWidth(LineEndWidth.LARGE);
+ assertEquals(LineEndWidth.MEDIUM, shape.getLineHeadWidth());
+ assertEquals(LineEndWidth.LARGE, shape.getLineTailWidth());
+ assertEquals(STLineEndWidth.MED, shape.getSpPr().getLn().getHeadEnd().getW());
+ assertEquals(STLineEndWidth.LG, shape.getSpPr().getLn().getTailEnd().getW());
+
+ // line end length
+ assertEquals(null, shape.getLineHeadLength());
+ assertEquals(null, shape.getLineTailLength());
+ shape.setLineHeadLength(null);
+ shape.setLineTailLength(null);
+ assertEquals(null, shape.getLineHeadLength());
+ assertEquals(null, shape.getLineTailLength());
+ assertFalse(shape.getSpPr().getLn().getHeadEnd().isSetLen());
+ assertFalse(shape.getSpPr().getLn().getTailEnd().isSetLen());
+ shape.setLineHeadLength(LineEndLength.LARGE);
+ shape.setLineTailLength(LineEndLength.MEDIUM);
+ assertEquals(LineEndLength.LARGE, shape.getLineHeadLength());
+ assertEquals(LineEndLength.MEDIUM, shape.getLineTailLength());
+ assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getHeadEnd().getLen());
+ assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getTailEnd().getLen());
+ shape.setLineHeadLength(LineEndLength.MEDIUM);
+ shape.setLineTailLength(LineEndLength.LARGE);
+ assertEquals(LineEndLength.MEDIUM, shape.getLineHeadLength());
+ assertEquals(LineEndLength.LARGE, shape.getLineTailLength());
+ assertEquals(STLineEndLength.MED, shape.getSpPr().getLn().getHeadEnd().getLen());
+ assertEquals(STLineEndLength.LG, shape.getSpPr().getLn().getTailEnd().getLen());
+
+ }
+
+}
\ No newline at end of file
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,50 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFFreeformShape extends TestCase {
+
+ public void testSetPath() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+ XSLFFreeformShape shape1 = slide.createFreeform();
+ // comples path consisting of a rectangle and an ellipse inside it
+ GeneralPath path1 = new GeneralPath(new Rectangle(150, 150, 300, 300));
+ path1.append(new Ellipse2D.Double(200, 200, 100, 50), false);
+ shape1.setPath(path1);
+
+ GeneralPath path2 = shape1.getPath();
+
+ // YK: how to compare the original path1 and the value returned by XSLFFreeformShape.getPath() ?
+ // one way is to create another XSLFFreeformShape from path2 and compare the resulting xml
+ assertEquals(path1.getBounds2D(), path2.getBounds2D());
+
+ XSLFFreeformShape shape2 = slide.createFreeform();
+ shape2.setPath(path2);
+
+ assertEquals(shape1.getSpPr().getCustGeom().toString(), shape2.getSpPr().getCustGeom().toString());
+ }
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,99 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFGroupShape extends TestCase {
+
+ public void testCreateShapes() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ ppt.setPageSize(new Dimension(792, 612));
+
+ XSLFGroupShape group = slide.createGroup();
+ assertEquals(1, slide.getShapes().length);
+
+ Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);
+ group.setInteriorAnchor(interior);
+ assertEquals(interior, group.getInteriorAnchor());
+
+ Rectangle2D anchor = new Rectangle2D.Double(0, 0, 792, 612);
+ group.setAnchor(anchor);
+ assertEquals(anchor, group.getAnchor());
+
+ assertEquals(0, group.getShapes().length);
+
+ XSLFTextBox shape1 = group.createTextBox();
+ assertEquals(1, group.getShapes().length);
+ assertSame(shape1, group.getShapes()[0]);
+ assertEquals(3, shape1.getShapeId());
+
+ XSLFAutoShape shape2 = group.createAutoShape();
+ assertEquals(2, group.getShapes().length);
+ assertSame(shape1, group.getShapes()[0]);
+ assertSame(shape2, group.getShapes()[1]);
+ assertEquals(4, shape2.getShapeId());
+
+ XSLFConnectorShape shape3 = group.createConnector();
+ assertEquals(3, group.getShapes().length);
+ assertSame(shape3, group.getShapes()[2]);
+ assertEquals(5, shape3.getShapeId());
+
+ XSLFGroupShape shape4 = group.createGroup();
+ assertEquals(4, group.getShapes().length);
+ assertSame(shape4, group.getShapes()[3]);
+ assertEquals(6, shape4.getShapeId());
+
+ group.removeShape(shape2);
+ assertEquals(3, group.getShapes().length);
+ assertSame(shape1, group.getShapes()[0]);
+ assertSame(shape3, group.getShapes()[1]);
+ assertSame(shape4, group.getShapes()[2]);
+
+ group.removeShape(shape3);
+ assertEquals(2, group.getShapes().length);
+ assertSame(shape1, group.getShapes()[0]);
+ assertSame(shape4, group.getShapes()[1]);
+
+ group.removeShape(shape1);
+ group.removeShape(shape4);
+ assertEquals(0, group.getShapes().length);
+ }
+
+ public void testRemoveShapes() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFGroupShape group1 = slide.createGroup();
+ group1.createTextBox();
+ XSLFGroupShape group2 = slide.createGroup();
+ group2.createTextBox();
+ XSLFGroupShape group3 = slide.createGroup();
+ slide.removeShape(group1);
+ slide.removeShape(group2);
+ slide.removeShape(group3);
+
+ }
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,65 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.util.*;
+import java.util.List;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFPictureShape extends TestCase {
+
+ public void testCreate() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ assertEquals(0, ppt.getAllPictures().size());
+ byte[] data1 = new byte[100];
+ int idx1 = ppt.addPicture(data1, XSLFPictureData.PICTURE_TYPE_JPEG);
+ assertEquals(0, idx1);
+ assertEquals(1, ppt.getAllPictures().size());
+
+ XSLFSlide slide = ppt.createSlide();
+ XSLFPictureShape shape1 = slide.createPicture(idx1);
+ assertNotNull(shape1.getPictureData());
+ assertTrue(Arrays.equals(data1, shape1.getPictureData().getData()));
+
+ byte[] data2 = new byte[200];
+ int idx2 = ppt.addPicture(data2, XSLFPictureData.PICTURE_TYPE_PNG);
+ XSLFPictureShape shape2 = slide.createPicture(idx2);
+ assertNotNull(shape2.getPictureData());
+ assertEquals(1, idx2);
+ assertEquals(2, ppt.getAllPictures().size());
+ assertTrue(Arrays.equals(data2, shape2.getPictureData().getData()));
+
+ ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+ List<XSLFPictureData> pics = ppt.getAllPictures();
+ assertEquals(2, pics.size());
+ assertTrue(Arrays.equals(data1, pics.get(0).getData()));
+ assertTrue(Arrays.equals(data2, pics.get(1).getData()));
+
+ XSLFShape[] shapes = ppt.getSlides()[0].getShapes();
+ assertTrue(Arrays.equals(data1, ((XSLFPictureShape)shapes[0]).getPictureData().getData()));
+ assertTrue(Arrays.equals(data2, ((XSLFPictureShape)shapes[1]).getPictureData().getData()));
+ }
+}
\ No newline at end of file
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,101 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
+
+import java.util.List;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFShape extends TestCase {
+
+ public void testReadTextShapes() {
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+ XSLFSlide[] slides = ppt.getSlides();
+ assertEquals(3, slides.length);
+
+ XSLFSlide slide1 = slides[0];
+ XSLFShape[] shapes1 = slide1.getShapes();
+ assertEquals(7, shapes1.length);
+ assertEquals("TextBox 3", shapes1[0].getShapeName());
+ XSLFAutoShape sh0 = (XSLFAutoShape) shapes1[0];
+ assertEquals("Learning PPTX", sh0.getText());
+ List<XSLFTextParagraph> paragraphs0 = sh0.getTextParagraphs();
+ assertEquals(1, paragraphs0.size());
+ XSLFTextParagraph p0 = paragraphs0.get(0);
+ assertEquals("Learning PPTX", p0.getText());
+ assertEquals(1, p0.getTextRuns().size());
+ XSLFTextRun r0 = p0.getTextRuns().get(0);
+ assertEquals("Learning PPTX", r0.getText());
+
+ XSLFSlide slide2 = slides[1];
+ XSLFShape[] shapes2 = slide2.getShapes();
+ assertTrue(shapes2[0] instanceof XSLFAutoShape);
+ assertEquals("PPTX Title", ((XSLFAutoShape) shapes2[0]).getText());
+ XSLFAutoShape sh1 = (XSLFAutoShape) shapes2[0];
+ List<XSLFTextParagraph> paragraphs1 = sh1.getTextParagraphs();
+ assertEquals(1, paragraphs1.size());
+ XSLFTextParagraph p1 = paragraphs1.get(0);
+ assertEquals("PPTX Title", p1.getText());
+ List<XSLFTextRun> r2 = paragraphs1.get(0).getTextRuns();
+ assertEquals(2, r2.size());
+ assertEquals("PPTX ", r2.get(0).getText());
+ assertEquals("Title", r2.get(1).getText());
+ // Title is underlined
+ assertEquals(STTextUnderlineType.SNG, r2.get(1).getXmlObject().getRPr().getU());
+
+
+ assertTrue(shapes2[1] instanceof XSLFAutoShape);
+ assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape) shapes2[1]).getText());
+ XSLFAutoShape sh2 = (XSLFAutoShape) shapes2[1];
+ List<XSLFTextParagraph> paragraphs2 = sh2.getTextParagraphs();
+ assertEquals(2, paragraphs2.size());
+ assertEquals("Subtitle", paragraphs2.get(0).getText());
+ assertEquals("And second line", paragraphs2.get(1).getText());
+
+ assertEquals(1, paragraphs2.get(0).getTextRuns().size());
+ assertEquals(1, paragraphs2.get(1).getTextRuns().size());
+
+ assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getText());
+ assertTrue(paragraphs2.get(0).getTextRuns().get(0).getXmlObject().getRPr().getB());
+ assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getText());
+ }
+
+ public void testCreateShapes() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+ assertEquals(0, slide.getShapes().length);
+
+ XSLFTextBox textBox = slide.createTextBox();
+
+ assertEquals(1, slide.getShapes().length);
+ assertSame(textBox, slide.getShapes()[0]);
+
+ assertEquals("", textBox.getText());
+ assertEquals(0, textBox.getTextParagraphs().size());
+ textBox.addNewTextParagraph().addNewTextRun().setText("Apache");
+ textBox.addNewTextParagraph().addNewTextRun().setText("POI");
+ assertEquals("Apache\nPOI", textBox.getText());
+ assertEquals(2, textBox.getTextParagraphs().size());
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,66 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+
+/**
+ * test common properties for sheets (slides, masters, layouts, etc.)
+ *
+ * @author Yegor Kozlov
+ */
+public class TestXSLFSheet extends TestCase {
+ public void testCreateShapes(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+ assertEquals(0, slide.getShapes().length);
+
+ XSLFSimpleShape shape1 = slide.createAutoShape();
+ assertEquals(1, slide.getShapes().length);
+ assertSame(shape1, slide.getShapes()[0]);
+
+ XSLFTextBox shape2 = slide.createTextBox();
+ assertEquals(2, slide.getShapes().length);
+ assertSame(shape1, slide.getShapes()[0]);
+ assertSame(shape2, slide.getShapes()[1]);
+
+ XSLFConnectorShape shape3 = slide.createConnector();
+ assertEquals(3, slide.getShapes().length);
+ assertSame(shape1, slide.getShapes()[0]);
+ assertSame(shape2, slide.getShapes()[1]);
+ assertSame(shape3, slide.getShapes()[2]);
+
+ XSLFGroupShape shape4 = slide.createGroup();
+ assertEquals(4, slide.getShapes().length);
+ assertSame(shape1, slide.getShapes()[0]);
+ assertSame(shape2, slide.getShapes()[1]);
+ assertSame(shape3, slide.getShapes()[2]);
+ assertSame(shape4, slide.getShapes()[3]);
+
+ ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+ slide = ppt.getSlides()[0];
+ XSLFShape[] shapes = slide.getShapes();
+ assertEquals(4, shapes.length);
+
+ assertTrue(shapes[0] instanceof XSLFAutoShape);
+ assertTrue(shapes[1] instanceof XSLFTextBox);
+ assertTrue(shapes[2] instanceof XSLFConnectorShape);
+ assertTrue(shapes[3] instanceof XSLFGroupShape);
+ }
+}
\ No newline at end of file
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,132 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.util.Units;
+import org.apache.poi.xslf.usermodel.LineCap;
+import org.apache.poi.xslf.usermodel.LineDash;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
+
+import java.awt.*;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFSimpleShape extends TestCase {
+ public void testLineStyles() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFSimpleShape shape = slide.createAutoShape();
+ assertEquals(1, slide.getShapes().length);
+ // line properties are not set by default
+ assertFalse(shape.getSpPr().isSetLn());
+
+ assertEquals(0., shape.getLineWidth());
+ assertEquals(null, shape.getLineColor());
+ assertEquals(null, shape.getLineDash());
+ assertEquals(null, shape.getLineCap());
+
+ shape.setLineWidth(0);
+ shape.setLineColor(null);
+ shape.setLineDash(null);
+ shape.setLineCap(null);
+
+ // still no line properties
+ assertFalse(shape.getSpPr().isSetLn());
+
+ // line width
+ shape.setLineWidth(1.0);
+ assertEquals(1.0, shape.getLineWidth());
+ assertEquals(Units.EMU_PER_POINT, shape.getSpPr().getLn().getW());
+ shape.setLineWidth(5.5);
+ assertEquals(5.5, shape.getLineWidth());
+ assertEquals(Units.toEMU(5.5), shape.getSpPr().getLn().getW());
+ shape.setLineWidth(0.0);
+ // setting line width to zero unsets the W attribute
+ assertFalse(shape.getSpPr().getLn().isSetW());
+
+ // line cap
+ shape.setLineCap(LineCap.FLAT);
+ assertEquals(LineCap.FLAT, shape.getLineCap());
+ assertEquals(STLineCap.FLAT, shape.getSpPr().getLn().getCap());
+ shape.setLineCap(LineCap.SQUARE);
+ assertEquals(LineCap.SQUARE, shape.getLineCap());
+ assertEquals(STLineCap.SQ, shape.getSpPr().getLn().getCap());
+ shape.setLineCap(LineCap.ROUND);
+ assertEquals(LineCap.ROUND, shape.getLineCap());
+ assertEquals(STLineCap.RND, shape.getSpPr().getLn().getCap());
+ shape.setLineCap(null);
+ // setting cap to null unsets the Cap attribute
+ assertFalse(shape.getSpPr().getLn().isSetCap());
+
+ // line dash
+ shape.setLineDash(LineDash.SOLID);
+ assertEquals(LineDash.SOLID, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.SOLID, shape.getSpPr().getLn().getPrstDash().getVal());
+ shape.setLineDash(LineDash.DASH_DOT);
+ assertEquals(LineDash.DASH_DOT, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.DASH_DOT, shape.getSpPr().getLn().getPrstDash().getVal());
+ shape.setLineDash(LineDash.LG_DASH_DOT);
+ assertEquals(LineDash.LG_DASH_DOT, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.LG_DASH_DOT, shape.getSpPr().getLn().getPrstDash().getVal());
+ shape.setLineDash(null);
+ // setting dash width to null unsets the Dash element
+ assertFalse(shape.getSpPr().getLn().isSetPrstDash());
+
+ // line color
+ assertFalse(shape.getSpPr().getLn().isSetSolidFill());
+ shape.setLineColor(Color.RED);
+ assertEquals(Color.RED, shape.getLineColor());
+ assertTrue(shape.getSpPr().getLn().isSetSolidFill());
+ shape.setLineColor(Color.BLUE);
+ assertEquals(Color.BLUE, shape.getLineColor());
+ assertTrue(shape.getSpPr().getLn().isSetSolidFill());
+ shape.setLineColor(null);
+ assertEquals(null, shape.getLineColor());
+ // setting dash width to null unsets the SolidFill element
+ assertFalse(shape.getSpPr().getLn().isSetSolidFill());
+ }
+
+ public void testFill() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFAutoShape shape = slide.createAutoShape();
+ // line properties are not set by default
+ assertFalse(shape.getSpPr().isSetSolidFill());
+
+ assertNull(shape.getFillColor());
+ shape.setFillColor(null);
+ assertNull(shape.getFillColor());
+ assertFalse(shape.getSpPr().isSetSolidFill());
+
+ shape.setFillColor(Color.RED);
+ assertEquals(Color.RED, shape.getFillColor());
+ shape.setFillColor(Color.DARK_GRAY);
+ assertEquals(Color.DARK_GRAY, shape.getFillColor());
+ assertTrue(shape.getSpPr().isSetSolidFill());
+
+ shape.setFillColor(null);
+ assertNull(shape.getFillColor());
+ assertFalse(shape.getSpPr().isSetSolidFill());
+ }
+
+}
\ No newline at end of file
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,102 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.apache.poi.POIXMLDocumentPart;
+
+import java.util.List;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFSlide extends TestCase {
+ public void testReadShapes(){
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+ XSLFSlide[] slides = ppt.getSlides();
+ assertEquals(3, slides.length);
+
+ XSLFSlide slide1 = slides[0];
+ XSLFShape[] shapes1 = slide1.getShapes();
+ assertEquals(7, shapes1.length);
+ assertEquals("TextBox 3", shapes1[0].getShapeName());
+ assertTrue(shapes1[0] instanceof XSLFTextBox);
+ XSLFAutoShape sh0 = (XSLFAutoShape)shapes1[0];
+ assertEquals("Learning PPTX", sh0.getText());
+
+
+ assertEquals("Straight Connector 5", shapes1[1].getShapeName());
+ assertTrue(shapes1[1] instanceof XSLFConnectorShape);
+
+ assertEquals("Freeform 6", shapes1[2].getShapeName());
+ assertTrue(shapes1[2] instanceof XSLFFreeformShape);
+ XSLFAutoShape sh2 = (XSLFAutoShape)shapes1[2];
+ assertEquals("Cloud", sh2.getText());
+
+ assertEquals("Picture 1", shapes1[3].getShapeName());
+ assertTrue(shapes1[3] instanceof XSLFPictureShape);
+
+ assertEquals("Table 2", shapes1[4].getShapeName());
+ assertTrue(shapes1[4] instanceof XSLFGraphicFrame);
+
+ assertEquals("Straight Arrow Connector 7", shapes1[5].getShapeName());
+ assertTrue(shapes1[5] instanceof XSLFConnectorShape);
+
+ assertEquals("Elbow Connector 9", shapes1[6].getShapeName());
+ assertTrue(shapes1[6] instanceof XSLFConnectorShape);
+
+ // titles on slide2
+ XSLFSlide slide2 = slides[1];
+ XSLFShape[] shapes2 = slide2.getShapes();
+ assertEquals(2, shapes2.length);
+ assertTrue(shapes2[0] instanceof XSLFAutoShape);
+ assertEquals("PPTX Title", ((XSLFAutoShape)shapes2[0]).getText());
+ assertTrue(shapes2[1] instanceof XSLFAutoShape);
+ assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape)shapes2[1]).getText());
+
+ // group shape on slide3
+ XSLFSlide slide3 = slides[2];
+ XSLFShape[] shapes3 = slide3.getShapes();
+ assertEquals(1, shapes3.length);
+ assertTrue(shapes3[0] instanceof XSLFGroupShape);
+ XSLFShape[] groupShapes = ((XSLFGroupShape)shapes3[0]).getShapes();
+ assertEquals(3, groupShapes.length);
+ assertTrue(groupShapes[0] instanceof XSLFAutoShape);
+ assertEquals("Rectangle 1", groupShapes[0].getShapeName());
+
+ assertTrue(groupShapes[1] instanceof XSLFAutoShape);
+ assertEquals("Oval 2", groupShapes[1].getShapeName());
+
+ assertTrue(groupShapes[2] instanceof XSLFAutoShape);
+ assertEquals("Right Arrow 3", groupShapes[2].getShapeName());
+ }
+
+ public void testCreateSlide(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ assertEquals(0, ppt.getSlides().length);
+
+ XSLFSlide slide = ppt.createSlide();
+ assertTrue(slide.getFollowMasterBackground());
+ slide.setFollowMasterBackground(false);
+ assertFalse(slide.getFollowMasterBackground());
+ slide.setFollowMasterBackground(true);
+ assertTrue(slide.getFollowMasterBackground());
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,108 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+import java.awt.Dimension;
+import java.util.List;
+
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.xslf.XSLFTestDataSamples;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFSlideShow extends TestCase {
+ public void testCreateSlide(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ assertEquals(0, ppt.getSlides().length);
+
+ XSLFSlide slide1 = ppt.createSlide();
+ assertEquals(1, ppt.getSlides().length);
+ assertSame(slide1, ppt.getSlides()[0]);
+
+ List<POIXMLDocumentPart> rels = slide1.getRelations();
+ assertEquals(1, rels.size());
+ assertEquals(slide1.getMasterSheet().getLayout("blank"), rels.get(0));
+
+ XSLFSlide slide2 = ppt.createSlide();
+ assertEquals(2, ppt.getSlides().length);
+ assertSame(slide2, ppt.getSlides()[1]);
+
+ ppt.setSlideOrder(slide2, 0);
+ assertSame(slide2, ppt.getSlides()[0]);
+ assertSame(slide1, ppt.getSlides()[1]);
+
+ ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+ assertEquals(2, ppt.getSlides().length);
+ rels = ppt.getSlides()[0].getRelations();
+ }
+
+ public void testRemoveSlide(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ assertEquals(0, ppt.getSlides().length);
+
+ XSLFSlide slide1 = ppt.createSlide();
+ XSLFSlide slide2 = ppt.createSlide();
+
+ assertEquals(2, ppt.getSlides().length);
+ assertSame(slide1, ppt.getSlides()[0]);
+ assertSame(slide2, ppt.getSlides()[1]);
+
+ XSLFSlide removedSlide = ppt.removeSlide(0);
+ assertSame(slide1, removedSlide);
+
+ assertEquals(1, ppt.getSlides().length);
+ assertSame(slide2, ppt.getSlides()[0]);
+
+ ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+ assertEquals(1, ppt.getSlides().length);
+ }
+
+ public void testDimension(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ Dimension sz = ppt.getPageSize();
+ assertEquals(720, sz.width);
+ assertEquals(540, sz.height);
+ ppt.setPageSize(new Dimension(792, 612));
+ sz = ppt.getPageSize();
+ assertEquals(792, sz.width);
+ assertEquals(612, sz.height);
+ }
+
+ public void testSlideMasters(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlideMaster[] masters = ppt.getSlideMasters();
+ assertEquals(1, masters.length);
+
+ XSLFSlide slide = ppt.createSlide();
+ assertSame(masters[0], slide.getMasterSheet());
+ }
+
+ public void testSlideLayout(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlideMaster[] masters = ppt.getSlideMasters();
+ assertEquals(1, masters.length);
+
+ XSLFSlide slide = ppt.createSlide();
+ XSLFSlideLayout layout = slide.getSlideLayout();
+ assertNotNull(layout);
+
+ assertSame(masters[0], layout.getSlideMaster());
+ }
+}
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,37 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFTextBox extends TestCase {
+
+ public void testPlaceholder() {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+
+ XSLFTextBox shape = slide.createTextBox();
+ assertNull(shape.getPlaceholder());
+ shape.setPlaceholder(Placeholder.TITLE);
+ assertEquals(Placeholder.TITLE, shape.getPlaceholder());
+ shape.setPlaceholder(null);
+ assertNull(shape.getPlaceholder());
+ }
+}
\ No newline at end of file
Added: poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/empty.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/empty.pptx?rev=1156539&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/empty.pptx
------------------------------------------------------------------------------
svn:executable = *
Propchange: poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/empty.pptx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: poi/trunk/test-data/slideshow/shapes.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/shapes.pptx?rev=1156539&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/slideshow/shapes.pptx
------------------------------------------------------------------------------
svn:executable = *
Propchange: poi/trunk/test-data/slideshow/shapes.pptx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org