From dbedfe14e8136bb095da0ee6672e399fd41a5d16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alain=20B=C3=A9arez?= Date: Mon, 27 Aug 2018 19:25:34 +0000 Subject: [PATCH] rebase XDDF text package git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1839369 13f79535-47bb-0310-9956-ffa450edef68 --- .../opc/internal/ContentTypeManager.java | 48 ++- .../poi/xddf/usermodel/chart/XDDFChart.java | 226 ++++++++---- .../poi/xddf/usermodel/text/AnchorType.java | 47 +++ .../usermodel/text/XDDFBodyProperties.java | 106 +++++- .../xddf/usermodel/text/XDDFBulletSize.java | 14 +- .../text/XDDFBulletSizeFollowText.java | 7 +- .../usermodel/text/XDDFBulletSizePercent.java | 9 +- .../usermodel/text/XDDFBulletSizePoints.java | 9 +- .../xddf/usermodel/text/XDDFBulletStyle.java | 3 +- .../text/XDDFBulletStyleAutoNumbered.java | 8 +- .../text/XDDFBulletStyleCharacter.java | 2 +- .../usermodel/text/XDDFBulletStyleNone.java | 2 +- .../text/XDDFBulletStylePicture.java | 2 +- .../poi/xddf/usermodel/text/XDDFFont.java | 16 +- .../xddf/usermodel/text/XDDFHyperlink.java | 32 +- .../usermodel/text/XDDFNormalAutoFit.java | 8 +- .../text/XDDFParagraphBulletProperties.java | 96 +++-- .../text/XDDFParagraphProperties.java | 64 +++- .../usermodel/text/XDDFRunProperties.java | 144 ++++++-- .../usermodel/text/XDDFSpacingPercent.java | 4 +- .../usermodel/text/XDDFSpacingPoints.java | 4 +- .../poi/xddf/usermodel/text/XDDFTabStop.java | 8 +- .../poi/xddf/usermodel/text/XDDFTextBody.java | 184 ++++++---- .../usermodel/text/XDDFTextParagraph.java | 334 ++++++++++-------- .../poi/xddf/usermodel/text/XDDFTextRun.java | 98 ++--- .../poi/xslf/usermodel/XSLFAutoShape.java | 6 +- 26 files changed, 993 insertions(+), 488 deletions(-) create mode 100644 src/ooxml/java/org/apache/poi/xddf/usermodel/text/AnchorType.java diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java index 3ddfc78035..9b22850ddc 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java @@ -26,11 +26,15 @@ import java.util.Locale; import java.util.Map.Entry; import java.util.TreeMap; +import org.apache.poi.ooxml.util.DocumentHelper; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; -import org.apache.poi.openxml4j.opc.*; -import org.apache.poi.ooxml.util.DocumentHelper; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackageNamespaces; +import org.apache.poi.openxml4j.opc.PackagePart; +import org.apache.poi.openxml4j.opc.PackagePartName; +import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -150,10 +154,11 @@ public abstract class ContentTypeManager { boolean defaultCTExists = this.defaultContentType.containsValue(contentType); String extension = partName.getExtension().toLowerCase(Locale.ROOT); if ((extension.length() == 0) - || (this.defaultContentType.containsKey(extension) && !defaultCTExists)) + || (this.defaultContentType.containsKey(extension) && !defaultCTExists)) { this.addOverrideContentType(partName, contentType); - else if (!defaultCTExists) + } else if (!defaultCTExists) { this.addDefaultContentType(extension, contentType); + } } /** @@ -166,8 +171,9 @@ public abstract class ContentTypeManager { */ private void addOverrideContentType(PackagePartName partName, String contentType) { - if (overrideContentType == null) + if (overrideContentType == null) { overrideContentType = new TreeMap<>(); + } overrideContentType.put(partName, contentType); } @@ -206,8 +212,9 @@ public abstract class ContentTypeManager { */ public void removeContentType(PackagePartName partName) throws InvalidOperationException { - if (partName == null) + if (partName == null) { throw new IllegalArgumentException("partName"); + } /* Override content type */ if (this.overrideContentType != null @@ -251,10 +258,11 @@ public abstract class ContentTypeManager { try { for (PackagePart part : this.container.getParts()) { if (!part.getPartName().equals(partName) - && this.getContentType(part.getPartName()) == null) + && this.getContentType(part.getPartName()) == null) { throw new InvalidOperationException( "Rule M2.4 is not respected: Nor a default element or override element is associated with the part: " + part.getPartName().getName()); + } } } catch (InvalidFormatException e) { throw new InvalidOperationException(e.getMessage()); @@ -271,8 +279,9 @@ public abstract class ContentTypeManager { * register, then false. */ public boolean isContentTypeRegister(String contentType) { - if (contentType == null) + if (contentType == null) { throw new IllegalArgumentException("contentType"); + } return (this.defaultContentType.values().contains(contentType) || (this.overrideContentType != null && this.overrideContentType .values().contains(contentType))); @@ -318,16 +327,19 @@ public abstract class ContentTypeManager { * content from an existing part. */ public String getContentType(PackagePartName partName) { - if (partName == null) + if (partName == null) { throw new IllegalArgumentException("partName"); + } if ((this.overrideContentType != null) - && this.overrideContentType.containsKey(partName)) + && this.overrideContentType.containsKey(partName)) { return this.overrideContentType.get(partName); + } String extension = partName.getExtension().toLowerCase(Locale.ROOT); - if (this.defaultContentType.containsKey(extension)) + if (this.defaultContentType.containsKey(extension)) { return this.defaultContentType.get(extension); + } /* * [M2.4] : The package implementer shall require that the Content Types @@ -338,9 +350,11 @@ public abstract class ContentTypeManager { */ if (this.container != null && this.container.getPart(partName) != null) { throw new OpenXML4JRuntimeException( - "Rule M2.4 exception : this error should NEVER happen!\n" - + "Check that your code is closing the open resources in the correct order prior to filing a bug report.\n" - + "If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!"); + "Rule M2.4 exception : Part \'" + + partName + + "\' not found - this error should NEVER happen!\n" + + "Check that your code is closing the open resources in the correct order prior to filing a bug report.\n" + + "If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!"); } return null; } @@ -350,8 +364,9 @@ public abstract class ContentTypeManager { */ public void clearAll() { this.defaultContentType.clear(); - if (this.overrideContentType != null) + if (this.overrideContentType != null) { this.overrideContentType.clear(); + } } /** @@ -359,8 +374,9 @@ public abstract class ContentTypeManager { * */ public void clearOverrideContentTypes() { - if (this.overrideContentType != null) + if (this.overrideContentType != null) { this.overrideContentType.clear(); + } } /** diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java index 88c8216ceb..f23ce6d23a 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java @@ -29,6 +29,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.function.Function; import javax.xml.namespace.QName; @@ -46,6 +48,8 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; +import org.apache.poi.xddf.usermodel.text.TextContainer; +import org.apache.poi.xddf.usermodel.text.XDDFTextBody; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -65,15 +69,19 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns; @Beta -public abstract class XDDFChart extends POIXMLDocumentPart { +public abstract class XDDFChart extends POIXMLDocumentPart implements TextContainer { /** * Underlying workbook */ @@ -109,8 +117,10 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * Construct a DrawingML chart from a package part. * - * @param part the package part holding the chart data, - * the content type must be application/vnd.openxmlformats-officedocument.drawingml.chart+xml + * @param part + * the package part holding the chart data, the content type must + * be + * application/vnd.openxmlformats-officedocument.drawingml.chart+xml * @since POI 3.14-Beta1 */ protected XDDFChart(PackagePart part) throws IOException, XmlException { @@ -121,7 +131,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * Return the underlying CTChartSpace bean, the root element of the Chart part. + * Return the underlying CTChartSpace bean, the root element of the Chart + * part. * * @return the underlying CTChartSpace bean */ @@ -152,8 +163,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * @return true if only visible cells will be present on the chart, - * false otherwise + * @return true if only visible cells will be present on the chart, false + * otherwise */ public boolean isPlotOnlyVisibleCells() { if (chart.isSetPlotVisOnly()) { @@ -164,8 +175,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * @param only a flag specifying if only visible cells should be - * present on the chart + * @param only + * a flag specifying if only visible cells should be present on + * the chart */ public void setPlotOnlyVisibleCells(boolean only) { if (!chart.isSetPlotVisOnly()) { @@ -202,6 +214,42 @@ public abstract class XDDFChart extends POIXMLDocumentPart { chart.getAutoTitleDeleted().setVal(deleted); } + /** + * Get the chart title body if there is one, i.e. title is set and is not a + * formula. + * + * @return text body or null, if title is a formula or no title is set. + */ + @Beta + public XDDFTextBody getFormattedTitle() { + if (!chart.isSetTitle()) { + return null; + } + CTTitle title = chart.getTitle(); + if (!title.isSetTx()) { + return null; + } + CTTx tx = title.getTx(); + if (!tx.isSetRich()) { + return null; + } + return new XDDFTextBody(this, tx.getRich()); + } + + @Override + public Optional findDefinedParagraphProperty(Function isSet, + Function getter) { + // TODO Auto-generated method stub + return Optional.empty(); + } + + @Override + public Optional findDefinedRunProperty(Function isSet, + Function getter) { + // TODO Auto-generated method stub + return Optional.empty(); + } + public XDDFShapeProperties getOrAddShapeProperties() { CTPlotArea plotArea = getCTPlotArea(); CTShapeProperties properties; @@ -336,18 +384,18 @@ public abstract class XDDFChart extends POIXMLDocumentPart { Map mapValues = Collections.singletonMap(values.getId(), values); final CTPlotArea plotArea = getCTPlotArea(); switch (type) { - case BAR: - return new XDDFBarChartData(plotArea.addNewBarChart(), categories, mapValues); - case LINE: - return new XDDFLineChartData(plotArea.addNewLineChart(), categories, mapValues); - case PIE: - return new XDDFPieChartData(plotArea.addNewPieChart()); - case RADAR: - return new XDDFRadarChartData(plotArea.addNewRadarChart(), categories, mapValues); - case SCATTER: - return new XDDFScatterChartData(plotArea.addNewScatterChart(), categories, mapValues); - default: - return null; + case BAR: + return new XDDFBarChartData(plotArea.addNewBarChart(), categories, mapValues); + case LINE: + return new XDDFLineChartData(plotArea.addNewLineChart(), categories, mapValues); + case PIE: + return new XDDFPieChartData(plotArea.addNewPieChart()); + case RADAR: + return new XDDFRadarChartData(plotArea.addNewRadarChart(), categories, mapValues); + case SCATTER: + return new XDDFScatterChartData(plotArea.addNewScatterChart(), categories, mapValues); + default: + return null; } } @@ -360,7 +408,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { private boolean hasAxes() { CTPlotArea ctPlotArea = chart.getPlotArea(); - int totalAxisCount = ctPlotArea.sizeOfValAxArray() + ctPlotArea.sizeOfCatAxArray() + ctPlotArea.sizeOfDateAxArray() + ctPlotArea.sizeOfSerAxArray(); + int totalAxisCount = ctPlotArea.sizeOfValAxArray() + ctPlotArea.sizeOfCatAxArray() + ctPlotArea + .sizeOfDateAxArray() + ctPlotArea.sizeOfSerAxArray(); return totalAxisCount > 0; } @@ -381,11 +430,17 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * Set value range (basic Axis Options) - * @param axisIndex 0 - primary axis, 1 - secondary axis - * @param minimum minimum value; Double.NaN - automatic; null - no change - * @param maximum maximum value; Double.NaN - automatic; null - no change - * @param majorUnit major unit value; Double.NaN - automatic; null - no change - * @param minorUnit minor unit value; Double.NaN - automatic; null - no change + * + * @param axisIndex + * 0 - primary axis, 1 - secondary axis + * @param minimum + * minimum value; Double.NaN - automatic; null - no change + * @param maximum + * maximum value; Double.NaN - automatic; null - no change + * @param majorUnit + * major unit value; Double.NaN - automatic; null - no change + * @param minorUnit + * minor unit value; Double.NaN - automatic; null - no change */ public void setValueRange(int axisIndex, Double minimum, Double maximum, Double majorUnit, Double minorUnit) { XDDFChartAxis axis = getAxes().get(axisIndex); @@ -407,16 +462,21 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * method to create relationship with embedded part - * for example writing xlsx file stream into output stream + * method to create relationship with embedded part for example writing xlsx + * file stream into output stream * - * @param chartRelation relationship object - * @param chartFactory ChartFactory object - * @param chartIndex index used to suffix on file - * @return return relation part which used to write relation in .rels file and get relation id + * @param chartRelation + * relationship object + * @param chartFactory + * ChartFactory object + * @param chartIndex + * index used to suffix on file + * @return return relation part which used to write relation in .rels file + * and get relation id * @since POI 4.0.0 */ - public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory, int chartIndex) { + public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory, + int chartIndex) { documentPart = createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart(); return this.addRelation(null, chartRelation, documentPart).getRelationship(); } @@ -424,14 +484,18 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * if embedded part was null then create new part * - * @param chartRelation chart relation object - * @param chartWorkbookRelation chart workbook relation object - * @param chartFactory factory object of POIXMLFactory (XWPFFactory/XSLFFactory) + * @param chartRelation + * chart relation object + * @param chartWorkbookRelation + * chart workbook relation object + * @param chartFactory + * factory object of POIXMLFactory (XWPFFactory/XSLFFactory) * @return return the new package part * @throws InvalidFormatException * @since POI 4.0.0 */ - private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation, POIXMLFactory chartFactory) throws InvalidFormatException { + private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation, + POIXMLFactory chartFactory) throws InvalidFormatException { PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex); this.setExternalId(xlsx.getId()); return getTargetPart(xlsx); @@ -440,7 +504,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * this method write the XSSFWorkbook object data into embedded excel file * - * @param workbook XSSFworkbook object + * @param workbook + * XSSFworkbook object * @throws IOException * @throws InvalidFormatException * @since POI 4.0.0 @@ -451,9 +516,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart { POIXMLRelation chartRelation = getChartRelation(); POIXMLRelation chartWorkbookRelation = getChartWorkbookRelation(); POIXMLFactory chartFactory = getChartFactory(); - if (chartRelation != null - && chartWorkbookRelation != null - && chartFactory != null) { + if (chartRelation != null && chartWorkbookRelation != null && chartFactory != null) { worksheetPart = createWorksheetPart(chartRelation, chartWorkbookRelation, chartFactory); } else { throw new InvalidFormatException("unable to determine chart relations"); @@ -489,9 +552,12 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * this method writes the data into sheet * - * @param sheet sheet of embedded excel - * @param categoryData category values - * @param valuesData data values + * @param sheet + * sheet of embedded excel + * @param categoryData + * category values + * @param valuesData + * data values * @since POI 4.0.0 */ protected void fillSheet(XSSFSheet sheet, XDDFDataSource categoryData, XDDFNumericalDataSource valuesData) { @@ -504,15 +570,16 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * this method return row on given index - * if row is null then create new row + * this method return row on given index if row is null then create new row * - * @param sheet current sheet object - * @param index index of current row + * @param sheet + * current sheet object + * @param index + * index of current row * @return this method return sheet row on given index * @since POI 4.0.0 */ - private XSSFRow getRow(XSSFSheet sheet,int index){ + private XSSFRow getRow(XSSFSheet sheet, int index) { if (sheet.getRow(index) != null) { return sheet.getRow(index); } else { @@ -521,15 +588,17 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * this method return cell on given index - * if cell is null then create new cell + * this method return cell on given index if cell is null then create new + * cell * - * @param row current row object - * @param index index of current cell + * @param row + * current row object + * @param index + * index of current cell * @return this method return sheet cell on given index * @since POI 4.0.0 */ - private XSSFCell getCell(XSSFRow row,int index){ + private XSSFCell getCell(XSSFRow row, int index) { if (row.getCell(index) != null) { return row.getCell(index); } else { @@ -540,7 +609,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * import content from other chart to created chart * - * @param other chart object + * @param other + * chart object * @since POI 4.0.0 */ public void importContent(XDDFChart other) { @@ -553,7 +623,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); - xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c")); + xmlOptions.setSaveSyntheticDocumentElement( + new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c")); if (workbook != null) { try { @@ -572,7 +643,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * set sheet time in excel file * - * @param title title of sheet + * @param title + * title of sheet * @return return cell reference * @since POI 4.0.0 */ @@ -588,18 +660,20 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * this method update column header of sheet into table * - * @param ctTable xssf table object - * @param title title of column - * @param index index of column + * @param ctTable + * xssf table object + * @param title + * title of column + * @param index + * index of column */ private void updateSheetTable(CTTable ctTable, String title, int index) { CTTableColumns tableColumnList = ctTable.getTableColumns(); CTTableColumn column = null; - if(tableColumnList.getCount() >= index) { + if (tableColumnList.getCount() >= index) { column = tableColumnList.getTableColumnArray(index); - } - else { - column = tableColumnList.addNewTableColumn(); + } else { + column = tableColumnList.addNewTableColumn(); column.setId(index); } column.setName(title); @@ -632,9 +706,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * this method is used to get worksheet part - * if call is from saveworkbook method then check isCommitted - * isCommitted variable shows that we are writing xssfworkbook object into output stream of embedded part + * this method is used to get worksheet part if call is from saveworkbook + * method then check isCommitted isCommitted variable shows that we are + * writing xssfworkbook object into output stream of embedded part * * @return returns the packagepart of embedded file * @throws InvalidFormatException @@ -683,10 +757,12 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * while reading chart from template file then we need to parse and store embedded excel - * file in chart object show that we can modify value according to use + * while reading chart from template file then we need to parse and store + * embedded excel file in chart object show that we can modify value + * according to use * - * @param workbook workbook object which we read from chart embedded part + * @param workbook + * workbook object which we read from chart embedded part * @since POI 4.0.0 */ public void setWorkbook(XSSFWorkbook workbook) { @@ -694,9 +770,12 @@ public abstract class XDDFChart extends POIXMLDocumentPart { } /** - * set the relation id of embedded excel relation id into external data relation tag + * set the relation id of embedded excel relation id into external data + * relation tag * - * @param id relation id of embedded excel relation id into external data relation tag + * @param id + * relation id of embedded excel relation id into external data + * relation tag * @since POI 4.0.0 */ public void setExternalId(String id) { @@ -714,7 +793,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart { /** * set chart index which can be use for relation part * - * @param chartIndex chart index which can be use for relation part + * @param chartIndex + * chart index which can be use for relation part */ public void setChartIndex(int chartIndex) { this.chartIndex = chartIndex; diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/AnchorType.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/AnchorType.java new file mode 100644 index 0000000000..48c1e98cfc --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/AnchorType.java @@ -0,0 +1,47 @@ +/* ==================================================================== + 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.xddf.usermodel.text; + +import java.util.HashMap; + +import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType; + +public enum AnchorType { + BOTTOM(STTextAnchoringType.B), + CENTER(STTextAnchoringType.CTR), + DISTRIBUTED(STTextAnchoringType.DIST), + JUSTIFIED(STTextAnchoringType.JUST), + TOP(STTextAnchoringType.T); + + final STTextAnchoringType.Enum underlying; + + AnchorType(STTextAnchoringType.Enum caps) { + this.underlying = caps; + } + + private final static HashMap reverse = new HashMap(); + static { + for (AnchorType value : values()) { + reverse.put(value.underlying, value); + } + } + + static AnchorType valueOf(STTextAnchoringType.Enum caps) { + return reverse.get(caps); + } +} diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java index 994770ee75..c27953ba99 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java @@ -37,6 +37,42 @@ public class XDDFBodyProperties { return props; } + public AnchorType getAnchoring() { + if (props.isSetAnchor()) { + return AnchorType.valueOf(props.getAnchor()); + } else { + return null; + } + } + + public void setAnchoring(AnchorType anchor) { + if (anchor == null) { + if (props.isSetAnchor()) { + props.unsetAnchor(); + } + } else { + props.setAnchor(anchor.underlying); + } + } + + public Boolean isAnchorCentered() { + if (props.isSetAnchorCtr()) { + return props.getAnchorCtr(); + } else { + return null; + } + } + + public void setAnchorCentered(Boolean centered) { + if (centered == null) { + if (props.isSetAnchorCtr()) { + props.unsetAnchorCtr(); + } + } else { + props.setAnchorCtr(centered); + } + } + public XDDFAutoFit getAutoFit() { if (props.isSetNoAutofit()) { return new XDDFNoAutoFit(props.getNoAutofit()); @@ -45,13 +81,19 @@ public class XDDFBodyProperties { } else if (props.isSetSpAutoFit()) { return new XDDFShapeAutoFit(props.getSpAutoFit()); } - return new XDDFNoAutoFit(); + return new XDDFNormalAutoFit(); } public void setAutoFit(XDDFAutoFit autofit) { - props.unsetNoAutofit(); - props.unsetNormAutofit(); - props.unsetSpAutoFit(); + if (props.isSetNoAutofit()) { + props.unsetNoAutofit(); + } + if (props.isSetNormAutofit()) { + props.unsetNormAutofit(); + } + if (props.isSetSpAutoFit()) { + props.unsetSpAutoFit(); + } if (autofit instanceof XDDFNoAutoFit) { props.setNoAutofit(((XDDFNoAutoFit) autofit).getXmlObject()); } else if (autofit instanceof XDDFNormalAutoFit) { @@ -71,7 +113,9 @@ public class XDDFBodyProperties { public void setExtensionList(XDDFExtensionList list) { if (list == null) { - props.unsetExtLst(); + if (props.isSetExtLst()) { + props.unsetExtLst(); + } } else { props.setExtLst(list.getXmlObject()); } @@ -87,7 +131,9 @@ public class XDDFBodyProperties { public void setBottomInset(Double points) { if (points == null || Double.isNaN(points)) { - props.unsetBIns(); + if (props.isSetBIns()) { + props.unsetBIns(); + } } else { props.setBIns(Units.toEMU(points)); } @@ -103,7 +149,9 @@ public class XDDFBodyProperties { public void setLeftInset(Double points) { if (points == null || Double.isNaN(points)) { - props.unsetLIns(); + if (props.isSetLIns()) { + props.unsetLIns(); + } } else { props.setLIns(Units.toEMU(points)); } @@ -119,7 +167,9 @@ public class XDDFBodyProperties { public void setRightInset(Double points) { if (points == null || Double.isNaN(points)) { - props.unsetRIns(); + if (props.isSetRIns()) { + props.unsetRIns(); + } } else { props.setRIns(Units.toEMU(points)); } @@ -135,9 +185,47 @@ public class XDDFBodyProperties { public void setTopInset(Double points) { if (points == null || Double.isNaN(points)) { - props.unsetTIns(); + if (props.isSetTIns()) { + props.unsetTIns(); + } } else { props.setTIns(Units.toEMU(points)); } } + + public Boolean hasParagraphSpacing() { + if (props.isSetSpcFirstLastPara()) { + return props.getSpcFirstLastPara(); + } else { + return null; + } + } + + public void setParagraphSpacing(Boolean spacing) { + if (spacing == null) { + if (props.isSetSpcFirstLastPara()) { + props.unsetSpcFirstLastPara(); + } + } else { + props.setSpcFirstLastPara(spacing); + } + } + + public Boolean isRightToLeft() { + if (props.isSetRtlCol()) { + return props.getRtlCol(); + } else { + return null; + } + } + + public void setRightToLeft(Boolean rightToLeft) { + if (rightToLeft == null) { + if (props.isSetRtlCol()) { + props.unsetRtlCol(); + } + } else { + props.setRtlCol(rightToLeft); + } + } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSize.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSize.java index 6bdbd25543..c1a4cb9e13 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSize.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSize.java @@ -18,19 +18,7 @@ package org.apache.poi.xddf.usermodel.text; import org.apache.poi.util.Beta; -import org.apache.poi.util.Internal; @Beta -public abstract class XDDFBulletSize { - public static enum Kind { - PERCENT, - POINTS, - TEXT; - } - - @Internal - protected XDDFBulletSize() { - } - - public abstract Kind getType(); +public interface XDDFBulletSize { } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizeFollowText.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizeFollowText.java index 39da4c2df7..098de23617 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizeFollowText.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizeFollowText.java @@ -22,7 +22,7 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizeFollowText; @Beta -public class XDDFBulletSizeFollowText extends XDDFBulletSize { +public class XDDFBulletSizeFollowText implements XDDFBulletSize { private CTTextBulletSizeFollowText follow; public XDDFBulletSizeFollowText() { @@ -38,9 +38,4 @@ public class XDDFBulletSizeFollowText extends XDDFBulletSize { protected CTTextBulletSizeFollowText getXmlObject() { return follow; } - - @Override - public Kind getType() { - return Kind.TEXT; - } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java index 90f8de2af2..56e2125791 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePercent.java @@ -22,7 +22,7 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePercent; @Beta -public class XDDFBulletSizePercent extends XDDFBulletSize { +public class XDDFBulletSizePercent implements XDDFBulletSize { private CTTextBulletSizePercent percent; private Double scale; @@ -42,16 +42,11 @@ public class XDDFBulletSizePercent extends XDDFBulletSize { return percent; } - @Override - public Kind getType() { - return Kind.PERCENT; - } - public double getPercent() { return percent.getVal() * scale; } public void setPercent(double value) { - percent.setVal((int)(1000 * value)); + percent.setVal((int) (1000 * value)); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePoints.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePoints.java index dbabf3c5e8..342ab72e0f 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePoints.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletSizePoints.java @@ -22,7 +22,7 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint; @Beta -public class XDDFBulletSizePoints extends XDDFBulletSize { +public class XDDFBulletSizePoints implements XDDFBulletSize { private CTTextBulletSizePoint points; public XDDFBulletSizePoints(double value) { @@ -40,16 +40,11 @@ public class XDDFBulletSizePoints extends XDDFBulletSize { return points; } - @Override - public Kind getType() { - return Kind.POINTS; - } - public double getPoints() { return points.getVal() * 0.01; } public void setPoints(double value) { - points.setVal((int)(100 * value)); + points.setVal((int) (100 * value)); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyle.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyle.java index 93f2c98734..0358881371 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyle.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyle.java @@ -20,6 +20,5 @@ package org.apache.poi.xddf.usermodel.text; import org.apache.poi.util.Beta; @Beta -public abstract class XDDFBulletStyle { - +public interface XDDFBulletStyle { } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleAutoNumbered.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleAutoNumbered.java index 086a1ce766..c5996057a0 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleAutoNumbered.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleAutoNumbered.java @@ -22,12 +22,12 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextAutonumberBullet; @Beta -public class XDDFBulletStyleAutoNumbered extends XDDFBulletStyle { +public class XDDFBulletStyleAutoNumbered implements XDDFBulletStyle { private CTTextAutonumberBullet style; @Internal protected XDDFBulletStyleAutoNumbered(CTTextAutonumberBullet style) { - this.style =style; + this.style = style; } @Internal @@ -53,7 +53,9 @@ public class XDDFBulletStyleAutoNumbered extends XDDFBulletStyle { public void setStartAt(Integer value) { if (value == null) { - style.unsetStartAt(); + if (style.isSetStartAt()) { + style.unsetStartAt(); + } } else { style.setStartAt(value); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleCharacter.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleCharacter.java index f8e21e5fbf..6f133715c5 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleCharacter.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleCharacter.java @@ -22,7 +22,7 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharBullet; @Beta -public class XDDFBulletStyleCharacter extends XDDFBulletStyle { +public class XDDFBulletStyleCharacter implements XDDFBulletStyle { private CTTextCharBullet style; @Internal diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleNone.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleNone.java index db9744c5ac..9c6da47d9c 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleNone.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStyleNone.java @@ -22,7 +22,7 @@ import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNoBullet; @Beta -public class XDDFBulletStyleNone extends XDDFBulletStyle { +public class XDDFBulletStyleNone implements XDDFBulletStyle { private CTTextNoBullet style; @Internal diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStylePicture.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStylePicture.java index 2684b9d077..173a4e0539 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStylePicture.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFBulletStylePicture.java @@ -23,7 +23,7 @@ import org.apache.poi.xddf.usermodel.XDDFPicture; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBlipBullet; @Beta -public class XDDFBulletStylePicture extends XDDFBulletStyle { +public class XDDFBulletStylePicture implements XDDFBulletStyle { private CTTextBlipBullet style; @Internal diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java index 7b1bbbad33..93cdc723e3 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFFont.java @@ -34,22 +34,30 @@ public class XDDFFont { public XDDFFont(FontGroup group, String typeface, Byte charset, Byte pitch, byte[] panose) { this(group, CTTextFont.Factory.newInstance()); if (typeface == null) { - font.unsetTypeface(); + if (font.isSetTypeface()) { + font.unsetTypeface(); + } } else { font.setTypeface(typeface); } if (charset == null) { - font.unsetCharset(); + if (font.isSetCharset()) { + font.unsetCharset(); + } } else { font.setCharset(charset); } if (pitch == null) { - font.unsetPitchFamily(); + if (font.isSetPitchFamily()) { + font.unsetPitchFamily(); + } } else { font.setPitchFamily(pitch); } if (panose == null || panose.length == 0) { - font.unsetPanose(); + if (font.isSetPanose()) { + font.unsetPanose(); + } } else { font.setPanose(panose); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFHyperlink.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFHyperlink.java index 879e2240ec..46d4dcdcec 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFHyperlink.java @@ -28,7 +28,7 @@ public class XDDFHyperlink { public XDDFHyperlink(String id) { this(CTHyperlink.Factory.newInstance()); - this.link.setId(id);; + this.link.setId(id); } public XDDFHyperlink(String id, String action) { @@ -72,7 +72,9 @@ public class XDDFHyperlink { public void setEndSound(Boolean ends) { if (ends == null) { - link.unsetEndSnd(); + if (link.isSetEndSnd()) { + link.unsetEndSnd(); + } } else { link.setEndSnd(ends); } @@ -88,11 +90,14 @@ public class XDDFHyperlink { public void setHighlightClick(Boolean highlights) { if (highlights == null) { - link.unsetHighlightClick(); + if (link.isSetHighlightClick()) { + link.unsetHighlightClick(); + } } else { link.setHighlightClick(highlights); } } + public Boolean getHistory() { if (link.isSetHistory()) { return link.getHistory(); @@ -103,13 +108,14 @@ public class XDDFHyperlink { public void setHistory(Boolean history) { if (history == null) { - link.unsetHistory(); + if (link.isSetHistory()) { + link.unsetHistory(); + } } else { link.setHistory(history); } } - public String getInvalidURL() { if (link.isSetInvalidUrl()) { return link.getInvalidUrl(); @@ -120,7 +126,9 @@ public class XDDFHyperlink { public void setInvalidURL(String invalid) { if (invalid == null) { - link.unsetInvalidUrl(); + if (link.isSetInvalidUrl()) { + link.unsetInvalidUrl(); + } } else { link.setInvalidUrl(invalid); } @@ -136,7 +144,9 @@ public class XDDFHyperlink { public void setTargetFrame(String frame) { if (frame == null) { - link.unsetTgtFrame(); + if (link.isSetTgtFrame()) { + link.unsetTgtFrame(); + } } else { link.setTgtFrame(frame); } @@ -152,7 +162,9 @@ public class XDDFHyperlink { public void setTooltip(String tooltip) { if (tooltip == null) { - link.unsetTooltip(); + if (link.isSetTooltip()) { + link.unsetTooltip(); + } } else { link.setTooltip(tooltip); } @@ -168,7 +180,9 @@ public class XDDFHyperlink { public void setExtensionList(XDDFExtensionList list) { if (list == null) { - link.unsetExtLst(); + if (link.isSetExtLst()) { + link.unsetExtLst(); + } } else { link.setExtLst(list.getXmlObject()); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java index d5266d70df..e476834806 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFNormalAutoFit.java @@ -50,7 +50,9 @@ public class XDDFNormalAutoFit implements XDDFAutoFit { public void setFontScale(Integer value) { if (value == null) { - autofit.unsetFontScale(); + if (autofit.isSetFontScale()) { + autofit.unsetFontScale(); + } } else { autofit.setFontScale(value); } @@ -67,7 +69,9 @@ public class XDDFNormalAutoFit implements XDDFAutoFit { public void setLineSpaceReduction(Integer value) { if (value == null) { - autofit.unsetLnSpcReduction(); + if (autofit.isSetLnSpcReduction()) { + autofit.unsetLnSpcReduction(); + } } else { autofit.setLnSpcReduction(value); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java index 36849c44f8..9875d583cd 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java @@ -47,10 +47,18 @@ public class XDDFParagraphBulletProperties { } public void setBulletStyle(XDDFBulletStyle style) { - props.unsetBuAutoNum(); - props.unsetBuBlip(); - props.unsetBuChar(); - props.unsetBuNone(); + if (props.isSetBuAutoNum()) { + props.unsetBuAutoNum(); + } + if (props.isSetBuBlip()) { + props.unsetBuBlip(); + } + if (props.isSetBuChar()) { + props.unsetBuChar(); + } + if (props.isSetBuNone()) { + props.unsetBuNone(); + } if (style != null) { if (style instanceof XDDFBulletStyleAutoNumbered) { props.setBuAutoNum(((XDDFBulletStyleAutoNumbered) style).getXmlObject()); @@ -73,16 +81,22 @@ public class XDDFParagraphBulletProperties { } public void setBulletColor(XDDFColor color) { - props.unsetBuClrTx(); + if (props.isSetBuClrTx()) { + props.unsetBuClrTx(); + } if (color == null) { - props.unsetBuClr(); + if (props.isSetBuClr()) { + props.unsetBuClr(); + } } else { props.setBuClr(color.getColorContainer()); } } public void setBulletColorFollowText() { - props.unsetBuClr(); + if (props.isSetBuClr()) { + props.unsetBuClr(); + } if (props.isSetBuClrTx()) { // nothing to do: already set } else { @@ -99,16 +113,22 @@ public class XDDFParagraphBulletProperties { } public void setBulletFont(XDDFFont font) { - props.unsetBuFontTx(); + if (props.isSetBuFontTx()) { + props.unsetBuFontTx(); + } if (font == null) { - props.unsetBuFont(); + if (props.isSetBuFont()) { + props.unsetBuFont(); + } } else { props.setBuFont(font.getXmlObject()); } } public void setBulletFontFollowText() { - props.unsetBuFont(); + if (props.isSetBuFont()) { + props.unsetBuFont(); + } if (props.isSetBuFontTx()) { // nothing to do: already set } else { @@ -129,9 +149,15 @@ public class XDDFParagraphBulletProperties { } public void setBulletSize(XDDFBulletSize size) { - props.unsetBuSzPct(); - props.unsetBuSzPts(); - props.unsetBuSzTx(); + if (props.isSetBuSzPct()) { + props.unsetBuSzPct(); + } + if (props.isSetBuSzPts()) { + props.unsetBuSzPts(); + } + if (props.isSetBuSzTx()) { + props.unsetBuSzTx(); + } if (size != null) { if (size instanceof XDDFBulletSizeFollowText) { props.setBuSzTx(((XDDFBulletSizeFollowText) size).getXmlObject()); @@ -144,16 +170,38 @@ public class XDDFParagraphBulletProperties { } public void clearAll() { - props.unsetBuAutoNum(); - props.unsetBuBlip(); - props.unsetBuChar(); - props.unsetBuNone(); - props.unsetBuClr(); - props.unsetBuClrTx(); - props.unsetBuFont(); - props.unsetBuFontTx(); - props.unsetBuSzPct(); - props.unsetBuSzPts(); - props.unsetBuSzTx(); + if (props.isSetBuAutoNum()) { + props.unsetBuAutoNum(); + } + if (props.isSetBuBlip()) { + props.unsetBuBlip(); + } + if (props.isSetBuChar()) { + props.unsetBuChar(); + } + if (props.isSetBuNone()) { + props.unsetBuNone(); + } + if (props.isSetBuClr()) { + props.unsetBuClr(); + } + if (props.isSetBuClrTx()) { + props.unsetBuClrTx(); + } + if (props.isSetBuFont()) { + props.unsetBuFont(); + } + if (props.isSetBuFontTx()) { + props.unsetBuFontTx(); + } + if (props.isSetBuSzPct()) { + props.unsetBuSzPct(); + } + if (props.isSetBuSzPts()) { + props.unsetBuSzPts(); + } + if (props.isSetBuSzTx()) { + props.unsetBuSzTx(); + } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java index 7038b35e94..1ed61533ab 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java @@ -57,7 +57,9 @@ public class XDDFParagraphProperties { public void setLevel(Integer level) { if (level == null) { - props.unsetLvl(); + if (props.isSetLvl()) { + props.unsetLvl(); + } } else if (level < 1 || 9 < level) { throw new IllegalArgumentException("Minimum inclusive: 1. Maximum inclusive: 9."); } else { @@ -75,7 +77,9 @@ public class XDDFParagraphProperties { public void setDefaultRunProperties(XDDFRunProperties properties) { if (properties == null) { - props.unsetDefRPr(); + if (props.isSetDefRPr()) { + props.unsetDefRPr(); + } } else { props.setDefRPr(properties.getXmlObject()); } @@ -83,7 +87,9 @@ public class XDDFParagraphProperties { public void setEastAsianLineBreak(Boolean value) { if (value == null) { - props.unsetEaLnBrk(); + if (props.isSetEaLnBrk()) { + props.unsetEaLnBrk(); + } } else { props.setEaLnBrk(value); } @@ -91,7 +97,9 @@ public class XDDFParagraphProperties { public void setLatinLineBreak(Boolean value) { if (value == null) { - props.unsetLatinLnBrk(); + if (props.isSetLatinLnBrk()) { + props.unsetLatinLnBrk(); + } } else { props.setLatinLnBrk(value); } @@ -99,7 +107,9 @@ public class XDDFParagraphProperties { public void setHangingPunctuation(Boolean value) { if (value == null) { - props.unsetHangingPunct(); + if (props.isSetHangingPunct()) { + props.unsetHangingPunct(); + } } else { props.setHangingPunct(value); } @@ -107,7 +117,9 @@ public class XDDFParagraphProperties { public void setRightToLeft(Boolean value) { if (value == null) { - props.unsetRtl(); + if (props.isSetRtl()) { + props.unsetRtl(); + } } else { props.setRtl(value); } @@ -115,7 +127,9 @@ public class XDDFParagraphProperties { public void setFontAlignment(FontAlignment align) { if (align == null) { - props.unsetFontAlgn(); + if (props.isSetFontAlgn()) { + props.unsetFontAlgn(); + } } else { props.setFontAlgn(align.underlying); } @@ -123,7 +137,9 @@ public class XDDFParagraphProperties { public void setTextAlignment(TextAlignment align) { if (align == null) { - props.unsetAlgn(); + if (props.isSetAlgn()) { + props.unsetAlgn(); + } } else { props.setAlgn(align.underlying); } @@ -131,7 +147,9 @@ public class XDDFParagraphProperties { public void setDefaultTabSize(Double points) { if (points == null) { - props.unsetDefTabSz(); + if (props.isSetDefTabSz()) { + props.unsetDefTabSz(); + } } else { props.setDefTabSz(Units.toEMU(points)); } @@ -139,7 +157,9 @@ public class XDDFParagraphProperties { public void setIndentation(Double points) { if (points == null) { - props.unsetIndent(); + if (props.isSetIndent()) { + props.unsetIndent(); + } } else if (points < -4032 || 4032 < points) { throw new IllegalArgumentException("Minimum inclusive = -4032. Maximum inclusive = 4032."); } else { @@ -149,7 +169,9 @@ public class XDDFParagraphProperties { public void setMarginLeft(Double points) { if (points == null) { - props.unsetMarL(); + if (props.isSetMarL()) { + props.unsetMarL(); + } } else if (points < 0 || 4032 < points) { throw new IllegalArgumentException("Minimum inclusive = 0. Maximum inclusive = 4032."); } else { @@ -159,7 +181,9 @@ public class XDDFParagraphProperties { public void setMarginRight(Double points) { if (points == null) { - props.unsetMarR(); + if (props.isSetMarR()) { + props.unsetMarR(); + } } else if (points < 0 || 4032 < points) { throw new IllegalArgumentException("Minimum inclusive = 0. Maximum inclusive = 4032."); } else { @@ -169,7 +193,9 @@ public class XDDFParagraphProperties { public void setLineSpacing(XDDFSpacing spacing) { if (spacing == null) { - props.unsetLnSpc(); + if (props.isSetLnSpc()) { + props.unsetLnSpc(); + } } else { props.setLnSpc(spacing.getXmlObject()); } @@ -177,7 +203,9 @@ public class XDDFParagraphProperties { public void setSpaceAfter(XDDFSpacing spacing) { if (spacing == null) { - props.unsetSpcAft(); + if (props.isSetSpcAft()) { + props.unsetSpcAft(); + } } else { props.setSpcAft(spacing.getXmlObject()); } @@ -185,7 +213,9 @@ public class XDDFParagraphProperties { public void setSpaceBefore(XDDFSpacing spacing) { if (spacing == null) { - props.unsetSpcBef(); + if (props.isSetSpcBef()) { + props.unsetSpcBef(); + } } else { props.setSpcBef(spacing.getXmlObject()); } @@ -250,7 +280,9 @@ public class XDDFParagraphProperties { public void setExtensionList(XDDFExtensionList list) { if (list == null) { - props.unsetExtLst(); + if (props.isSetExtLst()) { + props.unsetExtLst(); + } } else { props.setExtLst(list.getXmlObject()); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java index 6b1c952dda..a82786c7bf 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java @@ -56,7 +56,9 @@ public class XDDFRunProperties { public void setBaseline(Integer value) { if (value == null) { - props.unsetBaseline(); + if (props.isSetBaseline()) { + props.unsetBaseline(); + } } else { props.setBaseline(value); } @@ -64,7 +66,9 @@ public class XDDFRunProperties { public void setDirty(Boolean dirty) { if (dirty == null) { - props.unsetDirty(); + if (props.isSetDirty()) { + props.unsetDirty(); + } } else { props.setDirty(dirty); } @@ -72,7 +76,9 @@ public class XDDFRunProperties { public void setSpellError(Boolean error) { if (error == null) { - props.unsetErr(); + if (props.isSetErr()) { + props.unsetErr(); + } } else { props.setErr(error); } @@ -80,7 +86,9 @@ public class XDDFRunProperties { public void setNoProof(Boolean noproof) { if (noproof == null) { - props.unsetNoProof(); + if (props.isSetNoProof()) { + props.unsetNoProof(); + } } else { props.setNoProof(noproof); } @@ -88,7 +96,9 @@ public class XDDFRunProperties { public void setNormalizeHeights(Boolean normalize) { if (normalize == null) { - props.unsetNormalizeH(); + if (props.isSetNormalizeH()) { + props.unsetNormalizeH(); + } } else { props.setNormalizeH(normalize); } @@ -96,7 +106,9 @@ public class XDDFRunProperties { public void setKumimoji(Boolean kumimoji) { if (kumimoji == null) { - props.unsetKumimoji(); + if (props.isSetKumimoji()) { + props.unsetKumimoji(); + } } else { props.setKumimoji(kumimoji); } @@ -104,7 +116,9 @@ public class XDDFRunProperties { public void setBold(Boolean bold) { if (bold == null) { - props.unsetB(); + if (props.isSetB()) { + props.unsetB(); + } } else { props.setB(bold); } @@ -112,7 +126,9 @@ public class XDDFRunProperties { public void setItalic(Boolean italic) { if (italic == null) { - props.unsetI(); + if (props.isSetI()) { + props.unsetI(); + } } else { props.setI(italic); } @@ -120,21 +136,35 @@ public class XDDFRunProperties { public void setFontSize(Double size) { if (size == null) { - props.unsetSz(); + if (props.isSetSz()) { + props.unsetSz(); + } } else if (size < 1 || 400 < size) { throw new IllegalArgumentException("Minimum inclusive = 1. Maximum inclusive = 400."); } else { - props.setSz((int)(100 * size)); + props.setSz((int) (100 * size)); } } public void setFillProperties(XDDFFillProperties properties) { - props.unsetBlipFill(); - props.unsetGradFill(); - props.unsetGrpFill(); - props.unsetNoFill(); - props.unsetPattFill(); - props.unsetSolidFill(); + if (props.isSetBlipFill()) { + props.unsetBlipFill(); + } + if (props.isSetGradFill()) { + props.unsetGradFill(); + } + if (props.isSetGrpFill()) { + props.unsetGrpFill(); + } + if (props.isSetNoFill()) { + props.unsetNoFill(); + } + if (props.isSetPattFill()) { + props.unsetPattFill(); + } + if (props.isSetSolidFill()) { + props.unsetSolidFill(); + } if (properties == null) { return; } @@ -155,49 +185,61 @@ public class XDDFRunProperties { public void setCharacterKerning(Double kerning) { if (kerning == null) { - props.unsetKern(); + if (props.isSetKern()) { + props.unsetKern(); + } } else if (kerning < 0 || 4000 < kerning) { throw new IllegalArgumentException("Minimum inclusive = 0. Maximum inclusive = 4000."); } else { - props.setKern((int)(100*kerning)); + props.setKern((int) (100 * kerning)); } } public void setCharacterSpacing(Double spacing) { if (spacing == null) { - props.unsetSpc(); + if (props.isSetSpc()) { + props.unsetSpc(); + } } else if (spacing < -4000 || 4000 < spacing) { throw new IllegalArgumentException("Minimum inclusive = -4000. Maximum inclusive = 4000."); } else { - props.setSpc((int)(100*spacing)); + props.setSpc((int) (100 * spacing)); } } public void setFonts(XDDFFont[] fonts) { - for (XDDFFont font: fonts) { + for (XDDFFont font : fonts) { CTTextFont xml = font.getXmlObject(); switch (font.getGroup()) { case COMPLEX_SCRIPT: if (xml == null) { - props.unsetCs(); + if (props.isSetCs()) { + props.unsetCs(); + } } else { props.setCs(xml); } case EAST_ASIAN: if (xml == null) { - props.unsetEa(); + if (props.isSetEa()) { + props.unsetEa(); + } } else { props.setEa(xml); } case LATIN: if (xml == null) { - props.unsetLatin(); + if (props.isSetLatin()) { + props.unsetLatin(); + } } else { props.setLatin(xml); } case SYMBOL: if (xml == null) { - props.unsetSym(); + if (props.isSetSym()) { + props.unsetSym(); + } } else { props.setSym(xml); } @@ -207,7 +249,9 @@ public class XDDFRunProperties { public void setUnderline(UnderlineType underline) { if (underline == null) { - props.unsetU(); + if (props.isSetU()) { + props.unsetU(); + } } else { props.setU(underline.underlying); } @@ -215,7 +259,9 @@ public class XDDFRunProperties { public void setStrikeThrough(StrikeType strike) { if (strike == null) { - props.unsetStrike(); + if (props.isSetStrike()) { + props.unsetStrike(); + } } else { props.setStrike(strike.underlying); } @@ -223,7 +269,9 @@ public class XDDFRunProperties { public void setCapitals(CapsType caps) { if (caps == null) { - props.unsetCap(); + if (props.isSetCap()) { + props.unsetCap(); + } } else { props.setCap(caps.underlying); } @@ -231,7 +279,9 @@ public class XDDFRunProperties { public void setHyperlink(XDDFHyperlink link) { if (link == null) { - props.unsetHlinkClick(); + if (props.isSetHlinkClick()) { + props.unsetHlinkClick(); + } } else { props.setHlinkClick(link.getXmlObject()); } @@ -239,7 +289,9 @@ public class XDDFRunProperties { public void setMouseOver(XDDFHyperlink link) { if (link == null) { - props.unsetHlinkMouseOver(); + if (props.isSetHlinkMouseOver()) { + props.unsetHlinkMouseOver(); + } } else { props.setHlinkMouseOver(link.getXmlObject()); } @@ -247,7 +299,9 @@ public class XDDFRunProperties { public void setLanguage(Locale lang) { if (lang == null) { - props.unsetLang(); + if (props.isSetLang()) { + props.unsetLang(); + } } else { props.setLang(lang.toLanguageTag()); } @@ -255,7 +309,9 @@ public class XDDFRunProperties { public void setAlternativeLanguage(Locale lang) { if (lang == null) { - props.unsetAltLang(); + if (props.isSetAltLang()) { + props.unsetAltLang(); + } } else { props.setAltLang(lang.toLanguageTag()); } @@ -263,7 +319,9 @@ public class XDDFRunProperties { public void setHighlight(XDDFColor color) { if (color == null) { - props.unsetHighlight(); + if (props.isSetHighlight()) { + props.unsetHighlight(); + } } else { props.setHighlight(color.getColorContainer()); } @@ -271,7 +329,9 @@ public class XDDFRunProperties { public void setLineProperties(XDDFLineProperties properties) { if (properties == null) { - props.unsetLn(); + if (props.isSetLn()) { + props.unsetLn(); + } } else { props.setLn(properties.getXmlObject()); } @@ -279,7 +339,9 @@ public class XDDFRunProperties { public void setBookmark(String bookmark) { if (bookmark == null) { - props.unsetBmk(); + if (props.isSetBmk()) { + props.unsetBmk(); + } } else { props.setBmk(bookmark); } @@ -295,7 +357,9 @@ public class XDDFRunProperties { public void setExtensionList(XDDFExtensionList list) { if (list == null) { - props.unsetExtLst(); + if (props.isSetExtLst()) { + props.unsetExtLst(); + } } else { props.setExtLst(list.getXmlObject()); } @@ -311,7 +375,9 @@ public class XDDFRunProperties { public void setEffectContainer(XDDFEffectContainer container) { if (container == null) { - props.unsetEffectDag(); + if (props.isSetEffectDag()) { + props.unsetEffectDag(); + } } else { props.setEffectDag(container.getXmlObject()); } @@ -327,7 +393,9 @@ public class XDDFRunProperties { public void setEffectList(XDDFEffectList list) { if (list == null) { - props.unsetEffectLst(); + if (props.isSetEffectLst()) { + props.unsetEffectLst(); + } } else { props.setEffectLst(list.getXmlObject()); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java index 82594f0603..288f969d88 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPercent.java @@ -29,7 +29,9 @@ public class XDDFSpacingPercent extends XDDFSpacing { public XDDFSpacingPercent(double value) { this(CTTextSpacing.Factory.newInstance(), CTTextSpacingPercent.Factory.newInstance(), null); - spacing.unsetSpcPts(); + if (spacing.isSetSpcPts()) { + spacing.unsetSpcPts(); + } spacing.setSpcPct(percent); setPercent(value); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPoints.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPoints.java index 6b4fcc750c..ea1a771f7f 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPoints.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFSpacingPoints.java @@ -28,7 +28,9 @@ public class XDDFSpacingPoints extends XDDFSpacing { public XDDFSpacingPoints(double value) { this(CTTextSpacing.Factory.newInstance(), CTTextSpacingPoint.Factory.newInstance()); - spacing.unsetSpcPct(); + if (spacing.isSetSpcPct()) { + spacing.unsetSpcPct(); + } spacing.setSpcPts(points); setPoints(value); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java index 8b8701e776..074b5272dc 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTabStop.java @@ -46,7 +46,9 @@ public class XDDFTabStop { public void setAlignment(TabAlignment align) { if (align == null) { - stop.unsetAlgn(); + if (stop.isSetAlgn()) { + stop.unsetAlgn(); + } } else { stop.setAlgn(align.underlying); } @@ -62,7 +64,9 @@ public class XDDFTabStop { public void setPosition(Double position) { if (position == null) { - stop.unsetPos(); + if (stop.isSetPos()) { + stop.unsetPos(); + } } else { stop.setPos(Units.toEMU(position)); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java index f2b8103dae..b0ee5d8e4d 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java @@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.text; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -37,7 +38,7 @@ public class XDDFTextBody { public XDDFTextBody(TextContainer parent) { this(parent, CTTextBody.Factory.newInstance()); - this._body.addNewBodyPr(); + initialize(); } @Internal @@ -55,6 +56,20 @@ public class XDDFTextBody { return _parent; } + public XDDFTextParagraph initialize() { + _body.addNewLstStyle(); + _body.addNewBodyPr(); + XDDFBodyProperties bp = getBodyProperties(); + bp.setAnchoring(AnchorType.TOP); + bp.setRightToLeft(false); + XDDFTextParagraph p = addNewParagraph(); + p.setTextAlignment(TextAlignment.LEFT); + XDDFRunProperties end = p.addAfterLastRunProperties(); + end.setLanguage(Locale.US); + end.setFontSize(11.0); + return p; + } + public XDDFTextParagraph addNewParagraph() { return new XDDFTextParagraph(_body.addNewP(), this); } @@ -72,11 +87,8 @@ public class XDDFTextBody { } public List getParagraphs() { - return Collections.unmodifiableList(_body - .getPList() - .stream() - .map(ds -> new XDDFTextParagraph(ds, this)) - .collect(Collectors.toList())); + return Collections.unmodifiableList( + _body.getPList().stream().map(ds -> new XDDFTextParagraph(ds, this)).collect(Collectors.toList())); } public XDDFBodyProperties getBodyProperties() { @@ -102,7 +114,10 @@ public class XDDFTextBody { public void setDefaultProperties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetDefPPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetDefPPr()) { + style.unsetDefPPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -121,7 +136,10 @@ public class XDDFTextBody { public void setLevel1Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl1PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl1PPr()) { + style.unsetLvl1PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -140,7 +158,10 @@ public class XDDFTextBody { public void setLevel2Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl2PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl2PPr()) { + style.unsetLvl2PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -159,7 +180,10 @@ public class XDDFTextBody { public void setLevel3Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl3PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl3PPr()) { + style.unsetLvl3PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -178,7 +202,10 @@ public class XDDFTextBody { public void setLevel4Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl4PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl4PPr()) { + style.unsetLvl4PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -197,7 +224,10 @@ public class XDDFTextBody { public void setLevel5Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl5PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl5PPr()) { + style.unsetLvl5PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -216,7 +246,10 @@ public class XDDFTextBody { public void setLevel6Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl6PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl6PPr()) { + style.unsetLvl6PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -235,7 +268,10 @@ public class XDDFTextBody { public void setLevel7Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl7PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl7PPr()) { + style.unsetLvl7PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -254,7 +290,10 @@ public class XDDFTextBody { public void setLevel8Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl8PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl8PPr()) { + style.unsetLvl8PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -273,7 +312,10 @@ public class XDDFTextBody { public void setLevel9Properties(XDDFParagraphProperties properties) { if (properties == null) { if (_body.isSetLstStyle()) { - _body.getLstStyle().unsetLvl9PPr(); + CTTextListStyle style = _body.getLstStyle(); + if (style.isSetLvl9PPr()) { + style.unsetLvl9PPr(); + } } } else { CTTextListStyle style = _body.isSetLstStyle() ? _body.getLstStyle() : _body.addNewLstStyle(); @@ -292,8 +334,10 @@ public class XDDFTextBody { } else { return findDefinedParagraphProperty(isSet, getter, level - 1); } - } else { + } else if (_parent != null) { return _parent.findDefinedParagraphProperty(isSet, getter); + } else { + return Optional.empty(); } } @@ -308,59 +352,71 @@ public class XDDFTextBody { } else { return findDefinedRunProperty(isSet, getter, level - 1); } - } else { + } else if (_parent != null) { return _parent.findDefinedRunProperty(isSet, getter); + } else { + return Optional.empty(); } } private CTTextParagraphProperties retrieveProperties(CTTextListStyle list, int level) { - switch(level) { - case 1: if (list.isSetLvl1PPr()) { - return list.getLvl1PPr(); - } else { - return null; - } - case 2: if (list.isSetLvl2PPr()) { - return list.getLvl2PPr(); - } else { - return null; - } - case 3: if (list.isSetLvl3PPr()) { - return list.getLvl3PPr(); - } else { - return null; - } - case 4: if (list.isSetLvl4PPr()) { - return list.getLvl4PPr(); - } else { - return null; - } - case 5: if (list.isSetLvl5PPr()) { - return list.getLvl5PPr(); - } else { - return null; - } - case 6: if (list.isSetLvl6PPr()) { - return list.getLvl6PPr(); - } else { - return null; - } - case 7: if (list.isSetLvl7PPr()) { - return list.getLvl7PPr(); - } else { - return null; - } - case 8: if (list.isSetLvl8PPr()) { - return list.getLvl8PPr(); - } else { - return null; - } - case 9: if (list.isSetLvl9PPr()) { - return list.getLvl9PPr(); - } else { + switch (level) { + case 1: + if (list.isSetLvl1PPr()) { + return list.getLvl1PPr(); + } else { + return null; + } + case 2: + if (list.isSetLvl2PPr()) { + return list.getLvl2PPr(); + } else { + return null; + } + case 3: + if (list.isSetLvl3PPr()) { + return list.getLvl3PPr(); + } else { + return null; + } + case 4: + if (list.isSetLvl4PPr()) { + return list.getLvl4PPr(); + } else { + return null; + } + case 5: + if (list.isSetLvl5PPr()) { + return list.getLvl5PPr(); + } else { + return null; + } + case 6: + if (list.isSetLvl6PPr()) { + return list.getLvl6PPr(); + } else { + return null; + } + case 7: + if (list.isSetLvl7PPr()) { + return list.getLvl7PPr(); + } else { + return null; + } + case 8: + if (list.isSetLvl8PPr()) { + return list.getLvl8PPr(); + } else { + return null; + } + case 9: + if (list.isSetLvl9PPr()) { + return list.getLvl9PPr(); + } else { + return null; + } + default: return null; } - default: return null; - } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java index a87de6e05c..7ba6f8e2bf 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java @@ -40,8 +40,8 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing; /** - * Represents a paragraph of text within the containing text body. - * The paragraph is the highest level text separation mechanism. + * Represents a paragraph of text within the containing text body. The paragraph + * is the highest level text separation mechanism. */ @Beta public class XDDFTextParagraph { @@ -55,9 +55,7 @@ public class XDDFTextParagraph { this._p = paragraph; this._parent = parent; - final int count = paragraph.sizeOfBrArray() - + paragraph.sizeOfFldArray() - + paragraph.sizeOfRArray(); + final int count = paragraph.sizeOfBrArray() + paragraph.sizeOfFldArray() + paragraph.sizeOfRArray(); this._runs = new ArrayList<>(count); for (XmlObject xo : _p.selectChildren(QNameSet.ALL)) { @@ -83,11 +81,11 @@ public class XDDFTextParagraph { return _parent; } - public List getTextRuns(){ + public List getTextRuns() { return _runs; } - public Iterator iterator(){ + public Iterator iterator() { return _runs.iterator(); } @@ -96,10 +94,10 @@ public class XDDFTextParagraph { * * @return text run representing this line break ('\n'). */ - public XDDFTextRun appendLineBreak(){ + public XDDFTextRun appendLineBreak() { CTTextLineBreak br = _p.addNewBr(); // by default, line break has the font properties of the last text run - for (int i = _runs.size() - 1; i <= 0; i--){ + for (int i = _runs.size() - 1; i <= 0; i--) { CTTextCharacterProperties prevProps = _runs.get(i).getProperties(); // let's find one that is not undefined if (prevProps != null) { @@ -117,7 +115,7 @@ public class XDDFTextParagraph { * * @return the new text field. */ - public XDDFTextRun appendField(String id, String type, String text){ + public XDDFTextRun appendField(String id, String type, String text) { CTTextField f = _p.addNewFld(); f.setId(id); f.setType(type); @@ -134,7 +132,7 @@ public class XDDFTextParagraph { * * @return the new run of text. */ - public XDDFTextRun appendRegularRun(String text){ + public XDDFTextRun appendRegularRun(String text) { CTRegularTextRun r = _p.addNewR(); r.setT(text); CTTextCharacterProperties rPr = r.addNewRPr(); @@ -148,19 +146,20 @@ public class XDDFTextParagraph { * Returns the alignment that is applied to the paragraph. * * If this attribute is omitted, then a value of left is implied. + * * @return alignment that is applied to the paragraph */ public TextAlignment getTextAlignment() { return findDefinedParagraphProperty(props -> props.isSetAlgn(), props -> props.getAlgn()) - .map(align -> TextAlignment.valueOf(align)) - .orElse(null); + .map(align -> TextAlignment.valueOf(align)).orElse(null); } /** - * Specifies the alignment that is to be applied to the paragraph. - * Possible values for this include left, right, centered, justified and distributed, + * Specifies the alignment that is to be applied to the paragraph. Possible + * values for this include left, right, centered, justified and distributed, * - * @param align text alignment + * @param align + * text alignment */ public void setTextAlignment(TextAlignment align) { if (align != null || _p.isSetPPr()) { @@ -169,25 +168,27 @@ public class XDDFTextParagraph { } /** - * 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. + * 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 */ public FontAlignment getFontAlignment() { return findDefinedParagraphProperty(props -> props.isSetFontAlgn(), props -> props.getFontAlgn()) - .map(align -> FontAlignment.valueOf(align)) - .orElse(null); + .map(align -> FontAlignment.valueOf(align)).orElse(null); } /** - * Determines 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. For instance - * having text anchored to the top baseline, anchored to the bottom baseline, centered in - * between, etc. + * Determines 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. For instance having text anchored to the top + * baseline, anchored to the bottom baseline, centered in between, etc. * - * @param align text font alignment + * @param align + * text font alignment */ public void setFontAlignment(FontAlignment align) { if (align != null || _p.isSetPPr()) { @@ -197,27 +198,31 @@ public class XDDFTextParagraph { /** * - * @return the indentation, in points, applied to the first line of text in the paragraph. + * @return the indentation, in points, applied to the first line of text in + * the paragraph. */ public Double getIndentation() { return findDefinedParagraphProperty(props -> props.isSetIndent(), props -> props.getIndent()) - .map(emu -> Units.toPoints(emu)) - .orElse(null); + .map(emu -> Units.toPoints(emu)).orElse(null); } /** - * Specifies the indentation size that will be applied to the first line of text in the paragraph. - * - * @param points the indentation in points. - * The value null unsets the indentation for this paragraph. - *
- *
Minimum inclusive =
-4032
- *
Maximum inclusive =
4032
- * + * Specifies the indentation size that will be applied to the first line of + * text in the paragraph. + * + * @param points + * the indentation in points. The value null unsets + * the indentation for this paragraph. + *
+ *
Minimum inclusive =
+ *
-4032
+ *
Maximum inclusive =
+ *
4032
*/ public void setIndentation(Double points) { if (points != null || _p.isSetPPr()) { - getOrCreateProperties().setIndentation(points);; + getOrCreateProperties().setIndentation(points); + ; } } @@ -227,21 +232,23 @@ public class XDDFTextParagraph { */ public Double getMarginLeft() { return findDefinedParagraphProperty(props -> props.isSetMarL(), props -> props.getMarL()) - .map(emu -> Units.toPoints(emu)) - .orElse(null); + .map(emu -> Units.toPoints(emu)).orElse(null); } /** - * Specifies the left margin of the paragraph. This is specified in addition to the text body - * inset and applies only to this text paragraph. That is the text body inset and the LeftMargin - * attributes are additive with respect to the text position. - * - * @param points the margin in points. - * The value null unsets the left margin for this paragraph. - *
- *
Minimum inclusive =
0
- *
Maximum inclusive =
4032
- * + * Specifies the left margin of the paragraph. This is specified in addition + * to the text body inset and applies only to this text paragraph. That is + * the text body inset and the LeftMargin attributes are additive with + * respect to the text position. + * + * @param points + * the margin in points. The value null unsets the + * left margin for this paragraph. + *
+ *
Minimum inclusive =
+ *
0
+ *
Maximum inclusive =
+ *
4032
*/ public void setMarginLeft(Double points) { if (points != null || _p.isSetPPr()) { @@ -255,21 +262,23 @@ public class XDDFTextParagraph { */ public Double getMarginRight() { return findDefinedParagraphProperty(props -> props.isSetMarR(), props -> props.getMarR()) - .map(emu -> Units.toPoints(emu)) - .orElse(null); + .map(emu -> Units.toPoints(emu)).orElse(null); } /** - * Specifies the right margin of the paragraph. This is specified in addition to the text body - * inset and applies only to this text paragraph. That is the text body inset and the RightMargin - * attributes are additive with respect to the text position. - * - * @param points the margin in points. - * The value null unsets the right margin for this paragraph. - *
- *
Minimum inclusive =
0
- *
Maximum inclusive =
4032
- * + * Specifies the right margin of the paragraph. This is specified in + * addition to the text body inset and applies only to this text paragraph. + * That is the text body inset and the RightMargin attributes are additive + * with respect to the text position. + * + * @param points + * the margin in points. The value null unsets the + * right margin for this paragraph. + *
+ *
Minimum inclusive =
+ *
0
+ *
Maximum inclusive =
+ *
4032
*/ public void setMarginRight(Double points) { if (points != null || _p.isSetPPr()) { @@ -279,19 +288,20 @@ public class XDDFTextParagraph { /** * - * @return the default size for a tab character within this paragraph in points. + * @return the default size for a tab character within this paragraph in + * points. */ public Double getDefaultTabSize() { return findDefinedParagraphProperty(props -> props.isSetDefTabSz(), props -> props.getDefTabSz()) - .map(emu -> Units.toPoints(emu)) - .orElse(null); + .map(emu -> Units.toPoints(emu)).orElse(null); } /** * Specifies the default size for a tab character within this paragraph. * - * @param points the default tab size in points. - * The value null unsets the default tab size for this paragraph. + * @param points + * the default tab size in points. The value null + * unsets the default tab size for this paragraph. */ public void setDefaultTabSize(Double points) { if (points != null || _p.isSetPPr()) { @@ -301,30 +311,35 @@ public class XDDFTextParagraph { /** * Returns the vertical line spacing that is to be used within a paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * This may be specified in two different ways, percentage spacing or font + * points spacing: *

- * If line spacing is a percentage of normal line height, result is instance of XDDFSpacingPercent. - * If line spacing is expressed in points, result is instance of XDDFSpacingPoints. + * If line spacing is a percentage of normal line height, result is instance + * of XDDFSpacingPercent. If line spacing is expressed in points, result is + * instance of XDDFSpacingPoints. *

* * @return the vertical line spacing. */ public XDDFSpacing getLineSpacing() { return findDefinedParagraphProperty(props -> props.isSetLnSpc(), props -> props.getLnSpc()) - .map(spacing -> extractSpacing(spacing)) - .orElse(null); + .map(spacing -> extractSpacing(spacing)).orElse(null); } /** - * This element specifies the vertical line spacing that is to be used within a paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * This element specifies the vertical line spacing that is to be used + * within a paragraph. This may be specified in two different ways, + * percentage spacing or font points spacing: *

- * If spacing is instance of XDDFSpacingPercent, then line spacing is a percentage of normal line height. - * If spacing is instance of XDDFSpacingPoints, then line spacing is expressed in points. + * If spacing is instance of XDDFSpacingPercent, then line spacing is a + * percentage of normal line height. If spacing is instance of + * XDDFSpacingPoints, then line spacing is expressed in points. *

* Examples: - *

+     *
+     * 
+     * 
      *      // spacing will be 120% of the size of the largest text on each line
      *      paragraph.setLineSpacing(new XDDFSpacingPercent(120));
      *
@@ -333,9 +348,11 @@ public class XDDFTextParagraph {
      *
      *      // spacing will be 48 points
      *      paragraph.setLineSpacing(new XDDFSpacingPoints(48.0));
-     * 
+ *
+ *
* - * @param linespacing the vertical line spacing + * @param linespacing + * the vertical line spacing */ public void setLineSpacing(XDDFSpacing linespacing) { if (linespacing != null || _p.isSetPPr()) { @@ -344,39 +361,46 @@ public class XDDFTextParagraph { } /** - * The amount of vertical white space before the paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * The amount of vertical white space before the paragraph. This may be + * specified in two different ways, percentage spacing or font points + * spacing: *

- * If spacing is a percentage of normal line height, result is instance of XDDFSpacingPercent. - * If spacing is expressed in points, result is instance of XDDFSpacingPoints. + * If spacing is a percentage of normal line height, result is instance of + * XDDFSpacingPercent. If spacing is expressed in points, result is instance + * of XDDFSpacingPoints. *

* * @return the vertical white space before the paragraph. */ public XDDFSpacing getSpaceBefore() { return findDefinedParagraphProperty(props -> props.isSetSpcBef(), props -> props.getSpcBef()) - .map(spacing -> extractSpacing(spacing)) - .orElse(null); + .map(spacing -> extractSpacing(spacing)).orElse(null); } /** - * Set the amount of vertical white space that will be present before the paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * Set the amount of vertical white space that will be present before the + * paragraph. This may be specified in two different ways, percentage + * spacing or font points spacing: *

- * If spacing is instance of XDDFSpacingPercent, then spacing is a percentage of normal line height. - * If spacing is instance of XDDFSpacingPoints, then spacing is expressed in points. + * If spacing is instance of XDDFSpacingPercent, then spacing is a + * percentage of normal line height. If spacing is instance of + * XDDFSpacingPoints, then spacing is expressed in points. *

* Examples: - *

+     *
+     * 
+     * 
      *      // The paragraph will be formatted to have a spacing before the paragraph text.
      *      // The spacing will be 200% of the size of the largest text on each line
      *      paragraph.setSpaceBefore(new XDDFSpacingPercent(200));
      *
      *      // The spacing will be a size of 48 points
      *      paragraph.setSpaceBefore(new XDDFSpacingPoints(48.0));
-     * 
+ *
+ *
* - * @param spaceBefore the vertical white space before the paragraph. + * @param spaceBefore + * the vertical white space before the paragraph. */ public void setSpaceBefore(XDDFSpacing spaceBefore) { if (spaceBefore != null || _p.isSetPPr()) { @@ -385,39 +409,46 @@ public class XDDFTextParagraph { } /** - * The amount of vertical white space after the paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * The amount of vertical white space after the paragraph. This may be + * specified in two different ways, percentage spacing or font points + * spacing: *

- * If spacing is a percentage of normal line height, result is instance of XDDFSpacingPercent. - * If spacing is expressed in points, result is instance of XDDFSpacingPoints. + * If spacing is a percentage of normal line height, result is instance of + * XDDFSpacingPercent. If spacing is expressed in points, result is instance + * of XDDFSpacingPoints. *

* * @return the vertical white space after the paragraph. */ public XDDFSpacing getSpaceAfter() { return findDefinedParagraphProperty(props -> props.isSetSpcAft(), props -> props.getSpcAft()) - .map(spacing -> extractSpacing(spacing)) - .orElse(null); + .map(spacing -> extractSpacing(spacing)).orElse(null); } /** - * Set the amount of vertical white space that will be present after the paragraph. - * This may be specified in two different ways, percentage spacing or font points spacing: + * Set the amount of vertical white space that will be present after the + * paragraph. This may be specified in two different ways, percentage + * spacing or font points spacing: *

- * If spacing is instance of XDDFSpacingPercent, then spacing is a percentage of normal line height. - * If spacing is instance of XDDFSpacingPoints, then spacing is expressed in points. + * If spacing is instance of XDDFSpacingPercent, then spacing is a + * percentage of normal line height. If spacing is instance of + * XDDFSpacingPoints, then spacing is expressed in points. *

* Examples: - *

+     *
+     * 
+     * 
      *      // The paragraph will be formatted to have a spacing after the paragraph text.
      *      // The spacing will be 200% of the size of the largest text on each line
      *      paragraph.setSpaceAfter(new XDDFSpacingPercent(200));
      *
      *      // The spacing will be a size of 48 points
      *      paragraph.setSpaceAfter(new XDDFSpacingPoints(48.0));
-     * 
+ *
+ *
* - * @param spaceAfter the vertical white space after the paragraph. + * @param spaceAfter + * the vertical white space after the paragraph. */ public void setSpaceAfter(XDDFSpacing spaceAfter) { if (spaceAfter != null || _p.isSetPPr()) { @@ -427,20 +458,19 @@ public class XDDFTextParagraph { /** * - * @return the color of bullet characters within a given paragraph. - * A null value means to use the text font color. + * @return the color of bullet characters within a given paragraph. A + * null value means to use the text font color. */ - public XDDFColor getBulletColor(){ - return findDefinedParagraphProperty( - props -> props.isSetBuClr() || props.isSetBuClrTx(), - props -> new XDDFParagraphBulletProperties(props).getBulletColor() - ).orElse(null); + public XDDFColor getBulletColor() { + return findDefinedParagraphProperty(props -> props.isSetBuClr() || props.isSetBuClrTx(), + props -> new XDDFParagraphBulletProperties(props).getBulletColor()).orElse(null); } /** * Set the color to be used on bullet characters within a given paragraph. * - * @param color the bullet color + * @param color + * the bullet color */ public void setBulletColor(XDDFColor color) { if (color != null || _p.isSetPPr()) { @@ -449,7 +479,8 @@ public class XDDFTextParagraph { } /** - * Specifies the color to be used on bullet characters has to follow text color within a given paragraph. + * Specifies the color to be used on bullet characters has to follow text + * color within a given paragraph. */ public void setBulletColorFollowText() { getOrCreateBulletProperties().setBulletColorFollowText(); @@ -457,20 +488,19 @@ public class XDDFTextParagraph { /** * - * @return the font of bullet characters within a given paragraph. - * A null value means to use the text font font. + * @return the font of bullet characters within a given paragraph. A + * null value means to use the text font font. */ - public XDDFFont getBulletFont(){ - return findDefinedParagraphProperty( - props -> props.isSetBuFont() || props.isSetBuFontTx(), - props -> new XDDFParagraphBulletProperties(props).getBulletFont() - ).orElse(null); + public XDDFFont getBulletFont() { + return findDefinedParagraphProperty(props -> props.isSetBuFont() || props.isSetBuFontTx(), + props -> new XDDFParagraphBulletProperties(props).getBulletFont()).orElse(null); } /** * Set the font to be used on bullet characters within a given paragraph. * - * @param font the bullet font + * @param font + * the bullet font */ public void setBulletFont(XDDFFont font) { if (font != null || _p.isSetPPr()) { @@ -479,40 +509,46 @@ public class XDDFTextParagraph { } /** - * Specifies the font to be used on bullet characters has to follow text font within a given paragraph. + * Specifies the font to be used on bullet characters has to follow text + * font within a given paragraph. */ public void setBulletFontFollowText() { getOrCreateBulletProperties().setBulletFontFollowText(); } /** - * Returns the bullet size that is to be used within a paragraph. - * This may be specified in three different ways, follows text size, percentage size and font points size: + * Returns the bullet size that is to be used within a paragraph. This may + * be specified in three different ways, follows text size, percentage size + * and font points size: *

- * If returned value is instance of XDDFBulletSizeFollowText, then bullet size is text size; - * If returned value is instance of XDDFBulletSizePercent, then bullet size is a percentage of the font size; - * If returned value is instance of XDDFBulletSizePoints, then bullet size is specified in points. + * If returned value is instance of XDDFBulletSizeFollowText, then bullet + * size is text size; If returned value is instance of + * XDDFBulletSizePercent, then bullet size is a percentage of the font size; + * If returned value is instance of XDDFBulletSizePoints, then bullet size + * is specified in points. *

* * @return the bullet size */ - public XDDFBulletSize getBulletSize(){ + public XDDFBulletSize getBulletSize() { return findDefinedParagraphProperty( - props -> props.isSetBuSzPct() || props.isSetBuSzPts() || props.isSetBuSzTx(), - props -> new XDDFParagraphBulletProperties(props).getBulletSize() - ).orElse(null); + props -> props.isSetBuSzPct() || props.isSetBuSzPts() || props.isSetBuSzTx(), + props -> new XDDFParagraphBulletProperties(props).getBulletSize()).orElse(null); } /** - * Sets the bullet size that is to be used within a paragraph. - * This may be specified in three different ways, follows text size, percentage size and font points size: + * Sets the bullet size that is to be used within a paragraph. This may be + * specified in three different ways, follows text size, percentage size and + * font points size: *

- * If given value is instance of XDDFBulletSizeFollowText, then bullet size is text size; - * If given value is instance of XDDFBulletSizePercent, then bullet size is a percentage of the font size; - * If given value is instance of XDDFBulletSizePoints, then bullet size is specified in points. + * If given value is instance of XDDFBulletSizeFollowText, then bullet size + * is text size; If given value is instance of XDDFBulletSizePercent, then + * bullet size is a percentage of the font size; If given value is instance + * of XDDFBulletSizePoints, then bullet size is specified in points. *

* - * @param size the bullet size specification + * @param size + * the bullet size specification */ public void setBulletSize(XDDFBulletSize size) { if (size != null || _p.isSetPPr()) { @@ -520,11 +556,10 @@ public class XDDFTextParagraph { } } - public XDDFBulletStyle getBulletStyle(){ + public XDDFBulletStyle getBulletStyle() { return findDefinedParagraphProperty( - props -> props.isSetBuAutoNum() || props.isSetBuBlip() || props.isSetBuChar() || props.isSetBuNone(), - props -> new XDDFParagraphBulletProperties(props).getBulletStyle() - ).orElse(null); + props -> props.isSetBuAutoNum() || props.isSetBuBlip() || props.isSetBuChar() || props.isSetBuNone(), + props -> new XDDFParagraphBulletProperties(props).getBulletStyle()).orElse(null); } public void setBulletStyle(XDDFBulletStyle style) { @@ -534,8 +569,7 @@ public class XDDFTextParagraph { } public boolean hasEastAsianLineBreak() { - return findDefinedParagraphProperty(props -> props.isSetEaLnBrk(), props -> props.getEaLnBrk()) - .orElse(false); + return findDefinedParagraphProperty(props -> props.isSetEaLnBrk(), props -> props.getEaLnBrk()).orElse(false); } public void setEastAsianLineBreak(Boolean value) { @@ -567,8 +601,7 @@ public class XDDFTextParagraph { } public boolean isRightToLeft() { - return findDefinedParagraphProperty(props -> props.isSetRtl(), props -> props.getRtl()) - .orElse(false); + return findDefinedParagraphProperty(props -> props.isSetRtl(), props -> props.getRtl()).orElse(false); } public void setRightToLeft(Boolean value) { @@ -641,6 +674,13 @@ public class XDDFTextParagraph { } } + public XDDFRunProperties addAfterLastRunProperties() { + if (!_p.isSetEndParaRPr()) { + _p.addNewEndParaRPr(); + } + return getAfterLastRunProperties(); + } + public XDDFRunProperties getAfterLastRunProperties() { if (_p.isSetEndParaRPr()) { return new XDDFRunProperties(_p.getEndParaRPr()); @@ -651,7 +691,9 @@ public class XDDFTextParagraph { public void setAfterLastRunProperties(XDDFRunProperties properties) { if (properties == null) { - _p.unsetEndParaRPr(); + if (_p.isSetEndParaRPr()) { + _p.unsetEndParaRPr(); + } } else { _p.setEndParaRPr(properties.getXmlObject()); } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java index 608eb34db9..7903c9c570 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java @@ -22,8 +22,8 @@ import java.util.Locale; import java.util.Optional; import java.util.function.Function; -import org.apache.poi.POIXMLRelation; import org.apache.poi.common.usermodel.fonts.FontGroup; +import org.apache.poi.ooxml.POIXMLRelation; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackageRelationship; @@ -88,9 +88,9 @@ public class XDDFTextRun { public String getText() { if (isLineBreak()) { return "\n"; - } else if (isField()) { + } else if (isField()) { return _tf.getT(); - } else { + } else { return _rtr.getT(); } } @@ -151,7 +151,8 @@ public class XDDFTextRun { /** * Specifies whether this run of text will be formatted as bold text. * - * @param bold whether this run of text will be formatted as bold text. + * @param bold + * whether this run of text will be formatted as bold text. */ public void setBold(Boolean bold) { getOrCreateProperties().setBold(bold); @@ -166,7 +167,8 @@ public class XDDFTextRun { } /** - * @param italic whether this run of text is formatted as italic text. + * @param italic + * whether this run of text is formatted as italic text. */ public void setItalic(Boolean italic) { getOrCreateProperties().setItalic(italic); @@ -181,7 +183,8 @@ public class XDDFTextRun { } /** - * @param strike which strike style this run of text is formatted with. + * @param strike + * which strike style this run of text is formatted with. */ public void setStrikeThrough(StrikeType strike) { getOrCreateProperties().setStrikeThrough(strike); @@ -206,7 +209,8 @@ public class XDDFTextRun { } /** - * @param underline which underline style this run of text is formatted with. + * @param underline + * which underline style this run of text is formatted with. */ public void setUnderline(UnderlineType underline) { getOrCreateProperties().setUnderline(underline); @@ -231,7 +235,8 @@ public class XDDFTextRun { } /** - * @param caps which caps style this run of text is formatted with. + * @param caps + * which caps style this run of text is formatted with. */ public void setCapitals(CapsType caps) { getOrCreateProperties().setCapitals(caps); @@ -256,7 +261,8 @@ public class XDDFTextRun { } /** - * @return whether a run of text will be formatted as a subscript text. Default is false. + * @return whether a run of text will be formatted as a subscript text. + * Default is false. */ public boolean isSubscript() { return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline()) @@ -265,7 +271,8 @@ public class XDDFTextRun { } /** - * @return whether a run of text will be formatted as a superscript text. Default is false. + * @return whether a run of text will be formatted as a superscript text. + * Default is false. */ public boolean isSuperscript() { return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline()) @@ -282,31 +289,35 @@ public class XDDFTextRun { * * @param offset */ - public void setBaseline(Double offset){ - getOrCreateProperties().setBaseline((int)(offset * 1000)); + public void setBaseline(Double offset) { + if (offset == null) { + getOrCreateProperties().setBaseline(null); + } else { + getOrCreateProperties().setBaseline((int) (offset * 1000)); + } } /** * Set whether the text in this run is formatted as superscript. - *

- * The size is specified using a percentage. - *

+ *

+ * The size is specified using a percentage. + *

* * @param offset */ - public void setSuperscript(Double offset){ + public void setSuperscript(Double offset) { setBaseline(offset == null ? null : Math.abs(offset)); } /** * Set whether the text in this run is formatted as subscript. - *

- * The size is specified using a percentage. - *

+ *

+ * The size is specified using a percentage. + *

* * @param offset */ - public void setSubscript(Double offset){ + public void setSubscript(Double offset) { setBaseline(offset == null ? null : -Math.abs(offset)); } @@ -331,7 +342,8 @@ public class XDDFTextRun { * Note: In order to get fonts to unset the property for a given font family use * {@link XDDFFont#unsetFontForGroup(FontGroup)} * - * @param fonts to set or unset on the run. + * @param fonts + * to set or unset on the run. */ public void setFonts(XDDFFont[] fonts) { getOrCreateProperties().setFonts(fonts); @@ -357,12 +369,14 @@ public class XDDFTextRun { } /** - * @param size font size in points. - * The value null unsets the size for this run. - *
- *
Minimum inclusive =
1
- *
Maximum inclusive =
400
- * + * @param size + * font size in points. The value null unsets the + * size for this run. + *
+ *
Minimum inclusive =
+ *
1
+ *
Maximum inclusive =
+ *
400
* */ public void setFontSize(Double size) { @@ -371,7 +385,7 @@ public class XDDFTextRun { public Double getFontSize() { Integer size = findDefinedProperty(props -> props.isSetSz(), props -> props.getSz()) - .orElse(100 * XSSFFont.DEFAULT_FONT_SIZE); // default font size + .orElse(100 * XSSFFont.DEFAULT_FONT_SIZE); // default font size double scale = _parent.getParentBody().getBodyProperties().getAutoFit().getFontScale() / 10_000_000.0; return size * scale; } @@ -382,13 +396,15 @@ public class XDDFTextRun { * The value null unsets the kerning for this run. *

* - * @param kerning character kerning in points. - *
- *
Minimum inclusive =
0
- *
Maximum inclusive =
4000
- * + * @param kerning + * character kerning in points. + *
+ *
Minimum inclusive =
+ *
0
+ *
Maximum inclusive =
+ *
4000
*/ - public void setCharacterKerning(Double kerning){ + public void setCharacterKerning(Double kerning) { getOrCreateProperties().setCharacterKerning(kerning); } @@ -413,13 +429,15 @@ public class XDDFTextRun { * The value null unsets the spacing for this run. *

* - * @param spacing character spacing in points. - *
- *
Minimum inclusive =
-4000
- *
Maximum inclusive =
4000
- * + * @param spacing + * character spacing in points. + *
+ *
Minimum inclusive =
+ *
-4000
+ *
Maximum inclusive =
+ *
4000
*/ - public void setCharacterSpacing(Double spacing){ + public void setCharacterSpacing(Double spacing) { getOrCreateProperties().setCharacterSpacing(spacing); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java index d9d2c89163..aad07d158c 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java @@ -77,8 +77,10 @@ public class XSLFAutoShape extends XSLFTextShape implements AutoShape