|
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
|
|
|
* @link https://github.com/PHPOffice/PHPPresentation |
|
14
|
|
|
* @copyright 2009-2015 PHPPresentation contributors |
|
15
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace PhpOffice\PhpPresentation\Style; |
|
19
|
|
|
|
|
20
|
|
|
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph as RichTextParagraph; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class TextStyle |
|
24
|
|
|
*/ |
|
25
|
|
|
class TextStyle |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $bodyStyle = array(); |
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $titleStyle = array(); |
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $otherStyle = array(); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* TextStyle constructor. |
|
42
|
|
|
* @param bool $default |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct($default = true) |
|
45
|
|
|
{ |
|
46
|
|
|
if ($default) { |
|
47
|
|
|
$oRTParagraph = new RichTextParagraph(); |
|
48
|
|
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
|
49
|
|
|
$oRTParagraph->getFont()->setSize(44)->setColor(new SchemeColor())->getColor()->setValue("lt1"); |
|
|
|
|
|
|
50
|
|
|
$this->titleStyle[1] = $oRTParagraph; |
|
51
|
|
|
$oRTParagraph = new RichTextParagraph(); |
|
52
|
|
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER) |
|
53
|
|
|
->setIndent(-324900 / 9525) |
|
54
|
|
|
->setMarginLeft(342900 / 9525); |
|
55
|
|
|
$oRTParagraph->getFont()->setSize(32)->setColor(new SchemeColor())->getColor()->setValue("tx1"); |
|
|
|
|
|
|
56
|
|
|
$this->bodyStyle[1] = $oRTParagraph; |
|
57
|
|
|
$oRTParagraph = new RichTextParagraph(); |
|
58
|
|
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
|
59
|
|
|
$oRTParagraph->getFont()->setSize(10)->setColor(new SchemeColor())->getColor()->setValue("tx1"); |
|
|
|
|
|
|
60
|
|
|
$this->otherStyle[0] = $oRTParagraph; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $lvl |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
private function checkLvl($lvl) |
|
69
|
|
|
{ |
|
70
|
|
|
if (!is_int($lvl)) { |
|
71
|
|
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
if ($lvl > 9) { |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param RichTextParagraph $style |
|
81
|
|
|
* @param $lvl |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setBodyStyleAtLvl(RichTextParagraph $style, $lvl) |
|
84
|
|
|
{ |
|
85
|
|
|
if (!$this->checkLvl($lvl)) { |
|
86
|
|
|
$this->bodyStyle[$lvl] = $style; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param RichTextParagraph $style |
|
92
|
|
|
* @param $lvl |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setTitleStyleAtLvl(RichTextParagraph $style, $lvl) |
|
95
|
|
|
{ |
|
96
|
|
|
if (!$this->checkLvl($lvl)) { |
|
97
|
|
|
$this->titleStyle[$lvl] = $style; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param RichTextParagraph $style |
|
103
|
|
|
* @param $lvl |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setOtherStyleAtLvl(RichTextParagraph $style, $lvl) |
|
106
|
|
|
{ |
|
107
|
|
|
if (!$this->checkLvl($lvl)) { |
|
108
|
|
|
$this->otherStyle[$lvl] = $style; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param $lvl |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getBodyStyleAtLvl($lvl) |
|
117
|
|
|
{ |
|
118
|
|
|
if (!$this->checkLvl($lvl)) { |
|
119
|
|
|
return $this->bodyStyle[$lvl]; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param $lvl |
|
125
|
|
|
* @return mixed |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getTitleStyleAtLvl($lvl) |
|
128
|
|
|
{ |
|
129
|
|
|
if (!$this->checkLvl($lvl)) { |
|
130
|
|
|
return $this->bodyStyle[$lvl]; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param $lvl |
|
136
|
|
|
* @return mixed |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getOtherStyleAtLvl($lvl) |
|
139
|
|
|
{ |
|
140
|
|
|
if (!$this->checkLvl($lvl)) { |
|
141
|
|
|
return $this->bodyStyle[$lvl]; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return array |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getBodyStyle() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->bodyStyle; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return array |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getTitleStyle() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->titleStyle; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @return array |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getOtherStyle() |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->otherStyle; |
|
167
|
|
|
} |
|
168
|
|
|
// |
|
169
|
|
|
// |
|
170
|
|
|
// |
|
171
|
|
|
// |
|
172
|
|
|
// |
|
173
|
|
|
// |
|
174
|
|
|
// |
|
175
|
|
|
// |
|
176
|
|
|
// |
|
177
|
|
|
// |
|
178
|
|
|
// |
|
179
|
|
|
//<p:titleStyle> |
|
180
|
|
|
// <a:lvl1pPr algn="ctr" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1"> |
|
181
|
|
|
// <a:spcBef> |
|
182
|
|
|
// <a:spcPct val="0" /> |
|
183
|
|
|
// </a:spcBef> |
|
184
|
|
|
// <a:buNone /> |
|
185
|
|
|
// <a:defRPr sz="4400" kern="1200"> |
|
186
|
|
|
// <a:solidFill> |
|
187
|
|
|
// <a:schemeClr val="tx1" /> |
|
188
|
|
|
// </a:solidFill> |
|
189
|
|
|
// <a:latin typeface="+mj-lt" /> |
|
190
|
|
|
// <a:ea typeface="+mj-ea" /> |
|
191
|
|
|
// <a:cs typeface="+mj-cs" /> |
|
192
|
|
|
// </a:defRPr> |
|
193
|
|
|
// </a:lvl1pPr> |
|
194
|
|
|
//</p:titleStyle> |
|
195
|
|
|
// |
|
196
|
|
|
// |
|
197
|
|
|
// // Create a shape (text) |
|
198
|
|
|
//echo date('H:i:s') . ' Create a shape (rich text)'.EOL; |
|
199
|
|
|
//$shape = $currentSlide->createRichTextShape(); |
|
200
|
|
|
//$shape->setHeight(600) |
|
201
|
|
|
//->setWidth(930) |
|
202
|
|
|
//->setOffsetX(10) |
|
203
|
|
|
//->setOffsetY(130); |
|
204
|
|
|
//$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT) |
|
205
|
|
|
//->setMarginLeft(25) |
|
206
|
|
|
//->setIndent(-25); |
|
207
|
|
|
//$shape->getActiveParagraph()->getFont()->setSize(36) |
|
208
|
|
|
//->setColor($colorBlack); |
|
209
|
|
|
//$shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET); |
|
210
|
|
|
// |
|
211
|
|
|
//$shape->createTextRun('Generate slide decks'); |
|
212
|
|
|
// |
|
213
|
|
|
//$shape->createParagraph()->getAlignment()->setLevel(1) |
|
214
|
|
|
//->setMarginLeft(75) |
|
215
|
|
|
//->setIndent(-25); |
|
216
|
|
|
//$shape->createTextRun('Represent business data'); |
|
217
|
|
|
//$shape->createParagraph()->createTextRun('Show a family slide show'); |
|
218
|
|
|
//$shape->createParagraph()->createTextRun('...'); |
|
219
|
|
|
// |
|
220
|
|
|
//$shape->createParagraph()->getAlignment()->setLevel(0) |
|
221
|
|
|
//->setMarginLeft(25) |
|
222
|
|
|
//->setIndent(-25); |
|
223
|
|
|
//$shape->createTextRun('Export these to different formats'); |
|
224
|
|
|
//$shape->createParagraph()->getAlignment()->setLevel(1) |
|
225
|
|
|
//->setMarginLeft(75) |
|
226
|
|
|
//->setIndent(-25); |
|
227
|
|
|
//$shape->createTextRun('PHPPresentation 2007'); |
|
228
|
|
|
//$shape->createParagraph()->createTextRun('Serialized'); |
|
229
|
|
|
//$shape->createParagraph()->createTextRun('... (more to come) ...'); |
|
230
|
|
|
// |
|
231
|
|
|
/** |
|
232
|
|
|
* Text Styles |
|
233
|
|
|
* p:bodyStyle |
|
234
|
|
|
* p:titleStyle |
|
235
|
|
|
* p:otherStyle |
|
236
|
|
|
* |
|
237
|
|
|
* a:defPPr |
|
238
|
|
|
* a:lvl1pPr |
|
239
|
|
|
* . |
|
240
|
|
|
* . |
|
241
|
|
|
* . |
|
242
|
|
|
* a:lvl9pPr |
|
243
|
|
|
* attributes |
|
244
|
|
|
* - algn (alignment) |
|
245
|
|
|
* - defTabSz (default tab size) |
|
246
|
|
|
* - fontAlgn (font alignment) |
|
247
|
|
|
* - hangingPunct (specifies the handling of hanging text) |
|
248
|
|
|
* - indent (indentation for the first line of text) |
|
249
|
|
|
* - latinLnBrk (specifies whether to break words) |
|
250
|
|
|
* - marL and marR (left and right margins) |
|
251
|
|
|
* - lang |
|
252
|
|
|
*elements* |
|
253
|
|
|
* |
|
254
|
|
|
* Bullets & Numbering (http://officeopenxml.com/drwSp-text-paraProps-numbering.php) |
|
255
|
|
|
* <a:buAutoNum/> (auto-numbering bullet) |
|
256
|
|
|
* <a:buBlip> (picture bullet) |
|
257
|
|
|
* <a:buChar/> (character bullet) |
|
258
|
|
|
* <a:buClr> (color of bullets) |
|
259
|
|
|
* <a:buClrTx> (color of bullets is same as text run) |
|
260
|
|
|
* <a:buFont/> (font for bullets) |
|
261
|
|
|
* <a:buFontTx> (font for bullets is same as text run) |
|
262
|
|
|
* <a:buNone> (no bullet) |
|
263
|
|
|
* <a:buSzPct> (size in percentage of bullet characters) |
|
264
|
|
|
* <a:buSzPts/> (size in points of bullet characters) |
|
265
|
|
|
* <a:buSzTx> (size of bullet characters to be size of text run) |
|
266
|
|
|
* |
|
267
|
|
|
* List Properties and Default Style. (http://officeopenxml.com/drwSp-text-lstPr.php) |
|
268
|
|
|
* <a:defRPr> (default text run properties) |
|
269
|
|
|
* |
|
270
|
|
|
* Text - Spacing, Indents and Margins. (http://officeopenxml.com/drwSp-text-paraProps-margins.php) |
|
271
|
|
|
* <a:lnSpc> (line spacing) |
|
272
|
|
|
* <a:spcAft> (spacing after the paragraph) |
|
273
|
|
|
* <a:spcBef> (spacing before the paragraph) |
|
274
|
|
|
* |
|
275
|
|
|
* Text - Alignment, Tabs, Other (http://officeopenxml.com/drwSp-text-paraProps-align.php) |
|
276
|
|
|
* <a:tabLst> (list of tab stops in a paragraph) |
|
277
|
|
|
*/ |
|
278
|
|
|
} |
|
279
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: