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
This commit is contained in:
Yegor Kozlov 2012-01-19 08:09:26 +00:00
parent 8259a18fac
commit 49a75b1031
3 changed files with 136 additions and 7 deletions

View File

@ -211,6 +211,11 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
c.setChar(str);
}
/**
*
* @return the color of bullet characters within a given paragraph.
* A <code>null</code> value means to use the text font color.
*/
public Color getBulletFontColor(){
final XSLFTheme theme = getParentShape().getSheet().getTheme();
ParagraphPropertyFetcher<Color> fetcher = new ParagraphPropertyFetcher<Color>(getLevel()){
@ -227,6 +232,11 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
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<XSLFTextRun>{
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:
* <p>
* If bulletSize >= 0, then bulletSize is a percentage of the font size.
* If bulletSize < 0, then it specifies the size in points
* </p>
*
* @return the bullet size
*/
public double getBulletFontSize(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
@ -252,12 +272,29 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
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:
* <p>
* If bulletSize >= 0, then bulletSize is a percentage of the font size.
* If bulletSize < 0, then it specifies the size in points
* </p>
*
* @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<XSLFTextRun>{
*/
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<XSLFTextRun>{
/**
*
* @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<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){

View File

@ -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);
}
}

View File

@ -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());
}
}