Skip to content

Commit

Permalink
add reader/writer for additional values in settings.xml (#1098)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
troosan committed Jul 10, 2017
1 parent 88cc13d commit be6b600
Show file tree
Hide file tree
Showing 12 changed files with 934 additions and 37 deletions.
78 changes: 57 additions & 21 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -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
~~~~~~~~~~~~
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.

By default, every text appears in Arial 10 point. You can alter the
default font by using the following two functions:
.. code-block:: php
$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->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);
$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
--------------------
Expand Down Expand Up @@ -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);
104 changes: 104 additions & 0 deletions src/PhpWord/ComplexType/ProofState.php
Original file line number Diff line number Diff line change
@@ -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 https://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;

/**
* Spelling and Grammatical Checking State
*
* @see https://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;
}
}
166 changes: 166 additions & 0 deletions src/PhpWord/ComplexType/TrackChangesView.php
Original file line number Diff line number Diff line change
@@ -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 https://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;

/**
* Visibility of Annotation Types
*
* @see https://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;
}
}
Loading

0 comments on commit be6b600

Please sign in to comment.