Merge branch 'develop' into develop

This commit is contained in:
troosan 2018-03-20 21:49:36 +01:00 committed by GitHub
commit d7fc1a5f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
406 changed files with 3050 additions and 684 deletions

View File

@ -1,3 +1,8 @@
build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]
filter: filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ] excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]

View File

@ -15,12 +15,9 @@ matrix:
include: include:
- php: 5.6 - php: 5.6
env: COVERAGE=1 env: COVERAGE=1
allow_failures:
- php: 7.2
cache: cache:
directories: directories:
- vendor
- $HOME/.composer/cache - $HOME/.composer/cache
- .php-cs.cache - .php-cs.cache
@ -38,7 +35,7 @@ before_script:
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini ; fi - if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini ; fi
## Composer ## Composer
- composer self-update - composer self-update
- composer install --prefer-source - travis_wait composer install --prefer-source
## PHPDocumentor ## PHPDocumentor
- mkdir -p build/docs - mkdir -p build/docs
- mkdir -p build/coverage - mkdir -p build/coverage

View File

@ -13,6 +13,12 @@ v0.15.0 (?? ??? 2018)
- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276 - Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
- Add support for Cell Spacing @dox07 @troosan #1040 - Add support for Cell Spacing @dox07 @troosan #1040
- Add parsing of formatting inside lists @atomicalnet @troosan #594 - Add parsing of formatting inside lists @atomicalnet @troosan #594
- Added support for Vertically Raised or Lowered Text (w:position) @anrikun @troosan #640
- Add support for MACROBUTTON field @phryneas @troosan #1021
- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
- Added support for Floating Table Positioning (tblpPr) @anrikun #639
- Added support for Image text wrapping distance @troosan #1310
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
### Fixed ### Fixed
- Fix reading of docx default style - @troosan #1238 - Fix reading of docx default style - @troosan #1238
@ -23,6 +29,8 @@ v0.15.0 (?? ??? 2018)
- Bookmark are not writton as internal link in html writer @troosan #1263 - Bookmark are not writton as internal link in html writer @troosan #1263
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287 - It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
- Fix colspan and rowspan for tables in HTML Writer @mattbolt #1292 - Fix colspan and rowspan for tables in HTML Writer @mattbolt #1292
- Fix parsing of Heading and Title formating @troosan @gthomas2 #465
- Fix Dateformat typo, fix hours casing, add Month-Day-Year formats @ComputerTinker #591
### Changed ### Changed
- Remove zend-stdlib dependency @Trainmaster #1284 - Remove zend-stdlib dependency @Trainmaster #1284

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -36,19 +36,19 @@
], ],
"scripts": { "scripts": {
"test": [ "test": [
"./vendor/bin/phpunit --color=always" "phpunit --color=always"
], ],
"test-no-coverage": [ "test-no-coverage": [
"./vendor/bin/phpunit --color=always --no-coverage" "phpunit --color=always --no-coverage"
], ],
"check": [ "check": [
"./vendor/bin/php-cs-fixer fix --ansi --dry-run --diff", "php-cs-fixer fix --ansi --dry-run --diff",
"./vendor/bin/phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n", "phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
"./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php", "phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
"@test" "@test"
], ],
"fix": [ "fix": [
"./vendor/bin/php-cs-fixer fix --ansi" "php-cs-fixer fix --ansi"
] ]
}, },
"scripts-descriptions": { "scripts-descriptions": {

View File

@ -89,6 +89,7 @@ Titles
If you want to structure your document or build table of contents, you need titles or headings. If you want to structure your document or build table of contents, you need titles or headings.
To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` method. To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` method.
If `depth` is 0, a Title will be inserted, otherwise a Heading1, Heading2, ...
.. code-block:: php .. code-block:: php
@ -98,7 +99,7 @@ To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` metho
- ``depth``. - ``depth``.
- ``$fontStyle``. See :ref:`font-style`. - ``$fontStyle``. See :ref:`font-style`.
- ``$paragraphStyle``. See :ref:`paragraph-style`. - ``$paragraphStyle``. See :ref:`paragraph-style`.
- ``$text``. Text to be displayed in the document. - ``$text``. Text to be displayed in the document. This can be `string` or a `\PhpOffice\PhpWord\Element\TextRun`
It's necessary to add a title style to your document because otherwise the title won't be detected as a real title. It's necessary to add a title style to your document because otherwise the title won't be detected as a real title.
@ -481,6 +482,7 @@ Track changes can be set on text elements. There are 2 ways to set the change in
Either by calling the `setChangeInfo()`, or by setting the `TrackChange` instance on the element with `setTrackChange()`. Either by calling the `setChangeInfo()`, or by setting the `TrackChange` instance on the element with `setTrackChange()`.
.. code-block:: php .. code-block:: php
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section // New portrait section

View File

@ -217,10 +217,10 @@ The default language of the document can be change with the following.
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE)); $phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
``Languge`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages. ``Language`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used. A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used.
In case you are generating an RTF document the Language need to be set differently. In case you are generating an RTF document the language need to be set differently.
.. code-block:: php .. code-block:: php
@ -290,3 +290,45 @@ To force an update of the fields present in the document, set updateFields to tr
.. code-block:: php .. code-block:: php
$phpWord->getSettings()->setUpdateFields(true); $phpWord->getSettings()->setUpdateFields(true);
Hyphenation
-----------
Hyphenation describes the process of breaking words with hyphens. There are several options to control hyphenation.
Auto hyphenation
~~~~~~~~~~~~~~~~
To automatically hyphenate text set ``autoHyphenation`` to ``true``.
.. code-block:: php
$phpWord->getSettings()->setAutoHyphenation(true);
Consecutive Hyphen Limit
~~~~~~~~~~~~~~~~~~~~~~~~
The maximum number of consecutive lines of text ending with a hyphen can be controlled by the ``consecutiveHyphenLimit`` option.
There is no limit if the option is not set or the provided value is ``0``.
.. code-block:: php
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
Hyphenation Zone
~~~~~~~~~~~~~~~~
The hyphenation zone (in *twip*) is the allowed amount of whitespace before hyphenation is applied.
The smaller the hyphenation zone the more words are hyphenated. Or in other words, the wider the hyphenation zone the less words are hyphenated.
.. code-block:: php
$phpWord->getSettings()->setHyphenationZone(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
Hyphenate Caps
~~~~~~~~~~~~~~
To control whether or not words in all capital letters shall be hyphenated use the `doNotHyphenateCaps` option.
.. code-block:: php
$phpWord->getSettings()->setDoNotHyphenateCaps(true);

View File

@ -59,6 +59,7 @@ Available Font style options:
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
- ``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 - ``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
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes. See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
- ``position``. The text position, raised or lowered, in half points
.. _paragraph-style: .. _paragraph-style:
@ -81,6 +82,7 @@ Available Paragraph style options:
- ``spaceAfter``. Space after paragraph in *twip*. - ``spaceAfter``. Space after paragraph in *twip*.
- ``spacing``. Space between lines. - ``spacing``. Space between lines.
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast* - ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
- ``suppressAutoHyphens``. Hyphenation for paragraph, *true* or *false*.
- ``tabs``. Set of custom tab stops. - ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. - ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*. - ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
@ -106,6 +108,20 @@ Available Table style options:
- ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*. - ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*.
- ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants. - ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants.
- ``cellSpacing`` Cell spacing in *twip* - ``cellSpacing`` Cell spacing in *twip*
- ``position`` Floating Table Positioning, see below for options
Floating Table Positioning options:
- ``leftFromText`` Distance From Left of Table to Text in *twip*
- ``rightFromText`` Distance From Right of Table to Text in *twip*
- ``topFromText`` Distance From Top of Table to Text in *twip*
- ``bottomFromText`` Distance From Top of Table to Text in *twip*
- ``vertAnchor`` Table Vertical Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::VANCHOR_*``
- ``horzAnchor`` Table Horizontal Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::HANCHOR_*``
- ``tblpXSpec`` Relative Horizontal Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::XALIGN_*``
- ``tblpX`` Absolute Horizontal Distance From Anchorin *twip*
- ``tblpYSpec`` Relative Vertical Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::YALIGN_*``
- ``tblpY`` Absolute Vertical Distance From Anchorin *twip*
Available Row style options: Available Row style options:
@ -138,6 +154,10 @@ Available Image style options:
- ``marginTop``. Top margin in inches, can be negative. - ``marginTop``. Top margin in inches, can be negative.
- ``width``. Width in pixels. - ``width``. Width in pixels.
- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*. - ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*.
- ``wrapDistanceTop``. Top text wrapping in pixels.
- ``wrapDistanceBottom``. Bottom text wrapping in pixels.
- ``wrapDistanceLeft``. Left text wrapping in pixels.
- ``wrapDistanceRight``. Right text wrapping in pixels.
.. _numbering-level-style: .. _numbering-level-style:

View File

@ -1,4 +1,7 @@
<?php <?php
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Style\TablePosition;
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
@ -139,6 +142,15 @@ $cell->addText('This cell contains nested table.');
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell(); $innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
$innerCell->addText('Inside nested table'); $innerCell->addText('Inside nested table');
// 6. Table with floating position
$section->addTextBreak(2);
$section->addText('Table with floating positioning.', $header);
$table = $section->addTable(array('borderSize' => 6, 'borderColor' => '999999', 'position' => array('vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1))));
$cell = $table->addRow()->addCell();
$cell->addText('This is a single cell.');
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) { if (!CLI) {

View File

@ -1,4 +1,7 @@
<?php <?php
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Shared\Converter;
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
@ -9,45 +12,48 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Local image without any styles:'); $section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg'); $section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
printSeparator($section);
$section->addText('Local image with styles:'); $section->addText('Local image with styles:');
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$section->addTextBreak(2);
// Remote image // Remote image
printSeparator($section);
$source = 'http://php.net/images/logos/php-med-trans-light.gif'; $source = 'http://php.net/images/logos/php-med-trans-light.gif';
$section->addText("Remote image from: {$source}"); $section->addText("Remote image from: {$source}");
$section->addImage($source); $section->addImage($source);
// Image from string // Image from string
printSeparator($section);
$source = 'resources/_mars.jpg'; $source = 'resources/_mars.jpg';
$fileContent = file_get_contents($source); $fileContent = file_get_contents($source);
$section->addText('Image from string'); $section->addText('Image from string');
$section->addImage($fileContent); $section->addImage($fileContent);
//Wrapping style //Wrapping style
$text = str_repeat('Hello World! ', 15); printSeparator($section);
$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);
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
foreach ($wrappingStyles as $wrappingStyle) { foreach ($wrappingStyles as $wrappingStyle) {
$section->addTextBreak(5);
$section->addText("Wrapping style {$wrappingStyle}"); $section->addText("Wrapping style {$wrappingStyle}");
$section->addImage( $section->addImage(
'resources/_earth.jpg', 'resources/_earth.jpg',
array( array(
'positioning' => 'relative', 'positioning' => 'relative',
'marginTop' => -1, 'marginTop' => -1,
'marginLeft' => 1, 'marginLeft' => 1,
'width' => 80, 'width' => 80,
'height' => 80, 'height' => 80,
'wrappingStyle' => $wrappingStyle, 'wrappingStyle' => $wrappingStyle,
'wrapDistanceRight' => Converter::cmToPoint(1),
'wrapDistanceBottom' => Converter::cmToPoint(1),
) )
); );
$section->addText($text); $section->addText($text);
printSeparator($section);
} }
//Absolute positioning //Absolute positioning
$section->addTextBreak(3);
$section->addText('Absolute positioning: see top right corner of page'); $section->addText('Absolute positioning: see top right corner of page');
$section->addImage( $section->addImage(
'resources/_mars.jpg', 'resources/_mars.jpg',
@ -64,7 +70,7 @@ $section->addImage(
); );
//Relative positioning //Relative positioning
$section->addTextBreak(3); printSeparator($section);
$section->addText('Relative positioning: Horizontal position center relative to column,'); $section->addText('Relative positioning: Horizontal position center relative to column,');
$section->addText('Vertical position top relative to line'); $section->addText('Vertical position top relative to line');
$section->addImage( $section->addImage(
@ -80,6 +86,14 @@ $section->addImage(
) )
); );
function printSeparator(Section $section)
{
$section->addTextBreak();
$lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center');
$section->addLine($lineStyle);
$section->addTextBreak(2);
}
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) { if (!CLI) {

View File

@ -12,13 +12,14 @@ $section = $phpWord->addSection();
// Define styles // Define styles
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12); $fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
$fontStyle10 = array('size' => 10); $fontStyle10 = array('size' => 10);
$phpWord->addTitleStyle(null, array('size' => 22, 'bold' => true));
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true)); $phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666')); $phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
$phpWord->addTitleStyle(4, array('size' => 12)); $phpWord->addTitleStyle(4, array('size' => 12));
// Add text elements // Add text elements
$section->addText('Table of contents 1'); $section->addTitle('Table of contents 1', 0);
$section->addTextBreak(2); $section->addTextBreak(2);
// Add TOC #1 // Add TOC #1

View File

@ -4,6 +4,7 @@ include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addParagraphStyle('Heading2', array('alignment' => 'center'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$html = '<h1>Adding element via HTML</h1>'; $html = '<h1>Adding element via HTML</h1>';
@ -17,6 +18,11 @@ $html .= '<p lang="he-IL" style="text-align: right; direction: rtl">היי, זה
$html .= '<p style="margin-top: 240pt;">Unordered (bulleted) list:</p>'; $html .= '<p style="margin-top: 240pt;">Unordered (bulleted) list:</p>';
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>'; $html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
$html .= '<p style="margin-top: 240pt;">1.5 line height with first line text indent:</p>';
$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>';
$html .= '<h2 style="align: center">centered title</h2>';
$html .= '<p style="margin-top: 240pt;">Ordered (numbered) list:</p>'; $html .= '<p style="margin-top: 240pt;">Ordered (numbered) list:</p>';
$html .= '<ol> $html .= '<ol>
<li><p style="font-weight: bold;">List 1 item 1</p></li> <li><p style="font-weight: bold;">List 1 item 1</p></li>

View File

@ -20,6 +20,7 @@ $section->addField('PAGE', array('format' => 'Arabic'));
$section->addText('Number of pages field:'); $section->addText('Number of pages field:');
$section->addField('NUMPAGES', array('numformat' => '0,00', 'format' => 'Arabic'), array('PreserveFormat')); $section->addField('NUMPAGES', array('numformat' => '0,00', 'format' => 'Arabic'), array('PreserveFormat'));
$section->addTextBreak();
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText('An index field is '); $textrun->addText('An index field is ');
@ -43,6 +44,19 @@ $textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleTy
$textrun->addText('This is the date of lunar calendar '); $textrun->addText('This is the date of lunar calendar ');
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); $textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
$textrun->addText(' written in a textrun.'); $textrun->addText(' written in a textrun.');
$section->addTextBreak();
$macroText = new TextRun();
$macroText->addText('Double click', array('bold' => true));
$macroText->addText(' to ');
$macroText->addText('zoom to 100%', array('italic' => true));
$section->addText('A macro button with styled text:');
$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), $macroText);
$section->addTextBreak();
$section->addText('A macro button with simple text:');
$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), 'double click to zoom');
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -27,14 +27,14 @@ abstract class AbstractCollection
/** /**
* Items * Items
* *
* @var array * @var \PhpOffice\PhpWord\Element\AbstractContainer[]
*/ */
private $items = array(); private $items = array();
/** /**
* Get items * Get items
* *
* @return array * @return \PhpOffice\PhpWord\Element\AbstractContainer[]
*/ */
public function getItems() public function getItems()
{ {
@ -45,7 +45,7 @@ abstract class AbstractCollection
* Get item by index * Get item by index
* *
* @param int $index * @param int $index
* @return mixed * @return \PhpOffice\PhpWord\Element\AbstractContainer
*/ */
public function getItem($index) public function getItem($index)
{ {
@ -60,7 +60,7 @@ abstract class AbstractCollection
* Set item. * Set item.
* *
* @param int $index * @param int $index
* @param mixed $item * @param \PhpOffice\PhpWord\Element\AbstractContainer $item
*/ */
public function setItem($index, $item) public function setItem($index, $item)
{ {
@ -72,7 +72,7 @@ abstract class AbstractCollection
/** /**
* Add new item * Add new item
* *
* @param mixed $item * @param \PhpOffice\PhpWord\Element\AbstractContainer $item
* @return int * @return int
*/ */
public function addItem($item) public function addItem($item)

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -54,7 +54,7 @@ abstract class AbstractContainer extends AbstractElement
/** /**
* Elements collection * Elements collection
* *
* @var array * @var \PhpOffice\PhpWord\Element\AbstractElement[]
*/ */
protected $elements = array(); protected $elements = array();
@ -164,6 +164,41 @@ abstract class AbstractContainer extends AbstractElement
return $this->elements; return $this->elements;
} }
/**
* Returns the element at the requested position
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\AbstractElement|null
*/
public function getElement($index)
{
if (array_key_exists($index, $this->elements)) {
return $this->elements[$index];
}
return null;
}
/**
* Removes the element at requested index
*
* @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove
*/
public function removeElement($toRemove)
{
if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) {
unset($this->elements[$toRemove]);
} elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) {
foreach ($this->elements as $key => $element) {
if ($element->getElementId() === $toRemove->getElementId()) {
unset($this->elements[$key]);
return;
}
}
}
}
/** /**
* Count elements * Count elements
* *

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -43,7 +43,7 @@ class Bookmark extends AbstractElement
* *
* @param string $name * @param string $name
*/ */
public function __construct($name) public function __construct($name = '')
{ {
$this->name = CommonText::toUTF8($name); $this->name = CommonText::toUTF8($name);
} }

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -48,12 +48,28 @@ class Field extends AbstractElement
), ),
'DATE' => array( 'DATE' => array(
'properties' => array( 'properties' => array(
'dateformat' => array('d-M-yyyy', 'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-M-yy', 'yyyy-MM-dd', 'dateformat' => array(
'd-MMM-yy', 'd/M/yyyy', 'd MMM. yy', 'd/M/yy', 'MMM-yy', 'd-M-yyy H:mm', 'd-M-yyyy H:mm:ss', /* Generic formats */
'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss', ), 'yyyy-MM-dd', 'yyyy-MM', 'MMM-yy', 'MMM-yyyy', 'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss',
/* Day-Month-Year formats */
'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-MMM-yy', 'd MMM. yy',
'd-M-yy', 'd-M-yy h:mm', 'd-M-yy h:mm:ss', 'd-M-yy h:mm am/pm', 'd-M-yy h:mm:ss am/pm', 'd-M-yy HH:mm', 'd-M-yy HH:mm:ss',
'd/M/yy', 'd/M/yy h:mm', 'd/M/yy h:mm:ss', 'd/M/yy h:mm am/pm', 'd/M/yy h:mm:ss am/pm', 'd/M/yy HH:mm', 'd/M/yy HH:mm:ss',
'd-M-yyyy', 'd-M-yyyy h:mm', 'd-M-yyyy h:mm:ss', 'd-M-yyyy h:mm am/pm', 'd-M-yyyy h:mm:ss am/pm', 'd-M-yyyy HH:mm', 'd-M-yyyy HH:mm:ss',
'd/M/yyyy', 'd/M/yyyy h:mm', 'd/M/yyyy h:mm:ss', 'd/M/yyyy h:mm am/pm', 'd/M/yyyy h:mm:ss am/pm', 'd/M/yyyy HH:mm', 'd/M/yyyy HH:mm:ss',
/* Month-Day-Year formats */
'dddd, MMMM d yyyy', 'MMMM d yyyy', 'MMM-d-yy', 'MMM. d yy',
'M-d-yy', 'M-d-yy h:mm', 'M-d-yy h:mm:ss', 'M-d-yy h:mm am/pm', 'M-d-yy h:mm:ss am/pm', 'M-d-yy HH:mm', 'M-d-yy HH:mm:ss',
'M/d/yy', 'M/d/yy h:mm', 'M/d/yy h:mm:ss', 'M/d/yy h:mm am/pm', 'M/d/yy h:mm:ss am/pm', 'M/d/yy HH:mm', 'M/d/yy HH:mm:ss',
'M-d-yyyy', 'M-d-yyyy h:mm', 'M-d-yyyy h:mm:ss', 'M-d-yyyy h:mm am/pm', 'M-d-yyyy h:mm:ss am/pm', 'M-d-yyyy HH:mm', 'M-d-yyyy HH:mm:ss',
'M/d/yyyy', 'M/d/yyyy h:mm', 'M/d/yyyy h:mm:ss', 'M/d/yyyy h:mm am/pm', 'M/d/yyyy h:mm:ss am/pm', 'M/d/yyyy HH:mm', 'M/d/yyyy HH:mm:ss',
),
), ),
'options' => array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat'), 'options' => array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat'),
), ),
'MACROBUTTON' => array(
'properties' => array('macroname' => ''),
),
'XE' => array( 'XE' => array(
'properties' => array(), 'properties' => array(),
'options' => array('Bold', 'Italic'), 'options' => array('Bold', 'Italic'),
@ -92,6 +108,13 @@ class Field extends AbstractElement
*/ */
protected $options = array(); protected $options = array();
/**
* Font style
*
* @var \PhpOffice\PhpWord\Style\Font
*/
protected $fontStyle;
/** /**
* Create a new Field Element * Create a new Field Element
* *

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -62,7 +62,7 @@ class ListItem extends AbstractElement
// Version >= 0.10.0 will pass numbering style name. Older version will use old method // Version >= 0.10.0 will pass numbering style name. Older version will use old method
if (!is_null($listStyle) && is_string($listStyle)) { if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle); $this->style = new ListItemStyle($listStyle); // @codeCoverageIgnore
} else { } else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
} }

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -28,7 +28,7 @@ class Title extends AbstractElement
/** /**
* Title Text content * Title Text content
* *
* @var string * @var string|TextRun
*/ */
private $text; private $text;
@ -56,15 +56,25 @@ class Title extends AbstractElement
/** /**
* Create a new Title Element * Create a new Title Element
* *
* @param string $text * @param string|TextRun $text
* @param int $depth * @param int $depth
*/ */
public function __construct($text, $depth = 1) public function __construct($text, $depth = 1)
{ {
$this->text = CommonText::toUTF8($text); if (isset($text)) {
if (is_string($text)) {
$this->text = CommonText::toUTF8($text);
} elseif ($text instanceof TextRun) {
$this->text = $text;
} else {
throw new \InvalidArgumentException('Invalid text, should be a string or a TextRun');
}
}
$this->depth = $depth; $this->depth = $depth;
if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) { $styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}";
$this->style = "Heading{$this->depth}"; if (array_key_exists($styleName, Style::getStyles())) {
$this->style = str_replace('_', '', $styleName);
} }
return $this; return $this;

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -130,6 +130,32 @@ class Settings
*/ */
private $decimalSymbol = '.'; private $decimalSymbol = '.';
/**
* Automatically hyphenate document contents when displayed
*
* @var bool|null
*/
private $autoHyphenation;
/**
* Maximum number of consecutively hyphenated lines
*
* @var int|null
*/
private $consecutiveHyphenLimit;
/**
* The allowed amount of whitespace before hyphenation is applied
* @var float|null
*/
private $hyphenationZone;
/**
* Do not hyphenate words in all capital letters
* @var bool|null
*/
private $doNotHyphenateCaps;
/** /**
* @return Protection * @return Protection
*/ */
@ -387,4 +413,68 @@ class Settings
{ {
$this->decimalSymbol = $decimalSymbol; $this->decimalSymbol = $decimalSymbol;
} }
/**
* @return bool|null
*/
public function hasAutoHyphenation()
{
return $this->autoHyphenation;
}
/**
* @param bool $autoHyphenation
*/
public function setAutoHyphenation($autoHyphenation)
{
$this->autoHyphenation = (bool) $autoHyphenation;
}
/**
* @return int|null
*/
public function getConsecutiveHyphenLimit()
{
return $this->consecutiveHyphenLimit;
}
/**
* @param int $consecutiveHyphenLimit
*/
public function setConsecutiveHyphenLimit($consecutiveHyphenLimit)
{
$this->consecutiveHyphenLimit = (int) $consecutiveHyphenLimit;
}
/**
* @return float|null
*/
public function getHyphenationZone()
{
return $this->hyphenationZone;
}
/**
* @param float $hyphenationZone Measurement unit is twip
*/
public function setHyphenationZone($hyphenationZone)
{
$this->hyphenationZone = $hyphenationZone;
}
/**
* @return null|bool
*/
public function hasDoNotHyphenateCaps()
{
return $this->doNotHyphenateCaps;
}
/**
* @param bool $doNotHyphenateCaps
*/
public function setDoNotHyphenateCaps($doNotHyphenateCaps)
{
$this->doNotHyphenateCaps = (bool) $doNotHyphenateCaps;
}
} }

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -52,8 +52,17 @@ class PhpWord
* @const string|int * @const string|int
*/ */
const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME; const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE; const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR; const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
/**
* @deprecated 0.11.0 Use Settings constants
*/
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE; const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
/** /**
@ -85,6 +94,10 @@ class PhpWord
*/ */
public function __construct() public function __construct()
{ {
// Reset Media and styles
Media::resetElements();
Style::resetStyles();
// Collection // Collection
$collections = array('Bookmarks', 'Titles', 'Footnotes', 'Endnotes', 'Charts', 'Comments'); $collections = array('Bookmarks', 'Titles', 'Footnotes', 'Endnotes', 'Charts', 'Comments');
foreach ($collections as $collection) { foreach ($collections as $collection) {
@ -212,6 +225,21 @@ class PhpWord
return $this->sections; return $this->sections;
} }
/**
* Returns the section at the requested position
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\Section|null
*/
public function getSection($index)
{
if (array_key_exists($index, $this->sections)) {
return $this->sections[$index];
}
return null;
}
/** /**
* Create new section * Create new section
* *
@ -227,6 +255,17 @@ class PhpWord
return $section; return $section;
} }
/**
* Sorts the sections using the callable passed
*
* @see http://php.net/manual/en/function.usort.php for usage
* @param callable $sorter
*/
public function sortSections($sorter)
{
usort($this->sections, $sorter);
}
/** /**
* Get default font name * Get default font name
* *

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,13 +11,15 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader; use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
@ -103,12 +105,10 @@ abstract class AbstractPart
{ {
// Paragraph style // Paragraph style
$paragraphStyle = null; $paragraphStyle = null;
$headingMatches = array(); $headingDepth = null;
if ($xmlReader->elementExists('w:pPr', $domNode)) { if ($xmlReader->elementExists('w:pPr', $domNode)) {
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode); $paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
if (is_array($paragraphStyle) && isset($paragraphStyle['styleName'])) { $headingDepth = $this->getHeadingDepth($paragraphStyle);
preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches);
}
} }
// PreserveText // PreserveText
@ -147,35 +147,57 @@ abstract class AbstractPart
foreach ($nodes as $node) { foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $listItemRun, $docPart, $paragraphStyle); $this->readRun($xmlReader, $node, $listItemRun, $docPart, $paragraphStyle);
} }
} elseif (!empty($headingMatches)) { } elseif ($headingDepth !== null) {
// Heading // Heading or Title
$textContent = ''; $textContent = null;
$nodes = $xmlReader->getElements('w:r', $domNode); $nodes = $xmlReader->getElements('w:r', $domNode);
foreach ($nodes as $node) { if ($nodes->length === 1) {
$textContent .= $xmlReader->getValue('w:t', $node); $textContent = $xmlReader->getValue('w:t', $nodes->item(0));
} else {
$textContent = new TextRun($paragraphStyle);
foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $textContent, $docPart, $paragraphStyle);
}
} }
$parent->addTitle($textContent, $headingMatches[1]); $parent->addTitle($textContent, $headingDepth);
} else { } else {
// Text and TextRun // Text and TextRun
$runCount = $xmlReader->countElements('w:r', $domNode); $textRunContainers = $xmlReader->countElements('w:r|w:ins|w:del|w:hyperlink|w:smartTag', $domNode);
$insCount = $xmlReader->countElements('w:ins', $domNode); if (0 === $textRunContainers) {
$delCount = $xmlReader->countElements('w:del', $domNode);
$linkCount = $xmlReader->countElements('w:hyperlink', $domNode);
$runLinkCount = $runCount + $insCount + $delCount + $linkCount;
if (0 == $runLinkCount) {
$parent->addTextBreak(null, $paragraphStyle); $parent->addTextBreak(null, $paragraphStyle);
} else { } else {
$nodes = $xmlReader->getElements('*', $domNode); $nodes = $xmlReader->getElements('*', $domNode);
if ($runLinkCount > 1) { $paragraph = $parent->addTextRun($paragraphStyle);
$parent = $parent->addTextRun($paragraphStyle);
}
foreach ($nodes as $node) { foreach ($nodes as $node) {
$this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle); $this->readRun($xmlReader, $node, $paragraph, $docPart, $paragraphStyle);
} }
} }
} }
} }
/**
* Returns the depth of the Heading, returns 0 for a Title
*
* @param array $paragraphStyle
* @return number|null
*/
private function getHeadingDepth(array $paragraphStyle = null)
{
if (is_array($paragraphStyle) && isset($paragraphStyle['styleName'])) {
if ('Title' === $paragraphStyle['styleName']) {
return 0;
}
$headingMatches = array();
preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches);
if (!empty($headingMatches)) {
return $headingMatches[1];
}
}
return null;
}
/** /**
* Read w:r. * Read w:r.
* *
@ -189,71 +211,85 @@ abstract class AbstractPart
*/ */
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart, $paragraphStyle = null) protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, $docPart, $paragraphStyle = null)
{ {
if (in_array($domNode->nodeName, array('w:ins', 'w:del'))) { if (in_array($domNode->nodeName, array('w:ins', 'w:del', 'w:smartTag', 'w:hyperlink'))) {
$nodes = $xmlReader->getElements('*', $domNode); $nodes = $xmlReader->getElements('*', $domNode);
foreach ($nodes as $node) { foreach ($nodes as $node) {
return $this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle); $this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle);
}
} elseif ($domNode->nodeName == 'w:r') {
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
$nodes = $xmlReader->getElements('*', $domNode);
foreach ($nodes as $node) {
$this->readRunChild($xmlReader, $node, $parent, $docPart, $paragraphStyle, $fontStyle);
} }
} }
}
if (!in_array($domNode->nodeName, array('w:r', 'w:hyperlink'))) { /**
return; * Parses nodes under w:r
} *
$fontStyle = $this->readFontStyle($xmlReader, $domNode); * @param XMLReader $xmlReader
* @param \DOMElement $node
// Link * @param AbstractContainer $parent
if ('w:hyperlink' == $domNode->nodeName) { * @param string $docPart
$rId = $xmlReader->getAttribute('r:id', $domNode); * @param mixed $paragraphStyle
$textContent = $xmlReader->getValue('w:r/w:t', $domNode); * @param mixed $fontStyle
*/
protected function readRunChild(XMLReader $xmlReader, \DOMElement $node, AbstractContainer $parent, $docPart, $paragraphStyle = null, $fontStyle = null)
{
$runParent = $node->parentNode->parentNode;
if ($node->nodeName == 'w:footnoteReference') {
// Footnote
$wId = $xmlReader->getAttribute('w:id', $node);
$footnote = $parent->addFootnote();
$footnote->setRelationId($wId);
} elseif ($node->nodeName == 'w:endnoteReference') {
// Endnote
$wId = $xmlReader->getAttribute('w:id', $node);
$endnote = $parent->addEndnote();
$endnote->setRelationId($wId);
} elseif ($node->nodeName == 'w:pict') {
// Image
$rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId); $target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) { if (!is_null($target)) {
$parent->addLink($target, $textContent, $fontStyle, $paragraphStyle); if ('External' == $this->getTargetMode($docPart, $rId)) {
} $imageSource = $target;
} else {
if ($xmlReader->elementExists('w:footnoteReference', $domNode)) {
// Footnote
$parent->addFootnote();
} elseif ($xmlReader->elementExists('w:endnoteReference', $domNode)) {
// Endnote
$parent->addEndnote();
} elseif ($xmlReader->elementExists('w:pict', $domNode)) {
// Image
$rId = $xmlReader->getAttribute('r:id', $domNode, 'w:pict/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
if ('External' == $this->getTargetMode($docPart, $rId)) {
$imageSource = $target;
} else {
$imageSource = "zip://{$this->docFile}#{$target}";
}
$parent->addImage($imageSource);
}
} elseif ($xmlReader->elementExists('w:object', $domNode)) {
// Object
$rId = $xmlReader->getAttribute('r:id', $domNode, 'w:object/o:OLEObject');
// $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$textContent = "&lt;Object: {$target}>";
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
}
if ($xmlReader->elementExists('w:br', $domNode)) {
$parent->addTextBreak();
}
if ($xmlReader->elementExists('w:t', $domNode)) {
// TextRun
if ($domNode->parentNode->nodeName == 'w:del') {
$textContent = $xmlReader->getValue('w:delText', $domNode);
} else { } else {
$textContent = $xmlReader->getValue('w:t', $domNode); $imageSource = "zip://{$this->docFile}#{$target}";
} }
$parent->addImage($imageSource);
}
} elseif ($node->nodeName == 'w:object') {
// Object
$rId = $xmlReader->getAttribute('r:id', $node, 'o:OLEObject');
// $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$textContent = "&lt;Object: {$target}>";
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
} elseif ($node->nodeName == 'w:br') {
$parent->addTextBreak();
} elseif ($node->nodeName == 'w:tab') {
$parent->addText("\t");
} elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') {
// TextRun
$textContent = $xmlReader->getValue('.', $node);
if ($runParent->nodeName == 'w:hyperlink') {
$rId = $xmlReader->getAttribute('r:id', $runParent);
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$parent->addLink($target, $textContent, $fontStyle, $paragraphStyle);
}
} else {
/** @var AbstractElement $element */ /** @var AbstractElement $element */
$element = $parent->addText($textContent, $fontStyle, $paragraphStyle); $element = $parent->addText($textContent, $fontStyle, $paragraphStyle);
if (in_array($domNode->parentNode->nodeName, array('w:ins', 'w:del'))) { if (in_array($runParent->nodeName, array('w:ins', 'w:del'))) {
$type = ($domNode->parentNode->nodeName == 'w:del') ? TrackChange::DELETED : TrackChange::INSERTED; $type = ($runParent->nodeName == 'w:del') ? TrackChange::DELETED : TrackChange::INSERTED;
$author = $domNode->parentNode->getAttribute('w:author'); $author = $runParent->getAttribute('w:author');
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $domNode->parentNode->getAttribute('w:date')); $date = \DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $runParent->getAttribute('w:date'));
$element->setChangeInfo($type, $author, $date); $element->setChangeInfo($type, $author, $date);
} }
} }
@ -333,20 +369,21 @@ abstract class AbstractPart
$styleNode = $xmlReader->getElement('w:pPr', $domNode); $styleNode = $xmlReader->getElement('w:pPr', $domNode);
$styleDefs = array( $styleDefs = array(
'styleName' => array(self::READ_VALUE, array('w:pStyle', 'w:name')), 'styleName' => array(self::READ_VALUE, array('w:pStyle', 'w:name')),
'alignment' => array(self::READ_VALUE, 'w:jc'), 'alignment' => array(self::READ_VALUE, 'w:jc'),
'basedOn' => array(self::READ_VALUE, 'w:basedOn'), 'basedOn' => array(self::READ_VALUE, 'w:basedOn'),
'next' => array(self::READ_VALUE, 'w:next'), 'next' => array(self::READ_VALUE, 'w:next'),
'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'), 'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'),
'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'), 'hanging' => array(self::READ_VALUE, 'w:ind', 'w:hanging'),
'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'), 'spaceAfter' => array(self::READ_VALUE, 'w:spacing', 'w:after'),
'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'), 'spaceBefore' => array(self::READ_VALUE, 'w:spacing', 'w:before'),
'widowControl' => array(self::READ_FALSE, 'w:widowControl'), 'widowControl' => array(self::READ_FALSE, 'w:widowControl'),
'keepNext' => array(self::READ_TRUE, 'w:keepNext'), 'keepNext' => array(self::READ_TRUE, 'w:keepNext'),
'keepLines' => array(self::READ_TRUE, 'w:keepLines'), 'keepLines' => array(self::READ_TRUE, 'w:keepLines'),
'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'), 'pageBreakBefore' => array(self::READ_TRUE, 'w:pageBreakBefore'),
'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'), 'contextualSpacing' => array(self::READ_TRUE, 'w:contextualSpacing'),
'bidi' => array(self::READ_TRUE, 'w:bidi'), 'bidi' => array(self::READ_TRUE, 'w:bidi'),
'suppressAutoHyphens' => array(self::READ_TRUE, 'w:suppressAutoHyphens'),
); );
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs); return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
@ -391,6 +428,7 @@ abstract class AbstractPart
'fgColor' => array(self::READ_VALUE, 'w:highlight'), 'fgColor' => array(self::READ_VALUE, 'w:highlight'),
'rtl' => array(self::READ_TRUE, 'w:rtl'), 'rtl' => array(self::READ_TRUE, 'w:rtl'),
'lang' => array(self::READ_VALUE, 'w:lang'), 'lang' => array(self::READ_VALUE, 'w:lang'),
'position' => array(self::READ_VALUE, 'w:position'),
); );
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs); return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
@ -429,12 +467,42 @@ abstract class AbstractPart
$styleDefs['layout'] = array(self::READ_VALUE, 'w:tblLayout', 'w:type'); $styleDefs['layout'] = array(self::READ_VALUE, 'w:tblLayout', 'w:type');
$styleDefs['cellSpacing'] = array(self::READ_VALUE, 'w:tblCellSpacing', 'w:w'); $styleDefs['cellSpacing'] = array(self::READ_VALUE, 'w:tblCellSpacing', 'w:w');
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs); $style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
$tablePositionNode = $xmlReader->getElement('w:tblpPr', $styleNode);
if ($tablePositionNode !== null) {
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
}
} }
} }
return $style; return $style;
} }
/**
* Read w:tblpPr
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array
*/
private function readTablePosition(XMLReader $xmlReader, \DOMElement $domNode)
{
$styleDefs = array(
'leftFromText' => array(self::READ_VALUE, '.', 'w:leftFromText'),
'rightFromText' => array(self::READ_VALUE, '.', 'w:rightFromText'),
'topFromText' => array(self::READ_VALUE, '.', 'w:topFromText'),
'bottomFromText' => array(self::READ_VALUE, '.', 'w:bottomFromText'),
'vertAnchor' => array(self::READ_VALUE, '.', 'w:vertAnchor'),
'horzAnchor' => array(self::READ_VALUE, '.', 'w:horzAnchor'),
'tblpXSpec' => array(self::READ_VALUE, '.', 'w:tblpXSpec'),
'tblpX' => array(self::READ_VALUE, '.', 'w:tblpX'),
'tblpYSpec' => array(self::READ_VALUE, '.', 'w:tblpYSpec'),
'tblpY' => array(self::READ_VALUE, '.', 'w:tblpY'),
);
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
}
/** /**
* Read w:tcPr * Read w:tcPr
* *
@ -496,11 +564,9 @@ abstract class AbstractPart
return $possibleAttribute; return $possibleAttribute;
} }
} }
} else {
return $attributes;
} }
return null; return $attributes;
} }
/** /**
@ -548,7 +614,7 @@ abstract class AbstractPart
* *
* @param string $method * @param string $method
* @ignoreScrutinizerPatch * @ignoreScrutinizerPatch
* @param mixed $attributeValue * @param string|null $attributeValue
* @param mixed $expected * @param mixed $expected
* @return mixed * @return mixed
*/ */
@ -578,7 +644,7 @@ abstract class AbstractPart
*/ */
private function isOn($value = null) private function isOn($value = null)
{ {
return $value == null || $value == '1' || $value == 'true' || $value == 'on'; return $value === null || $value === '1' || $value === 'true' || $value === 'on';
} }
/** /**

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -48,9 +48,6 @@ class Footnotes extends AbstractPart
*/ */
public function read(PhpWord $phpWord) public function read(PhpWord $phpWord)
{ {
$getMethod = "get{$this->collection}";
$collection = $phpWord->$getMethod()->getItems();
$xmlReader = new XMLReader(); $xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile); $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$nodes = $xmlReader->getElements('*'); $nodes = $xmlReader->getElements('*');
@ -60,17 +57,41 @@ class Footnotes extends AbstractPart
$type = $xmlReader->getAttribute('w:type', $node); $type = $xmlReader->getAttribute('w:type', $node);
// Avoid w:type "separator" and "continuationSeparator" // Avoid w:type "separator" and "continuationSeparator"
// Only look for <footnote> or <endnote> without w:type attribute // Only look for <footnote> or <endnote> without w:type attribute, or with w:type = normal
if (is_null($type) && isset($collection[$id])) { if ((is_null($type) || $type === 'normal')) {
$element = $collection[$id]; $element = $this->getElement($phpWord, $id);
$pNodes = $xmlReader->getElements('w:p/*', $node); if ($element !== null) {
foreach ($pNodes as $pNode) { $pNodes = $xmlReader->getElements('w:p/*', $node);
$this->readRun($xmlReader, $pNode, $element, $this->collection); foreach ($pNodes as $pNode) {
$this->readRun($xmlReader, $pNode, $element, $this->collection);
}
$addMethod = "add{$this->element}";
$phpWord->$addMethod($element);
} }
$addMethod = "add{$this->element}";
$phpWord->$addMethod($element);
} }
} }
} }
} }
/**
* Searches for the element with the given relationId
*
* @param PhpWord $phpWord
* @param int $relationId
* @return \PhpOffice\PhpWord\Element\AbstractContainer|null
*/
private function getElement(PhpWord $phpWord, $relationId)
{
$getMethod = "get{$this->collection}";
$collection = $phpWord->$getMethod()->getItems();
//not found by key, looping to search by relationId
foreach ($collection as $collectionElement) {
if ($collectionElement->getRelationId() == $relationId) {
return $collectionElement;
}
}
return null;
}
} }

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -29,7 +29,18 @@ use PhpOffice\PhpWord\Style\Language;
*/ */
class Settings extends AbstractPart class Settings extends AbstractPart
{ {
private static $booleanProperties = array('hideSpellingErrors', 'hideGrammaticalErrors', 'trackRevisions', 'doNotTrackMoves', 'doNotTrackFormatting', 'evenAndOddHeaders'); private static $booleanProperties = array(
'mirrorMargins',
'hideSpellingErrors',
'hideGrammaticalErrors',
'trackRevisions',
'doNotTrackMoves',
'doNotTrackFormatting',
'evenAndOddHeaders',
'updateFields',
'autoHyphenation',
'doNotHyphenateCaps',
);
/** /**
* Read settings.xml. * Read settings.xml.
@ -157,4 +168,32 @@ class Settings extends AbstractPart
$revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN));
$phpWord->getSettings()->setRevisionView($revisionView); $phpWord->getSettings()->setRevisionView($revisionView);
} }
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setConsecutiveHyphenLimit(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setConsecutiveHyphenLimit($value);
}
}
/**
* @param XMLReader $xmlReader
* @param PhpWord $phpWord
* @param \DOMElement $node
*/
protected function setHyphenationZone(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node)
{
$value = $xmlReader->getAttribute('w:val', $node);
if ($value !== null) {
$phpWord->getSettings()->setHyphenationZone($value);
}
}
} }

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -252,7 +252,7 @@ class Html
$styles['font'] = self::recursiveParseStylesInHierarchy($node, $styles['font']); $styles['font'] = self::recursiveParseStylesInHierarchy($node, $styles['font']);
//alignment applies on paragraph, not on font. Let's copy it there //alignment applies on paragraph, not on font. Let's copy it there
if (isset($styles['font']['alignment'])) { if (isset($styles['font']['alignment']) && is_array($styles['paragraph'])) {
$styles['paragraph']['alignment'] = $styles['font']['alignment']; $styles['paragraph']['alignment'] = $styles['font']['alignment'];
} }
@ -486,8 +486,9 @@ class Html
private static function parseStyle($attribute, $styles) private static function parseStyle($attribute, $styles)
{ {
$properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;")); $properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;"));
foreach ($properties as $property) { foreach ($properties as $property) {
list($cKey, $cValue) = explode(':', $property, 2); list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null);
$cValue = trim($cValue); $cValue = trim($cValue);
switch (trim($cKey)) { switch (trim($cKey)) {
case 'text-decoration': case 'text-decoration':
@ -519,6 +520,23 @@ class Html
case 'background-color': case 'background-color':
$styles['bgColor'] = trim($cValue, '#'); $styles['bgColor'] = trim($cValue, '#');
break; break;
case 'line-height':
if (preg_match('/([0-9]+[a-z]+)/', $cValue, $matches)) {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::EXACT;
$spacing = Converter::cssToTwip($matches[1]) / \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT;
} elseif (preg_match('/([0-9]+)%/', $cValue, $matches)) {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
$spacing = ((int) $matches[1]) / 100;
} else {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
$spacing = $cValue;
}
$styles['spacingLineRule'] = $spacingLineRule;
$styles['lineHeight'] = $spacing;
break;
case 'text-indent':
$styles['indentation']['firstLine'] = Converter::cssToTwip($cValue);
break;
case 'font-weight': case 'font-weight':
$tValue = false; $tValue = false;
if (preg_match('#bold#', $cValue)) { if (preg_match('#bold#', $cValue)) {

Some files were not shown because too many files have changed in this diff Show More