2011-08-11 04:38:19 -04:00
|
|
|
/* ====================================================================
|
|
|
|
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;
|
|
|
|
|
2013-12-25 17:18:53 -05:00
|
|
|
import java.awt.Color;
|
|
|
|
|
2015-02-21 05:56:03 -05:00
|
|
|
import org.apache.poi.sl.usermodel.TextRun;
|
2011-08-11 04:38:19 -04:00
|
|
|
import org.apache.poi.util.Beta;
|
2011-10-21 09:17:33 -04:00
|
|
|
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
|
2015-06-17 18:21:13 -04:00
|
|
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
2011-11-24 11:13:42 -05:00
|
|
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
|
2011-08-11 04:38:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2015-02-21 05:56:03 -05:00
|
|
|
public class XSLFTextRun implements TextRun {
|
2011-08-11 04:38:19 -04:00
|
|
|
private final CTRegularTextRun _r;
|
2011-08-17 06:18:31 -04:00
|
|
|
private final XSLFTextParagraph _p;
|
2011-08-11 04:38:19 -04:00
|
|
|
|
2011-08-17 06:18:31 -04:00
|
|
|
XSLFTextRun(CTRegularTextRun r, XSLFTextParagraph p){
|
2011-08-11 04:38:19 -04:00
|
|
|
_r = r;
|
2011-08-17 06:18:31 -04:00
|
|
|
_p = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
XSLFTextParagraph getParentParagraph(){
|
|
|
|
return _p;
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
public String getRawText(){
|
2011-08-11 04:38:19 -04:00
|
|
|
return _r.getT();
|
|
|
|
}
|
|
|
|
|
2011-11-10 08:59:16 -05:00
|
|
|
String getRenderableText(){
|
|
|
|
String txt = _r.getT();
|
2011-11-17 05:33:59 -05:00
|
|
|
TextCap cap = getTextCap();
|
2011-11-14 08:00:13 -05:00
|
|
|
StringBuffer buf = new StringBuffer();
|
|
|
|
for(int i = 0; i < txt.length(); i++) {
|
|
|
|
char c = txt.charAt(i);
|
|
|
|
if(c == '\t') {
|
2011-11-17 05:33:59 -05:00
|
|
|
// TODO: finish support for tabs
|
2011-11-14 08:00:13 -05:00
|
|
|
buf.append(" ");
|
|
|
|
} else {
|
2011-11-17 05:33:59 -05:00
|
|
|
switch (cap){
|
2011-11-14 08:00:13 -05:00
|
|
|
case ALL:
|
|
|
|
buf.append(Character.toUpperCase(c));
|
|
|
|
break;
|
|
|
|
case SMALL:
|
|
|
|
buf.append(Character.toLowerCase(c));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buf.append(c);
|
|
|
|
}
|
|
|
|
}
|
2011-11-10 08:59:16 -05:00
|
|
|
}
|
2011-11-14 08:00:13 -05:00
|
|
|
|
|
|
|
return buf.toString();
|
2011-11-10 08:59:16 -05:00
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
public void setText(String text){
|
|
|
|
_r.setT(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CTRegularTextRun getXmlObject(){
|
|
|
|
return _r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFontColor(Color color){
|
2012-02-03 03:24:38 -05:00
|
|
|
CTTextCharacterProperties rPr = getRPr();
|
2011-08-11 04:38:19 -04:00
|
|
|
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()});
|
2011-11-10 08:59:16 -05:00
|
|
|
|
|
|
|
if(fill.isSetHslClr()) fill.unsetHslClr();
|
|
|
|
if(fill.isSetPrstClr()) fill.unsetPrstClr();
|
|
|
|
if(fill.isSetSchemeClr()) fill.unsetSchemeClr();
|
|
|
|
if(fill.isSetScrgbClr()) fill.unsetScrgbClr();
|
|
|
|
if(fill.isSetSysClr()) fill.unsetSysClr();
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2011-10-21 09:17:33 -04:00
|
|
|
public Color getFontColor(){
|
|
|
|
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
|
2011-11-07 04:12:16 -05:00
|
|
|
CTShapeStyle style = _p.getParentShape().getSpStyle();
|
2011-11-14 08:00:13 -05:00
|
|
|
final CTSchemeColor phClr = style == null ? null : style.getFontRef().getSchemeClr();
|
2011-10-21 09:17:33 -04:00
|
|
|
|
|
|
|
CharacterPropertyFetcher<Color> fetcher = new CharacterPropertyFetcher<Color>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
CTSolidColorFillProperties solidFill = props.getSolidFill();
|
2011-11-07 04:12:16 -05:00
|
|
|
if(solidFill != null) {
|
2011-11-14 08:00:13 -05:00
|
|
|
boolean useCtxColor =
|
|
|
|
(solidFill.isSetSchemeClr() && solidFill.getSchemeClr().getVal() == STSchemeColorVal.PH_CLR)
|
|
|
|
|| isFetchingFromMaster;
|
|
|
|
Color c = new XSLFColor(solidFill, theme, useCtxColor ? phClr : null).getColor();
|
2011-10-28 10:25:53 -04:00
|
|
|
setValue(c);
|
2011-10-21 09:17:33 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue();
|
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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){
|
2012-02-03 03:24:38 -05:00
|
|
|
CTTextCharacterProperties rPr = getRPr();
|
2011-08-11 04:38:19 -04:00
|
|
|
if(fontSize == -1.0) {
|
|
|
|
if(rPr.isSetSz()) rPr.unsetSz();
|
|
|
|
} else {
|
2012-01-25 02:53:07 -05:00
|
|
|
if(fontSize < 1.0) {
|
|
|
|
throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize);
|
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
rPr.setSz((int)(100*fontSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-17 18:21:13 -04:00
|
|
|
* @return font size in points or null if font size is not set.
|
2011-08-11 04:38:19 -04:00
|
|
|
*/
|
2015-06-17 18:21:13 -04:00
|
|
|
@Override
|
|
|
|
public Double getFontSize(){
|
2011-11-07 04:12:16 -05:00
|
|
|
double scale = 1;
|
|
|
|
CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
|
|
|
|
if(afit != null) scale = (double)afit.getFontScale() / 100000;
|
|
|
|
|
2011-10-21 09:17:33 -04:00
|
|
|
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetSz()){
|
|
|
|
setValue(props.getSz()*0.01);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
2015-06-17 18:21:13 -04:00
|
|
|
return fetcher.getValue() == null ? null : fetcher.getValue()*scale;
|
2011-11-07 04:12:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the spacing between characters within a text run,
|
|
|
|
* If this attribute is omitted than a value of 0 or no adjustment is assumed.
|
|
|
|
*/
|
|
|
|
public double getCharacterSpacing(){
|
|
|
|
|
|
|
|
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetSpc()){
|
|
|
|
setValue(props.getSpc()*0.01);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? 0 : fetcher.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2012-01-25 02:53:07 -05:00
|
|
|
/**
|
|
|
|
* 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){
|
2012-02-03 03:24:38 -05:00
|
|
|
CTTextCharacterProperties rPr = getRPr();
|
2012-01-25 02:53:07 -05:00
|
|
|
if(spc == 0.0) {
|
|
|
|
if(rPr.isSetSpc()) rPr.unsetSpc();
|
|
|
|
} else {
|
|
|
|
rPr.setSpc((int)(100*spc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
/**
|
|
|
|
* 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){
|
2012-02-03 03:24:38 -05:00
|
|
|
CTTextCharacterProperties rPr = getRPr();
|
2011-08-11 04:38:19 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-21 09:17:33 -04:00
|
|
|
* @return font family or null if not set
|
2011-08-11 04:38:19 -04:00
|
|
|
*/
|
|
|
|
public String getFontFamily(){
|
2011-10-21 09:17:33 -04:00
|
|
|
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
|
|
|
|
|
|
|
|
CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
CTTextFont font = props.getLatin();
|
|
|
|
if(font != null){
|
|
|
|
String typeface = font.getTypeface();
|
|
|
|
if("+mj-lt".equals(typeface)) {
|
|
|
|
typeface = theme.getMajorFont();
|
|
|
|
} else if ("+mn-lt".equals(typeface)){
|
|
|
|
typeface = theme.getMinorFont();
|
|
|
|
}
|
|
|
|
setValue(typeface);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(visitor);
|
2011-08-11 04:38:19 -04:00
|
|
|
|
2011-10-21 09:17:33 -04:00
|
|
|
return visitor.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2011-11-17 05:33:59 -05:00
|
|
|
public byte getPitchAndFamily(){
|
|
|
|
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
|
|
|
|
|
|
|
|
CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
CTTextFont font = props.getLatin();
|
|
|
|
if(font != null){
|
|
|
|
setValue(font.getPitchFamily());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(visitor);
|
|
|
|
|
|
|
|
return visitor.getValue() == null ? 0 : visitor.getValue();
|
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-02-03 03:24:38 -05:00
|
|
|
public void setStrikethrough(boolean strike) {
|
|
|
|
getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether a run of text will be formatted as strikethrough text. Default is false.
|
|
|
|
*/
|
2011-10-21 09:17:33 -04:00
|
|
|
public boolean isStrikethrough() {
|
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetStrike()){
|
|
|
|
setValue(props.getStrike() != STTextStrikeType.NO_STRIKE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2011-10-28 10:25:53 -04:00
|
|
|
/**
|
|
|
|
* @return whether a run of text will be formatted as a superscript text. Default is false.
|
|
|
|
*/
|
|
|
|
public boolean isSuperscript() {
|
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetBaseline()){
|
|
|
|
setValue(props.getBaseline() > 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
|
|
|
}
|
|
|
|
|
2012-06-20 04:46:50 -04:00
|
|
|
/**
|
|
|
|
* Set the baseline for both the superscript and subscript fonts.
|
|
|
|
* <p>
|
|
|
|
* The size is specified using a percentage.
|
|
|
|
* Positive values indicate superscript, negative values indicate subscript.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @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.);
|
|
|
|
}
|
|
|
|
|
2011-10-28 10:25:53 -04:00
|
|
|
/**
|
|
|
|
* @return whether a run of text will be formatted as a superscript text. Default is false.
|
|
|
|
*/
|
|
|
|
public boolean isSubscript() {
|
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetBaseline()){
|
|
|
|
setValue(props.getBaseline() < 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
|
|
|
}
|
|
|
|
|
2011-11-07 04:12:16 -05:00
|
|
|
/**
|
|
|
|
* @return whether a run of text will be formatted as a superscript text. Default is false.
|
|
|
|
*/
|
|
|
|
public TextCap getTextCap() {
|
|
|
|
CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetCap()){
|
|
|
|
int idx = props.getCap().intValue() - 1;
|
|
|
|
setValue(TextCap.values()[idx]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? TextCap.NONE : fetcher.getValue();
|
|
|
|
}
|
|
|
|
|
2011-08-11 04:38:19 -04:00
|
|
|
/**
|
|
|
|
* 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){
|
2012-02-03 03:24:38 -05:00
|
|
|
getRPr().setB(bold);
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this run of text is formatted as bold text
|
|
|
|
*/
|
|
|
|
public boolean isBold(){
|
2011-10-21 09:17:33 -04:00
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetB()){
|
|
|
|
setValue(props.getB());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param italic whether this run of text is formatted as italic text
|
|
|
|
*/
|
|
|
|
public void setItalic(boolean italic){
|
2012-02-03 03:24:38 -05:00
|
|
|
getRPr().setI(italic);
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this run of text is formatted as italic text
|
|
|
|
*/
|
|
|
|
public boolean isItalic(){
|
2011-10-21 09:17:33 -04:00
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetI()){
|
|
|
|
setValue(props.getI());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param underline whether this run of text is formatted as underlined text
|
|
|
|
*/
|
2012-02-03 03:24:38 -05:00
|
|
|
public void setUnderline(boolean underline) {
|
|
|
|
getRPr().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return whether this run of text is formatted as underlined text
|
|
|
|
*/
|
2015-04-27 16:13:43 -04:00
|
|
|
public boolean isUnderlined(){
|
2011-10-21 09:17:33 -04:00
|
|
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
|
|
|
public boolean fetch(CTTextCharacterProperties props){
|
|
|
|
if(props.isSetU()){
|
|
|
|
setValue(props.getU() != STTextUnderlineType.NONE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fetchCharacterProperty(fetcher);
|
|
|
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-03 03:24:38 -05:00
|
|
|
protected CTTextCharacterProperties getRPr(){
|
2011-08-11 04:38:19 -04:00
|
|
|
return _r.isSetRPr() ? _r.getRPr() : _r.addNewRPr();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString(){
|
2015-04-27 16:13:43 -04:00
|
|
|
return "[" + getClass() + "]" + getRawText();
|
2011-08-11 04:38:19 -04:00
|
|
|
}
|
2011-08-17 06:18:31 -04:00
|
|
|
|
|
|
|
public XSLFHyperlink createHyperlink(){
|
|
|
|
XSLFHyperlink link = new XSLFHyperlink(_r.getRPr().addNewHlinkClick(), this);
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
public XSLFHyperlink getHyperlink(){
|
|
|
|
if(!_r.getRPr().isSetHlinkClick()) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return new XSLFHyperlink(_r.getRPr().getHlinkClick(), this);
|
|
|
|
}
|
2011-10-21 09:17:33 -04:00
|
|
|
|
2015-06-17 18:21:13 -04:00
|
|
|
private boolean fetchCharacterProperty(CharacterPropertyFetcher<?> fetcher){
|
2011-10-21 09:17:33 -04:00
|
|
|
boolean ok = false;
|
|
|
|
|
2012-02-03 03:24:38 -05:00
|
|
|
if(_r.isSetRPr()) ok = fetcher.fetch(getRPr());
|
2011-10-21 09:17:33 -04:00
|
|
|
|
|
|
|
if(!ok) {
|
|
|
|
XSLFTextShape shape = _p.getParentShape();
|
|
|
|
ok = shape.fetchShapeProperty(fetcher);
|
2011-11-24 11:13:42 -05:00
|
|
|
if(!ok){
|
|
|
|
CTPlaceholder ph = shape.getCTPlaceholder();
|
|
|
|
if(ph == null){
|
|
|
|
// if it is a plain text box then take defaults from presentation.xml
|
|
|
|
XMLSlideShow ppt = shape.getSheet().getSlideShow();
|
|
|
|
CTTextParagraphProperties themeProps = ppt.getDefaultParagraphStyle(_p.getLevel());
|
|
|
|
if(themeProps != null) {
|
|
|
|
fetcher.isFetchingFromMaster = true;
|
|
|
|
ok = fetcher.fetch(themeProps);
|
|
|
|
}
|
2011-12-04 06:16:57 -05:00
|
|
|
}
|
|
|
|
if (!ok) {
|
2011-11-24 11:13:42 -05:00
|
|
|
CTTextParagraphProperties defaultProps = _p.getDefaultMasterStyle();
|
|
|
|
if(defaultProps != null) {
|
|
|
|
fetcher.isFetchingFromMaster = true;
|
|
|
|
ok = fetcher.fetch(defaultProps);
|
|
|
|
}
|
2011-11-14 08:00:13 -05:00
|
|
|
}
|
2011-10-21 09:17:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2011-11-10 08:59:16 -05:00
|
|
|
void copy(XSLFTextRun r){
|
|
|
|
String srcFontFamily = r.getFontFamily();
|
|
|
|
if(srcFontFamily != null && !srcFontFamily.equals(getFontFamily())){
|
|
|
|
setFontFamily(srcFontFamily);
|
|
|
|
}
|
|
|
|
|
|
|
|
Color srcFontColor = r.getFontColor();
|
|
|
|
if(srcFontColor != null && !srcFontColor.equals(getFontColor())){
|
|
|
|
setFontColor(srcFontColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
double srcFontSize = r.getFontSize();
|
|
|
|
if(srcFontSize != getFontSize()){
|
|
|
|
setFontSize(srcFontSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean bold = r.isBold();
|
|
|
|
if(bold != isBold()) setBold(bold);
|
|
|
|
|
|
|
|
boolean italic = r.isItalic();
|
|
|
|
if(italic != isItalic()) setItalic(italic);
|
|
|
|
|
2015-04-27 16:13:43 -04:00
|
|
|
boolean underline = r.isUnderlined();
|
|
|
|
if(underline != isUnderlined()) setUnderline(underline);
|
2011-11-10 08:59:16 -05:00
|
|
|
|
|
|
|
boolean strike = r.isStrikethrough();
|
|
|
|
if(strike != isStrikethrough()) setStrikethrough(strike);
|
|
|
|
}
|
2011-10-28 10:25:53 -04:00
|
|
|
}
|