2014-04-25 10:33:45 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-25 10:33:45 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|
|
|
|
|
|
|
|
|
use PhpOffice\PhpWord\Shared\String;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TextRun element writer
|
|
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
|
|
|
|
class Title extends Element
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Write title element
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
|
|
|
|
$bookmarkId = $this->element->getBookmarkId();
|
2014-05-04 00:57:44 +07:00
|
|
|
$anchor = '_Toc' . ($bookmarkId + 252634154);
|
2014-04-25 10:33:45 +07:00
|
|
|
$style = $this->element->getStyle();
|
|
|
|
|
$text = htmlspecialchars($this->element->getText());
|
|
|
|
|
$text = String::controlCharacterPHP2OOXML($text);
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:p');
|
|
|
|
|
|
|
|
|
|
if (!empty($style)) {
|
|
|
|
|
$this->xmlWriter->startElement('w:pPr');
|
|
|
|
|
$this->xmlWriter->startElement('w:pStyle');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:val', $style);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:r');
|
|
|
|
|
$this->xmlWriter->startElement('w:fldChar');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:fldCharType', 'end');
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:bookmarkStart');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:id', $bookmarkId);
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:name', $anchor);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:r');
|
|
|
|
|
$this->xmlWriter->startElement('w:t');
|
|
|
|
|
$this->xmlWriter->writeRaw($text);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:bookmarkEnd');
|
|
|
|
|
$this->xmlWriter->writeAttribute('w:id', $bookmarkId);
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
|
|
|
|
|
$this->xmlWriter->endElement();
|
|
|
|
|
}
|
|
|
|
|
}
|