summaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src/main
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-12-12 15:18:35 +0000
committerPJ Fanning <fanningpj@apache.org>2022-12-12 15:18:35 +0000
commit624f83431065e1a7613f1f044f1820c27e504266 (patch)
tree0941baadbb36c365b58899211f50789a550c11db /poi-ooxml/src/main
parente9aa298e1eea7be331128057d3d16c0849347916 (diff)
downloadpoi-624f83431065e1a7613f1f044f1820c27e504266.tar.gz
poi-624f83431065e1a7613f1f044f1820c27e504266.zip
[github-404] issue with text runs and styling relating to table cells. Thanks to gffloodg. This closes #404
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905933 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java49
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java2
2 files changed, 38 insertions, 13 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
index d30bfa5521..f84c37d08e 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
@@ -735,27 +735,44 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,
public PaintStyle getFontColor() {
CTTableStyleTextStyle txStyle = getTextStyle();
if (txStyle == null) {
+ // No table styling, so just use the text run output
return super.getFontColor();
+ } else {
+ final CTTextCharacterProperties props = this.getRPr(false);
+ final XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
+ if (fp != null && (fp.isSetSolidFill() || fp.isSetGradFill() || fp.isSetPattFill())) {
+ // If this run has style set locally, then it overrides table cell style.
+ return super.getFontColor();
+ } else {
+ // Otherwise just use the properties from the table cell style.
+ CTSchemeColor phClr = null;
+ CTFontReference fontRef = txStyle.getFontRef();
+ if (fontRef != null) {
+ phClr = fontRef.getSchemeClr();
+ }
+
+ XSLFTheme theme = getSheet().getTheme();
+ final XSLFColor c = new XSLFColor(txStyle, theme, phClr, getSheet());
+ return DrawPaint.createSolidPaint(c.getColorStyle());
+ }
}
-
- CTSchemeColor phClr = null;
- CTFontReference fontRef = txStyle.getFontRef();
- if (fontRef != null) {
- phClr = fontRef.getSchemeClr();
- }
-
- XSLFTheme theme = getSheet().getTheme();
- final XSLFColor c = new XSLFColor(txStyle, theme, phClr, getSheet());
- return DrawPaint.createSolidPaint(c.getColorStyle());
}
@Override
public boolean isBold() {
CTTableStyleTextStyle txStyle = getTextStyle();
if (txStyle == null) {
+ // No table styling, so just use the text run output
return super.isBold();
} else {
- return txStyle.isSetB() && txStyle.getB().intValue() == STOnOffStyleType.INT_ON;
+ final CTTextCharacterProperties rPr = super.getRPr(false);
+ if (rPr.isSetB()) {
+ // If this run has bold set locally, then it overrides table cell style.
+ return rPr.getB();
+ } else {
+ // Otherwise just use the properties from the table cell style.
+ return txStyle.isSetB() && txStyle.getB().intValue() == STOnOffStyleType.INT_ON;
+ }
}
}
@@ -763,9 +780,17 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,
public boolean isItalic() {
CTTableStyleTextStyle txStyle = getTextStyle();
if (txStyle == null) {
+ // No table styling, so just use the text run output
return super.isItalic();
} else {
- return txStyle.isSetI() && txStyle.getI().intValue() == STOnOffStyleType.INT_ON;
+ final CTTextCharacterProperties rPr = super.getRPr(false);
+ if (rPr.isSetI()) {
+ // If this run has italic set locally, then it overrides table cell style.
+ return rPr.getI();
+ } else {
+ // Otherwise just use the properties from the table cell style.
+ return txStyle.isSetI() && txStyle.getI().intValue() == STOnOffStyleType.INT_ON;
+ }
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
index d8bcd25f1d..60b648244b 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
@@ -75,7 +75,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
if (r instanceof CTTextLineBreak) {
_runs.add(new XSLFLineBreak((CTTextLineBreak)r, this));
} else if (r instanceof CTRegularTextRun || r instanceof CTTextField) {
- _runs.add(new XSLFTextRun(r, this));
+ _runs.add(this.newTextRun(r));
}
} while (c.toNextSibling());
}