Completed
Pull Request — develop (#523)
by Franck
08:40 queued 03:02
created

Paragraph::setLineSpacing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Shape\RichText;
19
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
use PhpOffice\PhpPresentation\Style\Alignment;
22
use PhpOffice\PhpPresentation\Style\Bullet;
23
use PhpOffice\PhpPresentation\Style\Font;
24
25
/**
26
 * \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
27
 */
28
class Paragraph implements ComparableInterface
29
{
30
    /**
31
     * Rich text elements
32
     *
33
     * @var \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[]
34
     */
35
    private $richTextElements;
36
37
    /**
38
     * Alignment
39
     *
40
     * @var \PhpOffice\PhpPresentation\Style\Alignment
41
     */
42
    private $alignment;
43
44
    /**
45
     * Font
46
     *
47
     * @var \PhpOffice\PhpPresentation\Style\Font
48
     */
49
    private $font;
50
51
    /**
52
     * Bullet style
53
     *
54
     * @var \PhpOffice\PhpPresentation\Style\Bullet
55
     */
56
    private $bulletStyle;
57
58
    /**
59
     * @var integer
60
     */
61
    private $lineSpacing = 1;
62
	
63
	private $dqSpacing=0;
64
65
    /**
66
     * Hash index
67
     *
68
     * @var string
69
     */
70
    private $hashIndex;
71
72
    /**
73
     * Create a new \PhpOffice\PhpPresentation\Shape\RichText\Paragraph instance
74
     */
75 300
    public function __construct()
76
    {
77
        // Initialise variables
78 300
        $this->richTextElements = array();
79 300
        $this->alignment = new Alignment();
80 300
        $this->font = new Font();
81 300
        $this->bulletStyle = new Bullet();
82 300
    }
83
84
    /**
85
     * Get alignment
86
     *
87
     * @return \PhpOffice\PhpPresentation\Style\Alignment
88
     */
89 235
    public function getAlignment()
90
    {
91 235
        return $this->alignment;
92
    }
93
94
    /**
95
     * Set alignment
96
     *
97
     * @param  \PhpOffice\PhpPresentation\Style\Alignment $alignment
98
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
99
     */
100 13
    public function setAlignment(Alignment $alignment)
101
    {
102 13
        $this->alignment = $alignment;
103
104 13
        return $this;
105
    }
106
107
    /**
108
     * Get font
109
     *
110
     * @return \PhpOffice\PhpPresentation\Style\Font
111
     */
112 236
    public function getFont()
113
    {
114 236
        return $this->font;
115
    }
116
117
    /**
118
     * Set font
119
     *
120
     * @param  \PhpOffice\PhpPresentation\Style\Font $pFont Font
121
     * @throws \Exception
122
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
123
     */
124 13
    public function setFont(Font $pFont = null)
125
    {
126 13
        $this->font = $pFont;
127
128 13
        return $this;
129
    }
130
131
    /**
132
     * Get bullet style
133
     *
134
     * @return \PhpOffice\PhpPresentation\Style\Bullet
135
     */
136 60
    public function getBulletStyle()
137
    {
138 60
        return $this->bulletStyle;
139
    }
140
141
    /**
142
     * Set bullet style
143
     *
144
     * @param  \PhpOffice\PhpPresentation\Style\Bullet $style
145
     * @throws \Exception
146
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
147
     */
148 13
    public function setBulletStyle(Bullet $style = null)
149
    {
150 13
        $this->bulletStyle = $style;
151
152 13
        return $this;
153
    }
154
155
    /**
156
     * Create text (can not be formatted !)
157
     *
158
     * @param  string $pText Text
159
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElement
160
     * @throws \Exception
161
     */
162 4
    public function createText($pText = '')
163
    {
164 4
        $objText = new TextElement($pText);
165 4
        $this->addText($objText);
166
167 4
        return $objText;
168
    }
169
170
    /**
171
     * Add text
172
     *
173
     * @param  \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface $pText Rich text element
174
     * @throws \Exception
175
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
176
     */
177 56
    public function addText(TextElementInterface $pText = null)
178
    {
179 56
        $this->richTextElements[] = $pText;
180
181 56
        return $this;
182
    }
183
184
    /**
185
     * Create break
186
     *
187
     * @return \PhpOffice\PhpPresentation\Shape\RichText\BreakElement
188
     * @throws \Exception
189
     */
190 12
    public function createBreak()
191
    {
192 12
        $objText = new BreakElement();
193 12
        $this->addText($objText);
194
195 12
        return $objText;
196
    }
197
198
    /**
199
     * Create text run (can be formatted)
200
     *
201
     * @param  string $pText Text
202
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Run
203
     * @throws \Exception
204
     */
205 52
    public function createTextRun($pText = '')
206
    {
207 52
        $objText = new Run($pText);
208 52
        $objText->setFont(clone $this->font);
209 52
        $this->addText($objText);
210
211 52
        return $objText;
212
    }
213
214
    /**
215
     * Convert to string
216
     *
217
     * @return string
218
     */
219 1
    public function __toString()
220
    {
221 1
        return $this->getPlainText();
222
    }
223
224
    /**
225
     * Get plain text
226
     *
227
     * @return string
228
     */
229 3
    public function getPlainText()
230
    {
231
        // Return value
232 3
        $returnValue = '';
233
234
        // Loop trough all \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
235 3
        foreach ($this->richTextElements as $text) {
236 3
            if ($text instanceof TextElementInterface) {
237 3
                $returnValue .= $text->getText();
238
            }
239
        }
240
241
        // Return
242 3
        return $returnValue;
243
    }
244
245
    /**
246
     * Get Rich Text elements
247
     *
248
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[]
249
     */
250 64
    public function getRichTextElements()
251
    {
252 64
        return $this->richTextElements;
253
    }
254
255
    /**
256
     * Set Rich Text elements
257
     *
258
     * @param  \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] $pElements Array of elements
259
     * @throws \Exception
260
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
261
     */
262 6
    public function setRichTextElements($pElements = null)
263
    {
264 6
        if (!is_array($pElements)) {
265 1
            throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] array passed.");
266
        }
267 5
        $this->richTextElements = $pElements;
268 5
        return $this;
269
    }
270
271
    /**
272
     * Get hash code
273
     *
274
     * @return string Hash code
275
     */
276 20
    public function getHashCode()
277
    {
278 20
        $hashElements = '';
279 20
        foreach ($this->richTextElements as $element) {
280 10
            $hashElements .= $element->getHashCode();
281
        }
282
283 20
        return md5($hashElements . $this->font->getHashCode() . __CLASS__);
284
    }
285
286
    /**
287
     * Get hash index
288
     *
289
     * Note that this index may vary during script execution! Only reliable moment is
290
     * while doing a write of a workbook and when changes are not allowed.
291
     *
292
     * @return string Hash index
293
     */
294 1
    public function getHashIndex()
295
    {
296 1
        return $this->hashIndex;
297
    }
298
299
    /**
300
     * Set hash index
301
     *
302
     * Note that this index may vary during script execution! Only reliable moment is
303
     * while doing a write of a workbook and when changes are not allowed.
304
     *
305
     * @param string $value Hash index
306
     */
307 1
    public function setHashIndex($value)
308
    {
309 1
        $this->hashIndex = $value;
310 1
    }
311
312
    /**
313
     * @return int
314
     */
315 36
    public function getLineSpacing()
316
    {
317 36
        return $this->lineSpacing;
318
    }
319
320
    /**
321
     * @param int $lineSpacing
322
     * @return Paragraph
323
     */
324 1
    public function setLineSpacing($lineSpacing)
325
    {
326 1
        $this->lineSpacing = $lineSpacing;
327 1
        return $this;
328
    }
329
	
330
	/**
331
     * @return int
332
     */
333 35
    public function getDqSpacing()
334
    {
335 35
        return $this->dqSpacing;
336
    }
337
338
    /**
339
     * @param int $lineSpacing
340
     * @return Paragraph
341
     */
342
    public function setDqSpacing($lineSpacing)
343
    {
344
        $this->dqSpacing = $lineSpacing;
345
        return $this;
346
    }
347
}
348