Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/PhpWord/Writer/ODText/Element/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PhpOffice\PhpWord\Writer\ODText\Element;

use PhpOffice\PhpWord\Settings;

/**
* Text element writer
*
Expand All @@ -44,11 +42,7 @@ public function write()
$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) {
Expand Down
36 changes: 36 additions & 0 deletions src/PhpWord/Writer/ODText/Element/PageBreak.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
12 changes: 2 additions & 10 deletions src/PhpWord/Writer/ODText/Element/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public function write()
} 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');
Expand All @@ -74,11 +70,7 @@ public function write()
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) {
Expand Down
8 changes: 1 addition & 7 deletions src/PhpWord/Writer/ODText/Element/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PhpOffice\PhpWord\Writer\ODText\Element;

use PhpOffice\PhpWord\Settings;

/**
* Title element writer
*
Expand All @@ -39,11 +37,7 @@ public function write()

$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
}
}
7 changes: 1 addition & 6 deletions src/PhpWord/Writer/ODText/Part/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part;

use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings;

/**
* ODText meta part writer: meta.xml
Expand Down Expand Up @@ -100,11 +99,7 @@ private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value)
// 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
}
}
19 changes: 19 additions & 0 deletions tests/PhpWord/Writer/ODText/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,4 +42,21 @@ public function testUnmatchedElements()
$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'));
}
}