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 | /** |
| 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\ODText\Part; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Element\AbstractElement; |
| 22 | use PhpOffice\PhpWord\Settings; |
| 23 | use PhpOffice\PhpWord\Shared\XMLWriter; |
| 24 | use PhpOffice\PhpWord\Style; |
| 25 | use PhpOffice\PhpWord\Style\Font; |
| 26 | use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart; |
| 27 | |
| 28 | /** |
| 29 | * ODText writer part abstract. |
| 30 | */ |
| 31 | abstract class AbstractPart extends Word2007AbstractPart |
| 32 | { |
| 33 | /** |
| 34 | * @var AbstractElement[] |
| 35 | */ |
| 36 | protected $objects = []; |
| 37 | |
| 38 | /** |
| 39 | * @var string Date format |
| 40 | */ |
| 41 | protected $dateFormat = 'Y-m-d\TH:i:s.000'; |
| 42 | |
| 43 | /** |
| 44 | * Write common root attributes. |
| 45 | */ |
| 46 | protected function writeCommonRootAttributes(XMLWriter $xmlWriter): void |
| 47 | { |
| 48 | $xmlWriter->writeAttribute('office:version', '1.2'); |
| 49 | $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
| 50 | $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
| 51 | $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
| 52 | $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
| 53 | $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
| 54 | $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
| 55 | $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
| 56 | $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
| 57 | $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
| 58 | $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
| 59 | $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
| 60 | $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
| 61 | $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
| 62 | $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
| 63 | $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
| 64 | $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
| 65 | $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
| 66 | $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
| 67 | $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
| 68 | $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
| 69 | $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
| 70 | $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
| 71 | $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); |
| 72 | $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
| 73 | $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); |
| 74 | $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Write font faces declaration. |
| 79 | */ |
| 80 | protected function writeFontFaces(XMLWriter $xmlWriter): void |
| 81 | { |
| 82 | $xmlWriter->startElement('office:font-face-decls'); |
| 83 | $fontTable = []; |
| 84 | $styles = Style::getStyles(); |
| 85 | $numFonts = 0; |
| 86 | if (count($styles) > 0) { |
| 87 | foreach ($styles as $style) { |
| 88 | // Font |
| 89 | if ($style instanceof Font) { |
| 90 | ++$numFonts; |
| 91 | $name = $style->getName(); |
| 92 | if (!in_array($name, $fontTable)) { |
| 93 | $fontTable[] = $name; |
| 94 | |
| 95 | // style:font-face |
| 96 | $xmlWriter->startElement('style:font-face'); |
| 97 | $xmlWriter->writeAttribute('style:name', $name); |
| 98 | $xmlWriter->writeAttribute('svg:font-family', $name); |
| 99 | $xmlWriter->endElement(); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | if (!in_array(Settings::getDefaultFontName(), $fontTable)) { |
| 105 | $xmlWriter->startElement('style:font-face'); |
| 106 | $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName()); |
| 107 | $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName()); |
| 108 | $xmlWriter->endElement(); |
| 109 | } |
| 110 | $xmlWriter->endElement(); |
| 111 | } |
| 112 | |
| 113 | public function addObject(AbstractElement $object): int |
| 114 | { |
| 115 | $this->objects[] = $object; |
| 116 | |
| 117 | return count($this->objects) - 1; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @param AbstractElement[] $objects |
| 122 | */ |
| 123 | public function setObjects(array $objects): self |
| 124 | { |
| 125 | $this->objects = $objects; |
| 126 | |
| 127 | return $this; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @return AbstractElement[] |
| 132 | */ |
| 133 | public function getObjects(): array |
| 134 | { |
| 135 | return $this->objects; |
| 136 | } |
| 137 | } |