Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
36 / 36 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Text | |
100.00% |
36 / 36 |
|
100.00% |
3 / 3 |
11 | |
100.00% |
1 / 1 |
write | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
4 | |||
writeOpeningTrackChange | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
writeClosingTrackChange | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
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 | use PhpOffice\PhpWord\Element\TrackChange; |
22 | |
23 | /** |
24 | * Text element writer. |
25 | * |
26 | * @since 0.10.0 |
27 | */ |
28 | class Text extends AbstractElement |
29 | { |
30 | /** |
31 | * Write text element. |
32 | */ |
33 | public function write(): void |
34 | { |
35 | $xmlWriter = $this->getXmlWriter(); |
36 | $element = $this->getElement(); |
37 | if (!$element instanceof \PhpOffice\PhpWord\Element\Text) { |
38 | return; |
39 | } |
40 | |
41 | $this->startElementP(); |
42 | |
43 | $this->writeOpeningTrackChange(); |
44 | |
45 | $xmlWriter->startElement('w:r'); |
46 | |
47 | $this->writeFontStyle(); |
48 | |
49 | $textElement = 'w:t'; |
50 | //'w:delText' in case of deleted text |
51 | $changed = $element->getTrackChange(); |
52 | if ($changed != null && $changed->getChangeType() == TrackChange::DELETED) { |
53 | $textElement = 'w:delText'; |
54 | } |
55 | $xmlWriter->startElement($textElement); |
56 | |
57 | $xmlWriter->writeAttribute('xml:space', 'preserve'); |
58 | $this->writeText($this->getText($element->getText())); |
59 | $xmlWriter->endElement(); |
60 | $xmlWriter->endElement(); // w:r |
61 | |
62 | $this->writeClosingTrackChange(); |
63 | |
64 | $this->endElementP(); // w:p |
65 | } |
66 | |
67 | /** |
68 | * Write opening of changed element. |
69 | */ |
70 | protected function writeOpeningTrackChange(): void |
71 | { |
72 | $changed = $this->getElement()->getTrackChange(); |
73 | if ($changed == null) { |
74 | return; |
75 | } |
76 | |
77 | $xmlWriter = $this->getXmlWriter(); |
78 | |
79 | if (($changed->getChangeType() == TrackChange::INSERTED)) { |
80 | $xmlWriter->startElement('w:ins'); |
81 | } elseif ($changed->getChangeType() == TrackChange::DELETED) { |
82 | $xmlWriter->startElement('w:del'); |
83 | } |
84 | $xmlWriter->writeAttribute('w:author', $changed->getAuthor()); |
85 | if ($changed->getDate() != null) { |
86 | $xmlWriter->writeAttribute('w:date', $changed->getDate()->format('Y-m-d\TH:i:s\Z')); |
87 | } |
88 | $xmlWriter->writeAttribute('w:id', $this->getElement()->getElementId()); |
89 | } |
90 | |
91 | /** |
92 | * Write ending. |
93 | */ |
94 | protected function writeClosingTrackChange(): void |
95 | { |
96 | $changed = $this->getElement()->getTrackChange(); |
97 | if ($changed == null) { |
98 | return; |
99 | } |
100 | |
101 | $xmlWriter = $this->getXmlWriter(); |
102 | |
103 | $xmlWriter->endElement(); // w:ins|w:del |
104 | } |
105 | } |