Completed
Pull Request — develop (#301)
by Franck
79:04 queued 76:21
created

Font::getSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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