Skip to content

Commit c52c7ab

Browse files
authored
Merge branch 'develop' into rtfchanges
2 parents 122aaf1 + 733f845 commit c52c7ab

File tree

12 files changed

+162
-21
lines changed

12 files changed

+162
-21
lines changed

docs/elements.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th
359359

360360
.. code-block:: php
361361
362-
$fp = new PhpWord\SimpleType\FootnoteProperties();
362+
$fp = new \PhpOffice\PhpWord\ComplexType\FootnoteProperties();
363363
//sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd)
364-
$fp->setPos(FootnoteProperties::POSITION_DOC_END);
364+
$fp->setPos(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::POSITION_BENEATH_TEXT);
365365
//set the number format to use (decimal (default), upperRoman, upperLetter, ...)
366-
$fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN);
366+
$fp->setNumFmt(\PhpOffice\PhpWord\SimpleType\NumberFormat::LOWER_ROMAN);
367367
//force starting at other than 1
368368
$fp->setNumStart(2);
369369
//when to restart counting (continuous (default), eachSect, eachPage)
370-
$fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
370+
$fp->setNumRestart(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
371371
//And finaly, set it on the Section
372-
$section->setFootnoteProperties($properties);
372+
$section->setFootnoteProperties($fp);
373373
374374
Checkboxes
375375
----------

docs/styles.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ Available Paragraph style options:
7575
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
7676
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
7777
- ``basedOn``. Parent style.
78-
- ``hanging``. Hanging in *twip*.
79-
- ``indent``. Indent in *twip*.
78+
- ``hanging``. Hanging indentation in *half inches*.
79+
- ``indent``. Indent (left indentation) in *half inches*.
80+
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation.
81+
See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types.
8082
- ``keepLines``. Keep all lines on one page, *true* or *false*.
8183
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
8284
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.

docs/templates-processing.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Given a template containing
127127
This block content will be replaced
128128
${/block_name}
129129
130-
The following will replace everything between``${block_name}`` and ``${/block_name}`` with the value passed.
130+
The following will replace everything between ``${block_name}`` and ``${/block_name}`` with the value passed.
131131

132132
.. code-block:: php
133133
@@ -244,3 +244,20 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
244244
$table->addCell(150)->addText('Cell B2');
245245
$table->addCell(150)->addText('Cell B3');
246246
$templateProcessor->setComplexBlock('table', $table);
247+
248+
save
249+
"""""""""
250+
Saves the loaded template within the current directory. Returns the file path.
251+
252+
.. code-block:: php
253+
254+
$filepath = $templateProcessor->save();
255+
256+
saveAs
257+
"""""""""
258+
Saves a copy of the loaded template in the indicated path.
259+
260+
.. code-block:: php
261+
262+
$pathToSave = 'path/to/save/file.ext';
263+
$templateProcessor->saveAs($pathToSave);

src/PhpWord/Element/Section.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ public function getFooters()
146146
*
147147
* @return FootnoteProperties
148148
*/
149+
public function getFootnoteProperties()
150+
{
151+
return $this->footnoteProperties;
152+
}
153+
154+
/**
155+
* Get the footnote properties
156+
*
157+
* @deprecated Use the `getFootnoteProperties` method instead
158+
*
159+
* @return FootnoteProperties
160+
*/
149161
public function getFootnotePropoperties()
150162
{
151163
return $this->footnoteProperties;

src/PhpWord/Style/Paragraph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function setStyleValue($key, $value)
198198
{
199199
$key = Text::removeUnderscorePrefix($key);
200200
if ('indent' == $key || 'hanging' == $key) {
201-
$value = $value * 720;
201+
$value = $value * 720; // 720 twips is 0.5 inch
202202
}
203203

204204
return parent::setStyleValue($key, $value);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
* @see https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2018 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Writer\HTML\Element;
19+
20+
/**
21+
* ListItem element HTML writer
22+
*
23+
* @since 0.10.0
24+
*/
25+
class ListItemRun extends TextRun
26+
{
27+
/**
28+
* Write list item
29+
*
30+
* @return string
31+
*/
32+
public function write()
33+
{
34+
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItemRun) {
35+
return '';
36+
}
37+
38+
$writer = new Container($this->parentWriter, $this->element);
39+
$content = $writer->write() . PHP_EOL;
40+
41+
return $content;
42+
}
43+
}

src/PhpWord/Writer/Word2007/Part/Document.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,27 @@ private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)
126126
$xmlWriter->endElement();
127127
}
128128

129-
//footnote properties
130-
if ($section->getFootnotePropoperties() !== null) {
129+
// Footnote properties
130+
if ($section->getFootnoteProperties() !== null) {
131131
$xmlWriter->startElement('w:footnotePr');
132-
if ($section->getFootnotePropoperties()->getPos() != null) {
132+
if ($section->getFootnoteProperties()->getPos() != null) {
133133
$xmlWriter->startElement('w:pos');
134-
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getPos());
134+
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos());
135135
$xmlWriter->endElement();
136136
}
137-
if ($section->getFootnotePropoperties()->getNumFmt() != null) {
137+
if ($section->getFootnoteProperties()->getNumFmt() != null) {
138138
$xmlWriter->startElement('w:numFmt');
139-
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumFmt());
139+
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt());
140140
$xmlWriter->endElement();
141141
}
142-
if ($section->getFootnotePropoperties()->getNumStart() != null) {
142+
if ($section->getFootnoteProperties()->getNumStart() != null) {
143143
$xmlWriter->startElement('w:numStart');
144-
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumStart());
144+
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart());
145145
$xmlWriter->endElement();
146146
}
147-
if ($section->getFootnotePropoperties()->getNumRestart() != null) {
147+
if ($section->getFootnoteProperties()->getNumRestart() != null) {
148148
$xmlWriter->startElement('w:numRestart');
149-
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumRestart());
149+
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart());
150150
$xmlWriter->endElement();
151151
}
152152
$xmlWriter->endElement();

