Merge pull request #1206 from troosan/odt_page_break

Implement PageBreak for the ODText writer
This commit is contained in:
troosan 2017-11-26 00:39:25 +01:00 committed by GitHub
commit 6a460c292d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 31 deletions

View File

@ -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 <u> 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
- Allow to force an update of all fields on opening a document - @troosan #951
### Fixed

View File

@ -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) {

View File

@ -0,0 +1,36 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\ODText\Element;
/**
* PageBreak element writer
*/
class PageBreak extends AbstractElement
{
/**
* Write element
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'P1');
$xmlWriter->endElement();
}
}

View File

@ -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) {

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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'));
}
}