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