Skip to content

Commit 18664fb

Browse files
authored
Merge branch 'develop' into patch-1
2 parents e9a4251 + 5b34391 commit 18664fb

File tree

9 files changed

+106
-46
lines changed

9 files changed

+106
-46
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ matrix:
1919
env: COVERAGE=1
2020
- php: 5.3
2121
dist: precise
22-
env: COMPOSER_MEMORY_LIMIT=2G
22+
env: COMPOSER_MEMORY_LIMIT=3G
2323
- php: 7.3
2424
env: DEPENDENCIES="--ignore-platform-reqs"
2525
exclude:
@@ -38,6 +38,7 @@ env:
3838

3939
before_install:
4040
## Packages
41+
- sudo rm -f /etc/apt/sources.list.d/mongodb.list # Makes apt crash on Precise, and we don't need MongoDB
4142
- sudo apt-get update -qq
4243
- sudo apt-get install -y graphviz
4344

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Develop:
1717

1818
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF.
1919

20-
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/).
20+
PHPWord is an open source project licensed under the terms of [LGPL version 3](COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/).
2121

2222
If you have any questions, please ask on [StackOverFlow](https://stackoverflow.com/questions/tagged/phpword)
2323

@@ -174,7 +174,7 @@ You can also read the [Developers' Documentation](http://phpword.readthedocs.org
174174

175175
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
176176

177-
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md).
177+
- Read [our contributing guide](CONTRIBUTING.md).
178178
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch.
179179
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub.
180180
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter.

phpmd.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
2020
<!-- AbstractContainer needs more coupling (default: 13) -->
2121
<properties>
22-
<property name="minimum" value="20" />
22+
<property name="maximum" value="20" />
2323
</properties>
2424
</rule>
2525
<rule ref="rulesets/design.xml/NumberOfChildren">

src/PhpWord/Element/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function checkValidity($method)
254254
// Special condition, e.g. preservetext can only exists in cell when
255255
// the cell is located in header or footer
256256
$validSubcontainers = array(
257-
'PreserveText' => array(array('Cell'), array('Header', 'Footer')),
257+
'PreserveText' => array(array('Cell'), array('Header', 'Footer', 'Section')),
258258
'Footnote' => array(array('Cell', 'TextRun'), array('Section')),
259259
'Endnote' => array(array('Cell', 'TextRun'), array('Section')),
260260
);

src/PhpWord/Shared/Html.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
*/
3333
class Html
3434
{
35-
private static $listIndex = 0;
36-
private static $xpath;
37-
private static $options;
35+
protected static $listIndex = 0;
36+
protected static $xpath;
37+
protected static $options;
3838

3939
/**
4040
* Add HTML parts.
@@ -203,7 +203,7 @@ protected static function parseNode($node, $element, $styles = array(), $data =
203203
* @param array $styles
204204
* @param array $data
205205
*/
206-
private static function parseChildNodes($node, $element, $styles, $data)
206+
protected static function parseChildNodes($node, $element, $styles, $data)
207207
{
208208
if ('li' != $node->nodeName) {
209209
$cNodes = $node->childNodes;
@@ -225,7 +225,7 @@ private static function parseChildNodes($node, $element, $styles, $data)
225225
* @param array &$styles
226226
* @return \PhpOffice\PhpWord\Element\TextRun
227227
*/
228-
private static function parseParagraph($node, $element, &$styles)
228+
protected static function parseParagraph($node, $element, &$styles)
229229
{
230230
$styles['paragraph'] = self::recursiveParseStylesInHierarchy($node, $styles['paragraph']);
231231
$newElement = $element->addTextRun($styles['paragraph']);
@@ -244,7 +244,7 @@ private static function parseParagraph($node, $element, &$styles)
244244
* @todo Think of a clever way of defining header styles, now it is only based on the assumption, that
245245
* Heading1 - Heading6 are already defined somewhere
246246
*/
247-
private static function parseHeading($element, &$styles, $argument1)
247+
protected static function parseHeading($element, &$styles, $argument1)
248248
{
249249
$styles['paragraph'] = $argument1;
250250
$newElement = $element->addTextRun($styles['paragraph']);
@@ -259,7 +259,7 @@ private static function parseHeading($element, &$styles, $argument1)
259259
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
260260
* @param array &$styles
261261
*/
262-
private static function parseText($node, $element, &$styles)
262+
protected static function parseText($node, $element, &$styles)
263263
{
264264
$styles['font'] = self::recursiveParseStylesInHierarchy($node, $styles['font']);
265265

@@ -280,7 +280,7 @@ private static function parseText($node, $element, &$styles)
280280
* @param string $argument1 Style name
281281
* @param string $argument2 Style value
282282
*/
283-
private static function parseProperty(&$styles, $argument1, $argument2)
283+
protected static function parseProperty(&$styles, $argument1, $argument2)
284284
{
285285
$styles['font'][$argument1] = $argument2;
286286
}
@@ -291,7 +291,7 @@ private static function parseProperty(&$styles, $argument1, $argument2)
291291
* @param \DOMNode $node
292292
* @param array &$styles
293293
*/
294-
private static function parseSpan($node, &$styles)
294+
protected static function parseSpan($node, &$styles)
295295
{
296296
self::parseInlineStyle($node, $styles['font']);
297297
}
@@ -306,7 +306,7 @@ private static function parseSpan($node, &$styles)
306306
*
307307
* @todo As soon as TableItem, RowItem and CellItem support relative width and height
308308
*/
309-
private static function parseTable($node, $element, &$styles)
309+
protected static function parseTable($node, $element, &$styles)
310310
{
311311
$elementStyles = self::parseInlineStyle($node, $styles['table']);
312312

@@ -335,7 +335,7 @@ private static function parseTable($node, $element, &$styles)
335335
* @param array &$styles
336336
* @return Row $element
337337
*/
338-
private static function parseRow($node, $element, &$styles)
338+
protected static function parseRow($node, $element, &$styles)
339339
{
340340
$rowStyles = self::parseInlineStyle($node, $styles['row']);
341341
if ($node->parentNode->nodeName == 'thead') {
@@ -353,7 +353,7 @@ private static function parseRow($node, $element, &$styles)
353353
* @param array &$styles
354354
* @return \PhpOffice\PhpWord\Element\Cell|\PhpOffice\PhpWord\Element\TextRun $element
355355
*/
356-
private static function parseCell($node, $element, &$styles)
356+
protected static function parseCell($node, $element, &$styles)
357357
{
358358
$cellStyles = self::recursiveParseStylesInHierarchy($node, $styles['cell']);
359359

@@ -376,7 +376,7 @@ private static function parseCell($node, $element, &$styles)
376376
* @param \DOMNode $node
377377
* @return bool Returns true if the node contains an HTML element that cannot be added to TextRun
378378
*/
379-
private static function shouldAddTextRun(\DOMNode $node)
379+
protected static function shouldAddTextRun(\DOMNode $node)
380380
{
381381
$containsBlockElement = self::$xpath->query('.//table|./p|./ul|./ol', $node)->length > 0;
382382
if ($containsBlockElement) {
@@ -393,7 +393,7 @@ private static function shouldAddTextRun(\DOMNode $node)
393393
* @param \DOMNode $node
394394
* @param array &$styles
395395
*/
396-
private static function recursiveParseStylesInHierarchy(\DOMNode $node, array $style)
396+
protected static function recursiveParseStylesInHierarchy(\DOMNode $node, array $style)
397397
{
398398
$parentStyle = self::parseInlineStyle($node, array());
399399
$style = array_merge($parentStyle, $style);
@@ -412,7 +412,7 @@ private static function recursiveParseStylesInHierarchy(\DOMNode $node, array $s
412412
* @param array &$styles
413413
* @param array &$data
414414
*/
415-
private static function parseList($node, $element, &$styles, &$data)
415+
protected static function parseList($node, $element, &$styles, &$data)
416416
{
417417
$isOrderedList = $node->nodeName === 'ol';
418418
if (isset($data['listdepth'])) {
@@ -431,7 +431,7 @@ private static function parseList($node, $element, &$styles, &$data)
431431
* @param bool $isOrderedList
432432
* @return array
433433
*/
434-
private static function getListStyle($isOrderedList)
434+
protected static function getListStyle($isOrderedList)
435435
{
436436
if ($isOrderedList) {
437437
return array(
@@ -477,7 +477,7 @@ private static function getListStyle($isOrderedList)
477477
* @todo This function is almost the same like `parseChildNodes`. Merged?
478478
* @todo As soon as ListItem inherits from AbstractContainer or TextRun delete parsing part of childNodes
479479
*/
480-
private static function parseListItem($node, $element, &$styles, $data)
480+
protected static function parseListItem($node, $element, &$styles, $data)
481481
{
482482
$cNodes = $node->childNodes;
483483
if (!empty($cNodes)) {
@@ -495,7 +495,7 @@ private static function parseListItem($node, $element, &$styles, $data)
495495
* @param array $styles
496496
* @return array
497497
*/
498-
private static function parseStyle($attribute, $styles)
498+
protected static function parseStyle($attribute, $styles)
499499
{
500500
$properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;"));
501501

@@ -623,7 +623,7 @@ private static function parseStyle($attribute, $styles)
623623
*
624624
* @return \PhpOffice\PhpWord\Element\Image
625625
**/
626-
private static function parseImage($node, $element)
626+
protected static function parseImage($node, $element)
627627
{
628628
$style = array();
629629
$src = null;
@@ -726,7 +726,7 @@ private static function parseImage($node, $element)
726726
* @param string $cssBorderStyle
727727
* @return null|string
728728
*/
729-
private static function mapBorderStyle($cssBorderStyle)
729+
protected static function mapBorderStyle($cssBorderStyle)
730730
{
731731
switch ($cssBorderStyle) {
732732
case 'none':
@@ -739,7 +739,7 @@ private static function mapBorderStyle($cssBorderStyle)
739739
}
740740
}
741741

742-
private static function mapBorderColor(&$styles, $cssBorderColor)
742+
protected static function mapBorderColor(&$styles, $cssBorderColor)
743743
{
744744
$numColors = substr_count($cssBorderColor, '#');
745745
if ($numColors === 1) {
@@ -759,7 +759,7 @@ private static function mapBorderColor(&$styles, $cssBorderColor)
759759
* @param string $cssAlignment
760760
* @return string|null
761761
*/
762-
private static function mapAlign($cssAlignment)
762+
protected static function mapAlign($cssAlignment)
763763
{
764764
switch ($cssAlignment) {
765765
case 'right':
@@ -778,7 +778,7 @@ private static function mapAlign($cssAlignment)
778778
*
779779
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
780780
*/
781-
private static function parseLineBreak($element)
781+
protected static function parseLineBreak($element)
782782
{
783783
$element->addTextBreak();
784784
}
@@ -790,7 +790,7 @@ private static function parseLineBreak($element)
790790
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
791791
* @param array $styles
792792
*/
793-
private static function parseLink($node, $element, &$styles)
793+
protected static function parseLink($node, $element, &$styles)
794794
{
795795
$target = null;
796796
foreach ($node->attributes as $attribute) {

src/PhpWord/Style/ListItem.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ public function getNumId()
139139
return $this->numId;
140140
}
141141

142+
/**
143+
* Set numbering Id. Same numId means same list
144+
* @param mixed $numInt
145+
*/
146+
public function setNumId($numInt)
147+
{
148+
$this->numId = $numInt;
149+
$this->getListTypeStyle();
150+
}
151+
142152
/**
143153
* Get legacy numbering definition
144154
*
@@ -148,7 +158,12 @@ public function getNumId()
148158
private function getListTypeStyle()
149159
{
150160
// Check if legacy style already registered in global Style collection
151-
$numStyle = "PHPWordList{$this->listType}";
161+
$numStyle = 'PHPWordListType' . $this->listType;
162+
163+
if ($this->numId) {
164+
$numStyle .= 'NumId' . $this->numId;
165+
}
166+
152167
if (Style::getStyle($numStyle) !== null) {
153168
$this->setNumStyle($numStyle);
154169

src/PhpWord/Writer/Word2007/Element/ListItemRun.php

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
1919

20+
use PhpOffice\PhpWord\Element\ListItemRun as ListItemRunElement;
2021
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
2122

2223
/**
@@ -31,34 +32,56 @@ class ListItemRun extends AbstractElement
3132
*/
3233
public function write()
3334
{
34-
$xmlWriter = $this->getXmlWriter();
3535
$element = $this->getElement();
36-
if (!$element instanceof \PhpOffice\PhpWord\Element\ListItemRun) {
36+
37+
if (!$element instanceof ListItemRunElement) {
3738
return;
3839
}
3940

41+
$this->writeParagraph($element);
42+
}
43+
44+
private function writeParagraph(ListItemRunElement $element)
45+
{
46+
$xmlWriter = $this->getXmlWriter();
4047
$xmlWriter->startElement('w:p');
4148

49+
$this->writeParagraphProperties($element);
50+
51+
$containerWriter = new Container($xmlWriter, $element);
52+
$containerWriter->write();
53+
54+
$xmlWriter->endElement(); // w:p
55+
}
56+
57+
private function writeParagraphProperties(ListItemRunElement $element)
58+
{
59+
$xmlWriter = $this->getXmlWriter();
4260
$xmlWriter->startElement('w:pPr');
43-
$paragraphStyle = $element->getParagraphStyle();
44-
$styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle);
61+
62+
$styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle());
4563
$styleWriter->setIsInline(true);
64+
$styleWriter->setWithoutPPR(true);
4665
$styleWriter->write();
4766

48-
$xmlWriter->startElement('w:numPr');
49-
$xmlWriter->startElement('w:ilvl');
50-
$xmlWriter->writeAttribute('w:val', $element->getDepth());
51-
$xmlWriter->endElement(); // w:ilvl
52-
$xmlWriter->startElement('w:numId');
53-
$xmlWriter->writeAttribute('w:val', $element->getStyle()->getNumId());
54-
$xmlWriter->endElement(); // w:numId
55-
$xmlWriter->endElement(); // w:numPr
67+
$this->writeParagraphPropertiesNumbering($element);
5668

5769
$xmlWriter->endElement(); // w:pPr
70+
}
5871

59-
$containerWriter = new Container($xmlWriter, $element);
60-
$containerWriter->write();
72+
private function writeParagraphPropertiesNumbering(ListItemRunElement $element)
73+
{
74+
$xmlWriter = $this->getXmlWriter();
75+
$xmlWriter->startElement('w:numPr');
6176

62-
$xmlWriter->endElement(); // w:p
77+
$xmlWriter->writeElementBlock('w:ilvl', array(
78+
'w:val' => $element->getDepth(),
79+
));
80+
81+
$xmlWriter->writeElementBlock('w:numId', array(
82+
'w:val' => $element->getStyle()->getNumId(),
83+
));
84+
85+
$xmlWriter->endElement(); // w:numPr
6386
}
6487
}

tests/PhpWord/Element/CellTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testAddPreserveTextNotUTF8()
233233
public function testAddPreserveTextException()
234234
{
235235
$oCell = new Cell();
236-
$oCell->setDocPart('Section', 1);
236+
$oCell->setDocPart('TextRun', 1);
237237
$oCell->addPreserveText('text');
238238
}
239239

0 commit comments

Comments
 (0)