| 23 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
//require_once 'class.style.php';
|
|
|
4 |
//require_once 'exceptions/class.styleexception.php';
|
|
|
5 |
|
|
|
6 |
include_once 'phpodt.php';
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* A Class representing style properties for text content.
|
|
|
10 |
*
|
|
|
11 |
* @author Issam RACHDI
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class TextStyle extends Style {
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
public function __construct($name = '') {
|
|
|
18 |
if (empty($name)) {
|
|
|
19 |
$name = 'textstyle'.rand(100, 9999999);
|
|
|
20 |
}
|
|
|
21 |
parent::__construct($name);
|
|
|
22 |
$this->styleElement->setAttribute('style:family', 'text');
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Possible values are StyleConstants::NONE, StyleConstants::LOWER_CASE,
|
|
|
27 |
* StyleConstants::UPPER_CASE and StyleConstants::CAPITALIZE.
|
|
|
28 |
* In case the value passed is equal to none of these values, a StyleException is thrown
|
|
|
29 |
* @param integer $transform
|
|
|
30 |
*/
|
|
|
31 |
function setTextTransform($transform) {
|
|
|
32 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
33 |
switch($transform) {
|
|
|
34 |
case StyleConstants::NONE:
|
|
|
35 |
$attrTransform = 'none';break;
|
|
|
36 |
case StyleConstants::LOWER_CASE:
|
|
|
37 |
$attrTransform = 'lowercase';break;
|
|
|
38 |
case StyleConstants::UPPER_CASE:
|
|
|
39 |
$attrTransform = 'uppercase';break;
|
|
|
40 |
case StyleConstants::CAPITALIZE:
|
|
|
41 |
$attrTransform = 'capitalize';break;
|
|
|
42 |
default: throw new StyleException($transform.' is not a valid "text-transform" value.');
|
|
|
43 |
}
|
|
|
44 |
$element->setAttribute('fo:text-transform', $attrTransform);
|
|
|
45 |
$this->styleElement->appendChild($element);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Changes the color of the text. The value passed
|
|
|
50 |
* must be a 6 character hexadecimal value, for example #FF0000
|
|
|
51 |
* or three integer (0 to 255) representing red, green, blue, for example "rgb(255, 0, 0)"
|
|
|
52 |
* or a valid color name : red, blue ...
|
|
|
53 |
* @param color $color
|
|
|
54 |
*/
|
|
|
55 |
function setColor($color = '#000000') {
|
|
|
56 |
if (isColor($color)) {
|
|
|
57 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
58 |
$element->setAttribute('fo:color', $color);
|
|
|
59 |
$this->styleElement->appendChild($element);
|
|
|
60 |
} else {
|
|
|
61 |
throw new StyleException('Color value '.$color.' is not valid.');
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Outline the text, or not
|
|
|
67 |
*
|
|
|
68 |
* @param boolean $outline
|
|
|
69 |
*/
|
|
|
70 |
function setTextOutline($outline = true) {
|
|
|
71 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
72 |
$element->setAttribute('style:text-outline', ($outline) ? 'true':'false');
|
|
|
73 |
$this->styleElement->appendChild($element);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Draw a line through text.
|
|
|
78 |
* lineType can have one of these
|
|
|
79 |
* lineWidth can have these
|
|
|
80 |
* @param integer $lineType values: StyleConstants::NONE, StyleConstants::SINGLE, StyleConstants::DOUBLE
|
|
|
81 |
* @param integer $lineWidth Valid values are: StyleConstants::NORMAL, StyleConstants::BOLD
|
|
|
82 |
*/
|
|
|
83 |
function setLineThrough($lineType = StyleConstants::SINGLE, $lineWidth = StyleConstants::NORMAL) {
|
|
|
84 |
switch ($lineType) {
|
|
|
85 |
case StyleConstants::NONE:
|
|
|
86 |
$lineType = 'none';break;
|
|
|
87 |
case StyleConstants::SINGLE:
|
|
|
88 |
$lineType = 'single';break;
|
|
|
89 |
case StyleConstants::DOUBLE:
|
|
|
90 |
$lineType = 'double';break;
|
|
|
91 |
default:
|
|
|
92 |
throw new StyleException('LineType value is not valid.');
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
switch ($lineWidth) {
|
|
|
96 |
case StyleConstants::NORMAL:
|
|
|
97 |
$lineWidth = 'normal';break;
|
|
|
98 |
case StyleConstants::BOLD:
|
|
|
99 |
$lineWidth = 'bold';break;
|
|
|
100 |
default:
|
|
|
101 |
throw new StyleException('LineStyle value is not valid.');
|
|
|
102 |
}
|
|
|
103 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
104 |
$element->setAttribute('style:text-line-through-type', $lineType);
|
|
|
105 |
$element->setAttribute('style:text-line-through-width', $lineWidth);
|
|
|
106 |
|
|
|
107 |
$this->styleElement->appendChild($element);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Make the text bold
|
|
|
112 |
*/
|
|
|
113 |
function setBold() {
|
|
|
114 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
115 |
$element->setAttribute('fo:font-weight', 'bold');
|
|
|
116 |
$this->styleElement->appendChild($element);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Sets the text position according to the baseline
|
|
|
121 |
* @param integer $position
|
|
|
122 |
*/
|
|
|
123 |
function setTextPosition($position) {
|
|
|
124 |
switch ($position) {
|
|
|
125 |
case StyleConstants::SUPER:
|
|
|
126 |
$position = 'super';
|
|
|
127 |
break;
|
|
|
128 |
case StyleConstants::SUB:
|
|
|
129 |
$position = 'sub';
|
|
|
130 |
break;
|
|
|
131 |
default:
|
|
|
132 |
throw new StyleException('Text position value is not valid.');
|
|
|
133 |
}
|
|
|
134 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
135 |
$element->setAttribute('style:text-position', $position);
|
|
|
136 |
$this->styleElement->appendChild($element);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Specify the font name for the text
|
|
|
141 |
* @param <type> $fontName
|
|
|
142 |
*/
|
|
|
143 |
function setFontName($fontName) {
|
|
|
144 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
145 |
$element->setAttribute('style:font-name', $fontName);
|
|
|
146 |
$this->styleElement->appendChild($element);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
*
|
|
|
151 |
* @param numeric|percentage $fontSize The font size can be either a numeric value representing absolute length
|
|
|
152 |
* or a percentage
|
|
|
153 |
*/
|
|
|
154 |
function setFontSize($fontSize) {
|
|
|
155 |
if (isNumeric($fontSize) || isPercentage($fontSize)) {
|
|
|
156 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
157 |
$element->setAttribute('fo:font-size', $fontSize);
|
|
|
158 |
$this->styleElement->appendChild($element);
|
|
|
159 |
} else {
|
|
|
160 |
throw new StyleException($fontSize. ' is not a valid font-size value');
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
// /**
|
|
|
165 |
// * Valid values for $style are: StyleConstants::NORMAL, StyleConstants::ITALIC, StyleConstants::OBLIQUE
|
|
|
166 |
// * @param integer $style
|
|
|
167 |
// */
|
|
|
168 |
// function setFontStyle($fontStyle) {
|
|
|
169 |
// switch ($fontStyle) {
|
|
|
170 |
// case StyleConstants::NORMAL:
|
|
|
171 |
// $fontStyle = 'normal';break;
|
|
|
172 |
// case StyleConstants::ITALIC:
|
|
|
173 |
// $fontStyle = 'italic';break;
|
|
|
174 |
// case StyleConstants::OBLIQUE:
|
|
|
175 |
// $fontStyle = 'oblique';break;
|
|
|
176 |
// default:
|
|
|
177 |
// throw new StyleException('Invalid font-style value');
|
|
|
178 |
// }
|
|
|
179 |
// $element = $this->styleDocument->createElement('style:text-properties');
|
|
|
180 |
// $element->setAttribute('fo:font-style', $fontStyle);
|
|
|
181 |
// $this->styleElement->appendChild($element);
|
|
|
182 |
// }
|
|
|
183 |
|
|
|
184 |
function setItalic() {
|
|
|
185 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
186 |
$element->setAttribute('fo:font-style', 'italic');
|
|
|
187 |
$this->styleElement->appendChild($element);
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
*
|
|
|
192 |
* @param integer $fontRelief Valid values: StyleConstants::EMBOSSED, StyleConstants::ENGRAVED
|
|
|
193 |
*/
|
|
|
194 |
function setFontRelief($fontRelief) {
|
|
|
195 |
switch ($fontRelief) {
|
|
|
196 |
case StyleConstants::EMBOSSED:
|
|
|
197 |
$fontRelief = 'embossed';break;
|
|
|
198 |
case StyleConstants::ENGRAVED:
|
|
|
199 |
$fontRelief = 'engraved';break;
|
|
|
200 |
default:
|
|
|
201 |
throw new StyleException('Invalid font-relief value');
|
|
|
202 |
}
|
|
|
203 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
204 |
$element->setAttribute('style:font-relief', $fontRelief);
|
|
|
205 |
$this->styleElement->appendChild($element);
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
/**
|
|
|
209 |
*
|
|
|
210 |
* @param color $shadowColor The color of the shadow
|
|
|
211 |
* @param numeric $xCoord The x coordinate of the shadow, relative to the text
|
|
|
212 |
* @param numeric $yCoord The x coordinate of the shadow, relative to the text
|
|
|
213 |
* @param numeric $blurRadius The amount of blurriness of the shadow
|
|
|
214 |
*/
|
|
|
215 |
function setTextShadow($shadowColor = '#000000', $xCoord = 5, $yCoord = 5, $blurRadius = 0) {
|
|
|
216 |
if (isColor($shadowColor) && isNumeric($xCoord) && isNumeric($yCoord) && isNumeric($blurRadius)) {
|
|
|
217 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
218 |
$element->setAttribute('fo:text-shadow', "$shadowColor ${xCoord}px ${yCoord}px $blurRadius");
|
|
|
219 |
$this->styleElement->appendChild($element);
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
*
|
|
|
225 |
* @param integer $underlineType Valid values: StyleConstants::SINGLE, StyleConstants::DOUBLE
|
|
|
226 |
* @param integer $underlineStyle Valid values: StyleConstants::SOLID, StyleConstants::DOTTED, StyleConstants::DASH, StyleConstants::LONG_DASH, StyleConstants::DOT_DOT_DASH, StyleConstants::WAVE
|
|
|
227 |
* @param integer $underlineWidth Valid values: StyleConstants::AUTO, StyleConstants::NORMAL, StyleConstants::BOLD, StyleConstants::THIN, StyleConstants::DASH, StyleConstants::MEDIUM, StyleConstants::THICK
|
|
|
228 |
* @param color $underlineColor a valid color
|
|
|
229 |
*/
|
|
|
230 |
function setTextUnderline($underlineType = StyleConstants::SINGLE,
|
|
|
231 |
$underlineStyle = StyleConstants::SOLID,
|
|
|
232 |
$underlineWidth = StyleConstants::NORMAL,
|
|
|
233 |
$underlineColor = '#000000') {
|
|
|
234 |
switch($underlineType) {
|
|
|
235 |
case StyleConstants::SINGLE:
|
|
|
236 |
$underlineType = 'single';break;
|
|
|
237 |
case StyleConstants::DOUBLE:
|
|
|
238 |
$underlineType = 'double';break;
|
|
|
239 |
default:
|
|
|
240 |
throw new StyleException('Invalid underline-type value.');
|
|
|
241 |
}
|
|
|
242 |
switch($underlineStyle) {
|
|
|
243 |
case StyleConstants::NONE:
|
|
|
244 |
$underlineStyle = 'none';break;
|
|
|
245 |
case StyleConstants::SOLID:
|
|
|
246 |
$underlineStyle = 'solid';break;
|
|
|
247 |
case StyleConstants::DOTTED:
|
|
|
248 |
$underlineStyle = 'dotted';break;
|
|
|
249 |
case StyleConstants::DASH:
|
|
|
250 |
$underlineStyle = 'dash';break;
|
|
|
251 |
case StyleConstants::LONG_DASH:
|
|
|
252 |
$underlineStyle = 'long-dash';break;
|
|
|
253 |
case StyleConstants::DOT_DOT_DASH:
|
|
|
254 |
$underlineStyle = 'dot-dot-dash';break;
|
|
|
255 |
case StyleConstants::WAVE:
|
|
|
256 |
$underlineStyle = 'wave';break;
|
|
|
257 |
default:
|
|
|
258 |
throw new StyleException('Invalid underline-style value.');
|
|
|
259 |
}
|
|
|
260 |
switch($underlineWidth) {
|
|
|
261 |
case StyleConstants::AUTO:
|
|
|
262 |
$underlineWidth = 'single';break;
|
|
|
263 |
case StyleConstants::NORMAL:
|
|
|
264 |
$underlineWidth = 'normal';break;
|
|
|
265 |
case StyleConstants::BOLD:
|
|
|
266 |
$underlineWidth = 'bold';break;
|
|
|
267 |
case StyleConstants::THIN:
|
|
|
268 |
$underlineWidth = 'thin';break;
|
|
|
269 |
// case StyleConstants::DASH:
|
|
|
270 |
// $underlineWidth = 'dash';break;
|
|
|
271 |
case StyleConstants::MEDIUM:
|
|
|
272 |
$underlineWidth = 'medium';break;
|
|
|
273 |
case StyleConstants::THICK:
|
|
|
274 |
$underlineWidth = 'thick';break;
|
|
|
275 |
default:
|
|
|
276 |
// throw new StyleException('Invalid underline-type value.');
|
|
|
277 |
}
|
|
|
278 |
if (!isColor($underlineColor)) {
|
|
|
279 |
throw new StyleException('Invalid color value.');
|
|
|
280 |
}
|
|
|
281 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
282 |
$element->setAttribute('style:text-underline-type', $underlineType);
|
|
|
283 |
$element->setAttribute('style:text-underline-style', $underlineStyle);
|
|
|
284 |
$element->setAttribute('style:text-underline-width', $underlineWidth);
|
|
|
285 |
$element->setAttribute('style:text-underline-color', $underlineColor);
|
|
|
286 |
$this->styleElement->appendChild($element);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
/**
|
|
|
290 |
* Specify whether underline white spaces or not when underlining
|
|
|
291 |
* @param integer $mode Valid values are StyleConstants::CONTINUOUS, StyleConstants::SKIP_WHITE_SPACE
|
|
|
292 |
*/
|
|
|
293 |
function setUnderlineWordMode($mode) {
|
|
|
294 |
switch($mode) {
|
|
|
295 |
case StyleConstants::CONTINUOUS:
|
|
|
296 |
$mode = 'continuous';break;
|
|
|
297 |
case StyleConstants::SKIP_WHITE_SPACE:
|
|
|
298 |
$mode = 'skip-white-space';break;
|
|
|
299 |
}
|
|
|
300 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
301 |
$element->setAttribute('style:text-underline-mode', $mode);
|
|
|
302 |
$this->styleElement->appendChild($element);
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
/**
|
|
|
306 |
* Same as setUnderlineWordMode but for line-through
|
|
|
307 |
* @param integer $mode Valid values are StyleConstants::CONTINUOUS, StyleConstants::SKIP_WHITE_SPACE
|
|
|
308 |
*/
|
|
|
309 |
function setLineThroughWordMode($mode) {
|
|
|
310 |
switch($mode) {
|
|
|
311 |
case StyleConstants::CONTINUOUS:
|
|
|
312 |
$mode = 'continuous';break;
|
|
|
313 |
case StyleConstants::SKIP_WHITE_SPACE:
|
|
|
314 |
$mode = 'skip-white-space';break;
|
|
|
315 |
}
|
|
|
316 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
317 |
$element->setAttribute('style:text-line-through-mode', $mode);
|
|
|
318 |
$this->styleElement->appendChild($element);
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
// /**
|
|
|
322 |
// * Enable or disable kerning between characters
|
|
|
323 |
// * @param boolean $kerning
|
|
|
324 |
// */
|
|
|
325 |
// function setLetterKerning($kerning) {
|
|
|
326 |
// $element = $this->styleDocument->createElement('style:text-properties');
|
|
|
327 |
// $element->setAttribute('style:letter-kerning', $kerning);
|
|
|
328 |
// $this->styleElement->appendChild($element);
|
|
|
329 |
// }
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
* Specify whether or not text blinks
|
|
|
333 |
* @param boolean $blinking
|
|
|
334 |
*/
|
|
|
335 |
function setTextBlinking() {
|
|
|
336 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
337 |
$element->setAttribute('style:text-blinking', 'true');
|
|
|
338 |
$this->styleElement->appendChild($element);
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
/**
|
|
|
342 |
* Specify the background color to apply to characters.
|
|
|
343 |
* @param color $color Background color
|
|
|
344 |
*/
|
|
|
345 |
function setTextBackgroundColor($color) {
|
|
|
346 |
if ($color == 'transparent' || isColor($color)) {
|
|
|
347 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
348 |
$element->setAttribute('fo:background-color', $color);
|
|
|
349 |
$this->styleElement->appendChild($element);
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
/**
|
|
|
354 |
* Combine characters so that they are displayed within two lines.
|
|
|
355 |
* The value of $textCombine can be StyleConstants::LETTERS or StyleConstants::LINES.
|
|
|
356 |
* If the value is StyleConstants::LINES, all characters with this attribute value that immediately follow each other are
|
|
|
357 |
* displayed within two lines of approximately the same length. There can be a line break between
|
|
|
358 |
* any two characters to meet this constraint. The text will be surrounded by $startChar & $endChar
|
|
|
359 |
* If the value of the attribute is StyleConstants::LETTERS, up to 5 characters are combined within two lines. Any
|
|
|
360 |
* additional character is displayed as normal text.
|
|
|
361 |
* @param integer $textCombine
|
|
|
362 |
*/
|
|
|
363 |
function setTextCombine($textCombine, $startChar = '', $endChar = '') {
|
|
|
364 |
switch ($textCombine) {
|
|
|
365 |
case StyleConstants::LETTERS:
|
|
|
366 |
$textCombine = 'letters';break;
|
|
|
367 |
case StyleConstants::LINES:
|
|
|
368 |
$textCombine = 'lines';break;
|
|
|
369 |
default:
|
|
|
370 |
throw new StyleException('Invalid text-combine value.');
|
|
|
371 |
}
|
|
|
372 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
373 |
$element->setAttribute('style:text-combine', $textCombine);
|
|
|
374 |
if ($textCombine == 'lines') {
|
|
|
375 |
$element->setAttribute('style:text-combine-start-char', $startChar);
|
|
|
376 |
$element->setAttribute('style:text-combine-end-char', $endChar);
|
|
|
377 |
}
|
|
|
378 |
$this->styleElement->appendChild($element);
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
/**
|
|
|
382 |
* Specifies an angle to which text is rotated. The angle can be 0, 90 or 270.
|
|
|
383 |
*
|
|
|
384 |
* @param integer $angle Angle of rotation
|
|
|
385 |
*/
|
|
|
386 |
function setRotationAngle($angle) {
|
|
|
387 |
if ($angle != 0 && $angle != 90 && $angle != 270) {
|
|
|
388 |
throw new StyleException('Rotation Angle must be equal to 0, 90 or 270');
|
|
|
389 |
}
|
|
|
390 |
$element = $this->styleDocument->createElement('style:text-properties');
|
|
|
391 |
$element->setAttribute('style:text-rotation-angle', $angle);
|
|
|
392 |
$this->styleElement->appendChild($element);
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
}
|
|
|
396 |
?>
|