75 lines
2.7 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
* @copyright 2010-2014 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;
/**
* 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();
$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);
}
2014-05-07 09:47:02 +07:00
$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);
}
2014-05-07 09:47:02 +07:00
$xmlWriter->writeRaw($element->getText());
$xmlWriter->endElement();
}
if (!$this->withoutP) {
2014-05-07 09:47:02 +07:00
$xmlWriter->endElement(); // text:p
}
}
}
}