SolidPaint sp = (SolidPaint)color;\r
Color c = DrawPaint.applyColorTransform(sp.getSolidColor());\r
\r
- CTTextCharacterProperties rPr = getRPr();\r
+ CTTextCharacterProperties rPr = getRPr(true);\r
CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();\r
\r
XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr());\r
public PaintStyle getFontColor(){\r
CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- XSLFShape shape = _p.getParentShape();\r
- CTShapeStyle style = shape.getSpStyle();\r
- CTSchemeColor phClr = null;\r
- if (style != null && style.getFontRef() != null) {\r
- phClr = style.getFontRef().getSchemeClr();\r
- }\r
-\r
- PaintStyle ps = shape.getPaint(props, phClr);\r
- if (ps != null) {\r
- setValue(ps);\r
- return true;\r
+ if (props != null) {\r
+ XSLFShape shape = _p.getParentShape();\r
+ CTShapeStyle style = shape.getSpStyle();\r
+ CTSchemeColor phClr = null;\r
+ if (style != null && style.getFontRef() != null) {\r
+ phClr = style.getFontRef().getSchemeClr();\r
+ }\r
+ \r
+ PaintStyle ps = shape.getPaint(props, phClr);\r
+ if (ps != null) {\r
+ setValue(ps);\r
+ return true;\r
+ }\r
}\r
\r
return false;\r
\r
@Override\r
public void setFontSize(Double fontSize){\r
- CTTextCharacterProperties rPr = getRPr();\r
+ CTTextCharacterProperties rPr = getRPr(true);\r
if(fontSize == null) {\r
if (rPr.isSetSz()) rPr.unsetSz();\r
} else {\r
\r
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetSz()){\r
+ if (props != null && props.isSetSz()) {\r
setValue(props.getSz()*0.01);\r
return true;\r
}\r
\r
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetSpc()){\r
+ if (props != null && props.isSetSpc()) {\r
setValue(props.getSpc()*0.01);\r
return true;\r
}\r
* @param spc character spacing in points.\r
*/\r
public void setCharacterSpacing(double spc){\r
- CTTextCharacterProperties rPr = getRPr();\r
+ CTTextCharacterProperties rPr = getRPr(true);\r
if(spc == 0.0) {\r
if(rPr.isSetSpc()) rPr.unsetSpc();\r
} else {\r
}\r
\r
public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol){\r
- CTTextCharacterProperties rPr = getRPr();\r
+ CTTextCharacterProperties rPr = getRPr(true);\r
\r
if(typeface == null){\r
if(rPr.isSetLatin()) rPr.unsetLatin();\r
\r
CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- CTTextFont font = props.getLatin();\r
- if(font != null){\r
- String typeface = font.getTypeface();\r
- if("+mj-lt".equals(typeface)) {\r
- typeface = theme.getMajorFont();\r
- } else if ("+mn-lt".equals(typeface)){\r
- typeface = theme.getMinorFont();\r
+ if (props != null) {\r
+ CTTextFont font = props.getLatin();\r
+ if (font != null) {\r
+ String typeface = font.getTypeface();\r
+ if("+mj-lt".equals(typeface)) {\r
+ typeface = theme.getMajorFont();\r
+ } else if ("+mn-lt".equals(typeface)){\r
+ typeface = theme.getMinorFont();\r
+ }\r
+ setValue(typeface);\r
+ return true;\r
}\r
- setValue(typeface);\r
- return true;\r
}\r
return false;\r
}\r
\r
CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- CTTextFont font = props.getLatin();\r
- if(font != null){\r
- setValue(font.getPitchFamily());\r
- return true;\r
+ if (props != null) {\r
+ CTTextFont font = props.getLatin();\r
+ if (font != null) {\r
+ setValue(font.getPitchFamily());\r
+ return true;\r
+ }\r
}\r
return false;\r
}\r
\r
@Override\r
public void setStrikethrough(boolean strike) {\r
- getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);\r
+ getRPr(true).setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);\r
}\r
\r
@Override\r
public boolean isStrikethrough() {\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetStrike()){\r
+ if(props != null && props.isSetStrike()) {\r
setValue(props.getStrike() != STTextStrikeType.NO_STRIKE);\r
return true;\r
}\r
public boolean isSuperscript() {\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetBaseline()){\r
+ if (props != null && props.isSetBaseline()) {\r
setValue(props.getBaseline() > 0);\r
return true;\r
}\r
* @param baselineOffset\r
*/\r
public void setBaselineOffset(double baselineOffset){\r
- getRPr().setBaseline((int) baselineOffset * 1000);\r
+ getRPr(true).setBaseline((int) baselineOffset * 1000);\r
}\r
\r
/**\r
public boolean isSubscript() {\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetBaseline()){\r
+ if (props != null && props.isSetBaseline()) {\r
setValue(props.getBaseline() < 0);\r
return true;\r
}\r
public TextCap getTextCap() {\r
CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetCap()){\r
+ if (props != null && props.isSetCap()) {\r
int idx = props.getCap().intValue() - 1;\r
setValue(TextCap.values()[idx]);\r
return true;\r
\r
@Override\r
public void setBold(boolean bold){\r
- getRPr().setB(bold);\r
+ getRPr(true).setB(bold);\r
}\r
\r
@Override\r
public boolean isBold(){\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetB()){\r
+ if (props != null && props.isSetB()) {\r
setValue(props.getB());\r
return true;\r
}\r
\r
@Override\r
public void setItalic(boolean italic){\r
- getRPr().setI(italic);\r
+ getRPr(true).setI(italic);\r
}\r
\r
@Override\r
public boolean isItalic(){\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetI()){\r
+ if (props != null && props.isSetI()) {\r
setValue(props.getI());\r
return true;\r
}\r
\r
@Override\r
public void setUnderlined(boolean underline) {\r
- getRPr().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);\r
+ getRPr(true).setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);\r
}\r
\r
@Override\r
public boolean isUnderlined(){\r
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){\r
public boolean fetch(CTTextCharacterProperties props){\r
- if(props.isSetU()){\r
+ if (props != null && props.isSetU()) {\r
setValue(props.getU() != STTextUnderlineType.NONE);\r
return true;\r
}\r
return fetcher.getValue() == null ? false : fetcher.getValue();\r
}\r
\r
- protected CTTextCharacterProperties getRPr(){\r
- return _r.isSetRPr() ? _r.getRPr() : _r.addNewRPr();\r
+ /**\r
+ * Return the character properties\r
+ *\r
+ * @param create if true, create an empty character properties object if it doesn't exist\r
+ * @return the character properties or null if create was false and the properties haven't exist\r
+ */\r
+ protected CTTextCharacterProperties getRPr(boolean create) {\r
+ if (_r.isSetRPr()) {\r
+ return _r.getRPr();\r
+ } else if (create) {\r
+ return _r.addNewRPr();\r
+ } else {\r
+ return null;\r
+ }\r
}\r
\r
@Override\r
XSLFSheet sheet = shape.getSheet();\r
boolean ok = false;\r
\r
- if (_r.isSetRPr()) ok = fetcher.fetch(getRPr());\r
+ if (_r.isSetRPr()) ok = fetcher.fetch(getRPr(false));\r
if (ok) return true;\r
\r
ok = shape.fetchShapeProperty(fetcher);\r
if (text == null) return null;
// copy properties from last paragraph / textrun or paragraph end marker
- CTTextParagraphProperties pPr = null;
- CTTextCharacterProperties rPr = null;
+ CTTextParagraphProperties otherPPr = null;
+ CTTextCharacterProperties otherRPr = null;
boolean firstPara;
XSLFTextParagraph para;
firstPara = !newParagraph;
para = _paragraphs.get(_paragraphs.size()-1);
CTTextParagraph ctp = para.getXmlObject();
- pPr = ctp.getPPr();
+ otherPPr = ctp.getPPr();
List<XSLFTextRun> runs = para.getTextRuns();
if (!runs.isEmpty()) {
XSLFTextRun r0 = runs.get(runs.size()-1);
- rPr = r0.getXmlObject().getRPr();
- } else if (ctp.isSetEndParaRPr()) {
- rPr = ctp.getEndParaRPr();
+ otherRPr = r0.getRPr(false);
+ if (otherRPr == null) {
+ otherRPr = ctp.getEndParaRPr();
+ }
}
+ // don't copy endParaRPr to the run in case there aren't any other runs
+ // this is the case when setText() was called initially
+ // otherwise the master style will be overridden/ignored
}
XSLFTextRun run = null;
for (String lineTxt : text.split("\\r\\n?|\\n")) {
if (!firstPara) {
- if (para != null && para.getXmlObject().isSetEndParaRPr()) {
- para.getXmlObject().unsetEndParaRPr();
+ if (para != null) {
+ CTTextParagraph ctp = para.getXmlObject();
+ CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
+ if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
+ ctp.unsetEndParaRPr();
+ }
}
para = addNewTextParagraph();
- if (pPr != null) {
- para.getXmlObject().setPPr(pPr);
+ if (otherPPr != null) {
+ para.getXmlObject().setPPr(otherPPr);
}
}
boolean firstRun = true;
}
run = para.addNewTextRun();
run.setText(runText);
- if (rPr != null) {
- run.getXmlObject().setRPr(rPr);
+ if (otherRPr != null) {
+ run.getRPr(true).set(otherRPr);
}
firstRun = false;
}
CTTextBodyProperties bodyPr = getTextBodyPr();
if (bodyPr != null) {
STTextVerticalType.Enum val = bodyPr.getVert();
- if(val != null){
- return TextDirection.values()[val.intValue() - 1];
+ if(val != null) {
+ switch (val.intValue()) {
+ default:
+ case STTextVerticalType.INT_HORZ:
+ return TextDirection.HORIZONTAL;
+ case STTextVerticalType.INT_EA_VERT:
+ case STTextVerticalType.INT_MONGOLIAN_VERT:
+ case STTextVerticalType.INT_VERT:
+ return TextDirection.VERTICAL;
+ case STTextVerticalType.INT_VERT_270:
+ return TextDirection.VERTICAL_270;
+ case STTextVerticalType.INT_WORD_ART_VERT_RTL:
+ case STTextVerticalType.INT_WORD_ART_VERT:
+ return TextDirection.STACKED;
+ }
}
}
return TextDirection.HORIZONTAL;