Completed
Pull Request — develop (#230)
by Franck
09:23
created

Font   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 382
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 36
lcom 1
cbo 1
dl 0
loc 382
ccs 91
cts 91
cp 1
rs 8.8
c 1
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getName() 0 4 1
A setName() 0 9 2
A getSize() 0 4 1
A setSize() 0 9 2
A isBold() 0 4 1
A setBold() 0 9 2
A isItalic() 0 4 1
A setItalic() 0 9 2
A isSuperScript() 0 4 1
A setSuperScript() 0 10 2
A isSubScript() 0 4 1
A setSubScript() 0 10 2
A getUnderline() 0 4 1
A setUnderline() 0 9 2
A isStrikethrough() 0 4 1
A setStrikethrough() 0 9 2
A getColor() 0 4 1
A setColor() 0 9 2
B getHashCode() 0 4 6
A getHashIndex() 0 4 1
A setHashIndex() 0 4 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
     * Hash index
112
     *
113
     * @var string
114
     */
115
    private $hashIndex;
116
117
    /**
118
     * Create a new \PhpOffice\PhpPresentation\Style\Font
119
     */
120 347
    public function __construct()
121
    {
122
        // Initialise values
123 347
        $this->name          = 'Calibri';
124 347
        $this->size          = 10;
125 347
        $this->bold          = false;
126 347
        $this->italic        = false;
127 347
        $this->superScript   = false;
128 347
        $this->subScript     = false;
129 347
        $this->underline     = self::UNDERLINE_NONE;
130 347
        $this->strikethrough = false;
131 347
        $this->color         = new Color(Color::COLOR_BLACK);
132 347
    }
133
134
    /**
135
     * Get Name
136
     *
137
     * @return string
138
     */
139 86
    public function getName()
140
    {
141 86
        return $this->name;
142
    }
143
144
    /**
145
     * Set Name
146
     *
147
     * @param  string                   $pValue
148
     * @return \PhpOffice\PhpPresentation\Style\Font
149
     */
150 103
    public function setName($pValue = 'Calibri')
151
    {
152 103
        if ($pValue == '') {
153 1
            $pValue = 'Calibri';
154 1
        }
155 103
        $this->name = $pValue;
156
157 103
        return $this;
158
    }
159
160
    /**
161
     * Get Size
162
     *
163
     * @return double
164
     */
165 133
    public function getSize()
166
    {
167 133
        return $this->size;
168
    }
169
170
    /**
171
     * Set Size
172
     *
173
     * @param float|int $pValue
174
     * @return \PhpOffice\PhpPresentation\Style\Font
175
     */
176 244
    public function setSize($pValue = 10)
177
    {
178 244
        if ($pValue == '') {
179 1
            $pValue = 10;
180 1
        }
181 244
        $this->size = $pValue;
182
183 244
        return $this;
184
    }
185
186
    /**
187
     * Get Bold
188
     *
189
     * @return boolean
190
     */
191 110
    public function isBold()
192
    {
193 110
        return $this->bold;
194
    }
195
196
    /**
197
     * Set Bold
198
     *
199
     * @param  boolean                  $pValue
200
     * @return \PhpOffice\PhpPresentation\Style\Font
201
     */
202 9
    public function setBold($pValue = false)
203
    {
204 9
        if ($pValue == '') {
205 4
            $pValue = false;
206 4
        }
207 9
        $this->bold = $pValue;
208
209 9
        return $this;
210
    }
211
212
    /**
213
     * Get Italic
214
     *
215
     * @return boolean
216
     */
217 119
    public function isItalic()
218
    {
219 119
        return $this->italic;
220
    }
221
222
    /**
223
     * Set Italic
224
     *
225
     * @param  boolean                  $pValue
226
     * @return \PhpOffice\PhpPresentation\Style\Font
227
     */
228 9
    public function setItalic($pValue = false)
229
    {
230 9
        if ($pValue == '') {
231 7
            $pValue = false;
232 7
        }
233 9
        $this->italic = $pValue;
234
235 9
        return $this;
236
    }
237
238
    /**
239
     * Get SuperScript
240
     *
241
     * @return boolean
242
     */
243 54
    public function isSuperScript()
244
    {
245 54
        return $this->superScript;
246
    }
247
248
    /**
249
     * Set SuperScript
250
     *
251
     * @param  boolean                  $pValue
252
     * @return \PhpOffice\PhpPresentation\Style\Font
253
     */
254 6
    public function setSuperScript($pValue = false)
255
    {
256 6
        if ($pValue == '') {
257 1
            $pValue = false;
258 1
        }
259 6
        $this->superScript = $pValue;
260 6
        $this->subScript   = !$pValue;
261
262 6
        return $this;
263
    }
264
265
    /**
266
     * Get SubScript
267
     *
268
     * @return boolean
269
     */
270 54
    public function isSubScript()
271
    {
272 54
        return $this->subScript;
273
    }
274
275
    /**
276
     * Set SubScript
277
     *
278
     * @param  boolean                  $pValue
279
     * @return \PhpOffice\PhpPresentation\Style\Font
280
     */
281 6
    public function setSubScript($pValue = false)
282
    {
283 6
        if ($pValue == '') {
284 1
            $pValue = false;
285 1
        }
286 6
        $this->subScript   = $pValue;
287 6
        $this->superScript = !$pValue;
288
289 6
        return $this;
290
    }
291
292
    /**
293
     * Get Underline
294
     *
295
     * @return string
296
     */
297 53
    public function getUnderline()
298
    {
299 53
        return $this->underline;
300
    }
301
302
    /**
303
     * Set Underline
304
     *
305
     * @param  string                   $pValue \PhpOffice\PhpPresentation\Style\Font underline type
306
     * @return \PhpOffice\PhpPresentation\Style\Font
307
     */
308 8
    public function setUnderline($pValue = self::UNDERLINE_NONE)
309
    {
310 8
        if ($pValue == '') {
311 4
            $pValue = self::UNDERLINE_NONE;
312 4
        }
313 8
        $this->underline = $pValue;
314
315 8
        return $this;
316
    }
317
318
    /**
319
     * Get Strikethrough
320
     *
321
     * @return boolean
322
     */
323 53
    public function isStrikethrough()
324
    {
325 53
        return $this->strikethrough;
326
    }
327
328
    /**
329
     * Set Strikethrough
330
     *
331
     * @param  boolean                  $pValue
332
     * @return \PhpOffice\PhpPresentation\Style\Font
333
     */
334 5
    public function setStrikethrough($pValue = false)
335
    {
336 5
        if ($pValue == '') {
337 4
            $pValue = false;
338 4
        }
339 5
        $this->strikethrough = $pValue;
340
341 5
        return $this;
342
    }
343
344
    /**
345
     * Get Color
346
     *
347
     * @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor
348
     */
349 193
    public function getColor()
350
    {
351 193
        return $this->color;
352
    }
353
354
    /**
355
     * Set Color
356
     *
357
     * @param  \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor $pValue
358
     * @throws \Exception
359
     * @return \PhpOffice\PhpPresentation\Style\Font
360
     */
361 193
    public function setColor($pValue = null)
362
    {
363 193
        if (!$pValue instanceof Color) {
364 1
            throw new \Exception('$pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color');
365
        }
366 192
        $this->color = $pValue;
367
368 192
        return $this;
369
    }
370
371
    /**
372
     * Get hash code
373
     *
374
     * @return string Hash code
375
     */
376 75
    public function getHashCode()
377
    {
378 75
        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__);
379
    }
380
381
    /**
382
     * Get hash index
383
     *
384
     * Note that this index may vary during script execution! Only reliable moment is
385
     * while doing a write of a workbook and when changes are not allowed.
386
     *
387
     * @return string Hash index
388
     */
389 1
    public function getHashIndex()
390
    {
391 1
        return $this->hashIndex;
392
    }
393
394
    /**
395
     * Set hash index
396
     *
397
     * Note that this index may vary during script execution! Only reliable moment is
398
     * while doing a write of a workbook and when changes are not allowed.
399
     *
400
     * @param string $value Hash index
401
     */
402 1
    public function setHashIndex($value)
403
    {
404 1
        $this->hashIndex = $value;
405 1
    }
406
}
407