diff --git a/docs/general.rst b/docs/general.rst index 8e347089..87fecb77 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -80,8 +80,8 @@ folder `__. /* Note: we skip RTF, because it's not XML-based and requires a different example. */ /* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */ -Settings --------- +PHPWord Settings +---------------- The ``PhpOffice\PhpWord\Settings`` class provides some options that will affect the behavior of PHPWord. Below are the options. @@ -130,6 +130,35 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); +Default font +~~~~~~~~~~~~ + +By default, every text appears in Arial 10 point. You can alter the +default font by using the following two functions: + +.. code-block:: php + + $phpWord->setDefaultFontName('Times New Roman'); + $phpWord->setDefaultFontSize(12); + +Document settings +----------------- +Settings for the generated document can be set using ``$phpWord->getSettings()`` + +Magnification Setting +~~~~~~~~~~~~~~~~~~~~~ +The default zoom value is 100 percent. This can be changed either to another percentage + +.. code-block:: php + + $phpWord->getSettings()->setZoom(75); + +Or to predefined values ``fullPage``, ``bestFit``, ``textFit`` + +.. code-block:: php + + $phpWord->getSettings()->setZoom(Zoom::BEST_FIT); + Spelling and grammatical checks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -141,16 +170,36 @@ For big documents this can slow down the opening of the document. You can hide t $phpWord->getSettings()->setHideGrammaticalErrors(true); $phpWord->getSettings()->setHideSpellingErrors(true); -Default font -~~~~~~~~~~~~ - -By default, every text appears in Arial 10 point. You can alter the -default font by using the following two functions: +You can also specify the status of the spell and grammar checks, marking spelling or grammar as dirty will force a re-check when opening the document. .. code-block:: php - $phpWord->setDefaultFontName('Times New Roman'); - $phpWord->setDefaultFontSize(12); + $proofState = new ProofState(); + $proofState->setGrammar(ProofState::CLEAN); + $proofState->setSpelling(ProofState::DIRTY); + + $phpWord->getSettings()->setProofState(proofState); + +Track Revisions +~~~~~~~~~~~~~~~ +Track changes can be activated using ``setTrackRevisions``, you can furture specify + +- Not to use move syntax, instead moved items will be seen as deleted in one place and added in another +- Not track formatting revisions + +.. code-block:: php + + $phpWord->getSettings()->setTrackRevisions(true); + $phpWord->getSettings()->setDoNotTrackMoves(true); + $phpWord->getSettings()->setDoNotTrackFormatting(true); + +Decimal Symbol +~~~~~~~~~~~~~~ +The default symbol to represent a decimal figure is the ``.`` in english. In french you might want to change it to ``,`` for instance. + +.. code-block:: php + + $phpWord->getSettings()->setDecimalSymbol(','); Document information -------------------- @@ -194,16 +243,3 @@ points to twips. $sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5)); // 2 cm right margin $sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2)); - -Language --------- - -You can hide spelling errors: - -.. code-block:: php - \PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true); - -And hide grammatical errors: - -.. code-block:: php - \PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true); diff --git a/src/PhpWord/ComplexType/ProofState.php b/src/PhpWord/ComplexType/ProofState.php new file mode 100644 index 00000000..e5ac9c20 --- /dev/null +++ b/src/PhpWord/ComplexType/ProofState.php @@ -0,0 +1,104 @@ +spelling = $spelling; + } else { + throw new \InvalidArgumentException("Invalid value, dirty or clean possible"); + } + return $this; + } + + /** + * Get the Spell Checking State + * + * @return string + */ + public function getSpelling() + { + return $this->spelling; + } + + /** + * Set the Grammatical Checking State (dirty or clean) + * + * @param string $grammar + * @throws \InvalidArgumentException + * @return self + */ + public function setGrammar($grammar) + { + if ($grammar == self::CLEAN || $grammar == self::DIRTY) { + $this->grammar = $grammar; + } else { + throw new \InvalidArgumentException("Invalid value, dirty or clean possible"); + } + return $this; + } + + /** + * Get the Grammatical Checking State + * + * @return string + */ + public function getGrammar() + { + return $this->grammar; + } +} diff --git a/src/PhpWord/ComplexType/TrackChangesView.php b/src/PhpWord/ComplexType/TrackChangesView.php new file mode 100644 index 00000000..ea26bc3c --- /dev/null +++ b/src/PhpWord/ComplexType/TrackChangesView.php @@ -0,0 +1,166 @@ +markup; + } + + /** + * Set Display Visual Indicator Of Markup Area + * + * @param boolean $markup + * Set to true to show markup + */ + public function setMarkup($markup) + { + $this->markup = $markup === null ? true : $markup; + } + + /** + * Get Display Comments + * + * @return boolean True if comments are shown + */ + public function hasComments() + { + return $this->comments; + } + + /** + * Set Display Comments + * + * @param boolean $comments + * Set to true to show comments + */ + public function setComments($comments) + { + $this->comments = $comments === null ? true : $comments; + } + + /** + * Get Display Content Revisions + * + * @return boolean True if content revisions are shown + */ + public function hasInsDel() + { + return $this->insDel; + } + + /** + * Set Display Content Revisions + * + * @param boolean $insDel + * Set to true to show content revisions + */ + public function setInsDel($insDel) + { + $this->insDel = $insDel === null ? true : $insDel; + } + + /** + * Get Display Formatting Revisions + * + * @return boolean True if formatting revisions are shown + */ + public function hasFormatting() + { + return $this->formatting; + } + + /** + * Set Display Formatting Revisions + * + * @param boolean $insDel + * Set to true to show formatting revisions + */ + public function setFormatting($formatting) + { + $this->formatting = $formatting === null ? true : $formatting; + } + + /** + * Get Display Ink Annotations + * + * @return boolean True if ink annotations are shown + */ + public function hasInkAnnotations() + { + return $this->inkAnnotations; + } + + /** + * Set Display Ink Annotations + * + * @param boolean $inkAnnotations + * Set to true to show ink annotations + */ + public function setInkAnnotations($inkAnnotations) + { + $this->inkAnnotations = $inkAnnotations === null ? true : $inkAnnotations; + } +} diff --git a/src/PhpWord/Metadata/Settings.php b/src/PhpWord/Metadata/Settings.php index d1d1f0ce..9b2c2285 100644 --- a/src/PhpWord/Metadata/Settings.php +++ b/src/PhpWord/Metadata/Settings.php @@ -14,9 +14,12 @@ * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ - namespace PhpOffice\PhpWord\Metadata; +use PhpOffice\PhpWord\ComplexType\ProofState; +use PhpOffice\PhpWord\SimpleType\Zoom; +use PhpOffice\PhpWord\ComplexType\TrackChangesView; + /** * Setting class * @@ -26,24 +29,67 @@ namespace PhpOffice\PhpWord\Metadata; class Settings { + /** + * Magnification Setting + * + * @link http://www.datypic.com/sc/ooxml/e-w_zoom-1.html + * @var mixed either integer, in which case it treated as a percent, or one of PhpOffice\PhpWord\SimpleType\Zoom + */ + private $zoom = 100; + /** * Hide spelling errors - * + * * @var boolean */ private $hideSpellingErrors = false; /** * Hide grammatical errors - * + * * @var boolean */ private $hideGrammaticalErrors = false; + /** + * Visibility of Annotation Types + * + * @var TrackChangesView + */ + private $revisionView; + + /** + * Track Revisions to Document + * + * @var boolean + */ + private $trackRevisions = false; + + /** + * Do Not Use Move Syntax When Tracking Revisions + * + * @var boolean + */ + private $doNotTrackMoves = false; + + /** + * Do Not Track Formatting Revisions When Tracking Revisions + * + * @var boolean + */ + private $doNotTrackFormatting = false; + + /** + * Spelling and Grammatical Checking State + * + * @var \PhpOffice\PhpWord\Metadata\ProofState + */ + private $proofState; + /** * Document Editing Restrictions - * - * @var PhpOffice\PhpWord\Metadata\Protection + * + * @var \PhpOffice\PhpWord\Metadata\Protection */ private $documentProtection; @@ -54,6 +100,13 @@ class Settings */ private $evenAndOddHeaders = false; + /** + * Radix Point for Field Code Evaluation + * + * @var string + */ + private $decimalSymbol = '.'; + /** * @return Protection */ @@ -73,6 +126,25 @@ class Settings $this->documentProtection = $documentProtection; } + /** + * @return ProofState + */ + public function getProofState() + { + if ($this->proofState == null) { + $this->proofState = new ProofState(); + } + return $this->proofState; + } + + /** + * @param ProofState $proofState + */ + public function setProofState($proofState) + { + $this->proofState = $proofState; + } + /** * Are spelling errors hidden * @@ -128,4 +200,114 @@ class Settings { $this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders; } + + /** + * Get the Visibility of Annotation Types + * + * @return \PhpOffice\PhpWord\ComplexType\TrackChangesView + */ + public function getRevisionView() + { + return $this->revisionView; + } + + /** + * Set the Visibility of Annotation Types + * + * @param TrackChangesView $trackChangesView + */ + public function setRevisionView(TrackChangesView $trackChangesView = null) + { + $this->revisionView = $trackChangesView; + } + + /** + * @return boolean + */ + public function hasTrackRevisions() + { + return $this->trackRevisions; + } + + /** + * @param boolean $trackRevisions + */ + public function setTrackRevisions($trackRevisions) + { + $this->trackRevisions = $trackRevisions === null ? true : $trackRevisions; + } + + /** + * @return boolean + */ + public function hasDoNotTrackMoves() + { + return $this->doNotTrackMoves; + } + + /** + * @param boolean $doNotTrackMoves + */ + public function setDoNotTrackMoves($doNotTrackMoves) + { + $this->doNotTrackMoves = $doNotTrackMoves === null ? true : $doNotTrackMoves; + } + + /** + * @return boolean + */ + public function hasDoNotTrackFormatting() + { + return $this->doNotTrackFormatting; + } + + /** + * @param boolean $doNotTrackFormatting + */ + public function setDoNotTrackFormatting($doNotTrackFormatting) + { + $this->doNotTrackFormatting = $doNotTrackFormatting === null ? true : $doNotTrackFormatting; + } + + /** + * @return mixed + */ + public function getZoom() + { + return $this->zoom; + } + + /** + * @param mixed $zoom + */ + public function setZoom($zoom) + { + if (is_numeric($zoom)) { + // zoom is a percentage + $this->zoom = $zoom; + } else { + Zoom::validate($zoom); + $this->zoom = $zoom; + } + } + + /** + * Returns the Radix Point for Field Code Evaluation + * + * @return string + */ + public function getDecimalSymbol() + { + return $this->decimalSymbol; + } + + /** + * sets the Radix Point for Field Code Evaluation + * + * @param string $decimalSymbol + */ + public function setDecimalSymbol($decimalSymbol) + { + $this->decimalSymbol = $decimalSymbol; + } } diff --git a/src/PhpWord/Reader/Word2007/Settings.php b/src/PhpWord/Reader/Word2007/Settings.php index df0d6dcf..d2ffc1f3 100644 --- a/src/PhpWord/Reader/Word2007/Settings.php +++ b/src/PhpWord/Reader/Word2007/Settings.php @@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Reader\Word2007; use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\ComplexType\TrackChangesView; /** * Settings reader @@ -28,7 +29,7 @@ use PhpOffice\PhpWord\PhpWord; class Settings extends AbstractPart { - private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'evenAndOddHeaders'); + private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'trackRevisions', 'doNotTrackMoves', 'doNotTrackFormatting', 'evenAndOddHeaders'); /** * Read settings.xml. @@ -58,7 +59,7 @@ class Settings extends AbstractPart } } else if (method_exists($this, $method)) { $this->$method($xmlReader, $phpWord, $node); - } else if (method_exists($this, $method)) { + } else if (method_exists($docSettings, $method)) { $docSettings->$method($value); } } @@ -79,4 +80,61 @@ class Settings extends AbstractPart $edit = $xmlReader->getAttribute('w:edit', $node); $documentProtection->setEditing($edit); } + + /** + * Sets the proof state + * + * @param XMLReader $xmlReader + * @param PhpWord $phpWord + * @param \DOMNode $node + */ + protected function setProofState(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node) + { + $proofState = $phpWord->getSettings()->getProofState(); + + $spelling = $xmlReader->getAttribute('w:spelling', $node); + $grammar = $xmlReader->getAttribute('w:grammar', $node); + + if ($spelling != null) { + $proofState->setSpelling($spelling); + } + if ($grammar != null) { + $proofState->setGrammar($grammar); + } + } + + /** + * Sets the proof state + * + * @param XMLReader $xmlReader + * @param PhpWord $phpWord + * @param \DOMNode $node + */ + protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node) + { + $percent = $xmlReader->getAttribute('w:percent', $node); + $val = $xmlReader->getAttribute('w:val', $node); + + if ($percent != null || $val != null) { + $phpWord->getSettings()->setZoom($percent == null ? $val : $percent); + } + } + + /** + * Set the Revision view + * + * @param XMLReader $xmlReader + * @param PhpWord $phpWord + * @param \DOMNode $node + */ + protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMNode $node) + { + $revisionView = new TrackChangesView(); + $revisionView->setMarkup($xmlReader->getAttribute('w:markup', $node)); + $revisionView->setComments($xmlReader->getAttribute('w:comments', $node)); + $revisionView->setInsDel($xmlReader->getAttribute('w:insDel', $node)); + $revisionView->setFormatting($xmlReader->getAttribute('w:formatting', $node)); + $revisionView->setInkAnnotations($xmlReader->getAttribute('w:inkAnnotations', $node)); + $phpWord->getSettings()->setRevisionView($revisionView); + } } diff --git a/src/PhpWord/SimpleType/Zoom.php b/src/PhpWord/SimpleType/Zoom.php new file mode 100644 index 00000000..3b78fdf9 --- /dev/null +++ b/src/PhpWord/SimpleType/Zoom.php @@ -0,0 +1,42 @@ +getParentWriter()->getPhpWord()->getSettings(); + // Default settings $this->settings = array( - 'w:zoom' => array('@attributes' => array('w:percent' => '100')), 'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')), 'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')), 'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')), 'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')), - 'w:decimalSymbol' => array('@attributes' => array('w:val' => '.')), + 'w:decimalSymbol' => array('@attributes' => array('w:val' => $documentSettings->getDecimalSymbol())), 'w:listSeparator' => array('@attributes' => array('w:val' => ';')), 'w:compat' => array(), 'm:mathPr' => array( @@ -140,15 +145,17 @@ class Settings extends AbstractPart ), ); - /** @var \PhpOffice\PhpWord\Metadata\Settings $documentSettings */ - $documentSettings = $this->getParentWriter()->getPhpWord()->getSettings(); - $this->setOnOffValue('w:hideSpellingErrors', $documentSettings->hasHideSpellingErrors()); $this->setOnOffValue('w:hideGrammaticalErrors', $documentSettings->hasHideGrammaticalErrors()); + $this->setOnOffValue('w:trackRevisions', $documentSettings->hasTrackRevisions()); + $this->setOnOffValue('w:doNotTrackMoves', $documentSettings->hasDoNotTrackMoves()); + $this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting()); $this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders()); - // Other settings + $this->setRevisionView($documentSettings->getRevisionView()); $this->setDocumentProtection($documentSettings->getDocumentProtection()); + $this->setProofState($documentSettings->getProofState()); + $this->setZoom($documentSettings->getZoom()); $this->getCompatibility(); } @@ -161,7 +168,11 @@ class Settings extends AbstractPart private function setOnOffValue($settingName, $booleanValue) { if ($booleanValue !== null && is_bool($booleanValue)) { - $this->settings[$settingName] = array('@attributes' => array('w:val' => $booleanValue ? 'true': 'false')); + if ($booleanValue) { + $this->settings[$settingName] = array('@attributes' => array()); + } else { + $this->settings[$settingName] = array('@attributes' => array('w:val' => 'false')); + } } } @@ -183,6 +194,55 @@ class Settings extends AbstractPart } } + /** + * Set the Proof state + * + * @param ProofState $proofState + */ + private function setProofState(ProofState $proofState = null) + { + if ($proofState != null && $proofState->getGrammar() !== null && $proofState->getSpelling() !== null) { + $this->settings['w:proofState'] = array( + '@attributes' => array( + 'w:spelling' => $proofState->getSpelling(), + 'w:grammar' => $proofState->getGrammar() + ) + ); + } + } + + /** + * Set the Proof state + * + * @param ProofState $proofState + */ + private function setRevisionView(TrackChangesView $trackChangesView = null) + { + if ($trackChangesView != null) { + + $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true': 'false'; + $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true': 'false'; + $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true': 'false'; + $revisionView['w:formatting'] = $trackChangesView->hasFormatting() ? 'true': 'false'; + $revisionView['w:inkAnnotations'] = $trackChangesView->hasInkAnnotations() ? 'true': 'false'; + + $this->settings['w:revisionView'] = array('@attributes' => $revisionView); + } + } + + /** + * Set the magnification + * + * @param mixed $zoom + */ + private function setZoom($zoom = null) + { + if ($zoom !== null) { + $attr = is_int($zoom) ? 'w:percent' : 'w:val'; + $this->settings['w:zoom'] = array('@attributes' => array($attr => $zoom)); + } + } + /** * Get compatibility setting. * diff --git a/tests/PhpWord/Metadata/SettingsTest.php b/tests/PhpWord/Metadata/SettingsTest.php index 35c15edd..fff51652 100644 --- a/tests/PhpWord/Metadata/SettingsTest.php +++ b/tests/PhpWord/Metadata/SettingsTest.php @@ -17,6 +17,9 @@ namespace PhpOffice\PhpWord\Metadata; +use PhpOffice\PhpWord\ComplexType\ProofState; +use PhpOffice\PhpWord\SimpleType\Zoom; + /** * Test class for PhpOffice\PhpWord\Metadata\Settings * @@ -66,4 +69,70 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $oSettings->getDocumentProtection()->setEditing('trackedChanges'); $this->assertEquals('trackedChanges', $oSettings->getDocumentProtection()->getEditing()); } + + /** + * TrackRevistions + */ + public function testTrackRevisions() + { + $oSettings = new Settings(); + $oSettings->setTrackRevisions(true); + $this->assertEquals(true, $oSettings->hasTrackRevisions()); + } + + /** + * DoNotTrackFormatting + */ + public function testDoNotTrackFormatting() + { + $oSettings = new Settings(); + $oSettings->setDoNotTrackFormatting(true); + $this->assertEquals(true, $oSettings->hasDoNotTrackFormatting()); + } + + /** + * DoNotTrackMoves + */ + public function testDoNotTrackMoves() + { + $oSettings = new Settings(); + $oSettings->setDoNotTrackMoves(true); + $this->assertEquals(true, $oSettings->hasDoNotTrackMoves()); + } + + /** + * ProofState + */ + public function testProofState() + { + $proofState = new ProofState(); + $proofState->setGrammar(ProofState::CLEAN); + $proofState->setSpelling(ProofState::DIRTY); + + $oSettings = new Settings(); + $oSettings->setProofState($proofState); + $this->assertNotNull($oSettings->getProofState()); + $this->assertEquals(ProofState::CLEAN, $oSettings->getProofState()->getGrammar()); + $this->assertEquals(ProofState::DIRTY, $oSettings->getProofState()->getSpelling()); + } + + /** + * Zoom as percentage + */ + public function testZoomPercentage() + { + $oSettings = new Settings(); + $oSettings->setZoom(75); + $this->assertEquals(75, $oSettings->getZoom()); + } + + /** + * Zoom as string + */ + public function testZoomEnum() + { + $oSettings = new Settings(); + $oSettings->setZoom(Zoom::FULL_PAGE); + $this->assertEquals('fullPage', $oSettings->getZoom()); + } } diff --git a/tests/PhpWord/Reader/MsDocTest.php b/tests/PhpWord/Reader/MsDocTest.php new file mode 100644 index 00000000..b4173d17 --- /dev/null +++ b/tests/PhpWord/Reader/MsDocTest.php @@ -0,0 +1,59 @@ +assertTrue($object->canRead($filename)); + } + + /** + * Can read exception + */ + public function testCanReadFailed() + { + $object = new MsDoc(); + $filename = __DIR__ . '/../_files/documents/foo.doc'; + $this->assertFalse($object->canRead($filename)); + } + + /** + * Load + */ + public function testLoad() + { + $filename = __DIR__ . '/../_files/documents/reader.doc'; + $phpWord = IOFactory::load($filename, 'MsDoc'); + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord); + } +} diff --git a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php index fe6ea61c..828e1283 100644 --- a/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php @@ -19,6 +19,8 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\Settings; +use PhpOffice\PhpWord\SimpleType\Zoom; +use PhpOffice\PhpWord\ComplexType\TrackChangesView; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings @@ -102,7 +104,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertTrue($doc->elementExists($path, $file)); $element = $doc->getElement($path, $file); - $this->assertEquals('true', $element->getAttribute('w:val')); + $this->assertNotEquals('false', $element->getAttribute('w:val')); } /** @@ -121,6 +123,125 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertTrue($doc->elementExists($path, $file)); $element = $doc->getElement($path, $file); - $this->assertEquals('true', $element->getAttribute('w:val')); + $this->assertNotEquals('false', $element->getAttribute('w:val')); + } + + /** + * Test zoom percentage + */ + public function testZoomPercentage() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setZoom(75); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:zoom'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertEquals('75', $element->getAttribute('w:percent')); + } + + /** + * Test zoom value + */ + public function testZoomValue() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setZoom(Zoom::FULL_PAGE); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:zoom'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertEquals('fullPage', $element->getAttribute('w:val')); + } + + /** + * Test Revision View + */ + public function testRevisionView() + { + $trackChangesView = new TrackChangesView(); + $trackChangesView->setFormatting(false); + $trackChangesView->setComments(true); + + $phpWord = new PhpWord(); + $phpWord->getSettings()->setRevisionView($trackChangesView); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:revisionView'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertEquals('false', $element->getAttribute('w:formatting')); + $this->assertEquals('true', $element->getAttribute('w:comments')); + } + + /** + * Test track Revisions + */ + public function testTrackRevisions() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setTrackRevisions(true); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:trackRevisions'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertNotEquals('false', $element->getAttribute('w:val')); + } + + /** + * Test doNotTrackMoves + */ + public function testDoNotTrackMoves() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setDoNotTrackMoves(true); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:doNotTrackMoves'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertNotEquals('false', $element->getAttribute('w:val')); + } + + /** + * Test DoNotTrackFormatting + */ + public function testDoNotTrackFormatting() + { + $phpWord = new PhpWord(); + $phpWord->getSettings()->setDoNotTrackFormatting(true); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/settings.xml'; + + $path = '/w:settings/w:doNotTrackFormatting'; + $this->assertTrue($doc->elementExists($path, $file)); + + $element = $doc->getElement($path, $file); + $this->assertNotEquals('false', $element->getAttribute('w:val')); } } diff --git a/tests/PhpWord/_files/documents/reader.doc b/tests/PhpWord/_files/documents/reader.doc new file mode 100644 index 00000000..a5ce295d Binary files /dev/null and b/tests/PhpWord/_files/documents/reader.doc differ diff --git a/tests/PhpWord/_files/documents/reader.docx b/tests/PhpWord/_files/documents/reader.docx index d09091b1..ef6b6615 100644 Binary files a/tests/PhpWord/_files/documents/reader.docx and b/tests/PhpWord/_files/documents/reader.docx differ