Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
44 / 44 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
TextStyle | |
100.00% |
44 / 44 |
|
100.00% |
11 / 11 |
23 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
2 | |||
checkLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
setBodyStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setTitleStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setOtherStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getBodyStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
getTitleStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
getOtherStyleAtLvl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
getBodyStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTitleStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOtherStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation 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/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation\Style; |
21 | |
22 | use PhpOffice\PhpPresentation\Shape\RichText\Paragraph as RichTextParagraph; |
23 | |
24 | class TextStyle |
25 | { |
26 | /** |
27 | * @var array<int, RichTextParagraph> |
28 | */ |
29 | protected $bodyStyle = []; |
30 | |
31 | /** |
32 | * @var array<int, RichTextParagraph> |
33 | */ |
34 | protected $titleStyle = []; |
35 | |
36 | /** |
37 | * @var array<int, RichTextParagraph> |
38 | */ |
39 | protected $otherStyle = []; |
40 | |
41 | /** |
42 | * TextStyle constructor. |
43 | */ |
44 | public function __construct(bool $default = true) |
45 | { |
46 | if ($default) { |
47 | $oColorLT1 = new SchemeColor(); |
48 | $oColorLT1->setValue('lt1'); |
49 | $oColorTX1 = new SchemeColor(); |
50 | $oColorTX1->setValue('tx1'); |
51 | |
52 | $oRTParagraphBody = new RichTextParagraph(); |
53 | $oRTParagraphBody->getAlignment() |
54 | ->setHorizontal(Alignment::HORIZONTAL_CENTER) |
55 | ->setIndent(-324900 / 9525) |
56 | ->setMarginLeft(342900 / 9525); |
57 | $oRTParagraphBody->getFont()->setSize(32)->setColor($oColorTX1); |
58 | $this->bodyStyle[1] = $oRTParagraphBody; |
59 | |
60 | $oRTParagraphOther = new RichTextParagraph(); |
61 | $oRTParagraphOther->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
62 | $oRTParagraphOther->getFont()->setSize(10)->setColor($oColorTX1); |
63 | $this->otherStyle[0] = $oRTParagraphOther; |
64 | |
65 | $oRTParagraphTitle = new RichTextParagraph(); |
66 | $oRTParagraphTitle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
67 | $oRTParagraphTitle->getFont()->setSize(44)->setColor($oColorLT1); |
68 | $this->titleStyle[1] = $oRTParagraphTitle; |
69 | } |
70 | } |
71 | |
72 | private function checkLvl(?int $lvl): bool |
73 | { |
74 | if (null === $lvl || $lvl > 9) { |
75 | return false; |
76 | } |
77 | |
78 | return true; |
79 | } |
80 | |
81 | public function setBodyStyleAtLvl(RichTextParagraph $style, ?int $lvl): self |
82 | { |
83 | if ($this->checkLvl($lvl)) { |
84 | $this->bodyStyle[$lvl] = $style; |
85 | } |
86 | |
87 | return $this; |
88 | } |
89 | |
90 | public function setTitleStyleAtLvl(RichTextParagraph $style, ?int $lvl): self |
91 | { |
92 | if ($this->checkLvl($lvl)) { |
93 | $this->titleStyle[$lvl] = $style; |
94 | } |
95 | |
96 | return $this; |
97 | } |
98 | |
99 | public function setOtherStyleAtLvl(RichTextParagraph $style, ?int $lvl): self |
100 | { |
101 | if ($this->checkLvl($lvl)) { |
102 | $this->otherStyle[$lvl] = $style; |
103 | } |
104 | |
105 | return $this; |
106 | } |
107 | |
108 | public function getBodyStyleAtLvl(?int $lvl): ?RichTextParagraph |
109 | { |
110 | if ($this->checkLvl($lvl) && !empty($this->bodyStyle[$lvl])) { |
111 | return $this->bodyStyle[$lvl]; |
112 | } |
113 | |
114 | return null; |
115 | } |
116 | |
117 | public function getTitleStyleAtLvl(?int $lvl): ?RichTextParagraph |
118 | { |
119 | if ($this->checkLvl($lvl) && !empty($this->titleStyle[$lvl])) { |
120 | return $this->titleStyle[$lvl]; |
121 | } |
122 | |
123 | return null; |
124 | } |
125 | |
126 | public function getOtherStyleAtLvl(?int $lvl): ?RichTextParagraph |
127 | { |
128 | if ($this->checkLvl($lvl) && !empty($this->otherStyle[$lvl])) { |
129 | return $this->otherStyle[$lvl]; |
130 | } |
131 | |
132 | return null; |
133 | } |
134 | |
135 | /** |
136 | * @return array<int, RichTextParagraph> |
137 | */ |
138 | public function getBodyStyle(): array |
139 | { |
140 | return $this->bodyStyle; |
141 | } |
142 | |
143 | /** |
144 | * @return array<int, RichTextParagraph> |
145 | */ |
146 | public function getTitleStyle(): array |
147 | { |
148 | return $this->titleStyle; |
149 | } |
150 | |
151 | /** |
152 | * @return array<int, RichTextParagraph> |
153 | */ |
154 | public function getOtherStyle(): array |
155 | { |
156 | return $this->otherStyle; |
157 | } |
158 | } |