Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Font | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
write | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
2 | |||
setNameIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setColorIndex | |
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\RTF\Style; |
19 | |
20 | use PhpOffice\PhpWord\Style\Font as FontStyle; |
21 | |
22 | /** |
23 | * RTF font style writer. |
24 | * |
25 | * @since 0.11.0 |
26 | */ |
27 | class Font extends AbstractStyle |
28 | { |
29 | /** |
30 | * @var int Font name index |
31 | */ |
32 | private $nameIndex = 0; |
33 | |
34 | /** |
35 | * @var int Font color index |
36 | */ |
37 | private $colorIndex = 0; |
38 | |
39 | /** |
40 | * Write style. |
41 | * |
42 | * @return string |
43 | */ |
44 | public function write() |
45 | { |
46 | $style = $this->getStyle(); |
47 | if (!$style instanceof FontStyle) { |
48 | return ''; |
49 | } |
50 | |
51 | $content = ''; |
52 | $content .= $this->getValueIf($style->isRTL(), '\rtlch'); |
53 | $content .= '\cf' . $this->colorIndex; |
54 | $content .= '\f' . $this->nameIndex; |
55 | |
56 | $size = $style->getSize(); |
57 | $content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2)); |
58 | |
59 | $content .= $this->getValueIf($style->isBold(), '\b'); |
60 | $content .= $this->getValueIf($style->isItalic(), '\i'); |
61 | $content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul'); |
62 | $content .= $this->getValueIf($style->isStrikethrough(), '\strike'); |
63 | $content .= $this->getValueIf($style->isSuperScript(), '\super'); |
64 | $content .= $this->getValueIf($style->isSubScript(), '\sub'); |
65 | |
66 | return $content . ' '; |
67 | } |
68 | |
69 | /** |
70 | * Set font name index. |
71 | * |
72 | * @param int $value |
73 | */ |
74 | public function setNameIndex($value = 0): void |
75 | { |
76 | $this->nameIndex = $value; |
77 | } |
78 | |
79 | /** |
80 | * Set font color index. |
81 | * |
82 | * @param int $value |
83 | */ |
84 | public function setColorIndex($value = 0): void |
85 | { |
86 | $this->colorIndex = $value; |
87 | } |
88 | } |