Skip to content

Commit d7fc1a5

Browse files
authored
Merge branch 'develop' into develop
2 parents 296706a + 992d842 commit d7fc1a5

File tree

406 files changed

+3048
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

406 files changed

+3048
-682
lines changed

.scrutinizer.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
build:
2+
nodes:
3+
analysis:
4+
tests:
5+
override: [php-scrutinizer-run]
16
filter:
27
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]
38

.travis.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ matrix:
1515
include:
1616
- php: 5.6
1717
env: COVERAGE=1
18-
allow_failures:
19-
- php: 7.2
2018

2119
cache:
2220
directories:
23-
- vendor
2421
- $HOME/.composer/cache
2522
- .php-cs.cache
2623

@@ -38,7 +35,7 @@ before_script:
3835
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini ; fi
3936
## Composer
4037
- composer self-update
41-
- composer install --prefer-source
38+
- travis_wait composer install --prefer-source
4239
## PHPDocumentor
4340
- mkdir -p build/docs
4441
- mkdir -p build/coverage

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ v0.15.0 (?? ??? 2018)
1313
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
1414
- Add support for Cell Spacing @dox07 @troosan #1040
1515
- Add parsing of formatting inside lists @atomicalnet @troosan #594
16+
- Added support for Vertically Raised or Lowered Text (w:position) @anrikun @troosan #640
17+
- Add support for MACROBUTTON field @phryneas @troosan #1021
18+
- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
19+
- Added support for Floating Table Positioning (tblpPr) @anrikun #639
20+
- Added support for Image text wrapping distance @troosan #1310
21+
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
1622

1723
### Fixed
1824
- Fix reading of docx default style - @troosan #1238
@@ -23,6 +29,8 @@ v0.15.0 (?? ??? 2018)
2329
- Bookmark are not writton as internal link in html writer @troosan #1263
2430
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
2531
- Fix colspan and rowspan for tables in HTML Writer @mattbolt #1292
32+
- Fix parsing of Heading and Title formating @troosan @gthomas2 #465
33+
- Fix Dateformat typo, fix hours casing, add Month-Day-Year formats @ComputerTinker #591
2634

2735
### Changed
2836
- Remove zend-stdlib dependency @Trainmaster #1284
@@ -475,4 +483,4 @@ This is the first release after a long development hiatus in [CodePlex](https://
475483
- Basic CI with Travis - @Progi1984
476484
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
477485
- IMPROVED: Moved examples out of Classes directory - @Progi1984
478-
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)
486+
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)

bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap
1212
*
1313
* @see https://github.com/PHPOffice/PHPWord
14-
* @copyright 2010-2017 PHPWord contributors
14+
* @copyright 2010-2018 PHPWord contributors
1515
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
1616
*/
1717

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@
3636
],
3737
"scripts": {
3838
"test": [
39-
"./vendor/bin/phpunit --color=always"
39+
"phpunit --color=always"
4040
],
4141
"test-no-coverage": [
42-
"./vendor/bin/phpunit --color=always --no-coverage"
42+
"phpunit --color=always --no-coverage"
4343
],
4444
"check": [
45-
"./vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",
46-
"./vendor/bin/phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
47-
"./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
45+
"php-cs-fixer fix --ansi --dry-run --diff",
46+
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
47+
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
4848
"@test"
4949
],
5050
"fix": [
51-
"./vendor/bin/php-cs-fixer fix --ansi"
51+
"php-cs-fixer fix --ansi"
5252
]
5353
},
5454
"scripts-descriptions": {

docs/elements.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Titles
8989

9090
If you want to structure your document or build table of contents, you need titles or headings.
9191
To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` method.
92+
If `depth` is 0, a Title will be inserted, otherwise a Heading1, Heading2, ...
9293

9394
.. code-block:: php
9495
@@ -98,7 +99,7 @@ To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` metho
9899
- ``depth``.
99100
- ``$fontStyle``. See :ref:`font-style`.
100101
- ``$paragraphStyle``. See :ref:`paragraph-style`.
101-
- ``$text``. Text to be displayed in the document.
102+
- ``$text``. Text to be displayed in the document. This can be `string` or a `\PhpOffice\PhpWord\Element\TextRun`
102103

103104
It's necessary to add a title style to your document because otherwise the title won't be detected as a real title.
104105

@@ -481,6 +482,7 @@ Track changes can be set on text elements. There are 2 ways to set the change in
481482
Either by calling the `setChangeInfo()`, or by setting the `TrackChange` instance on the element with `setTrackChange()`.
482483

483484
.. code-block:: php
485+
484486
$phpWord = new \PhpOffice\PhpWord\PhpWord();
485487
486488
// New portrait section

docs/general.rst

+44-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ The default language of the document can be change with the following.
217217
218218
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
219219
220-
``Languge`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
220+
``Language`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
221221
A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used.
222222

223-
In case you are generating an RTF document the Language need to be set differently.
223+
In case you are generating an RTF document the language need to be set differently.
224224

225225
.. code-block:: php
226226
@@ -290,3 +290,45 @@ To force an update of the fields present in the document, set updateFields to tr
290290
.. code-block:: php
291291
292292
$phpWord->getSettings()->setUpdateFields(true);
293+
294+
Hyphenation
295+
-----------
296+
Hyphenation describes the process of breaking words with hyphens. There are several options to control hyphenation.
297+
298+
Auto hyphenation
299+
~~~~~~~~~~~~~~~~
300+
301+
To automatically hyphenate text set ``autoHyphenation`` to ``true``.
302+
303+
.. code-block:: php
304+
305+
$phpWord->getSettings()->setAutoHyphenation(true);
306+
307+
Consecutive Hyphen Limit
308+
~~~~~~~~~~~~~~~~~~~~~~~~
309+
310+
The maximum number of consecutive lines of text ending with a hyphen can be controlled by the ``consecutiveHyphenLimit`` option.
311+
There is no limit if the option is not set or the provided value is ``0``.
312+
313+
.. code-block:: php
314+
315+
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
316+
317+
Hyphenation Zone
318+
~~~~~~~~~~~~~~~~
319+
320+
The hyphenation zone (in *twip*) is the allowed amount of whitespace before hyphenation is applied.
321+
The smaller the hyphenation zone the more words are hyphenated. Or in other words, the wider the hyphenation zone the less words are hyphenated.
322+
323+
.. code-block:: php
324+
325+
$phpWord->getSettings()->setHyphenationZone(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
326+
327+
Hyphenate Caps
328+
~~~~~~~~~~~~~~
329+
330+
To control whether or not words in all capital letters shall be hyphenated use the `doNotHyphenateCaps` option.
331+
332+
.. code-block:: php
333+
334+
$phpWord->getSettings()->setDoNotHyphenateCaps(true);

docs/styles.rst

+20
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Available Font style options:
5959
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
6060
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
6161
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
62+
- ``position``. The text position, raised or lowered, in half points
6263

6364
.. _paragraph-style:
6465

@@ -81,6 +82,7 @@ Available Paragraph style options:
8182
- ``spaceAfter``. Space after paragraph in *twip*.
8283
- ``spacing``. Space between lines.
8384
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
85+
- ``suppressAutoHyphens``. Hyphenation for paragraph, *true* or *false*.
8486
- ``tabs``. Set of custom tab stops.
8587
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
8688
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
@@ -106,6 +108,20 @@ Available Table style options:
106108
- ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*.
107109
- ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants.
108110
- ``cellSpacing`` Cell spacing in *twip*
111+
- ``position`` Floating Table Positioning, see below for options
112+
113+
Floating Table Positioning options:
114+
115+
- ``leftFromText`` Distance From Left of Table to Text in *twip*
116+
- ``rightFromText`` Distance From Right of Table to Text in *twip*
117+
- ``topFromText`` Distance From Top of Table to Text in *twip*
118+
- ``bottomFromText`` Distance From Top of Table to Text in *twip*
119+
- ``vertAnchor`` Table Vertical Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::VANCHOR_*``
120+
- ``horzAnchor`` Table Horizontal Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::HANCHOR_*``
121+
- ``tblpXSpec`` Relative Horizontal Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::XALIGN_*``
122+
- ``tblpX`` Absolute Horizontal Distance From Anchorin *twip*
123+
- ``tblpYSpec`` Relative Vertical Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::YALIGN_*``
124+
- ``tblpY`` Absolute Vertical Distance From Anchorin *twip*
109125

110126
Available Row style options:
111127

@@ -138,6 +154,10 @@ Available Image style options:
138154
- ``marginTop``. Top margin in inches, can be negative.
139155
- ``width``. Width in pixels.
140156
- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*.
157+
- ``wrapDistanceTop``. Top text wrapping in pixels.
158+
- ``wrapDistanceBottom``. Bottom text wrapping in pixels.
159+
- ``wrapDistanceLeft``. Left text wrapping in pixels.
160+
- ``wrapDistanceRight``. Right text wrapping in pixels.
141161

142162
.. _numbering-level-style:
143163

samples/Sample_09_Tables.php

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PhpOffice\PhpWord\Shared\Converter;
3+
use PhpOffice\PhpWord\Style\TablePosition;
4+
25
include_once 'Sample_Header.php';
36

47
// New Word Document
@@ -139,6 +142,15 @@
139142
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
140143
$innerCell->addText('Inside nested table');
141144

145+
// 6. Table with floating position
146+
147+
$section->addTextBreak(2);
148+
$section->addText('Table with floating positioning.', $header);
149+
150+
$table = $section->addTable(array('borderSize' => 6, 'borderColor' => '999999', 'position' => array('vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1))));
151+
$cell = $table->addRow()->addCell();
152+
$cell->addText('This is a single cell.');
153+
142154
// Save file
143155
echo write($phpWord, basename(__FILE__, '.php'), $writers);
144156
if (!CLI) {

samples/Sample_13_Images.php

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
use PhpOffice\PhpWord\Element\Section;
3+
use PhpOffice\PhpWord\Shared\Converter;
4+
25
include_once 'Sample_Header.php';
36

47
// New Word document
@@ -9,45 +12,48 @@
912
$section = $phpWord->addSection();
1013
$section->addText('Local image without any styles:');
1114
$section->addImage('resources/_mars.jpg');
12-
$section->addTextBreak(2);
1315

16+
printSeparator($section);
1417
$section->addText('Local image with styles:');
1518
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
16-
$section->addTextBreak(2);
1719

1820
// Remote image
21+
printSeparator($section);
1922
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
2023
$section->addText("Remote image from: {$source}");
2124
$section->addImage($source);
2225

2326
// Image from string
27+
printSeparator($section);
2428
$source = 'resources/_mars.jpg';
2529
$fileContent = file_get_contents($source);
2630
$section->addText('Image from string');
2731
$section->addImage($fileContent);
2832

2933
//Wrapping style
30-
$text = str_repeat('Hello World! ', 15);
34+
printSeparator($section);
35+
$text = str_repeat('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 2);
3136
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
3237
foreach ($wrappingStyles as $wrappingStyle) {
33-
$section->addTextBreak(5);
3438
$section->addText("Wrapping style {$wrappingStyle}");
3539
$section->addImage(
3640
'resources/_earth.jpg',
3741
array(
38-
'positioning' => 'relative',
39-
'marginTop' => -1,
40-
'marginLeft' => 1,
41-
'width' => 80,
42-
'height' => 80,
43-
'wrappingStyle' => $wrappingStyle,
42+
'positioning' => 'relative',
43+
'marginTop' => -1,
44+
'marginLeft' => 1,
45+
'width' => 80,
46+
'height' => 80,
47+
'wrappingStyle' => $wrappingStyle,
48+
'wrapDistanceRight' => Converter::cmToPoint(1),
49+
'wrapDistanceBottom' => Converter::cmToPoint(1),
4450
)
4551
);
4652
$section->addText($text);
53+
printSeparator($section);
4754
}
4855

4956
//Absolute positioning
50-
$section->addTextBreak(3);
5157
$section->addText('Absolute positioning: see top right corner of page');
5258
$section->addImage(
5359
'resources/_mars.jpg',
@@ -64,7 +70,7 @@
6470
);
6571

6672
//Relative positioning
67-
$section->addTextBreak(3);
73+
printSeparator($section);
6874
$section->addText('Relative positioning: Horizontal position center relative to column,');
6975
$section->addText('Vertical position top relative to line');
7076
$section->addImage(
@@ -80,6 +86,14 @@
8086
)
8187
);
8288

89+
function printSeparator(Section $section)
90+
{
91+
$section->addTextBreak();
92+
$lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center');
93+
$section->addLine($lineStyle);
94+
$section->addTextBreak(2);
95+
}
96+
8397
// Save file
8498
echo write($phpWord, basename(__FILE__, '.php'), $writers);
8599
if (!CLI) {

samples/Sample_17_TitleTOC.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// Define styles
1313
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
1414
$fontStyle10 = array('size' => 10);
15+
$phpWord->addTitleStyle(null, array('size' => 22, 'bold' => true));
1516
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
1617
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
1718
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
1819
$phpWord->addTitleStyle(4, array('size' => 12));
1920

2021
// Add text elements
21-
$section->addText('Table of contents 1');
22+
$section->addTitle('Table of contents 1', 0);
2223
$section->addTextBreak(2);
2324

2425
// Add TOC #1

samples/Sample_26_Html.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// New Word Document
55
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
66
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
$phpWord->addParagraphStyle('Heading2', array('alignment' => 'center'));
78

89
$section = $phpWord->addSection();
910
$html = '<h1>Adding element via HTML</h1>';
@@ -17,6 +18,11 @@
1718
$html .= '<p style="margin-top: 240pt;">Unordered (bulleted) list:</p>';
1819
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
1920

21+
$html .= '<p style="margin-top: 240pt;">1.5 line height with first line text indent:</p>';
22+
$html .= '<p style="text-align: justify; text-indent: 70.9pt; line-height: 150%;">Lorem ipsum dolor sit amet, <strong>consectetur adipiscing elit</strong>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>';
23+
24+
$html .= '<h2 style="align: center">centered title</h2>';
25+
2026
$html .= '<p style="margin-top: 240pt;">Ordered (numbered) list:</p>';
2127
$html .= '<ol>
2228
<li><p style="font-weight: bold;">List 1 item 1</p></li>

0 commit comments

Comments
 (0)