Regression fix for XSLF
- master style was always overridden, because of r1745100 - AIOOB in TextDirection mapping git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1746858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d80170f9ac
commit
bd2b438ee1
@ -22,17 +22,13 @@ package org.apache.poi.xslf.model;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public abstract class CharacterPropertyFetcher<T> extends ParagraphPropertyFetcher<T> {
|
public abstract class CharacterPropertyFetcher<T> extends ParagraphPropertyFetcher<T> {
|
||||||
public CharacterPropertyFetcher(int level) {
|
public CharacterPropertyFetcher(int level) {
|
||||||
super(level);
|
super(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fetch(CTTextParagraphProperties props) {
|
public boolean fetch(CTTextParagraphProperties props) {
|
||||||
if (props.isSetDefRPr()) {
|
if (props != null && props.isSetDefRPr()) {
|
||||||
return fetch(props.getDefRPr());
|
return fetch(props.getDefRPr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,6 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
class XSLFLineBreak extends XSLFTextRun {
|
class XSLFLineBreak extends XSLFTextRun {
|
||||||
private final CTTextCharacterProperties _brProps;
|
private final CTTextCharacterProperties _brProps;
|
||||||
|
|
||||||
@ -34,7 +31,7 @@ class XSLFLineBreak extends XSLFTextRun {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CTTextCharacterProperties getRPr(){
|
protected CTTextCharacterProperties getRPr(boolean create){
|
||||||
return _brProps;
|
return _brProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
|
|||||||
CTTextCharacterProperties brProps = br.addNewRPr();
|
CTTextCharacterProperties brProps = br.addNewRPr();
|
||||||
if(_runs.size() > 0){
|
if(_runs.size() > 0){
|
||||||
// by default line break has the font size of the last text run
|
// by default line break has the font size of the last text run
|
||||||
CTTextCharacterProperties prevRun = _runs.get(_runs.size() - 1).getRPr();
|
CTTextCharacterProperties prevRun = _runs.get(_runs.size() - 1).getRPr(true);
|
||||||
brProps.set(prevRun);
|
brProps.set(prevRun);
|
||||||
}
|
}
|
||||||
CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
|
CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
|
||||||
@ -1043,7 +1043,15 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
|
|||||||
}
|
}
|
||||||
if (!_runs.isEmpty()) {
|
if (!_runs.isEmpty()) {
|
||||||
int size = _runs.size();
|
int size = _runs.size();
|
||||||
thisP.setEndParaRPr(_runs.get(size-1).getRPr());
|
XSLFTextRun lastRun = _runs.get(size-1);
|
||||||
|
CTTextCharacterProperties cpOther = lastRun.getRPr(false);
|
||||||
|
if (cpOther != null) {
|
||||||
|
if (thisP.isSetEndParaRPr()) {
|
||||||
|
thisP.unsetEndParaRPr();
|
||||||
|
}
|
||||||
|
CTTextCharacterProperties cp = thisP.addNewEndParaRPr();
|
||||||
|
cp.set(cpOther);
|
||||||
|
}
|
||||||
for (int i=size; i>0; i--) {
|
for (int i=size; i>0; i--) {
|
||||||
thisP.removeR(i-1);
|
thisP.removeR(i-1);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
SolidPaint sp = (SolidPaint)color;
|
SolidPaint sp = (SolidPaint)color;
|
||||||
Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
|
Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
|
||||||
|
|
||||||
CTTextCharacterProperties rPr = getRPr();
|
CTTextCharacterProperties rPr = getRPr(true);
|
||||||
CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
|
CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
|
||||||
|
|
||||||
XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr());
|
XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr());
|
||||||
@ -107,6 +107,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
public PaintStyle getFontColor(){
|
public PaintStyle getFontColor(){
|
||||||
CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
|
if (props != null) {
|
||||||
XSLFShape shape = _p.getParentShape();
|
XSLFShape shape = _p.getParentShape();
|
||||||
CTShapeStyle style = shape.getSpStyle();
|
CTShapeStyle style = shape.getSpStyle();
|
||||||
CTSchemeColor phClr = null;
|
CTSchemeColor phClr = null;
|
||||||
@ -119,6 +120,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
setValue(ps);
|
setValue(ps);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -129,7 +131,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFontSize(Double fontSize){
|
public void setFontSize(Double fontSize){
|
||||||
CTTextCharacterProperties rPr = getRPr();
|
CTTextCharacterProperties rPr = getRPr(true);
|
||||||
if(fontSize == null) {
|
if(fontSize == null) {
|
||||||
if (rPr.isSetSz()) rPr.unsetSz();
|
if (rPr.isSetSz()) rPr.unsetSz();
|
||||||
} else {
|
} else {
|
||||||
@ -149,7 +151,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetSz()){
|
if (props != null && props.isSetSz()) {
|
||||||
setValue(props.getSz()*0.01);
|
setValue(props.getSz()*0.01);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -169,7 +171,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetSpc()){
|
if (props != null && props.isSetSpc()) {
|
||||||
setValue(props.getSpc()*0.01);
|
setValue(props.getSpc()*0.01);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -190,7 +192,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
* @param spc character spacing in points.
|
* @param spc character spacing in points.
|
||||||
*/
|
*/
|
||||||
public void setCharacterSpacing(double spc){
|
public void setCharacterSpacing(double spc){
|
||||||
CTTextCharacterProperties rPr = getRPr();
|
CTTextCharacterProperties rPr = getRPr(true);
|
||||||
if(spc == 0.0) {
|
if(spc == 0.0) {
|
||||||
if(rPr.isSetSpc()) rPr.unsetSpc();
|
if(rPr.isSetSpc()) rPr.unsetSpc();
|
||||||
} else {
|
} else {
|
||||||
@ -204,7 +206,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol){
|
public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol){
|
||||||
CTTextCharacterProperties rPr = getRPr();
|
CTTextCharacterProperties rPr = getRPr(true);
|
||||||
|
|
||||||
if(typeface == null){
|
if(typeface == null){
|
||||||
if(rPr.isSetLatin()) rPr.unsetLatin();
|
if(rPr.isSetLatin()) rPr.unsetLatin();
|
||||||
@ -229,8 +231,9 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
|
if (props != null) {
|
||||||
CTTextFont font = props.getLatin();
|
CTTextFont font = props.getLatin();
|
||||||
if(font != null){
|
if (font != null) {
|
||||||
String typeface = font.getTypeface();
|
String typeface = font.getTypeface();
|
||||||
if("+mj-lt".equals(typeface)) {
|
if("+mj-lt".equals(typeface)) {
|
||||||
typeface = theme.getMajorFont();
|
typeface = theme.getMajorFont();
|
||||||
@ -240,6 +243,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
setValue(typeface);
|
setValue(typeface);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -253,11 +257,13 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
|
if (props != null) {
|
||||||
CTTextFont font = props.getLatin();
|
CTTextFont font = props.getLatin();
|
||||||
if(font != null){
|
if (font != null) {
|
||||||
setValue(font.getPitchFamily());
|
setValue(font.getPitchFamily());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -268,14 +274,14 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStrikethrough(boolean strike) {
|
public void setStrikethrough(boolean strike) {
|
||||||
getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);
|
getRPr(true).setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isStrikethrough() {
|
public boolean isStrikethrough() {
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetStrike()){
|
if(props != null && props.isSetStrike()) {
|
||||||
setValue(props.getStrike() != STTextStrikeType.NO_STRIKE);
|
setValue(props.getStrike() != STTextStrikeType.NO_STRIKE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -290,7 +296,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
public boolean isSuperscript() {
|
public boolean isSuperscript() {
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetBaseline()){
|
if (props != null && props.isSetBaseline()) {
|
||||||
setValue(props.getBaseline() > 0);
|
setValue(props.getBaseline() > 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -311,7 +317,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
* @param baselineOffset
|
* @param baselineOffset
|
||||||
*/
|
*/
|
||||||
public void setBaselineOffset(double baselineOffset){
|
public void setBaselineOffset(double baselineOffset){
|
||||||
getRPr().setBaseline((int) baselineOffset * 1000);
|
getRPr(true).setBaseline((int) baselineOffset * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,7 +344,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
public boolean isSubscript() {
|
public boolean isSubscript() {
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetBaseline()){
|
if (props != null && props.isSetBaseline()) {
|
||||||
setValue(props.getBaseline() < 0);
|
setValue(props.getBaseline() < 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -355,7 +361,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
public TextCap getTextCap() {
|
public TextCap getTextCap() {
|
||||||
CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetCap()){
|
if (props != null && props.isSetCap()) {
|
||||||
int idx = props.getCap().intValue() - 1;
|
int idx = props.getCap().intValue() - 1;
|
||||||
setValue(TextCap.values()[idx]);
|
setValue(TextCap.values()[idx]);
|
||||||
return true;
|
return true;
|
||||||
@ -369,14 +375,14 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBold(boolean bold){
|
public void setBold(boolean bold){
|
||||||
getRPr().setB(bold);
|
getRPr(true).setB(bold);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBold(){
|
public boolean isBold(){
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetB()){
|
if (props != null && props.isSetB()) {
|
||||||
setValue(props.getB());
|
setValue(props.getB());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -389,14 +395,14 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItalic(boolean italic){
|
public void setItalic(boolean italic){
|
||||||
getRPr().setI(italic);
|
getRPr(true).setI(italic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItalic(){
|
public boolean isItalic(){
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetI()){
|
if (props != null && props.isSetI()) {
|
||||||
setValue(props.getI());
|
setValue(props.getI());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -409,14 +415,14 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUnderlined(boolean underline) {
|
public void setUnderlined(boolean underline) {
|
||||||
getRPr().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);
|
getRPr(true).setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnderlined(){
|
public boolean isUnderlined(){
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getIndentLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetU()){
|
if (props != null && props.isSetU()) {
|
||||||
setValue(props.getU() != STTextUnderlineType.NONE);
|
setValue(props.getU() != STTextUnderlineType.NONE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -427,8 +433,20 @@ public class XSLFTextRun implements TextRun {
|
|||||||
return fetcher.getValue() == null ? false : fetcher.getValue();
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CTTextCharacterProperties getRPr(){
|
/**
|
||||||
return _r.isSetRPr() ? _r.getRPr() : _r.addNewRPr();
|
* Return the character properties
|
||||||
|
*
|
||||||
|
* @param create if true, create an empty character properties object if it doesn't exist
|
||||||
|
* @return the character properties or null if create was false and the properties haven't exist
|
||||||
|
*/
|
||||||
|
protected CTTextCharacterProperties getRPr(boolean create) {
|
||||||
|
if (_r.isSetRPr()) {
|
||||||
|
return _r.getRPr();
|
||||||
|
} else if (create) {
|
||||||
|
return _r.addNewRPr();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -463,7 +481,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
XSLFSheet sheet = shape.getSheet();
|
XSLFSheet sheet = shape.getSheet();
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
|
|
||||||
if (_r.isSetRPr()) ok = fetcher.fetch(getRPr());
|
if (_r.isSetRPr()) ok = fetcher.fetch(getRPr(false));
|
||||||
if (ok) return true;
|
if (ok) return true;
|
||||||
|
|
||||||
ok = shape.fetchShapeProperty(fetcher);
|
ok = shape.fetchShapeProperty(fetcher);
|
||||||
|
@ -112,8 +112,8 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
|
|||||||
if (text == null) return null;
|
if (text == null) return null;
|
||||||
|
|
||||||
// copy properties from last paragraph / textrun or paragraph end marker
|
// copy properties from last paragraph / textrun or paragraph end marker
|
||||||
CTTextParagraphProperties pPr = null;
|
CTTextParagraphProperties otherPPr = null;
|
||||||
CTTextCharacterProperties rPr = null;
|
CTTextCharacterProperties otherRPr = null;
|
||||||
|
|
||||||
boolean firstPara;
|
boolean firstPara;
|
||||||
XSLFTextParagraph para;
|
XSLFTextParagraph para;
|
||||||
@ -124,25 +124,33 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
|
|||||||
firstPara = !newParagraph;
|
firstPara = !newParagraph;
|
||||||
para = _paragraphs.get(_paragraphs.size()-1);
|
para = _paragraphs.get(_paragraphs.size()-1);
|
||||||
CTTextParagraph ctp = para.getXmlObject();
|
CTTextParagraph ctp = para.getXmlObject();
|
||||||
pPr = ctp.getPPr();
|
otherPPr = ctp.getPPr();
|
||||||
List<XSLFTextRun> runs = para.getTextRuns();
|
List<XSLFTextRun> runs = para.getTextRuns();
|
||||||
if (!runs.isEmpty()) {
|
if (!runs.isEmpty()) {
|
||||||
XSLFTextRun r0 = runs.get(runs.size()-1);
|
XSLFTextRun r0 = runs.get(runs.size()-1);
|
||||||
rPr = r0.getXmlObject().getRPr();
|
otherRPr = r0.getRPr(false);
|
||||||
} else if (ctp.isSetEndParaRPr()) {
|
if (otherRPr == null) {
|
||||||
rPr = ctp.getEndParaRPr();
|
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;
|
XSLFTextRun run = null;
|
||||||
for (String lineTxt : text.split("\\r\\n?|\\n")) {
|
for (String lineTxt : text.split("\\r\\n?|\\n")) {
|
||||||
if (!firstPara) {
|
if (!firstPara) {
|
||||||
if (para != null && para.getXmlObject().isSetEndParaRPr()) {
|
if (para != null) {
|
||||||
para.getXmlObject().unsetEndParaRPr();
|
CTTextParagraph ctp = para.getXmlObject();
|
||||||
|
CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
|
||||||
|
if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
|
||||||
|
ctp.unsetEndParaRPr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
para = addNewTextParagraph();
|
para = addNewTextParagraph();
|
||||||
if (pPr != null) {
|
if (otherPPr != null) {
|
||||||
para.getXmlObject().setPPr(pPr);
|
para.getXmlObject().setPPr(otherPPr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean firstRun = true;
|
boolean firstRun = true;
|
||||||
@ -152,8 +160,8 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
|
|||||||
}
|
}
|
||||||
run = para.addNewTextRun();
|
run = para.addNewTextRun();
|
||||||
run.setText(runText);
|
run.setText(runText);
|
||||||
if (rPr != null) {
|
if (otherRPr != null) {
|
||||||
run.getXmlObject().setRPr(rPr);
|
run.getRPr(true).set(otherRPr);
|
||||||
}
|
}
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
}
|
}
|
||||||
@ -261,8 +269,21 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
|
|||||||
CTTextBodyProperties bodyPr = getTextBodyPr();
|
CTTextBodyProperties bodyPr = getTextBodyPr();
|
||||||
if (bodyPr != null) {
|
if (bodyPr != null) {
|
||||||
STTextVerticalType.Enum val = bodyPr.getVert();
|
STTextVerticalType.Enum val = bodyPr.getVert();
|
||||||
if(val != null){
|
if(val != null) {
|
||||||
return TextDirection.values()[val.intValue() - 1];
|
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;
|
return TextDirection.HORIZONTAL;
|
||||||
|
@ -34,9 +34,6 @@ import org.junit.Test;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public class TestXSLFTable {
|
public class TestXSLFTable {
|
||||||
@Test
|
@Test
|
||||||
public void testRead() throws IOException {
|
public void testRead() throws IOException {
|
||||||
@ -82,8 +79,8 @@ public class TestXSLFTable {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() throws IOException {
|
public void testCreate() throws IOException {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt1 = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt1.createSlide();
|
||||||
|
|
||||||
XSLFTable tbl = slide.createTable();
|
XSLFTable tbl = slide.createTable();
|
||||||
assertNotNull(tbl.getCTTable());
|
assertNotNull(tbl.getCTTable());
|
||||||
@ -145,7 +142,17 @@ public class TestXSLFTable {
|
|||||||
cell1.setVerticalAlignment(null);
|
cell1.setVerticalAlignment(null);
|
||||||
assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment());
|
||||||
|
|
||||||
ppt.close();
|
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||||
|
ppt1.close();
|
||||||
|
|
||||||
|
slide = ppt2.getSlides().get(0);
|
||||||
|
tbl = (XSLFTable)slide.getShapes().get(0);
|
||||||
|
assertEquals(2, tbl.getNumberOfColumns());
|
||||||
|
assertEquals(1, tbl.getNumberOfRows());
|
||||||
|
assertEquals("POI", tbl.getCell(0, 0).getText());
|
||||||
|
assertEquals("Apache", tbl.getCell(0, 1).getText());
|
||||||
|
|
||||||
|
ppt2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -40,7 +40,7 @@ public class TestXSLFTextRun {
|
|||||||
XSLFTextShape sh = slide.createAutoShape();
|
XSLFTextShape sh = slide.createAutoShape();
|
||||||
|
|
||||||
XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun();
|
XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun();
|
||||||
assertEquals("en-US", r.getRPr().getLang());
|
assertEquals("en-US", r.getRPr(true).getLang());
|
||||||
|
|
||||||
assertEquals(0., r.getCharacterSpacing(), 0);
|
assertEquals(0., r.getCharacterSpacing(), 0);
|
||||||
r.setCharacterSpacing(3);
|
r.setCharacterSpacing(3);
|
||||||
@ -49,7 +49,7 @@ public class TestXSLFTextRun {
|
|||||||
assertEquals(-3., r.getCharacterSpacing(), 0);
|
assertEquals(-3., r.getCharacterSpacing(), 0);
|
||||||
r.setCharacterSpacing(0);
|
r.setCharacterSpacing(0);
|
||||||
assertEquals(0., r.getCharacterSpacing(), 0);
|
assertEquals(0., r.getCharacterSpacing(), 0);
|
||||||
assertFalse(r.getRPr().isSetSpc());
|
assertFalse(r.getRPr(true).isSetSpc());
|
||||||
|
|
||||||
assertTrue(sameColor(Color.black, r.getFontColor()));
|
assertTrue(sameColor(Color.black, r.getFontColor()));
|
||||||
r.setFontColor(Color.red);
|
r.setFontColor(Color.red);
|
||||||
|
BIN
test-data/slideshow/table_test2.pptx
Normal file
BIN
test-data/slideshow/table_test2.pptx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user