<changes>
<release version="3.8-beta3" date="2011-??-??">
+ <action dev="poi-developers" type="add">51188 - Support for getting and setting XPWF zoom settings</action>
<action dev="poi-developers" type="add">51134 - Support for adding Numbering and Styles to a XWPF document that doesn't already have them</action>
<action dev="poi-developers" type="fix">51273 - Formula Value Cache fix for repeated evaluations</action>
<action dev="poi-developers" type="add">51171 - Improved performance of SharedValueManager </action>
public void removeProtectionEnforcement() {
settings.removeEnforcement();
}
+
+ /**
+ * Return the zoom level, as a percentage
+ */
+ public long getZoomPercent() {
+ return settings.getZoomPercent();
+ }
+
+ /**
+ * Sets the zoom level, as a percentage
+ */
+ public void setZoomPercent(long zoomPercent) {
+ settings.setZoomPercent(zoomPercent);
+ }
/**
* inserts an existing XWPFTable to the arrays bodyElements and tables
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSettings;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTZoom;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.SettingsDocument;
ctSettings = CTSettings.Factory.newInstance();
}
+ /**
+ * Set zoom.<br/>
+ * In the zoom tag inside settings.xml file <br/>
+ * it sets the value of zoom
+ * <br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * <w:zoom w:percent="50" />
+ * <pre>
+ * @return percentage as an integer of zoom level
+ */
+ public long getZoomPercent() {
+ CTZoom zoom;
+ if (!ctSettings.isSetZoom()) {
+ zoom = ctSettings.addNewZoom();
+ } else {
+ zoom = ctSettings.getZoom();
+ }
+
+ return zoom.getPercent().longValue();
+ }
+
+ /**
+ * Set zoom.<br/>
+ * In the zoom tag inside settings.xml file <br/>
+ * it sets the value of zoom
+ * <br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * <w:zoom w:percent="50" />
+ * <pre>
+ * @return percentage as an integer of zoom level
+ */
+ public void setZoomPercent(long zoomPercent) {
+ if (! ctSettings.isSetZoom()) {
+ ctSettings.addNewZoom();
+ }
+ CTZoom zoom = ctSettings.getZoom();
+ zoom.setPercent(BigInteger.valueOf(zoomPercent));
+ }
/**
* Verifies the documentProtection tag inside settings.xml file <br/>
assertEquals(p3, doc.getParagraphs().get(0));
}
- public void testGIFSupport() throws Exception
- {
+ public void testSettings() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithGIF.docx");
+ assertEquals(120, doc.getZoomPercent());
+ assertEquals(false, doc.isEnforcedCommentsProtection());
+ assertEquals(false, doc.isEnforcedFillingFormsProtection());
+ assertEquals(false, doc.isEnforcedReadonlyProtection());
+ assertEquals(false, doc.isEnforcedTrackedChangesProtection());
+
+ doc.setZoomPercent(124);
+
+ // Only one enforcement allowed, last one wins!
+ doc.enforceFillingFormsProtection();
+ doc.enforceReadonlyProtection();
+
+ doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+
+ assertEquals(124, doc.getZoomPercent());
+ assertEquals(false, doc.isEnforcedCommentsProtection());
+ assertEquals(false, doc.isEnforcedFillingFormsProtection());
+ assertEquals(true, doc.isEnforcedReadonlyProtection());
+ assertEquals(false, doc.isEnforcedTrackedChangesProtection());
+ }
+
+ public void testGIFSupport() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("WithGIF.docx");
ArrayList<PackagePart> gifParts = doc.getPackage().getPartsByContentType(XWPFRelation.IMAGE_GIF.getContentType());
assertEquals("Expected exactly one GIF part in package.",1,gifParts.size());