aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-12-12 23:15:20 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-12-12 23:15:20 +0000
commitc5f6dfa68e04c5a42b64b3f862756b9c990665dc (patch)
treeabeaa3d26edfb046c64ef744451648999b0d3a53 /src
parent1f072afe18b3022f90a7f2dae52b9606b459e045 (diff)
downloadpoi-c5f6dfa68e04c5a42b64b3f862756b9c990665dc.tar.gz
poi-c5f6dfa68e04c5a42b64b3f862756b9c990665dc.zip
Bug 56205 - Upgrade OOXML schema to 3rd edition (transitional)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884368 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/util/Units.java38
-rw-r--r--src/multimodule/ooxml-lite/java9/module-info.classbin1528 -> 1599 bytes
-rw-r--r--src/multimodule/ooxml-lite/java9/module-info.java1
-rw-r--r--src/ooxml/java/org/apache/poi/ooxml/util/POIXMLUnits.java265
-rw-r--r--src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorHsl.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorPreset.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorRgbPercent.java33
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFDashStop.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientStop.java3
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLineJoinMiterProperties.java3
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFPoint2D.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFRelativeRectangle.java11
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFTileInfoProperties.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java10
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java3
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java3
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java24
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComment.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java8
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGradientPaint.java14
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java35
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java8
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTabStop.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java15
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java4
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java19
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java13
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTexturePaint.java24
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java57
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java7
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java11
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSignatureLine.java5
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java85
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java18
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFSingleXmlCell.java39
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFXmlColumnPr.java9
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/model/WMLHelper.java33
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java33
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultParagraphStyle.java14
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultRunStyle.java14
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java80
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java66
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java55
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java18
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java12
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java18
-rw-r--r--src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zipbin0 -> 99115 bytes
-rw-r--r--src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zipbin222730 -> 0 bytes
-rw-r--r--src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zipbin3349 -> 3037 bytes
-rw-r--r--src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java17
-rw-r--r--src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java3
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java9
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java4
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java112
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java22
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java106
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java968
78 files changed, 1438 insertions, 1165 deletions
diff --git a/src/java/org/apache/poi/util/Units.java b/src/java/org/apache/poi/util/Units.java
index 599e443f63..1aad77db8b 100644
--- a/src/java/org/apache/poi/util/Units.java
+++ b/src/java/org/apache/poi/util/Units.java
@@ -29,11 +29,17 @@ public class Units {
public static final int EMU_PER_POINT = 12700;
public static final int EMU_PER_CENTIMETER = 360000;
+ /** 72 points per inch (dpi) */
+ public static final int EMU_PER_INCH = 12700*72;
+
+ /** EMU_PER_POINT/20 */
+ public static final int EMU_PER_DXA = 635;
+
/**
* Master DPI (576 pixels per inch).
* Used by the reference coordinate system in PowerPoint (HSLF)
*/
- public static final int MASTER_DPI = 576;
+ public static final int MASTER_DPI = 576;
/**
* Pixels DPI (96 pixels per inch)
@@ -43,7 +49,7 @@ public class Units {
/**
* Points DPI (72 pixels per inch)
*/
- public static final int POINT_DPI = 72;
+ public static final int POINT_DPI = 72;
/**
@@ -59,7 +65,7 @@ public class Units {
/**
* Column widths are in fractional characters, this is the EMU equivalent.
- * One character is defined as the widest value for the integers 0-9 in the
+ * One character is defined as the widest value for the integers 0-9 in the
* default font.
*/
public static final int EMU_PER_CHARACTER = (int) (EMU_PER_PIXEL * DEFAULT_CHARACTER_WIDTH);
@@ -72,7 +78,7 @@ public class Units {
public static int toEMU(double points){
return (int)Math.rint(EMU_PER_POINT*points);
}
-
+
/**
* Converts pixels to EMUs
* @param pixels pixels
@@ -88,15 +94,15 @@ public class Units {
* @return points
*/
public static double toPoints(long emu){
- return (double)emu/EMU_PER_POINT;
+ return (emu == -1) ? -1.d : (double)emu/EMU_PER_POINT;
}
-
+
/**
* Converts a value of type FixedPoint to a floating point
*
* @param fixedPoint value in fixed point notation
* @return floating point (double)
- *
+ *
* @see <a href="http://msdn.microsoft.com/en-us/library/dd910765(v=office.12).aspx">[MS-OSHARED] - 2.2.1.6 FixedPoint</a>
*/
public static double fixedPointToDouble(int fixedPoint) {
@@ -104,13 +110,13 @@ public class Units {
int f = fixedPoint & 0xFFFF;
return (i + f/65536d);
}
-
+
/**
* Converts a value of type floating point to a FixedPoint
*
* @param floatPoint value in floating point notation
* @return fixedPoint value in fixed points notation
- *
+ *
* @see <a href="http://msdn.microsoft.com/en-us/library/dd910765(v=office.12).aspx">[MS-OSHARED] - 2.2.1.6 FixedPoint</a>
*/
public static int doubleToFixedPoint(double floatPoint) {
@@ -133,7 +139,7 @@ public class Units {
points /= POINT_DPI;
return (int)Math.rint(points);
}
-
+
public static int pointsToPixel(double points) {
points *= PIXEL_DPI;
points /= POINT_DPI;
@@ -178,7 +184,7 @@ public class Units {
public static int charactersToEMU(double characters) {
return (int) characters * EMU_PER_CHARACTER;
}
-
+
/**
* @param columnWidth specified in 256ths of a standard character
* @return equivalent EMUs
@@ -186,12 +192,8 @@ public class Units {
public static int columnWidthToEMU(int columnWidth) {
return charactersToEMU(columnWidth / 256d);
}
-
- /**
- * @param twips (1/20th of a point) typically used for row heights
- * @return equivalent EMUs
- */
- public static int TwipsToEMU(short twips) {
- return (int) (twips / 20d * EMU_PER_POINT);
+
+ public static double toDXA(long emu) {
+ return (emu == -1) ? -1.d : (double)emu/EMU_PER_DXA;
}
}
diff --git a/src/multimodule/ooxml-lite/java9/module-info.class b/src/multimodule/ooxml-lite/java9/module-info.class
index 8cc8de8e16..f6cd8ef67d 100644
--- a/src/multimodule/ooxml-lite/java9/module-info.class
+++ b/src/multimodule/ooxml-lite/java9/module-info.class
Binary files differ
diff --git a/src/multimodule/ooxml-lite/java9/module-info.java b/src/multimodule/ooxml-lite/java9/module-info.java
index 6736f8669c..1b22147d88 100644
--- a/src/multimodule/ooxml-lite/java9/module-info.java
+++ b/src/multimodule/ooxml-lite/java9/module-info.java
@@ -41,6 +41,7 @@ open module org.apache.poi.ooxml.schemas {
exports org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes;
exports org.openxmlformats.schemas.officeDocument.x2006.extendedProperties;
exports org.openxmlformats.schemas.officeDocument.x2006.relationships;
+ exports org.openxmlformats.schemas.officeDocument.x2006.sharedTypes;
exports org.openxmlformats.schemas.presentationml.x2006.main;
exports org.openxmlformats.schemas.spreadsheetml.x2006.main;
exports org.openxmlformats.schemas.wordprocessingml.x2006.main;
diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLUnits.java b/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLUnits.java
new file mode 100644
index 0000000000..b2538f2ff9
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/ooxml/util/POIXMLUnits.java
@@ -0,0 +1,265 @@
+/* ====================================================================
+ 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.ooxml.util;
+
+import static org.apache.poi.util.Units.EMU_PER_DXA;
+import static org.apache.poi.util.Units.EMU_PER_INCH;
+import static org.apache.poi.util.Units.EMU_PER_POINT;
+
+import java.util.Locale;
+
+public class POIXMLUnits {
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPositivePercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPositiveFixedPercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Specifies the percentage of the text size that this bullet should be. It is specified here in terms of
+ * 100% being equal to 100000 and 1% being specified in increments of 1000. This attribute should not be
+ * lower than 25%, or 25000, and not be higher than 400%, or 400000.
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextBulletSizePercent pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextSpacingPercentOrPercentString pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextFontScalePercentOrPercentString pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * This type seems to be interpreted as percent value when the trailing percent sign is missing.<br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * &lt;w:zoom w:percent="50" /&gt;
+ * <pre>
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDecimalNumberOrPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+ /**
+ * This type seems to be interpreted as percent value when the trailing percent sign is missing.<br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * &lt;w:textscale w:w="50" /&gt;
+ * <pre>
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextScale pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STGapAmount pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STOverlap pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STDepthPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STHPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ private static int parsePercentInner(org.apache.xmlbeans.XmlAnySimpleType pctUnion, int noUnitScale) {
+ String strVal = pctUnion.getStringValue();
+ if (strVal.endsWith("%")) {
+ return Integer.parseInt(strVal.substring(0, strVal.length()-1)) * 1000;
+ } else {
+ return Integer.parseInt(strVal) * noUnitScale;
+ }
+ }
+
+ /**
+ * The standard states that ST_Coordinate32 is read and written as either a length
+ * followed by a unit, or EMUs with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STCoordinate32 coordUnion) {
+ return parseLengthInner(coordUnion, 1d);
+ }
+
+ /**
+ * The standard states that ST_Coordinate is read and written as either a length
+ * followed by a unit, or EMUs with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STCoordinate coordUnion) {
+ return parseLengthInner(coordUnion, 1d);
+ }
+
+ /**
+ * The standard states that ST_TextPoint is read and written as a length followed by a unit
+ * or as hundredths of a point with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STTextPoint coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT/100d);
+ }
+
+ /**
+ * If no unit is specified, a twips-measure is a twentieth of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTwipsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+ /**
+ * If no unit is specified, a twips-measure is a twentieth of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STSignedTwipsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+ /**
+ * If no unit is specified, a hps-measure is a half of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STHpsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT*2d);
+ }
+
+
+ /**
+ * If no unit is specified, a hps-measure is a half of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STSignedHpsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT*2d);
+ }
+
+
+ /**
+ * If not unit is specified, DXA (twentieth of a point) is assumed
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STMeasurementOrPercent coordUnion) {
+ if (coordUnion.getStringValue().endsWith("%")) return -1;
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+
+ /**
+ * Returns the EMUs for the given measurment (mm|cm|in|pt|pc|pi, defaults to EMUs*noUnitEmuFactor if not specified)
+ *
+ * @param coordUnion the raw type
+ * @return the EMUs for the given attribute
+ */
+ private static long parseLengthInner(org.apache.xmlbeans.XmlAnySimpleType coordUnion, double noUnitEmuFactor) {
+ String strVal = coordUnion.getStringValue().toLowerCase(Locale.ROOT);
+ double digVal = Double.parseDouble(strVal.replaceAll("(mm|cm|in|pt|pc|pi)", ""));
+ long emu = 0;
+ // http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
+ if (strVal.endsWith("mm")) {
+ emu = (long)(((digVal/10f)/2.54f)*EMU_PER_INCH);
+ } else if (strVal.endsWith("cm")) {
+ emu = (long)((digVal/2.54f)*EMU_PER_INCH);
+ } else if (strVal.endsWith("in")) {
+ emu = (long)(digVal*EMU_PER_INCH);
+ } else if (strVal.endsWith("pc") || strVal.endsWith("pi")) {
+ emu = (long)(digVal*0.166f*EMU_PER_INCH);
+ } else if (strVal.endsWith("pt")) {
+ emu = (long)(digVal*EMU_PER_POINT);
+ } else {
+ emu = (long)(digVal*noUnitEmuFactor);
+ }
+ return emu;
+ }
+
+
+
+ public static boolean parseOnOff(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff onOff) {
+ if(onOff == null) return false;
+ if(!onOff.isSetVal()) return true;
+ return parseOnOff(onOff.xgetVal());
+ }
+
+ public static boolean parseOnOff(org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff onOff) {
+ if (onOff == null) return false;
+ String str = onOff.getStringValue();
+ return ("true".equalsIgnoreCase(str) || "on".equalsIgnoreCase(str) || "x".equalsIgnoreCase(str) || "1".equals(str));
+ }
+
+}
diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
index 075ac95a6a..c6dcde6d74 100644
--- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
+++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/SignatureLine.java
@@ -42,7 +42,6 @@ import javax.imageio.ImageIO;
import javax.xml.namespace.QName;
import com.microsoft.schemas.office.office.CTSignatureLine;
-import com.microsoft.schemas.office.office.STTrueFalse;
import com.microsoft.schemas.vml.CTGroup;
import com.microsoft.schemas.vml.CTImageData;
import com.microsoft.schemas.vml.CTShape;
@@ -56,6 +55,7 @@ import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.draw.ImageRenderer;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
/**
* Base class for SignatureLines (XSSF,XWPF only)
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorHsl.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorHsl.java
index a25296de83..3eea2d6279 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorHsl.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorHsl.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
@@ -60,7 +61,7 @@ public class XDDFColorHsl extends XDDFColor {
}
public int getSaturation() {
- return color.getSat2();
+ return POIXMLUnits.parsePercent(color.xgetSat2()) / 1000;
}
public void setSaturation(int saturation) {
@@ -68,7 +69,7 @@ public class XDDFColorHsl extends XDDFColor {
}
public int getLuminance() {
- return color.getLum2();
+ return POIXMLUnits.parsePercent(color.xgetLum2()) / 1000;
}
public void setLuminance(int lightness) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorPreset.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorPreset.java
index 9b477f8ba0..5ec7d07e1e 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorPreset.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorPreset.java
@@ -50,7 +50,7 @@ public class XDDFColorPreset extends XDDFColor {
}
public PresetColor getValue() {
- if (color.isSetVal()) {
+ if (color.xgetVal() != null) {
return PresetColor.valueOf(color.getVal());
} else {
return null;
@@ -59,8 +59,9 @@ public class XDDFColorPreset extends XDDFColor {
public void setValue(PresetColor value) {
if (value == null) {
- if (color.isSetVal()) {
- color.unsetVal();
+ if (color.xgetVal() != null) {
+ // TODO: val is a requires attribute - removing a preset must be done in the parent container
+ color.setVal(PresetColor.WHITE.underlying);
}
} else {
color.setVal(value.underlying);
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorRgbPercent.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorRgbPercent.java
index a7eefebfc1..4e0563e1a8 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorRgbPercent.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFColorRgbPercent.java
@@ -19,15 +19,17 @@ package org.apache.poi.xddf.usermodel;
import java.util.Locale;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPercentage;
@Beta
public class XDDFColorRgbPercent extends XDDFColor {
- private CTScRgbColor color;
+ private final CTScRgbColor color;
public XDDFColorRgbPercent(int red, int green, int blue) {
this(CTScRgbColor.Factory.newInstance(), CTColor.Factory.newInstance());
@@ -54,7 +56,7 @@ public class XDDFColorRgbPercent extends XDDFColor {
}
public int getRed() {
- return color.getR();
+ return POIXMLUnits.parsePercent(color.xgetR());
}
public void setRed(int red) {
@@ -62,7 +64,7 @@ public class XDDFColorRgbPercent extends XDDFColor {
}
public int getGreen() {
- return color.getG();
+ return POIXMLUnits.parsePercent(color.xgetG());
}
public void setGreen(int green) {
@@ -70,7 +72,7 @@ public class XDDFColorRgbPercent extends XDDFColor {
}
public int getBlue() {
- return color.getB();
+ return POIXMLUnits.parsePercent(color.xgetB());
}
public void setBlue(int blue) {
@@ -78,25 +80,14 @@ public class XDDFColorRgbPercent extends XDDFColor {
}
private int normalize(int value) {
- if (value < 0) {
- return 0;
- }
- if (100_000 < value) {
- return 100_000;
- }
- return value;
+ return value < 0 ? 0 : Math.min(100_000, value);
}
public String toRGBHex() {
- StringBuilder sb = new StringBuilder(6);
- appendHex(sb, color.getR());
- appendHex(sb, color.getG());
- appendHex(sb, color.getB());
- return sb.toString().toUpperCase(Locale.ROOT);
- }
-
- private void appendHex(StringBuilder sb, int value) {
- int b = value * 255 / 100_000;
- sb.append(String.format(Locale.ROOT, "%02X", b));
+ int c = 0;
+ for (STPercentage pct : new STPercentage[] { color.xgetR(), color.xgetG(), color.xgetB() }) {
+ c = c << 8 | ((POIXMLUnits.parsePercent(pct) * 255 / 100_000) & 0xFF);
+ }
+ return String.format(Locale.ROOT, "%06X", c);
}
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFDashStop.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFDashStop.java
index 7735665eaf..d79c245dbe 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFDashStop.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFDashStop.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTDashStop;
@@ -36,7 +37,7 @@ public class XDDFDashStop {
}
public int getDashLength() {
- return stop.getD();
+ return POIXMLUnits.parsePercent(stop.xgetD());
}
public void setDashLength(int length) {
@@ -44,7 +45,7 @@ public class XDDFDashStop {
}
public int getSpaceLength() {
- return stop.getSp();
+ return POIXMLUnits.parsePercent(stop.xgetSp());
}
public void setSpaceLength(int length) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientStop.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientStop.java
index 7d647dc043..ba7c088ed4 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientStop.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFGradientStop.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop;
@@ -42,7 +43,7 @@ public class XDDFGradientStop {
}
public int getPosition() {
- return stop.getPos();
+ return POIXMLUnits.parsePercent(stop.xgetPos());
}
public void setPosition(int position) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLineJoinMiterProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLineJoinMiterProperties.java
index 3abddeaa75..3317e1c6a1 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLineJoinMiterProperties.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLineJoinMiterProperties.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineJoinMiterProperties;
@@ -40,7 +41,7 @@ public class XDDFLineJoinMiterProperties implements XDDFLineJoinProperties {
public Integer getLimit() {
if (join.isSetLim()) {
- return join.getLim();
+ return POIXMLUnits.parsePercent(join.xgetLim());
} else {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFPoint2D.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFPoint2D.java
index e01aec9064..cdd4a03f85 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFPoint2D.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFPoint2D.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
@@ -39,7 +40,7 @@ public class XDDFPoint2D {
if (point == null) {
return x;
} else {
- return point.getX();
+ return POIXMLUnits.parseLength(point.xgetX());
}
}
@@ -47,7 +48,7 @@ public class XDDFPoint2D {
if (point == null) {
return y;
} else {
- return point.getY();
+ return POIXMLUnits.parseLength(point.xgetY());
}
}
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFRelativeRectangle.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFRelativeRectangle.java
index 582b9623fa..44d19bfd0a 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFRelativeRectangle.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFRelativeRectangle.java
@@ -17,13 +17,14 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRelativeRect;
@Beta
public class XDDFRelativeRectangle {
- private CTRelativeRect rect;
+ private final CTRelativeRect rect;
public XDDFRelativeRectangle() {
this(CTRelativeRect.Factory.newInstance());
@@ -40,7 +41,7 @@ public class XDDFRelativeRectangle {
public Integer getBottom() {
if (rect.isSetB()) {
- return rect.getB();
+ return POIXMLUnits.parsePercent(rect.xgetB());
} else {
return null;
}
@@ -58,7 +59,7 @@ public class XDDFRelativeRectangle {
public Integer getLeft() {
if (rect.isSetL()) {
- return rect.getL();
+ return POIXMLUnits.parsePercent(rect.xgetL());
} else {
return null;
}
@@ -76,7 +77,7 @@ public class XDDFRelativeRectangle {
public Integer getRight() {
if (rect.isSetR()) {
- return rect.getR();
+ return POIXMLUnits.parsePercent(rect.xgetR());
} else {
return null;
}
@@ -94,7 +95,7 @@ public class XDDFRelativeRectangle {
public Integer getTop() {
if (rect.isSetT()) {
- return rect.getT();
+ return POIXMLUnits.parsePercent(rect.xgetT());
} else {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFTileInfoProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFTileInfoProperties.java
index 63bb9f2b65..59542330d1 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFTileInfoProperties.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFTileInfoProperties.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTileInfoProperties;
@@ -64,7 +65,7 @@ public class XDDFTileInfoProperties {
public Integer getSx() {
if (props.isSetSx()) {
- return props.getSx();
+ return POIXMLUnits.parsePercent(props.xgetSx());
} else {
return null;
}
@@ -82,7 +83,7 @@ public class XDDFTileInfoProperties {
public Integer getSy() {
if (props.isSetSy()) {
- return props.getSy();
+ return POIXMLUnits.parsePercent(props.xgetSy());
} else {
return null;
}
@@ -100,7 +101,7 @@ public class XDDFTileInfoProperties {
public Long getTx() {
if (props.isSetTx()) {
- return props.getTx();
+ return POIXMLUnits.parseLength(props.xgetTx());
} else {
return null;
}
@@ -118,7 +119,7 @@ public class XDDFTileInfoProperties {
public Long getTy() {
if (props.isSetTy()) {
- return props.getTy();
+ return POIXMLUnits.parseLength(props.xgetTy());
} else {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java
index 1c132a2830..c94cb32381 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart;
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
@@ -102,11 +103,7 @@ public class XDDFArea3DChartData extends XDDFChartData {
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return chart.isSetGapDepth() ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
index 263e8c1324..6c52b8e30f 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart;
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
@@ -113,11 +114,7 @@ public class XDDFBar3DChartData extends XDDFChartData {
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapDepth()) ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
@@ -135,11 +132,7 @@ public class XDDFBar3DChartData extends XDDFChartData {
}
public Integer getGapWidth() {
- if (chart.isSetGapWidth()) {
- return chart.getGapWidth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapWidth()) ? POIXMLUnits.parsePercent(chart.getGapWidth().xgetVal()) / 1000 : null;
}
public void setGapWidth(Integer width) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
index 85f75ffe5f..25eb5d97e2 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart;
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
@@ -113,11 +114,7 @@ public class XDDFBarChartData extends XDDFChartData {
}
public Integer getGapWidth() {
- if (chart.isSetGapWidth()) {
- return chart.getGapWidth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapWidth()) ? (int)(POIXMLUnits.parsePercent(chart.getGapWidth().xgetVal()) / 1000.) : null;
}
public void setGapWidth(Integer width) {
@@ -135,11 +132,7 @@ public class XDDFBarChartData extends XDDFChartData {
}
public Byte getOverlap() {
- if (chart.isSetOverlap()) {
- return chart.getOverlap().getVal();
- } else {
- return null;
- }
+ return chart.isSetOverlap() ? (byte)(POIXMLUnits.parsePercent(chart.getOverlap().xgetVal())/1000) : null;
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
index ac47f4d373..db55a7a31e 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart;
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
@@ -93,11 +94,7 @@ public class XDDFLine3DChartData extends XDDFChartData {
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapDepth()) ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java
index 5d9d10f614..4bfe1e10b6 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java
@@ -19,6 +19,7 @@
package org.apache.poi.xddf.usermodel.chart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTView3D;
@@ -128,11 +129,7 @@ public class XDDFView3D {
}
public Integer getDepthPercent() {
- if (view3D.isSetDepthPercent()) {
- return view3D.getDepthPercent().getVal();
- } else {
- return null;
- }
+ return (view3D.isSetDepthPercent()) ? POIXMLUnits.parsePercent(view3D.getDepthPercent().xgetVal()) : null;
}
public void setDepthPercent(Integer percent) {
@@ -153,11 +150,7 @@ public class XDDFView3D {
}
public Integer getHPercent() {
- if (view3D.isSetHPercent()) {
- return view3D.getHPercent().getVal();
- } else {
- return null;
- }
+ return (view3D.isSetHPercent()) ? POIXMLUnits.parsePercent(view3D.getHPercent().xgetVal()) : null;
}
public void setHPercent(Integer percent) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
index c27953ba99..80d6f019bf 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
@@ -123,7 +124,7 @@ public class XDDFBodyProperties {
public Double getBottomInset() {
if (props.isSetBIns()) {
- return Units.toPoints(props.getBIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetBIns()));
} else {
return null;
}
@@ -141,7 +142,7 @@ public class XDDFBodyProperties {
public Double getLeftInset() {
if (props.isSetLIns()) {
- return Units.toPoints(props.getLIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetLIns()));
} else {
return null;
}
@@ -159,7 +160,7 @@ public class XDDFBodyProperties {
public Double getRightInset() {
if (props.isSetRIns()) {
- return Units.toPoints(props.getRIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetRIns()));
} else {
return null;
}
@@ -177,7 +178,7 @@ public class XDDFBodyProperties {
public Double getTopInset() {
if (props.isSetTIns()) {
- return Units.toPoints(props.getTIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetTIns()));
} else {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java
index 6426c8e32b..b1eefa90f7 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePercent;
@@ -43,10 +44,10 @@ public class XDDFBulletSizePercent implements XDDFBulletSize {
}
public double getPercent() {
- return percent.getVal() * scale;
+ return POIXMLUnits.parsePercent(percent.xgetVal()) * scale;
}
public void setPercent(double value) {
- percent.setVal(Math.toIntExact(Math.round(1000 * value)));
+ percent.setVal(Long.toString(Math.round(1000 * value)));
}
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java
index 93cdc723e3..e0f0b42528 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java
@@ -34,8 +34,8 @@ public class XDDFFont {
public XDDFFont(FontGroup group, String typeface, Byte charset, Byte pitch, byte[] panose) {
this(group, CTTextFont.Factory.newInstance());
if (typeface == null) {
- if (font.isSetTypeface()) {
- font.unsetTypeface();
+ if (font.getTypeface() != null && !font.getTypeface().equals("")) {
+ font.setTypeface("");
}
} else {
font.setTypeface(typeface);
@@ -79,11 +79,7 @@ public class XDDFFont {
}
public String getTypeface() {
- if (font.isSetTypeface()) {
- return font.getTypeface();
- } else {
- return null;
- }
+ return font.getTypeface();
}
public Byte getCharset() {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java
index e476834806..ada34afe94 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;
@@ -42,7 +43,7 @@ public class XDDFNormalAutoFit implements XDDFAutoFit {
@Override
public int getFontScale() {
if (autofit.isSetFontScale()) {
- return autofit.getFontScale();
+ return POIXMLUnits.parsePercent(autofit.xgetFontScale());
} else {
return 100_000;
}
@@ -61,7 +62,7 @@ public class XDDFNormalAutoFit implements XDDFAutoFit {
@Override
public int getLineSpaceReduction() {
if (autofit.isSetLnSpcReduction()) {
- return autofit.getLnSpcReduction();
+ return POIXMLUnits.parsePercent(autofit.xgetLnSpcReduction());
} else {
return 0;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java
index 288f969d88..70c099e725 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;
@@ -49,7 +50,7 @@ public class XDDFSpacingPercent extends XDDFSpacing {
}
public double getPercent() {
- return percent.getVal() * scale;
+ return POIXMLUnits.parsePercent(percent.xgetVal()) * scale;
}
public void setPercent(double value) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java
index 074b5272dc..a843002dd1 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java
@@ -17,6 +17,7 @@
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
@@ -56,7 +57,7 @@ public class XDDFTabStop {
public Double getPosition() {
if (stop.isSetPos()) {
- return Units.toPoints(stop.getPos());
+ return Units.toPoints(POIXMLUnits.parseLength(stop.xgetPos()));
} else {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
index b5e3378795..7fa888b05f 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
@@ -27,6 +27,7 @@ import java.util.function.Predicate;
import org.apache.commons.collections4.iterators.IteratorIterable;
import org.apache.commons.collections4.iterators.ReverseListIterator;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
@@ -361,8 +362,8 @@ public class XDDFTextParagraph {
public Double getDefaultTabSize() {
return findDefinedParagraphProperty(
CTTextParagraphProperties::isSetDefTabSz,
- CTTextParagraphProperties::getDefTabSz)
- .map(Units::toPoints).orElse(null);
+ CTTextParagraphProperties::xgetDefTabSz)
+ .map(POIXMLUnits::parseLength).map(Units::toPoints).orElse(null);
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java
index 89f5dced01..0817f23592 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java
@@ -25,12 +25,14 @@ import java.util.function.Predicate;
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.ooxml.POIXMLRelation;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFFillProperties;
import org.apache.poi.xddf.usermodel.XDDFLineProperties;
@@ -294,7 +296,8 @@ public class XDDFTextRun {
public boolean isSubscript() {
return findDefinedProperty(
CTTextCharacterProperties::isSetBaseline,
- CTTextCharacterProperties::getBaseline)
+ CTTextCharacterProperties::xgetBaseline)
+ .map(POIXMLUnits::parsePercent)
.map(baseline -> baseline < 0)
.orElse(false);
}
@@ -306,7 +309,8 @@ public class XDDFTextRun {
public boolean isSuperscript() {
return findDefinedProperty(
CTTextCharacterProperties::isSetBaseline,
- CTTextCharacterProperties::getBaseline)
+ CTTextCharacterProperties::xgetBaseline)
+ .map(POIXMLUnits::parsePercent)
.map(baseline -> baseline > 0)
.orElse(false);
}
@@ -488,8 +492,9 @@ public class XDDFTextRun {
public Double getCharacterSpacing() {
return findDefinedProperty(
CTTextCharacterProperties::isSetSpc,
- CTTextCharacterProperties::getSpc)
- .map(spacing -> 0.01 * spacing)
+ CTTextCharacterProperties::xgetSpc)
+ .map(POIXMLUnits::parseLength)
+ .map(Units::toPoints)
.orElse(null);
}
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 63daaf6395..cafb705a7e 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
@@ -22,6 +22,7 @@ import java.awt.Color;
import javax.xml.namespace.QName;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.AbstractColorStyle;
import org.apache.poi.sl.usermodel.ColorStyle;
@@ -52,10 +53,10 @@ public class XSLFColor {
private static final POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);
private static final QName VAL_ATTR = new QName("val");
- private XmlObject _xmlObject;
- private Color _color;
- private CTSchemeColor _phClr;
- private XSLFSheet _sheet;
+ private final XmlObject _xmlObject;
+ private final Color _color;
+ private final CTSchemeColor _phClr;
+ private final XSLFSheet _sheet;
@SuppressWarnings("WeakerAccess")
public XSLFColor(XmlObject obj, XSLFTheme theme, CTSchemeColor phClr, XSLFSheet sheet) {
@@ -88,8 +89,8 @@ public class XSLFColor {
private Color toColor(CTHslColor hsl) {
return DrawPaint.HSL2RGB(
hsl.getHue2() / 60000d,
- hsl.getSat2() / 1000d,
- hsl.getLum2() / 1000d,
+ POIXMLUnits.parsePercent(hsl.xgetSat2()) / 1000d,
+ POIXMLUnits.parsePercent(hsl.xgetLum2()) / 1000d,
1d);
}
@@ -112,7 +113,10 @@ public class XSLFColor {
private Color toColor(CTScRgbColor scrgb) {
// percental [0..100000] scRGB color space needs to be gamma corrected for AWT/sRGB colorspace
- return DrawPaint.SCRGB2RGB(scrgb.getR()/100_000d,scrgb.getG()/100_000d,scrgb.getB()/100_000d);
+ return DrawPaint.SCRGB2RGB(
+ POIXMLUnits.parsePercent(scrgb.xgetR())/100_000d,
+ POIXMLUnits.parsePercent(scrgb.xgetG())/100_000d,
+ POIXMLUnits.parsePercent(scrgb.xgetB())/100_000d);
}
private Color toColor(CTSRgbColor srgb) {
@@ -487,9 +491,9 @@ public class XSLFColor {
}
private static class XSLFColorStyle extends AbstractColorStyle {
- private XmlObject xmlObject;
- private Color color;
- private CTSchemeColor phClr;
+ private final XmlObject xmlObject;
+ private final Color color;
+ private final CTSchemeColor phClr;
XSLFColorStyle(XmlObject xmlObject, Color color, CTSchemeColor phClr) {
this.xmlObject = xmlObject;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComment.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComment.java
index 917df0dd9b..ab925b2f0c 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComment.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFComment.java
@@ -21,6 +21,7 @@ import java.awt.geom.Point2D;
import java.util.Calendar;
import java.util.Date;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.Comment;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Units;
@@ -111,7 +112,9 @@ public class XSLFComment implements Comment {
@Override
public Point2D getOffset() {
final CTPoint2D pos = comment.getPos();
- return new Point2D.Double(Units.toPoints(pos.getX()), Units.toPoints(pos.getY()));
+ return new Point2D.Double(
+ Units.toPoints(POIXMLUnits.parseLength(pos.xgetX())),
+ Units.toPoints(POIXMLUnits.parseLength(pos.xgetY())));
}
@Override
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
index 8c41fe1b93..13a4842735 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
@@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.poi.ooxml.POIXMLTypeLoader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.geom.CustomGeometry;
import org.apache.poi.sl.draw.geom.PresetGeometries;
import org.apache.poi.sl.usermodel.FreeformShape;
@@ -113,7 +114,7 @@ public class XSLFFreeformShape extends XSLFAutoShape
numPoints += Math.max(points.length, 1);
it.next();
}
-
+
XmlObject xo = getShapeProperties();
if (!(xo instanceof CTShapeProperties)) {
return -1;
@@ -157,9 +158,8 @@ public class XSLFFreeformShape extends XSLFAutoShape
if (!(xo instanceof CTShapeProperties)) {
return null;
}
-
+
final CTCustomGeometry2D geom = ((CTShapeProperties)xo).getCustGeom();
- //noinspection deprecation
for(CTPath2D spPath : geom.getPathLst().getPathArray()){
XmlCursor cursor = spPath.newCursor();
try {
@@ -193,7 +193,7 @@ public class XSLFFreeformShape extends XSLFAutoShape
final CTTransform2D xfrm = getXfrm(false);
final Rectangle2D xfrm2d = new Rectangle2D.Double
- (xfrm.getOff().getX(), xfrm.getOff().getY(), xfrm.getExt().getCx(), xfrm.getExt().getCy());
+ (POIXMLUnits.parseLength(xfrm.getOff().xgetX()), POIXMLUnits.parseLength(xfrm.getOff().xgetY()), xfrm.getExt().getCx(), xfrm.getExt().getCy());
final Rectangle2D bounds = getAnchor();
at.translate(bounds.getX()+bounds.getCenterX(), bounds.getY()+bounds.getCenterY());
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGradientPaint.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGradientPaint.java
index f86d2e9035..3938295e11 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGradientPaint.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGradientPaint.java
@@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
import java.util.Arrays;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.Insets2D;
import org.apache.poi.sl.usermodel.PaintStyle;
@@ -43,8 +44,8 @@ public class XSLFGradientPaint implements PaintStyle.GradientPaint {
new CTGradientStop[0] : gradFill.getGsLst().getGsArray();
Arrays.sort(gs, (o1, o2) -> {
- int pos1 = o1.getPos();
- int pos2 = o2.getPos();
+ int pos1 = POIXMLUnits.parsePercent(o1.xgetPos());
+ int pos2 = POIXMLUnits.parsePercent(o2.xgetPos());
return Integer.compare(pos1, pos2);
});
@@ -58,7 +59,7 @@ public class XSLFGradientPaint implements PaintStyle.GradientPaint {
phClrCgs = cgs.getSchemeClr();
}
cs[i] = new XSLFColor(cgs, theme, phClrCgs, sheet).getColorStyle();
- fractions[i] = cgs.getPos() / 100000.f;
+ fractions[i] = POIXMLUnits.parsePercent(cgs.xgetPos()) / 100000.f;
i++;
}
@@ -113,7 +114,12 @@ public class XSLFGradientPaint implements PaintStyle.GradientPaint {
if (gradFill.isSetPath() && gradFill.getPath().isSetFillToRect()) {
final double base = 100_000;
CTRelativeRect rect = gradFill.getPath().getFillToRect();
- return new Insets2D(rect.getT()/base, rect.getL()/base, rect.getB()/base, rect.getR()/base);
+ return new Insets2D(
+ POIXMLUnits.parsePercent(rect.xgetT())/base,
+ POIXMLUnits.parsePercent(rect.xgetL())/base,
+ POIXMLUnits.parsePercent(rect.xgetB())/base,
+ POIXMLUnits.parsePercent(rect.xgetR())/base
+ );
}
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
index a57e0b7463..490908e35c 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLException;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@@ -64,8 +65,8 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
public Rectangle2D getAnchor(){
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
index 1d077b73db..095659a153 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.List;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
@@ -49,14 +50,14 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
/**
* Represents a group shape that consists of many shapes grouped together.
- *
+ *
* @author Yegor Kozlov
*/
@Beta
public class XSLFGroupShape extends XSLFShape
implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
private final static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class);
-
+
private final List<XSLFShape> _shapes;
private final CTGroupShapeProperties _grpSpPr;
private XSLFDrawing _drawing;
@@ -71,12 +72,12 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
protected CTGroupShapeProperties getGrpSpPr() {
return _grpSpPr;
}
-
+
private CTGroupTransform2D getSafeXfrm() {
CTGroupTransform2D xfrm = getXfrm();
return (xfrm == null ? getGrpSpPr().addNewXfrm() : xfrm);
}
-
+
protected CTGroupTransform2D getXfrm() {
return getGrpSpPr().getXfrm();
}
@@ -85,8 +86,8 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
public Rectangle2D getAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
@@ -118,8 +119,8 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
public Rectangle2D getInteriorAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getChOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getChExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
@@ -287,20 +288,20 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
Dimension dim = pictureData.getImageDimension();
oleObj.setImgW(Units.toEMU(dim.getWidth()));
oleObj.setImgH(Units.toEMU(dim.getHeight()));
-
-
+
+
getShapes().add(sh);
sh.setParent(this);
return sh;
}
-
+
public XSLFTable createTable(){
XSLFTable sh = getDrawing().createTable();
_shapes.add(sh);
sh.setParent(this);
return sh;
}
-
+
@Override
public XSLFTable createTable(int numRows, int numCols){
if (numRows < 1 || numCols < 1) {
@@ -318,7 +319,7 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
return sh;
}
-
+
@Override
public void setFlipHorizontal(boolean flip){
getSafeXfrm().setFlipH(flip);
@@ -359,7 +360,7 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
// recursively update each shape
List<XSLFShape> tgtShapes = getShapes();
List<XSLFShape> srcShapes = gr.getShapes();
-
+
// workaround for a call by XSLFSheet.importContent:
// if we have already the same amount of child shapes
// then assume, that we've been called by import content and only need to update the children
@@ -367,13 +368,13 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
for(int i = 0; i < tgtShapes.size(); i++){
XSLFShape s1 = srcShapes.get(i);
XSLFShape s2 = tgtShapes.get(i);
-
+
s2.copy(s1);
}
} else {
// otherwise recreate the shapes from scratch
clear();
-
+
// recursively update each shape
for(XSLFShape shape : srcShapes) {
XSLFShape newShape;
@@ -398,7 +399,7 @@ implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
_logger.log(POILogger.WARN, "copying of class "+shape.getClass()+" not supported.");
continue;
}
-
+
newShape.copy(shape);
}
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
index 4d6fc246a5..848c8c86c3 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
@@ -35,6 +35,7 @@ import javax.imageio.ImageIO;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.ooxml.util.XPathHelper;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@@ -216,7 +217,12 @@ public class XSLFPictureShape extends XSLFSimpleShape
@Override
public Insets getClipping(){
CTRelativeRect r = getBlipFill().getSrcRect();
- return (r == null) ? null : new Insets(r.getT(), r.getL(), r.getB(), r.getR());
+
+ return (r == null) ? null : new Insets(
+ POIXMLUnits.parsePercent(r.xgetT()),
+ POIXMLUnits.parsePercent(r.xgetL()),
+ POIXMLUnits.parsePercent(r.xgetB()),
+ POIXMLUnits.parsePercent(r.xgetR()));
}
/**
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 eccd5ba778..0f4448a3af 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
@@ -25,6 +25,7 @@ import java.awt.geom.Rectangle2D;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.draw.geom.CustomGeometry;
@@ -129,8 +130,8 @@ public abstract class XSLFSimpleShape extends XSLFShape
}
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
@@ -978,7 +979,6 @@ public abstract class XSLFSimpleShape extends XSLFShape
XSLFGeometryProperties gp = XSLFPropertiesDelegate.getGeometryDelegate(getShapeProperties());
if (gp != null && gp.isSetPrstGeom() && gp.getPrstGeom().isSetAvLst()) {
- //noinspection deprecation
for (CTGeomGuide g : gp.getPrstGeom().getAvLst().getGdArray()) {
if (g.getName().equals(name)) {
Guide gd = new Guide();
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTabStop.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTabStop.java
index 7f87205bd0..3d699af3ab 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTabStop.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTabStop.java
@@ -17,6 +17,7 @@
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.TabStop;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop;
@@ -25,14 +26,14 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextTabAlignType;
public class XSLFTabStop implements TabStop {
final CTTextTabStop tabStop;
-
+
XSLFTabStop(CTTextTabStop tabStop) {
this.tabStop = tabStop;
}
-
+
/** position in EMUs */
public int getPosition() {
- return tabStop.getPos();
+ return (int)POIXMLUnits.parseLength(tabStop.xgetPos());
}
/** position in EMUs */
@@ -49,7 +50,7 @@ public class XSLFTabStop implements TabStop {
public void setPositionInPoints(final double points) {
setPosition(Units.toEMU(points));
}
-
+
public TabStopType getType() {
return TabStopType.fromOoxmlId(tabStop.getAlgn().intValue());
}
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 1f5040e380..f334052e81 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
@@ -27,6 +27,7 @@ import java.util.List;
import javax.xml.namespace.QName;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawTableShape;
import org.apache.poi.sl.draw.DrawTextShape;
@@ -52,8 +53,8 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
TableShape<XSLFShape,XSLFTextParagraph> {
/* package */ static final String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
- private CTTable _table;
- private List<XSLFTableRow> _rows;
+ private final CTTable _table;
+ private final List<XSLFTableRow> _rows;
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
super(shape, sheet);
@@ -123,8 +124,8 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
@Override
public double getColumnWidth(int idx){
- return Units.toPoints(
- _table.getTblGrid().getGridColArray(idx).getW());
+ return Units.toPoints(POIXMLUnits.parseLength(
+ _table.getTblGrid().getGridColArray(idx).xgetW()));
}
@Override
@@ -134,7 +135,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
@Override
public double getRowHeight(int row) {
- return Units.toPoints(_table.getTrArray(row).getH());
+ return Units.toPoints(POIXMLUnits.parseLength(_table.getTrArray(row).xgetH()));
}
@Override
@@ -201,7 +202,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
* @since POI 4.1.2
*/
public void addColumn() {
- long width = _table.getTblGrid().getGridColArray(getNumberOfColumns() - 1).getW();
+ long width = POIXMLUnits.parseLength(_table.getTblGrid().getGridColArray(getNumberOfColumns() - 1).xgetW());
CTTableCol col = _table.getTblGrid().addNewGridCol();
col.setW(width);
for (XSLFTableRow row : _rows) {
@@ -219,7 +220,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
if (getNumberOfColumns() < colIdx) {
throw new IndexOutOfBoundsException("Cannot insert column at " + colIdx + "; table has only " + getNumberOfColumns() + "columns.");
}
- long width = _table.getTblGrid().getGridColArray(colIdx).getW();
+ long width = POIXMLUnits.parseLength(_table.getTblGrid().getGridColArray(colIdx).xgetW());
CTTableCol col = _table.getTblGrid().insertNewGridCol(colIdx);
col.setW(width);
for (XSLFTableRow row : _rows) {
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 710465eee1..db67222c21 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
@@ -39,7 +40,6 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> {
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
_row = row;
_table = table;
- @SuppressWarnings("deprecation")
CTTableCell[] tcArray = _row.getTcArray();
_cells = new ArrayList<>(tcArray.length);
for(CTTableCell cell : tcArray) {
@@ -61,7 +61,7 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> {
}
public double getHeight(){
- return Units.toPoints(_row.getH());
+ return Units.toPoints(POIXMLUnits.parseLength(_row.xgetH()));
}
public void setHeight(double height){
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 7c36b1dd8e..9b3dae4e5e 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
@@ -25,6 +25,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.AutoNumberingScheme;
import org.apache.poi.sl.usermodel.PaintStyle;
@@ -302,7 +303,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
private static void fetchBulletFontSize(CTTextParagraphProperties props, Consumer<Double> val) {
if(props.isSetBuSzPct()){
- val.accept(props.getBuSzPct().getVal() * 0.001);
+ val.accept(POIXMLUnits.parsePercent(props.getBuSzPct().xgetVal()) * 0.001);
}
if(props.isSetBuSzPts()){
val.accept( - props.getBuSzPts().getVal() * 0.01);
@@ -324,7 +325,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
if(bulletSize >= 0) {
CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();
- pt.setVal((int)(bulletSize*1000));
+ pt.setVal(Integer.toString((int)(bulletSize*1000)));
if(pr.isSetBuSzPts()) {
pr.unsetBuSzPts();
}
@@ -452,7 +453,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
public Double getDefaultTabSize(){
return fetchParagraphProperty((props, val) -> {
if (props.isSetDefTabSz()) {
- val.accept(Units.toPoints(props.getDefTabSz()));
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(props.xgetDefTabSz())));
}
});
}
@@ -468,7 +469,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
CTTextTabStopList tabStops = props.getTabLst();
if(idx < tabStops.sizeOfTabArray() ) {
CTTextTabStop ts = tabStops.getTabArray(idx);
- val.accept(Units.toPoints(ts.getPos()));
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(ts.xgetPos())));
}
}
}
@@ -493,7 +494,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
// check if the percentage value is scaled
final CTTextNormalAutofit normAutofit = getParentShape().getTextBodyPr().getNormAutofit();
if (normAutofit != null) {
- final double scale = 1 - (double)normAutofit.getLnSpcReduction() / 100000;
+ final double scale = 1 - POIXMLUnits.parsePercent(normAutofit.xgetLnSpcReduction()) / 100_000.;
return lnSpc * scale;
}
}
@@ -569,7 +570,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagr
final CTTextSpacing spc = getSpc.apply(props).get();
if (spc != null) {
if (spc.isSetSpcPct()) {
- val.accept( spc.getSpcPct().getVal()*0.001 );
+ val.accept( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
} else if (spc.isSetSpcPts()) {
val.accept( -spc.getSpcPts().getVal()*0.01 );
}
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 b57e2da602..930e9abfa3 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
@@ -24,6 +24,7 @@ import org.apache.poi.common.usermodel.fonts.FontFamily;
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.common.usermodel.fonts.FontInfo;
import org.apache.poi.common.usermodel.fonts.FontPitch;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.draw.DrawPaint;
@@ -34,6 +35,7 @@ import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.apache.poi.xslf.model.CharacterPropertyFetcher.CharPropFetcher;
import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
@@ -182,7 +184,7 @@ public class XSLFTextRun implements TextRun {
if (tbp != null) {
CTTextNormalAutofit afit = tbp.getNormAutofit();
if (afit != null && afit.isSetFontScale()) {
- scale = afit.getFontScale() / 100000.;
+ scale = POIXMLUnits.parsePercent(afit.xgetFontScale()) / 100000.;
}
}
}
@@ -203,7 +205,7 @@ public class XSLFTextRun implements TextRun {
public double getCharacterSpacing(){
Double d = fetchCharacterProperty((props, val) -> {
if (props.isSetSpc()) {
- val.accept(props.getSpc()*0.01);
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(props.xgetSpc())));
}
});
return d == null ? 0 : d;
@@ -297,7 +299,7 @@ public class XSLFTextRun implements TextRun {
public boolean isSuperscript() {
Boolean b = fetchCharacterProperty((props, val) -> {
if (props.isSetBaseline()) {
- val.accept(props.getBaseline() > 0);
+ val.accept(POIXMLUnits.parsePercent(props.xgetBaseline()) > 0);
}
});
return b != null && b;
@@ -341,7 +343,7 @@ public class XSLFTextRun implements TextRun {
public boolean isSubscript() {
Boolean b = fetchCharacterProperty((props, val) -> {
if (props.isSetBaseline()) {
- val.accept(props.getBaseline() < 0);
+ val.accept(POIXMLUnits.parsePercent(props.xgetBaseline()) < 0);
}
});
return b != null && b;
@@ -565,7 +567,7 @@ public class XSLFTextRun implements TextRun {
@Override
public String getTypeface() {
CTTextFont tf = getXmlObject(false);
- return (tf != null && tf.isSetTypeface()) ? tf.getTypeface() : null;
+ return (tf != null) ? tf.getTypeface() : null;
}
@Override
@@ -718,7 +720,10 @@ public class XSLFTextRun implements TextRun {
return null;
}
- String typeface = font.isSetTypeface() ? font.getTypeface() : "";
+ String typeface = font.getTypeface();
+ if (typeface == null) {
+ typeface = "";
+ }
if (typeface.startsWith("+mj-") || typeface.startsWith("+mn-")) {
// "+mj-lt".equals(typeface) || "+mn-lt".equals(typeface)
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
@@ -737,7 +742,7 @@ public class XSLFTextRun implements TextRun {
}
// SYMBOL is missing
- if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
+ if (font == null || font.getTypeface() == null || "".equals(font.getTypeface())) {
// don't fallback to latin but bubble up in the style hierarchy (slide -> layout -> master -> theme)
return null;
// font = coll.getLatin();
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 b0dce8b7de..a147758403 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
@@ -29,6 +29,7 @@ import java.util.function.Function;
import java.util.function.Predicate;
import org.apache.poi.ooxml.POIXMLException;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawTextShape;
import org.apache.poi.sl.usermodel.Insets2D;
@@ -277,7 +278,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
}
};
fetchShapeProperty(fetcher);
- return fetcher.getValue() == null ? false : fetcher.getValue();
+ return fetcher.getValue() != null && fetcher.getValue();
}
@Override
@@ -348,7 +349,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetBIns()) {
- double val = Units.toPoints(props.getBIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetBIns()));
setValue(val);
return true;
}
@@ -372,7 +373,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetLIns()) {
- double val = Units.toPoints(props.getLIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetLIns()));
setValue(val);
return true;
}
@@ -396,7 +397,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetRIns()) {
- double val = Units.toPoints(props.getRIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetRIns()));
setValue(val);
return true;
}
@@ -419,7 +420,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetTIns()) {
- double val = Units.toPoints(props.getTIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetTIns()));
setValue(val);
return true;
}
@@ -533,7 +534,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
}
};
fetchShapeProperty(fetcher);
- return fetcher.getValue() == null ? true : fetcher.getValue();
+ return fetcher.getValue() == null || fetcher.getValue();
}
@Override
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTexturePaint.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTexturePaint.java
index 2a2c8edf8b..655be92305 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTexturePaint.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTexturePaint.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@@ -40,6 +41,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTDuotoneEffect;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRelativeRect;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTileInfoProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPercentage;
import org.openxmlformats.schemas.drawingml.x2006.main.STTileFlipMode;
@Internal
@@ -92,7 +94,7 @@ public class XSLFTexturePaint implements PaintStyle.TexturePaint {
@Override
public int getAlpha() {
return (blip.sizeOfAlphaModFixArray() > 0)
- ? blip.getAlphaModFixArray(0).getAmt()
+ ? POIXMLUnits.parsePercent(blip.getAlphaModFixArray(0).xgetAmt())
: 100000;
}
@@ -105,16 +107,16 @@ public class XSLFTexturePaint implements PaintStyle.TexturePaint {
public Dimension2D getScale() {
CTTileInfoProperties tile = blipFill.getTile();
return (tile == null) ? null : new Dimension2DDouble(
- tile.isSetSx() ? tile.getSx()/100_000. : 1,
- tile.isSetSy() ? tile.getSy()/100_000. : 1);
+ tile.isSetSx() ? POIXMLUnits.parsePercent(tile.xgetSx())/100_000. : 1,
+ tile.isSetSy() ? POIXMLUnits.parsePercent(tile.xgetSy())/100_000. : 1);
}
@Override
public Point2D getOffset() {
CTTileInfoProperties tile = blipFill.getTile();
return (tile == null) ? null : new Point2D.Double(
- tile.isSetTx() ? Units.toPoints(tile.getTx()) : 0,
- tile.isSetTy() ? Units.toPoints(tile.getTy()) : 0);
+ tile.isSetTx() ? Units.toPoints(POIXMLUnits.parseLength(tile.xgetTx())) : 0,
+ tile.isSetTy() ? Units.toPoints(POIXMLUnits.parseLength(tile.xgetTy())) : 0);
}
@Override
@@ -166,14 +168,14 @@ public class XSLFTexturePaint implements PaintStyle.TexturePaint {
private static Insets2D getRectVal(CTRelativeRect rect) {
return rect == null ? null : new Insets2D(
- getRectVal(rect::isSetT, rect::getT),
- getRectVal(rect::isSetL, rect::getL),
- getRectVal(rect::isSetB, rect::getB),
- getRectVal(rect::isSetR, rect::getR)
+ getRectVal(rect::isSetT, rect::xgetT),
+ getRectVal(rect::isSetL, rect::xgetL),
+ getRectVal(rect::isSetB, rect::xgetB),
+ getRectVal(rect::isSetR, rect::xgetR)
);
}
- private static int getRectVal(Supplier<Boolean> isSet, Supplier<Integer> val) {
- return isSet.get() ? val.get() : 0;
+ private static int getRectVal(Supplier<Boolean> isSet, Supplier<STPercentage> val) {
+ return isSet.get() ? POIXMLUnits.parsePercent(val.get()) : 0;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
index 43095deba6..7c0a71c8e4 100644
--- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
+++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
@@ -35,10 +35,10 @@ import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
+import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.ooxml.util.XPathHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -49,7 +49,6 @@ import org.apache.poi.xssf.usermodel.XSSFTable;
import org.apache.poi.xssf.usermodel.XSSFTableColumn;
import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -104,7 +103,7 @@ public class XSSFImportFromXML {
for (XSSFSingleXmlCell singleXmlCell : singleXmlCells) {
- STXmlDataType.Enum xmlDataType = singleXmlCell.getXmlDataType();
+ String xmlDataType = singleXmlCell.getXmlDataType();
String xpathString = singleXmlCell.getXpath();
Node result = (Node) xpath.evaluate(xpathString, doc, XPathConstants.NODE);
// result can be null if value is optional (xsd:minOccurs=0), see bugzilla 55864
@@ -166,22 +165,22 @@ public class XSSFImportFromXML {
}
}
-
- private static enum DataType {
- BOOLEAN(STXmlDataType.BOOLEAN), //
- DOUBLE(STXmlDataType.DOUBLE), //
- INTEGER(STXmlDataType.INT, STXmlDataType.UNSIGNED_INT, STXmlDataType.INTEGER), //
- STRING(STXmlDataType.STRING), //
- DATE(STXmlDataType.DATE);
- private Set<STXmlDataType.Enum> xmlDataTypes;
+ private enum DataType {
+ BOOLEAN("boolean"), //
+ DOUBLE("double"), //
+ INTEGER("int", "unsignedInt", "integer"), //
+ STRING("string"), //
+ DATE("date");
+
+ private Set<String> xmlDataTypes;
- private DataType(STXmlDataType.Enum... xmlDataTypes) {
+ DataType(String... xmlDataTypes) {
this.xmlDataTypes = new HashSet<>(Arrays.asList(xmlDataTypes));
}
- public static DataType getDataType(STXmlDataType.Enum xmlDataType) {
+ public static DataType getDataType(String xmlDataType) {
for (DataType dataType : DataType.values()) {
if (dataType.xmlDataTypes.contains(xmlDataType)) {
return dataType;
@@ -191,7 +190,7 @@ public class XSSFImportFromXML {
}
}
- private void setCellValue(String value, XSSFCell cell, STXmlDataType.Enum xmlDataType) {
+ private void setCellValue(String value, XSSFCell cell, String xmlDataType) {
DataType type = DataType.getDataType(xmlDataType);
try {
if (value.isEmpty() || type == null) {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
index d13392e608..428a06ddf1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
@@ -17,6 +17,7 @@
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
@@ -32,15 +33,15 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
* <li>A position relative to a cell (top-left) and sized relative to another cell (bottom right)
* </ol>
*
- * which method is used is determined by the {@link AnchorType}.
+ * which method is used is determined by the {@link AnchorType}.
*/
public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
-
+
/**
* placeholder for zeros when needed for dynamic position calculations
*/
private static final CTMarker EMPTY_MARKER = CTMarker.Factory.newInstance();
-
+
private AnchorType anchorType;
/**
@@ -59,18 +60,18 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
* if present, fixed size of the object to use instead of cell2, which is inferred instead
*/
private CTPositiveSize2D size;
-
+
/**
* if present, fixed top-left position to use instead of cell1, which is inferred instead
*/
private CTPoint2D position;
-
+
/**
* sheet to base dynamic calculations on, if needed. Required if size and/or position or set.
* Not needed if cell1/2 are set explicitly (dynamic sizing and position relative to cells).
*/
private XSSFSheet sheet;
-
+
/**
* Creates a new client anchor and defaults all the anchor positions to 0.
* Sets the type to {@link AnchorType#MOVE_AND_RESIZE} relative to cell range A1:A1.
@@ -134,7 +135,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
this.cell1 = cell1;
// this.cell2 = calcCell(sheet, cell1, size.getCx(), size.getCy());
}
-
+
/**
* Create XSSFClientAnchor from existing xml beans, sized and positioned relative to a pair of cells.
* Sets the type to {@link AnchorType#DONT_MOVE_AND_RESIZE}.
@@ -152,18 +153,18 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
// this.cell1 = calcCell(sheet, EMPTY_MARKER, position.getCx(), position.getCy());
// this.cell2 = calcCell(sheet, cell1, size.getCx(), size.getCy());
}
-
+
private CTMarker calcCell(CTMarker cell, long w, long h) {
CTMarker c2 = CTMarker.Factory.newInstance();
-
+
int r = cell.getRow();
int c = cell.getCol();
-
+
int cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
-
+
// start with width - offset, then keep adding column widths until the next one puts us over w
- long wPos = cw - cell.getColOff();
-
+ long wPos = cw - POIXMLUnits.parseLength(cell.xgetColOff());
+
while (wPos < w) {
c++;
cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
@@ -172,11 +173,11 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
// now wPos >= w, so end column = c, now figure offset
c2.setCol(c);
c2.setColOff(cw - (wPos - w));
-
+
int rh = Units.toEMU(getRowHeight(sheet, r));
// start with height - offset, then keep adding row heights until the next one puts us over h
- long hPos = rh - cell.getRowOff();
-
+ long hPos = rh - POIXMLUnits.parseLength(cell.xgetRowOff());
+
while (hPos < h) {
r++;
rh = Units.toEMU(getRowHeight(sheet, r));
@@ -185,10 +186,10 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
// now hPos >= h, so end row = r, now figure offset
c2.setRow(r);
c2.setRowOff(rh - (hPos - h));
-
+
return c2;
}
-
+
/**
* @param sheet
* @param row
@@ -198,15 +199,15 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
XSSFRow r = sheet.getRow(row);
return r == null ? sheet.getDefaultRowHeightInPoints() : r.getHeightInPoints();
}
-
+
private CTMarker getCell1() {
- return cell1 != null ? cell1 : calcCell(EMPTY_MARKER, position.getX(), position.getY());
+ return cell1 != null ? cell1 : calcCell(EMPTY_MARKER, POIXMLUnits.parseLength(position.xgetX()), POIXMLUnits.parseLength(position.xgetY()));
}
-
+
private CTMarker getCell2() {
return cell2 != null ? cell2 : calcCell(getCell1(), size.getCx(), size.getCy());
}
-
+
public short getCol1() {
return (short)getCell1().getCol();
}
@@ -256,7 +257,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDx1() {
- return Math.toIntExact(getCell1().getColOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetColOff()));
}
/**
@@ -268,7 +269,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDy1() {
- return Math.toIntExact(getCell1().getRowOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetRowOff()));
}
/**
@@ -280,7 +281,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDy2() {
- return Math.toIntExact(getCell2().getRowOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetRowOff()));
}
/**
@@ -292,7 +293,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDx2() {
- return Math.toIntExact(getCell2().getColOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetColOff()));
}
/**
@@ -365,7 +366,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
public CTPoint2D getPosition() {
return position;
}
-
+
/**
* Sets the top-left absolute position of the object. To use this, "from" must be set to null.
* @param position
@@ -383,7 +384,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
public CTPositiveSize2D getSize() {
return size;
}
-
+
/**
* Sets the size of the object. To use this, "to" must be set to null.
* @param size
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
index 7b26dcb565..b6d4465ecc 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
@@ -29,9 +29,11 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
@@ -40,7 +42,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
/**
* Represents a font used in a workbook.
@@ -618,7 +619,7 @@ public class XSSFFont implements Font {
* @see org.apache.poi.ss.usermodel.FontFamily
*/
public int getFamily() {
- CTIntProperty family = _ctFont.sizeOfFamilyArray() == 0 ? null : _ctFont.getFamilyArray(0);
+ CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? null : _ctFont.getFamilyArray(0);
return family == null ? FontFamily.NOT_APPLICABLE.getValue() : FontFamily.valueOf(family.getVal()).getValue();
}
@@ -631,7 +632,7 @@ public class XSSFFont implements Font {
* @see FontFamily
*/
public void setFamily(int value) {
- CTIntProperty family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
+ CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
family.setVal(value);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java
index d211b3cfe1..6b359a2988 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java
@@ -22,13 +22,13 @@ import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FontFormatting;
import org.apache.poi.ss.usermodel.FontUnderline;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
index 7af9ee4cac..d71641b7de 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
@@ -17,24 +17,27 @@
package org.apache.poi.xssf.usermodel;
-import java.util.*;
-import java.util.regex.Pattern;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.xml.namespace.QName;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.util.Internal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
-import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlCursor;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSignatureLine.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSignatureLine.java
index 972dbe6aa8..478bca9626 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSignatureLine.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSignatureLine.java
@@ -23,9 +23,7 @@ import java.io.OutputStream;
import javax.xml.namespace.QName;
import com.microsoft.schemas.office.excel.CTClientData;
-import com.microsoft.schemas.office.excel.STCF;
import com.microsoft.schemas.office.excel.STObjectType;
-import com.microsoft.schemas.office.excel.STTrueFalseBlank;
import com.microsoft.schemas.office.office.CTSignatureLine;
import com.microsoft.schemas.vml.CTImageData;
import com.microsoft.schemas.vml.CTShape;
@@ -38,6 +36,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.poifs.crypt.dsig.SignatureLine;
import org.apache.poi.schemas.vmldrawing.CTXML;
import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank;
public class XSSFSignatureLine extends SignatureLine {
private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml";
@@ -78,7 +77,7 @@ public class XSSFSignatureLine extends SignatureLine {
clientData.addAnchor(anchorStr);
clientData.setObjectType(STObjectType.PICT);
clientData.addSizeWithCells(STTrueFalseBlank.X);
- clientData.addCF(STCF.PICT);
+ clientData.addCF("pict");
clientData.addAutoPict(STTrueFalseBlank.X);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
index 99d235901b..0d33e0c4f6 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
@@ -17,6 +17,12 @@
package org.apache.poi.xssf.usermodel;
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
import org.apache.poi.xssf.model.ParagraphPropertyFetcher;
@@ -24,11 +30,6 @@ import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
/**
* Represents a paragraph of text within the containing text body.
* The paragraph is the highest level text separation mechanism.
@@ -142,7 +143,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
}
};
fetchParagraphProperty(fetcher);
- return fetcher.getValue() == null ? TextAlign.LEFT : fetcher.getValue();
+ return fetcher.getValue() == null ? TextAlign.LEFT : fetcher.getValue();
}
/**
@@ -159,12 +160,12 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
} else {
pr.setAlgn(STTextAlignType.Enum.forInt(align.ordinal() + 1));
}
- }
+ }
/**
* Returns where vertically on a line of text the actual words are positioned. This deals
* with vertical placement of the characters with respect to the baselines.
- *
+ *
* If this attribute is omitted, then a value of baseline is implied.
* @return alignment that is applied to the paragraph
*/
@@ -180,7 +181,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
}
};
fetchParagraphProperty(fetcher);
- return fetcher.getValue() == null ? TextFontAlign.BASELINE : fetcher.getValue();
+ return fetcher.getValue() == null ? TextFontAlign.BASELINE : fetcher.getValue();
}
/**
@@ -295,7 +296,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuSzPct()){
- setValue(props.getBuSzPct().getVal() * 0.001);
+ setValue(POIXMLUnits.parsePercent(props.getBuSzPct().xgetVal()) * 0.001);
return true;
}
if(props.isSetBuSzPts()){
@@ -323,7 +324,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
if(bulletSize >= 0) {
// percentage
CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();
- pt.setVal((int)(bulletSize*1000));
+ pt.setVal(Integer.toString((int)(bulletSize*1000)));
// unset points if percentage is now set
if(pr.isSetBuSzPts()) pr.unsetBuSzPts();
} else {
@@ -338,7 +339,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
/**
* Specifies the indent size that will be applied to the first line of text in the paragraph.
*
- * @param value the indent in points, -1 to unset indent and use the default of 0.
+ * @param value the indent in points, -1 to unset indent and use the default of 0.
*/
public void setIndent(double value){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
@@ -441,8 +442,8 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
};
fetchParagraphProperty(fetcher);
// if the marL attribute is omitted, then a value of 347663 is implied
- return fetcher.getValue() == null ? 0 : fetcher.getValue();
- }
+ return fetcher.getValue() == null ? 0 : fetcher.getValue();
+ }
/**
*
@@ -452,7 +453,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetDefTabSz()){
- double val = Units.toPoints(props.getDefTabSz());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetDefTabSz()));
setValue(val);
return true;
}
@@ -470,7 +471,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
CTTextTabStopList tabStops = props.getTabLst();
if(idx < tabStops.sizeOfTabArray() ) {
CTTextTabStop ts = tabStops.getTabArray(idx);
- double val = Units.toPoints(ts.getPos());
+ double val = Units.toPoints(POIXMLUnits.parseLength(ts.xgetPos()));
setValue(val);
return true;
}
@@ -483,8 +484,8 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
}
/**
* Add a single tab stop to be used on a line of text when there are one or more tab characters
- * present within the text.
- *
+ * present within the text.
+ *
* @param value the position of the tab stop relative to the left margin
*/
public void addTabStop(double value){
@@ -511,7 +512,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
* // spacing will be 48 points
* paragraph.setLineSpacing(-48.0);
* </code></pre>
- *
+ *
* @param linespacing the vertical line spacing
*/
public void setLineSpacing(double linespacing){
@@ -538,7 +539,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
if(props.isSetLnSpc()){
CTTextSpacing spc = props.getLnSpc();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
@@ -556,7 +557,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
lnSpc *= scale;
}
}
-
+
return lnSpc;
}
@@ -603,7 +604,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
if(props.isSetSpcBef()){
CTTextSpacing spc = props.getSpcBef();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
@@ -658,7 +659,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
if(props.isSetSpcAft()){
CTTextSpacing spc = props.getSpcAft();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
@@ -676,7 +677,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
* that this paragraph belongs to (therefore in the parent shape).
* <p>
* Note that the closest properties object to the text is used, therefore if there is
- * a conflict between the text paragraph properties and the list style properties for
+ * a conflict between the text paragraph properties and the list style properties for
* this level then the text paragraph properties will take precedence.
* </p>
*
@@ -690,7 +691,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
/**
* Returns the level of text properties that this paragraph will follow.
- *
+ *
* @return the text level of this paragraph (0-based). Default is 0.
*/
public int getLevel(){
@@ -699,7 +700,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
return pr.getLvl();
}
-
+
/**
* Returns whether this paragraph has bullets
@@ -727,10 +728,10 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? false : fetcher.getValue();
}
-
+
/**
* Set or unset this paragraph as a bullet point
- *
+ *
* @param flag whether text in this paragraph has bullets
*/
public void setBullet(boolean flag) {
@@ -739,7 +740,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
if(!flag) {
pr.addNewBuNone();
-
+
if(pr.isSetBuAutoNum()) pr.unsetBuAutoNum();
if(pr.isSetBuBlip()) pr.unsetBuBlip();
if(pr.isSetBuChar()) pr.unsetBuChar();
@@ -767,17 +768,17 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
public void setBullet(ListAutoNumber scheme, int startAt) {
if(startAt < 1) throw new IllegalArgumentException("Start Number must be greater or equal that 1") ;
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
- CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
+ CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1));
lst.setStartAt(startAt);
-
+
if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial");
- if(pr.isSetBuNone()) pr.unsetBuNone();
+ if(pr.isSetBuNone()) pr.unsetBuNone();
// remove these elements if present as it results in invalid content when opening in Excel.
if(pr.isSetBuBlip()) pr.unsetBuBlip();
- if(pr.isSetBuChar()) pr.unsetBuChar();
+ if(pr.isSetBuChar()) pr.unsetBuChar();
}
-
+
/**
* Set this paragraph as an automatic numbered bullet point
*
@@ -787,14 +788,14 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1));
-
+
if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial");
if(pr.isSetBuNone()) pr.unsetBuNone();
// remove these elements if present as it results in invalid content when opening in Excel.
if(pr.isSetBuBlip()) pr.unsetBuBlip();
if(pr.isSetBuChar()) pr.unsetBuChar();
}
-
+
/**
* Returns whether this paragraph has automatic numbered bullets
*/
@@ -811,7 +812,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? false : fetcher.getValue();
}
-
+
/**
* Returns the starting number if this paragraph has automatic numbered bullets, otherwise returns 0
*/
@@ -828,7 +829,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
-
+
/**
* Returns the auto number scheme if this paragraph has automatic numbered bullets, otherwise returns ListAutoNumber.ARABIC_PLAIN
*/
@@ -843,12 +844,12 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
}
};
fetchParagraphProperty(fetcher);
-
+
// Note: documentation does not define a default, return ListAutoNumber.ARABIC_PLAIN (1,2,3...)
return fetcher.getValue() == null ? ListAutoNumber.ARABIC_PLAIN : fetcher.getValue();
- }
+ }
+
-
@SuppressWarnings("rawtypes")
private boolean fetchParagraphProperty(ParagraphPropertyFetcher visitor){
boolean ok = false;
@@ -861,7 +862,7 @@ public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
return ok;
}
-
+
@Override
public String toString(){
return "[" + getClass() + "]" + getText();
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
index 5b63e94f1e..1809e16cd5 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
@@ -16,6 +16,10 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import java.awt.Color;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
@@ -25,8 +29,6 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
-import java.awt.Color;
-
/**
* Represents a run of text within the containing text body. The run element is the
* lowest level text separation mechanism within a text body.
@@ -80,7 +82,7 @@ public class XSSFTextRun {
CTSRgbColor clr = fill.getSrgbClr();
byte[] rgb = clr.getVal();
return new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2]);
- }
+ }
}
return new Color(0, 0, 0);
@@ -115,7 +117,7 @@ public class XSSFTextRun {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetSz()){
- size = rPr.getSz()*0.01;
+ size = rPr.getSz()*0.01;
}
return size * scale;
@@ -129,7 +131,7 @@ public class XSSFTextRun {
public double getCharacterSpacing(){
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetSpc()){
- return rPr.getSpc()*0.01;
+ return Units.toPoints(POIXMLUnits.parseLength(rPr.xgetSpc()));
}
return 0;
}
@@ -229,7 +231,7 @@ public class XSSFTextRun {
public boolean isSuperscript() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetBaseline()){
- return rPr.getBaseline() > 0;
+ return POIXMLUnits.parsePercent(rPr.xgetBaseline()) > 0;
}
return false;
}
@@ -273,7 +275,7 @@ public class XSSFTextRun {
public boolean isSubscript() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetBaseline()){
- return rPr.getBaseline() < 0;
+ return POIXMLUnits.parsePercent(rPr.xgetBaseline()) < 0;
}
return false;
}
@@ -281,7 +283,7 @@ public class XSSFTextRun {
/**
* @return whether a run of text will be formatted as a superscript text. Default is false.
*/
- public TextCap getTextCap() {
+ public TextCap getTextCap() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetCap()){
return TextCap.values()[rPr.getCap().intValue() - 1];
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
index 10ed7eae70..756ef39b03 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java
@@ -45,7 +45,6 @@ import com.microsoft.schemas.vml.CTShape;
import com.microsoft.schemas.vml.CTShapetype;
import com.microsoft.schemas.vml.STExt;
import com.microsoft.schemas.vml.STStrokeJoinStyle;
-import com.microsoft.schemas.vml.STTrueFalse;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.openxml4j.opc.PackagePart;
@@ -55,6 +54,7 @@ import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFSingleXmlCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFSingleXmlCell.java
index 0435f69bb5..79cc921a34 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFSingleXmlCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFSingleXmlCell.java
@@ -24,64 +24,63 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSingleXmlCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlCellPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType.Enum;
/**
- *
+ *
* This class is a wrapper around the CTSingleXmlCell (Open Office XML Part 4:
- * chapter 3.5.2.1)
- *
+ * chapter 3.5.2.1)
+ *
- *
+ *
* @author Roberto Manicardi
*
*/
public class XSSFSingleXmlCell {
-
+
private CTSingleXmlCell singleXmlCell;
private SingleXmlCells parent;
-
-
+
+
public XSSFSingleXmlCell(CTSingleXmlCell singleXmlCell, SingleXmlCells parent){
this.singleXmlCell = singleXmlCell;
this.parent = parent;
}
-
+
/**
* Gets the XSSFCell referenced by the R attribute or creates a new one if cell doesn't exists
* @return the referenced XSSFCell, null if the cell reference is invalid
*/
public XSSFCell getReferencedCell(){
XSSFCell cell = null;
-
-
- CellReference cellReference = new CellReference(singleXmlCell.getR());
-
+
+
+ CellReference cellReference = new CellReference(singleXmlCell.getR());
+
XSSFRow row = parent.getXSSFSheet().getRow(cellReference.getRow());
if(row==null){
row = parent.getXSSFSheet().createRow(cellReference.getRow());
}
-
- cell = row.getCell(cellReference.getCol());
+
+ cell = row.getCell(cellReference.getCol());
if(cell==null){
cell = row.createCell(cellReference.getCol());
}
-
-
+
+
return cell;
}
-
+
public String getXpath(){
CTXmlCellPr xmlCellPr = singleXmlCell.getXmlCellPr();
CTXmlPr xmlPr = xmlCellPr.getXmlPr();
return xmlPr.getXpath();
}
-
+
public long getMapId(){
return singleXmlCell.getXmlCellPr().getXmlPr().getMapId();
}
- public Enum getXmlDataType() {
+ public String getXmlDataType() {
CTXmlCellPr xmlCellPr = singleXmlCell.getXmlCellPr();
CTXmlPr xmlPr = xmlCellPr.getXmlPr();
return xmlPr.getXmlDataType();
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFXmlColumnPr.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFXmlColumnPr.java
index 6fad3dd567..08e9ca05c1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFXmlColumnPr.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFXmlColumnPr.java
@@ -21,13 +21,12 @@ import org.apache.poi.util.Internal;
import org.apache.poi.xssf.usermodel.XSSFTable;
import org.apache.poi.xssf.usermodel.XSSFTableColumn;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlColumnPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType.Enum;
/**
- *
+ *
* This class is a wrapper around the CTXmlColumnPr (Open Office XML Part 4:
* chapter 3.5.1.7)
- *
+ *
*
* @author Roberto Manicardi
*/
@@ -73,7 +72,7 @@ public class XSSFXmlColumnPr {
/**
* If the XPath is, for example, /Node1/Node2/Node3 and /Node1/Node2 is the common XPath for the table, the local XPath is /Node3
- *
+ *
* @return the local XPath
*/
public String getLocalXPath() {
@@ -87,7 +86,7 @@ public class XSSFXmlColumnPr {
return localXPath.toString();
}
- public Enum getXmlDataType() {
+ public String getXmlDataType() {
return ctXmlColumnPr.getXmlDataType();
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/WMLHelper.java b/src/ooxml/java/org/apache/poi/xwpf/model/WMLHelper.java
deleted file mode 100644
index 0761aebebe..0000000000
--- a/src/ooxml/java/org/apache/poi/xwpf/model/WMLHelper.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ====================================================================
- 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.xwpf.model;
-
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-
-public final class WMLHelper {
-
- public static boolean convertSTOnOffToBoolean (STOnOff.Enum value) {
- if (value == STOnOff.TRUE || value == STOnOff.ON || value == STOnOff.X_1) {
- return true;
- }
- return false;
- }
-
- public static STOnOff.Enum convertBooleanToSTOnOff (boolean value) {
- return (value ? STOnOff.TRUE : STOnOff.FALSE);
- }
-}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
index 7cb5326291..3c956be237 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
@@ -16,6 +16,17 @@
==================================================================== */
package org.apache.poi.xwpf.model;
+import com.microsoft.schemas.office.office.CTLock;
+import com.microsoft.schemas.office.office.STConnectType;
+import com.microsoft.schemas.vml.CTFormulas;
+import com.microsoft.schemas.vml.CTGroup;
+import com.microsoft.schemas.vml.CTH;
+import com.microsoft.schemas.vml.CTHandles;
+import com.microsoft.schemas.vml.CTPath;
+import com.microsoft.schemas.vml.CTShape;
+import com.microsoft.schemas.vml.CTShapetype;
+import com.microsoft.schemas.vml.CTTextPath;
+import com.microsoft.schemas.vml.STExt;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@@ -26,6 +37,7 @@ import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
@@ -40,19 +52,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr.Enum;
-import com.microsoft.schemas.office.office.CTLock;
-import com.microsoft.schemas.office.office.STConnectType;
-import com.microsoft.schemas.vml.CTFormulas;
-import com.microsoft.schemas.vml.CTGroup;
-import com.microsoft.schemas.vml.CTH;
-import com.microsoft.schemas.vml.CTHandles;
-import com.microsoft.schemas.vml.CTPath;
-import com.microsoft.schemas.vml.CTShape;
-import com.microsoft.schemas.vml.CTShapetype;
-import com.microsoft.schemas.vml.CTTextPath;
-import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
-
/**
* A .docx file can have no headers/footers, the same header/footer
* on each page, odd/even page footers, and optionally also
@@ -305,7 +304,7 @@ public class XWPFHeaderFooterPolicy {
ref.setType(type);
ref.setId(doc.getRelationId(wrapper));
}
-
+
public XWPFHeader getFirstPageHeader() {
return firstPageHeader;
}
@@ -361,7 +360,7 @@ public class XWPFHeaderFooterPolicy {
}
return defaultHeader;
}
-
+
/**
* Get this section header for the given type
*
@@ -392,7 +391,7 @@ public class XWPFHeaderFooterPolicy {
}
return defaultFooter;
}
-
+
/**
* Get this section footer for the given type
*
@@ -407,7 +406,7 @@ public class XWPFHeaderFooterPolicy {
}
return defaultFooter;
}
-
+
public void createWatermark(String text) {
XWPFParagraph[] pars = new XWPFParagraph[1];
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
index 9f6496d49f..e3599032f8 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
@@ -20,6 +20,8 @@ package org.apache.poi.xwpf.usermodel;
import java.util.HashMap;
import java.util.Map;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+
/**
* Specifies all types of alignment which are available to be applied to objects in a
* WordprocessingML document
@@ -29,18 +31,21 @@ import java.util.Map;
public enum ParagraphAlignment {
//YK: TODO document each alignment option
- LEFT(1),
- CENTER(2),
- RIGHT(3),
- BOTH(4),
- MEDIUM_KASHIDA(5),
- DISTRIBUTE(6),
- NUM_TAB(7),
- HIGH_KASHIDA(8),
- LOW_KASHIDA(9),
- THAI_DISTRIBUTE(10);
+ START(STJc.INT_START), // 1
+ CENTER(STJc.INT_CENTER), // 2
+ END(STJc.INT_END), // 3
+ BOTH(STJc.INT_BOTH), // 4
+ MEDIUM_KASHIDA(STJc.INT_MEDIUM_KASHIDA), // 5
+ DISTRIBUTE(STJc.INT_DISTRIBUTE), // 6
+ NUM_TAB(STJc.INT_NUM_TAB), // 7
+ HIGH_KASHIDA(STJc.INT_HIGH_KASHIDA), // 8
+ LOW_KASHIDA(STJc.INT_LOW_KASHIDA), // 9
+ THAI_DISTRIBUTE(STJc.INT_THAI_DISTRIBUTE), // 10
+ LEFT(STJc.INT_LEFT), // 11
+ RIGHT(STJc.INT_RIGHT) // 12
+ ;
- private static Map<Integer, ParagraphAlignment> imap = new HashMap<>();
+ private static final Map<Integer, ParagraphAlignment> imap = new HashMap<>();
static {
for (ParagraphAlignment p : values()) {
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java
index 82acbb2817..74913cf815 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java
@@ -21,6 +21,7 @@ import java.math.BigInteger;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute.Space;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
@@ -35,7 +36,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTabStop;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTabs;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabTlc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTheme;
@@ -61,8 +61,8 @@ public class TOC {
fonts.setEastAsiaTheme(STTheme.MINOR_H_ANSI);
fonts.setHAnsiTheme(STTheme.MINOR_H_ANSI);
fonts.setCstheme(STTheme.MINOR_BIDI);
- rPr.addNewB().setVal(STOnOff.OFF);
- rPr.addNewBCs().setVal(STOnOff.OFF);
+ rPr.addNewB().setVal(STOnOff1.OFF);
+ rPr.addNewBCs().setVal(STOnOff1.OFF);
rPr.addNewColor().setVal("auto");
rPr.addNewSz().setVal(BigInteger.valueOf(24));
rPr.addNewSzCs().setVal(BigInteger.valueOf(24));
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultParagraphStyle.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultParagraphStyle.java
index 9a1a973e8b..77679d2db7 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultParagraphStyle.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultParagraphStyle.java
@@ -17,26 +17,26 @@
package org.apache.poi.xwpf.usermodel;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrGeneral;
/**
* Default Paragraph style, from which other styles will override
* TODO Share logic with {@link XWPFParagraph} which also uses CTPPr
*/
public class XWPFDefaultParagraphStyle {
- private CTPPr ppr;
+ private final CTPPrGeneral ppr;
- public XWPFDefaultParagraphStyle(CTPPr ppr) {
+ public XWPFDefaultParagraphStyle(CTPPrGeneral ppr) {
this.ppr = ppr;
}
- protected CTPPr getPPr() {
+ protected CTPPrGeneral getPPr() {
return ppr;
}
public int getSpacingAfter() {
- if (ppr.isSetSpacing())
- return ppr.getSpacing().getAfter().intValue();
- return -1;
+ return ppr.isSetSpacing() ? (int) Units.toDXA(POIXMLUnits.parseLength(ppr.getSpacing().xgetAfter())) : -1;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultRunStyle.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultRunStyle.java
index 140ca8bfc2..8eb8f6c1e0 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultRunStyle.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDefaultRunStyle.java
@@ -17,12 +17,14 @@
package org.apache.poi.xwpf.usermodel;
-import org.apache.poi.util.Removal;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-
import java.math.BigDecimal;
import java.math.RoundingMode;
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+
/**
* Default Character Run style, from which other styles will override
* TODO Share logic with {@link XWPFRun} which also uses CTRPr
@@ -64,8 +66,8 @@ public class XWPFDefaultRunStyle {
}
private BigDecimal getFontSizeAsBigDecimal(int scale) {
- return (rpr != null && rpr.isSetSz()) ?
- new BigDecimal(rpr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
- null;
+ return (rpr != null && rpr.isSetSz())
+ ? BigDecimal.valueOf(Units.toPoints(POIXMLUnits.parseLength(rpr.getSz().xgetVal()))).divide(BigDecimal.valueOf(4), scale, RoundingMode.HALF_UP)
+ : null;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index 420bbb3c7f..64b877060b 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -64,27 +64,8 @@ import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
* <p>High(ish) level class for working with .docx files.</p>
@@ -508,7 +489,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
CTSectPr ctSectPr = getSection();
if (!ctSectPr.isSetTitlePg()) {
CTOnOff titlePg = ctSectPr.addNewTitlePg();
- titlePg.setVal(STOnOff.ON);
+ titlePg.setVal(STOnOff1.ON);
}
// } else if (type == HeaderFooterType.EVEN) {
// TODO Add support for Even/Odd headings and footers
@@ -530,7 +511,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
CTSectPr ctSectPr = getSection();
if (!ctSectPr.isSetTitlePg()) {
CTOnOff titlePg = ctSectPr.addNewTitlePg();
- titlePg.setVal(STOnOff.ON);
+ titlePg.setVal(STOnOff1.ON);
}
// } else if (type == HeaderFooterType.EVEN) {
// TODO Add support for Even/Odd headings and footers
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
index 58064b00fd..bbf59867d1 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
@@ -23,10 +23,13 @@ import java.util.List;
import java.util.function.Function;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.poi.wp.usermodel.Paragraph;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
@@ -429,7 +432,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public boolean isKeepNext() {
if (getCTP() != null && getCTP().getPPr() != null && getCTP().getPPr().isSetKeepNext()) {
- return getCTP().getPPr().getKeepNext().getVal() == STOnOff.ON;
+ return POIXMLUnits.parseOnOff(getCTP().getPPr().getKeepNext().xgetVal());
}
return false;
}
@@ -441,7 +444,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public void setKeepNext(boolean keepNext) {
CTOnOff state = CTOnOff.Factory.newInstance();
- state.setVal(keepNext ? STOnOff.ON : STOnOff.OFF);
+ state.setVal(keepNext ? STOnOff1.ON : STOnOff1.OFF);
getCTP().getPPr().setKeepNext(state);
}
@@ -874,24 +877,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
if (ctPageBreak == null) {
return false;
}
- return isTruelike(ctPageBreak.getVal());
- }
-
- private static boolean isTruelike(final STOnOff.Enum value) {
- if (value == null) {
- return false;
- }
- switch (value.intValue()) {
- case STOnOff.INT_TRUE:
- case STOnOff.INT_X_1:
- case STOnOff.INT_ON:
- return true;
- /*STOnOff.INT_FALSE:
- STOnOff.INT_X_0:
- STOnOff.INT_OFF:*/
- default:
- return false;
- }
+ return POIXMLUnits.parseOnOff(ctPageBreak.xgetVal());
}
/**
@@ -914,11 +900,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
CTPPr ppr = getCTPPr();
CTOnOff ctPageBreak = ppr.isSetPageBreakBefore() ? ppr
.getPageBreakBefore() : ppr.addNewPageBreakBefore();
- if (pageBreak) {
- ctPageBreak.setVal(STOnOff.TRUE);
- } else {
- ctPageBreak.setVal(STOnOff.FALSE);
- }
+ ctPageBreak.setVal(pageBreak ? STOnOff1.ON : STOnOff1.OFF);
}
/**
@@ -929,7 +911,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public int getSpacingAfter() {
CTSpacing spacing = getCTSpacing(false);
- return (spacing != null && spacing.isSetAfter()) ? spacing.getAfter().intValue() : -1;
+ return (spacing != null && spacing.isSetAfter()) ? (int)Units.toDXA(POIXMLUnits.parseLength(spacing.xgetAfter())) : -1;
}
/**
@@ -995,7 +977,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public int getSpacingBefore() {
CTSpacing spacing = getCTSpacing(false);
- return (spacing != null && spacing.isSetBefore()) ? spacing.getBefore().intValue() : -1;
+ return (spacing != null && spacing.isSetBefore()) ? (int)Units.toDXA(POIXMLUnits.parseLength(spacing.xgetBefore())) : -1;
}
/**
@@ -1088,12 +1070,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
CTSpacing spacing = getCTSpacing(false);
if (spacing == null || !spacing.isSetLine()) {
return -1;
- } else if (spacing.getLineRule() == null || spacing.getLineRule() == STLineSpacingRule.AUTO) {
- BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(240L));
- return val[0].doubleValue() + (val[1].doubleValue() / 240L);
}
- BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(20L));
- return val[0].doubleValue() + (val[1].doubleValue() / 20L);
+
+ double twips = Units.toDXA(POIXMLUnits.parseLength(spacing.xgetLine()));
+
+ return twips / ((spacing.getLineRule() == null || spacing.getLineRule() == STLineSpacingRule.AUTO) ? 240 : 20);
}
/**
@@ -1143,8 +1124,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public int getIndentationLeft() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetLeft()) ? indentation.getLeft().intValue()
- : -1;
+ return (indentation != null && indentation.isSetLeft())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetLeft()))
+ : -1;
}
/**
@@ -1208,8 +1190,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
public int getIndentationRight() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetRight()) ? indentation.getRight().intValue()
- : -1;
+ return (indentation != null && indentation.isSetRight())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetRight()))
+ : -1;
}
/**
@@ -1272,7 +1255,8 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public int getIndentationHanging() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetHanging()) ? indentation.getHanging().intValue() : -1;
+ return (indentation != null && indentation.isSetHanging())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetHanging())) : -1;
}
/**
@@ -1312,8 +1296,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
public int getIndentationFirstLine() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetFirstLine()) ? indentation.getFirstLine().intValue()
- : -1;
+ return (indentation != null && indentation.isSetFirstLine())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetFirstLine()))
+ : -1;
}
/**
@@ -1376,12 +1361,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
@Override
public boolean isWordWrapped() {
- CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
- .getWordWrap() : null;
- if (wordWrap != null) {
- return isTruelike(wordWrap.getVal());
- }
- return false;
+ return getCTPPr().isSetWordWrap() && POIXMLUnits.parseOnOff(getCTPPr().getWordWrap());
}
/**
@@ -1394,12 +1374,14 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
*/
@Override
public void setWordWrapped(boolean wrap) {
- CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
- .getWordWrap() : getCTPPr().addNewWordWrap();
+ CTPPr ppr = getCTPPr();
if (wrap) {
- wordWrap.setVal(STOnOff.TRUE);
+ CTOnOff wordWrap = ppr.isSetWordWrap() ? ppr.getWordWrap() : ppr.addNewWordWrap();
+ wordWrap.setVal(STOnOff1.ON);
} else {
- wordWrap.unsetVal();
+ if (ppr.isSetWordWrap()) {
+ ppr.unsetWordWrap();
+ }
}
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
index bbc49aea1f..c7ba363119 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
@@ -32,10 +32,12 @@ import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.util.DocumentHelper;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
import org.apache.poi.wp.usermodel.CharacterRun;
import org.apache.xmlbeans.SimpleValue;
import org.apache.xmlbeans.XmlCursor;
@@ -61,6 +63,9 @@ import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STHexColorRGB;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
@@ -223,15 +228,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
* For isBold, isItalic etc
*/
private static boolean isCTOnOff(CTOnOff onoff) {
- if (!onoff.isSetVal()) {
- return true;
- }
- final STOnOff.Enum val = onoff.getVal();
- return (
- (STOnOff.TRUE == val) ||
- (STOnOff.X_1 == val) ||
- (STOnOff.ON == val)
- );
+ return !onoff.isSetVal() || POIXMLUnits.parseOnOff(onoff);
}
/**
@@ -297,7 +294,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setBold(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff bold = pr.isSetB() ? pr.getB() : pr.addNewB();
- bold.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ bold.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
@@ -408,7 +405,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setItalic(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff italic = pr.isSetI() ? pr.getI() : pr.addNewI();
- italic.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ italic.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
@@ -573,7 +570,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setStrikeThrough(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff strike = pr.isSetStrike() ? pr.getStrike() : pr.addNewStrike();
- strike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ strike.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Deprecated
@@ -608,7 +605,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setDoubleStrikethrough(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff dstrike = pr.isSetDstrike() ? pr.getDstrike() : pr.addNewDstrike();
- dstrike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ dstrike.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
@@ -621,7 +618,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setSmallCaps(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff caps = pr.isSetSmallCaps() ? pr.getSmallCaps() : pr.addNewSmallCaps();
- caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ caps.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
@@ -634,7 +631,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setCapitalized(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff caps = pr.isSetCaps() ? pr.getCaps() : pr.addNewCaps();
- caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ caps.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
@@ -647,7 +644,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setShadow(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff shadow = pr.isSetShadow() ? pr.getShadow() : pr.addNewShadow();
- shadow.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ shadow.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
@@ -660,7 +657,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setImprinted(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff imprinted = pr.isSetImprint() ? pr.getImprint() : pr.addNewImprint();
- imprinted.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ imprinted.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
@@ -673,7 +670,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setEmbossed(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff emboss = pr.isSetEmboss() ? pr.getEmboss() : pr.addNewEmboss();
- emboss.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ emboss.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
@@ -704,7 +701,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
if (pr == null || !pr.isSetKern()) {
return 0;
}
- return pr.getKern().getVal().intValue();
+ return (int)POIXMLUnits.parseLength(pr.getKern().xgetVal());
}
@Override
@@ -735,7 +732,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
if (pr == null || !pr.isSetSpacing()) {
return 0;
}
- return pr.getSpacing().getVal().intValue();
+ return (int)Units.toDXA(POIXMLUnits.parseLength(pr.getSpacing().xgetVal()));
}
@Override
@@ -878,9 +875,9 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
private BigDecimal getFontSizeAsBigDecimal(int scale) {
CTRPr pr = getRunProperties(false);
- return (pr != null && pr.isSetSz()) ?
- new BigDecimal(pr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
- null;
+ return (pr != null && pr.isSetSz())
+ ? BigDecimal.valueOf(Units.toPoints(POIXMLUnits.parseLength(pr.getSz().xgetVal()))).divide(BigDecimal.valueOf(4), scale, RoundingMode.HALF_UP)
+ : null;
}
/**
@@ -936,7 +933,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
*/
public int getTextPosition() {
CTRPr pr = getRunProperties(false);
- return (pr != null && pr.isSetPosition()) ? pr.getPosition().getVal().intValue()
+ return (pr != null && pr.isSetPosition()) ? (int)(Units.toPoints(POIXMLUnits.parseLength(pr.getPosition().xgetVal())) / 2.)
: -1;
}
@@ -1385,11 +1382,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
if (ctfldChar.getFldCharType() == STFldCharType.BEGIN) {
if (ctfldChar.getFfData() != null) {
for (CTFFCheckBox checkBox : ctfldChar.getFfData().getCheckBoxList()) {
- if (checkBox.getDefault() != null && checkBox.getDefault().getVal() == STOnOff.X_1) {
- text.append("|X|");
- } else {
- text.append("|_|");
- }
+ text.append((checkBox.getDefault() != null && POIXMLUnits.parseOnOff(checkBox.getDefault().xgetVal())) ? "|X|" : "|_|");
}
}
}
@@ -1455,13 +1448,14 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
* @since 4.0.0
*/
public int getTextScale() {
- CTRPr pr = getRunProperties(true);
- CTTextScale scale = pr.isSetW() ? pr.getW() : pr.addNewW();
- int value = scale.getVal();
- if (value == 0) {
- value = 100; // 100% scaling, that is, no change. See 17.3.2.43 w (Expanded/Compressed Text)
+ CTRPr pr = getRunProperties(false);
+ if (pr == null || !pr.isSetW()) {
+ return 100;
}
- return value;
+
+ int value = POIXMLUnits.parsePercent(pr.getW().xgetVal());
+ // 100% scaling, that is, no change. See 17.3.2.43 w (Expanded/Compressed Text)
+ return value == 0 ? 100 : value / 1000;
}
/**
@@ -1522,7 +1516,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
public void setVanish(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff vanish = pr.isSetVanish() ? pr.getVanish() : pr.addNewVanish();
- vanish.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ vanish.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
index 39a8444b8b..8df9e3f806 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
@@ -29,19 +29,20 @@ import javax.xml.namespace.QName;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgClass;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgType;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STCryptProv;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSettings;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTZoom;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STAlgClass;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STAlgType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STCryptProv;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.SettingsDocument;
public class XWPFSettings extends POIXMLDocumentPart {
@@ -54,7 +55,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
public XWPFSettings(PackagePart part) throws IOException {
super(part);
}
-
+
public XWPFSettings() {
super();
ctSettings = CTSettings.Factory.newInstance();
@@ -86,12 +87,8 @@ public class XWPFSettings extends POIXMLDocumentPart {
zoom = ctSettings.getZoom();
}
-
- BigInteger percent = zoom.getPercent();
- if(percent == null) {
- return 100;
- }
- return percent.longValue();
+
+ return (zoom.getPercent() == null) ? 100 : POIXMLUnits.parsePercent(zoom.xgetPercent()) / 1000;
}
/**
@@ -111,7 +108,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
CTZoom zoom = ctSettings.getZoom();
zoom.setPercent(BigInteger.valueOf(zoomPercent));
}
-
+
/**
* Verifies the documentProtection tag inside settings.xml file <br>
* if the protection is enforced (w:enforcement="1") <br>
@@ -127,12 +124,8 @@ public class XWPFSettings extends POIXMLDocumentPart {
*/
public boolean isEnforcedWith() {
CTDocProtect ctDocProtect = ctSettings.getDocumentProtection();
+ return ctDocProtect != null && POIXMLUnits.parseOnOff(ctDocProtect.xgetEnforcement());
- if (ctDocProtect == null) {
- return false;
- }
-
- return ctDocProtect.getEnforcement().equals(STOnOff.X_1);
}
/**
@@ -151,12 +144,8 @@ public class XWPFSettings extends POIXMLDocumentPart {
*/
public boolean isEnforcedWith(STDocProtect.Enum editValue) {
CTDocProtect ctDocProtect = ctSettings.getDocumentProtection();
+ return ctDocProtect != null && POIXMLUnits.parseOnOff(ctDocProtect.xgetEnforcement()) && ctDocProtect.getEdit().equals(editValue);
- if (ctDocProtect == null) {
- return false;
- }
-
- return ctDocProtect.getEnforcement().equals(STOnOff.X_1) && ctDocProtect.getEdit().equals(editValue);
}
/**
@@ -173,7 +162,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
* </pre>
*/
public void setEnforcementEditValue(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect.Enum editValue) {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_1);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.ON);
safeGetDocumentProtection().setEdit(editValue);
}
@@ -196,7 +185,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
*/
public void setEnforcementEditValue(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect.Enum editValue,
String password, HashAlgorithm hashAlgo) {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_1);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.ON);
safeGetDocumentProtection().setEdit(editValue);
if (password == null) {
@@ -233,7 +222,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
if (hashAlgo == null) {
hashAlgo = HashAlgorithm.sha1;
}
-
+
switch (hashAlgo) {
case md2:
providerType = STCryptProv.RSA_FULL;
@@ -295,7 +284,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
/**
* Validates the existing password
*
- * @param password
+ * @param password the password
* @return true, only if password was set and equals, false otherwise
*/
public boolean validateProtectionPassword(String password) {
@@ -348,7 +337,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
* it sets the value of enforcement to "0" (w:enforcement="0") <br>
*/
public void removeEnforcement() {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_0);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.OFF);
}
/**
@@ -365,12 +354,12 @@ public class XWPFSettings extends POIXMLDocumentPart {
*/
public void setUpdateFields() {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(STOnOff.TRUE);
+ onOff.setVal(STOnOff1.ON);
ctSettings.setUpdateFields(onOff);
}
boolean isUpdateFields() {
- return ctSettings.isSetUpdateFields() && ctSettings.getUpdateFields().getVal() == STOnOff.TRUE;
+ return ctSettings.isSetUpdateFields() && POIXMLUnits.parseOnOff(ctSettings.getUpdateFields().xgetVal());
}
/**
@@ -443,12 +432,12 @@ public class XWPFSettings extends POIXMLDocumentPart {
/**
* Turn separate even-and-odd headings on or off
*
- * @param enable <code>true</code> to turn on separate even and odd headings,
+ * @param enable <code>true</code> to turn on separate even and odd headings,
* <code>false</code> to turn off even and odd headings.
*/
public void setEvenAndOddHeadings(boolean enable) {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE);
+ onOff.setVal(enable ? STOnOff1.ON : STOnOff1.OFF);
ctSettings.setEvenAndOddHeaders(onOff);
}
@@ -464,12 +453,12 @@ public class XWPFSettings extends POIXMLDocumentPart {
/**
* Turn mirrored margins on or off
*
- * @param enable <code>true</code> to turn on mirrored margins,
+ * @param enable <code>true</code> to turn on mirrored margins,
* <code>false</code> to turn off mirrored marginss.
*/
public void setMirrorMargins(boolean enable) {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE);
+ onOff.setVal(enable ? STOnOff1.ON : STOnOff1.OFF);
ctSettings.setMirrorMargins(onOff);
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
index 0705bbe696..b8294c771a 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
@@ -26,10 +26,12 @@ import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJcTable;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
@@ -40,7 +42,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJcTable;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
/**
@@ -279,7 +281,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
*/
public int getWidth() {
CTTblPr tblPr = getTblPr();
- return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
+ return tblPr.isSetTblW() ? (int)Units.toDXA(POIXMLUnits.parseLength(tblPr.getTblW().xgetW())) : -1;
}
/**
@@ -407,8 +409,8 @@ public class XWPFTable implements IBodyElement, ISDTContents {
*/
public void setTableAlignment(TableRowAlign tra) {
CTTblPr tPr = getTblPr(true);
- CTJc jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
- jc.setVal(STJc.Enum.forInt(tra.getValue()));
+ CTJcTable jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
+ jc.setVal(STJcTable.Enum.forInt(tra.getValue()));
}
/**
@@ -985,7 +987,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
if (tcm != null) {
CTTblWidth tw = margin.apply(tcm);
if (tw != null) {
- return tw.getW().intValue();
+ return (int) Units.toDXA(POIXMLUnits.parseLength(tw.xgetW()));
}
}
return 0;
@@ -1154,11 +1156,11 @@ public class XWPFTable implements IBodyElement, ISDTContents {
if (typeValue == STTblWidth.DXA
|| typeValue == STTblWidth.AUTO
|| typeValue == STTblWidth.NIL) {
- result = 0.0 + ctWidth.getW().intValue();
+ result = 0.0 + Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW()));
} else if (typeValue == STTblWidth.PCT) {
// Percentage values are stored as integers that are 50 times
// percentage.
- result = ctWidth.getW().intValue() / 50.0;
+ result = Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW())) / 50.0;
} else {
// Should never get here
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
index 8490154cbf..57f7d20516 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
@@ -23,7 +23,9 @@ import java.util.HashMap;
import java.util.List;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
@@ -528,8 +530,8 @@ public class XWPFTableCell implements IBody, ICell {
* @return Width value as a double-precision decimal.
* @since 4.0.0
*/
- public double getWidthDecimal() {
- return XWPFTable.getWidthDecimal(getTcWidth());
+ public double getWidthDecimal() {
+ return XWPFTable.getWidthDecimal(getTcWidth());
}
/**
@@ -541,7 +543,7 @@ public class XWPFTableCell implements IBody, ICell {
* @since 4.0.0
*/
public TableWidthType getWidthType() {
- return XWPFTable.getWidthType(getTcWidth());
+ return XWPFTable.getWidthType(getTcWidth());
}
/**
@@ -551,7 +553,7 @@ public class XWPFTableCell implements IBody, ICell {
* @since 4.0.0
*/
public void setWidth(String widthValue) {
- XWPFTable.setWidthValue(widthValue, getTcWidth());
+ XWPFTable.setWidthValue(widthValue, getTcWidth());
}
private CTTblWidth getTcWidth() {
@@ -582,6 +584,6 @@ public class XWPFTableCell implements IBody, ICell {
}
public int getWidth() {
- return getTcWidth().getW().intValue();
+ return (int) Units.toDXA(POIXMLUnits.parseLength(getTcWidth().xgetW()));
}
}
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
index 953ca6db08..c01643ec0d 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
@@ -20,10 +20,12 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
-import org.apache.poi.xwpf.model.WMLHelper;
+import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
@@ -101,7 +103,7 @@ public class XWPFTableRow {
*/
public int getHeight() {
CTTrPr properties = getTrPr();
- return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
+ return properties.sizeOfTrHeightArray() == 0 ? 0 : (int) Units.toDXA(POIXMLUnits.parseLength(properties.getTrHeightArray(0).xgetVal()));
}
/**
@@ -229,7 +231,7 @@ public class XWPFTableRow {
CTTrPr trpr = getTrPr();
if (trpr.sizeOfCantSplitArray() > 0) {
CTOnOff onoff = trpr.getCantSplitArray(0);
- isCant = (onoff.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(onoff.getVal()) : true);
+ isCant = !onoff.isSetVal() || POIXMLUnits.parseOnOff(onoff.xgetVal());
}
}
return isCant;
@@ -246,7 +248,7 @@ public class XWPFTableRow {
public void setCantSplitRow(boolean split) {
CTTrPr trpr = getTrPr();
CTOnOff onoff = (trpr.sizeOfCantSplitArray() > 0 ? trpr.getCantSplitArray(0) : trpr.addNewCantSplit());
- onoff.setVal(WMLHelper.convertBooleanToSTOnOff(split));
+ onoff.setVal(split ? STOnOff1.ON : STOnOff1.OFF);
}
/**
@@ -254,7 +256,7 @@ public class XWPFTableRow {
* table split across pages. NOTE - Word will not repeat a table row unless
* all preceding rows of the table are also repeated. This function returns
* false if the row will not be repeated even if the repeat tag is present
- * for this row.
+ * for this row.
*
* @return true if table's header row should be repeated at the top of each
* page of table, false otherwise.
@@ -269,14 +271,14 @@ public class XWPFTableRow {
}
return repeat;
}
-
+
private boolean getRepeat() {
boolean repeat = false;
if (ctRow.isSetTrPr()) {
CTTrPr trpr = getTrPr();
if (trpr.sizeOfTblHeaderArray() > 0) {
CTOnOff rpt = trpr.getTblHeaderArray(0);
- repeat = (rpt.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(rpt.getVal()) : true);
+ repeat = !rpt.isSetVal() || POIXMLUnits.parseOnOff(rpt.xgetVal());
}
}
return repeat;
@@ -293,6 +295,6 @@ public class XWPFTableRow {
public void setRepeatHeader(boolean repeat) {
CTTrPr trpr = getTrPr();
CTOnOff onoff = (trpr.sizeOfTblHeaderArray() > 0 ? trpr.getTblHeaderArray(0) : trpr.addNewTblHeader());
- onoff.setVal(WMLHelper.convertBooleanToSTOnOff(repeat));
+ onoff.setVal(repeat ? STOnOff1.ON : STOnOff1.OFF);
}
}
diff --git a/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip b/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip
new file mode 100644
index 0000000000..5a2e31dd99
--- /dev/null
+++ b/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip
Binary files differ
diff --git a/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip b/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip
deleted file mode 100644
index dacf2bd59a..0000000000
--- a/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip
+++ /dev/null
Binary files differ
diff --git a/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip b/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip
index 5ff09c4449..5c4f52cea7 100644
--- a/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip
+++ b/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip
Binary files differ
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
index e4d8d4c331..49dba1a091 100644
--- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
+++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
@@ -21,6 +21,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@@ -47,10 +52,6 @@ import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
public final class TestContentTypeManager {
/**
@@ -176,10 +177,10 @@ public final class TestContentTypeManager {
anchor = (XSSFClientAnchor) helper.createClientAnchor();
CTMarker markerFrom = oldAnchor.getFrom();
CTMarker markerTo = oldAnchor.getTo();
- anchor.setDx1((int) markerFrom.getColOff());
- anchor.setDx2((int) markerTo.getColOff());
- anchor.setDy1((int) markerFrom.getRowOff());
- anchor.setDy2((int) markerTo.getRowOff());
+ anchor.setDx1((int) POIXMLUnits.parseLength(markerFrom.xgetColOff()));
+ anchor.setDx2((int) POIXMLUnits.parseLength(markerTo.xgetColOff()));
+ anchor.setDy1((int) POIXMLUnits.parseLength(markerFrom.xgetRowOff()));
+ anchor.setDy2((int) POIXMLUnits.parseLength(markerTo.xgetRowOff()));
anchor.setCol1(markerFrom.getCol());
anchor.setCol2(markerTo.getCol());
anchor.setRow1(markerFrom.getRow());
diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java
index 156133ad62..ca0775dd2f 100644
--- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java
+++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestXDDFColor.java
@@ -124,5 +124,8 @@ public class TestXDDFColor {
built = (XDDFColorRgbPercent) XDDFColor.from(654321, 654321, 654321);
assertEquals(expected, built.getXmlObject().toString());
assertEquals("FFFFFF", built.toRGBHex());
+
+ built = (XDDFColorRgbPercent) XDDFColor.from(75000, 50000, 25000);
+ assertEquals("BF7F3F", built.toRGBHex());
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
index 05ab555550..a6f75c520b 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
@@ -17,6 +17,8 @@
package org.apache.poi.xssf.usermodel;
+import static org.junit.Assert.*;
+
import java.io.IOException;
import org.apache.poi.common.usermodel.fonts.FontCharset;
@@ -33,9 +35,11 @@ import org.apache.poi.util.LocaleUtil;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
@@ -44,9 +48,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
-
-import static org.junit.Assert.*;
public final class TestXSSFFont extends BaseTestFont{
@@ -330,7 +331,7 @@ public final class TestXSSFFont extends BaseTestFont{
@Test
public void testFamily() {
CTFont ctFont=CTFont.Factory.newInstance();
- CTIntProperty family=ctFont.addNewFamily();
+ CTFontFamily family=ctFont.addNewFamily();
family.setVal(FontFamily.MODERN.getValue());
ctFont.setFamilyArray(0,family);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
index 8d4cb67a16..e83ad65ead 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
@@ -34,10 +34,10 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
/**
* Tests functionality of the XSSFRichTextRun object
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java
index b57c255b40..8dbd8e7a81 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFVMLDrawing.java
@@ -35,7 +35,6 @@ import java.util.regex.Pattern;
import com.microsoft.schemas.office.excel.CTClientData;
import com.microsoft.schemas.office.excel.STObjectType;
-import com.microsoft.schemas.office.excel.STTrueFalseBlank;
import com.microsoft.schemas.office.office.CTShapeLayout;
import com.microsoft.schemas.office.office.STConnectType;
import com.microsoft.schemas.office.office.STInsetMode;
@@ -43,12 +42,13 @@ import com.microsoft.schemas.vml.CTShadow;
import com.microsoft.schemas.vml.CTShape;
import com.microsoft.schemas.vml.CTShapetype;
import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
import org.apache.poi.POIDataSamples;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank;
public class TestXSSFVMLDrawing {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java
new file mode 100644
index 0000000000..8a85d8b7ce
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSF3DChartData.java
@@ -0,0 +1,112 @@
+/* ====================================================================
+ 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.xssf.usermodel.charts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.SheetBuilder;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.XDDFArea3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFBar3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFLine3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
+
+/**
+ * Tests for XSSF Area3d Charts
+ */
+public class TestXSSF3DChartData {
+
+ private static final Object[][] plotData = {
+ {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"},
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+ };
+
+ @Test
+ public void testArea3D() throws IOException {
+ // This test currently doesn't produce a valid area 3d chart and is only used to test accessors
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+
+ Map<ChartTypes, Consumer<XDDFChartData>> map = new HashMap<>();
+ map.put(ChartTypes.AREA3D, this::handleArea3D);
+ map.put(ChartTypes.BAR3D, this::handleBar3D);
+ map.put(ChartTypes.LINE3D, this::handleLine3D);
+
+ for (Map.Entry<ChartTypes, Consumer<XDDFChartData>> me : map.entrySet()) {
+
+ XSSFChart chart = drawing.createChart(anchor);
+
+ XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+
+ XDDFDataSource<String> xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
+ XDDFNumericalDataSource<Double> ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
+
+ XDDFChartData data = chart.createData(me.getKey(), bottomAxis, leftAxis);
+ XDDFChartData.Series series = data.addSeries(xs, ys);
+
+ assertNotNull(series);
+ assertEquals(1, data.getSeriesCount());
+ assertEquals(series, data.getSeries(0));
+ chart.plot(data);
+
+ me.getValue().accept(data);
+ }
+ }
+ }
+
+ private void handleArea3D(XDDFChartData data) {
+ XDDFArea3DChartData xArea3d = (XDDFArea3DChartData)data;
+ xArea3d.setGapDepth(10);
+ assertEquals(10, (int)xArea3d.getGapDepth());
+ }
+
+ private void handleBar3D(XDDFChartData data) {
+ XDDFBar3DChartData xBar3d = (XDDFBar3DChartData) data;
+ xBar3d.setGapDepth(10);
+ assertEquals(10, (int)xBar3d.getGapDepth());
+ xBar3d.setGapWidth(10);
+ assertEquals(10, (int)xBar3d.getGapWidth());
+ }
+
+ private void handleLine3D(XDDFChartData data) {
+ XDDFLine3DChartData xLine3d = (XDDFLine3DChartData) data;
+ xLine3d.setGapDepth(10);
+ assertEquals(10, (int)xLine3d.getGapDepth());
+ }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
index 6dd394a215..d9985ab30f 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
@@ -32,6 +32,7 @@ import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
@@ -46,7 +47,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
/**
@@ -163,9 +163,9 @@ public final class TestXWPFParagraph {
assertEquals(10, p.getSpacingBefore());
p.setSpacingAfter(100);
- assertEquals(100, spacing.getAfter().intValue());
+ assertEquals("100", spacing.xgetAfter().getStringValue());
p.setSpacingBefore(100);
- assertEquals(100, spacing.getBefore().intValue());
+ assertEquals("100", spacing.xgetBefore().getStringValue());
p.setSpacingBetween(.25, LineSpacingRule.EXACT);
assertEquals(.25, p.getSpacingBetween(), 0.01);
@@ -197,7 +197,7 @@ public final class TestXWPFParagraph {
assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
p.setSpacingAfter(100);
- assertEquals(100, spacing.getAfter().intValue());
+ assertEquals("100", spacing.xgetAfter().getStringValue());
}
}
@@ -234,7 +234,7 @@ public final class TestXWPFParagraph {
assertEquals(10, p.getIndentationLeft());
p.setIndentationLeft(100);
- assertEquals(100, ind.getLeft().intValue());
+ assertEquals("100", ind.xgetLeft().getStringValue());
}
}
@Test
@@ -264,11 +264,11 @@ public final class TestXWPFParagraph {
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
CTOnOff wordWrap = ppr.addNewWordWrap();
- wordWrap.setVal(STOnOff.FALSE);
+ wordWrap.setVal(STOnOff1.OFF);
assertFalse(p.isWordWrap());
p.setWordWrapped(true);
- assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
+ assertEquals("on", ppr.getWordWrap().getVal());
}
}
@@ -281,11 +281,11 @@ public final class TestXWPFParagraph {
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
CTOnOff pageBreak = ppr.addNewPageBreakBefore();
- pageBreak.setVal(STOnOff.FALSE);
+ pageBreak.setVal(STOnOff1.OFF);
assertFalse(p.isPageBreak());
p.setPageBreak(true);
- assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
+ assertEquals("on", ppr.getPageBreakBefore().getVal());
}
}
@@ -713,7 +713,7 @@ public final class TestXWPFParagraph {
assertTrue(p.removeRun(0));
}
}
-
+
@Test
public void testFieldRuns() throws IOException {
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx")) {
@@ -777,7 +777,7 @@ public final class TestXWPFParagraph {
/**
* Tests for numbered lists
- *
+ *
* See also https://github.com/jimklo/apache-poi-sample/blob/master/src/main/java/com/sri/jklo/StyledDocument.java
* for someone else trying a similar thing
*/
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
index b154f37d41..e29186ab10 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
@@ -16,6 +16,19 @@
==================================================================== */
package org.apache.poi.xwpf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Units;
@@ -28,16 +41,19 @@ import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STEm;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
/**
* Tests for XWPF Run
@@ -88,34 +104,34 @@ public class TestXWPFRun {
@Test
public void testCTOnOff() {
CTRPr rpr = ctRun.addNewRPr();
- CTOnOff bold = rpr.addNewB();
+ CTOnOff bold = rpr.addNewB();
XWPFRun run = new XWPFRun(ctRun, irb);
// True values: "true", "1", "on"
- bold.setVal(STOnOff.TRUE);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
- bold.setVal(STOnOff.X_1);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
- bold.setVal(STOnOff.ON);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
// False values: "false", "0", "off"
- bold.setVal(STOnOff.FALSE);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
- bold.setVal(STOnOff.X_0);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
- bold.setVal(STOnOff.OFF);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
}
@Test
public void testSetGetBold() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewB().setVal(STOnOff.TRUE);
+ rpr.addNewB().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isBold());
@@ -123,31 +139,31 @@ public class TestXWPFRun {
run.setBold(false);
// Implementation detail: POI natively prefers <w:b w:val="false"/>,
// but should correctly read val="0" and val="off"
- assertEquals(STOnOff.FALSE, rpr.getB().getVal());
+ assertEquals("off", rpr.getB().getVal());
}
@Test
public void testSetGetItalic() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewI().setVal(STOnOff.TRUE);
+ rpr.addNewI().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isItalic());
run.setItalic(false);
- assertEquals(STOnOff.FALSE, rpr.getI().getVal());
+ assertEquals("off", rpr.getI().getVal());
}
@Test
public void testSetGetStrike() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewStrike().setVal(STOnOff.TRUE);
+ rpr.addNewStrike().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isStrikeThrough());
run.setStrikeThrough(false);
- assertEquals(STOnOff.FALSE, rpr.getStrike().getVal());
+ assertEquals("off", rpr.getStrike().getVal());
}
@Test
@@ -186,10 +202,10 @@ public class TestXWPFRun {
assertEquals(7.0, run.getFontSizeAsDouble(), 0.01);
run.setFontSize(24);
- assertEquals(48, rpr.getSz().getVal().longValue());
+ assertEquals("48", rpr.getSz().getVal().toString());
run.setFontSize(24.5f);
- assertEquals(49, rpr.getSz().getVal().longValue());
+ assertEquals("49", rpr.getSz().getVal().toString());
assertEquals(25, run.getFontSize());
assertEquals(24.5, run.getFontSizeAsDouble(), 0.01);
}
@@ -203,7 +219,7 @@ public class TestXWPFRun {
assertEquals(4000, run.getTextPosition());
run.setTextPosition(2400);
- assertEquals(2400, rpr.getPosition().getVal().longValue());
+ assertEquals("2400", rpr.getPosition().getVal().toString());
}
@Test
@@ -408,7 +424,7 @@ public class TestXWPFRun {
assertFalse(run.isItalic());
assertFalse(run.isStrikeThrough());
assertNull(run.getCTR().getRPr());
-
+
doc.close();
}
@@ -481,17 +497,17 @@ public class TestXWPFRun {
assertEquals(1, doc.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().size());
-
+
XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
XWPFParagraph pBack = docBack.getParagraphArray(2);
XWPFRun rBack = pBack.getRuns().get(0);
-
+
assertEquals(1, docBack.getAllPictures().size());
assertEquals(1, rBack.getEmbeddedPictures().size());
docBack.close();
doc.close();
}
-
+
/**
* Bugzilla #58237 - Unable to add image to word document header
*/
@@ -501,7 +517,7 @@ public class TestXWPFRun {
XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
XWPFParagraph p = hdr.createParagraph();
XWPFRun r = p.createRun();
-
+
assertEquals(0, hdr.getAllPictures().size());
assertEquals(0, r.getEmbeddedPictures().size());
@@ -509,23 +525,23 @@ public class TestXWPFRun {
assertEquals(1, hdr.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().size());
-
+
XWPFPicture pic = r.getEmbeddedPictures().get(0);
CTPicture ctPic = pic.getCTPicture();
CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
assertNotNull(ctBlipFill);
-
+
CTBlip ctBlip = ctBlipFill.getBlip();
-
+
assertNotNull(ctBlip);
assertEquals("rId1", ctBlip.getEmbed());
-
+
XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
XWPFHeader hdrBack = docBack.getHeaderArray(0);
XWPFParagraph pBack = hdrBack.getParagraphArray(0);
XWPFRun rBack = pBack.getRuns().get(0);
-
+
assertEquals(1, hdrBack.getAllPictures().size());
assertEquals(1, rBack.getEmbeddedPictures().size());
docBack.close();
@@ -633,7 +649,7 @@ public class TestXWPFRun {
run.setTextPosition(-1);
assertEquals(-1, run.getTextPosition());
-
+
document.close();
}
@@ -658,7 +674,7 @@ public class TestXWPFRun {
run.setImprinted(true);
run.setItalic(true);
}
-
+
@Test
public void testSetGetTextScale() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -668,7 +684,7 @@ public class TestXWPFRun {
assertEquals(200, run.getTextScale());
document.close();
}
-
+
@Test
public void testSetGetTextHighlightColor() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -680,7 +696,7 @@ public class TestXWPFRun {
assertTrue(run.isHighlighted());
run.setTextHighlightColor("none");
assertFalse(run.isHighlighted());
-
+
document.close();
}
@@ -695,7 +711,7 @@ public class TestXWPFRun {
assertFalse(run.isVanish());
document.close();
}
-
+
@Test
public void testSetGetVerticalAlignment() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -732,7 +748,7 @@ public class TestXWPFRun {
assertEquals(STEm.DOT, run.getEmphasisMark());
document.close();
}
-
+
@Test
public void testSetGetUnderlineColor() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -747,7 +763,7 @@ public class TestXWPFRun {
assertEquals("auto", run.getUnderlineColor());
document.close();
}
-
+
@Test
public void testSetGetUnderlineThemeColor() throws IOException {
XWPFDocument document = new XWPFDocument();
@@ -762,13 +778,13 @@ public class TestXWPFRun {
assertEquals(STThemeColor.NONE, run.getUnderlineThemeColor());
document.close();
}
-
+
@Test
public void testSetStyleId() throws IOException {
XWPFDocument document = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
final XWPFRun run = document.createParagraph().createRun();
-
+
String styleId = "bolditalic";
run.setStyle(styleId);
String candStyleId = run.getCTR().getRPr().getRStyle().getVal();
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
index a110d17019..52f2404363 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
@@ -19,7 +19,6 @@ package org.apache.poi.xwpf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.math.BigInteger;
@@ -35,6 +34,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblCellMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
@@ -46,218 +46,190 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
public class TestXWPFTable {
@Test
- public void testConstructor() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable xtab = new XWPFTable(ctTable, doc);
- assertNotNull(xtab);
- assertEquals(1, ctTable.sizeOfTrArray());
- assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
- assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-
- ctTable = CTTbl.Factory.newInstance();
- xtab = new XWPFTable(ctTable, doc, 3, 2);
- assertNotNull(xtab);
- assertEquals(3, ctTable.sizeOfTrArray());
- assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
- assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testConstructor() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable xtab = new XWPFTable(ctTable, doc);
+ assertNotNull(xtab);
+ assertEquals(1, ctTable.sizeOfTrArray());
+ assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
+ assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+
+ ctTable = CTTbl.Factory.newInstance();
+ xtab = new XWPFTable(ctTable, doc, 3, 2);
+ assertNotNull(xtab);
+ assertEquals(3, ctTable.sizeOfTrArray());
+ assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
+ assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
}
}
@Test
- public void testTblGrid() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- CTTblGrid cttblgrid = ctTable.addNewTblGrid();
- cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
- cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
-
- XWPFTable xtab = new XWPFTable(ctTable, doc);
- assertEquals(123, xtab.getCTTbl().getTblGrid().getGridColArray(0).getW().intValue());
- assertEquals(321, xtab.getCTTbl().getTblGrid().getGridColArray(1).getW().intValue());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testTblGrid() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ CTTblGrid cttblgrid = ctTable.addNewTblGrid();
+ cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
+ cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
+
+ XWPFTable xtab = new XWPFTable(ctTable, doc);
+ CTTblGridCol[] ca = xtab.getCTTbl().getTblGrid().getGridColArray();
+ assertEquals("123", ca[0].getW().toString());
+ assertEquals("321", ca[1].getW().toString());
}
}
@Test
- public void testGetText() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl table = CTTbl.Factory.newInstance();
- CTRow row = table.addNewTr();
- CTTc cell = row.addNewTc();
- CTP paragraph = cell.addNewP();
- CTR run = paragraph.addNewR();
- CTText text = run.addNewT();
- text.setStringValue("finally I can write!");
-
- XWPFTable xtab = new XWPFTable(table, doc);
- assertEquals("finally I can write!\n", xtab.getText());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testGetText() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl table = CTTbl.Factory.newInstance();
+ CTRow row = table.addNewTr();
+ CTTc cell = row.addNewTc();
+ CTP paragraph = cell.addNewP();
+ CTR run = paragraph.addNewR();
+ CTText text = run.addNewT();
+ text.setStringValue("finally I can write!");
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ assertEquals("finally I can write!\n", xtab.getText());
}
}
@Test
- public void testCreateRow() {
- XWPFDocument doc = new XWPFDocument();
-
- CTTbl table = CTTbl.Factory.newInstance();
- CTRow r1 = table.addNewTr();
- r1.addNewTc().addNewP();
- r1.addNewTc().addNewP();
- CTRow r2 = table.addNewTr();
- r2.addNewTc().addNewP();
- r2.addNewTc().addNewP();
- CTRow r3 = table.addNewTr();
- r3.addNewTc().addNewP();
- r3.addNewTc().addNewP();
-
- XWPFTable xtab = new XWPFTable(table, doc);
- assertEquals(3, xtab.getNumberOfRows());
- assertNotNull(xtab.getRow(2));
-
- //add a new row
- xtab.createRow();
- assertEquals(4, xtab.getNumberOfRows());
-
- //check number of cols
- assertEquals(2, table.getTrArray(0).sizeOfTcArray());
-
- //check creation of first row
- xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
- assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testCreateRow() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ CTTbl table = CTTbl.Factory.newInstance();
+ CTRow r1 = table.addNewTr();
+ r1.addNewTc().addNewP();
+ r1.addNewTc().addNewP();
+ CTRow r2 = table.addNewTr();
+ r2.addNewTc().addNewP();
+ r2.addNewTc().addNewP();
+ CTRow r3 = table.addNewTr();
+ r3.addNewTc().addNewP();
+ r3.addNewTc().addNewP();
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ assertEquals(3, xtab.getNumberOfRows());
+ assertNotNull(xtab.getRow(2));
+
+ //add a new row
+ xtab.createRow();
+ assertEquals(4, xtab.getNumberOfRows());
+
+ //check number of cols
+ assertEquals(2, table.getTrArray(0).sizeOfTcArray());
+
+ //check creation of first row
+ xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
+ assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
}
}
@Test
- public void testSetGetWidth() {
- XWPFDocument doc = new XWPFDocument();
-
- XWPFTable xtab = doc.createTable();
-
- assertEquals(0, xtab.getWidth());
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
-
- xtab.setWidth(1000);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(1000, xtab.getWidth());
-
- xtab.setWidth("auto");
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
- assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
-
- xtab.setWidth("999");
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(999, xtab.getWidth());
-
- xtab.setWidth("50.5%");
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
- assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
-
- // Test effect of setting width type to a new value
-
- // From PCT to NIL:
- xtab.setWidthType(TableWidthType.NIL);
- assertEquals(TableWidthType.NIL, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- xtab.setWidth("999"); // Sets type to DXA
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
-
- // From DXA to AUTO:
- xtab.setWidthType(TableWidthType.AUTO);
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- xtab.setWidthType(TableWidthType.PCT);
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
-
- // From PCT to DXA:
- xtab.setWidth("33.3%");
- xtab.setWidthType(TableWidthType.DXA);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- // From DXA to DXA: (value should be unchanged)
- xtab.setWidth("999");
- xtab.setWidthType(TableWidthType.DXA);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(999, xtab.getWidth());
-
- // From DXA to PCT:
- xtab.setWidthType(TableWidthType.PCT);
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
- assertEquals(100.0, xtab.getWidthDecimal(), 0.0);
-
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetWidth() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ XWPFTable xtab = doc.createTable();
+
+ assertEquals(0, xtab.getWidth());
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+
+ xtab.setWidth(1000);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(1000, xtab.getWidth());
+
+ xtab.setWidth("auto");
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+ assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
+
+ xtab.setWidth("999");
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(999, xtab.getWidth());
+
+ xtab.setWidth("50.5%");
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+ assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
+
+ // Test effect of setting width type to a new value
+
+ // From PCT to NIL:
+ xtab.setWidthType(TableWidthType.NIL);
+ assertEquals(TableWidthType.NIL, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ xtab.setWidth("999"); // Sets type to DXA
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+
+ // From DXA to AUTO:
+ xtab.setWidthType(TableWidthType.AUTO);
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ xtab.setWidthType(TableWidthType.PCT);
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+
+ // From PCT to DXA:
+ xtab.setWidth("33.3%");
+ xtab.setWidthType(TableWidthType.DXA);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ // From DXA to DXA: (value should be unchanged)
+ xtab.setWidth("999");
+ xtab.setWidthType(TableWidthType.DXA);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(999, xtab.getWidth());
+
+ // From DXA to PCT:
+ xtab.setWidthType(TableWidthType.PCT);
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+ assertEquals(100.0, xtab.getWidthDecimal(), 0.0);
}
}
@Test
- public void testSetGetHeight() {
- XWPFDocument doc = new XWPFDocument();
-
- CTTbl table = CTTbl.Factory.newInstance();
-
- XWPFTable xtab = new XWPFTable(table, doc);
- XWPFTableRow row = xtab.createRow();
- row.setHeight(20);
- assertEquals(20, row.getHeight());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetHeight() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ CTTbl table = CTTbl.Factory.newInstance();
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ XWPFTableRow row = xtab.createRow();
+ row.setHeight(20);
+ assertEquals(20, row.getHeight());
}
}
@Test
- public void testSetGetMargins() {
+ public void testSetGetMargins() throws IOException {
// instantiate the following class so it'll get picked up by
// the XmlBean process and added to the jar file. it's required
// for the following XWPFTable methods.
CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
assertNotNull(ctm);
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // set margins
- table.setCellMargins(50, 50, 250, 450);
- // get margin components
- int t = table.getCellMarginTop();
- assertEquals(50, t);
- int l = table.getCellMarginLeft();
- assertEquals(50, l);
- int b = table.getCellMarginBottom();
- assertEquals(250, b);
- int r = table.getCellMarginRight();
- assertEquals(450, r);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // set margins
+ table.setCellMargins(50, 50, 250, 450);
+ // get margin components
+ int t = table.getCellMarginTop();
+ assertEquals(50, t);
+ int l = table.getCellMarginLeft();
+ assertEquals(50, l);
+ int b = table.getCellMarginBottom();
+ assertEquals(250, b);
+ int r = table.getCellMarginRight();
+ assertEquals(450, r);
}
}
@Test
- public void testSetGetHBorders() {
+ public void testSetGetHBorders() throws IOException {
// instantiate the following classes so they'll get picked up by
// the XmlBean process and added to the jar file. they are required
// for the following XWPFTable methods.
@@ -266,388 +238,348 @@ public class TestXWPFTable {
STBorder stb = STBorder.Factory.newInstance();
assertNotNull(stb);
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getInsideHBorderSize();
- assertEquals(-1, sz);
- int sp = table.getInsideHBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getInsideHBorderColor();
- assertNull(clr);
- // set inside horizontal border
- table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
- // get inside horizontal border components
- bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- sz = table.getInsideHBorderSize();
- assertEquals(4, sz);
- sp = table.getInsideHBorderSpace();
- assertEquals(0, sp);
- clr = table.getInsideHBorderColor();
- assertEquals("FF0000", clr);
- // remove the border and verify state
- table.removeInsideHBorder();
- bt = table.getInsideHBorderType();
- assertNull(bt);
- sz = table.getInsideHBorderSize();
- assertEquals(-1, sz);
- sp = table.getInsideHBorderSpace();
- assertEquals(-1, sp);
- clr = table.getInsideHBorderColor();
- assertNull(clr);
- // check other borders
- bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- // remove the rest all at once and test
- table.removeBorders();
- bt = table.getInsideVBorderType();
- assertNull(bt);
- bt = table.getTopBorderType();
- assertNull(bt);
- bt = table.getBottomBorderType();
- assertNull(bt);
- bt = table.getLeftBorderType();
- assertNull(bt);
- bt = table.getRightBorderType();
- assertNull(bt);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getInsideHBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getInsideHBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getInsideHBorderColor();
+ assertNull(clr);
+ // set inside horizontal border
+ table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
+ // get inside horizontal border components
+ bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ sz = table.getInsideHBorderSize();
+ assertEquals(4, sz);
+ sp = table.getInsideHBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getInsideHBorderColor();
+ assertEquals("FF0000", clr);
+ // remove the border and verify state
+ table.removeInsideHBorder();
+ bt = table.getInsideHBorderType();
+ assertNull(bt);
+ sz = table.getInsideHBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getInsideHBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getInsideHBorderColor();
+ assertNull(clr);
+ // check other borders
+ bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ // remove the rest all at once and test
+ table.removeBorders();
+ bt = table.getInsideVBorderType();
+ assertNull(bt);
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ bt = table.getRightBorderType();
+ assertNull(bt);
}
}
@Test
- public void testSetGetVBorders() {
+ public void testSetGetVBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getInsideVBorderSize();
- assertEquals(-1, sz);
- int sp = table.getInsideVBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getInsideVBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.DOUBLE, bt);
- sz = table.getInsideVBorderSize();
- assertEquals(4, sz);
- sp = table.getInsideVBorderSpace();
- assertEquals(0, sp);
- clr = table.getInsideVBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeInsideVBorder();
- bt = table.getInsideVBorderType();
- assertNull(bt);
- sz = table.getInsideVBorderSize();
- assertEquals(-1, sz);
- sp = table.getInsideVBorderSpace();
- assertEquals(-1, sp);
- clr = table.getInsideVBorderColor();
- assertNull(clr);
- // check the rest
- bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- // remove the rest one at a time and test
- table.removeInsideHBorder();
- table.removeTopBorder();
- table.removeBottomBorder();
- table.removeLeftBorder();
- table.removeRightBorder();
- bt = table.getInsideHBorderType();
- assertNull(bt);
- bt = table.getTopBorderType();
- assertNull(bt);
- bt = table.getBottomBorderType();
- assertNull(bt);
- bt = table.getLeftBorderType();
- assertNull(bt);
- bt = table.getRightBorderType();
- assertNull(bt);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getInsideVBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getInsideVBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getInsideVBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.DOUBLE, bt);
+ sz = table.getInsideVBorderSize();
+ assertEquals(4, sz);
+ sp = table.getInsideVBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getInsideVBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeInsideVBorder();
+ bt = table.getInsideVBorderType();
+ assertNull(bt);
+ sz = table.getInsideVBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getInsideVBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getInsideVBorderColor();
+ assertNull(clr);
+ // check the rest
+ bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ // remove the rest one at a time and test
+ table.removeInsideHBorder();
+ table.removeTopBorder();
+ table.removeBottomBorder();
+ table.removeLeftBorder();
+ table.removeRightBorder();
+ bt = table.getInsideHBorderType();
+ assertNull(bt);
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ bt = table.getRightBorderType();
+ assertNull(bt);
}
}
@Test
- public void testSetGetTopBorders() {
+ public void testSetGetTopBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getTopBorderSize();
- assertEquals(-1, sz);
- int sp = table.getTopBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getTopBorderColor();
- assertNull(clr);
- // set top border
- table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.THICK, bt);
- sz = table.getTopBorderSize();
- assertEquals(4, sz);
- sp = table.getTopBorderSpace();
- assertEquals(0, sp);
- clr = table.getTopBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeTopBorder();
- bt = table.getTopBorderType();
- assertNull(bt);
- sz = table.getTopBorderSize();
- assertEquals(-1, sz);
- sp = table.getTopBorderSpace();
- assertEquals(-1, sp);
- clr = table.getTopBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getTopBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getTopBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getTopBorderColor();
+ assertNull(clr);
+ // set top border
+ table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.THICK, bt);
+ sz = table.getTopBorderSize();
+ assertEquals(4, sz);
+ sp = table.getTopBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getTopBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeTopBorder();
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ sz = table.getTopBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getTopBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getTopBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetBottomBorders() {
+ public void testSetGetBottomBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getBottomBorderSize();
- assertEquals(-1, sz);
- int sp = table.getBottomBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getBottomBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.DOTTED, bt);
- sz = table.getBottomBorderSize();
- assertEquals(4, sz);
- sp = table.getBottomBorderSpace();
- assertEquals(0, sp);
- clr = table.getBottomBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeBottomBorder();
- bt = table.getBottomBorderType();
- assertNull(bt);
- sz = table.getBottomBorderSize();
- assertEquals(-1, sz);
- sp = table.getBottomBorderSpace();
- assertEquals(-1, sp);
- clr = table.getBottomBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getBottomBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getBottomBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getBottomBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.DOTTED, bt);
+ sz = table.getBottomBorderSize();
+ assertEquals(4, sz);
+ sp = table.getBottomBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getBottomBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeBottomBorder();
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ sz = table.getBottomBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getBottomBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getBottomBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetLeftBorders() {
+ public void testSetGetLeftBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getLeftBorderSize();
- assertEquals(-1, sz);
- int sp = table.getLeftBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getLeftBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.DASHED, bt);
- sz = table.getLeftBorderSize();
- assertEquals(4, sz);
- sp = table.getLeftBorderSpace();
- assertEquals(0, sp);
- clr = table.getLeftBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeLeftBorder();
- bt = table.getLeftBorderType();
- assertNull(bt);
- sz = table.getLeftBorderSize();
- assertEquals(-1, sz);
- sp = table.getLeftBorderSpace();
- assertEquals(-1, sp);
- clr = table.getLeftBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getLeftBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getLeftBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getLeftBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.DASHED, bt);
+ sz = table.getLeftBorderSize();
+ assertEquals(4, sz);
+ sp = table.getLeftBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getLeftBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeLeftBorder();
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ sz = table.getLeftBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getLeftBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getLeftBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetRightBorders() {
+ public void testSetGetRightBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getRightBorderSize();
- assertEquals(-1, sz);
- int sp = table.getRightBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getRightBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.DOT_DASH, bt);
- sz = table.getRightBorderSize();
- assertEquals(4, sz);
- sp = table.getRightBorderSpace();
- assertEquals(0, sp);
- clr = table.getRightBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeRightBorder();
- bt = table.getRightBorderType();
- assertNull(bt);
- sz = table.getRightBorderSize();
- assertEquals(-1, sz);
- sp = table.getRightBorderSpace();
- assertEquals(-1, sp);
- clr = table.getRightBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getRightBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getRightBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getRightBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.DOT_DASH, bt);
+ sz = table.getRightBorderSize();
+ assertEquals(4, sz);
+ sp = table.getRightBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getRightBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeRightBorder();
+ bt = table.getRightBorderType();
+ assertNull(bt);
+ sz = table.getRightBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getRightBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getRightBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetRowBandSize() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- table.setRowBandSize(12);
- int sz = table.getRowBandSize();
- assertEquals(12, sz);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetRowBandSize() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ table.setRowBandSize(12);
+ int sz = table.getRowBandSize();
+ assertEquals(12, sz);
}
}
@Test
- public void testSetGetColBandSize() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- table.setColBandSize(16);
- int sz = table.getColBandSize();
- assertEquals(16, sz);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetColBandSize() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ table.setColBandSize(16);
+ int sz = table.getColBandSize();
+ assertEquals(16, sz);
}
}
@Test
public void testCreateTable() throws Exception {
// open an empty document
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-
- // create a table with 5 rows and 7 columns
- int noRows = 5;
- int noCols = 7;
- XWPFTable table = doc.createTable(noRows, noCols);
-
- // assert the table is empty
- List<XWPFTableRow> rows = table.getRows();
- assertEquals("Table has less rows than requested.", noRows, rows.size());
- for (XWPFTableRow xwpfRow : rows) {
- assertNotNull(xwpfRow);
- for (int i = 0; i < 7; i++) {
- XWPFTableCell xwpfCell = xwpfRow.getCell(i);
- assertNotNull(xwpfCell);
- assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
- xwpfCell = xwpfRow.getCell(i);
- assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+ try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
+
+ // create a table with 5 rows and 7 columns
+ int noRows = 5;
+ int noCols = 7;
+ XWPFTable table = doc.createTable(noRows, noCols);
+
+ // assert the table is empty
+ List<XWPFTableRow> rows = table.getRows();
+ assertEquals("Table has less rows than requested.", noRows, rows.size());
+ for (XWPFTableRow xwpfRow : rows) {
+ assertNotNull(xwpfRow);
+ for (int i = 0; i < 7; i++) {
+ XWPFTableCell xwpfCell = xwpfRow.getCell(i);
+ assertNotNull(xwpfCell);
+ assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
+ xwpfCell = xwpfRow.getCell(i);
+ assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+ }
}
- }
- doc.getPackage().revert();
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ doc.getPackage().revert();
}
}
-
+
@Test
- public void testSetGetTableAlignment() {
- XWPFDocument doc = new XWPFDocument();
- XWPFTable tbl = doc.createTable(1, 1);
- tbl.setTableAlignment(TableRowAlign.LEFT);
- assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
- tbl.setTableAlignment(TableRowAlign.CENTER);
- assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
- tbl.setTableAlignment(TableRowAlign.RIGHT);
- assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
- tbl.removeTableAlignment();
- assertNull(tbl.getTableAlignment());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetTableAlignment() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ XWPFTable tbl = doc.createTable(1, 1);
+ tbl.setTableAlignment(TableRowAlign.LEFT);
+ assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.CENTER);
+ assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.RIGHT);
+ assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
+ tbl.removeTableAlignment();
+ assertNull(tbl.getTableAlignment());
}
}
} \ No newline at end of file