add reader/writer for additional values in settings.xml (#1098)

* add reader/writer for settings.xml
The following values can currently be set/read
- w:trackRevisions
- w:doNotTrackMoves
- w:doNotTrackFormatting
- w:proofState
- w:zoom
- w:decimalSymbol
- w:revisionView
This commit is contained in:
troosan 2017-07-11 01:56:20 +02:00 committed by GitHub
parent 88cc13dd85
commit be6b6008e8
12 changed files with 935 additions and 38 deletions

View File

@ -80,8 +80,8 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
/* 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);

View File

@ -0,0 +1,104 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Spelling and Grammatical Checking State
*
* @see http://www.datypic.com/sc/ooxml/e-w_proofState-1.html
*/
final class ProofState
{
/**
* Check Completed
*/
const CLEAN = 'clean';
/**
* Check Not Completed
*/
const DIRTY = 'dirty';
/**
* Spell Checking State
*
* @var string
*/
private $spelling;
/**
* Grammatical Checking State
*
* @var string
*/
private $grammar;
/**
* Set the Spell Checking State (dirty or clean)
*
* @param string $spelling
* @throws \InvalidArgumentException
* @return self
*/
public function setSpelling($spelling)
{
if ($spelling == self::CLEAN || $spelling == self::DIRTY) {
$this->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;
}
}

View File

@ -0,0 +1,166 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Visibility of Annotation Types
*
* @see http://www.datypic.com/sc/ooxml/e-w_revisionView-1.html
*/
final class TrackChangesView
{
/**
* Display Visual Indicator Of Markup Area
*
* @var boolean
*/
private $markup;
/**
* Display Comments
*
* @var boolean
*/
private $comments;
/**
* Display Content Revisions
*
* @var boolean
*/
private $insDel;
/**
* Display Formatting Revisions
*
* @var boolean
*/
private $formatting;
/**
* Display Ink Annotations
*
* @var boolean
*/
private $inkAnnotations;
/**
* Get Display Visual Indicator Of Markup Area
*
* @return boolean True if markup is shown
*/
public function hasMarkup()
{
return $this->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;
}
}

View File

@ -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,6 +29,14 @@ 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
*
@ -40,10 +51,45 @@ class Settings
*/
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;
}
}

View File

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

View File

@ -0,0 +1,42 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Magnification Preset Values
*
* @since 0.14.0
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Zoom.html
*/
final class Zoom extends AbstractEnum
{
//No Preset Magnification
const NONE = 'none';
//Display One Full Page
const FULL_PAGE = 'fullPage';
//Display Page Width
const BEST_FIT = 'bestFit';
//Display Text Width
const TEXT_FIT = 'textFit';
}

View File

@ -18,6 +18,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Settings as DocumentSettings;
use PhpOffice\PhpWord\ComplexType\ProofState;
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
/**
* Word2007 settings part writer: word/settings.xml
@ -99,14 +101,17 @@ class Settings extends AbstractPart
*/
private function getSettings()
{
/** @var \PhpOffice\PhpWord\Metadata\Settings $documentSettings */
$documentSettings = $this->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.
*

View File

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

View File

@ -0,0 +1,59 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\IOFactory;
/**
* Test class for PhpOffice\PhpWord\Reader\MsDoc
*
* @coversDefaultClass \PhpOffice\PhpWord\Reader\MsDoc
* @runTestsInSeparateProcesses
*/
class MsDocTest extends \PHPUnit_Framework_TestCase
{
/**
* Test canRead() method
*/
public function testCanRead()
{
$object = new MsDoc();
$filename = __DIR__ . '/../_files/documents/reader.doc';
$this->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);
}
}

View File

@ -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'));
}
}

Binary file not shown.