From 98d2e0df335d8ef820efe9c7843add2966a603fb Mon Sep 17 00:00:00 2001 From: Michael Spahn Date: Tue, 16 Aug 2016 17:10:51 +0200 Subject: [PATCH 1/5] Implement PageBreak for odt writer --- .../Writer/ODText/Element/PageBreak.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/PhpWord/Writer/ODText/Element/PageBreak.php diff --git a/src/PhpWord/Writer/ODText/Element/PageBreak.php b/src/PhpWord/Writer/ODText/Element/PageBreak.php new file mode 100644 index 00000000..47b4eeba --- /dev/null +++ b/src/PhpWord/Writer/ODText/Element/PageBreak.php @@ -0,0 +1,36 @@ +getXmlWriter(); + + $xmlWriter->startElement('text:p'); + $xmlWriter->writeAttribute('text:style-name', 'P1'); + $xmlWriter->endElement(); + } +} From 5d928db91627245a79cdc38e626208b274b8cc2a Mon Sep 17 00:00:00 2001 From: Michael Spahn Date: Tue, 16 Aug 2016 17:10:51 +0200 Subject: [PATCH 2/5] Implement PageBreak for odt writer --- .../Writer/ODText/Element/PageBreak.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/PhpWord/Writer/ODText/Element/PageBreak.php diff --git a/src/PhpWord/Writer/ODText/Element/PageBreak.php b/src/PhpWord/Writer/ODText/Element/PageBreak.php new file mode 100644 index 00000000..47b4eeba --- /dev/null +++ b/src/PhpWord/Writer/ODText/Element/PageBreak.php @@ -0,0 +1,36 @@ +getXmlWriter(); + + $xmlWriter->startElement('text:p'); + $xmlWriter->writeAttribute('text:style-name', 'P1'); + $xmlWriter->endElement(); + } +} From 72a6b1b19fb26ffcf2871ef41ee95617cc20a55e Mon Sep 17 00:00:00 2001 From: troosan Date: Sat, 25 Nov 2017 23:44:22 +0100 Subject: [PATCH 3/5] Add unit test --- tests/PhpWord/Writer/ODText/ElementTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/PhpWord/Writer/ODText/ElementTest.php b/tests/PhpWord/Writer/ODText/ElementTest.php index 253c8e11..f56114ea 100644 --- a/tests/PhpWord/Writer/ODText/ElementTest.php +++ b/tests/PhpWord/Writer/ODText/ElementTest.php @@ -18,6 +18,8 @@ namespace PhpOffice\PhpWord\Writer\ODText; use PhpOffice\Common\XMLWriter; +use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Element subnamespace @@ -40,4 +42,21 @@ class ElementTest extends \PHPUnit\Framework\TestCase $this->assertEquals('', $xmlWriter->getData()); } } + + /** + * Test PageBreak + */ + public function testPageBreak() + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + $section->addText('test'); + $section->addPageBreak(); + + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); + + $element = '/office:document-content/office:body/office:text/text:section/text:p[2]'; + $this->assertTrue($doc->elementExists($element, 'content.xml')); + $this->assertEquals('P1', $doc->getElementAttribute($element, 'text:style-name', 'content.xml')); + } } From 355027d854b27889a64de6e74634c9589ea27853 Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 26 Nov 2017 00:11:09 +0100 Subject: [PATCH 4/5] PHP-CS fix, improve code coverage --- src/PhpWord/Writer/ODText/Element/Link.php | 8 +------- src/PhpWord/Writer/ODText/Element/PageBreak.php | 4 ++-- src/PhpWord/Writer/ODText/Element/Text.php | 12 ++---------- src/PhpWord/Writer/ODText/Element/Title.php | 8 +------- src/PhpWord/Writer/ODText/Part/Meta.php | 7 +------ 5 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/PhpWord/Writer/ODText/Element/Link.php b/src/PhpWord/Writer/ODText/Element/Link.php index c996ab59..34d72c1a 100644 --- a/src/PhpWord/Writer/ODText/Element/Link.php +++ b/src/PhpWord/Writer/ODText/Element/Link.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; -use PhpOffice\PhpWord\Settings; - /** * Text element writer * @@ -44,11 +42,7 @@ class Link extends AbstractElement $xmlWriter->startElement('text:a'); $xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:href', $element->getSource()); - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); // text:a if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/PageBreak.php b/src/PhpWord/Writer/ODText/Element/PageBreak.php index 47b4eeba..6eee6cfc 100644 --- a/src/PhpWord/Writer/ODText/Element/PageBreak.php +++ b/src/PhpWord/Writer/ODText/Element/PageBreak.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * - * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2016 PHPWord contributors + * @see https://github.com/PHPOffice/PHPWord + * @copyright 2010-2017 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Text.php b/src/PhpWord/Writer/ODText/Element/Text.php index 3b06217d..dc377699 100644 --- a/src/PhpWord/Writer/ODText/Element/Text.php +++ b/src/PhpWord/Writer/ODText/Element/Text.php @@ -58,11 +58,7 @@ class Text extends AbstractElement } elseif (is_string($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); } else { if (empty($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', 'Standard'); @@ -74,11 +70,7 @@ class Text extends AbstractElement if (is_string($fontStyle)) { $xmlWriter->writeAttribute('text:style-name', $fontStyle); } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); } if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/Title.php b/src/PhpWord/Writer/ODText/Element/Title.php index bf9bf9d6..769d293f 100644 --- a/src/PhpWord/Writer/ODText/Element/Title.php +++ b/src/PhpWord/Writer/ODText/Element/Title.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; -use PhpOffice\PhpWord\Settings; - /** * Title element writer * @@ -39,11 +37,7 @@ class Title extends AbstractElement $xmlWriter->startElement('text:h'); $xmlWriter->writeAttribute('text:outline-level', $element->getDepth()); - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); // text:h } } diff --git a/src/PhpWord/Writer/ODText/Part/Meta.php b/src/PhpWord/Writer/ODText/Part/Meta.php index 72d03ae6..f592c5f0 100644 --- a/src/PhpWord/Writer/ODText/Part/Meta.php +++ b/src/PhpWord/Writer/ODText/Part/Meta.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\Common\XMLWriter; -use PhpOffice\PhpWord\Settings; /** * ODText meta part writer: meta.xml @@ -100,11 +99,7 @@ class Meta extends AbstractPart // if ($type !== null) { // $xmlWriter->writeAttribute('meta:value-type', $type); // } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($value); - } else { - $xmlWriter->writeRaw($value); - } + $this->writeText($value); $xmlWriter->endElement(); // meta:user-defined } } From 01008a591b731579f960bed7093853da6c690d03 Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 26 Nov 2017 00:35:21 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e39ed3f..7f5376a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -v0.14.0 (?? ???? 2017) +v0.14.0 (?? Dec 2017) ---------------------- This release fixes several bugs and adds some new features. This is the last version to support PHP 5.3 @@ -20,6 +20,7 @@ This is the last version to support PHP 5.3 - Add support for HTML underline tag in addHtml - @zNightFalLz #1186 - Allow to change cell width unit - guillaume-ro-fr #986 - Allow to change the line height rule @troosan +- Implement PageBreak for odt writer @cookiekiller #863 #824 ### Fixed - Loosen dependency to Zend