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 e78acefb8..b2d595374 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -117,7 +117,8 @@ public class XSLFTextParagraph implements Iterable{ public XSLFTextRun addNewTextRun(){ CTRegularTextRun r = _p.addNewR(); - r.addNewRPr(); + CTTextCharacterProperties rPr = r.addNewRPr(); + rPr.setLang("en-US"); XSLFTextRun run = new XSLFTextRun(r, this); _runs.add(run); return run; 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 cd94cdd0b..ff54d5ceb 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java @@ -167,6 +167,10 @@ public class XSLFTextRun { if(fontSize == -1.0) { if(rPr.isSetSz()) rPr.unsetSz(); } else { + if(fontSize < 1.0) { + throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize); + } + rPr.setSz((int)(100*fontSize)); } } @@ -212,6 +216,24 @@ public class XSLFTextRun { return fetcher.getValue() == null ? 0 : fetcher.getValue(); } + /** + * Set the spacing between characters within a text run. + *

+ * The spacing is specified in points. Positive values will cause the text to expand, + * negative values to condense. + *

+ * + * @param spc character spacing in points. + */ + public void setCharacterSpacing(double spc){ + CTTextCharacterProperties rPr = getRpR(); + if(spc == 0.0) { + if(rPr.isSetSpc()) rPr.unsetSpc(); + } else { + rPr.setSpc((int)(100*spc)); + } + } + /** * Specifies the typeface, or name of the font that is to be used for this text run. * 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 50d4c812b..19eee771f 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java @@ -27,11 +27,7 @@ import java.awt.image.BufferedImage; import java.util.List; /** - * Created by IntelliJ IDEA. - * User: yegor - * Date: Nov 10, 2011 - * Time: 1:43:25 PM - * To change this template use File | Settings | File Templates. + * @author Yegor Kozlov */ public class TestXSLFTextParagraph extends TestCase { private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class); diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java new file mode 100644 index 000000000..3ee2616b0 --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java @@ -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.util.POILogFactory; +import org.apache.poi.util.POILogger; +import org.apache.poi.xslf.XSLFTestDataSamples; + +import java.awt.*; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.util.List; + +/** + * @author Yegor Kozlov + */ +public class TestXSLFTextRun extends TestCase { + + public void testRunProperties(){ + XMLSlideShow ppt = new XMLSlideShow(); + XSLFSlide slide = ppt.createSlide(); + XSLFTextShape sh = slide.createAutoShape(); + + XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun(); + assertEquals("en-US", r.getRpR().getLang()); + + assertEquals(0., r.getCharacterSpacing()); + r.setCharacterSpacing(3); + assertEquals(3., r.getCharacterSpacing()); + r.setCharacterSpacing(-3); + assertEquals(-3., r.getCharacterSpacing()); + r.setCharacterSpacing(0); + assertEquals(0., r.getCharacterSpacing()); + assertFalse(r.getRpR().isSetSpc()); + + assertEquals(Color.black, r.getFontColor()); + r.setFontColor(Color.red); + assertEquals(Color.red, r.getFontColor()); + + assertEquals("Calibri", r.getFontFamily()); + r.setFontFamily("Arial"); + assertEquals("Arial", r.getFontFamily()); + + assertEquals(18.0, r.getFontSize()); + r.setFontSize(13.0); + assertEquals(13.0, r.getFontSize()); + + } +}