Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Title | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| write | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | * word processing documents. |
| 6 | * |
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | * General Public License version 3 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * For the full copyright and license information, please read the LICENSE |
| 11 | * file that was distributed with this source code. For the full list of |
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | * |
| 14 | * @see https://github.com/PHPOffice/PHPWord |
| 15 | * |
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | */ |
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Writer\Word2007\Element; |
| 20 | |
| 21 | /** |
| 22 | * TextRun element writer. |
| 23 | * |
| 24 | * @since 0.10.0 |
| 25 | */ |
| 26 | class Title extends AbstractElement |
| 27 | { |
| 28 | /** |
| 29 | * Write title element. |
| 30 | */ |
| 31 | public function write(): void |
| 32 | { |
| 33 | $xmlWriter = $this->getXmlWriter(); |
| 34 | $element = $this->getElement(); |
| 35 | if (!$element instanceof \PhpOffice\PhpWord\Element\Title) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $style = $element->getStyle(); |
| 40 | |
| 41 | $xmlWriter->startElement('w:p'); |
| 42 | |
| 43 | if (!empty($style)) { |
| 44 | $xmlWriter->startElement('w:pPr'); |
| 45 | $xmlWriter->startElement('w:pStyle'); |
| 46 | $xmlWriter->writeAttribute('w:val', $style); |
| 47 | $xmlWriter->endElement(); |
| 48 | $xmlWriter->endElement(); |
| 49 | } |
| 50 | |
| 51 | $bookmarkRId = null; |
| 52 | if ($element->getDepth() !== 0) { |
| 53 | $rId = $element->getRelationId(); |
| 54 | $bookmarkRId = $element->getPhpWord()->addBookmark(); |
| 55 | |
| 56 | // Bookmark start for TOC |
| 57 | $xmlWriter->startElement('w:bookmarkStart'); |
| 58 | $xmlWriter->writeAttribute('w:id', $bookmarkRId); |
| 59 | $xmlWriter->writeAttribute('w:name', "_Toc{$rId}"); |
| 60 | $xmlWriter->endElement(); //w:bookmarkStart |
| 61 | } |
| 62 | |
| 63 | // Actual text |
| 64 | $text = $element->getText(); |
| 65 | if (is_string($text)) { |
| 66 | $xmlWriter->startElement('w:r'); |
| 67 | $xmlWriter->startElement('w:t'); |
| 68 | $this->writeText($text); |
| 69 | $xmlWriter->endElement(); // w:t |
| 70 | $xmlWriter->endElement(); // w:r |
| 71 | } |
| 72 | if ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { |
| 73 | $containerWriter = new Container($xmlWriter, $text); |
| 74 | $containerWriter->write(); |
| 75 | } |
| 76 | |
| 77 | if ($element->getDepth() !== 0) { |
| 78 | // Bookmark end |
| 79 | $xmlWriter->startElement('w:bookmarkEnd'); |
| 80 | $xmlWriter->writeAttribute('w:id', $bookmarkRId); |
| 81 | $xmlWriter->endElement(); //w:bookmarkEnd |
| 82 | } |
| 83 | $xmlWriter->endElement(); //w:p |
| 84 | } |
| 85 | } |