Skip to content

Commit be6b600

Browse files
authored
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
1 parent 88cc13d commit be6b600

File tree

12 files changed

+934
-37
lines changed

12 files changed

+934
-37
lines changed

docs/general.rst

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
8080
/* Note: we skip RTF, because it's not XML-based and requires a different example. */
8181
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
8282
83-
Settings
84-
--------
83+
PHPWord Settings
84+
----------------
8585

8686
The ``PhpOffice\PhpWord\Settings`` class provides some options that will
8787
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
130130
131131
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
132132
133+
Default font
134+
~~~~~~~~~~~~
135+
136+
By default, every text appears in Arial 10 point. You can alter the
137+
default font by using the following two functions:
138+
139+
.. code-block:: php
140+
141+
$phpWord->setDefaultFontName('Times New Roman');
142+
$phpWord->setDefaultFontSize(12);
143+
144+
Document settings
145+
-----------------
146+
Settings for the generated document can be set using ``$phpWord->getSettings()``
147+
148+
Magnification Setting
149+
~~~~~~~~~~~~~~~~~~~~~
150+
The default zoom value is 100 percent. This can be changed either to another percentage
151+
152+
.. code-block:: php
153+
154+
$phpWord->getSettings()->setZoom(75);
155+
156+
Or to predefined values ``fullPage``, ``bestFit``, ``textFit``
157+
158+
.. code-block:: php
159+
160+
$phpWord->getSettings()->setZoom(Zoom::BEST_FIT);
161+
133162
Spelling and grammatical checks
134163
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135164

@@ -141,16 +170,36 @@ For big documents this can slow down the opening of the document. You can hide t
141170
$phpWord->getSettings()->setHideGrammaticalErrors(true);
142171
$phpWord->getSettings()->setHideSpellingErrors(true);
143172
144-
Default font
145-
~~~~~~~~~~~~
173+
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.
146174

147-
By default, every text appears in Arial 10 point. You can alter the
148-
default font by using the following two functions:
175+
.. code-block:: php
176+
177+
$proofState = new ProofState();
178+
$proofState->setGrammar(ProofState::CLEAN);
179+
$proofState->setSpelling(ProofState::DIRTY);
180+
181+
$phpWord->getSettings()->setProofState(proofState);
182+
183+
Track Revisions
184+
~~~~~~~~~~~~~~~
185+
Track changes can be activated using ``setTrackRevisions``, you can furture specify
186+
187+
- Not to use move syntax, instead moved items will be seen as deleted in one place and added in another
188+
- Not track formatting revisions
149189

150190
.. code-block:: php
151191
152-
$phpWord->setDefaultFontName('Times New Roman');
153-
$phpWord->setDefaultFontSize(12);
192+
$phpWord->getSettings()->setTrackRevisions(true);
193+
$phpWord->getSettings()->setDoNotTrackMoves(true);
194+
$phpWord->getSettings()->setDoNotTrackFormatting(true);
195+
196+
Decimal Symbol
197+
~~~~~~~~~~~~~~
198+
The default symbol to represent a decimal figure is the ``.`` in english. In french you might want to change it to ``,`` for instance.
199+
200+
.. code-block:: php
201+
202+
$phpWord->getSettings()->setDecimalSymbol(',');
154203
155204
Document information
156205
--------------------
@@ -194,16 +243,3 @@ points to twips.
194243
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
195244
// 2 cm right margin
196245
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
197-
198-
Language
199-
--------
200-
201-
You can hide spelling errors:
202-
203-
.. code-block:: php
204-
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
205-
206-
And hide grammatical errors:
207-
208-
.. code-block:: php
209-
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2016 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
namespace PhpOffice\PhpWord\ComplexType;
18+
19+
/**
20+
* Spelling and Grammatical Checking State
21+
*
22+
* @see http://www.datypic.com/sc/ooxml/e-w_proofState-1.html
23+
*/
24+
final class ProofState
25+
{
26+
27+
/**
28+
* Check Completed
29+
*/
30+
const CLEAN = 'clean';
31+
32+
/**
33+
* Check Not Completed
34+
*/
35+
const DIRTY = 'dirty';
36+
37+
/**
38+
* Spell Checking State
39+
*
40+
* @var string
41+
*/
42+
private $spelling;
43+
44+
/**
45+
* Grammatical Checking State
46+
*
47+
* @var string
48+
*/
49+
private $grammar;
50+
51+
/**
52+
* Set the Spell Checking State (dirty or clean)
53+
*
54+
* @param string $spelling
55+
* @throws \InvalidArgumentException
56+
* @return self
57+
*/
58+
public function setSpelling($spelling)
59+
{
60+
if ($spelling == self::CLEAN || $spelling == self::DIRTY) {
61+
$this->spelling = $spelling;
62+
} else {
63+
throw new \InvalidArgumentException("Invalid value, dirty or clean possible");
64+
}
65+
return $this;
66+
}
67+
68+
/**
69+
* Get the Spell Checking State
70+
*
71+
* @return string
72+
*/
73+
public function getSpelling()
74+
{
75+
return $this->spelling;
76+
}
77+
78+
/**
79+
* Set the Grammatical Checking State (dirty or clean)
80+
*
81+
* @param string $grammar
82+
* @throws \InvalidArgumentException
83+
* @return self
84+
*/
85+
public function setGrammar($grammar)
86+
{
87+
if ($grammar == self::CLEAN || $grammar == self::DIRTY) {
88+
$this->grammar = $grammar;
89+
} else {
90+
throw new \InvalidArgumentException("Invalid value, dirty or clean possible");
91+
}
92+
return $this;
93+
}
94+
95+
/**
96+
* Get the Grammatical Checking State
97+
*
98+
* @return string
99+
*/
100+
public function getGrammar()
101+
{
102+
return $this->grammar;
103+
}
104+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2016 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
namespace PhpOffice\PhpWord\ComplexType;
18+
19+
/**
20+
* Visibility of Annotation Types
21+
*
22+
* @see http://www.datypic.com/sc/ooxml/e-w_revisionView-1.html
23+
*/
24+
final class TrackChangesView
25+
{
26+
27+
/**
28+
* Display Visual Indicator Of Markup Area
29+
*
30+
* @var boolean
31+
*/
32+
private $markup;
33+
34+
/**
35+
* Display Comments
36+
*
37+
* @var boolean
38+
*/
39+
private $comments;
40+
41+
/**
42+
* Display Content Revisions
43+
*
44+
* @var boolean
45+
*/
46+
private $insDel;
47+
48+
/**
49+
* Display Formatting Revisions
50+
*
51+
* @var boolean
52+
*/
53+
private $formatting;
54+
55+
/**
56+
* Display Ink Annotations
57+
*
58+
* @var boolean
59+
*/
60+
private $inkAnnotations;
61+
62+
/**
63+
* Get Display Visual Indicator Of Markup Area
64+
*
65+
* @return boolean True if markup is shown
66+
*/
67+
public function hasMarkup()
68+
{
69+
return $this->markup;
70+
}
71+
72+
/**
73+
* Set Display Visual Indicator Of Markup Area
74+
*
75+
* @param boolean $markup
76+
* Set to true to show markup
77+
*/
78+
public function setMarkup($markup)
79+
{
80+
$this->markup = $markup === null ? true : $markup;
81+
}
82+
83+
/**
84+
* Get Display Comments
85+
*
86+
* @return boolean True if comments are shown
87+
*/
88+
public function hasComments()
89+
{
90+
return $this->comments;
91+
}
92+
93+
/**
94+
* Set Display Comments
95+
*
96+
* @param boolean $comments
97+
* Set to true to show comments
98+
*/
99+
public function setComments($comments)
100+
{
101+
$this->comments = $comments === null ? true : $comments;
102+
}
103+
104+
/**
105+
* Get Display Content Revisions
106+
*
107+
* @return boolean True if content revisions are shown
108+
*/
109+
public function hasInsDel()
110+
{
111+
return $this->insDel;
112+
}
113+
114+
/**
115+
* Set Display Content Revisions
116+
*
117+
* @param boolean $insDel
118+
* Set to true to show content revisions
119+
*/
120+
public function setInsDel($insDel)
121+
{
122+
$this->insDel = $insDel === null ? true : $insDel;
123+
}
124+
125+
/**
126+
* Get Display Formatting Revisions
127+
*
128+
* @return boolean True if formatting revisions are shown
129+
*/
130+
public function hasFormatting()
131+
{
132+
return $this->formatting;
133+
}
134+
135+
/**
136+
* Set Display Formatting Revisions
137+
*
138+
* @param boolean $insDel
139+
* Set to true to show formatting revisions
140+
*/
141+
public function setFormatting($formatting)
142+
{
143+
$this->formatting = $formatting === null ? true : $formatting;
144+
}
145+
146+
/**
147+
* Get Display Ink Annotations
148+
*
149+
* @return boolean True if ink annotations are shown
150+
*/
151+
public function hasInkAnnotations()
152+
{
153+
return $this->inkAnnotations;
154+
}
155+
156+
/**
157+
* Set Display Ink Annotations
158+
*
159+
* @param boolean $inkAnnotations
160+
* Set to true to show ink annotations
161+
*/
162+
public function setInkAnnotations($inkAnnotations)
163+
{
164+
$this->inkAnnotations = $inkAnnotations === null ? true : $inkAnnotations;
165+
}
166+
}

0 commit comments

Comments
 (0)