diff options
Diffstat (limited to 'src/ooxml/java')
11 files changed, 552 insertions, 128 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java index e9a889d766..43034a2d1c 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java @@ -29,6 +29,7 @@ import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference;
import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor;
@@ -165,6 +166,8 @@ public class XSLFColor { color = Color.black;
}
}
+ } else if (ch instanceof CTFontReference) {
+ // try next ...
} else {
throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass());
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java index 5db266e42a..6dfe1d0c93 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -65,8 +65,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; /**
* Base super-class class for all shapes in PresentationML
- *
- * @author Yegor Kozlov
*/
@Beta
public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
@@ -150,6 +148,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { }
protected PaintStyle getFillPaint() {
+ final XSLFTheme theme = getSheet().getTheme();
PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
public boolean fetch(XSLFShape shape) {
XmlObject pr = null;
@@ -178,7 +177,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { PaintStyle paint = null;
PackagePart pp = getSheet().getPackagePart();
for (XmlObject obj : pr.selectPath("*")) {
- paint = selectPaint(obj, null, pp);
+ paint = selectPaint(obj, null, pp, theme);
if (paint != null) {
setValue(paint);
return true;
@@ -203,7 +202,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { if (fillRef == null) {
fillRef = getBgRef();
}
- paint = selectPaint(fillRef);
+ paint = selectPaint(fillRef, theme);
return paint;
}
@@ -365,9 +364,11 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { protected PaintStyle getPaint(XmlObject spPr, CTSchemeColor phClr) {
PaintStyle paint = null;
- PackagePart pp = getSheet().getPackagePart();
+ XSLFSheet sheet = getSheet();
+ PackagePart pp = sheet.getPackagePart();
+ XSLFTheme theme = sheet.getTheme();
for (XmlObject obj : spPr.selectPath("*")) {
- paint = selectPaint(obj, phClr, pp);
+ paint = selectPaint(obj, phClr, pp, theme);
if(paint != null) break;
}
return paint;
@@ -392,24 +393,23 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { *
* @return the applied Paint or null if none was applied
*/
- protected PaintStyle selectPaint(XmlObject obj, final CTSchemeColor phClr, final PackagePart parentPart) {
+ protected static PaintStyle selectPaint(XmlObject obj, final CTSchemeColor phClr, final PackagePart parentPart, final XSLFTheme theme) {
if (obj instanceof CTNoFillProperties) {
return null;
} else if (obj instanceof CTSolidColorFillProperties) {
- return selectPaint((CTSolidColorFillProperties)obj, phClr);
+ return selectPaint((CTSolidColorFillProperties)obj, phClr, theme);
} else if (obj instanceof CTBlipFillProperties) {
return selectPaint((CTBlipFillProperties)obj, parentPart);
} else if (obj instanceof CTGradientFillProperties) {
- return selectPaint((CTGradientFillProperties) obj, phClr);
+ return selectPaint((CTGradientFillProperties) obj, phClr, theme);
} else if (obj instanceof CTStyleMatrixReference) {
- return selectPaint((CTStyleMatrixReference)obj);
+ return selectPaint((CTStyleMatrixReference)obj, theme);
} else {
return null;
}
}
- protected PaintStyle selectPaint(CTSolidColorFillProperties solidFill, CTSchemeColor phClr) {
- final XSLFTheme theme = getSheet().getTheme();
+ protected static PaintStyle selectPaint(CTSolidColorFillProperties solidFill, CTSchemeColor phClr, final XSLFTheme theme) {
if (phClr == null && solidFill.isSetSchemeClr()) {
phClr = solidFill.getSchemeClr();
}
@@ -417,7 +417,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { return DrawPaint.createSolidPaint(c.getColorStyle());
}
- protected PaintStyle selectPaint(final CTBlipFillProperties blipFill, final PackagePart parentPart) {
+ protected static PaintStyle selectPaint(final CTBlipFillProperties blipFill, final PackagePart parentPart) {
final CTBlip blip = blipFill.getBlip();
return new TexturePaint() {
private PackagePart getPart() {
@@ -451,7 +451,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { };
}
- protected PaintStyle selectPaint(final CTGradientFillProperties gradFill, CTSchemeColor phClr) {
+ protected static PaintStyle selectPaint(final CTGradientFillProperties gradFill, CTSchemeColor phClr, final XSLFTheme theme) {
final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
@@ -465,7 +465,6 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { final ColorStyle cs[] = new ColorStyle[gs.length];
final float fractions[] = new float[gs.length];
- XSLFTheme theme = getSheet().getTheme();
int i=0;
for (CTGradientStop cgs : gs) {
@@ -519,7 +518,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { };
}
- protected PaintStyle selectPaint(CTStyleMatrixReference fillRef) {
+ protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme) {
if (fillRef == null) return null;
// The idx attribute refers to the index of a fill style or
@@ -529,8 +528,6 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
int idx = (int)fillRef.getIdx();
CTSchemeColor phClr = fillRef.getSchemeClr();
- XSLFSheet sheet = getSheet();
- XSLFTheme theme = sheet.getTheme();
XmlObject fillProps = null;
CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
if (idx >= 1 && idx <= 999) {
@@ -538,7 +535,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> { } else if (idx >= 1001 ){
fillProps = matrix.getBgFillStyleLst().selectPath("*")[idx - 1001];
}
- return (fillProps == null) ? null : selectPaint(fillProps, phClr, theme.getPackagePart());
+ return (fillProps == null) ? null : selectPaint(fillProps, phClr, theme.getPackagePart(), theme);
}
@Override
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index 1f3393d1f0..b90fbb0672 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -77,8 +77,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; /**
* Represents a single (non-group) shape in a .pptx slide show
- *
- * @author Yegor Kozlov
*/
@Beta
public abstract class XSLFSimpleShape extends XSLFShape
@@ -259,6 +257,7 @@ public abstract class XSLFSimpleShape extends XSLFShape }
protected PaintStyle getLinePaint() {
+ final XSLFTheme theme = getSheet().getTheme();
PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
public boolean fetch(XSLFShape shape) {
CTLineProperties spPr = shape.getSpPr().getLn();
@@ -271,7 +270,7 @@ public abstract class XSLFSimpleShape extends XSLFShape PaintStyle paint = null;
PackagePart pp = getSheet().getPackagePart();
for (XmlObject obj : spPr.selectPath("*")) {
- paint = selectPaint(obj, null, pp);
+ paint = selectPaint(obj, null, pp, theme);
if (paint != null) {
setValue(paint);
return true;
@@ -280,7 +279,7 @@ public abstract class XSLFSimpleShape extends XSLFShape CTShapeStyle style = shape.getSpStyle();
if (style != null) {
- paint = selectPaint(style.getLnRef());
+ paint = selectPaint(style.getLnRef(), theme);
if (paint != null) {
setValue(paint);
return true;
@@ -305,7 +304,6 @@ public abstract class XSLFSimpleShape extends XSLFShape int idx = (int)lnRef.getIdx();
CTSchemeColor phClr = lnRef.getSchemeClr();
if(idx > 0){
- XSLFTheme theme = getSheet().getTheme();
XmlObject lnProps = theme.getXmlObject().
getThemeElements().getFmtScheme().getLnStyleLst().selectPath("*")[idx - 1];
paint = getPaint(lnProps, phClr);
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java index 21472d709b..023c8f7b4e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java @@ -21,6 +21,7 @@ package org.apache.poi.xslf.usermodel; import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
+import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -29,6 +30,9 @@ import java.util.List; import javax.xml.namespace.QName;
import org.apache.poi.POIXMLException;
+import org.apache.poi.sl.draw.DrawFactory;
+import org.apache.poi.sl.draw.DrawTableShape;
+import org.apache.poi.sl.draw.DrawTextShape;
import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
@@ -45,12 +49,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra /**
* Represents a table in a .pptx presentation
- *
- * @author Yegor Kozlov
*/
public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow>,
TableShape<XSLFShape,XSLFTextParagraph> {
- static String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
+ /* package */ static final String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
private CTTable _table;
private List<XSLFTableRow> _rows;
@@ -77,7 +79,11 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow _table = (CTTable) rs[0];
CTTableRow[] trArray = _table.getTrArray();
_rows = new ArrayList<XSLFTableRow>(trArray.length);
- for(CTTableRow row : trArray) _rows.add(new XSLFTableRow(row, this));
+ for(CTTableRow row : trArray) {
+ XSLFTableRow xr = new XSLFTableRow(row, this);
+ _rows.add(xr);
+ }
+ updateRowColIndexes();
}
@Override
@@ -146,8 +152,10 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow public XSLFTableRow addRow(){
CTTableRow tr = _table.addNewTr();
XSLFTableRow row = new XSLFTableRow(tr, this);
- row.setHeight(20.0); // default height is 20 points
+ // default height is 20 points
+ row.setHeight(20.0);
_rows.add(row);
+ updateRowColIndexes();
return row;
}
@@ -224,4 +232,110 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow }
}
}
+
+ /**
+ * Get assigned TableStyle
+ *
+ * @return the assigned TableStyle
+ *
+ * @since POI 3.15-beta2
+ */
+ protected XSLFTableStyle getTableStyle() {
+ CTTable tab = getCTTable();
+ // TODO: support inline table style
+ if (!tab.isSetTblPr() || !tab.getTblPr().isSetTableStyleId()) {
+ return null;
+ }
+
+ String styleId = tab.getTblPr().getTableStyleId();
+ XSLFTableStyles styles = getSheet().getSlideShow().getTableStyles();
+ for (XSLFTableStyle style : styles.getStyles()) {
+ if (style.getStyleId().equals(styleId)) {
+ return style;
+ }
+ }
+ return null;
+ }
+
+ /* package */ void updateRowColIndexes() {
+ int rowIdx = 0;
+ for (XSLFTableRow xr : this) {
+ int colIdx = 0;
+ for (XSLFTableCell tc : xr) {
+ tc.setRowColIndex(rowIdx, colIdx);
+ colIdx++;
+ }
+ rowIdx++;
+ }
+ }
+
+ /* package */ void updateCellAnchor() {
+ int rows = getNumberOfRows();
+ int cols = getNumberOfColumns();
+
+ double colWidths[] = new double[cols];
+ double rowHeights[] = new double[rows];
+
+ for (int row=0; row<rows; row++) {
+ rowHeights[row] = getRowHeight(row);
+ }
+ for (int col=0; col<cols; col++) {
+ colWidths[col] = getColumnWidth(col);
+ }
+
+ Rectangle2D tblAnc = getAnchor();
+ DrawFactory df = DrawFactory.getInstance(null);
+
+ double newY = tblAnc.getY();
+
+ // #1 pass - determine row heights, the height values might be too low or 0 ...
+ for (int row=0; row<rows; row++) {
+ double maxHeight = 0;
+ for (int col=0; col<cols; col++) {
+ XSLFTableCell tc = getCell(row, col);
+ if (tc.getGridSpan() != 1 || tc.getRowSpan() != 1) {
+ continue;
+ }
+ // need to set the anchor before height calculation
+ tc.setAnchor(new Rectangle2D.Double(0,0,colWidths[col],0));
+ DrawTextShape dts = df.getDrawable(tc);
+ maxHeight = Math.max(maxHeight, dts.getTextHeight());
+ }
+ rowHeights[row] = Math.max(rowHeights[row],maxHeight);
+ }
+
+ // #2 pass - init properties
+ for (int row=0; row<rows; row++) {
+ double newX = tblAnc.getX();
+ for (int col=0; col<cols; col++) {
+ Rectangle2D bounds = new Rectangle2D.Double(newX, newY, colWidths[col], rowHeights[row]);
+ XSLFTableCell tc = getCell(row, col);
+ tc.setAnchor(bounds);
+ newX += colWidths[col]+DrawTableShape.borderSize;
+ }
+ newY += rowHeights[row]+DrawTableShape.borderSize;
+ }
+
+ // #3 pass - update merge info
+ for (int row=0; row<rows; row++) {
+ for (int col=0; col<cols; col++) {
+ XSLFTableCell tc = getCell(row, col);
+ Rectangle2D mergedBounds = tc.getAnchor();
+ for (int col2=col+1; col2<col+tc.getGridSpan(); col2++) {
+ assert(col2 < cols);
+ XSLFTableCell tc2 = getCell(row, col2);
+ assert(tc2.getGridSpan() == 1 && tc2.getRowSpan() == 1);
+ mergedBounds.add(tc2.getAnchor());
+ }
+ for (int row2=row+1; row2<row+tc.getRowSpan(); row2++) {
+ assert(row2 < rows);
+ XSLFTableCell tc2 = getCell(row2, col);
+ assert(tc2.getGridSpan() == 1 && tc2.getRowSpan() == 1);
+ mergedBounds.add(tc2.getAnchor());
+ }
+ tc.setAnchor(mergedBounds);
+ }
+ }
+
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java index d4c3822fe5..fc77468731 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java @@ -20,6 +20,7 @@ package org.apache.poi.xslf.usermodel;
import java.awt.Color;
+import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle;
@@ -30,18 +31,32 @@ import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.sl.usermodel.TableCell;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.Units;
+import org.apache.poi.xslf.usermodel.XSLFTableStyle.TablePartStyle;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTablePartStyle;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleTextStyle;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
+import org.openxmlformats.schemas.drawingml.x2006.main.STOnOffStyleType;
import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment;
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
@@ -52,14 +67,22 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType; */
public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,XSLFTextParagraph> {
private CTTableCellProperties _tcPr = null;
+ private final XSLFTable table;
+ private int row = 0, col = 0;
- /*package*/ XSLFTableCell(CTTableCell cell, XSLFSheet sheet){
- super(cell, sheet);
+ /**
+ * Volatile/temporary anchor - e.g. for rendering
+ */
+ private Rectangle2D anchor = null;
+
+ /*package*/ XSLFTableCell(CTTableCell cell, XSLFTable table){
+ super(cell, table.getSheet());
+ this.table = table;
}
@Override
protected CTTextBody getTextBody(boolean create){
- CTTableCell cell = (CTTableCell)getXmlObject();
+ CTTableCell cell = getCell();
CTTextBody txBody = cell.getTxBody();
if (txBody == null && create) {
txBody = cell.addNewTxBody();
@@ -80,7 +103,7 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, protected CTTableCellProperties getCellProperties(boolean create) {
if (_tcPr == null) {
- CTTableCell cell = (CTTableCell)getXmlObject();
+ CTTableCell cell = getCell();
_tcPr = cell.getTcPr();
if (_tcPr == null && create) {
_tcPr = cell.addNewTcPr();
@@ -190,28 +213,28 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, }
};
}
-
+
@Override
public void setBorderStyle(BorderEdge edge, StrokeStyle style) {
if (style == null) {
throw new IllegalArgumentException("StrokeStyle needs to be specified.");
}
-
+
LineCap cap = style.getLineCap();
if (cap != null) {
setBorderCap(edge, cap);
}
-
+
LineCompound compound = style.getLineCompound();
if (compound != null) {
setBorderCompound(edge, compound);
}
-
+
LineDash dash = style.getLineDash();
if (dash != null) {
setBorderDash(edge, dash);
}
-
+
double width = style.getLineWidth();
setBorderWidth(edge, width);
}
@@ -273,10 +296,9 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, }
CTLineProperties ln = setBorderDefaults(edge);
-
- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
- rgb.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});
- ln.addNewSolidFill().setSrgbClr(rgb);
+ CTSolidColorFillProperties fill = ln.addNewSolidFill();
+ XSLFColor c = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
+ c.setColor(color);
}
public Color getBorderColor(BorderEdge edge) {
@@ -284,12 +306,8 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, if (ln == null || ln.isSetNoFill() || !ln.isSetSolidFill()) return null;
CTSolidColorFillProperties fill = ln.getSolidFill();
- if (!fill.isSetSrgbClr()) {
- // TODO for now return null for all colors except explicit RGB
- return null;
- }
- byte[] val = fill.getSrgbClr().getVal();
- return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
+ XSLFColor c = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
+ return c.getColor();
}
public LineCompound getBorderCompound(BorderEdge edge) {
@@ -335,7 +353,7 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, if (ln == null || ln.isSetNoFill() || !ln.isSetSolidFill() || !ln.isSetCap()) {
return null;
}
-
+
return LineCap.fromOoxmlId(ln.getCap().intValue());
}
@@ -361,14 +379,10 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, CTTableCellProperties spPr = getCellProperties(true);
if (color == null) {
if(spPr.isSetSolidFill()) spPr.unsetSolidFill();
- }
- else {
+ } else {
CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill();
-
- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
- rgb.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
-
- fill.setSrgbClr(rgb);
+ XSLFColor c = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
+ c.setColor(color);
}
}
@@ -379,31 +393,126 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, @Override
public Color getFillColor(){
CTTableCellProperties spPr = getCellProperties(false);
- if (spPr == null || !spPr.isSetSolidFill()) return null;
+ if (spPr == null || !spPr.isSetSolidFill()) {
+ return null;
+ }
CTSolidColorFillProperties fill = spPr.getSolidFill();
- if (!fill.isSetSrgbClr()) {
- // TODO for now return null for all colors except explicit RGB
+ XSLFColor c = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
+ return c.getColor();
+ }
+
+ @SuppressWarnings("resource")
+ @Override
+ public PaintStyle getFillPaint() {
+ Color c = getFillColor();
+ if (c != null) {
+ return DrawPaint.createSolidPaint(c);
+ }
+
+ CTTablePartStyle tps = getTablePartStyle(null);
+ if (tps == null || !tps.isSetTcStyle()) {
+ tps = getTablePartStyle(TablePartStyle.wholeTbl);
+ if (tps == null || !tps.isSetTcStyle()) {
+ return null;
+ }
+ }
+
+ XMLSlideShow slideShow = table.getSheet().getSlideShow();
+ assert(slideShow != null);
+ XSLFTheme theme = slideShow.getSlides().get(0).getTheme();
+ CTFillProperties pr = tps.getTcStyle().getFill();
+
+ for (XmlObject obj : pr.selectPath("*")) {
+ PaintStyle paint = XSLFShape.selectPaint(obj, null, slideShow.getPackagePart(), theme);
+
+ if (paint != null) {
+ return paint;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Retrieves the part style depending on the location of this cell
+ *
+ * @param tablePartStyle the part to be returned, usually this is null
+ * and only set when used as a helper method
+ * @return the table part style
+ */
+ private CTTablePartStyle getTablePartStyle(TablePartStyle tablePartStyle) {
+ CTTable ct = table.getCTTable();
+ if (!ct.isSetTblPr()) {
+ return null;
+ }
+
+ CTTableProperties pr = ct.getTblPr();
+ boolean bandRow = (pr.isSetBandRow() && pr.getBandRow());
+ boolean firstRow = (pr.isSetFirstRow() && pr.getFirstRow());
+ boolean lastRow = (pr.isSetLastRow() && pr.getLastRow());
+ boolean bandCol = (pr.isSetBandCol() && pr.getBandCol());
+ boolean firstCol = (pr.isSetFirstCol() && pr.getFirstCol());
+ boolean lastCol = (pr.isSetLastCol() && pr.getLastCol());
+
+ TablePartStyle tps;
+ if (tablePartStyle != null) {
+ tps = tablePartStyle;
+ } else if (row == 0 && firstRow) {
+ tps = TablePartStyle.firstRow;
+ } else if (row == table.getNumberOfRows()-1 && lastRow) {
+ tps = TablePartStyle.lastRow;
+ } else if (col == 0 && firstCol) {
+ tps = TablePartStyle.firstCol;
+ } else if (col == table.getNumberOfColumns()-1 && lastCol) {
+ tps = TablePartStyle.lastCol;
+ } else {
+ tps = TablePartStyle.wholeTbl;
+
+ int br = row + (firstRow ? 1 : 0);
+ int bc = col + (firstCol ? 1 : 0);
+ if (bandRow && (br & 1) == 0) {
+ tps = TablePartStyle.band1H;
+ } else if (bandCol && (bc & 1) == 0) {
+ tps = TablePartStyle.band1V;
+ }
+ }
+
+ XSLFTableStyle tabStyle = table.getTableStyle();
+ if (tabStyle == null) {
return null;
}
- byte[] val = fill.getSrgbClr().getVal();
- return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
+
+ CTTablePartStyle part = tabStyle.getTablePartStyle(tps);
+ return (part == null) ? tabStyle.getTablePartStyle(TablePartStyle.wholeTbl) : part;
}
void setGridSpan(int gridSpan_) {
- ((CTTableCell)getXmlObject()).setGridSpan(gridSpan_);
+ getCell().setGridSpan(gridSpan_);
+ }
+
+ @Override
+ public int getGridSpan() {
+ CTTableCell c = getCell();
+ return (c.isSetGridSpan()) ? c.getGridSpan() : 1;
}
void setRowSpan(int rowSpan_) {
- ((CTTableCell)getXmlObject()).setRowSpan(rowSpan_);
+ getCell().setRowSpan(rowSpan_);
+ }
+
+ @Override
+ public int getRowSpan() {
+ CTTableCell c = getCell();
+ return (c.isSetRowSpan()) ? c.getRowSpan() : 1;
}
void setHMerge(boolean merge_) {
- ((CTTableCell)getXmlObject()).setHMerge(merge_);
+ getCell().setHMerge(merge_);
}
void setVMerge(boolean merge_) {
- ((CTTableCell)getXmlObject()).setVMerge(merge_);
+ getCell().setVMerge(merge_);
}
@Override
@@ -457,7 +566,7 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, vt = STTextVerticalType.WORD_ART_VERT;
break;
}
-
+
cellProps.setVert(vt);
}
}
@@ -475,7 +584,7 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, } else {
orientation = STTextVerticalType.HORZ;
}
-
+
switch (orientation.intValue()) {
default:
case STTextVerticalType.INT_HORZ:
@@ -491,4 +600,142 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape, return TextDirection.STACKED;
}
}
-}
+
+ private CTTableCell getCell() {
+ return (CTTableCell)getXmlObject();
+ }
+
+ /* package */ void setRowColIndex(int row, int col) {
+ this.row = row;
+ this.col = col;
+ }
+
+ /**
+ * Return a fake-xfrm which is used for calculating the text height
+ */
+ protected CTTransform2D getXfrm() {
+ Rectangle2D anc = getAnchor();
+ CTTransform2D xfrm = CTTransform2D.Factory.newInstance();
+ CTPoint2D off = xfrm.addNewOff();
+ off.setX(Units.toEMU(anc.getX()));
+ off.setY(Units.toEMU(anc.getY()));
+ CTPositiveSize2D size = xfrm.addNewExt();
+ size.setCx(Units.toEMU(anc.getWidth()));
+ size.setCy(Units.toEMU(anc.getHeight()));
+ return xfrm;
+ }
+
+ /**
+ * There's no real anchor for table cells - this method is used to temporarily store the location
+ * of the cell for a later retrieval, e.g. for rendering
+ *
+ * @since POI 3.15-beta2
+ */
+ @Override
+ public void setAnchor(Rectangle2D anchor) {
+ if (this.anchor == null) {
+ this.anchor = (Rectangle2D)anchor.clone();
+ } else {
+ this.anchor.setRect(anchor);
+ }
+ }
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ @Override
+ public Rectangle2D getAnchor() {
+ if (anchor == null) {
+ table.updateCellAnchor();
+ }
+ // anchor should be set, after updateCellAnchor is through
+ assert(anchor != null);
+ return anchor;
+ }
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ @Override
+ public boolean isMerged() {
+ CTTableCell c = getCell();
+ return (c.isSetHMerge() && c.getHMerge()) || (c.isSetVMerge() && c.getVMerge());
+ }
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ @Override
+ protected XSLFCellTextParagraph newTextParagraph(CTTextParagraph p) {
+ return new XSLFCellTextParagraph(p, this);
+ }
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ private class XSLFCellTextParagraph extends XSLFTextParagraph {
+ protected XSLFCellTextParagraph(CTTextParagraph p, XSLFTextShape shape) {
+ super(p, shape);
+ }
+
+ @Override
+ protected XSLFCellTextRun newTextRun(CTRegularTextRun r) {
+ return new XSLFCellTextRun(r, this);
+ }
+ }
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ private class XSLFCellTextRun extends XSLFTextRun {
+ protected XSLFCellTextRun(CTRegularTextRun r, XSLFTextParagraph p) {
+ super(r, p);
+ }
+
+ @Override
+ public PaintStyle getFontColor(){
+ CTTableStyleTextStyle txStyle = getTextStyle();
+ if (txStyle == null) {
+ return super.getFontColor();
+ }
+
+ 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);
+ return DrawPaint.createSolidPaint(c.getColorStyle());
+ }
+
+ @Override
+ public boolean isBold() {
+ CTTableStyleTextStyle txStyle = getTextStyle();
+ if (txStyle == null) {
+ return super.isBold();
+ } else {
+ return txStyle.isSetB() && txStyle.getB().intValue() == STOnOffStyleType.INT_ON;
+ }
+ }
+
+ @Override
+ public boolean isItalic() {
+ CTTableStyleTextStyle txStyle = getTextStyle();
+ if (txStyle == null) {
+ return super.isItalic();
+ } else {
+ return txStyle.isSetI() && txStyle.getI().intValue() == STOnOffStyleType.INT_ON;
+ }
+ }
+
+ private CTTableStyleTextStyle getTextStyle() {
+ CTTablePartStyle tps = getTablePartStyle(null);
+ if (tps == null || !tps.isSetTcTxStyle()) {
+ tps = getTablePartStyle(TablePartStyle.wholeTbl);
+ }
+ return (tps == null) ? null : tps.getTcTxStyle();
+ }
+ }
+}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java index 491583f5aa..5326d9e784 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java @@ -30,8 +30,6 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow; /**
* Represents a table in a .pptx presentation
- *
- * @author Yegor Kozlov
*/
public class XSLFTableRow implements Iterable<XSLFTableCell> {
private CTTableRow _row;
@@ -44,7 +42,7 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> { CTTableCell[] tcArray = _row.getTcArray();
_cells = new ArrayList<XSLFTableCell>(tcArray.length);
for(CTTableCell cell : tcArray) {
- _cells.add(new XSLFTableCell(cell, table.getSheet()));
+ _cells.add(new XSLFTableCell(cell, table));
}
}
@@ -71,12 +69,13 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> { public XSLFTableCell addCell(){
CTTableCell c = _row.addNewTc();
c.set(XSLFTableCell.prototype());
- XSLFTableCell cell = new XSLFTableCell(c, _table.getSheet());
+ XSLFTableCell cell = new XSLFTableCell(c, _table);
_cells.add(cell);
if(_table.getNumberOfColumns() < _row.sizeOfTcArray()) {
_table.getCTTable().getTblGrid().addNewGridCol().setW(Units.toEMU(100.0));
}
+ _table.updateRowColIndexes();
return cell;
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java index 31840314b9..b3bcdfabd9 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyle.java @@ -19,16 +19,19 @@ package org.apache.poi.xslf.usermodel;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTablePartStyle;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
/**
- * Represents a table in a .pptx presentation
- *
- * @author Yegor Kozlov
+ * Represents a table style in a .pptx presentation
*/
public class XSLFTableStyle {
private CTTableStyle _tblStyle;
+ public enum TablePartStyle {
+ wholeTbl, band1H, band2H, band1V, band2V, firstCol, lastCol, firstRow, lastRow, seCell, swCell, neCell, nwCell;
+ }
+
/*package*/ XSLFTableStyle(CTTableStyle style){
_tblStyle = style;
}
@@ -44,4 +47,39 @@ public class XSLFTableStyle { public String getStyleId(){
return _tblStyle.getStyleId();
}
+
+ /**
+ * @since POI 3.15-beta2
+ */
+ protected CTTablePartStyle getTablePartStyle(TablePartStyle tps) {
+ switch (tps) {
+ default:
+ case wholeTbl:
+ return _tblStyle.getWholeTbl();
+ case band1H:
+ return _tblStyle.getBand1H();
+ case band2H:
+ return _tblStyle.getBand2H();
+ case band1V:
+ return _tblStyle.getBand1V();
+ case band2V:
+ return _tblStyle.getBand2V();
+ case firstCol:
+ return _tblStyle.getFirstCol();
+ case lastCol:
+ return _tblStyle.getLastCol();
+ case firstRow:
+ return _tblStyle.getFirstRow();
+ case lastRow:
+ return _tblStyle.getLastRow();
+ case seCell:
+ return _tblStyle.getSeCell();
+ case swCell:
+ return _tblStyle.getSwCell();
+ case neCell:
+ return _tblStyle.getNeCell();
+ case nwCell:
+ return _tblStyle.getNwCell();
+ }
+ }
}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java index 76455d64df..410f84101d 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableStyles.java @@ -16,9 +16,8 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; -import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; - import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -31,6 +30,7 @@ import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle; import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleList; +import org.openxmlformats.schemas.drawingml.x2006.main.TblStyleLstDocument; @Beta public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLFTableStyle>{ @@ -47,7 +47,10 @@ public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLF public XSLFTableStyles(PackagePart part) throws IOException, XmlException { super(part); - _tblStyleLst = CTTableStyleList.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); + InputStream is = getPackagePart().getInputStream(); + TblStyleLstDocument styleDoc = TblStyleLstDocument.Factory.parse(is); + is.close(); + _tblStyleLst = styleDoc.getTblStyleLst(); CTTableStyle[] tblStyleArray = _tblStyleLst.getTblStyleArray(); _styles = new ArrayList<XSLFTableStyle>(tblStyleArray.length); for(CTTableStyle c : tblStyleArray){ diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index 9576eea3c2..b2a8b3314b 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -59,7 +59,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; * Represents a paragraph of text within the containing text body.
* The paragraph is the highest level text separation mechanism.
*
- * @author Yegor Kozlov
* @since POI-3.8
*/
@Beta
@@ -76,19 +75,19 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr for(XmlObject ch : _p.selectPath("*")){
if(ch instanceof CTRegularTextRun){
CTRegularTextRun r = (CTRegularTextRun)ch;
- _runs.add(new XSLFTextRun(r, this));
+ _runs.add(newTextRun(r));
} else if (ch instanceof CTTextLineBreak){
CTTextLineBreak br = (CTTextLineBreak)ch;
CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
r.setRPr(br.getRPr());
r.setT("\n");
- _runs.add(new XSLFTextRun(r, this));
+ _runs.add(newTextRun(r));
} else if (ch instanceof CTTextField){
CTTextField f = (CTTextField)ch;
CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
r.setRPr(f.getRPr());
r.setT(f.getT());
- _runs.add(new XSLFTextRun(r, this));
+ _runs.add(newTextRun(r));
}
}
}
@@ -137,7 +136,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr CTRegularTextRun r = _p.addNewR();
CTTextCharacterProperties rPr = r.addNewRPr();
rPr.setLang("en-US");
- XSLFTextRun run = new XSLFTextRun(r, this);
+ XSLFTextRun run = newTextRun(r);
_runs.add(run);
return run;
}
@@ -774,22 +773,23 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr int level = getIndentLevel();
// wind up and find the root master sheet which must be slide master
- final String nsDecl =
- "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " +
- "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' ";
- final String xpaths[] = {
- nsDecl+".//p:txStyles/p:" + defaultStyleSelector +"/a:lvl" +(level+1)+ "pPr",
- nsDecl+".//p:notesStyle/a:lvl" +(level+1)+ "pPr"
- };
+ final String nsPML = "http://schemas.openxmlformats.org/presentationml/2006/main";
+ final String nsDML = "http://schemas.openxmlformats.org/drawingml/2006/main";
XSLFSheet masterSheet = _shape.getSheet();
for (XSLFSheet m = masterSheet; m != null; m = (XSLFSheet)m.getMasterSheet()) {
masterSheet = m;
XmlObject xo = masterSheet.getXmlObject();
- for (String xpath : xpaths) {
- XmlObject[] o = xo.selectPath(xpath);
- if (o.length == 1) {
- return (CTTextParagraphProperties)o[0];
+ XmlCursor cur = xo.newCursor();
+ try {
+ cur.push();
+ if ((cur.toChild(nsPML, "txStyles") && cur.toChild(nsPML, defaultStyleSelector)) ||
+ (cur.pop() && cur.toChild(nsPML, "notesStyle"))) {
+ if (cur.toChild(nsDML, "lvl" +(level+1)+ "pPr")) {
+ return (CTTextParagraphProperties)cur.getObject();
+ }
}
+ } finally {
+ cur.dispose();
}
}
@@ -880,7 +880,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr List<XSLFTextRun> otherRs = other.getTextRuns();
int i=0;
for(CTRegularTextRun rtr : thisP.getRArray()) {
- XSLFTextRun run = new XSLFTextRun(rtr, this);
+ XSLFTextRun run = newTextRun(rtr);
run.copy(otherRs.get(i++));
_runs.add(run);
}
@@ -949,6 +949,9 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr @Override
public Double getDefaultFontSize() {
CTTextCharacterProperties endPr = _p.getEndParaRPr();
+ if (endPr == null || !endPr.isSetSz()) {
+ endPr = getDefaultMasterStyle().getDefRPr();
+ }
return (endPr == null || !endPr.isSetSz()) ? 12 : (endPr.getSz() / 100.);
}
@@ -1062,4 +1065,17 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr return false;
}
}
+
+ /**
+ * Helper method to allow subclasses to provide their own text run
+ *
+ * @param r the xml reference
+ *
+ * @return a new text paragraph
+ *
+ * @since POI 3.15-beta2
+ */
+ protected XSLFTextRun newTextRun(CTRegularTextRun r) {
+ return new XSLFTextRun(r, this);
+ }
}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java index 1a6bcc384a..c374c4016b 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java @@ -30,15 +30,13 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; /**
* 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
public class XSLFTextRun implements TextRun {
private final CTRegularTextRun _r;
private final XSLFTextParagraph _p;
- XSLFTextRun(CTRegularTextRun r, XSLFTextParagraph p){
+ protected XSLFTextRun(CTRegularTextRun r, XSLFTextParagraph p){
_r = r;
_p = p;
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java index f38ea9701e..a4400d21ba 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java @@ -62,7 +62,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape CTTextBody txBody = getTextBody(false); if (txBody != null) { for (CTTextParagraph p : txBody.getPArray()) { - _paragraphs.add(new XSLFTextParagraph(p, this)); + _paragraphs.add(newTextParagraph(p)); } } } @@ -100,13 +100,13 @@ public abstract class XSLFTextShape extends XSLFSimpleShape txBody.removeP(i-1); _paragraphs.remove(i-1); } - + _paragraphs.get(0).clearButKeepProperties(); } - + return appendText(text, false); } - + @Override public XSLFTextRun appendText(String text, boolean newParagraph) { if (text == null) return null; @@ -114,7 +114,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape // copy properties from last paragraph / textrun or paragraph end marker CTTextParagraphProperties pPr = null; CTTextCharacterProperties rPr = null; - + boolean firstPara; XSLFTextParagraph para; if (_paragraphs.isEmpty()) { @@ -133,7 +133,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape rPr = ctp.getEndParaRPr(); } } - + XSLFTextRun run = null; for (String lineTxt : text.split("\\r\\n?|\\n")) { if (!firstPara) { @@ -159,7 +159,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape } firstPara = false; } - + assert(run != null); return run; } @@ -184,7 +184,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape } else { p = txBody.addNewP(); } - XSLFTextParagraph paragraph = new XSLFTextParagraph(p, this); + XSLFTextParagraph paragraph = newTextParagraph(p); _paragraphs.add(paragraph); return paragraph; } @@ -243,7 +243,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape fetchShapeProperty(fetcher); return fetcher.getValue() == null ? false : fetcher.getValue(); } - + @Override public void setTextDirection(TextDirection orientation){ CTTextBodyProperties bodyPr = getTextBodyPr(true); @@ -274,9 +274,9 @@ public abstract class XSLFTextShape extends XSLFSimpleShape if (bodyPr != null && bodyPr.isSetRot()) { return bodyPr.getRot() / 60000.; } - return null; + return null; } - + @Override public void setTextRotation(Double rotation) { CTTextBodyProperties bodyPr = getTextBodyPr(true); @@ -284,8 +284,8 @@ public abstract class XSLFTextShape extends XSLFSimpleShape bodyPr.setRot((int)(rotation * 60000.)); } } - - + + /** * Returns the distance (in points) between the bottom of the text frame * and the bottom of the inscribed rectangle of the shape that contains the text. @@ -437,7 +437,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape Insets2D insets = new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset()); return insets; } - + @Override public void setInsets(Insets2D insets) { setTopInset(insets.top); @@ -445,7 +445,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape setBottomInset(insets.bottom); setRightInset(insets.right); } - + @Override public boolean getWordWrap(){ PropertyFetcher<Boolean> fetcher = new TextBodyPropertyFetcher<Boolean>(){ @@ -520,14 +520,14 @@ public abstract class XSLFTextShape extends XSLFSimpleShape } return textBodyPr; } - + protected abstract CTTextBody getTextBody(boolean create); @Override public void setPlaceholder(Placeholder placeholder) { super.setPlaceholder(placeholder); } - + public Placeholder getTextType(){ CTPlaceholder ph = getCTPlaceholder(); if (ph == null) return null; @@ -552,15 +552,15 @@ public abstract class XSLFTextShape extends XSLFSimpleShape Rectangle2D anchor = getAnchor(); if(anchor.getWidth() == 0.) throw new POIXMLException( "Anchor of the shape was not set."); - double height = getTextHeight(); + double height = getTextHeight(); height += 1; // add a pixel to compensate rounding errors - + anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height); setAnchor(anchor); - + return anchor; - } - + } + @Override void copy(XSLFShape other){ @@ -572,14 +572,14 @@ public abstract class XSLFTextShape extends XSLFSimpleShape if (otherTB == null) { return; } - + thisTB.setBodyPr((CTTextBodyProperties)otherTB.getBodyPr().copy()); if (thisTB.isSetLstStyle()) thisTB.unsetLstStyle(); if (otherTB.isSetLstStyle()) { thisTB.setLstStyle((CTTextListStyle)otherTB.getLstStyle().copy()); } - + boolean srcWordWrap = otherTS.getWordWrap(); if(srcWordWrap != getWordWrap()){ setWordWrap(srcWordWrap); @@ -608,7 +608,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape } clearText(); - + for (XSLFTextParagraph srcP : otherTS.getTextParagraphs()) { XSLFTextParagraph tgtP = addNewTextParagraph(); tgtP.copy(srcP); @@ -621,7 +621,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape default: case NOTES: case HALF_BODY: - case QUARTER_BODY: + case QUARTER_BODY: case BODY: setPlaceholder(Placeholder.BODY); break; @@ -651,8 +651,19 @@ public abstract class XSLFTextShape extends XSLFSimpleShape case CENTERED_TITLE: return TextPlaceholder.CENTER_TITLE; default: case CONTENT: return TextPlaceholder.OTHER; - } + } + } + + /** + * Helper method to allow subclasses to provide their own text paragraph + * + * @param p the xml reference + * + * @return a new text paragraph + * + * @since POI 3.15-beta2 + */ + protected XSLFTextParagraph newTextParagraph(CTTextParagraph p) { + return new XSLFTextParagraph(p, this); } - - }
\ No newline at end of file |