Support for Mirrored page setup for docx (#1183)

This commit is contained in:
troosan 2017-11-05 02:07:53 +01:00 committed by GitHub
parent de9268ae12
commit 8c7ed19d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 0 deletions

View File

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

View File

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

View File

@ -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());

View File

@ -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
*/