Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
53 / 53 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
AbstractPart | |
100.00% |
53 / 53 |
|
100.00% |
5 / 5 |
10 | |
100.00% |
1 / 1 |
writeCommonRootAttributes | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
1 | |||
writeFontFaces | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
6 | |||
addObject | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setObjects | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getObjects | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Writer\ODText\Part; |
19 | |
20 | use PhpOffice\PhpWord\Element\AbstractElement; |
21 | use PhpOffice\PhpWord\Settings; |
22 | use PhpOffice\PhpWord\Shared\XMLWriter; |
23 | use PhpOffice\PhpWord\Style; |
24 | use PhpOffice\PhpWord\Style\Font; |
25 | use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart; |
26 | |
27 | /** |
28 | * ODText writer part abstract. |
29 | */ |
30 | abstract class AbstractPart extends Word2007AbstractPart |
31 | { |
32 | /** |
33 | * @var AbstractElement[] |
34 | */ |
35 | protected $objects = []; |
36 | |
37 | /** |
38 | * @var string Date format |
39 | */ |
40 | protected $dateFormat = 'Y-m-d\TH:i:s.000'; |
41 | |
42 | /** |
43 | * Write common root attributes. |
44 | */ |
45 | protected function writeCommonRootAttributes(XMLWriter $xmlWriter): void |
46 | { |
47 | $xmlWriter->writeAttribute('office:version', '1.2'); |
48 | $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
49 | $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
50 | $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
51 | $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
52 | $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
53 | $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
54 | $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
55 | $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
56 | $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
57 | $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
58 | $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
59 | $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
60 | $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
61 | $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
62 | $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
63 | $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
64 | $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
65 | $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
66 | $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
67 | $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
68 | $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
69 | $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
70 | $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); |
71 | $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
72 | $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); |
73 | $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); |
74 | } |
75 | |
76 | /** |
77 | * Write font faces declaration. |
78 | */ |
79 | protected function writeFontFaces(XMLWriter $xmlWriter): void |
80 | { |
81 | $xmlWriter->startElement('office:font-face-decls'); |
82 | $fontTable = []; |
83 | $styles = Style::getStyles(); |
84 | $numFonts = 0; |
85 | if (count($styles) > 0) { |
86 | foreach ($styles as $style) { |
87 | // Font |
88 | if ($style instanceof Font) { |
89 | ++$numFonts; |
90 | $name = $style->getName(); |
91 | if (!in_array($name, $fontTable)) { |
92 | $fontTable[] = $name; |
93 | |
94 | // style:font-face |
95 | $xmlWriter->startElement('style:font-face'); |
96 | $xmlWriter->writeAttribute('style:name', $name); |
97 | $xmlWriter->writeAttribute('svg:font-family', $name); |
98 | $xmlWriter->endElement(); |
99 | } |
100 | } |
101 | } |
102 | } |
103 | if (!in_array(Settings::getDefaultFontName(), $fontTable)) { |
104 | $xmlWriter->startElement('style:font-face'); |
105 | $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName()); |
106 | $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName()); |
107 | $xmlWriter->endElement(); |
108 | } |
109 | $xmlWriter->endElement(); |
110 | } |
111 | |
112 | public function addObject(AbstractElement $object): int |
113 | { |
114 | $this->objects[] = $object; |
115 | |
116 | return count($this->objects) - 1; |
117 | } |
118 | |
119 | /** |
120 | * @param AbstractElement[] $objects |
121 | */ |
122 | public function setObjects(array $objects): self |
123 | { |
124 | $this->objects = $objects; |
125 | |
126 | return $this; |
127 | } |
128 | |
129 | /** |
130 | * @return AbstractElement[] |
131 | */ |
132 | public function getObjects(): array |
133 | { |
134 | return $this->objects; |
135 | } |
136 | } |