aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xslf
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2018-11-02 18:35:34 +0000
committerAndreas Beeker <kiwiwings@apache.org>2018-11-02 18:35:34 +0000
commit0e68ef5f843ab6052faae2cb2d60b2575f94d805 (patch)
tree60e7c2c57afd09761eb549861a5ce2ae2cf48650 /src/ooxml/java/org/apache/poi/xslf
parent8b3974f9452388acf0fa65ec3bad316ec955883c (diff)
parent9aabade3f067b0befbc2680489ace13a6d5fa7e6 (diff)
downloadpoi-0e68ef5f843ab6052faae2cb2d60b2575f94d805.tar.gz
poi-0e68ef5f843ab6052faae2cb2d60b2575f94d805.zip
merge trunk
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hemf@1845617 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xslf')
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java32
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java93
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java16
5 files changed, 83 insertions, 70 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index 4019030761..687ddc5f5b 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -36,6 +36,7 @@ import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor;
+import org.apache.poi.ooxml.util.PackageHelper;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
@@ -50,7 +51,6 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.apache.poi.ooxml.util.PackageHelper;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
@@ -362,7 +362,7 @@ public class XMLSlideShow extends POIXMLDocument
CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId();
notesMasterId.setId(rp.getRelationship().getId());
- Integer themeIndex = 1;
+ int themeIndex = 1;
// TODO: check if that list can be replaced by idx = Math.max(idx,themeIdx)
List<Integer> themeIndexList = new ArrayList<>();
for (POIXMLDocumentPart p : getRelations()) {
@@ -626,7 +626,7 @@ public class XMLSlideShow extends POIXMLDocument
// TODO: implement!
throw new UnsupportedOperationException();
}
-
+
@Override
public POIXMLPropertiesTextExtractor getMetadataTextExtractor() {
return new POIXMLPropertiesTextExtractor(this);
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
index d7aed091b1..50b82df3b0 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
@@ -48,7 +48,7 @@ import org.w3c.dom.Node;
@Internal
public class XSLFColor {
private final static POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);
-
+
private XmlObject _xmlObject;
private Color _color;
private CTSchemeColor _phClr;
@@ -128,7 +128,7 @@ public class XSLFColor {
}
};
}
-
+
private Color toColor(XmlObject obj, XSLFTheme theme) {
Color color = null;
for (XmlObject ch : obj.selectPath("*")) {
@@ -207,19 +207,19 @@ public class XSLFColor {
if (fill.isSetScrgbClr()) {
fill.unsetScrgbClr();
}
-
+
if (fill.isSetHslClr()) {
fill.unsetHslClr();
}
-
+
if (fill.isSetPrstClr()) {
fill.unsetPrstClr();
}
-
+
if (fill.isSetSchemeClr()) {
fill.unsetSchemeClr();
}
-
+
if (fill.isSetSysClr()) {
fill.unsetSysClr();
}
@@ -227,12 +227,12 @@ public class XSLFColor {
float[] rgbaf = color.getRGBComponents(null);
boolean addAlpha = (rgbaf.length == 4 && rgbaf[3] < 1f);
CTPositiveFixedPercentage alphaPct;
-
+
// see office open xml part 4 - 5.1.2.2.30 and 5.1.2.2.32
if (isInt(rgbaf[0]) && isInt(rgbaf[1]) && isInt(rgbaf[2])) {
// sRGB has a gamma of 2.2
CTSRgbColor rgb = fill.addNewSrgbClr();
-
+
byte rgbBytes[] = { (byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue() };
rgb.setVal(rgbBytes);
alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
@@ -249,14 +249,14 @@ public class XSLFColor {
alphaPct.setVal((int)(100000 * rgbaf[3]));
}
}
-
+
/**
* @return true, if this is an integer color value
*/
private static boolean isInt(float f) {
- return Math.abs((f*255f) - Math.rint(f*255f)) < 0.00001f;
+ return Math.abs((f*255d) - Math.rint(f*255d)) < 0.00001;
}
-
+
private int getRawValue(String elem) {
String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
@@ -281,9 +281,9 @@ public class XSLFColor {
}
}
- return -1;
+ return -1;
}
-
+
/**
* Read a perecentage value from the supplied xml bean.
* Example:
@@ -305,7 +305,7 @@ public class XSLFColor {
* or -1 if the value is not set
*/
int getAlpha(){
- return getPercentageValue("alpha");
+ return getPercentageValue("alpha");
}
/**
@@ -413,7 +413,7 @@ public class XSLFColor {
/**
* specifies the input color with the specific red component, but with the blue and green color
* components unchanged
- *
+ *
* @return the value of the red component specified as a
* percentage with 0% indicating minimal blue and 100% indicating maximum
* or -1 if the value is not set
@@ -479,7 +479,7 @@ public class XSLFColor {
/**
* specifies a darker version of its input color.
* A 10% shade is 10% of the input color combined with 90% black.
- *
+ *
* @return the value of the shade specified as a
* percentage with 0% indicating minimal shade and 100% indicating maximum
* or -1 if the value is not set
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
index 64b92a9bbf..72d19e7aee 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
@@ -49,9 +49,7 @@ implements Notes<XSLFShape,XSLFTextParagraph> {
*
* @param part the package part holding the notes data,
* the content type must be <code>application/vnd.openxmlformats-officedocument.notes+xml</code>
- * @param rel the package relationship holding this notes,
- * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/notes
- *
+ *
* @since POI 3.14-Beta1
*/
XSLFNotes(PackagePart part) throws IOException, XmlException {
@@ -77,7 +75,7 @@ implements Notes<XSLFShape,XSLFTextParagraph> {
@Override
protected String getRootElementName(){
- return "notes";
+ return "notes";
}
@Override
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
index 4d162027e8..aded851db5 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
@@ -70,7 +70,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
@Beta
public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
static final String PML_NS = "http://schemas.openxmlformats.org/presentationml/2006/main";
-
+
private final XmlObject _shape;
private final XSLFSheet _sheet;
private XSLFShapeContainer _parent;
@@ -82,7 +82,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
_shape = shape;
_sheet = sheet;
}
-
+
/**
* @return the xml bean holding this shape's data
*/
@@ -91,11 +91,12 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
// the (not existing) xmlbeans hierarchy and subclasses shouldn't narrow it's return value
return _shape;
}
-
+
+ @Override
public XSLFSheet getSheet() {
return _sheet;
}
-
+
@Override
public String getShapeName(){
return getCNvPr().getName();
@@ -124,22 +125,24 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
PlaceableShape<?,?> ps = (PlaceableShape<?,?>)this;
ps.setAnchor(sh.getAnchor());
}
-
-
+
+
}
-
+
public void setParent(XSLFShapeContainer parent) {
this._parent = parent;
}
-
+
+ @Override
public XSLFShapeContainer getParent() {
return this._parent;
}
-
+
protected PaintStyle getFillPaint() {
final XSLFTheme theme = getSheet().getTheme();
final boolean hasPlaceholder = getPlaceholder() != null;
PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
+ @Override
public boolean fetch(XSLFShape shape) {
XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(shape.getShapeProperties());
if (fp == null) {
@@ -150,7 +153,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
setValue(null);
return true;
}
-
+
PackagePart pp = shape.getSheet().getPackagePart();
PaintStyle paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
if (paint != null) {
@@ -167,8 +170,8 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
setValue(paint);
return true;
}
-
-
+
+
return false;
}
};
@@ -181,16 +184,16 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
protected CTBackgroundProperties getBgPr() {
return getChild(CTBackgroundProperties.class, PML_NS, "bgPr");
}
-
+
@SuppressWarnings("unused")
protected CTStyleMatrixReference getBgRef() {
return getChild(CTStyleMatrixReference.class, PML_NS, "bgRef");
}
-
+
protected CTGroupShapeProperties getGrpSpPr() {
return getChild(CTGroupShapeProperties.class, PML_NS, "grpSpPr");
}
-
+
protected CTNonVisualDrawingProps getCNvPr() {
if (_nvPr == null) {
String xquery = "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr";
@@ -239,7 +242,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
public Placeholder getPlaceholder() {
return getPlaceholderDetails().getPlaceholder();
}
-
+
/**
* @see PlaceholderDetails#setPlaceholder(Placeholder)
*/
@@ -268,7 +271,9 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
@SuppressWarnings({"unchecked", "WeakerAccess"})
protected <T extends XmlObject> T selectProperty(Class<T> resultClass, String xquery) {
XmlObject[] rs = getXmlObject().selectPath(xquery);
- if (rs.length == 0) return null;
+ if (rs.length == 0) {
+ return null;
+ }
return (resultClass.isInstance(rs[0])) ? (T)rs[0] : null;
}
@@ -281,7 +286,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
* <li>slideLayout
* <li>slideMaster
* </ol>
- *
+ *
* Currently themes and their defaults aren't correctly handled
*
* @param visitor the object that collects the desired property
@@ -299,7 +304,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
return false;
}
MasterSheet<XSLFShape,XSLFTextParagraph> sm = getSheet().getMasterSheet();
-
+
// try slide layout
if (sm instanceof XSLFSlideLayout) {
XSLFSlideLayout slideLayout = (XSLFSlideLayout)sm;
@@ -309,7 +314,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
}
sm = slideLayout.getMasterSheet();
}
-
+
// try slide master
if (sm instanceof XSLFSlideMaster) {
XSLFSlideMaster master = (XSLFSlideMaster)sm;
@@ -317,15 +322,15 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
XSLFSimpleShape masterShape = master.getPlaceholderByType(textType);
return masterShape != null && visitor.fetch(masterShape);
}
-
+
return false;
}
-
+
private static int getPlaceholderType(CTPlaceholder ph) {
if ( !ph.isSetType()) {
return STPlaceholderType.INT_BODY;
}
-
+
switch (ph.getType().intValue()) {
case STPlaceholderType.INT_TITLE:
case STPlaceholderType.INT_CTR_TITLE:
@@ -397,7 +402,8 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
throw new RuntimeException(e);
}
}
-
+
+ @Override
public InputStream getImageData() {
try {
return getPart().getInputStream();
@@ -406,17 +412,19 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
}
}
+ @Override
public String getContentType() {
/* TOOD: map content-type */
return getPart().getContentType();
}
+ @Override
public int getAlpha() {
return (blip.sizeOfAlphaModFixArray() > 0)
? blip.getAlphaModFixArray(0).getAmt()
: 100000;
}
- };
+ };
}
@SuppressWarnings("WeakerAccess")
@@ -426,14 +434,14 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
Arrays.sort(gs, (o1, o2) -> {
- Integer pos1 = o1.getPos();
- Integer pos2 = o2.getPos();
- return pos1.compareTo(pos2);
+ int pos1 = o1.getPos();
+ int pos2 = o2.getPos();
+ return Integer.compare(pos1, pos2);
});
final ColorStyle cs[] = new ColorStyle[gs.length];
final float fractions[] = new float[gs.length];
-
+
int i=0;
for (CTGradientStop cgs : gs) {
CTSchemeColor phClrCgs = phClr;
@@ -444,32 +452,37 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
fractions[i] = cgs.getPos() / 100000.f;
i++;
}
-
+
return new GradientPaint() {
+ @Override
public double getGradientAngle() {
return (gradFill.isSetLin())
? gradFill.getLin().getAng() / 60000.d
: 0;
}
+ @Override
public ColorStyle[] getGradientColors() {
return cs;
}
+ @Override
public float[] getGradientFractions() {
return fractions;
}
+ @Override
public boolean isRotatedWithShape() {
return gradFill.getRotWithShape();
}
+ @Override
public GradientType getGradientType() {
if (gradFill.isSetLin()) {
return GradientType.linear;
}
-
+
if (gradFill.isSetPath()) {
/* TODO: handle rect path */
STPathShadeType.Enum ps = gradFill.getPath().getPath();
@@ -479,16 +492,18 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
return GradientType.shape;
}
}
-
+
return GradientType.linear;
}
- };
+ };
}
-
+
@SuppressWarnings("WeakerAccess")
protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
- if (fillRef == null) return null;
-
+ if (fillRef == null) {
+ return null;
+ }
+
// The idx attribute refers to the index of a fill style or
// background fill style within the presentation's style matrix, defined by the fmtScheme element.
// value of 0 or 1000 indicates no background,
@@ -513,7 +528,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
}
cur.dispose();
-
+
CTSchemeColor phClr = fillRef.getSchemeClr();
PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
// check for empty placeholder value
@@ -524,12 +539,12 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
XSLFColor col = new XSLFColor(fillRef, theme, phClr);
return DrawPaint.createSolidPaint(col.getColorStyle());
}
-
+
@Override
public void draw(Graphics2D graphics, Rectangle2D bounds) {
DrawFactory.getInstance(graphics).drawShape(graphics, this, bounds);
}
-
+
/**
* Return the shape specific (visual) properties
*
diff --git a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
index c4fbb4ca3b..2ae1293113 100644
--- a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
+++ b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
@@ -74,13 +74,13 @@ public class PPTX2PNG {
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) {
if ("-scale".equals(args[i])) {
- scale = Float.parseFloat(args[++i]);
+ scale = Float.parseFloat(args[++i]); // lgtm[java/index-out-of-bounds]
} else if ("-slide".equals(args[i])) {
- slidenumStr = args[++i];
+ slidenumStr = args[++i]; // lgtm[java/index-out-of-bounds]
} else if ("-format".equals(args[i])) {
- format = args[++i];
+ format = args[++i]; // lgtm[java/index-out-of-bounds]
} else if ("-outdir".equals(args[i])) {
- outdir = new File(args[++i]);
+ outdir = new File(args[++i]); // lgtm[java/index-out-of-bounds]
} else if ("-quiet".equals(args[i])) {
quiet = true;
}
@@ -98,11 +98,11 @@ public class PPTX2PNG {
usage("Invalid format given");
return;
}
-
+
if (outdir == null) {
outdir = file.getParentFile();
}
-
+
if (!"null".equals(format) && (outdir == null || !outdir.exists() || !outdir.isDirectory())) {
usage("Output directory doesn't exist");
return;
@@ -112,7 +112,7 @@ public class PPTX2PNG {
usage("Invalid scale given");
return;
}
-
+
if (!quiet) {
System.out.println("Processing " + file);
}
@@ -168,7 +168,7 @@ public class PPTX2PNG {
System.out.println("Done");
}
}
-
+
private static Set<Integer> slideIndexes(final int slideCount, String range) {
Set<Integer> slideIdx = new TreeSet<>();
if ("-1".equals(range)) {