mirror of https://github.com/apache/poi.git
Sonar Fixes - code smells
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875979 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e00a42767
commit
d383fea7bd
|
@ -31,6 +31,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
@ -115,8 +116,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
|
|
||||||
private int chartIndex = 0;
|
private int chartIndex = 0;
|
||||||
|
|
||||||
private POIXMLDocumentPart documentPart = null;
|
|
||||||
|
|
||||||
protected List<XDDFChartAxis> axes = new ArrayList<>();
|
protected List<XDDFChartAxis> axes = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -362,14 +361,14 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -578,23 +577,23 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
private Map<Long, XDDFChartAxis> getCategoryAxes() {
|
private Map<Long, XDDFChartAxis> getCategoryAxes() {
|
||||||
CTPlotArea plotArea = getCTPlotArea();
|
CTPlotArea plotArea = getCTPlotArea();
|
||||||
int sizeOfArray = plotArea.sizeOfCatAxArray();
|
int sizeOfArray = plotArea.sizeOfCatAxArray();
|
||||||
Map<Long, XDDFChartAxis> axes = new HashMap<>(sizeOfArray);
|
Map<Long, XDDFChartAxis> axesMap = new HashMap<>(sizeOfArray);
|
||||||
for (int i = 0; i < sizeOfArray; i++) {
|
for (int i = 0; i < sizeOfArray; i++) {
|
||||||
CTCatAx category = plotArea.getCatAxArray(i);
|
CTCatAx category = plotArea.getCatAxArray(i);
|
||||||
axes.put(category.getAxId().getVal(), new XDDFCategoryAxis(category));
|
axesMap.put(category.getAxId().getVal(), new XDDFCategoryAxis(category));
|
||||||
}
|
}
|
||||||
return axes;
|
return axesMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, XDDFValueAxis> getValueAxes() {
|
private Map<Long, XDDFValueAxis> getValueAxes() {
|
||||||
CTPlotArea plotArea = getCTPlotArea();
|
CTPlotArea plotArea = getCTPlotArea();
|
||||||
int sizeOfArray = plotArea.sizeOfValAxArray();
|
int sizeOfArray = plotArea.sizeOfValAxArray();
|
||||||
Map<Long, XDDFValueAxis> axes = new HashMap<>(sizeOfArray);
|
Map<Long, XDDFValueAxis> axesMap = new HashMap<>(sizeOfArray);
|
||||||
for (int i = 0; i < sizeOfArray; i++) {
|
for (int i = 0; i < sizeOfArray; i++) {
|
||||||
CTValAx values = plotArea.getValAxArray(i);
|
CTValAx values = plotArea.getValAxArray(i);
|
||||||
axes.put(values.getAxId().getVal(), new XDDFValueAxis(values));
|
axesMap.put(values.getAxId().getVal(), new XDDFValueAxis(values));
|
||||||
}
|
}
|
||||||
return axes;
|
return axesMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFValueAxis createValueAxis(AxisPosition pos) {
|
public XDDFValueAxis createValueAxis(AxisPosition pos) {
|
||||||
|
@ -767,15 +766,14 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
*/
|
*/
|
||||||
public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory,
|
public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory,
|
||||||
int chartIndex) {
|
int chartIndex) {
|
||||||
documentPart = createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart();
|
POIXMLDocumentPart documentPart =
|
||||||
|
createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart();
|
||||||
return addRelation(null, chartRelation, documentPart).getRelationship();
|
return addRelation(null, chartRelation, documentPart).getRelationship();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if embedded part was null then create new part
|
* if embedded part was null then create new part
|
||||||
*
|
*
|
||||||
* @param chartRelation
|
|
||||||
* chart relation object
|
|
||||||
* @param chartWorkbookRelation
|
* @param chartWorkbookRelation
|
||||||
* chart workbook relation object
|
* chart workbook relation object
|
||||||
* @param chartFactory
|
* @param chartFactory
|
||||||
|
@ -784,8 +782,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
* @since POI 4.0.0
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation,
|
private PackagePart createWorksheetPart(POIXMLRelation chartWorkbookRelation, POIXMLFactory chartFactory)
|
||||||
POIXMLFactory chartFactory) throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex);
|
PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex);
|
||||||
setExternalId(xlsx.getId());
|
setExternalId(xlsx.getId());
|
||||||
return getTargetPart(xlsx);
|
return getTargetPart(xlsx);
|
||||||
|
@ -803,11 +801,10 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
public void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException {
|
public void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException {
|
||||||
PackagePart worksheetPart = getWorksheetPart();
|
PackagePart worksheetPart = getWorksheetPart();
|
||||||
if (worksheetPart == null) {
|
if (worksheetPart == null) {
|
||||||
POIXMLRelation chartRelation = getChartRelation();
|
|
||||||
POIXMLRelation chartWorkbookRelation = getChartWorkbookRelation();
|
POIXMLRelation chartWorkbookRelation = getChartWorkbookRelation();
|
||||||
POIXMLFactory chartFactory = getChartFactory();
|
POIXMLFactory chartFactory = getChartFactory();
|
||||||
if (chartRelation != null && chartWorkbookRelation != null && chartFactory != null) {
|
if (chartWorkbookRelation != null && chartFactory != null) {
|
||||||
worksheetPart = createWorksheetPart(chartRelation, chartWorkbookRelation, chartFactory);
|
worksheetPart = createWorksheetPart(chartWorkbookRelation, chartFactory);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidFormatException("unable to determine chart relations");
|
throw new InvalidFormatException("unable to determine chart relations");
|
||||||
}
|
}
|
||||||
|
@ -950,6 +947,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
*/
|
*/
|
||||||
public CellReference setSheetTitle(String title, int column) {
|
public CellReference setSheetTitle(String title, int column) {
|
||||||
XSSFSheet sheet = getSheet();
|
XSSFSheet sheet = getSheet();
|
||||||
|
if (sheet == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
XSSFRow row = getRow(sheet, 0);
|
XSSFRow row = getRow(sheet, 0);
|
||||||
XSSFCell cell = getCell(row, column);
|
XSSFCell cell = getCell(row, column);
|
||||||
cell.setCellValue(title);
|
cell.setCellValue(title);
|
||||||
|
@ -1000,7 +1000,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setWorksheetPartCommitted() throws InvalidFormatException {
|
private void setWorksheetPartCommitted() {
|
||||||
for (RelationPart part : getRelationParts()) {
|
for (RelationPart part : getRelationParts()) {
|
||||||
if (POIXMLDocument.PACK_OBJECT_REL_TYPE.equals(part.getRelationship().getRelationshipType())) {
|
if (POIXMLDocument.PACK_OBJECT_REL_TYPE.equals(part.getRelationship().getRelationshipType())) {
|
||||||
part.getDocumentPart().setCommitted(true);
|
part.getDocumentPart().setCommitted(true);
|
||||||
|
|
|
@ -408,7 +408,10 @@ public abstract class XDDFChartAxis implements HasShapeProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long getNextAxId(CTPlotArea plotArea) {
|
protected long getNextAxId(CTPlotArea plotArea) {
|
||||||
long totalAxisCount = plotArea.sizeOfValAxArray() + plotArea.sizeOfCatAxArray() + plotArea.sizeOfDateAxArray()
|
long totalAxisCount = 0L
|
||||||
|
+ plotArea.sizeOfValAxArray()
|
||||||
|
+ plotArea.sizeOfCatAxArray()
|
||||||
|
+ plotArea.sizeOfDateAxArray()
|
||||||
+ plotArea.sizeOfSerAxArray();
|
+ plotArea.sizeOfSerAxArray();
|
||||||
return totalAxisCount;
|
return totalAxisCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
|
@ -195,14 +196,16 @@ public final class XDDFChartLegend implements TextContainer {
|
||||||
legend.getOverlay().setVal(value);
|
legend.getOverlay().setVal(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public <R> Optional<R> findDefinedParagraphProperty(
|
public <R> Optional<R> findDefinedParagraphProperty(
|
||||||
Function<CTTextParagraphProperties, Boolean> isSet,
|
Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
return Optional.empty(); // chart legend has no (indirect) paragraph properties
|
return Optional.empty(); // chart legend has no (indirect) paragraph properties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public <R> Optional<R> findDefinedRunProperty(
|
public <R> Optional<R> findDefinedRunProperty(
|
||||||
Function<CTTextCharacterProperties, Boolean> isSet,
|
Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
return Optional.empty(); // chart legend has no (indirect) paragraph properties
|
return Optional.empty(); // chart legend has no (indirect) paragraph properties
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
|
@ -113,14 +114,14 @@ public class XDDFLegendEntry implements TextContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedParagraphProperty(
|
public <R> Optional<R> findDefinedParagraphProperty(
|
||||||
Function<CTTextParagraphProperties, Boolean> isSet,
|
Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
return Optional.empty(); // legend entry has no (indirect) paragraph properties
|
return Optional.empty(); // legend entry has no (indirect) paragraph properties
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedRunProperty(
|
public <R> Optional<R> findDefinedRunProperty(
|
||||||
Function<CTTextCharacterProperties, Boolean> isSet,
|
Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
return Optional.empty(); // legend entry has no (indirect) paragraph properties
|
return Optional.empty(); // legend entry has no (indirect) paragraph properties
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.text;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
||||||
|
@ -27,10 +28,10 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties
|
||||||
@Beta
|
@Beta
|
||||||
public interface TextContainer {
|
public interface TextContainer {
|
||||||
|
|
||||||
<R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
<R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter);
|
Function<CTTextParagraphProperties, R> getter);
|
||||||
|
|
||||||
<R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
<R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter);
|
Function<CTTextCharacterProperties, R> getter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
|
@ -337,12 +338,12 @@ public class XDDFTextBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
protected <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
protected <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter, int level) {
|
Function<CTTextParagraphProperties, R> getter, int level) {
|
||||||
if (_body.isSetLstStyle() && level >= 0) {
|
if (_body.isSetLstStyle() && level >= 0) {
|
||||||
CTTextListStyle list = _body.getLstStyle();
|
CTTextListStyle list = _body.getLstStyle();
|
||||||
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level);
|
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level);
|
||||||
if (props != null && isSet.apply(props)) {
|
if (props != null && isSet.test(props)) {
|
||||||
return Optional.of(getter.apply(props));
|
return Optional.of(getter.apply(props));
|
||||||
} else {
|
} else {
|
||||||
return findDefinedParagraphProperty(isSet, getter, level - 1);
|
return findDefinedParagraphProperty(isSet, getter, level - 1);
|
||||||
|
@ -355,12 +356,12 @@ public class XDDFTextBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
protected <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
protected <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter, int level) {
|
Function<CTTextCharacterProperties, R> getter, int level) {
|
||||||
if (_body.isSetLstStyle() && level >= 0) {
|
if (_body.isSetLstStyle() && level >= 0) {
|
||||||
CTTextListStyle list = _body.getLstStyle();
|
CTTextListStyle list = _body.getLstStyle();
|
||||||
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level);
|
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level);
|
||||||
if (props != null && props.isSetDefRPr() && isSet.apply(props.getDefRPr())) {
|
if (props != null && props.isSetDefRPr() && isSet.test(props.getDefRPr())) {
|
||||||
return Optional.of(getter.apply(props.getDefRPr()));
|
return Optional.of(getter.apply(props.getDefRPr()));
|
||||||
} else {
|
} else {
|
||||||
return findDefinedRunProperty(isSet, getter, level - 1);
|
return findDefinedRunProperty(isSet, getter, level - 1);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.commons.collections4.iterators.IteratorIterable;
|
import org.apache.commons.collections4.iterators.IteratorIterable;
|
||||||
import org.apache.commons.collections4.iterators.ReverseListIterator;
|
import org.apache.commons.collections4.iterators.ReverseListIterator;
|
||||||
|
@ -178,8 +179,10 @@ public class XDDFTextParagraph {
|
||||||
* @return alignment that is applied to the paragraph
|
* @return alignment that is applied to the paragraph
|
||||||
*/
|
*/
|
||||||
public TextAlignment getTextAlignment() {
|
public TextAlignment getTextAlignment() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetAlgn(), props -> props.getAlgn())
|
return findDefinedParagraphProperty(
|
||||||
.map(align -> TextAlignment.valueOf(align)).orElse(null);
|
CTTextParagraphProperties::isSetAlgn,
|
||||||
|
CTTextParagraphProperties::getAlgn)
|
||||||
|
.map(TextAlignment::valueOf).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,8 +208,10 @@ public class XDDFTextParagraph {
|
||||||
* @return alignment that is applied to the paragraph
|
* @return alignment that is applied to the paragraph
|
||||||
*/
|
*/
|
||||||
public FontAlignment getFontAlignment() {
|
public FontAlignment getFontAlignment() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetFontAlgn(), props -> props.getFontAlgn())
|
return findDefinedParagraphProperty(
|
||||||
.map(align -> FontAlignment.valueOf(align)).orElse(null);
|
CTTextParagraphProperties::isSetFontAlgn,
|
||||||
|
CTTextParagraphProperties::getFontAlgn)
|
||||||
|
.map(FontAlignment::valueOf).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,8 +235,10 @@ public class XDDFTextParagraph {
|
||||||
* the paragraph.
|
* the paragraph.
|
||||||
*/
|
*/
|
||||||
public Double getIndentation() {
|
public Double getIndentation() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetIndent(), props -> props.getIndent())
|
return findDefinedParagraphProperty(
|
||||||
.map(emu -> Units.toPoints(emu)).orElse(null);
|
CTTextParagraphProperties::isSetIndent,
|
||||||
|
CTTextParagraphProperties::getIndent)
|
||||||
|
.map(Units::toPoints).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,8 +266,10 @@ public class XDDFTextParagraph {
|
||||||
* @return the left margin, in points, of the paragraph.
|
* @return the left margin, in points, of the paragraph.
|
||||||
*/
|
*/
|
||||||
public Double getMarginLeft() {
|
public Double getMarginLeft() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetMarL(), props -> props.getMarL())
|
return findDefinedParagraphProperty(
|
||||||
.map(emu -> Units.toPoints(emu)).orElse(null);
|
CTTextParagraphProperties::isSetMarL,
|
||||||
|
CTTextParagraphProperties::getMarL)
|
||||||
|
.map(Units::toPoints).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -290,8 +299,10 @@ public class XDDFTextParagraph {
|
||||||
* @return the right margin, in points, of the paragraph.
|
* @return the right margin, in points, of the paragraph.
|
||||||
*/
|
*/
|
||||||
public Double getMarginRight() {
|
public Double getMarginRight() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetMarR(), props -> props.getMarR())
|
return findDefinedParagraphProperty(
|
||||||
.map(emu -> Units.toPoints(emu)).orElse(null);
|
CTTextParagraphProperties::isSetMarR,
|
||||||
|
CTTextParagraphProperties::getMarR)
|
||||||
|
.map(Units::toPoints).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,8 +333,10 @@ public class XDDFTextParagraph {
|
||||||
* points.
|
* points.
|
||||||
*/
|
*/
|
||||||
public Double getDefaultTabSize() {
|
public Double getDefaultTabSize() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetDefTabSz(), props -> props.getDefTabSz())
|
return findDefinedParagraphProperty(
|
||||||
.map(emu -> Units.toPoints(emu)).orElse(null);
|
CTTextParagraphProperties::isSetDefTabSz,
|
||||||
|
CTTextParagraphProperties::getDefTabSz)
|
||||||
|
.map(Units::toPoints).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -352,8 +365,10 @@ public class XDDFTextParagraph {
|
||||||
* @return the vertical line spacing.
|
* @return the vertical line spacing.
|
||||||
*/
|
*/
|
||||||
public XDDFSpacing getLineSpacing() {
|
public XDDFSpacing getLineSpacing() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetLnSpc(), props -> props.getLnSpc())
|
return findDefinedParagraphProperty(
|
||||||
.map(spacing -> extractSpacing(spacing)).orElse(null);
|
CTTextParagraphProperties::isSetLnSpc,
|
||||||
|
CTTextParagraphProperties::getLnSpc)
|
||||||
|
.map(this::extractSpacing).orElse(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,8 +418,10 @@ public class XDDFTextParagraph {
|
||||||
* @return the vertical white space before the paragraph.
|
* @return the vertical white space before the paragraph.
|
||||||
*/
|
*/
|
||||||
public XDDFSpacing getSpaceBefore() {
|
public XDDFSpacing getSpaceBefore() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetSpcBef(), props -> props.getSpcBef())
|
return findDefinedParagraphProperty(
|
||||||
.map(spacing -> extractSpacing(spacing)).orElse(null);
|
CTTextParagraphProperties::isSetSpcBef,
|
||||||
|
CTTextParagraphProperties::getSpcBef)
|
||||||
|
.map(this::extractSpacing).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -451,8 +468,10 @@ public class XDDFTextParagraph {
|
||||||
* @return the vertical white space after the paragraph.
|
* @return the vertical white space after the paragraph.
|
||||||
*/
|
*/
|
||||||
public XDDFSpacing getSpaceAfter() {
|
public XDDFSpacing getSpaceAfter() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetSpcAft(), props -> props.getSpcAft())
|
return findDefinedParagraphProperty(
|
||||||
.map(spacing -> extractSpacing(spacing)).orElse(null);
|
CTTextParagraphProperties::isSetSpcAft,
|
||||||
|
CTTextParagraphProperties::getSpcAft)
|
||||||
|
.map(this::extractSpacing).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -599,7 +618,10 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEastAsianLineBreak() {
|
public boolean hasEastAsianLineBreak() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetEaLnBrk(), props -> props.getEaLnBrk()).orElse(false);
|
return findDefinedParagraphProperty(
|
||||||
|
CTTextParagraphProperties::isSetEaLnBrk,
|
||||||
|
CTTextParagraphProperties::getEaLnBrk)
|
||||||
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEastAsianLineBreak(Boolean value) {
|
public void setEastAsianLineBreak(Boolean value) {
|
||||||
|
@ -609,7 +631,9 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasLatinLineBreak() {
|
public boolean hasLatinLineBreak() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetLatinLnBrk(), props -> props.getLatinLnBrk())
|
return findDefinedParagraphProperty(
|
||||||
|
CTTextParagraphProperties::isSetLatinLnBrk,
|
||||||
|
CTTextParagraphProperties::getLatinLnBrk)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +644,9 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasHangingPunctuation() {
|
public boolean hasHangingPunctuation() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetHangingPunct(), props -> props.getHangingPunct())
|
return findDefinedParagraphProperty(
|
||||||
|
CTTextParagraphProperties::isSetHangingPunct,
|
||||||
|
CTTextParagraphProperties::getHangingPunct)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,7 +657,10 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRightToLeft() {
|
public boolean isRightToLeft() {
|
||||||
return findDefinedParagraphProperty(props -> props.isSetRtl(), props -> props.getRtl()).orElse(false);
|
return findDefinedParagraphProperty(
|
||||||
|
CTTextParagraphProperties::isSetRtl,
|
||||||
|
CTTextParagraphProperties::getRtl)
|
||||||
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRightToLeft(Boolean value) {
|
public void setRightToLeft(Boolean value) {
|
||||||
|
@ -760,7 +789,7 @@ public class XDDFTextParagraph {
|
||||||
return getProperties();
|
return getProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
protected <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
if (_p.isSetPPr()) {
|
if (_p.isSetPPr()) {
|
||||||
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0;
|
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0;
|
||||||
|
@ -770,17 +799,17 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
private <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter, int level) {
|
Function<CTTextParagraphProperties, R> getter, int level) {
|
||||||
final CTTextParagraphProperties props = _p.getPPr();
|
final CTTextParagraphProperties props = _p.getPPr();
|
||||||
if (props != null && isSet.apply(props)) {
|
if (props != null && isSet.test(props)) {
|
||||||
return Optional.ofNullable(getter.apply(props));
|
return Optional.ofNullable(getter.apply(props));
|
||||||
} else {
|
} else {
|
||||||
return _parent.findDefinedParagraphProperty(isSet, getter, level);
|
return _parent.findDefinedParagraphProperty(isSet, getter, level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
protected <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
if (_p.isSetPPr()) {
|
if (_p.isSetPPr()) {
|
||||||
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0;
|
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0;
|
||||||
|
@ -790,10 +819,10 @@ public class XDDFTextParagraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
private <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter, int level) {
|
Function<CTTextCharacterProperties, R> getter, int level) {
|
||||||
final CTTextCharacterProperties props = _p.getPPr().isSetDefRPr() ? _p.getPPr().getDefRPr() : null;
|
final CTTextCharacterProperties props = _p.getPPr().isSetDefRPr() ? _p.getPPr().getDefRPr() : null;
|
||||||
if (props != null && isSet.apply(props)) {
|
if (props != null && isSet.test(props)) {
|
||||||
return Optional.ofNullable(getter.apply(props));
|
return Optional.ofNullable(getter.apply(props));
|
||||||
} else {
|
} else {
|
||||||
return _parent.findDefinedRunProperty(isSet, getter, level);
|
return _parent.findDefinedRunProperty(isSet, getter, level);
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.LinkedList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.poi.common.usermodel.fonts.FontGroup;
|
import org.apache.poi.common.usermodel.fonts.FontGroup;
|
||||||
import org.apache.poi.ooxml.POIXMLRelation;
|
import org.apache.poi.ooxml.POIXMLRelation;
|
||||||
|
@ -108,7 +109,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDirty() {
|
public Boolean getDirty() {
|
||||||
return findDefinedProperty(props -> props.isSetDirty(), props -> props.getDirty())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetDirty,
|
||||||
|
CTTextCharacterProperties::getDirty)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +120,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getSpellError() {
|
public Boolean getSpellError() {
|
||||||
return findDefinedProperty(props -> props.isSetErr(), props -> props.getErr())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetErr,
|
||||||
|
CTTextCharacterProperties::getErr)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +131,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getNoProof() {
|
public Boolean getNoProof() {
|
||||||
return findDefinedProperty(props -> props.isSetNoProof(), props -> props.getNoProof())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetNoProof,
|
||||||
|
CTTextCharacterProperties::getNoProof)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +142,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getNormalizeHeights() {
|
public Boolean getNormalizeHeights() {
|
||||||
return findDefinedProperty(props -> props.isSetNormalizeH(), props -> props.getNormalizeH())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetNormalizeH,
|
||||||
|
CTTextCharacterProperties::getNormalizeH)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +153,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKumimoji() {
|
public boolean isKumimoji() {
|
||||||
return findDefinedProperty(props -> props.isSetKumimoji(), props -> props.getKumimoji())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetKumimoji,
|
||||||
|
CTTextCharacterProperties::getKumimoji)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +173,9 @@ public class XDDFTextRun {
|
||||||
* @return whether this run of text is formatted as bold text.
|
* @return whether this run of text is formatted as bold text.
|
||||||
*/
|
*/
|
||||||
public boolean isBold() {
|
public boolean isBold() {
|
||||||
return findDefinedProperty(props -> props.isSetB(), props -> props.getB())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetB,
|
||||||
|
CTTextCharacterProperties::getB)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +191,9 @@ public class XDDFTextRun {
|
||||||
* @return whether this run of text is formatted as italic text.
|
* @return whether this run of text is formatted as italic text.
|
||||||
*/
|
*/
|
||||||
public boolean isItalic() {
|
public boolean isItalic() {
|
||||||
return findDefinedProperty(props -> props.isSetI(), props -> props.getI())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetI,
|
||||||
|
CTTextCharacterProperties::getI)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +209,9 @@ public class XDDFTextRun {
|
||||||
* @return whether this run of text is formatted as striked text.
|
* @return whether this run of text is formatted as striked text.
|
||||||
*/
|
*/
|
||||||
public boolean isStrikeThrough() {
|
public boolean isStrikeThrough() {
|
||||||
return findDefinedProperty(props -> props.isSetStrike(), props -> props.getStrike())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetStrike,
|
||||||
|
CTTextCharacterProperties::getStrike)
|
||||||
.map(strike -> strike != STTextStrikeType.NO_STRIKE)
|
.map(strike -> strike != STTextStrikeType.NO_STRIKE)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
@ -203,8 +220,10 @@ public class XDDFTextRun {
|
||||||
* @return which strike style this run of text is formatted with.
|
* @return which strike style this run of text is formatted with.
|
||||||
*/
|
*/
|
||||||
public StrikeType getStrikeThrough() {
|
public StrikeType getStrikeThrough() {
|
||||||
return findDefinedProperty(props -> props.isSetStrike(), props -> props.getStrike())
|
return findDefinedProperty(
|
||||||
.map(strike -> StrikeType.valueOf(strike))
|
CTTextCharacterProperties::isSetStrike,
|
||||||
|
CTTextCharacterProperties::getStrike)
|
||||||
|
.map(StrikeType::valueOf)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +239,9 @@ public class XDDFTextRun {
|
||||||
* @return whether this run of text is formatted as underlined text.
|
* @return whether this run of text is formatted as underlined text.
|
||||||
*/
|
*/
|
||||||
public boolean isUnderline() {
|
public boolean isUnderline() {
|
||||||
return findDefinedProperty(props -> props.isSetU(), props -> props.getU())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetU,
|
||||||
|
CTTextCharacterProperties::getU)
|
||||||
.map(underline -> underline != STTextUnderlineType.NONE)
|
.map(underline -> underline != STTextUnderlineType.NONE)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
@ -229,8 +250,10 @@ public class XDDFTextRun {
|
||||||
* @return which underline style this run of text is formatted with.
|
* @return which underline style this run of text is formatted with.
|
||||||
*/
|
*/
|
||||||
public UnderlineType getUnderline() {
|
public UnderlineType getUnderline() {
|
||||||
return findDefinedProperty(props -> props.isSetU(), props -> props.getU())
|
return findDefinedProperty(
|
||||||
.map(underline -> UnderlineType.valueOf(underline))
|
CTTextCharacterProperties::isSetU,
|
||||||
|
CTTextCharacterProperties::getU)
|
||||||
|
.map(UnderlineType::valueOf)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +269,9 @@ public class XDDFTextRun {
|
||||||
* @return whether this run of text is formatted as capitalized text.
|
* @return whether this run of text is formatted as capitalized text.
|
||||||
*/
|
*/
|
||||||
public boolean isCapitals() {
|
public boolean isCapitals() {
|
||||||
return findDefinedProperty(props -> props.isSetCap(), props -> props.getCap())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetCap,
|
||||||
|
CTTextCharacterProperties::getCap)
|
||||||
.map(caps -> caps != STTextCapsType.NONE)
|
.map(caps -> caps != STTextCapsType.NONE)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
@ -255,8 +280,10 @@ public class XDDFTextRun {
|
||||||
* @return which caps style this run of text is formatted with.
|
* @return which caps style this run of text is formatted with.
|
||||||
*/
|
*/
|
||||||
public CapsType getCapitals() {
|
public CapsType getCapitals() {
|
||||||
return findDefinedProperty(props -> props.isSetCap(), props -> props.getCap())
|
return findDefinedProperty(
|
||||||
.map(caps -> CapsType.valueOf(caps))
|
CTTextCharacterProperties::isSetCap,
|
||||||
|
CTTextCharacterProperties::getCap)
|
||||||
|
.map(CapsType::valueOf)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +292,9 @@ public class XDDFTextRun {
|
||||||
* Default is false.
|
* Default is false.
|
||||||
*/
|
*/
|
||||||
public boolean isSubscript() {
|
public boolean isSubscript() {
|
||||||
return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetBaseline,
|
||||||
|
CTTextCharacterProperties::getBaseline)
|
||||||
.map(baseline -> baseline < 0)
|
.map(baseline -> baseline < 0)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +304,9 @@ public class XDDFTextRun {
|
||||||
* Default is false.
|
* Default is false.
|
||||||
*/
|
*/
|
||||||
public boolean isSuperscript() {
|
public boolean isSuperscript() {
|
||||||
return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetBaseline,
|
||||||
|
CTTextCharacterProperties::getBaseline)
|
||||||
.map(baseline -> baseline > 0)
|
.map(baseline -> baseline > 0)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
@ -332,8 +363,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFColor getFontColor() {
|
public XDDFColor getFontColor() {
|
||||||
XDDFSolidFillProperties solid = findDefinedProperty(props -> props.isSetSolidFill(), props -> props.getSolidFill())
|
XDDFSolidFillProperties solid = findDefinedProperty(
|
||||||
.map(props -> new XDDFSolidFillProperties(props))
|
CTTextCharacterProperties::isSetSolidFill,
|
||||||
|
CTTextCharacterProperties::getSolidFill)
|
||||||
|
.map(XDDFSolidFillProperties::new)
|
||||||
.orElse(new XDDFSolidFillProperties());
|
.orElse(new XDDFSolidFillProperties());
|
||||||
return solid.getColor();
|
return solid.getColor();
|
||||||
}
|
}
|
||||||
|
@ -352,18 +385,18 @@ public class XDDFTextRun {
|
||||||
public XDDFFont[] getFonts() {
|
public XDDFFont[] getFonts() {
|
||||||
LinkedList<XDDFFont> list = new LinkedList<>();
|
LinkedList<XDDFFont> list = new LinkedList<>();
|
||||||
|
|
||||||
findDefinedProperty(props -> props.isSetCs(), props -> props.getCs())
|
findDefinedProperty(CTTextCharacterProperties::isSetCs, CTTextCharacterProperties::getCs)
|
||||||
.map(font -> new XDDFFont(FontGroup.COMPLEX_SCRIPT, font))
|
.map(font -> new XDDFFont(FontGroup.COMPLEX_SCRIPT, font))
|
||||||
.ifPresent(font -> list.add(font));
|
.ifPresent(list::add);
|
||||||
findDefinedProperty(props -> props.isSetEa(), props -> props.getEa())
|
findDefinedProperty(CTTextCharacterProperties::isSetEa, CTTextCharacterProperties::getEa)
|
||||||
.map(font -> new XDDFFont(FontGroup.EAST_ASIAN, font))
|
.map(font -> new XDDFFont(FontGroup.EAST_ASIAN, font))
|
||||||
.ifPresent(font -> list.add(font));
|
.ifPresent(list::add);
|
||||||
findDefinedProperty(props -> props.isSetLatin(), props -> props.getLatin())
|
findDefinedProperty(CTTextCharacterProperties::isSetLatin, CTTextCharacterProperties::getLatin)
|
||||||
.map(font -> new XDDFFont(FontGroup.LATIN, font))
|
.map(font -> new XDDFFont(FontGroup.LATIN, font))
|
||||||
.ifPresent(font -> list.add(font));
|
.ifPresent(list::add);
|
||||||
findDefinedProperty(props -> props.isSetSym(), props -> props.getSym())
|
findDefinedProperty(CTTextCharacterProperties::isSetSym, CTTextCharacterProperties::getSym)
|
||||||
.map(font -> new XDDFFont(FontGroup.SYMBOL, font))
|
.map(font -> new XDDFFont(FontGroup.SYMBOL, font))
|
||||||
.ifPresent(font -> list.add(font));
|
.ifPresent(list::add);
|
||||||
|
|
||||||
return list.toArray(new XDDFFont[0]);
|
return list.toArray(new XDDFFont[0]);
|
||||||
}
|
}
|
||||||
|
@ -384,7 +417,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getFontSize() {
|
public Double getFontSize() {
|
||||||
Integer size = findDefinedProperty(props -> props.isSetSz(), props -> props.getSz())
|
Integer size = findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetSz,
|
||||||
|
CTTextCharacterProperties::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;
|
double scale = _parent.getParentBody().getBodyProperties().getAutoFit().getFontScale() / 10_000_000.0;
|
||||||
return size * scale;
|
return size * scale;
|
||||||
|
@ -415,7 +450,9 @@ public class XDDFTextRun {
|
||||||
* If this attribute is omitted then returns <code>null</code>.
|
* If this attribute is omitted then returns <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public Double getCharacterKerning() {
|
public Double getCharacterKerning() {
|
||||||
return findDefinedProperty(props -> props.isSetKern(), props -> props.getKern())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetKern,
|
||||||
|
CTTextCharacterProperties::getKern)
|
||||||
.map(kerning -> 0.01 * kerning)
|
.map(kerning -> 0.01 * kerning)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
@ -449,7 +486,9 @@ public class XDDFTextRun {
|
||||||
* If this attribute is omitted then returns <code>null</code>.
|
* If this attribute is omitted then returns <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public Double getCharacterSpacing() {
|
public Double getCharacterSpacing() {
|
||||||
return findDefinedProperty(props -> props.isSetSpc(), props -> props.getSpc())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetSpc,
|
||||||
|
CTTextCharacterProperties::getSpc)
|
||||||
.map(spacing -> 0.01 * spacing)
|
.map(spacing -> 0.01 * spacing)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
@ -459,7 +498,9 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBookmark() {
|
public String getBookmark() {
|
||||||
return findDefinedProperty(props -> props.isSetBmk(), props -> props.getBmk())
|
return findDefinedProperty(
|
||||||
|
CTTextCharacterProperties::isSetBmk,
|
||||||
|
CTTextCharacterProperties::getBmk)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,8 +525,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFHyperlink getHyperlink() {
|
public XDDFHyperlink getHyperlink() {
|
||||||
return findDefinedProperty(props -> props.isSetHlinkClick(), props -> props.getHlinkClick())
|
return findDefinedProperty(
|
||||||
.map(link -> new XDDFHyperlink(link))
|
CTTextCharacterProperties::isSetHlinkClick,
|
||||||
|
CTTextCharacterProperties::getHlinkClick)
|
||||||
|
.map(XDDFHyperlink::new)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,8 +539,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFHyperlink getMouseOver() {
|
public XDDFHyperlink getMouseOver() {
|
||||||
return findDefinedProperty(props -> props.isSetHlinkMouseOver(), props -> props.getHlinkMouseOver())
|
return findDefinedProperty(
|
||||||
.map(link -> new XDDFHyperlink(link))
|
CTTextCharacterProperties::isSetHlinkMouseOver,
|
||||||
|
CTTextCharacterProperties::getHlinkMouseOver)
|
||||||
|
.map(XDDFHyperlink::new)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,8 +551,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getLanguage() {
|
public Locale getLanguage() {
|
||||||
return findDefinedProperty(props -> props.isSetLang(), props -> props.getLang())
|
return findDefinedProperty(
|
||||||
.map(lang -> Locale.forLanguageTag(lang))
|
CTTextCharacterProperties::isSetLang,
|
||||||
|
CTTextCharacterProperties::getLang)
|
||||||
|
.map(Locale::forLanguageTag)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,8 +563,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getAlternativeLanguage() {
|
public Locale getAlternativeLanguage() {
|
||||||
return findDefinedProperty(props -> props.isSetAltLang(), props -> props.getAltLang())
|
return findDefinedProperty(
|
||||||
.map(lang -> Locale.forLanguageTag(lang))
|
CTTextCharacterProperties::isSetAltLang,
|
||||||
|
CTTextCharacterProperties::getAltLang)
|
||||||
|
.map(Locale::forLanguageTag)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,8 +575,10 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFColor getHighlight() {
|
public XDDFColor getHighlight() {
|
||||||
return findDefinedProperty(props -> props.isSetHighlight(), props -> props.getHighlight())
|
return findDefinedProperty(
|
||||||
.map(color -> XDDFColor.forColorContainer(color))
|
CTTextCharacterProperties::isSetHighlight,
|
||||||
|
CTTextCharacterProperties::getHighlight)
|
||||||
|
.map(XDDFColor::forColorContainer)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,14 +587,16 @@ public class XDDFTextRun {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDDFLineProperties getLineProperties() {
|
public XDDFLineProperties getLineProperties() {
|
||||||
return findDefinedProperty(props -> props.isSetLn(), props -> props.getLn())
|
return findDefinedProperty(
|
||||||
.map(props -> new XDDFLineProperties(props))
|
CTTextCharacterProperties::isSetLn,
|
||||||
|
CTTextCharacterProperties::getLn)
|
||||||
|
.map(XDDFLineProperties::new)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R> Optional<R> findDefinedProperty(Function<CTTextCharacterProperties, Boolean> isSet, Function<CTTextCharacterProperties, R> getter) {
|
private <R> Optional<R> findDefinedProperty(Predicate<CTTextCharacterProperties> isSet, Function<CTTextCharacterProperties, R> getter) {
|
||||||
CTTextCharacterProperties props = getProperties();
|
CTTextCharacterProperties props = getProperties();
|
||||||
if (props != null && isSet.apply(props)) {
|
if (props != null && isSet.test(props)) {
|
||||||
return Optional.ofNullable(getter.apply(props));
|
return Optional.ofNullable(getter.apply(props));
|
||||||
} else {
|
} else {
|
||||||
return _parent.findDefinedRunProperty(isSet, getter);
|
return _parent.findDefinedRunProperty(isSet, getter);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.poi.ooxml.POIXMLException;
|
import org.apache.poi.ooxml.POIXMLException;
|
||||||
import org.apache.poi.sl.draw.DrawFactory;
|
import org.apache.poi.sl.draw.DrawFactory;
|
||||||
|
@ -773,14 +774,14 @@ public abstract class XSLFTextShape extends XSLFSimpleShape
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import org.apache.poi.hssf.util.HSSFColor;
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.ss.usermodel.SimpleShape;
|
import org.apache.poi.ss.usermodel.SimpleShape;
|
||||||
|
@ -1005,14 +1006,14 @@ public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet,
|
||||||
Function<CTTextParagraphProperties, R> getter) {
|
Function<CTTextParagraphProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet,
|
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet,
|
||||||
Function<CTTextCharacterProperties, R> getter) {
|
Function<CTTextCharacterProperties, R> getter) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
Loading…
Reference in New Issue