Add possibility to set zoomPercent for XWPFDocument
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1697992 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fd02230c1d
commit
6bdc2fb024
@ -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
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user