mirror of https://github.com/apache/poi.git
support kerning in XSLF text runs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1235668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1df1a286b9
commit
97d0beab68
|
@ -117,7 +117,8 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
|
||||||
|
|
||||||
public XSLFTextRun addNewTextRun(){
|
public XSLFTextRun addNewTextRun(){
|
||||||
CTRegularTextRun r = _p.addNewR();
|
CTRegularTextRun r = _p.addNewR();
|
||||||
r.addNewRPr();
|
CTTextCharacterProperties rPr = r.addNewRPr();
|
||||||
|
rPr.setLang("en-US");
|
||||||
XSLFTextRun run = new XSLFTextRun(r, this);
|
XSLFTextRun run = new XSLFTextRun(r, this);
|
||||||
_runs.add(run);
|
_runs.add(run);
|
||||||
return run;
|
return run;
|
||||||
|
|
|
@ -167,6 +167,10 @@ public class XSLFTextRun {
|
||||||
if(fontSize == -1.0) {
|
if(fontSize == -1.0) {
|
||||||
if(rPr.isSetSz()) rPr.unsetSz();
|
if(rPr.isSetSz()) rPr.unsetSz();
|
||||||
} else {
|
} else {
|
||||||
|
if(fontSize < 1.0) {
|
||||||
|
throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize);
|
||||||
|
}
|
||||||
|
|
||||||
rPr.setSz((int)(100*fontSize));
|
rPr.setSz((int)(100*fontSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,6 +216,24 @@ public class XSLFTextRun {
|
||||||
return fetcher.getValue() == null ? 0 : fetcher.getValue();
|
return fetcher.getValue() == null ? 0 : fetcher.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the spacing between characters within a text run.
|
||||||
|
* <p>
|
||||||
|
* The spacing is specified in points. Positive values will cause the text to expand,
|
||||||
|
* negative values to condense.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @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.
|
* Specifies the typeface, or name of the font that is to be used for this text run.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,11 +27,7 @@ import java.awt.image.BufferedImage;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* @author Yegor Kozlov
|
||||||
* User: yegor
|
|
||||||
* Date: Nov 10, 2011
|
|
||||||
* Time: 1:43:25 PM
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTextParagraph extends TestCase {
|
public class TestXSLFTextParagraph extends TestCase {
|
||||||
private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class);
|
private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class);
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue