Skip to content

Commit 64957d9

Browse files
committed
Support for Mirrored page setup for docx
1 parent 056f810 commit 64957d9

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

docs/general.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ Or to predefined values ``fullPage``, ``bestFit``, ``textFit``
159159
160160
$phpWord->getSettings()->setZoom(Zoom::BEST_FIT);
161161
162+
Mirroring the Page Margins
163+
~~~~~~~~~~~~~~~~~~~~~~~~~~
164+
Use mirror margins to set up facing pages for double-sided documents, such as books or magazines.
165+
166+
.. code-block:: php
167+
168+
$phpWord->getSettings()->setMirrorMargins(true);
169+
170+
162171
Spelling and grammatical checks
163172
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164173

src/PhpWord/Metadata/Settings.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ class Settings
3838
*/
3939
private $zoom = 100;
4040

41+
/**
42+
* Mirror Page Margins
43+
*
44+
* @see http://www.datypic.com/sc/ooxml/e-w_mirrorMargins-1.html
45+
* @var bool
46+
*/
47+
private $mirrorMargins;
48+
4149
/**
4250
* Hide spelling errors
4351
*
@@ -301,6 +309,22 @@ public function setZoom($zoom)
301309
}
302310
}
303311

312+
/**
313+
* @return bool
314+
*/
315+
public function hasMirrorMargins()
316+
{
317+
return $this->mirrorMargins;
318+
}
319+
320+
/**
321+
* @param bool $mirrorMargins
322+
*/
323+
public function setMirrorMargins($mirrorMargins)
324+
{
325+
$this->mirrorMargins = $mirrorMargins;
326+
}
327+
304328
/**
305329
* Returns the Language
306330
*

src/PhpWord/Writer/Word2007/Part/Settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ private function getSettings()
140140
),
141141
);
142142

143+
$this->setOnOffValue('w:mirrorMargins', $documentSettings->hasMirrorMargins());
143144
$this->setOnOffValue('w:hideSpellingErrors', $documentSettings->hasHideSpellingErrors());
144145
$this->setOnOffValue('w:hideGrammaticalErrors', $documentSettings->hasHideGrammaticalErrors());
145146
$this->setOnOffValue('w:trackRevisions', $documentSettings->hasTrackRevisions());

tests/PhpWord/Writer/Word2007/Part/SettingsTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PhpOffice\PhpWord\SimpleType\Zoom;
2424
use PhpOffice\PhpWord\Style\Language;
2525
use PhpOffice\PhpWord\TestHelperDOCX;
26+
use PhpOffice\PhpWord\ComplexType\ProofState;
2627

2728
/**
2829
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
@@ -110,6 +111,29 @@ public function testLanguage()
110111
$this->assertEquals(Language::HE_IL, $element->getAttribute('w:bidi'));
111112
}
112113

114+
/**
115+
* Test proofState
116+
*/
117+
public function testProofState()
118+
{
119+
$proofState = new ProofState();
120+
$proofState->setSpelling(ProofState::DIRTY);
121+
$proofState->setGrammar(ProofState::DIRTY);
122+
$phpWord = new PhpWord();
123+
$phpWord->getSettings()->setProofState($proofState);
124+
125+
$doc = TestHelperDOCX::getDocument($phpWord);
126+
127+
$file = 'word/settings.xml';
128+
129+
$path = '/w:settings/w:proofState';
130+
$this->assertTrue($doc->elementExists($path, $file));
131+
$element = $doc->getElement($path, $file);
132+
133+
$this->assertEquals('dirty', $element->getAttribute('w:spelling'));
134+
$this->assertEquals('dirty', $element->getAttribute('w:grammar'));
135+
}
136+
113137
/**
114138
* Test spelling
115139
*/
@@ -186,6 +210,22 @@ public function testZoomValue()
186210
$this->assertEquals('fullPage', $element->getAttribute('w:val'));
187211
}
188212

213+
public function testMirrorMargins()
214+
{
215+
$phpWord = new PhpWord();
216+
$phpWord->getSettings()->setMirrorMargins(true);
217+
218+
$doc = TestHelperDOCX::getDocument($phpWord);
219+
220+
$file = 'word/settings.xml';
221+
222+
$path = '/w:settings/w:mirrorMargins';
223+
$this->assertTrue($doc->elementExists($path, $file));
224+
225+
$element = $doc->getElement($path, $file);
226+
$this->assertNotEquals('false', $element->getAttribute('w:val'));
227+
}
228+
189229
/**
190230
* Test Revision View
191231
*/

0 commit comments

Comments
 (0)