Browse Source

Fix bug #51188 - Support for getting and setting XPWF zoom settings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1128312 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA3
Nick Burch 13 years ago
parent
commit
e21094eaaa

+ 1
- 0
src/documentation/content/xdocs/status.xml View File

@@ -34,6 +34,7 @@

<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>

+ 14
- 0
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java View File

@@ -960,6 +960,20 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
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

+ 42
- 0
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java View File

@@ -19,6 +19,7 @@ package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

@@ -30,6 +31,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
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;
@@ -48,6 +50,46 @@ public class XWPFSettings extends POIXMLDocumentPart {
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>
* &lt;w:zoom w:percent="50" /&gt;
* <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>
* &lt;w:zoom w:percent="50" /&gt;
* <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/>

+ 24
- 2
src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java View File

@@ -200,8 +200,30 @@ public final class TestXWPFDocument extends TestCase {
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());

Loading…
Cancel
Save