Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
46 / 46 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Font | |
100.00% |
46 / 46 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
write | |
100.00% |
46 / 46 |
|
100.00% |
1 / 1 |
5 |
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\Style; |
20 | |
21 | /** |
22 | * Font style writer. |
23 | * |
24 | * @since 0.10.0 |
25 | */ |
26 | class Font extends AbstractStyle |
27 | { |
28 | /** |
29 | * Write style. |
30 | */ |
31 | public function write(): void |
32 | { |
33 | $style = $this->getStyle(); |
34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { |
35 | return; |
36 | } |
37 | $xmlWriter = $this->getXmlWriter(); |
38 | |
39 | $stylep = (method_exists($style, 'getParagraph')) ? $style->getParagraph() : null; |
40 | if ($stylep instanceof \PhpOffice\PhpWord\Style\Paragraph) { |
41 | $temp1 = clone $stylep; |
42 | $temp1->setStyleName($style->getStyleName()); |
43 | $temp2 = new Paragraph($xmlWriter, $temp1); |
44 | $temp2->write(); |
45 | } |
46 | |
47 | $xmlWriter->startElement('style:style'); |
48 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); |
49 | $xmlWriter->writeAttribute('style:family', 'text'); |
50 | $xmlWriter->startElement('style:text-properties'); |
51 | |
52 | // Name |
53 | $font = $style->getName(); |
54 | $xmlWriter->writeAttributeIf($font != '', 'style:font-name', $font); |
55 | $xmlWriter->writeAttributeIf($font != '', 'style:font-name-complex', $font); |
56 | $size = $style->getSize(); |
57 | |
58 | // Size |
59 | $xmlWriter->writeAttributeIf(is_numeric($size), 'fo:font-size', $size . 'pt'); |
60 | $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-asian', $size . 'pt'); |
61 | $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-complex', $size . 'pt'); |
62 | |
63 | // Color |
64 | $color = $style->getColor(); |
65 | $xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . \PhpOffice\PhpWord\Shared\Converter::stringToRgb($color)); |
66 | |
67 | // Bold & italic |
68 | $xmlWriter->writeAttributeIf($style->isBold(), 'fo:font-weight', 'bold'); |
69 | $xmlWriter->writeAttributeIf($style->isBold(), 'style:font-weight-asian', 'bold'); |
70 | $xmlWriter->writeAttributeIf($style->isItalic(), 'fo:font-style', 'italic'); |
71 | $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-asian', 'italic'); |
72 | $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-complex', 'italic'); |
73 | |
74 | // Underline |
75 | // @todo Various mode of underline |
76 | $underline = $style->getUnderline(); |
77 | $xmlWriter->writeAttributeIf($underline != 'none', 'style:text-underline-style', 'solid'); |
78 | |
79 | // Strikethrough, double strikethrough |
80 | $xmlWriter->writeAttributeIf($style->isStrikethrough(), 'style:text-line-through-type', 'single'); |
81 | $xmlWriter->writeAttributeIf($style->isDoubleStrikethrough(), 'style:text-line-through-type', 'double'); |
82 | |
83 | // Small caps, all caps |
84 | $xmlWriter->writeAttributeIf($style->isSmallCaps(), 'fo:font-variant', 'small-caps'); |
85 | $xmlWriter->writeAttributeIf($style->isAllCaps(), 'fo:text-transform', 'uppercase'); |
86 | |
87 | //Hidden text |
88 | $xmlWriter->writeAttributeIf($style->isHidden(), 'text:display', 'none'); |
89 | |
90 | // Superscript/subscript |
91 | $xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super'); |
92 | $xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub'); |
93 | |
94 | if ($style->isNoProof()) { |
95 | $xmlWriter->writeAttribute('fo:language', 'zxx'); |
96 | $xmlWriter->writeAttribute('style:language-asian', 'zxx'); |
97 | $xmlWriter->writeAttribute('style:language-complex', 'zxx'); |
98 | $xmlWriter->writeAttribute('fo:country', 'none'); |
99 | $xmlWriter->writeAttribute('style:country-asian', 'none'); |
100 | $xmlWriter->writeAttribute('style:country-complex', 'none'); |
101 | } |
102 | |
103 | // @todo Foreground-Color |
104 | |
105 | // @todo Background color |
106 | |
107 | $xmlWriter->endElement(); // style:text-properties |
108 | $xmlWriter->endElement(); // style:style |
109 | } |
110 | } |