From 64957d9ec8dce1feb2fb3ca9ad637106866e0ace Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 5 Nov 2017 01:58:17 +0100 Subject: [PATCH] Support for Mirrored page setup for docx --- docs/general.rst | 9 +++++ src/PhpWord/Metadata/Settings.php | 24 +++++++++++ src/PhpWord/Writer/Word2007/Part/Settings.php | 1 + .../Writer/Word2007/Part/SettingsTest.php | 40 +++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/docs/general.rst b/docs/general.rst index 5b5c5d9e..b11734b1 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -159,6 +159,15 @@ Or to predefined values ``fullPage``, ``bestFit``, ``textFit`` $phpWord->getSettings()->setZoom(Zoom::BEST_FIT); +Mirroring the Page Margins +~~~~~~~~~~~~~~~~~~~~~~~~~~ +Use mirror margins to set up facing pages for double-sided documents, such as books or magazines. + +.. code-block:: php + + $phpWord->getSettings()->setMirrorMargins(true); + + Spelling and grammatical checks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/PhpWord/Metadata/Settings.php b/src/PhpWord/Metadata/Settings.php index 85c0659d..dc9270e7 100644 --- a/src/PhpWord/Metadata/Settings.php +++ b/src/PhpWord/Metadata/Settings.php @@ -38,6 +38,14 @@ class Settings */ private $zoom = 100; + /** + * Mirror Page Margins + * + * @see http://www.datypic.com/sc/ooxml/e-w_mirrorMargins-1.html + * @var bool + */ + private $mirrorMargins; + /** * Hide spelling errors * @@ -301,6 +309,22 @@ class Settings } } + /** + * @return bool + */ + public function hasMirrorMargins() + { + return $this->mirrorMargins; + } + + /** + * @param bool $mirrorMargins + */ + public function setMirrorMargins($mirrorMargins) + { + $this->mirrorMargins = $mirrorMargins; + } + /** * Returns the Language * diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index b205619d..c8772e71 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -140,6 +140,7 @@ class Settings extends AbstractPart ), ); + $this->setOnOffValue('w:mirrorMargins', $documentSettings->hasMirrorMargins()); $this->setOnOffValue('w:hideSpellingErrors', $documentSettings->hasHideSpellingErrors()); $this->setOnOffValue('w:hideGrammaticalErrors', $documentSettings->hasHideGrammaticalErrors()); $this->setOnOffValue('w:trackRevisions', $documentSettings->hasTrackRevisions()); diff --git a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php index 7d85995c..4715d2da 100644 --- a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php @@ -23,6 +23,7 @@ use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\SimpleType\Zoom; use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\TestHelperDOCX; +use PhpOffice\PhpWord\ComplexType\ProofState; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings @@ -110,6 +111,29 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertEquals(Language::HE_IL, $element->getAttribute('w:bidi')); } + /** + * Test proofState + */ + public function testProofState() + { + $proofState = new ProofState(); + $proofState->setSpelling(ProofState::DIRTY); + $proofState->setGrammar(ProofState::DIRTY); + $phpWord = new PhpWord(); + $phpWord->getSettings()->setProofState($proofState); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:proofState'; + $this->assertTrue($doc->elementExists($path, $file)); + $element = $doc->getElement($path, $file); + + $this->assertEquals('dirty', $element->getAttribute('w:spelling')); + $this->assertEquals('dirty', $element->getAttribute('w:grammar')); + } + /** * Test spelling */ @@ -186,6 +210,22 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertEquals('fullPage', $element->getAttribute('w:val')); } + public function testMirrorMargins() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setMirrorMargins(true); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:mirrorMargins'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertNotEquals('false', $element->getAttribute('w:val')); + } + /** * Test Revision View */