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