From 5e93950bc3746846ab1ca45d8c9fca10f917989f Mon Sep 17 00:00:00 2001 From: Hugo Carvalho Date: Wed, 2 Oct 2019 22:15:14 -0300 Subject: [PATCH 01/14] Update templates processing docs Adding save() and saveAs() methods docs --- docs/templates-processing.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/templates-processing.rst b/docs/templates-processing.rst index 5b32aa18e0..2e8de3a42a 100644 --- a/docs/templates-processing.rst +++ b/docs/templates-processing.rst @@ -244,3 +244,20 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples. $table->addCell(150)->addText('Cell B2'); $table->addCell(150)->addText('Cell B3'); $templateProcessor->setComplexBlock('table', $table); + +save +""""""""" +Saves the loaded template within the current directory. Returns the file path. + +.. code-block:: php + + $filepath = $templateProcessor->save(); + +saveAs +""""""""" +Saves a copy of the loaded template in the indicated path. + +.. code-block:: php + + $pathToSave = 'path/to/save/file.ext'; + $templateProcessor->saveAs($pathToSave); From b0de8e7d1d13ea4ee1f91bca70b4af021c858dd4 Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:41:35 +0500 Subject: [PATCH 02/14] Improve unit test --- tests/PhpWord/MediaTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/PhpWord/MediaTest.php b/tests/PhpWord/MediaTest.php index 3cf62b59f4..cca413f505 100644 --- a/tests/PhpWord/MediaTest.php +++ b/tests/PhpWord/MediaTest.php @@ -34,6 +34,22 @@ public function testGetSectionMediaElementsWithNull() $this->assertEquals(array(), Media::getElements('section')); } + /** + * Get header media elements + */ + public function testGetHeaderMediaElementsWithNull() + { + $this->assertEquals(array(), Media::getElements('header')); + } + + /** + * Get footer media elements + */ + public function testGetFooterMediaElementsWithNull() + { + $this->assertEquals(array(), Media::getElements('footer')); + } + /** * Count section media elements */ From cb7ffd0ac2bc15b3c1900992d28427f7a67af081 Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:44:47 +0500 Subject: [PATCH 03/14] Improve unit test --- tests/PhpWord/PhpWordTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/PhpWord/PhpWordTest.php b/tests/PhpWord/PhpWordTest.php index d818e0f8bb..4acd0fe67a 100644 --- a/tests/PhpWord/PhpWordTest.php +++ b/tests/PhpWord/PhpWordTest.php @@ -225,4 +225,13 @@ public function testSortSections() $this->assertEquals(2, $phpWord->getSection(0)->countElements()); $this->assertEquals(1, $phpWord->getSection(1)->countElements()); } + + /** + * @covers \PhpOffice\PhpWord\PhpWord::getSettings + */ + public function testGetSettings() + { + $phpWord = new PhpWord(); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Metadata\\Settings', $phpWord->getSettings()); + } } From 21db2d40a4fb292c7a4a5a6bd9fef928835ca0be Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:46:58 +0500 Subject: [PATCH 04/14] Improve unit test --- tests/PhpWord/StyleTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/StyleTest.php b/tests/PhpWord/StyleTest.php index cbc39c871e..d45bb74962 100644 --- a/tests/PhpWord/StyleTest.php +++ b/tests/PhpWord/StyleTest.php @@ -33,6 +33,7 @@ class StyleTest extends \PHPUnit\Framework\TestCase * @covers ::addParagraphStyle * @covers ::addFontStyle * @covers ::addLinkStyle + * @covers ::addNumberingStyle * @covers ::addTitleStyle * @covers ::addTableStyle * @covers ::setDefaultParagraphStyle @@ -47,6 +48,20 @@ public function testStyles() $paragraph = array('alignment' => Jc::CENTER); $font = array('italic' => true, '_bold' => true); $table = array('bgColor' => 'CCCCCC'); + $numbering = array( + 'type' => 'multilevel', + 'levels' => array( + array( + 'start' => 1, + 'format' => 'decimal', + 'restart' => 1, + 'suffix' => 'space', + 'text' => '%1.', + 'alignment' => Jc::START, + ), + ), + ); + $styles = array( 'Paragraph' => 'Paragraph', 'Font' => 'Font', @@ -54,12 +69,13 @@ public function testStyles() 'Table' => 'Table', 'Heading_1' => 'Font', 'Normal' => 'Paragraph', + 'Numbering' => 'Numbering', ); Style::addParagraphStyle('Paragraph', $paragraph); Style::addFontStyle('Font', $font); Style::addLinkStyle('Link', $font); - // @todo Style::addNumberingStyle + Style::addNumberingStyle('Numbering', $numbering); Style::addTitleStyle(1, $font); Style::addTableStyle('Table', $table); Style::setDefaultParagraphStyle($paragraph); From b23024212709ee9d91e0403b20e03a5f74209f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bc=2E=20=C5=A0tefan=20Kubini?= Date: Tue, 5 Nov 2019 10:46:24 +0100 Subject: [PATCH 05/14] fixed List item fail #1711 --- .../Writer/HTML/Element/ListItemRun.php | 50 +++++++++++++++++++ tests/PhpWord/Writer/HTML/ElementTest.php | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/PhpWord/Writer/HTML/Element/ListItemRun.php diff --git a/src/PhpWord/Writer/HTML/Element/ListItemRun.php b/src/PhpWord/Writer/HTML/Element/ListItemRun.php new file mode 100644 index 0000000000..6842b23941 --- /dev/null +++ b/src/PhpWord/Writer/HTML/Element/ListItemRun.php @@ -0,0 +1,50 @@ +element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { + return ''; + } + + $writer = new Container($this->parentWriter, $this->element); + + if (Settings::isOutputEscapingEnabled()) { + $content = '

' . $this->escaper->escapeHtml($writer->write()) . '

' . PHP_EOL; + } else { + $content = '

' . $writer->write() . '

' . PHP_EOL; + } + + return $content; + } +} diff --git a/tests/PhpWord/Writer/HTML/ElementTest.php b/tests/PhpWord/Writer/HTML/ElementTest.php index 101e226f50..c8ee4b2650 100644 --- a/tests/PhpWord/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Writer/HTML/ElementTest.php @@ -34,7 +34,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase */ public function testUnmatchedElements() { - $elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title', 'Bookmark'); + $elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Table', 'Title', 'Bookmark'); foreach ($elements as $element) { $objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element; $parentWriter = new HTML(); From a10fe823b2977010f82552f357bece578a8b2865 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Sat, 16 Nov 2019 21:37:57 -0800 Subject: [PATCH 06/14] Errors in RTF Escaping 1. Codes meant to be in hex are specified in decimal. Consequently characters which don't need escaping are escaped. 2. Special handling (prepend backslash) needed for {, }, and \. RTF docs generated with those characters cannot be opened in Word. 3. Tab character needs to be escaped as \tab. RTF docs drop these characters. While running test suite, found that Writer/RTF/ElementTest was coded only for Unix line endings, and fails on Windows. Changed so that it would work on either. --- src/PhpWord/Escaper/Rtf.php | 12 +++- tests/PhpWord/Escaper/RtfEscaper2Test.php | 81 +++++++++++++++++++++++ tests/PhpWord/Writer/RTF/ElementTest.php | 11 +-- 3 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 tests/PhpWord/Escaper/RtfEscaper2Test.php diff --git a/src/PhpWord/Escaper/Rtf.php b/src/PhpWord/Escaper/Rtf.php index b8e0b2169c..42eb22a777 100644 --- a/src/PhpWord/Escaper/Rtf.php +++ b/src/PhpWord/Escaper/Rtf.php @@ -26,8 +26,14 @@ class Rtf extends AbstractEscaper { protected function escapeAsciiCharacter($code) { - if (20 > $code || $code >= 80) { - return '{\u' . $code . '}'; + if ($code == 9) { + return '{\\tab}'; + } + if (0x20 > $code || $code >= 0x80) { + return '{\\u' . $code . '}'; + } + if ($code == 123 || $code == 125 || $code == 92) { // open or close brace or backslash + return '\\' . chr($code); } return chr($code); @@ -35,7 +41,7 @@ protected function escapeAsciiCharacter($code) protected function escapeMultibyteCharacter($code) { - return '\uc0{\u' . $code . '}'; + return '\\uc0{\\u' . $code . '}'; } /** diff --git a/tests/PhpWord/Escaper/RtfEscaper2Test.php b/tests/PhpWord/Escaper/RtfEscaper2Test.php new file mode 100644 index 0000000000..b16dc469a4 --- /dev/null +++ b/tests/PhpWord/Escaper/RtfEscaper2Test.php @@ -0,0 +1,81 @@ +write()); + + return $txt2; + } + + public function expect($str) + { + return self::HEADER . $str . self::TRAILER; + } + + /** + * Test special characters which require escaping + */ + public function testSpecial() + { + $str = 'Special characters { open brace } close brace \\ backslash'; + $expect = $this->expect('Special characters \\{ open brace \\} close brace \\\\ backslash'); + $this->assertEquals($expect, $this->escapestring($str)); + } + + /** + * Test accented character + */ + public function testAccent() + { + $str = 'Voilà - string with accented char'; + $expect = $this->expect('Voil\\uc0{\\u224} - string with accented char'); + $this->assertEquals($expect, $this->escapestring($str)); + } + + /** + * Test Hebrew + */ + public function testHebrew() + { + $str = 'Hebrew - שלום'; + $expect = $this->expect('Hebrew - \\uc0{\\u1513}\\uc0{\\u1500}\\uc0{\\u1493}\\uc0{\\u1501}'); + $this->assertEquals($expect, $this->escapestring($str)); + } + + /** + * Test tab + */ + public function testTab() + { + $str = "Here's a tab\tfollowed by more characters."; + $expect = $this->expect("Here's a tab{\\tab}followed by more characters."); + $this->assertEquals($expect, $this->escapestring($str)); + } +} diff --git a/tests/PhpWord/Writer/RTF/ElementTest.php b/tests/PhpWord/Writer/RTF/ElementTest.php index 4b01bacfa2..4c9dfc5eb6 100644 --- a/tests/PhpWord/Writer/RTF/ElementTest.php +++ b/tests/PhpWord/Writer/RTF/ElementTest.php @@ -24,6 +24,9 @@ */ class ElementTest extends \PHPUnit\Framework\TestCase { + public function removeCr($field) { + return str_replace("\r\n", "\n", $field->write()); + } /** * Test unmatched elements */ @@ -46,7 +49,7 @@ public function testPageField() $element = new \PhpOffice\PhpWord\Element\Field('PAGE'); $field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element); - $this->assertEquals("{\\field{\\*\\fldinst PAGE}{\\fldrslt}}\\par\n", $field->write()); + $this->assertEquals("{\\field{\\*\\fldinst PAGE}{\\fldrslt}}\\par\n", $this->removeCr($field)); } public function testNumpageField() @@ -55,7 +58,7 @@ public function testNumpageField() $element = new \PhpOffice\PhpWord\Element\Field('NUMPAGES'); $field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element); - $this->assertEquals("{\\field{\\*\\fldinst NUMPAGES}{\\fldrslt}}\\par\n", $field->write()); + $this->assertEquals("{\\field{\\*\\fldinst NUMPAGES}{\\fldrslt}}\\par\n", $this->removeCr($field)); } public function testDateField() @@ -64,7 +67,7 @@ public function testDateField() $element = new \PhpOffice\PhpWord\Element\Field('DATE', array('dateformat' => 'd MM yyyy H:mm:ss')); $field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element); - $this->assertEquals("{\\field{\\*\\fldinst DATE \\\\@ \"d MM yyyy H:mm:ss\"}{\\fldrslt}}\\par\n", $field->write()); + $this->assertEquals("{\\field{\\*\\fldinst DATE \\\\@ \"d MM yyyy H:mm:ss\"}{\\fldrslt}}\\par\n", $this->removeCr($field)); } public function testIndexField() @@ -73,6 +76,6 @@ public function testIndexField() $element = new \PhpOffice\PhpWord\Element\Field('INDEX'); $field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element); - $this->assertEquals("{}\\par\n", $field->write()); + $this->assertEquals("{}\\par\n", $this->removeCr($field)); } } From 2513e545406c81a117af7166cc3a053cc01f68e4 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Sat, 16 Nov 2019 23:20:02 -0800 Subject: [PATCH 07/14] Errors in RTF Escaping 1. Codes meant to be in hex are specified in decimal. Consequently characters which don't need escaping are escaped. 2. Special handling (prepend backslash) needed for {, }, and . RTF docs generated with those characters cannot be opened in Word. 3. Tab character needs to be escaped as \tab. RTF docs drop these characters. While running test suite, found that Writer/RTF/ElementTest was coded only for Unix line endings, and fails on Windows. Changed so that it would work on either. --- tests/PhpWord/Escaper/RtfEscaper2Test.php | 4 +++- tests/PhpWord/Writer/RTF/ElementTest.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/PhpWord/Escaper/RtfEscaper2Test.php b/tests/PhpWord/Escaper/RtfEscaper2Test.php index b16dc469a4..27e8a985ad 100644 --- a/tests/PhpWord/Escaper/RtfEscaper2Test.php +++ b/tests/PhpWord/Escaper/RtfEscaper2Test.php @@ -15,8 +15,10 @@ * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ +namespace PhpOffice\PhpWord\Escaper; + /** - * Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace + * Test class for PhpOffice\PhpWord\Escaper\RTF */ class RtfEscaperTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/PhpWord/Writer/RTF/ElementTest.php b/tests/PhpWord/Writer/RTF/ElementTest.php index 4c9dfc5eb6..67a319e619 100644 --- a/tests/PhpWord/Writer/RTF/ElementTest.php +++ b/tests/PhpWord/Writer/RTF/ElementTest.php @@ -24,7 +24,8 @@ */ class ElementTest extends \PHPUnit\Framework\TestCase { - public function removeCr($field) { + public function removeCr($field) + { return str_replace("\r\n", "\n", $field->write()); } /** From 00f9bb5897b18c3507990cc34bc1c4d152e93db1 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Sun, 17 Nov 2019 00:07:02 -0800 Subject: [PATCH 08/14] Formatting changes in source code. --- tests/PhpWord/Escaper/RtfEscaper2Test.php | 2 +- tests/PhpWord/Writer/RTF/ElementTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/Escaper/RtfEscaper2Test.php b/tests/PhpWord/Escaper/RtfEscaper2Test.php index 27e8a985ad..21c8a8c34f 100644 --- a/tests/PhpWord/Escaper/RtfEscaper2Test.php +++ b/tests/PhpWord/Escaper/RtfEscaper2Test.php @@ -20,7 +20,7 @@ /** * Test class for PhpOffice\PhpWord\Escaper\RTF */ -class RtfEscaperTest extends \PHPUnit\Framework\TestCase +class RtfEscaper2Test extends \PHPUnit\Framework\TestCase { const HEADER = '\\pard\\nowidctlpar {\\cf0\\f0 '; const TRAILER = '}\\par'; diff --git a/tests/PhpWord/Writer/RTF/ElementTest.php b/tests/PhpWord/Writer/RTF/ElementTest.php index 67a319e619..3e9c235d13 100644 --- a/tests/PhpWord/Writer/RTF/ElementTest.php +++ b/tests/PhpWord/Writer/RTF/ElementTest.php @@ -28,6 +28,7 @@ public function removeCr($field) { return str_replace("\r\n", "\n", $field->write()); } + /** * Test unmatched elements */ From 1451fadc4ad1cecad3c567b9b7bea049cec71b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bc=2E=20=C5=A0tefan=20Kubini?= Date: Thu, 28 Nov 2019 23:33:10 +0100 Subject: [PATCH 09/14] Add List for docx to html writer #1717 --- .../Writer/HTML/Element/ListItemRun.php | 11 ++------ tests/PhpWord/Writer/HTML/ElementTest.php | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/PhpWord/Writer/HTML/Element/ListItemRun.php b/src/PhpWord/Writer/HTML/Element/ListItemRun.php index 6842b23941..a4d7e46073 100644 --- a/src/PhpWord/Writer/HTML/Element/ListItemRun.php +++ b/src/PhpWord/Writer/HTML/Element/ListItemRun.php @@ -17,14 +17,12 @@ namespace PhpOffice\PhpWord\Writer\HTML\Element; -use PhpOffice\PhpWord\Settings; - /** * ListItem element HTML writer * * @since 0.10.0 */ -class ListItemRun extends ListItem +class ListItemRun extends TextRun { /** * Write list item @@ -38,12 +36,7 @@ public function write() } $writer = new Container($this->parentWriter, $this->element); - - if (Settings::isOutputEscapingEnabled()) { - $content = '

' . $this->escaper->escapeHtml($writer->write()) . '

' . PHP_EOL; - } else { - $content = '

' . $writer->write() . '

' . PHP_EOL; - } + $content = $writer->write() . PHP_EOL; return $content; } diff --git a/tests/PhpWord/Writer/HTML/ElementTest.php b/tests/PhpWord/Writer/HTML/ElementTest.php index c8ee4b2650..4eb92fe557 100644 --- a/tests/PhpWord/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Writer/HTML/ElementTest.php @@ -163,6 +163,31 @@ public function testWriteTitleTextRun() $this->assertContains($expected, $content); } + /** + * Test write element ListItemRun + */ + public function testListItemRun() + { + $expected1 = 'List item run 1'; + $expected2 = 'List item run 1 in bold'; + + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + + $listItemRun = $section->addListItemRun(0, null, 'MyParagraphStyle'); + $listItemRun->addText($expected1); + $listItemRun->addText($expected2, array('bold' => true)); + + $htmlWriter = new HTML($phpWord); + $content = $htmlWriter->getContent(); + + $dom = new \DOMDocument(); + $dom->loadHTML($content); + + $this->assertEquals($expected1, $dom->getElementsByTagName('p')->item(0)->textContent); + $this->assertEquals($expected2, $dom->getElementsByTagName('p')->item(1)->textContent); + } + /** * Tests writing table with layout */ From aa44594ed37b372574084eefa9f4239ea4c02c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Mon, 2 Dec 2019 14:23:34 +0100 Subject: [PATCH 10/14] fix: PHPUnit test Process() format \Symfony\Component\Process\Process refuses being passed a string with version > 5, which is installed with PHP > 7.2.5. It also refuses being passed an array with version < 3.3, which is installed with PHP < 5.5.9. Solved by checking if Process::fromShellCommandLine() exists, which was introduced in version 4.2.0. --- .../AbstractWebServerEmbeddedTest.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php index 9316a9fe61..25fe836ac1 100644 --- a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php +++ b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php @@ -26,7 +26,26 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass() { if (self::isBuiltinServerSupported()) { - self::$httpServer = new Process('php -S localhost:8080 -t tests/PhpWord/_files'); + $commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files'; + + /* + * Make sure to invoke \Symfony\Component\Process\Process correctly + * regardless of PHP version used. + * + * In Process version >= 5 / PHP >= 7.2.5, the constructor requires + * an array, while in version < 3.3 / PHP < 5.5.9 it requires a string. + * In between, it can accept both. + * + * Process::fromShellCommandLine() was introduced in version 4.2.0, + * to enable recent versions of Process to parse a command string, + * so if it is not available it means it is still possible to pass + * a string to the constructor. + */ + if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandLine')) { + self::$httpServer = Process::fromShellCommandline($commandLine); + } else { + self::$httpServer = new Process($commandLine); + } self::$httpServer->start(); while (!self::$httpServer->isRunning()) { usleep(1000); From f51811b96b08143573c7c489e5fe75b9d77d6467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Thu, 28 Nov 2019 11:32:29 +0100 Subject: [PATCH 11/14] fix: documentation about paragraph indentation Documentation contained the wrong unit for Paragraph indentation. --- docs/styles.rst | 6 ++++-- src/PhpWord/Style/Paragraph.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/styles.rst b/docs/styles.rst index 27f8ee66ce..18a9c2eca3 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -75,8 +75,10 @@ Available Paragraph style options: - ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values. - ``basedOn``. Parent style. -- ``hanging``. Hanging in *twip*. -- ``indent``. Indent in *twip*. +- ``hanging``. Hanging indentation in *half inches*. +- ``indent``. Indent (left indentation) in *half inches*. +- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation. + See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types. - ``keepLines``. Keep all lines on one page, *true* or *false*. - ``keepNext``. Keep paragraph with next paragraph, *true* or *false*. - ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc. diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 6e9aaf15dc..72f0f8096c 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -198,7 +198,7 @@ public function setStyleValue($key, $value) { $key = Text::removeUnderscorePrefix($key); if ('indent' == $key || 'hanging' == $key) { - $value = $value * 720; + $value = $value * 720; // 720 twips is 0.5 inch } return parent::setStyleValue($key, $value); From 485202874370e7cbd35197735e870eb3ed700f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Mon, 9 Dec 2019 11:29:18 +0100 Subject: [PATCH 12/14] fix: typo in getFootnoteProperties() method name Was "getFootnotePropoperties()". Former bogus spelling is still working, albeit deprecated. --- src/PhpWord/Element/Section.php | 12 +++++++++++ src/PhpWord/Writer/Word2007/Part/Document.php | 20 +++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index b495ef7bca..b6da9f3b9d 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -146,6 +146,18 @@ public function getFooters() * * @return FootnoteProperties */ + public function getFootnoteProperties() + { + return $this->footnoteProperties; + } + + /** + * Get the footnote properties + * + * @deprecated Use the `getFootnoteProperties` method instead + * + * @return FootnoteProperties + */ public function getFootnotePropoperties() { return $this->footnoteProperties; diff --git a/src/PhpWord/Writer/Word2007/Part/Document.php b/src/PhpWord/Writer/Word2007/Part/Document.php index 986b498570..e0cabd7e1c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Document.php +++ b/src/PhpWord/Writer/Word2007/Part/Document.php @@ -126,27 +126,27 @@ private function writeSectionSettings(XMLWriter $xmlWriter, Section $section) $xmlWriter->endElement(); } - //footnote properties - if ($section->getFootnotePropoperties() !== null) { + // Footnote properties + if ($section->getFootnoteProperties() !== null) { $xmlWriter->startElement('w:footnotePr'); - if ($section->getFootnotePropoperties()->getPos() != null) { + if ($section->getFootnoteProperties()->getPos() != null) { $xmlWriter->startElement('w:pos'); - $xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getPos()); + $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos()); $xmlWriter->endElement(); } - if ($section->getFootnotePropoperties()->getNumFmt() != null) { + if ($section->getFootnoteProperties()->getNumFmt() != null) { $xmlWriter->startElement('w:numFmt'); - $xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumFmt()); + $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt()); $xmlWriter->endElement(); } - if ($section->getFootnotePropoperties()->getNumStart() != null) { + if ($section->getFootnoteProperties()->getNumStart() != null) { $xmlWriter->startElement('w:numStart'); - $xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumStart()); + $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart()); $xmlWriter->endElement(); } - if ($section->getFootnotePropoperties()->getNumRestart() != null) { + if ($section->getFootnoteProperties()->getNumRestart() != null) { $xmlWriter->startElement('w:numRestart'); - $xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumRestart()); + $xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart()); $xmlWriter->endElement(); } $xmlWriter->endElement(); From cb3e2111350e964ce30615d1811f8d083a41b302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Mon, 9 Dec 2019 11:22:08 +0100 Subject: [PATCH 13/14] fix(documentation): snippet for FootnoteProperties The documentation contained an incorrect code snippet for configuring FootnoteProperties. Now the code is valid. --- docs/elements.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/elements.rst b/docs/elements.rst index 9d446b27d0..e497491533 100644 --- a/docs/elements.rst +++ b/docs/elements.rst @@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th .. code-block:: php - $fp = new PhpWord\SimpleType\FootnoteProperties(); + $fp = new \PhpOffice\PhpWord\ComplexType\FootnoteProperties(); //sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd) - $fp->setPos(FootnoteProperties::POSITION_DOC_END); + $fp->setPos(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::POSITION_BENEATH_TEXT); //set the number format to use (decimal (default), upperRoman, upperLetter, ...) - $fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN); + $fp->setNumFmt(\PhpOffice\PhpWord\SimpleType\NumberFormat::LOWER_ROMAN); //force starting at other than 1 $fp->setNumStart(2); //when to restart counting (continuous (default), eachSect, eachPage) - $fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE); + $fp->setNumRestart(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::RESTART_NUMBER_EACH_PAGE); //And finaly, set it on the Section - $section->setFootnoteProperties($properties); + $section->setFootnoteProperties($fp); Checkboxes ---------- From 431b11bd7492702edd9fc09ed1ff9794852ce984 Mon Sep 17 00:00:00 2001 From: Mike Houben Date: Mon, 6 Jan 2020 15:34:24 +0100 Subject: [PATCH 14/14] Changing from zendframework to laminas Would fix https://github.com/PHPOffice/PHPWord/issues/1797 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5f751ec04..276d4e0806 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "require": { "php": "^5.3.3 || ^7.0", "ext-xml": "*", - "zendframework/zend-escaper": "^2.2", + "laminas/laminas-escaper": "^2.6", "phpoffice/common": "^0.2.9" }, "require-dev": {