From d2594d3207d3a7b50d124a6f2a2145db504e8d9d Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 30 Jul 2018 22:23:25 +0000 Subject: [PATCH] [github-118] Added get/set for mirror margins setting. This closes #118 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1837093 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/XWPFDocument.java | 35 +++++++++++++++ .../poi/xwpf/usermodel/XWPFSettings.java | 44 +++++++++++++++++++ .../poi/xwpf/usermodel/TestXWPFDocument.java | 16 +++++++ 3 files changed, 95 insertions(+) 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 fa252662b8..e11388a13f 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -1338,6 +1338,40 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { settings.setZoomPercent(zoomPercent); } + /** + * Returns the even-and-odd-headings setting + * + * @return True or false indicating whether or not separate even and odd headings is turned on. + */ + public boolean getEvenAndOddHeadings() { + return settings.getEvenAndOddHeadings(); + } + + /** + * Sets the even-and-odd-headings setting + * @param enable Set to true to turn on separate even and odd headings. + */ + public void setEvenAndOddHeadings(boolean enable) { + settings.setEvenAndOddHeadings(enable); + } + + /** + * Returns the mirror margins setting + * + * @return True or false indicating whether or not mirror margins is turned on. + */ + public boolean getMirrorMargins() { + return settings.getMirrorMargins(); + } + + /** + * Sets the mirror margins setting + * @param enable Set to true to turn on mirror margins. + */ + public void setMirrorMargins(boolean enable) { + settings.setMirrorMargins(enable); + } + /** * inserts an existing XWPFTable to the arrays bodyElements and tables * @@ -1758,4 +1792,5 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { return false; } } + } 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 a37e68b687..f40e283968 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java @@ -430,4 +430,48 @@ public class XWPFSettings extends POIXMLDocumentPart { throw new RuntimeException(e); } } + + /** + * Check if separate even and odd headings is turned on. + * + * @return True if even and odd headings is turned on. + */ + public boolean getEvenAndOddHeadings() { + return ctSettings.isSetEvenAndOddHeaders(); + } + + /** + * Turn separate even-and-odd headings on or off + * + * @param enable true to turn on separate even and odd headings, + * false to turn off even and odd headings. + */ + public void setEvenAndOddHeadings(boolean enable) { + CTOnOff onOff = CTOnOff.Factory.newInstance(); + onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE); + ctSettings.setEvenAndOddHeaders(onOff); + } + + /** + * Check if mirrored margins is turned on + * + * @return True if mirrored margins is turned on. + */ + public boolean getMirrorMargins() { + return ctSettings.isSetMirrorMargins(); + } + + /** + * Turn mirrored margins on or off + * + * @param enable true to turn on mirrored margins, + * false to turn off mirrored marginss. + */ + public void setMirrorMargins(boolean enable) { + CTOnOff onOff = CTOnOff.Factory.newInstance(); + onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE); + ctSettings.setMirrorMargins(onOff); + } + + } 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 36757ff6ad..15611bcf4b 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -402,6 +402,14 @@ public final class TestXWPFDocument { assertEquals(100, settings.getZoomPercent()); settings.setZoomPercent(50); assertEquals(50, settings.getZoomPercent()); + + assertEquals(false, settings.getEvenAndOddHeadings()); + settings.setEvenAndOddHeadings(true); + assertEquals(true, settings.getEvenAndOddHeadings()); + + assertEquals(false, settings.getMirrorMargins()); + settings.setMirrorMargins(true); + assertEquals(true, settings.getMirrorMargins()); XWPFDocument doc = new XWPFDocument(); assertEquals(100, doc.getZoomPercent()); @@ -412,6 +420,14 @@ public final class TestXWPFDocument { doc.setZoomPercent(200); assertEquals(200, doc.getZoomPercent()); + assertEquals(false, doc.getEvenAndOddHeadings()); + doc.setEvenAndOddHeadings(true); + assertEquals(true, doc.getEvenAndOddHeadings()); + + assertEquals(false, doc.getMirrorMargins()); + doc.setMirrorMargins(true); + assertEquals(true, doc.getMirrorMargins()); + XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc); assertEquals(200, back.getZoomPercent()); back.close(); -- 2.39.5