diff --git a/src/documentation/content/xdocs/index.xml b/src/documentation/content/xdocs/index.xml index 56e89aa2b4..61fc1de6f9 100644 --- a/src/documentation/content/xdocs/index.xml +++ b/src/documentation/content/xdocs/index.xml @@ -32,8 +32,8 @@
-The Apache POI team is pleased to announce the release of 3.8 beta 3.
+ The Apache POI team is pleased to announce the release of 3.8 beta 4.
This includes a large number of bug fixes and enhancements.
A full list of changes is available in the change log.
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 96acff77ec..4c9f245e02 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
Anchor* constants defined in this class.
- *
- * @param anchor - the type of alignment. Default is {@link VerticalAlignment#TOP}
- */
- public void setVerticalAlignment(VerticalAlignment anchor){
+ protected CTTextBody getTextBody(boolean create){
CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(anchor == null) {
- if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
- } else {
- bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
- }
- }
- }
-
- /**
- * Returns the type of vertical alignment for the text.
- *
- * @return the type of alignment
- */
- public VerticalAlignment getVerticalAlignment(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- STTextAnchoringType.Enum val = shape.getTxBody().getBodyPr().getAnchor();
- if(val != null){
- return VerticalAlignment.values()[val.intValue() - 1];
- }
- }
- return VerticalAlignment.TOP;
- }
-
- /**
- *
- * @param orientation vertical orientation of the text
- */
- public void setTextDirection(TextDirection orientation){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(orientation == null) {
- if(bodyPr.isSetVert()) bodyPr.unsetVert();
- } else {
- bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
- }
- }
- }
-
- /**
- * @return vertical orientation of the text
- */
- public TextDirection getTextDirection(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- STTextVerticalType.Enum val = shape.getTxBody().getBodyPr().getVert();
- if(val != null){
- return TextDirection.values()[val.intValue() - 1];
- }
- }
- return TextDirection.HORIZONTAL;
- }
- /**
- * Returns the distance (in points) between the bottom of the text frame
- * and the bottom of the inscribed rectangle of the shape that contains the text.
- *
- * @return the bottom margin or -1 if not set
- */
- public double getMarginBottom(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- return bodyPr.isSetBIns() ? Units.toPoints(bodyPr.getBIns()) : -1;
- }
- return -1;
- }
-
- /**
- * Returns the distance (in points) between the left edge of the text frame
- * and the left edge of the inscribed rectangle of the shape that contains
- * the text.
- *
- * @return the left margin
- */
- public double getMarginLeft(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- return bodyPr.isSetLIns() ? Units.toPoints(bodyPr.getLIns()) : -1;
- }
- return -1;
- }
-
- /**
- * Returns the distance (in points) between the right edge of the
- * text frame and the right edge of the inscribed rectangle of the shape
- * that contains the text.
- *
- * @return the right margin
- */
- public double getMarginRight(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- return bodyPr.isSetRIns() ? Units.toPoints(bodyPr.getRIns()) : -1;
- }
- return -1;
- }
-
- /**
- * Returns the distance (in points) between the top of the text frame
- * and the top of the inscribed rectangle of the shape that contains the text.
- *
- * @return the top margin
- */
- public double getMarginTop(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- return bodyPr.isSetTIns() ? Units.toPoints(bodyPr.getTIns()) : -1;
- }
- return -1;
- }
-
- /**
- * Sets the botom margin.
- * @see #getMarginBottom()
- *
- * @param margin the bottom margin
- */
- public void setMarginBottom(double margin){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(margin == -1) bodyPr.unsetBIns();
- else bodyPr.setBIns(Units.toEMU(margin));
- }
- }
-
- /**
- * Sets the left margin.
- * @see #getMarginLeft()
- *
- * @param margin the left margin
- */
- public void setMarginLeft(double margin){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(margin == -1) bodyPr.unsetLIns();
- else bodyPr.setLIns(Units.toEMU(margin));
- }
- }
-
- /**
- * Sets the right margin.
- * @see #getMarginRight()
- *
- * @param margin the right margin
- */
- public void setMarginRight(double margin){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(margin == -1) bodyPr.unsetRIns();
- else bodyPr.setRIns(Units.toEMU(margin));
- }
- }
-
- /**
- * Sets the top margin.
- * @see #getMarginTop()
- *
- * @param margin the top margin
- */
- public void setMarginTop(double margin){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(margin == -1) bodyPr.unsetTIns();
- else bodyPr.setTIns(Units.toEMU(margin));
- }
- }
-
-
- /**
- * Returns the value indicating word wrap.
- * One of the Wrap* constants defined in this class.
- *
- * @return the value indicating word wrap
- */
- public boolean getWordWrap(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- return shape.getTxBody().getBodyPr().getWrap() == STTextWrappingType.SQUARE;
- }
- return false;
- }
-
- /**
- * Specifies how the text should be wrapped
- *
- * @param wrap the value indicating how the text should be wrapped
- */
- public void setWordWrap(boolean wrap){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- shape.getTxBody().getBodyPr().setWrap(wrap ? STTextWrappingType.SQUARE : STTextWrappingType.NONE);
- }
- }
-
- /**
- *
- * 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
- *
- * @param value type of autofit
- */
- public void setTextAutofit(TextAutofit value){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
- if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
- if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
-
- switch(value){
- case NONE: bodyPr.addNewNoAutofit(); break;
- case NORMAL: bodyPr.addNewNormAutofit(); break;
- case SHAPE: bodyPr.addNewSpAutoFit(); break;
- }
- }
- }
-
- /**
- *
- * @return type of autofit
- */
- public TextAutofit getTextAutofit(){
- CTShape shape = (CTShape) getXmlObject();
- if (shape.isSetTxBody()) {
- CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
- if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
- else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
- else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
- }
- return TextAutofit.NORMAL;
- }
-
-
- @Override
- void onCopy(XSLFSheet srcSheet){
- CTShape shape = (CTShape) getXmlObject();
- if (!shape.isSetTxBody()) return;
-
- CTPlaceholder ph = shape.getNvSpPr().getNvPr().getPh();
- if(ph == null || !ph.isSetType()) return;
-
- if(ph.getType() == STPlaceholderType.TITLE){
-
+ CTTextBody txBody = shape.getTxBody();
+ if (txBody == null && create) {
+ txBody = shape.addNewTxBody();
+ txBody.addNewBodyPr();
+ txBody.addNewLstStyle();
}
+ return txBody;
}
}
\ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
index ab8c1658fe..e731a632d6 100755
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
@@ -24,6 +24,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
import java.awt.*;
@@ -97,4 +98,12 @@ public class XSLFDrawing {
shape.setAnchor(new Rectangle());
return shape;
}
+
+ public XSLFTable createTable(){
+ CTGraphicalObjectFrame obj = _spTree.addNewGraphicFrame();
+ obj.set(XSLFTable.prototype(_shapeId++));
+ XSLFTable shape = new XSLFTable(obj, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
}
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 0abad44f30..7e0990331f 100755
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
@@ -44,6 +44,10 @@ public class XSLFGraphicFrame extends XSLFShape {
return _shape;
}
+ public XSLFSheet getSheet(){
+ return _sheet;
+ }
+
public int getShapeType(){
throw new RuntimeException("NotImplemented");
}
@@ -64,16 +68,14 @@ public class XSLFGraphicFrame extends XSLFShape {
throw new RuntimeException("NotImplemented");
}
- public ShapeGroup getParent(){
- throw new RuntimeException("NotImplemented");
+
+ static XSLFGraphicFrame create(CTGraphicalObjectFrame shape, XSLFSheet sheet){
+ String uri = shape.getGraphic().getGraphicData().getUri();
+ if(XSLFTable.TABLE_URI.equals(uri)){
+ return new XSLFTable(shape, sheet);
+ } else {
+ return new XSLFGraphicFrame(shape, sheet);
+ }
}
- public Shape[] getShapes(){
- throw new RuntimeException("NotImplemented");
- }
-
-
- public boolean removeShape(Shape shape){
- throw new RuntimeException("NotImplemented");
- }
}
\ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
new file mode 100644
index 0000000000..5a25851b5c
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
@@ -0,0 +1,69 @@
+/* ====================================================================
+ 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 org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.util.Internal;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink;
+
+import java.net.URI;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class XSLFHyperlink {
+ final XSLFTextRun _r;
+ final CTHyperlink _link;
+
+ XSLFHyperlink(CTHyperlink link, XSLFTextRun r){
+ _r = r;
+ _link = link;
+ }
+
+ @Internal
+ public CTHyperlink getXmlObject(){
+ return _link;
+ }
+
+ public void setAddress(String address){
+ XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
+ PackageRelationship rel =
+ sheet.getPackagePart().
+ addExternalRelationship(address, XSLFRelation.HYPERLINK.getRelation());
+ _link.setId(rel.getId());
+
+ }
+
+ public void setAddress(XSLFSlide slide){
+ XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
+ PackageRelationship rel =
+ sheet.getPackagePart().
+ addRelationship(slide.getPackagePart().getPartName(),
+ TargetMode.INTERNAL,
+ XSLFRelation.SLIDE.getRelation());
+ _link.setId(rel.getId());
+ _link.setAction("ppaction://hlinksldjump");
+ }
+
+ @Internal
+ public URI getTargetURI(){
+ XSLFSheet sheet = _r.getParentParagraph().getParentShape().getSheet();
+ String id = _link.getId();
+ return sheet.getPackagePart().getRelationship(id).getTargetURI();
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
index 10a35dfeee..15f91c6ec5 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
@@ -103,6 +103,13 @@ public class XSLFRelation extends POIXMLRelation {
null, null
);
+ public static final XSLFRelation HYPERLINK = new XSLFRelation(
+ null,
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
+ null,
+ null
+ );
+
public static final XSLFRelation THEME = new XSLFRelation(
"application/vnd.openxmlformats-officedocument.theme+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",
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 b1b65eac40..dfb659557f 100755
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
@@ -41,8 +41,4 @@ public abstract class XSLFShape {
public abstract String getShapeName();
public abstract int getShapeId();
-
- void onCopy(XSLFSheet srcSheet){
-
- }
}
\ No newline at end of file
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 02ce9fdb7d..d97600d398 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
@@ -70,7 +70,8 @@ public abstract class XSLFSheet extends POIXMLDocumentPart {
} else if (ch instanceof CTPicture){
shapes.add(new XSLFPictureShape((CTPicture)ch, this));
} else if (ch instanceof CTGraphicalObjectFrame){
- shapes.add(new XSLFGraphicFrame((CTGraphicalObjectFrame)ch, this));
+ XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame)ch, this);
+ shapes.add(shape);
}
}
return shapes;
@@ -147,6 +148,13 @@ public abstract class XSLFSheet extends POIXMLDocumentPart {
return sh;
}
+ public XSLFTable createTable(){
+ Listnull unsets the solidFIll attribute from the underlying xml
+ */
+ @Override
+ public void setFillColor(Color color) {
+ CTTableCellProperties spPr = getXmlObject().getTcPr();
+ if (color == null) {
+ if(spPr.isSetSolidFill()) spPr.unsetSolidFill();
+ }
+ else {
+ CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill();
+
+ CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
+ rgb.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
+
+ fill.setSrgbClr(rgb);
+ }
+ }
+
+ /**
+ *
+ * @return solid fill color of null if not set
+ */
+ @Override
+ public Color getFillColor(){
+ CTTableCellProperties spPr = getXmlObject().getTcPr();
+ if(!spPr.isSetSolidFill() ) return null;
+
+ CTSolidColorFillProperties fill = spPr.getSolidFill();
+ if(!fill.isSetSrgbClr()) {
+ // TODO for now return null for all colors except explicit RGB
+ return null;
+ }
+ byte[] val = fill.getSrgbClr().getVal();
+ return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
+ }
+
+}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
new file mode 100644
index 0000000000..328c76ae76
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
@@ -0,0 +1,86 @@
+/*
+ * ====================================================================
+ * 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 org.apache.poi.util.Units;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * Represents a table in a .pptx presentation
+ *
+ * @author Yegor Kozlov
+ */
+public class XSLFTableRow implements Iterablenull unsets the solidFIll attribute from the underlying xml
+ */
+ public void setFillColor(Color color) {
+ CTShapeProperties spPr = getSpPr();
+ if (color == null) {
+ if(spPr.isSetSolidFill()) spPr.unsetSolidFill();
+ }
+ else {
+ CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill();
+
+ CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
+ rgb.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
+
+ fill.setSrgbClr(rgb);
+ }
+ }
+
+ /**
+ *
+ * @return solid fill color of null if not set
+ */
+ public Color getFillColor(){
+ CTShapeProperties spPr = getSpPr();
+ if(!spPr.isSetSolidFill() ) return null;
+
+ CTSolidColorFillProperties fill = spPr.getSolidFill();
+ if(!fill.isSetSrgbClr()) {
+ // TODO for now return null for all colors except explicit RGB
+ return null;
+ }
+ byte[] val = fill.getSrgbClr().getVal();
+ return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
+ }
+
+ /**
+ * Sets the type of vertical alignment for the text.
+ * One of the Anchor* constants defined in this class.
+ *
+ * @param anchor - the type of alignment. Default is {@link org.apache.poi.xslf.usermodel.VerticalAlignment#TOP}
+ */
+ public void setVerticalAlignment(VerticalAlignment anchor){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(anchor == null) {
+ if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
+ } else {
+ bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
+ }
+ }
+ }
+
+ /**
+ * Returns the type of vertical alignment for the text.
+ *
+ * @return the type of alignment
+ */
+ public VerticalAlignment getVerticalAlignment(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ STTextAnchoringType.Enum val = bodyPr.getAnchor();
+ if(val != null){
+ return VerticalAlignment.values()[val.intValue() - 1];
+ }
+ }
+ return VerticalAlignment.TOP;
+ }
+
+ /**
+ *
+ * @param orientation vertical orientation of the text
+ */
+ public void setTextDirection(TextDirection orientation){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(orientation == null) {
+ if(bodyPr.isSetVert()) bodyPr.unsetVert();
+ } else {
+ bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
+ }
+ }
+ }
+
+ /**
+ * @return vertical orientation of the text
+ */
+ public TextDirection getTextDirection(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ STTextVerticalType.Enum val = bodyPr.getVert();
+ if(val != null){
+ return TextDirection.values()[val.intValue() - 1];
+ }
+ }
+ return TextDirection.HORIZONTAL;
+ }
+ /**
+ * Returns the distance (in points) between the bottom of the text frame
+ * and the bottom of the inscribed rectangle of the shape that contains the text.
+ *
+ * @return the bottom margin or -1 if not set
+ */
+ public double getMarginBottom(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ return bodyPr.isSetBIns() ? Units.toPoints(bodyPr.getBIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the left edge of the text frame
+ * and the left edge of the inscribed rectangle of the shape that contains
+ * the text.
+ *
+ * @return the left margin
+ */
+ public double getMarginLeft(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ return bodyPr.isSetLIns() ? Units.toPoints(bodyPr.getLIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the right edge of the
+ * text frame and the right edge of the inscribed rectangle of the shape
+ * that contains the text.
+ *
+ * @return the right margin
+ */
+ public double getMarginRight(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ return bodyPr.isSetRIns() ? Units.toPoints(bodyPr.getRIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the top of the text frame
+ * and the top of the inscribed rectangle of the shape that contains the text.
+ *
+ * @return the top margin
+ */
+ public double getMarginTop(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ return bodyPr.isSetTIns() ? Units.toPoints(bodyPr.getTIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Sets the botom margin.
+ * @see #getMarginBottom()
+ *
+ * @param margin the bottom margin
+ */
+ public void setMarginBottom(double margin){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(margin == -1) bodyPr.unsetBIns();
+ else bodyPr.setBIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the left margin.
+ * @see #getMarginLeft()
+ *
+ * @param margin the left margin
+ */
+ public void setMarginLeft(double margin){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(margin == -1) bodyPr.unsetLIns();
+ else bodyPr.setLIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the right margin.
+ * @see #getMarginRight()
+ *
+ * @param margin the right margin
+ */
+ public void setMarginRight(double margin){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(margin == -1) bodyPr.unsetRIns();
+ else bodyPr.setRIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the top margin.
+ * @see #getMarginTop()
+ *
+ * @param margin the top margin
+ */
+ public void setMarginTop(double margin){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(margin == -1) bodyPr.unsetTIns();
+ else bodyPr.setTIns(Units.toEMU(margin));
+ }
+ }
+
+
+ /**
+ * Returns the value indicating word wrap.
+ * One of the Wrap* constants defined in this class.
+ *
+ * @return the value indicating word wrap
+ */
+ public boolean getWordWrap(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ return bodyPr.getWrap() == STTextWrappingType.SQUARE;
+ }
+ return false;
+ }
+
+ /**
+ * Specifies how the text should be wrapped
+ *
+ * @param wrap the value indicating how the text should be wrapped
+ */
+ public void setWordWrap(boolean wrap){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ bodyPr.setWrap(wrap ? STTextWrappingType.SQUARE : STTextWrappingType.NONE);
+ }
+ }
+
+ /**
+ *
+ * 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
+ *
+ * @param value type of autofit
+ */
+ public void setTextAutofit(TextAutofit value){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
+ if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
+ if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
+
+ switch(value){
+ case NONE: bodyPr.addNewNoAutofit(); break;
+ case NORMAL: bodyPr.addNewNormAutofit(); break;
+ case SHAPE: bodyPr.addNewSpAutoFit(); break;
+ }
+ }
+ }
+
+ /**
+ *
+ * @return type of autofit
+ */
+ public TextAutofit getTextAutofit(){
+ CTTextBodyProperties bodyPr = getTextBodyPr();
+ if (bodyPr != null) {
+ if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
+ else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
+ else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
+ }
+ return TextAutofit.NORMAL;
+ }
+
+ protected CTTextBodyProperties getTextBodyPr(){
+ CTTextBody textBody = getTextBody(false);
+ return textBody == null ? null : textBody.getBodyPr();
+ }
+
+
+ protected abstract CTTextBody getTextBody(boolean create);
+}
\ No newline at end of file
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
index 69be4b7a6b..efed3ca034 100755
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
@@ -210,7 +210,7 @@ public class TestXSLFAutoShape extends TestCase {
assertSame(r, p.getTextRuns().get(0));
assertEquals(-1.0, r.getFontSize());
- assertFalse(r.getXmlObject().isSetRPr());
+ assertFalse(r.getXmlObject().getRPr().isSetSz());
r.setFontSize(10.0);
assertTrue(r.getXmlObject().isSetRPr());
assertEquals(1000, r.getXmlObject().getRPr().getSz());
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java
new file mode 100644
index 0000000000..fe968b0b7f
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java
@@ -0,0 +1,102 @@
+/* ====================================================================
+ 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 junit.framework.TestCase;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.util.*;
+import java.util.List;
+import java.net.URI;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.apache.poi.xssf.usermodel.XSSFTable;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.TargetMode;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFHyperlink extends TestCase {
+
+ public void testRead(){
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+
+ XSLFSlide slide = ppt.getSlides()[4];
+ XSLFShape[] shapes = slide.getShapes();
+ XSLFTable tbl = (XSLFTable)shapes[0];
+ XSLFTableCell cell1 = tbl.getRows().get(1).getCells().get(0);
+ assertEquals("Web Page", cell1.getText());
+ XSLFHyperlink link1 = cell1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
+ assertNotNull(link1);
+ assertEquals(URI.create("http://poi.apache.org/"), link1.getTargetURI());
+
+ XSLFTableCell cell2 = tbl.getRows().get(2).getCells().get(0);
+ assertEquals("Place in this document", cell2.getText());
+ XSLFHyperlink link2 = cell2.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
+ assertNotNull(link2);
+ assertEquals(URI.create("/ppt/slides/slide2.xml"), link2.getTargetURI());
+
+ XSLFTableCell cell3 = tbl.getRows().get(3).getCells().get(0);
+ assertEquals("Email", cell3.getText());
+ XSLFHyperlink link3 = cell3.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
+ assertNotNull(link3);
+ assertEquals(URI.create("mailto:dev@poi.apache.org?subject=Hi%20There"), link3.getTargetURI());
+ }
+
+ public void testCreate() throws Exception {
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide1 = ppt.createSlide();
+ XSLFSlide slide2 = ppt.createSlide();
+
+ int numRel = slide1.getPackagePart().getRelationships().size();
+ assertEquals(1, numRel);
+ XSLFTextBox sh1 = slide1.createTextBox();
+ XSLFTextRun r1 = sh1.addNewTextParagraph().addNewTextRun();
+ r1.setText("Web Page");
+ XSLFHyperlink link1 = r1.createHyperlink();
+ link1.setAddress("http://poi.apache.org/");
+ assertEquals(URI.create("http://poi.apache.org/"), link1.getTargetURI());
+ assertEquals(numRel + 1, slide1.getPackagePart().getRelationships().size());
+
+ String id1 = link1.getXmlObject().getId();
+ assertNotNull(id1);
+ PackageRelationship rel1 = slide1.getPackagePart().getRelationship(id1);
+ assertNotNull(rel1);
+ assertEquals(id1, rel1.getId());
+ assertEquals(TargetMode.EXTERNAL, rel1.getTargetMode());
+ assertEquals(XSLFRelation.HYPERLINK.getRelation(), rel1.getRelationshipType());
+
+ XSLFTextBox sh2 = slide1.createTextBox();
+ XSLFTextRun r2 = sh2.addNewTextParagraph().addNewTextRun();
+ r2.setText("Place in this document");
+ XSLFHyperlink link2 = r2.createHyperlink();
+ link2.setAddress(slide2);
+ assertEquals(URI.create("/ppt/slides/slide2.xml"), link2.getTargetURI());
+ assertEquals(numRel + 2, slide1.getPackagePart().getRelationships().size());
+
+ String id2 = link2.getXmlObject().getId();
+ assertNotNull(id2);
+ PackageRelationship rel2 = slide1.getPackagePart().getRelationship(id2);
+ assertNotNull(rel2);
+ assertEquals(id2, rel2.getId());
+ assertEquals(TargetMode.INTERNAL, rel2.getTargetMode());
+ assertEquals(XSLFRelation.SLIDE.getRelation(), rel2.getRelationshipType());
+ }
+}
\ No newline at end of file
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
index ca3d82f975..ecdcdd032d 100755
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java
@@ -31,7 +31,6 @@ public class TestXSLFShape extends TestCase {
public void testReadTextShapes() {
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
XSLFSlide[] slides = ppt.getSlides();
- assertEquals(3, slides.length);
XSLFSlide slide1 = slides[0];
XSLFShape[] shapes1 = slide1.getShapes();
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
index 9c7d131d80..9ffe69fe98 100755
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
@@ -30,7 +30,6 @@ public class TestXSLFSlide extends TestCase {
public void testReadShapes(){
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
XSLFSlide[] slides = ppt.getSlides();
- assertEquals(3, slides.length);
XSLFSlide slide1 = slides[0];
XSLFShape[] shapes1 = slide1.getShapes();
@@ -85,6 +84,14 @@ public class TestXSLFSlide extends TestCase {
assertTrue(groupShapes[2] instanceof XSLFAutoShape);
assertEquals("Right Arrow 3", groupShapes[2].getShapeName());
+
+ XSLFSlide slide4 = slides[3];
+ XSLFShape[] shapes4 = slide4.getShapes();
+ assertEquals(1, shapes4.length);
+ assertTrue(shapes4[0] instanceof XSLFTable);
+ XSLFTable tbl = (XSLFTable)shapes4[0];
+ assertEquals(3, tbl.getNumberOfColumns());
+ assertEquals(6, tbl.getNumberOfRows());
}
public void testCreateSlide(){
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java
new file mode 100644
index 0000000000..a5cdb0d6ca
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTable.java
@@ -0,0 +1,150 @@
+/* ====================================================================
+ 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 junit.framework.TestCase;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.util.*;
+import java.util.List;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSLFTable extends TestCase {
+
+ public void testRead(){
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+
+ XSLFSlide slide = ppt.getSlides()[3];
+ XSLFShape[] shapes = slide.getShapes();
+ assertEquals(1, shapes.length);
+ assertTrue(shapes[0] instanceof XSLFTable);
+ XSLFTable tbl = (XSLFTable)shapes[0];
+ assertEquals(3, tbl.getNumberOfColumns());
+ assertEquals(6, tbl.getNumberOfRows());
+ assertNotNull(tbl.getCTTable());
+
+ List