Completed
Pull Request — develop (#301)
by Franck
23:29 queued 20:54
created

Font::isItalic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
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
     * Hash index
112
     *
113
     * @var string
114
     */
115
    private $hashIndex;
116
117
    /**
118
     * Create a new \PhpOffice\PhpPresentation\Style\Font
119
     */
120 357
    public function __construct()
121
    {
122
        // Initialise values
123 357
        $this->name             = 'Calibri';
124 357
        $this->size             = 10;
125 357
        $this->characterSpacing = 0;
0 ignored issues
show
Bug introduced by
The property characterSpacing does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

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