Completed
Pull Request — develop (#629)
by
unknown
07:50
created

Font::setFormat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\ComparableInterface;
21
22
/**
23
 * \PhpOffice\PhpPresentation\Style\Font
24
 */
25
class Font implements ComparableInterface
26
{
27
    /* Underline types */
28
    const UNDERLINE_NONE = 'none';
29
    const UNDERLINE_DASH = 'dash';
30
    const UNDERLINE_DASHHEAVY = 'dashHeavy';
31
    const UNDERLINE_DASHLONG = 'dashLong';
32
    const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
33
    const UNDERLINE_DOUBLE = 'dbl';
34
    const UNDERLINE_DOTHASH = 'dotDash';
35
    const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
36
    const UNDERLINE_DOTDOTDASH = 'dotDotDash';
37
    const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
38
    const UNDERLINE_DOTTED = 'dotted';
39
    const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
40
    const UNDERLINE_HEAVY = 'heavy';
41
    const UNDERLINE_SINGLE = 'sng';
42
    const UNDERLINE_WAVY = 'wavy';
43
    const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
44
    const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
45
    const UNDERLINE_WORDS = 'words';
46
47
    const FONT_FORMAT_LATIN = 'latin';
48
    const FONT_FORMAT_EAST_ASIAN = 'ea';
49
    const FONT_FORMAT_COMPLEX_SCRIPT = 'cs';
50
51
    /**
52
     * Name
53
     *
54
     * @var string
55
     */
56
    private $name;
57
58
	/**
59
	 * Format
60
	 *
61
	 * @var string
62
	 */
63
	private $format;
64
    
65
    /**
66
     * Font Size
67
     *
68
     * @var float|int
69
     */
70
    private $size;
71
    
72
    /**
73
     * Bold
74
     *
75
     * @var boolean
76
     */
77
    private $bold;
78
79
    /**
80
     * Italic
81
     *
82
     * @var boolean
83
     */
84
    private $italic;
85
86
    /**
87
     * Superscript
88
     *
89
     * @var boolean
90
     */
91
    private $superScript;
92
93
    /**
94
     * Subscript
95
     *
96
     * @var boolean
97
     */
98
    private $subScript;
99
100
    /**
101
     * Underline
102
     *
103
     * @var string
104
     */
105
    private $underline;
106
107
    /**
108
     * Strikethrough
109
     *
110
     * @var boolean
111
     */
112
    private $strikethrough;
113
114
    /**
115
     * Foreground color
116
     *
117
     * @var \PhpOffice\PhpPresentation\Style\Color
118
     */
119
    private $color;
120
121
    /**
122
     * Character Spacing
123
     *
124
     * @var int
125
     */
126
    private $characterSpacing;
127
128
    /**
129
     * Hash index
130
     *
131
     * @var string
132
     */
133
    private $hashIndex;
134
135
    /**
136
     * Create a new \PhpOffice\PhpPresentation\Style\Font
137
     */
138 408
    public function __construct()
139
    {
140
        // Initialise values
141 408
        $this->name             = 'Calibri';
142 408
        $this->format             = self::FONT_FORMAT_LATIN;
143 408
        $this->size             = 10;
144 408
        $this->characterSpacing = 0;
145 408
        $this->bold             = false;
146 408
        $this->italic           = false;
147 408
        $this->superScript      = false;
148 408
        $this->subScript        = false;
149 408
        $this->underline        = self::UNDERLINE_NONE;
150 408
        $this->strikethrough    = false;
151 408
        $this->color            = new Color(Color::COLOR_BLACK);
152 408
    }
153
154
    /**
155
     * Get Name
156
     *
157
     * @return string
158
     */
159 102
    public function getName()
160
    {
161 102
        return $this->name;
162
    }
163
164
    /**
165
     * Set Name
166
     *
167
     * @param  string                   $pValue
168
     * @return \PhpOffice\PhpPresentation\Style\Font
169
     */
170 125
    public function setName($pValue = 'Calibri')
171
    {
172 125
        if ($pValue == '') {
173 1
            $pValue = 'Calibri';
174
        }
175 125
        $this->name = $pValue;
176
177 125
        return $this;
178
    }
179
180
181
	/**
182
	 * Get Font Format
183
	 *
184
	 * @return string
185
	 */
186 29
	public function getFormat()
187
	{
188 29
		return $this->format;
189
	}
190
191
	/**
192
	 * Set Font Format
193
	 *
194
	 * @param  string                   $pValue
195
	 * @return \PhpOffice\PhpPresentation\Style\Font
196
	 */
197
	public function setFormat($pValue = self::FONT_FORMAT_LATIN)
198
	{
199
		if ($pValue == '') {
200
			$pValue = self::FONT_FORMAT_LATIN;
201
		}
202
		$this->format = $pValue;
203
204
		return $this;
205
	}
206
    
207
    /**
208
     * Get Character Spacing
209
     *
210
     * @return double
211
     */
212 31
    public function getCharacterSpacing()
213
    {
214 31
        return $this->characterSpacing;
215
    }
216
    
217
    /**
218
     * Set Character Spacing
219
     * Value in pt
220
     * @param float|int $pValue
221
     * @return \PhpOffice\PhpPresentation\Style\Font
222
     */
223 2
    public function setCharacterSpacing($pValue = 0)
224
    {
225 2
        if ($pValue == '') {
226 1
            $pValue = 0;
227
        }
228 2
        $this->characterSpacing = $pValue * 100;
229
    
230 2
        return $this;
231
    }
232
233
    /**
234
     * Get Size
235
     *
236
     * @return double
237
     */
238 154
    public function getSize()
239
    {
240 154
        return $this->size;
241
    }
242
243
    /**
244
     * Set Size
245
     *
246
     * @param float|int $pValue
247
     * @return \PhpOffice\PhpPresentation\Style\Font
248
     */
249 292
    public function setSize($pValue = 10)
250
    {
251 292
        if ($pValue == '') {
252 1
            $pValue = 10;
253
        }
254 292
        $this->size = $pValue;
255
256 292
        return $this;
257
    }
258
259
    /**
260
     * Get Bold
261
     *
262
     * @return boolean
263
     */
264 127
    public function isBold()
265
    {
266 127
        return $this->bold;
267
    }
268
269
    /**
270
     * Set Bold
271
     *
272
     * @param  boolean                  $pValue
273
     * @return \PhpOffice\PhpPresentation\Style\Font
274
     */
275 10
    public function setBold($pValue = false)
276
    {
277 10
        if ($pValue == '') {
278 4
            $pValue = false;
279
        }
280 10
        $this->bold = $pValue;
281
282 10
        return $this;
283
    }
284
285
    /**
286
     * Get Italic
287
     *
288
     * @return boolean
289
     */
290 139
    public function isItalic()
291
    {
292 139
        return $this->italic;
293
    }
294
295
    /**
296
     * Set Italic
297
     *
298
     * @param  boolean                  $pValue
299
     * @return \PhpOffice\PhpPresentation\Style\Font
300
     */
301 9
    public function setItalic($pValue = false)
302
    {
303 9
        if ($pValue == '') {
304 7
            $pValue = false;
305
        }
306 9
        $this->italic = $pValue;
307
308 9
        return $this;
309
    }
310
311
    /**
312
     * Get SuperScript
313
     *
314
     * @return boolean
315
     */
316 66
    public function isSuperScript()
317
    {
318 66
        return $this->superScript;
319
    }
320
321
    /**
322
     * Set SuperScript
323
     *
324
     * @param  boolean                  $pValue
325
     * @return \PhpOffice\PhpPresentation\Style\Font
326
     */
327 7
    public function setSuperScript($pValue = false)
328
    {
329 7
        if ($pValue == '') {
330 2
            $pValue = false;
331
        }
332
333 7
        $this->superScript = $pValue;
334
335
        // Set SubScript at false only if SuperScript is true
336 7
        if ($pValue === true) {
337 7
            $this->subScript = false;
338
        }
339
340 7
        return $this;
341
    }
342
343
    /**
344
     * Get SubScript
345
     *
346
     * @return boolean
347
     */
348 66
    public function isSubScript()
349
    {
350 66
        return $this->subScript;
351
    }
352
353
    /**
354
     * Set SubScript
355
     *
356
     * @param  boolean                  $pValue
357
     * @return \PhpOffice\PhpPresentation\Style\Font
358
     */
359 7
    public function setSubScript($pValue = false)
360
    {
361 7
        if ($pValue == '') {
362 2
            $pValue = false;
363
        }
364
365 7
        $this->subScript = $pValue;
366
367
        // Set SuperScript at false only if SubScript is true
368 7
        if ($pValue === true) {
369 7
            $this->superScript = false;
370
        }
371
372 7
        return $this;
373
    }
374
375
    /**
376
     * Get Underline
377
     *
378
     * @return string
379
     */
380 66
    public function getUnderline()
381
    {
382 66
        return $this->underline;
383
    }
384
385
    /**
386
     * Set Underline
387
     *
388
     * @param  string                   $pValue \PhpOffice\PhpPresentation\Style\Font underline type
389
     * @return \PhpOffice\PhpPresentation\Style\Font
390
     */
391 8
    public function setUnderline($pValue = self::UNDERLINE_NONE)
392
    {
393 8
        if ($pValue == '') {
394 4
            $pValue = self::UNDERLINE_NONE;
395
        }
396 8
        $this->underline = $pValue;
397
398 8
        return $this;
399
    }
400
401
    /**
402
     * Get Strikethrough
403
     *
404
     * @return boolean
405
     */
406 66
    public function isStrikethrough()
407
    {
408 66
        return $this->strikethrough;
409
    }
410
411
    /**
412
     * Set Strikethrough
413
     *
414
     * @param  boolean                  $pValue
415
     * @return \PhpOffice\PhpPresentation\Style\Font
416
     */
417 5
    public function setStrikethrough($pValue = false)
418
    {
419 5
        if ($pValue == '') {
420 4
            $pValue = false;
421
        }
422 5
        $this->strikethrough = $pValue;
423
424 5
        return $this;
425
    }
426
427
    /**
428
     * Get Color
429
     *
430
     * @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor
431
     */
432 152
    public function getColor()
433
    {
434 152
        return $this->color;
435
    }
436
437
    /**
438
     * Set Color
439
     *
440
     * @param  \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor $pValue
441
     * @throws \Exception
442
     * @return \PhpOffice\PhpPresentation\Style\Font
443
     */
444 233
    public function setColor($pValue = null)
445
    {
446 233
        if (!$pValue instanceof Color) {
447 1
            throw new \Exception('$pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color');
448
        }
449 232
        $this->color = $pValue;
450
451 232
        return $this;
452
    }
453
454
    /**
455
     * Get hash code
456
     *
457
     * @return string Hash code
458
     */
459 90
    public function getHashCode()
460
    {
461 90
        return md5($this->name . $this->format . $this->size . ($this->bold ? 't' : 'f') . ($this->italic ? 't' : 'f') . ($this->superScript ? 't' : 'f') . ($this->subScript ? 't' : 'f') . $this->underline . ($this->strikethrough ? 't' : 'f') . $this->color->getHashCode() . __CLASS__);
462
    }
463
464
    /**
465
     * Get hash index
466
     *
467
     * Note that this index may vary during script execution! Only reliable moment is
468
     * while doing a write of a workbook and when changes are not allowed.
469
     *
470
     * @return string Hash index
471
     */
472 1
    public function getHashIndex()
473
    {
474 1
        return $this->hashIndex;
475
    }
476
477
    /**
478
     * Set hash index
479
     *
480
     * Note that this index may vary during script execution! Only reliable moment is
481
     * while doing a write of a workbook and when changes are not allowed.
482
     *
483
     * @param string $value Hash index
484
     */
485 1
    public function setHashIndex($value)
486
    {
487 1
        $this->hashIndex = $value;
488 1
    }
489
}
490