diff --git a/build.xml b/build.xml
index cfa95666e..f2d6630f5 100644
--- a/build.xml
+++ b/build.xml
@@ -103,6 +103,12 @@ under the License.
+
+
+
+
+
+
@@ -371,6 +377,7 @@ under the License.
+
@@ -690,7 +697,38 @@ under the License.
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [MS-OSHARED] - 2.2.1.6 FixedPoint
*/
- public static double fixedPointToDecimal(int fixedPoint) {
+ public static double fixedPointToDouble(int fixedPoint) {
int i = (fixedPoint >> 16);
int f = (fixedPoint >> 0) & 0xFFFF;
- double decimal = (i + f/65536.0);
- return decimal;
+ double floatPoint = (i + f/65536d);
+ return floatPoint;
+ }
+
+ /**
+ * Converts a value of type floating point to a FixedPoint
+ *
+ * @param floatPoint
+ * @return fixedPoint
+ *
+ * @see [MS-OSHARED] - 2.2.1.6 FixedPoint
+ */
+ public static int doubleToFixedPoint(double floatPoint) {
+ int i = (int)Math.floor(floatPoint);
+ int f = (int)((floatPoint % 1d)*65536d);
+ int fixedPoint = (i << 16) | (f & 0xFFFF);
+ return fixedPoint;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java b/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java
index d446ccedd..ddb3f0745 100644
--- a/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java
+++ b/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java
@@ -19,8 +19,8 @@
package org.apache.poi.xslf.model;
-import org.apache.poi.xslf.usermodel.XSLFSimpleShape;
import org.apache.poi.util.Internal;
+import org.apache.poi.xslf.usermodel.XSLFShape;
/**
* Used internally to navigate the PresentationML text style hierarchy and fetch properties
@@ -36,7 +36,7 @@ public abstract class PropertyFetcher {
* @param shape the shape being examined
* @return true if the desired property was fetched
*/
- public abstract boolean fetch(XSLFSimpleShape shape) ;
+ public abstract boolean fetch(XSLFShape shape) ;
public T getValue(){
return _value;
diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java
deleted file mode 100644
index 62accc42f..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.apache.poi.xslf.model.geom;
-
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
-import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
-
-import java.io.InputStream;
-import java.util.LinkedHashMap;
-
-/**
- * Date: 10/25/11
- *
- * @author Yegor Kozlov
- */
-public class PresetGeometries extends LinkedHashMap {
- private static PresetGeometries _inst;
-
- private PresetGeometries(){
- try {
- InputStream is =
- XMLSlideShow.class.getResourceAsStream("presetShapeDefinitions.xml");
- read(is);
- } catch (Exception e){
- throw new RuntimeException(e);
- }
- }
-
- private void read(InputStream is) throws Exception {
- XmlObject obj = XmlObject.Factory.parse(is);
- for (XmlObject def : obj.selectPath("*/*")) {
-
- String name = def.getDomNode().getLocalName();
- CTCustomGeometry2D geom = CTCustomGeometry2D.Factory.parse(def.toString());
-
- if(containsKey(name)) {
- System.out.println("Duplicate definoition of " + name) ;
- }
- put(name, new CustomGeometry(geom));
- }
- }
-
- public static PresetGeometries getInstance(){
- if(_inst == null) _inst = new PresetGeometries();
-
- return _inst;
- }
-
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java
deleted file mode 100644
index 71891f841..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.xslf.usermodel;
-
-/**
- * @author Yegor Kozlov
- */
-public enum LineDash {
- SOLID,
- DOT,
- DASH,
- LG_DASH,
- DASH_DOT,
- LG_DASH_DOT,
- LG_DASH_DOT_DOT,
- SYS_DASH,
- SYS_DOT,
- SYS_DASH_DOT,
- SYS_DASH_DOT_DOT;
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java
index 053ccd491..8a11c1cd1 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java
@@ -40,6 +40,8 @@ import java.util.Comparator;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.LineCap;
+import org.apache.poi.sl.usermodel.LineDash;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
deleted file mode 100644
index 2570e6cfc..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-package org.apache.poi.xslf.usermodel;
-
-/**
- * Specified a list of text alignment types
- *
- * @author Yegor Kozlov
- */
-public enum TextAlign {
- /**
- * Align text to the left margin.
- */
- LEFT,
- /**
- * Align text in the center.
- */
- CENTER,
-
- /**
- * Align text to the right margin.
- */
- RIGHT,
-
- /**
- * Align text so that it is justified across the whole line. It
- * is smart in the sense that it will not justify sentences
- * which are short
- */
- JUSTIFY,
- JUSTIFY_LOW,
- DIST,
- THAI_DIST
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java
deleted file mode 100644
index 94d6b2435..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-package org.apache.poi.xslf.usermodel;
-
-/**
- * Specifies alist of auto-fit types.
- *
- * Autofit specofies that a shape should be auto-fit to fully contain the text described within it.
- * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
- *
- *
- * @author Yegor Kozlov
- */
-public enum TextAutofit {
- /**
- * Specifies that text within the text body should not be auto-fit to the bounding box.
- * Auto-fitting is when text within a text box is scaled in order to remain inside
- * the text box.
- */
- NONE,
- /**
- * Specifies that text within the text body should be normally auto-fit to the bounding box.
- * Autofitting is when text within a text box is scaled in order to remain inside the text box.
- *
- *
- * Example: Consider the situation where a user is building a diagram and needs
- * to have the text for each shape that they are using stay within the bounds of the shape.
- * An easy way this might be done is by using NORMAL autofit
- *
- */
- NORMAL,
- /**
- * Specifies that a shape should be auto-fit to fully contain the text described within it.
- * Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
- *
- *
- * Example: Consider the situation where a user is building a diagram and needs to have
- * the text for each shape that they are using stay within the bounds of the shape.
- * An easy way this might be done is by using SHAPE autofit
- *
- */
- SHAPE
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java
deleted file mode 100644
index 3f35ec23a..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-package org.apache.poi.xslf.usermodel;
-
-/**
- * Vertical Text Types
- */
-public enum TextDirection {
- /**
- * Horizontal text. This should be default.
- */
- HORIZONTAL,
- /**
- * Vertical orientation.
- * (each line is 90 degrees rotated clockwise, so it goes
- * from top to bottom; each next line is to the left from
- * the previous one).
- */
- VERTICAL,
- /**
- * Vertical orientation.
- * (each line is 270 degrees rotated clockwise, so it goes
- * from bottom to top; each next line is to the right from
- * the previous one).
- */
- VERTICAL_270,
- /**
- * Determines if all of the text is vertical
- * ("one letter on top of another").
- */
- STACKED;
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java
deleted file mode 100644
index 1114b8944..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.apache.poi.xslf.usermodel;
-
-import java.awt.*;
-import java.awt.font.TextLayout;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.text.CharacterIterator;
-
-/**
- * a renderable text fragment
-*/
-class TextFragment {
- final TextLayout _layout;
- final AttributedString _str;
-
- TextFragment(TextLayout layout, AttributedString str){
- _layout = layout;
- _str = str;
- }
-
- void draw(Graphics2D graphics, double x, double y){
- if(_str == null) {
- return;
- }
-
- double yBaseline = y + _layout.getAscent();
-
- Integer textMode = (Integer)graphics.getRenderingHint(XSLFRenderingHint.TEXT_RENDERING_MODE);
- if(textMode != null && textMode == XSLFRenderingHint.TEXT_AS_SHAPES){
- _layout.draw(graphics, (float)x, (float)yBaseline);
- } else {
- graphics.drawString(_str.getIterator(), (float)x, (float)yBaseline );
- }
- }
-
- /**
- * @return full height of this text run which is sum of ascent, descent and leading
- */
- public float getHeight(){
- double h = Math.ceil(_layout.getAscent()) + Math.ceil(_layout.getDescent()) + _layout.getLeading();
- return (float)h;
- }
-
- /**
- *
- * @return width if this text run
- */
- public float getWidth(){
- return _layout.getAdvance();
- }
-
- /**
- *
- * @return the string to be painted
- */
- public String getString(){
- if(_str == null) return "";
-
- AttributedCharacterIterator it = _str.getIterator();
- StringBuffer buf = new StringBuffer();
- for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
- buf.append(c);
- }
- return buf.toString();
- }
-
- @Override
- public String toString(){
- return "[" + getClass().getSimpleName() + "] " + getString();
- }
-}
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 b1c6be457..1c5f855db 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -20,7 +20,11 @@ import java.awt.Dimension;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
import org.apache.poi.POIXMLDocument;
@@ -32,6 +36,9 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Resources;
+import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -53,6 +60,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+import com.sun.org.apache.xml.internal.utils.UnImplNode;
+
/**
* High level representation of a ooxml slideshow.
* This is the first object most users will construct whether
@@ -60,7 +71,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument
* top level object for creating new slides/etc.
*/
@Beta
-public class XMLSlideShow extends POIXMLDocument {
+public class XMLSlideShow extends POIXMLDocument implements SlideShow {
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
private CTPresentation _presentation;
@@ -437,7 +448,7 @@ public class XMLSlideShow extends POIXMLDocument {
*/
public int addPicture(byte[] pictureData, int format) {
XSLFPictureData img = findPictureData(pictureData);
- POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format];
+ // POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format];
if(img == null) {
int imageNumber = _pictures.size();
@@ -485,4 +496,17 @@ public class XMLSlideShow extends POIXMLDocument {
return null;
}
+ public MasterSheet[] getMasterSheet() {
+ return getSlideMasters();
+ }
+
+ public MasterSheet createMasterSheet() throws IOException {
+ // TODO: implement!
+ throw new UnsupportedOperationException();
+ }
+
+ public Resources getResources() {
+ // TODO: implement!
+ throw new UnsupportedOperationException();
+ }
}
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 1ee8f6f55..47bcace2f 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
@@ -19,6 +19,7 @@
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.AutoShape;
import org.apache.poi.util.Beta;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
@@ -35,7 +36,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
* @author Yegor Kozlov
*/
@Beta
-public class XSLFAutoShape extends XSLFTextShape {
+public class XSLFAutoShape extends XSLFTextShape implements AutoShape {
/*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
super(shape, sheet);
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
index 604c9dff3..80c6a1acb 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
@@ -17,25 +17,20 @@
package org.apache.poi.xslf.usermodel;
-import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Paint;
+import java.awt.*;
import java.awt.geom.Rectangle2D;
+import org.apache.poi.sl.usermodel.Background;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
+
/**
* Background shape
*
* @author Yegor Kozlov
*/
-public class XSLFBackground extends XSLFSimpleShape {
+public class XSLFBackground extends XSLFSimpleShape implements Background {
/* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
super(shape, sheet);
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 c0f4762c7..527cef781 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
@@ -18,22 +18,18 @@
*/
package org.apache.poi.xslf.usermodel;
-import org.apache.poi.util.Beta;
-import org.apache.poi.util.Internal;
-import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
-import org.w3c.dom.Node;
-
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
+import org.apache.poi.sl.draw.DrawPaint;
+import org.apache.poi.sl.usermodel.ColorStyle;
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.w3c.dom.Node;
+
/**
* Encapsulates logic to read color definitions from DrawingML and convert them to java.awt.Color
*
@@ -63,40 +59,37 @@ public class XSLFColor {
* If not color information was found in the supplied xml object then a null is returned.
*/
public Color getColor() {
- return _color == null ? null : applyColorTransform(_color);
+ return DrawPaint.applyColorTransform(getColorStyle());
}
- private Color applyColorTransform(Color color){
- Color result = color;
+ public ColorStyle getColorStyle() {
+ return new ColorStyle() {
+ public Color getColor() {
+ return _color;
+ }
- int alpha = getAlpha();
- if(alpha != -1){
- result = new Color(
- result.getRed(), result.getGreen(), result.getBlue(),
- Math.round(255 * alpha * 0.01f));
- }
+ public int getAlpha() {
+ return getRawValue("alpha");
+ }
- int lumOff = getLumOff();
- int lumMod = getLumMod();
- if(lumMod != -1 || lumOff != -1){
- result = modulateLuminanace(result,
- lumMod == -1 ? 100 : lumMod,
- lumOff == -1 ? 0 : lumOff);
- }
+ public int getLumOff() {
+ return getRawValue("lumOff");
+ }
- int shade = getShade();
- if(shade != -1){
- result = shade(result, shade);
- }
+ public int getLumMod() {
+ return getRawValue("lumMod");
+ }
- int tint = getTint();
- if(tint != -1){
- result = tint(result, tint);
- }
+ public int getShade() {
+ return getRawValue("shade");
+ }
- return result;
+ public int getTint() {
+ return getRawValue("tint");
+ }
+ };
}
-
+
Color toColor(XmlObject obj, XSLFTheme theme) {
Color color = null;
for (XmlObject ch : obj.selectPath("*")) {
@@ -140,6 +133,7 @@ public class XSLFColor {
color = new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
} else {
// YK: color is a string like "menuText" or "windowText", we return black for such cases
+ @SuppressWarnings("unused")
String colorName = sys.getVal().toString();
color = Color.black;
}
@@ -150,6 +144,33 @@ public class XSLFColor {
return color;
}
+ private int getRawValue(String elem) {
+ String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
+
+ XmlObject[] obj;
+
+ // first ask the context color and if not found, ask the actual color bean
+ if (_phClr != null){
+ obj = _phClr.selectPath(query);
+ if (obj.length == 1){
+ Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
+ if(attr != null) {
+ return Integer.parseInt(attr.getNodeValue());
+ }
+ }
+ }
+
+ obj = _xmlObject.selectPath(query);
+ if (obj.length == 1){
+ Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
+ if(attr != null) {
+ return Integer.parseInt(attr.getNodeValue());
+ }
+ }
+
+ return -1;
+ }
+
/**
* Read a perecentage value from the supplied xml bean.
* Example:
@@ -160,56 +181,13 @@ public class XSLFColor {
* @return the percentage value in the range [0 .. 100]
*/
private int getPercentageValue(String elem){
- String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
-
- XmlObject[] obj;
-
- // first ask the context color and if not found, ask the actual color bean
- if(_phClr != null){
- obj = _phClr.selectPath(query);
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 1000;
- }
- }
- }
-
- obj = _xmlObject.selectPath(query);
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 1000;
- }
- }
-
-
- return -1;
+ int val = getRawValue(elem);
+ return (val == -1) ? val : (val / 1000);
}
private int getAngleValue(String elem){
- String color = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
- XmlObject[] obj;
-
- // first ask the context color and if not found, ask the actual color bean
- if(_phClr != null){
- obj = _xmlObject.selectPath( color );
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 60000;
- }
- }
- }
-
- obj = _xmlObject.selectPath( color );
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 60000;
- }
- }
- return -1;
+ int val = getRawValue(elem);
+ return (val == -1) ? val : (val / 60000);
}
/**
@@ -387,7 +365,7 @@ public class XSLFColor {
* percentage with 0% indicating minimal shade and 100% indicating maximum
* or -1 if the value is not set
*/
- int getShade(){
+ public int getShade(){
return getPercentageValue("shade");
}
@@ -399,69 +377,11 @@ public class XSLFColor {
* percentage with 0% indicating minimal tint and 100% indicating maximum
* or -1 if the value is not set
*/
- int getTint(){
+ public int getTint(){
return getPercentageValue("tint");
}
- /**
- * Apply lumMod / lumOff adjustments
- *
- * @param c the color to modify
- * @param lumMod luminance modulation in the range [0..100]
- * @param lumOff luminance offset in the range [0..100]
- * @return modified color
- */
- private static Color modulateLuminanace(Color c, int lumMod, int lumOff) {
- Color color;
- if (lumOff > 0) {
- color = new Color(
- (int) (Math.round((255 - c.getRed()) * (100.0 - lumMod) / 100.0 + c.getRed())),
- (int) (Math.round((255 - c.getGreen()) * lumOff / 100.0 + c.getGreen())),
- (int) (Math.round((255 - c.getBlue()) * lumOff / 100.0 + c.getBlue())),
- c.getAlpha()
- );
- } else {
- color = new Color(
- (int) (Math.round(c.getRed() * lumMod / 100.0)),
- (int) (Math.round(c.getGreen() * lumMod / 100.0)),
- (int) (Math.round(c.getBlue() * lumMod / 100.0)),
- c.getAlpha()
- );
- }
- return color;
- }
-
- /**
- * This algorithm returns result different from PowerPoint.
- * TODO: revisit and improve
- */
- private static Color shade(Color c, int shade) {
- return new Color(
- (int)(c.getRed() * shade * 0.01),
- (int)(c.getGreen() * shade * 0.01),
- (int)(c.getBlue() * shade * 0.01),
- c.getAlpha());
- }
-
- /**
- * This algorithm returns result different from PowerPoint.
- * TODO: revisit and improve
- */
- private static Color tint(Color c, int tint) {
- int r = c.getRed();
- int g = c.getGreen();
- int b = c.getBlue();
-
- float ftint = tint / 100.0f;
-
- int red = Math.round(ftint * r + (1 - ftint) * 255);
- int green = Math.round(ftint * g + (1 - ftint) * 255);
- int blue = Math.round(ftint * b + (1 - ftint) * 255);
-
- return new Color(red, green, blue);
- }
-
/**
* Preset colors defined in DrawingML
*/
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
index 529bacf73..514c1bc90 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
@@ -23,6 +23,7 @@ import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
@@ -34,6 +35,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
import javax.xml.namespace.QName;
+
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
@@ -58,8 +60,8 @@ public class XSLFGraphicFrame extends XSLFShape {
return _sheet;
}
- public int getShapeType(){
- throw new RuntimeException("NotImplemented");
+ public ShapeType getShapeType(){
+ throw new UnsupportedOperationException();
}
public int getShapeId(){
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
index 2ad699b40..f93fc803f 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
@@ -19,9 +19,17 @@
package org.apache.poi.xslf.usermodel;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlObject;
@@ -35,13 +43,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Pattern;
-
/**
* Represents a group shape that consists of many shapes grouped together.
*
@@ -207,30 +208,35 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer {
public XSLFAutoShape createAutoShape(){
XSLFAutoShape sh = getDrawing().createAutoShape();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFFreeformShape createFreeform(){
XSLFFreeformShape sh = getDrawing().createFreeform();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFTextBox createTextBox(){
XSLFTextBox sh = getDrawing().createTextBox();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFConnectorShape createConnector(){
XSLFConnectorShape sh = getDrawing().createConnector();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFGroupShape createGroup(){
XSLFGroupShape sh = getDrawing().createGroup();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -251,6 +257,7 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer {
XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
sh.resize();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -343,4 +350,13 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer {
}
}
+ public ShapeType getShapeType(){
+ return null;
+ }
+
+ public void addShape(XSLFShape shape) {
+ throw new UnsupportedOperationException(
+ "Adding a shape from a different container is not supported -"
+ + " create it from scratch witht XSLFGroupShape.create* methods");
+ }
}
\ No newline at end of file
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 0a33132e2..62f9cc4ad 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.Notes;
+import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
@@ -28,7 +30,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
@Beta
-public final class XSLFNotes extends XSLFSheet {
+public final class XSLFNotes extends XSLFSheet implements Notes {
private CTNotesSlide _notes;
/**
@@ -80,7 +82,6 @@ public final class XSLFNotes extends XSLFSheet {
return getMasterSheet().getTheme();
}
- @Override
public XSLFNotesMaster getMasterSheet() {
for (POIXMLDocumentPart p : getRelations()) {
if (p instanceof XSLFNotesMaster){
@@ -89,4 +90,20 @@ public final class XSLFNotes extends XSLFSheet {
}
return null;
}
+
+ public TextRun getTextRun() {
+ for (XSLFShape sh : super.getShapes()) {
+ if (sh instanceof XSLFTextShape) {
+ XSLFTextShape txt = (XSLFTextShape)sh;
+ for (XSLFTextParagraph p : txt.getTextParagraphs()) {
+ for (XSLFTextRun r : p.getTextRuns()) {
+ return r;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
index 40937e878..c5de53767 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
@@ -23,6 +23,7 @@ import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.drawingml.x2006.main.CTColorMapping;
@@ -46,7 +47,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
* @author Yegor Kozlov
*/
@Beta
- public class XSLFNotesMaster extends XSLFSheet {
+ public class XSLFNotesMaster extends XSLFSheet implements MasterSheet {
private CTNotesMaster _slide;
private XSLFTheme _theme;
@@ -93,7 +94,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
}
@Override
- public XSLFSheet getMasterSheet() {
+ public MasterSheet getMasterSheet() {
return null;
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
index 42dc360cd..fa4b192ec 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
@@ -17,6 +17,7 @@
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.Shadow;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
@@ -31,7 +32,7 @@ import java.awt.geom.Rectangle2D;
*
* @author Yegor Kozlov
*/
-public class XSLFShadow extends XSLFSimpleShape {
+public class XSLFShadow extends XSLFSimpleShape implements Shadow {
private XSLFSimpleShape _parent;
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 82addf7dd..aa6e2c712 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
@@ -19,13 +19,25 @@
package org.apache.poi.xslf.usermodel;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
+import java.awt.Color;
import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Comparator;
-import org.apache.poi.util.Beta;
-import org.apache.poi.util.Internal;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.draw.DrawPaint;
+import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.util.*;
+import org.apache.poi.xslf.model.PropertyFetcher;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
+import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
/**
* Base super-class class for all shapes in PresentationML
@@ -33,25 +45,43 @@ import org.apache.xmlbeans.XmlObject;
* @author Yegor Kozlov
*/
@Beta
-public abstract class XSLFShape {
+public abstract class XSLFShape implements Shape {
+ protected final XmlObject _shape;
+ protected final XSLFSheet _sheet;
+ protected XSLFShapeContainer _parent;
- /**
- * @return the position of this shape within the drawing canvas.
- * The coordinates are expressed in points
- */
- public abstract Rectangle2D getAnchor();
+ private CTShapeProperties _spPr;
+ private CTShapeStyle _spStyle;
+ private CTNonVisualDrawingProps _nvPr;
+ private CTPlaceholder _ph;
- /**
- * @param anchor the position of this shape within the drawing canvas.
- * The coordinates are expressed in points
- */
- public abstract void setAnchor(Rectangle2D anchor);
+ private static final PaintStyle TRANSPARENT_PAINT = new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return new ColorStyle(){
+ public Color getColor() { return DrawPaint.NO_PAINT; }
+ public int getAlpha() { return -1; }
+ public int getLumOff() { return -1; }
+ public int getLumMod() { return -1; }
+ public int getShade() { return -1; }
+ public int getTint() { return -1; }
+ };
+ }
+ };
+
+
+ protected XSLFShape(XmlObject shape, XSLFSheet sheet) {
+ _shape = shape;
+ _sheet = sheet;
+ }
+
/**
* @return the xml bean holding this shape's data
*/
- public abstract XmlObject getXmlObject();
-
+ public XmlObject getXmlObject() {
+ return _shape;
+ }
+
/**
* @return human-readable name of this shape, e.g. "Rectange 3"
*/
@@ -118,84 +148,6 @@ public abstract class XSLFShape {
*/
public abstract boolean getFlipVertical();
- /**
- * Draw this shape into the supplied canvas
- *
- * @param graphics the graphics to draw into
- */
- public abstract void draw(Graphics2D graphics);
-
- /**
- * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
- *
- * @param graphics the graphics whos transform matrix will be modified
- */
- protected void applyTransform(Graphics2D graphics) {
- Rectangle2D anchor = getAnchor();
- AffineTransform tx = (AffineTransform)graphics.getRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM);
- if(tx != null) {
- anchor = tx.createTransformedShape(anchor).getBounds2D();
- }
-
- // rotation
- double rotation = getRotation();
- if (rotation != 0.) {
- // PowerPoint rotates shapes relative to the geometric center
- double centerX = anchor.getCenterX();
- double centerY = anchor.getCenterY();
-
- // normalize rotation
- rotation = (360.+(rotation%360.))%360.;
- int quadrant = (((int)rotation+45)/90)%4;
- double scaleX = 1.0, scaleY = 1.0;
-
- // scale to bounding box (bug #53176)
- if (quadrant == 1 || quadrant == 3) {
- // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation
- // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple
- // of 90 degrees and then resize the bounding box to its original bbox. After that we can
- // rotate the shape to the exact rotation amount.
- // It's strange that you'll need to rotate the shape back and forth again, but you can
- // think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might
- // be already (differently) scaled, so you can paint the shape in its default orientation
- // and later on, turn it around again to compare it with its original size ...
- AffineTransform txg = new AffineTransform(); // graphics coordinate space
- AffineTransform txs = new AffineTransform(tx); // shape coordinate space
- txg.translate(centerX, centerY);
- txg.rotate(Math.toRadians(quadrant*90));
- txg.translate(-centerX, -centerY);
- txs.translate(centerX, centerY);
- txs.rotate(Math.toRadians(-quadrant*90));
- txs.translate(-centerX, -centerY);
- txg.concatenate(txs);
- Rectangle2D anchor2 = txg.createTransformedShape(getAnchor()).getBounds2D();
- scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth();
- scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();
- }
-
- // transformation is applied reversed ...
- graphics.translate(centerX, centerY);
- graphics.rotate(Math.toRadians(rotation-(double)(quadrant*90)));
- graphics.scale(scaleX, scaleY);
- graphics.rotate(Math.toRadians(quadrant*90));
- graphics.translate(-centerX, -centerY);
- }
-
- //flip horizontal
- if (getFlipHorizontal()) {
- graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
- graphics.scale(-1, 1);
- graphics.translate(-anchor.getX(), -anchor.getY());
- }
-
- //flip vertical
- if (getFlipVertical()) {
- graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
- graphics.scale(1, -1);
- graphics.translate(-anchor.getX(), -anchor.getY());
- }
- }
-
/**
* Set the contents of this shape to be a copy of the source shape.
* This method is called recursively for each shape when merging slides
@@ -212,4 +164,402 @@ public abstract class XSLFShape {
setAnchor(sh.getAnchor());
}
+
+ public void setParent(XSLFShapeContainer parent) {
+ this._parent = parent;
+ }
+
+ public XSLFShapeContainer getParent() {
+ return this._parent;
+ }
+
+ public boolean isPlaceholder() {
+ return false;
+ }
+
+ public StrokeStyle getStrokeStyle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CustomGeometry getGeometry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ShapeType getShapeType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public XSLFSheet getSheet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * fetch shape fill as a java.awt.Paint
+ *
+ * @return either Color or GradientPaint or TexturePaint or null
+ */
+ @Override
+ public FillStyle getFillStyle() {
+ return new FillStyle() {
+ public PaintStyle getPaint() {
+ PropertyFetcher fetcher = new PropertyFetcher() {
+ public boolean fetch(XSLFShape shape) {
+ CTShapeProperties spPr = shape.getSpPr();
+ if (spPr.isSetNoFill()) {
+ setValue(TRANSPARENT_PAINT);
+ return true;
+ }
+
+ PaintStyle paint = null;
+ for (XmlObject obj : spPr.selectPath("*")) {
+ paint = selectPaint(obj, null, getSheet().getPackagePart());
+ if (paint != null) break;
+ }
+
+ if (paint == null) return false;
+
+ setValue(paint);
+ return true;
+ }
+ };
+ fetchShapeProperty(fetcher);
+
+ PaintStyle paint = fetcher.getValue();
+
+ if (paint != null) return paint;
+
+ // fill color was not found, check if it is defined in the theme
+ CTShapeStyle style = getSpStyle();
+ if (style != null) {
+ // get a reference to a fill style within the style matrix.
+ CTStyleMatrixReference fillRef = style.getFillRef();
+ // 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,
+ // values 1-999 refer to the index of a fill style within the fillStyleLst element
+ // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
+ int idx = (int)fillRef.getIdx();
+ CTSchemeColor phClr = fillRef.getSchemeClr();
+ XSLFSheet sheet = _sheet;
+ XSLFTheme theme = sheet.getTheme();
+ XmlObject fillProps = null;
+ CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
+ if(idx >= 1 && idx <= 999){
+ fillProps = matrix.getFillStyleLst().selectPath("*")[idx - 1];
+ } else if (idx >= 1001 ){
+ fillProps = matrix.getBgFillStyleLst().selectPath("*")[idx - 1001];
+ }
+ if(fillProps != null) {
+ paint = selectPaint(fillProps, phClr, sheet.getPackagePart());
+ }
+ }
+ return paint == RenderableShape.NO_PAINT ? null : paint;
+ }
+ };
+ }
+
+ /**
+ * Walk up the inheritance tree and fetch shape properties.
+ *
+ * The following order of inheritance is assumed:
+ *
+ * slide <-- slideLayout <-- slideMaster
+ *
+ *
+ * @param visitor the object that collects the desired property
+ * @return true if the property was fetched
+ */
+ protected boolean fetchShapeProperty(PropertyFetcher> visitor) {
+ boolean ok = visitor.fetch(this);
+
+ XSLFSimpleShape masterShape;
+ XSLFSheet masterSheet = (XSLFSheet)getSheet().getMasterSheet();
+ CTPlaceholder ph = getCTPlaceholder();
+
+ if (masterSheet != null && ph != null) {
+ if (!ok) {
+ masterShape = masterSheet.getPlaceholder(ph);
+ if (masterShape != null) {
+ ok = visitor.fetch(masterShape);
+ }
+ }
+
+ // try slide master
+ if (!ok ) {
+ int textType;
+ if ( !ph.isSetType()) textType = STPlaceholderType.INT_BODY;
+ else {
+ switch (ph.getType().intValue()) {
+ case STPlaceholderType.INT_TITLE:
+ case STPlaceholderType.INT_CTR_TITLE:
+ textType = STPlaceholderType.INT_TITLE;
+ break;
+ case STPlaceholderType.INT_FTR:
+ case STPlaceholderType.INT_SLD_NUM:
+ case STPlaceholderType.INT_DT:
+ textType = ph.getType().intValue();
+ break;
+ default:
+ textType = STPlaceholderType.INT_BODY;
+ break;
+ }
+ }
+ XSLFSheet master = (XSLFSheet)masterSheet.getMasterSheet();
+ if (master != null) {
+ masterShape = master.getPlaceholderByType(textType);
+ if (masterShape != null) {
+ ok = visitor.fetch(masterShape);
+ }
+ }
+ }
+ }
+ return ok;
+ }
+
+ protected CTPlaceholder getCTPlaceholder() {
+ if (_ph == null) {
+ XmlObject[] obj = _shape.selectPath(
+ "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:nvPr/p:ph");
+ if (obj.length == 1) {
+ _ph = (CTPlaceholder) obj[0];
+ }
+ }
+ return _ph;
+ }
+
+ protected CTShapeStyle getSpStyle() {
+ if (_spStyle == null) {
+ for (XmlObject obj : _shape.selectPath("*")) {
+ if (obj instanceof CTShapeStyle) {
+ _spStyle = (CTShapeStyle) obj;
+ }
+ }
+ }
+ return _spStyle;
+ }
+
+ protected CTNonVisualDrawingProps getNvPr() {
+ if (_nvPr == null) {
+ XmlObject[] rs = _shape
+ .selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
+ if (rs.length != 0) {
+ _nvPr = (CTNonVisualDrawingProps) rs[0];
+ }
+ }
+ return _nvPr;
+ }
+
+ protected CTShapeProperties getSpPr() {
+ if (_spPr == null) {
+ for (XmlObject obj : _shape.selectPath("*")) {
+ if (obj instanceof CTShapeProperties) {
+ _spPr = (CTShapeProperties) obj;
+ }
+ }
+ }
+ if (_spPr == null) {
+ throw new IllegalStateException("CTShapeProperties was not found.");
+ }
+ return _spPr;
+ }
+
+ CTTransform2D getXfrm() {
+ PropertyFetcher fetcher = new PropertyFetcher() {
+ public boolean fetch(XSLFShape shape) {
+ CTShapeProperties pr = shape.getSpPr();
+ if (pr.isSetXfrm()) {
+ setValue(pr.getXfrm());
+ return true;
+ }
+ return false;
+ }
+ };
+ fetchShapeProperty(fetcher);
+ return fetcher.getValue();
+ }
+
+ /**
+ * @return the position of this shape within the drawing canvas.
+ * The coordinates are expressed in points
+ */
+ public Rectangle2D getAnchor() {
+ CTTransform2D xfrm = getXfrm();
+ if (xfrm == null) return null;
+
+ CTPoint2D off = xfrm.getOff();
+ long x = off.getX();
+ long y = off.getY();
+ CTPositiveSize2D ext = xfrm.getExt();
+ long cx = ext.getCx();
+ long cy = ext.getCy();
+ return new Rectangle2D.Double(
+ Units.toPoints(x), Units.toPoints(y),
+ Units.toPoints(cx), Units.toPoints(cy));
+ }
+
+ /**
+ * @param anchor the position of this shape within the drawing canvas.
+ * The coordinates are expressed in points
+ */
+ public void setAnchor(Rectangle2D anchor) {
+ CTShapeProperties spPr = getSpPr();
+ if (spPr == null) return;
+
+ CTTransform2D xfrm = spPr.isSetXfrm() ? spPr.getXfrm() : spPr.addNewXfrm();
+ CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
+ long x = Units.toEMU(anchor.getX());
+ long y = Units.toEMU(anchor.getY());
+ off.setX(x);
+ off.setY(y);
+ CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm
+ .addNewExt();
+ long cx = Units.toEMU(anchor.getWidth());
+ long cy = Units.toEMU(anchor.getHeight());
+ ext.setCx(cx);
+ ext.setCy(cy);
+ }
+
+ /**
+ * Convert shape fill into java.awt.Paint. The result is either Color or
+ * TexturePaint or GradientPaint or null
+ *
+ * @param graphics the target graphics
+ * @param obj the xml to read. Must contain elements from the EG_ColorChoice group:
+ *
+ * a:scrgbClr RGB Color Model - Percentage Variant
+ * a:srgbClr RGB Color Model - Hex Variant
+ * a:hslClr Hue, Saturation, Luminance Color Model
+ * a:sysClr System Color
+ * a:schemeClr Scheme Color
+ * a:prstClr Preset Color
+ *
+ *
+ * @param phClr context color
+ * @param parentPart the parent package part. Any external references (images, etc.) are resolved relative to it.
+ *
+ * @return the applied Paint or null if none was applied
+ */
+ protected PaintStyle selectPaint(XmlObject obj, final CTSchemeColor phClr, final PackagePart parentPart) {
+ final XSLFTheme theme = getSheet().getTheme();
+
+ if (obj instanceof CTNoFillProperties) {
+ return TRANSPARENT_PAINT;
+ }
+
+ if (obj instanceof CTSolidColorFillProperties) {
+ CTSolidColorFillProperties solidFill = (CTSolidColorFillProperties) obj;
+ final XSLFColor c = new XSLFColor(solidFill, theme, phClr);
+ return new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return c.getColorStyle();
+ }
+ };
+ }
+
+ if (obj instanceof CTBlipFillProperties) {
+ CTBlipFillProperties blipFill = (CTBlipFillProperties)obj;
+ final CTBlip blip = blipFill.getBlip();
+ return new TexturePaint() {
+ private PackagePart getPart() {
+ try {
+ String blipId = blip.getEmbed();
+ PackageRelationship rel = parentPart.getRelationship(blipId);
+ return parentPart.getRelatedPart(rel);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public InputStream getImageData() {
+ try {
+ return getPart().getInputStream();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getContentType() {
+ /* TOOD: map content-type */
+ return getPart().getContentType();
+ }
+
+ public int getAlpha() {
+ return (blip.sizeOfAlphaModFixArray() > 0)
+ ? blip.getAlphaModFixArray(0).getAmt()
+ : 0;
+ }
+ };
+ }
+
+ if (obj instanceof CTGradientFillProperties) {
+ final CTGradientFillProperties gradFill = (CTGradientFillProperties) obj;
+
+ @SuppressWarnings("deprecation")
+ final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
+
+ Arrays.sort(gs, new Comparator() {
+ public int compare(CTGradientStop o1, CTGradientStop o2) {
+ Integer pos1 = o1.getPos();
+ Integer pos2 = o2.getPos();
+ return pos1.compareTo(pos2);
+ }
+ });
+
+ final ColorStyle cs[] = new ColorStyle[gs.length];
+ final float fractions[] = new float[gs.length];
+
+ int i=0;
+ for (CTGradientStop cgs : gs) {
+ cs[i] = new XSLFColor(cgs, theme, phClr).getColorStyle();
+ fractions[i] = cgs.getPos() / 100000.f;
+ }
+
+ return new GradientPaint() {
+
+ public double getGradientAngle() {
+ return (gradFill.isSetLin())
+ ? gradFill.getLin().getAng() / 60000.d
+ : 0;
+ }
+
+ public ColorStyle[] getGradientColors() {
+ return cs;
+ }
+
+ public float[] getGradientFractions() {
+ return fractions;
+ }
+
+ public boolean isRotatedWithShape() {
+ // TODO: is this correct???
+ return (gradFill.isSetRotWithShape() || !gradFill.getRotWithShape());
+ }
+
+ public GradientType getGradientType() {
+ if (gradFill.isSetLin()) {
+ return GradientType.linear;
+ }
+
+ if (gradFill.isSetPath()) {
+ /* TODO: handle rect path */
+ STPathShadeType.Enum ps = gradFill.getPath().getPath();
+ if (ps == STPathShadeType.CIRCLE) {
+ return GradientType.circular;
+ } else if (ps == STPathShadeType.SHAPE) {
+ return GradientType.shape;
+ }
+ }
+
+ return GradientType.linear;
+ }
+ };
+ }
+
+ return TRANSPARENT_PAINT;
+ }
+
}
\ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java
index 3a2089184..d839a49d3 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java
@@ -19,10 +19,12 @@
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+
/**
* Common interface for shape containers, e.g. sheets or groups of shapes
*/
-public interface XSLFShapeContainer extends Iterable {
+public interface XSLFShapeContainer extends ShapeContainer {
/**
* create a new shape with a predefined geometry and add it to this shape container
@@ -55,27 +57,6 @@ public interface XSLFShapeContainer extends Iterable {
*/
XSLFPictureShape createPicture(int pictureIndex);
- /**
- * Returns an array containing all of the elements in this container in proper
- * sequence (from first to last element).
- *
- * @return an array containing all of the elements in this container in proper
- * sequence
- */
- XSLFShape[] getShapes();
-
- /**
- * Removes the specified shape from this sheet, if it is present
- * (optional operation). If this sheet does not contain the element,
- * it is unchanged.
- *
- * @param xShape shape to be removed from this sheet, if present
- * @return true if this sheet contained the specified element
- * @throws IllegalArgumentException if the type of the specified shape
- * is incompatible with this sheet (optional)
- */
- boolean removeShape(XSLFShape xShape) ;
-
/**
* Removes all of the elements from this container (optional operation).
* The container will be empty after this call returns.
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java
deleted file mode 100644
index 57163ff74..000000000
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.apache.poi.xslf.usermodel;
-
-/**
- * known preset shape geometries in PresentationML
- *
- * @author Yegor Kozlov
- */
-public enum XSLFShapeType {
- LINE(1),
- LINE_INV(2),
- TRIANGLE(3),
- RT_TRIANGLE(4),
- RECT(5),
- DIAMOND(6),
- PARALLELOGRAM(7),
- TRAPEZOID(8),
- NON_ISOSCELES_TRAPEZOID(9),
- PENTAGON(10),
- HEXAGON(11),
- HEPTAGON(12),
- OCTAGON(13),
- DECAGON(14),
- DODECAGON(15),
- STAR_4(16),
- STAR_5(17),
- STAR_6(18),
- STAR_7(19),
- STAR_8(20),
- STAR_10(21),
- STAR_12(22),
- STAR_16(23),
- STAR_24(24),
- STAR_32(25),
- ROUND_RECT(26),
- ROUND_1_RECT(27),
- ROUND_2_SAME_RECT(28),
- ROUND_2_DIAG_RECT(29),
- SNIP_ROUND_RECT(30),
- SNIP_1_RECT(31),
- SNIP_2_SAME_RECT(32),
- SNIP_2_DIAG_RECT(33),
- PLAQUE(34),
- ELLIPSE(35),
- TEARDROP(36),
- HOME_PLATE(37),
- CHEVRON(38),
- PIE_WEDGE(39),
- PIE(40),
- BLOCK_ARC(41),
- DONUT(42),
- NO_SMOKING(43),
- RIGHT_ARROW(44),
- LEFT_ARROW(45),
- UP_ARROW(46),
- DOWN_ARROW(47),
- STRIPED_RIGHT_ARROW(48),
- NOTCHED_RIGHT_ARROW(49),
- BENT_UP_ARROW(50),
- LEFT_RIGHT_ARROW(51),
- UP_DOWN_ARROW(52),
- LEFT_UP_ARROW(53),
- LEFT_RIGHT_UP_ARROW(54),
- QUAD_ARROW(55),
- LEFT_ARROW_CALLOUT(56),
- RIGHT_ARROW_CALLOUT(57),
- UP_ARROW_CALLOUT(58),
- DOWN_ARROW_CALLOUT(59),
- LEFT_RIGHT_ARROW_CALLOUT(60),
- UP_DOWN_ARROW_CALLOUT(61),
- QUAD_ARROW_CALLOUT(62),
- BENT_ARROW(63),
- UTURN_ARROW(64),
- CIRCULAR_ARROW(65),
- LEFT_CIRCULAR_ARROW(66),
- LEFT_RIGHT_CIRCULAR_ARROW(67),
- CURVED_RIGHT_ARROW(68),
- CURVED_LEFT_ARROW(69),
- CURVED_UP_ARROW(70),
- CURVED_DOWN_ARROW(71),
- SWOOSH_ARROW(72),
- CUBE(73),
- CAN(74),
- LIGHTNING_BOLT(75),
- HEART(76),
- SUN(77),
- MOON(78),
- SMILEY_FACE(79),
- IRREGULAR_SEAL_1(80),
- IRREGULAR_SEAL_2(81),
- FOLDED_CORNER(82),
- BEVEL(83),
- FRAME(84),
- HALF_FRAME(85),
- CORNER(86),
- DIAG_STRIPE(87),
- CHORD(88),
- ARC(89),
- LEFT_BRACKET(90),
- RIGHT_BRACKET(91),
- LEFT_BRACE(92),
- RIGHT_BRACE(93),
- BRACKET_PAIR(94),
- BRACE_PAIR(95),
- STRAIGHT_CONNECTOR_1(96),
- BENT_CONNECTOR_2(97),
- BENT_CONNECTOR_3(98),
- BENT_CONNECTOR_4(99),
- BENT_CONNECTOR_5(100),
- CURVED_CONNECTOR_2(101),
- CURVED_CONNECTOR_3(102),
- CURVED_CONNECTOR_4(103),
- CURVED_CONNECTOR_5(104),
- CALLOUT_1(105),
- CALLOUT_2(106),
- CALLOUT_3(107),
- ACCENT_CALLOUT_1(108),
- ACCENT_CALLOUT_2(109),
- ACCENT_CALLOUT_3(110),
- BORDER_CALLOUT_1(111),
- BORDER_CALLOUT_2(112),
- BORDER_CALLOUT_3(113),
- ACCENT_BORDER_CALLOUT_1(114),
- ACCENT_BORDER_CALLOUT_2(115),
- ACCENT_BORDER_CALLOUT_3(116),
- WEDGE_RECT_CALLOUT(117),
- WEDGE_ROUND_RECT_CALLOUT(118),
- WEDGE_ELLIPSE_CALLOUT(119),
- CLOUD_CALLOUT(120),
- CLOUD(121),
- RIBBON(122),
- RIBBON_2(123),
- ELLIPSE_RIBBON(124),
- ELLIPSE_RIBBON_2(125),
- LEFT_RIGHT_RIBBON(126),
- VERTICAL_SCROLL(127),
- HORIZONTAL_SCROLL(128),
- WAVE(129),
- DOUBLE_WAVE(130),
- PLUS(131),
- FLOW_CHART_PROCESS(132),
- FLOW_CHART_DECISION(133),
- FLOW_CHART_INPUT_OUTPUT(134),
- FLOW_CHART_PREDEFINED_PROCESS(135),
- FLOW_CHART_INTERNAL_STORAGE(136),
- FLOW_CHART_DOCUMENT(137),
- FLOW_CHART_MULTIDOCUMENT(138),
- FLOW_CHART_TERMINATOR(139),
- FLOW_CHART_PREPARATION(140),
- FLOW_CHART_MANUAL_INPUT(141),
- FLOW_CHART_MANUAL_OPERATION(142),
- FLOW_CHART_CONNECTOR(143),
- FLOW_CHART_PUNCHED_CARD(144),
- FLOW_CHART_PUNCHED_TAPE(145),
- FLOW_CHART_SUMMING_JUNCTION(146),
- FLOW_CHART_OR(147),
- FLOW_CHART_COLLATE(148),
- FLOW_CHART_SORT(149),
- FLOW_CHART_EXTRACT(150),
- FLOW_CHART_MERGE(151),
- FLOW_CHART_OFFLINE_STORAGE(152),
- FLOW_CHART_ONLINE_STORAGE(153),
- FLOW_CHART_MAGNETIC_TAPE(154),
- FLOW_CHART_MAGNETIC_DISK(155),
- FLOW_CHART_MAGNETIC_DRUM(156),
- FLOW_CHART_DISPLAY(157),
- FLOW_CHART_DELAY(158),
- FLOW_CHART_ALTERNATE_PROCESS(159),
- FLOW_CHART_OFFPAGE_CONNECTOR(160),
- ACTION_BUTTON_BLANK(161),
- ACTION_BUTTON_HOME(162),
- ACTION_BUTTON_HELP(163),
- ACTION_BUTTON_INFORMATION(164),
- ACTION_BUTTON_FORWARD_NEXT(165),
- ACTION_BUTTON_BACK_PREVIOUS(166),
- ACTION_BUTTON_END(167),
- ACTION_BUTTON_BEGINNING(168),
- ACTION_BUTTON_RETURN(169),
- ACTION_BUTTON_DOCUMENT(170),
- ACTION_BUTTON_SOUND(171),
- ACTION_BUTTON_MOVIE(172),
- GEAR_6(173),
- GEAR_9(174),
- FUNNEL(175),
- MATH_PLUS(176),
- MATH_MINUS(177),
- MATH_MULTIPLY(178),
- MATH_DIVIDE(179),
- MATH_EQUAL(180),
- MATH_NOT_EQUAL(181),
- CORNER_TABS(182),
- SQUARE_TABS(183),
- PLAQUE_TABS(184),
- CHART_X(185),
- CHART_STAR(186),
- CHART_PLUS(187);
-
- private int _idx;
-
- XSLFShapeType(int idx){
- _idx = idx;
- }
-
- /**
- *
- * @return index in the STShapeType enum
- */
- int getIndex(){
- return _idx;
- }
-
- static XSLFShapeType forInt(int idx){
- for(XSLFShapeType t : values()){
- if(t._idx == idx) return t;
- }
- throw new IllegalArgumentException("Unknown shape type: " + idx);
- }
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
index 35100d119..c9694e218 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
@@ -23,6 +23,8 @@ import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -37,7 +39,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
+import com.sun.org.apache.xml.internal.utils.UnImplNode;
+
import javax.xml.namespace.QName;
+
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.io.IOException;
@@ -51,7 +56,7 @@ import java.util.Map;
import java.util.regex.Pattern;
@Beta
-public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer {
+public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet {
private XSLFCommonSlideData _commonSlideData;
private XSLFDrawing _drawing;
private List _shapes;
@@ -142,6 +147,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFAutoShape sh = getDrawing().createAutoShape();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -149,6 +155,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFFreeformShape sh = getDrawing().createFreeform();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -156,6 +163,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFTextBox sh = getDrawing().createTextBox();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -163,6 +171,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFConnectorShape sh = getDrawing().createConnector();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -170,6 +179,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFGroupShape sh = getDrawing().createGroup();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -191,6 +201,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
sh.resize();
getShapeList().add(sh);
+ sh.setParent(this);
return sh;
}
@@ -198,6 +209,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
List shapes = getShapeList();
XSLFTable sh = getDrawing().createTable();
shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -219,6 +231,12 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return getShapeList().iterator();
}
+ public void addShape(XSLFShape shape) {
+ throw new UnsupportedOperationException(
+ "Adding a shape from a different container is not supported -"
+ + " create it from scratch witht XSLFSheet.create* methods");
+ }
+
/**
* Removes the specified shape from this sheet, if it is present
* (optional operation). If this sheet does not contain the element,
@@ -370,12 +388,6 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return null;
}
- /**
- *
- * @return master of this sheet.
- */
- public abstract XSLFSheet getMasterSheet();
-
protected XSLFTextShape getTextShapeByType(Placeholder type){
for(XSLFShape shape : this.getShapes()){
if(shape instanceof XSLFTextShape) {
@@ -486,7 +498,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
* @param graphics
*/
public void draw(Graphics2D graphics){
- XSLFSheet master = getMasterSheet();
+ XSLFSheet master = (XSLFSheet)getMasterSheet();
if(getFollowMasterGraphics() && master != null) master.draw(graphics);
graphics.setRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM, new AffineTransform());
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
index d6cfa7fba..ca548dd63 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
@@ -19,26 +19,25 @@
package org.apache.poi.xslf.usermodel;
+import java.awt.*;
+import java.awt.Shape;
+import java.awt.geom.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.poi.sl.draw.geom.*;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
-import org.apache.poi.xslf.model.geom.CustomGeometry;
-import org.apache.poi.xslf.model.geom.Outline;
-import org.apache.poi.xslf.model.geom.Path;
-import org.apache.poi.xslf.model.geom.PresetGeometries;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.*;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
-
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
+import org.openxmlformats.schemas.presentationml.x2006.main.*;
/**
* Represents a single (non-group) shape in a .pptx slide show
@@ -46,24 +45,11 @@ import java.util.List;
* @author Yegor Kozlov
*/
@Beta
-public abstract class XSLFSimpleShape extends XSLFShape {
+public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape {
private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance();
- private final XmlObject _shape;
- private final XSLFSheet _sheet;
- private CTShapeProperties _spPr;
- private CTShapeStyle _spStyle;
- private CTNonVisualDrawingProps _nvPr;
- private CTPlaceholder _ph;
-
/* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) {
- _shape = shape;
- _sheet = sheet;
- }
-
- @Override
- public XmlObject getXmlObject() {
- return _shape;
+ super(shape,sheet);
}
/**
@@ -78,16 +64,16 @@ public abstract class XSLFSimpleShape extends XSLFShape {
*
* @param type
*/
- public void setShapeType(XSLFShapeType type){
+ public void setShapeType(ShapeType type){
CTShape shape = (CTShape) getXmlObject();
- STShapeType.Enum geom = STShapeType.Enum.forInt(type.getIndex());
+ STShapeType.Enum geom = STShapeType.Enum.forInt(type.ooxmlId);
shape.getSpPr().getPrstGeom().setPrst(geom);
}
- public XSLFShapeType getShapeType(){
+ public ShapeType getShapeType(){
CTShape shape = (CTShape) getXmlObject();
STShapeType.Enum geom = shape.getSpPr().getPrstGeom().getPrst();
- return XSLFShapeType.forInt(geom.intValue());
+ return ShapeType.forId(geom.intValue(), true);
}
@Override
@@ -100,101 +86,6 @@ public abstract class XSLFSimpleShape extends XSLFShape {
return (int) getNvPr().getId();
}
- protected CTNonVisualDrawingProps getNvPr() {
- if (_nvPr == null) {
- XmlObject[] rs = _shape
- .selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
- if (rs.length != 0) {
- _nvPr = (CTNonVisualDrawingProps) rs[0];
- }
- }
- return _nvPr;
- }
-
- protected CTShapeProperties getSpPr() {
- if (_spPr == null) {
- for (XmlObject obj : _shape.selectPath("*")) {
- if (obj instanceof CTShapeProperties) {
- _spPr = (CTShapeProperties) obj;
- }
- }
- }
- if (_spPr == null) {
- throw new IllegalStateException("CTShapeProperties was not found.");
- }
- return _spPr;
- }
-
- protected CTShapeStyle getSpStyle() {
- if (_spStyle == null) {
- for (XmlObject obj : _shape.selectPath("*")) {
- if (obj instanceof CTShapeStyle) {
- _spStyle = (CTShapeStyle) obj;
- }
- }
- }
- return _spStyle;
- }
-
- protected CTPlaceholder getCTPlaceholder() {
- if (_ph == null) {
- XmlObject[] obj = _shape.selectPath(
- "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:nvPr/p:ph");
- if (obj.length == 1) {
- _ph = (CTPlaceholder) obj[0];
- }
- }
- return _ph;
- }
-
- CTTransform2D getXfrm() {
- PropertyFetcher fetcher = new PropertyFetcher() {
- public boolean fetch(XSLFSimpleShape shape) {
- CTShapeProperties pr = shape.getSpPr();
- if (pr.isSetXfrm()) {
- setValue(pr.getXfrm());
- return true;
- }
- return false;
- }
- };
- fetchShapeProperty(fetcher);
- return fetcher.getValue();
- }
-
- @Override
- public Rectangle2D getAnchor() {
-
- CTTransform2D xfrm = getXfrm();
-
- CTPoint2D off = xfrm.getOff();
- long x = off.getX();
- long y = off.getY();
- CTPositiveSize2D ext = xfrm.getExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
- }
-
- @Override
- public void setAnchor(Rectangle2D anchor) {
- CTShapeProperties spPr = getSpPr();
- CTTransform2D xfrm = spPr.isSetXfrm() ? spPr.getXfrm() : spPr.addNewXfrm();
- CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
- long x = Units.toEMU(anchor.getX());
- long y = Units.toEMU(anchor.getY());
- off.setX(x);
- off.setY(y);
- CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm
- .addNewExt();
- long cx = Units.toEMU(anchor.getWidth());
- long cy = Units.toEMU(anchor.getHeight());
- ext.setCx(cx);
- ext.setCy(cy);
- }
-
@Override
public void setRotation(double theta) {
CTShapeProperties spPr = getSpPr();
@@ -314,7 +205,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
*/
public double getLineWidth() {
PropertyFetcher fetcher = new PropertyFetcher() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -371,7 +262,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
public LineDash getLineDash() {
PropertyFetcher fetcher = new PropertyFetcher() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -421,7 +312,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
*/
public LineCap getLineCap() {
PropertyFetcher fetcher = new PropertyFetcher() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -499,7 +390,7 @@ public abstract class XSLFSimpleShape extends XSLFShape {
*/
public XSLFShadow getShadow() {
PropertyFetcher fetcher = new PropertyFetcher() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
if (spPr.isSetEffectLst()) {
CTOuterShadowEffect obj = spPr.getEffectLst().getOuterShdw();
@@ -528,90 +419,11 @@ public abstract class XSLFSimpleShape extends XSLFShape {
return (obj == null || obj == NO_SHADOW) ? null : new XSLFShadow(obj, this);
}
- @Override
- public void draw(Graphics2D graphics) {
- RenderableShape rShape = new RenderableShape(this);
- rShape.render(graphics);
-
- // draw line decorations
- Color lineColor = getLineColor();
- if(lineColor != null) {
- graphics.setPaint(lineColor);
- for(Outline o : getDecorationOutlines(graphics)){
- if(o.getPath().isFilled()){
- graphics.fill(o.getOutline());
- }
- if(o.getPath().isStroked()){
- graphics.draw(o.getOutline());
- }
- }
- }
- }
-
-
- /**
- * Walk up the inheritance tree and fetch shape properties.
- *
- * The following order of inheritance is assumed:
- *
+ */
+public class ImageRenderer {
+ protected BufferedImage img;
+
+ /**
+ * Load and buffer the image
+ *
+ * @param data the raw image stream
+ * @param contentType the content type
+ */
+ public void loadImage(InputStream data, String contentType) throws IOException {
+ img = ImageIO.read(data);
+ }
+
+ /**
+ * @return the buffered image
+ */
+ public BufferedImage getImage() {
+ return img;
+ }
+
+ /**
+ * @return the dimension of the buffered image
+ */
+ public Dimension getDimension() {
+ return (img == null)
+ ? new Dimension(0,0)
+ : new Dimension(img.getWidth(),img.getHeight());
+ }
+
+ /**
+ * @param alpha the alpha [0..1] to be added to the image (possibly already containing an alpha channel)
+ */
+ public void setAlpha(double alpha) {
+ if (img == null) return;
+
+ Dimension dim = getDimension();
+ BufferedImage newImg = new BufferedImage((int)dim.getWidth(), (int)dim.getHeight(), BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = newImg.createGraphics();
+ RescaleOp op = new RescaleOp(new float[]{1.0f, 1.0f, 1.0f, (float)alpha}, new float[]{0,0,0,0}, null);
+ g.drawImage(img, op, 0, 0);
+ g.dispose();
+
+ img = newImg;
+ }
+
+
+ /**
+ * Render picture data into the supplied graphics
+ *
+ * @return true if the picture data was successfully rendered
+ */
+ public boolean drawImage(
+ Graphics2D graphics,
+ Rectangle2D anchor) {
+ return drawImage(graphics, anchor, null);
+ }
+
+ /**
+ * Render picture data into the supplied graphics
+ *
+ * @return true if the picture data was successfully rendered
+ */
+ public boolean drawImage(
+ Graphics2D graphics,
+ Rectangle2D anchor,
+ Insets clip) {
+ if (img == null) return false;
+
+ boolean isClipped = true;
+ if (clip == null) {
+ isClipped = false;
+ clip = new Insets(0,0,0,0);
+ }
+
+ int iw = img.getWidth();
+ int ih = img.getHeight();
+
+ double cw = (100000-clip.left-clip.right) / 100000.0;
+ double ch = (100000-clip.top-clip.bottom) / 100000.0;
+ double sx = anchor.getWidth()/(iw*cw);
+ double sy = anchor.getHeight()/(ih*ch);
+ double tx = anchor.getX()-(iw*sx*clip.left/100000.0);
+ double ty = anchor.getY()-(ih*sy*clip.top/100000.0);
+ AffineTransform at = new AffineTransform(sx, 0, 0, sy, tx, ty) ;
+
+ Shape clipOld = graphics.getClip();
+ if (isClipped) graphics.clip(anchor.getBounds2D());
+ graphics.drawRenderedImage(img, at);
+ graphics.setClip(clipOld);
+
+ return true;
+ }
+}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjPoint2D.java b/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjPoint2D.java
new file mode 100644
index 000000000..ff07ce7cf
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjPoint2D.java
@@ -0,0 +1,126 @@
+/* ====================================================================
+ 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.sl.draw.binding;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import com.sun.xml.internal.bind.Locatable;
+import com.sun.xml.internal.bind.annotation.XmlLocation;
+import org.xml.sax.Locator;
+
+
+/**
+ *
Java class for CT_AdjPoint2D complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "CT_AdjPoint2D", namespace = "http://schemas.openxmlformats.org/drawingml/2006/main")
+public class CTAdjPoint2D
+ implements Locatable
+{
+
+ @XmlAttribute(name = "x", required = true)
+ protected String x;
+ @XmlAttribute(name = "y", required = true)
+ protected String y;
+ @XmlLocation
+ @XmlTransient
+ protected Locator locator;
+
+ /**
+ * Gets the value of the x property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getX() {
+ return x;
+ }
+
+ /**
+ * Sets the value of the x property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setX(String value) {
+ this.x = value;
+ }
+
+ public boolean isSetX() {
+ return (this.x!= null);
+ }
+
+ /**
+ * Gets the value of the y property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getY() {
+ return y;
+ }
+
+ /**
+ * Sets the value of the y property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setY(String value) {
+ this.y = value;
+ }
+
+ public boolean isSetY() {
+ return (this.y!= null);
+ }
+
+ public Locator sourceLocation() {
+ return locator;
+ }
+
+ public void setSourceLocation(Locator newLocator) {
+ locator = newLocator;
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjustHandleList.java b/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjustHandleList.java
new file mode 100644
index 000000000..ae1482e49
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/binding/CTAdjustHandleList.java
@@ -0,0 +1,116 @@
+/* ====================================================================
+ 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.sl.draw.binding;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import com.sun.xml.internal.bind.Locatable;
+import com.sun.xml.internal.bind.annotation.XmlLocation;
+import org.xml.sax.Locator;
+
+
+/**
+ *
Java class for CT_AdjustHandleList complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *