Skip to content

Commit a6c6f9f

Browse files
committed
Merge branch 'development' into develop
Conflicts: tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
2 parents cbea5ae + f3f11cb commit a6c6f9f

File tree

21 files changed

+386
-115
lines changed

21 files changed

+386
-115
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ composer.lock
1212
composer.phar
1313
vendor
1414
/report
15+
/build
1516
/samples/resources
1617
/samples/results
1718
/.settings

docs/general.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ Zip class
109109
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
110110
to deal with ZIP compressed archives and files inside them. If you can't have
111111
Zip extension installed on your server, you can use pure PHP library
112-
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which
113-
included with PHPWord.
112+
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which is
113+
included in PHPWord.
114114

115115
.. code-block:: php
116116
@@ -130,6 +130,17 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
130130
131131
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
132132
133+
Spelling and grammatical checks
134+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135+
136+
By default spelling and grammatical errors are shown as soon as you open a word document.
137+
For big documents this can slow down the opening of the document. You can hide the spelling and/or grammatical errors with:
138+
139+
.. code-block:: php
140+
141+
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
142+
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
143+
133144
Default font
134145
~~~~~~~~~~~~
135146

docs/styles.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
7777
- ``spaceAfter``. Space after paragraph.
7878
- ``tabs``. Set of custom tab stops.
7979
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
80+
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
8081

8182
.. _table-style:
8283

samples/Sample_06_Footnote.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
2+
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
3+
use PhpOffice\PhpWord\SimpleType\NumberFormat;
34

45
include_once 'Sample_Header.php';
56

@@ -50,7 +51,7 @@
5051
$footnote->addText('The reference for this is wrapped in its own line');
5152

5253
$footnoteProperties = new FootnoteProperties();
53-
$footnoteProperties->setNumFmt(FootnoteProperties::NUMBER_FORMAT_UPPER_ROMAN);
54+
$footnoteProperties->setNumFmt(NumberFormat::DECIMAL_ENCLOSED_CIRCLE);
5455
$section->setFootnoteProperties($footnoteProperties);
5556

5657
// Save file

samples/Sample_09_Tables.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,22 @@
107107
$section->addPageBreak();
108108
$section->addText('Table with colspan and rowspan', $header);
109109

110-
$styleTable = ['borderSize' => 6, 'borderColor' => '999999'];
110+
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
111111
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
112112
$table = $section->addTable('Colspan Rowspan');
113113

114114
$row = $table->addRow();
115115

116-
$row->addCell(null, ['vMerge' => 'restart'])->addText('A');
117-
$row->addCell(null, ['gridSpan' => 2, 'vMerge' => 'restart',])->addText('B');
116+
$row->addCell(null, array('vMerge' => 'restart'))->addText('A');
117+
$row->addCell(null, array('gridSpan' => 2, 'vMerge' => 'restart',))->addText('B');
118118
$row->addCell()->addText('1');
119119

120120
$row = $table->addRow();
121-
$row->addCell(null, ['vMerge' => 'continue']);
122-
$row->addCell(null, ['vMerge' => 'continue','gridSpan' => 2,]);
121+
$row->addCell(null, array('vMerge' => 'continue'));
122+
$row->addCell(null, array('vMerge' => 'continue','gridSpan' => 2,));
123123
$row->addCell()->addText('2');
124124
$row = $table->addRow();
125-
$row->addCell(null, ['vMerge' => 'continue']);
125+
$row->addCell(null, array('vMerge' => 'continue'));
126126
$row->addCell()->addText('C');
127127
$row->addCell()->addText('D');
128128
$row->addCell()->addText('3');

src/PhpWord/SimpleType/FootnoteProperties.php renamed to src/PhpWord/ComplexType/FootnoteProperties.php

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* @copyright 2010-2016 PHPWord contributors
1515
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
1616
*/
17-
namespace PhpOffice\PhpWord\SimpleType;
17+
namespace PhpOffice\PhpWord\ComplexType;
18+
19+
use PhpOffice\PhpWord\SimpleType\NumberFormat;
1820

1921
/**
2022
* Footnote properties
@@ -28,17 +30,6 @@ final class FootnoteProperties
2830
const RESTART_NUMBER_EACH_SECTION = 'eachSect';
2931
const RESTART_NUMBER_EACH_PAGE = 'eachPage';
3032

31-
const NUMBER_FORMAT_DECIMAL = 'decimal';
32-
const NUMBER_FORMAT_UPPER_ROMAN = 'upperRoman';
33-
const NUMBER_FORMAT_LOWER_ROMAN = 'lowerRoman';
34-
const NUMBER_FORMAT_UPPER_LETTER = 'upperLetter';
35-
const NUMBER_FORMAT_LOWER_LETTER = 'lowerLetter';
36-
const NUMBER_FORMAT_ORDINAL = 'ordinal';
37-
const NUMBER_FORMAT_CARDINAL_TEXT = 'cardinalText';
38-
const NUMBER_FORMAT_ORDINAL_TEXT = 'ordinalText';
39-
const NUMBER_FORMAT_NONE = 'none';
40-
const NUMBER_FORMAT_BULLET = 'bullet';
41-
4233
const POSITION_PAGE_BOTTOM = 'pageBottom';
4334
const POSITION_BENEATH_TEXT = 'beneathText';
4435
const POSITION_SECTION_END = 'sectEnd';
@@ -52,7 +43,7 @@ final class FootnoteProperties
5243
private $pos;
5344

5445
/**
55-
* Footnote Numbering Format
46+
* Footnote Numbering Format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
5647
*
5748
* @var string
5849
*/
@@ -61,7 +52,7 @@ final class FootnoteProperties
6152
/**
6253
* Footnote and Endnote Numbering Starting Value
6354
*
64-
* @var decimal
55+
* @var double
6556
*/
6657
private $numStart;
6758

@@ -72,11 +63,23 @@ final class FootnoteProperties
7263
*/
7364
private $numRestart;
7465

66+
/**
67+
* Get the Footnote Positioning Location
68+
*
69+
* @return string
70+
*/
7571
public function getPos()
7672
{
7773
return $this->pos;
7874
}
7975

76+
/**
77+
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
78+
*
79+
* @param string $pos
80+
* @throws \InvalidArgumentException
81+
* @return self
82+
*/
8083
public function setPos($pos)
8184
{
8285
$position = array(
@@ -91,50 +94,71 @@ public function setPos($pos)
9194
} else {
9295
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $position) . " possible");
9396
}
97+
return $this;
9498
}
9599

100+
/**
101+
* Get the Footnote Numbering Format
102+
*
103+
* @return string
104+
*/
96105
public function getNumFmt()
97106
{
98107
return $this->numFmt;
99108
}
100109

110+
/**
111+
* Set the Footnote Numbering Format
112+
*
113+
* @param string $numFmt One of NumberFormat
114+
* @return self
115+
*/
101116
public function setNumFmt($numFmt)
102117
{
103-
$numberFormat = array(
104-
self::NUMBER_FORMAT_DECIMAL,
105-
self::NUMBER_FORMAT_UPPER_ROMAN,
106-
self::NUMBER_FORMAT_LOWER_ROMAN,
107-
self::NUMBER_FORMAT_UPPER_LETTER,
108-
self::NUMBER_FORMAT_LOWER_LETTER,
109-
self::NUMBER_FORMAT_ORDINAL,
110-
self::NUMBER_FORMAT_CARDINAL_TEXT,
111-
self::NUMBER_FORMAT_ORDINAL_TEXT,
112-
self::NUMBER_FORMAT_NONE,
113-
self::NUMBER_FORMAT_BULLET
114-
);
115-
116-
if (in_array($numFmt, $numberFormat)) {
117-
$this->numFmt = $numFmt;
118-
} else {
119-
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $numberFormat) . " possible");
120-
}
118+
NumberFormat::validate($numFmt);
119+
$this->numFmt = $numFmt;
120+
return $this;
121121
}
122122

123+
/**
124+
* Get the Footnote Numbering Format
125+
*
126+
* @return double
127+
*/
123128
public function getNumStart()
124129
{
125130
return $this->numStart;
126131
}
127132

133+
/**
134+
* Set the Footnote Numbering Format
135+
*
136+
* @param double $numStart
137+
* @return self
138+
*/
128139
public function setNumStart($numStart)
129140
{
130141
$this->numStart = $numStart;
142+
return $this;
131143
}
132144

145+
/**
146+
* Get the Footnote and Endnote Numbering Starting Value
147+
*
148+
* @return string
149+
*/
133150
public function getNumRestart()
134151
{
135152
return $this->numRestart;
136153
}
137154

155+
/**
156+
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
157+
*
158+
* @param string $numRestart
159+
* @throws \InvalidArgumentException
160+
* @return self
161+
*/
138162
public function setNumRestart($numRestart)
139163
{
140164
$restartNumbers = array(
@@ -148,5 +172,6 @@ public function setNumRestart($numRestart)
148172
} else {
149173
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $restartNumbers) . " possible");
150174
}
175+
return $this;
151176
}
152177
}

src/PhpWord/Element/Section.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
2021
use PhpOffice\PhpWord\Style\Section as SectionStyle;
21-
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
2222

2323
class Section extends AbstractContainer
2424
{

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,11 @@ protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, $pa
167167
$parent->addTextBreak(null, $paragraphStyle);
168168
} else {
169169
$nodes = $xmlReader->getElements('*', $domNode);
170+
if ($runLinkCount > 1) {
171+
$parent = $parent->addTextRun($paragraphStyle);
172+
}
170173
foreach ($nodes as $node) {
171-
$this->readRun(
172-
$xmlReader,
173-
$node,
174-
($runLinkCount > 1) ? $parent->addTextRun($paragraphStyle) : $parent,
175-
$docPart,
176-
$paragraphStyle
177-
);
174+
$this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle);
178175
}
179176
}
180177
}

src/PhpWord/Reader/Word2007/Document.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode)
113113
'orientation' => array(self::READ_VALUE, 'w:pgSz', 'w:orient'),
114114
'colsNum' => array(self::READ_VALUE, 'w:cols', 'w:num'),
115115
'colsSpace' => array(self::READ_VALUE, 'w:cols', 'w:space'),
116-
'topMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:top'),
117-
'leftMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:left'),
118-
'bottomMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'),
119-
'rightMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:right'),
116+
'marginTop' => array(self::READ_VALUE, 'w:pgMar', 'w:top'),
117+
'marginLeft' => array(self::READ_VALUE, 'w:pgMar', 'w:left'),
118+
'marginBottom' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'),
119+
'marginRight' => array(self::READ_VALUE, 'w:pgMar', 'w:right'),
120120
'headerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:header'),
121121
'footerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:footer'),
122122
'gutter' => array(self::READ_VALUE, 'w:pgMar', 'w:gutter'),

src/PhpWord/Shared/AbstractEnum.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace PhpOffice\PhpWord\Shared;
3+
4+
abstract class AbstractEnum
5+
{
6+
7+
private static $constCacheArray = null;
8+
9+
private static function getConstants()
10+
{
11+
if (self::$constCacheArray == null) {
12+
self::$constCacheArray = array();
13+
}
14+
$calledClass = get_called_class();
15+
if (! array_key_exists($calledClass, self::$constCacheArray)) {
16+
$reflect = new \ReflectionClass($calledClass);
17+
self::$constCacheArray[$calledClass] = $reflect->getConstants();
18+
}
19+
return self::$constCacheArray[$calledClass];
20+
}
21+
22+
public static function values()
23+
{
24+
return array_values(self::getConstants());
25+
}
26+
27+
public static function validate($value)
28+
{
29+
$values = array_values(self::getConstants());
30+
if (!in_array($value, $values, true)) {
31+
$calledClass = get_called_class();
32+
throw new \InvalidArgumentException("$value is not a valid value for $calledClass, possible values are " . implode(', ', $values));
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)