Completed
Pull Request — master (#350)
by Franck
13:06 queued 09:42
created

TextStyle::getOtherStyle()   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 1
Bugs 0 Features 0
Metric Value
c 1
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\Shape\RichText\Paragraph as RichTextParagraph;
21
22
/**
23
 * Class TextStyle
24
 */
25
class TextStyle
26
{
27
    /**
28
     * @var array
29
     */
30
    protected $bodyStyle = array();
31
    /**
32
     * @var array
33
     */
34
    protected $titleStyle = array();
35
    /**
36
     * @var array
37
     */
38
    protected $otherStyle = array();
39
40
    /**
41
     * TextStyle constructor.
42
     * @param bool $default
43
     */
44 219
    public function __construct($default = true)
45
    {
46 219
        if ($default) {
47 217
            $oColorLT1 = new SchemeColor();
48 217
            $oColorLT1->setValue('lt1');
49 217
            $oColorTX1 = new SchemeColor();
50 217
            $oColorTX1->setValue('tx1');
51
52 217
            $oRTParagraphBody = new RichTextParagraph();
53 217
            $oRTParagraphBody->getAlignment()
54 217
                ->setHorizontal(Alignment::HORIZONTAL_CENTER)
55 217
                ->setIndent(-324900 / 9525)
56 217
                ->setMarginLeft(342900 / 9525);
57 217
            $oRTParagraphBody->getFont()->setSize(32)->setColor($oColorTX1);
58 217
            $this->bodyStyle[1] = $oRTParagraphBody;
59
60 217
            $oRTParagraphOther = new RichTextParagraph();
61 217
            $oRTParagraphOther->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
62 217
            $oRTParagraphOther->getFont()->setSize(10)->setColor($oColorTX1);
63 217
            $this->otherStyle[0] = $oRTParagraphOther;
64
65 217
            $oRTParagraphTitle = new RichTextParagraph();
66 217
            $oRTParagraphTitle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
67 217
            $oRTParagraphTitle->getFont()->setSize(44)->setColor($oColorLT1);
68 217
            $this->titleStyle[1] = $oRTParagraphTitle;
69 217
        }
70 219
    }
71
72
    /**
73
     * @param $lvl
74
     * @return bool
75
     */
76 6
    private function checkLvl($lvl)
77
    {
78 6
        if (!is_int($lvl)) {
79 5
            return false;
80
        }
81 5
        if ($lvl > 9) {
82 1
            return false;
83
        }
84 5
        return true;
85
    }
86
87
    /**
88
     * @param RichTextParagraph $style
89
     * @param $lvl
90
     * @return TextStyle
91
     */
92 5
    public function setBodyStyleAtLvl(RichTextParagraph $style, $lvl)
93
    {
94 5
        if ($this->checkLvl($lvl)) {
95 1
            $this->bodyStyle[$lvl] = $style;
96 1
        }
97 5
        return $this;
98
    }
99
100
    /**
101
     * @param RichTextParagraph $style
102
     * @param $lvl
103
     * @return TextStyle
104
     */
105 5
    public function setTitleStyleAtLvl(RichTextParagraph $style, $lvl)
106
    {
107 5
        if ($this->checkLvl($lvl)) {
108 1
            $this->titleStyle[$lvl] = $style;
109 1
        }
110 5
        return $this;
111
    }
112
113
    /**
114
     * @param RichTextParagraph $style
115
     * @param $lvl
116
     * @return TextStyle
117
     */
118 5
    public function setOtherStyleAtLvl(RichTextParagraph $style, $lvl)
119
    {
120 5
        if ($this->checkLvl($lvl)) {
121 4
            $this->otherStyle[$lvl] = $style;
122 4
        }
123 5
        return $this;
124
    }
125
126
    /**
127
     * @param $lvl
128
     * @return mixed
129
     */
130 2
    public function getBodyStyleAtLvl($lvl)
131
    {
132 2
        if ($this->checkLvl($lvl) && !empty($this->bodyStyle[$lvl])) {
133 2
            return $this->bodyStyle[$lvl];
134
        }
135 2
        return null;
136
    }
137
138
    /**
139
     * @param $lvl
140
     * @return mixed
141
     */
142 2
    public function getTitleStyleAtLvl($lvl)
143
    {
144 2
        if ($this->checkLvl($lvl) && !empty($this->titleStyle[$lvl])) {
145 2
            return $this->titleStyle[$lvl];
146
        }
147 2
        return null;
148
    }
149
150
    /**
151
     * @param $lvl
152
     * @return mixed
153
     */
154 2
    public function getOtherStyleAtLvl($lvl)
155
    {
156 2
        if ($this->checkLvl($lvl) && !empty($this->otherStyle[$lvl])) {
157 2
            return $this->otherStyle[$lvl];
158
        }
159 2
        return null;
160
    }
161
162
    /**
163
     * @return array
164
     */
165 109
    public function getBodyStyle()
166
    {
167 109
        return $this->bodyStyle;
168
    }
169
170
    /**
171
     * @return array
172
     */
173 109
    public function getTitleStyle()
174
    {
175 109
        return $this->titleStyle;
176
    }
177
178
    /**
179
     * @return array
180
     */
181 109
    public function getOtherStyle()
182
    {
183 109
        return $this->otherStyle;
184
    }
185
}
186