aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-08-26 19:34:28 +0000
committerDominik Stadler <centic@apache.org>2015-08-26 19:34:28 +0000
commit68314791122dfee3e5a4e1a0c78b3d6b0410a1c8 (patch)
tree5c1f69b95b9ffd354e37ccf256afe9644e101c42 /src/ooxml
parent61de04b84908d9a785ae81c68b48dabec3926b3c (diff)
downloadpoi-68314791122dfee3e5a4e1a0c78b3d6b0410a1c8.tar.gz
poi-68314791122dfee3e5a4e1a0c78b3d6b0410a1c8.zip
Add possibility to set zoomPercent for XWPFDocument
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1697992 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java19
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java7
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java26
3 files changed, 49 insertions, 3 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index 707f142bf3..be206d7398 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -1199,6 +1199,25 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
settings.setTrackRevisions(enable);
}
+
+ /**
+ * Returns the current zoom factor in percent values, i.e. 100 is normal zoom.
+ *
+ * @return A percent value denoting the current zoom setting of this document.
+ */
+ public long getZoomPercent() {
+ return settings.getZoomPercent();
+ }
+
+ /**
+ * Set the zoom setting as percent value, i.e. 100 is normal zoom.
+ *
+ * @param zoomPercent A percent value denoting the zoom setting for this document.
+ */
+ public void setZoomPercent(long zoomPercent) {
+ settings.setZoomPercent(zoomPercent);;
+ }
+
/**
* inserts an existing XWPFTable to the arrays bodyElements and tables
*
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
index 6ce7e2ac3d..778f020f29 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
@@ -84,7 +84,12 @@ public class XWPFSettings extends POIXMLDocumentPart {
zoom = ctSettings.getZoom();
}
- return zoom.getPercent().longValue();
+
+ BigInteger percent = zoom.getPercent();
+ if(percent == null) {
+ return 100;
+ }
+ return percent.longValue();
}
/**
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
index f46fd716b4..034e7118b3 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
@@ -17,12 +17,12 @@
package org.apache.poi.xwpf.usermodel;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLProperties;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -36,6 +36,8 @@ import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import junit.framework.TestCase;
+
public final class TestXWPFDocument extends TestCase {
public void testContainsMainContentType() throws Exception {
@@ -352,9 +354,29 @@ public final class TestXWPFDocument extends TestCase {
assertEquals(0, extendedProperties.getUnderlyingProperties().getCharacters());
}
- public void testSettings() {
+ public void testSettings() throws IOException {
XWPFSettings settings = new XWPFSettings();
+ assertEquals(100, settings.getZoomPercent());
settings.setZoomPercent(50);
assertEquals(50, settings.getZoomPercent());
+
+ XWPFDocument doc = new XWPFDocument();
+ assertEquals(100, doc.getZoomPercent());
+
+ doc.setZoomPercent(50);
+ assertEquals(50, doc.getZoomPercent());
+
+ doc.setZoomPercent(200);
+ assertEquals(200, doc.getZoomPercent());
+
+ XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc);
+ assertEquals(200, back.getZoomPercent());
+ back.close();
+
+// OutputStream out = new FileOutputStream("/tmp/testZoom.docx");
+// doc.write(out);
+// out.close();
+
+ doc.close();
}
}