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
This commit is contained in:
Andreas Beeker 2020-12-12 23:15:20 +00:00
parent 1f072afe18
commit c5f6dfa68e
79 changed files with 1422 additions and 1149 deletions

View File

@ -326,13 +326,13 @@ under the License.
<!-- See https://www.ecma-international.org/publications/standards/Ecma-376.htm -->
<!-- "Copy these file(s), free of charge" -->
<property name="ooxml.xsds.izip.1" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip"/>
<property name="ooxml.xsds.izip.1" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip"/>
<property name="ooxml.xsds.src.dir" location="build/ooxml-xsds-src"/>
<property name="ooxml.xsds.src.jar" location="build/dist/maven/ooxml-schemas/ooxml-schemas-${maven.ooxml.xsds.version.id}-sources.jar"/>
<property name="ooxml.xsds.jar" location="build/dist/maven/ooxml-schemas/ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
<!-- additional schemas are packed into the poi schemas jar, -->
<!-- so we don't have to care about a seperate versioning of the original ooxml schemas -->
<!-- so we don't have to care about a separate versioning of the original ooxml schemas -->
<property name="ooxml.xsds.izip.2" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip"/>
<property name="ooxml.security.src.dir" location="build/ooxml-security-src"/>
<property name="ooxml.security.xsd.dir" location="src/ooxml/resources/org/apache/poi/poifs/crypt"/>

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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));
}
}

View File

@ -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)

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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());
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}
/**

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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)));
}
}

View File

@ -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() {

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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;

View File

@ -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

View File

@ -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());

View File

@ -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;
}

View File

@ -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());

View File

@ -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);
}
}

View File

@ -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()));
}
/**

View File

@ -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();

View File

@ -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());
}

View File

@ -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) {

View File

@ -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){

View File

@ -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 );
}

View File

@ -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();

View File

@ -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

View File

@ -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;
}
}

View File

@ -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 DataType(STXmlDataType.Enum... xmlDataTypes) {
private Set<String> 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) {

View File

@ -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

View File

@ -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);
}

View File

@ -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;
/**

View File

@ -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;
/**

View File

@ -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);
}

View File

@ -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();

View File

@ -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];

View File

@ -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;

View File

@ -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();

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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];

View File

@ -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()) {

View File

@ -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));

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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();
}
}
}

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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
}

View File

@ -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()));
}
}

View File

@ -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);
}
}

View File

@ -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());

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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

View File

@ -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 {

View File

@ -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());
}
}

View File

@ -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
*/

View File

@ -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();