89 lines
3.2 KiB
PHP
Raw Normal View History

<?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.
*
* @link https://github.com/PHPOffice/PHPWord
2015-12-05 21:25:59 +04:00
* @copyright 2010-2015 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\PhpWord\Exception\Exception;
2016-06-13 20:14:54 +04:00
use PhpOffice\PhpWord\Settings;
/**
* Text element writer
*
* @since 0.10.0
*/
2014-05-07 09:47:02 +07:00
class Text extends AbstractElement
{
/**
* Write element
*/
public function write()
{
2014-05-07 09:47:02 +07:00
$xmlWriter = $this->getXmlWriter();
$element = $this->getElement();
2014-05-11 19:41:48 +07:00
if (!$element instanceof \PhpOffice\PhpWord\Element\Text) {
return;
}
2014-05-07 09:47:02 +07:00
$fontStyle = $element->getFontStyle();
$paragraphStyle = $element->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
2014-05-04 15:13:31 +07:00
// $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
$fStyleIsObject = false;
2014-05-04 15:13:31 +07:00
if ($fStyleIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared
2014-05-04 15:13:31 +07:00
throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
} else {
if (!$this->withoutP) {
2014-05-07 09:47:02 +07:00
$xmlWriter->startElement('text:p'); // text:p
}
if (empty($fontStyle)) {
if (empty($paragraphStyle)) {
2014-05-07 09:47:02 +07:00
$xmlWriter->writeAttribute('text:style-name', 'P1');
} elseif (is_string($paragraphStyle)) {
2014-05-07 09:47:02 +07:00
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
2016-06-13 20:14:54 +04:00
if (Settings::isOutputEscapingEnabled()) {
$xmlWriter->text($element->getText());
} else {
$xmlWriter->writeRaw($element->getText());
}
} else {
if (empty($paragraphStyle)) {
2014-05-07 09:47:02 +07:00
$xmlWriter->writeAttribute('text:style-name', 'Standard');
} elseif (is_string($paragraphStyle)) {
2014-05-07 09:47:02 +07:00
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
// text:span
2014-05-07 09:47:02 +07:00
$xmlWriter->startElement('text:span');
if (is_string($fontStyle)) {
2014-05-07 09:47:02 +07:00
$xmlWriter->writeAttribute('text:style-name', $fontStyle);
}
2016-06-13 20:14:54 +04:00
if (Settings::isOutputEscapingEnabled()) {
$xmlWriter->text($element->getText());
} else {
$xmlWriter->writeRaw($element->getText());
}
2014-05-07 09:47:02 +07:00
$xmlWriter->endElement();
}
if (!$this->withoutP) {
2014-05-07 09:47:02 +07:00
$xmlWriter->endElement(); // text:p
}
}
}
}