tests/PhpWord/MediaTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ public function testGetSectionMediaElementsWithNull()
3434
$this->assertEquals(array(), Media::getElements('section'));
3535
}
3636

37+
/**
38+
* Get header media elements
39+
*/
40+
public function testGetHeaderMediaElementsWithNull()
41+
{
42+
$this->assertEquals(array(), Media::getElements('header'));
43+
}
44+
45+
/**
46+
* Get footer media elements
47+
*/
48+
public function testGetFooterMediaElementsWithNull()
49+
{
50+
$this->assertEquals(array(), Media::getElements('footer'));
51+
}
52+
3753
/**
3854
* Count section media elements
3955
*/

tests/PhpWord/PhpWordTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,13 @@ public function testSortSections()
225225
$this->assertEquals(2, $phpWord->getSection(0)->countElements());
226226
$this->assertEquals(1, $phpWord->getSection(1)->countElements());
227227
}
228+
229+
/**
230+
* @covers \PhpOffice\PhpWord\PhpWord::getSettings
231+
*/
232+
public function testGetSettings()
233+
{
234+
$phpWord = new PhpWord();
235+
$this->assertInstanceOf('PhpOffice\\PhpWord\\Metadata\\Settings', $phpWord->getSettings());
236+
}
228237
}

tests/PhpWord/StyleTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class StyleTest extends \PHPUnit\Framework\TestCase
3333
* @covers ::addParagraphStyle
3434
* @covers ::addFontStyle
3535
* @covers ::addLinkStyle
36+
* @covers ::addNumberingStyle
3637
* @covers ::addTitleStyle
3738
* @covers ::addTableStyle
3839
* @covers ::setDefaultParagraphStyle
@@ -47,19 +48,34 @@ public function testStyles()
4748
$paragraph = array('alignment' => Jc::CENTER);
4849
$font = array('italic' => true, '_bold' => true);
4950
$table = array('bgColor' => 'CCCCCC');
51+
$numbering = array(
52+
'type' => 'multilevel',
53+
'levels' => array(
54+
array(
55+
'start' => 1,
56+
'format' => 'decimal',
57+
'restart' => 1,
58+
'suffix' => 'space',
59+
'text' => '%1.',
60+
'alignment' => Jc::START,
61+
),
62+
),
63+
);
64+
5065
$styles = array(
5166
'Paragraph' => 'Paragraph',
5267
'Font' => 'Font',
5368
'Link' => 'Font',
5469
'Table' => 'Table',
5570
'Heading_1' => 'Font',
5671
'Normal' => 'Paragraph',
72+
'Numbering' => 'Numbering',
5773
);
5874

5975
Style::addParagraphStyle('Paragraph', $paragraph);
6076
Style::addFontStyle('Font', $font);
6177
Style::addLinkStyle('Link', $font);
62-
// @todo Style::addNumberingStyle
78+
Style::addNumberingStyle('Numbering', $numbering);
6379
Style::addTitleStyle(1, $font);
6480
Style::addTableStyle('Table', $table);
6581
Style::setDefaultParagraphStyle($paragraph);

tests/PhpWord/Writer/HTML/ElementTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
3434
*/
3535
public function testUnmatchedElements()
3636
{
37-
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title', 'Bookmark');
37+
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Table', 'Title', 'Bookmark');
3838
foreach ($elements as $element) {
3939
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
4040
$parentWriter = new HTML();
@@ -163,6 +163,31 @@ public function testWriteTitleTextRun()
163163
$this->assertContains($expected, $content);
164164
}
165165

166+
/**
167+
* Test write element ListItemRun
168+
*/
169+
public function testListItemRun()
170+
{
171+
$expected1 = 'List item run 1';
172+
$expected2 = 'List item run 1 in bold';
173+
174+
$phpWord = new PhpWord();
175+
$section = $phpWord->addSection();
176+
177+
$listItemRun = $section->addListItemRun(0, null, 'MyParagraphStyle');
178+
$listItemRun->addText($expected1);
179+
$listItemRun->addText($expected2, array('bold' => true));
180+
181+
$htmlWriter = new HTML($phpWord);
182+
$content = $htmlWriter->getContent();
183+
184+
$dom = new \DOMDocument();
185+
$dom->loadHTML($content);
186+
187+
$this->assertEquals($expected1, $dom->getElementsByTagName('p')->item(0)->textContent);
188+
$this->assertEquals($expected2, $dom->getElementsByTagName('p')->item(1)->textContent);
189+
}
190+
166191
/**
167192
* Tests writing table with layout
168193
*/

tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function setUpBeforeClass()
2727
{
2828
if (self::isBuiltinServerSupported()) {
2929
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
30+
3031
/*
3132
* Make sure to invoke \Symfony\Component\Process\Process correctly
3233
* regardless of PHP version used.

0 commit comments

Comments
 (0)