Skip to content

Commit d9cb88e

Browse files
authored
Merge branch 'develop' into fixes-1750-block-with-images-inside
2 parents 0945a37 + 5a7a11a commit d9cb88e

File tree

7 files changed

+84
-5
lines changed

7 files changed

+84
-5
lines changed

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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);

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/_includes/AbstractWebServerEmbeddedTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
2626
public static function setUpBeforeClass()
2727
{
2828
if (self::isBuiltinServerSupported()) {
29-
self::$httpServer = new Process(array('php', '-S', 'localhost:8080', '-t', 'tests/PhpWord/_files'));
29+
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
30+
31+
/*
32+
* Make sure to invoke \Symfony\Component\Process\Process correctly
33+
* regardless of PHP version used.
34+
*
35+
* In Process version >= 5 / PHP >= 7.2.5, the constructor requires
36+
* an array, while in version < 3.3 / PHP < 5.5.9 it requires a string.
37+
* In between, it can accept both.
38+
*
39+
* Process::fromShellCommandLine() was introduced in version 4.2.0,
40+
* to enable recent versions of Process to parse a command string,
41+
* so if it is not available it means it is still possible to pass
42+
* a string to the constructor.
43+
*/
44+
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandLine')) {
45+
self::$httpServer = Process::fromShellCommandline($commandLine);
46+
} else {
47+
self::$httpServer = new Process($commandLine);
48+
}
3049
self::$httpServer->start();
3150
while (!self::$httpServer->isRunning()) {
3251
usleep(1000);

0 commit comments

Comments
 (0)