Completed
Pull Request — develop (#301)
by Franck
55:33 queued 34:55
created

Font::getCharacterSpacing()   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 1
Bugs 0 Features 0
Metric Value
c 1
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
     * 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
    }
134
135
    /**
136
     * Get Name
137
     *
138
     * @return string
139 87
     */
140
    public function getName()
141 87
    {
142
        return $this->name;
143
    }
144
145
    /**
146
     * Set Name
147
     *
148
     * @param  string                   $pValue
149
     * @return \PhpOffice\PhpPresentation\Style\Font
150 103
     */
151
    public function setName($pValue = 'Calibri')
152 103
    {
153 1
        if ($pValue == '') {
154 1
            $pValue = 'Calibri';
155 103
        }
156
        $this->name = $pValue;
157 103
158
        return $this;
159
    }
160
    
161
    /**
162
     * Get Character Spacing
163
     *
164
     * @return double
165 135
     */
166
    public function getCharacterSpacing()
167 135
    {
168
        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 253
     */
177
    public function setCharacterSpacing($pValue = 0)
178 253
    {
179 1
        if ($pValue == '') {
180 1
            $pValue = 0;
181 253
        }
182
        $this->characterSpacing = $pValue * 100;
183 253
    
184
        return $this;
185
    }
186
187
    /**
188
     * Get Size
189
     *
190
     * @return double
191 112
     */
192
    public function getSize()
193 112
    {
194
        return $this->size;
195
    }
196
197
    /**
198
     * Set Size
199
     *
200
     * @param float|int $pValue
201
     * @return \PhpOffice\PhpPresentation\Style\Font
202 10
     */
203
    public function setSize($pValue = 10)
204 10
    {
205 4
        if ($pValue == '') {
206 4
            $pValue = 10;
207 10
        }
208
        $this->size = $pValue;
209 10
210
        return $this;
211
    }
212
213
    /**
214
     * Get Bold
215
     *
216
     * @return boolean
217 121
     */
218
    public function isBold()
219 121
    {
220
        return $this->bold;
221
    }
222
223
    /**
224
     * Set Bold
225
     *
226
     * @param  boolean                  $pValue
227
     * @return \PhpOffice\PhpPresentation\Style\Font
228 9
     */
229
    public function setBold($pValue = false)
230 9
    {
231 7
        if ($pValue == '') {
232 7
            $pValue = false;
233 9
        }
234
        $this->bold = $pValue;
235 9
236
        return $this;
237
    }
238
239
    /**
240
     * Get Italic
241
     *
242
     * @return boolean
243 55
     */
244
    public function isItalic()
245 55
    {
246
        return $this->italic;
247
    }
248
249
    /**
250
     * Set Italic
251
     *
252
     * @param  boolean                  $pValue
253
     * @return \PhpOffice\PhpPresentation\Style\Font
254 6
     */
255
    public function setItalic($pValue = false)
256 6
    {
257 1
        if ($pValue == '') {
258 1
            $pValue = false;
259 6
        }
260 6
        $this->italic = $pValue;
261
262 6
        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 54
    public function isSubScript()
298
    {
299 54
        return $this->subScript;
300
    }
301
302
    /**
303
     * Set SubScript
304
     *
305
     * @param  boolean                  $pValue
306
     * @return \PhpOffice\PhpPresentation\Style\Font
307
     */
308 8
    public function setSubScript($pValue = false)
309
    {
310 8
        if ($pValue == '') {
311 4
            $pValue = false;
312 4
        }
313 8
        $this->subScript   = $pValue;
314
        $this->superScript = !$pValue;
315 8
316
        return $this;
317
    }
318
319
    /**
320
     * Get Underline
321
     *
322
     * @return string
323 54
     */
324
    public function getUnderline()
325 54
    {
326
        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 5
     */
335
    public function setUnderline($pValue = self::UNDERLINE_NONE)
336 5
    {
337 4
        if ($pValue == '') {
338 4
            $pValue = self::UNDERLINE_NONE;
339 5
        }
340
        $this->underline = $pValue;
341 5
342
        return $this;
343
    }
344
345
    /**
346
     * Get Strikethrough
347
     *
348
     * @return boolean
349 202
     */
350
    public function isStrikethrough()
351 202
    {
352
        return $this->strikethrough;
353
    }
354
355
    /**
356
     * Set Strikethrough
357
     *
358
     * @param  boolean                  $pValue
359
     * @return \PhpOffice\PhpPresentation\Style\Font
360
     */
361 202
    public function setStrikethrough($pValue = false)
362
    {
363 202
        if ($pValue == '') {
364 1
            $pValue = false;
365
        }
366 201
        $this->strikethrough = $pValue;
367
368 201
        return $this;
369
    }
370
371
    /**
372
     * Get Color
373
     *
374
     * @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor
375
     */
376 75
    public function getColor()
377
    {
378 75
        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
    public function setColor($pValue = null)
389 1
    {
390
        if (!$pValue instanceof Color) {
391 1
            throw new \Exception('$pValue must be an instance of \PhpOffice\PhpPresentation\Style\Color');
392
        }
393
        $this->color = $pValue;
394
395
        return $this;
396
    }
397
398
    /**
399
     * Get hash code
400
     *
401
     * @return string Hash code
402 1
     */
403
    public function getHashCode()
404 1
    {
405 1
        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 1
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
    public function getHashIndex()
417
    {
418
        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
    public function setHashIndex($value)
430
    {
431
        $this->hashIndex = $value;
432
    }
433
}
434