Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
36 / 36 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
AbstractGraphic | |
100.00% |
36 / 36 |
|
100.00% |
11 / 11 |
21 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
__clone | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getImageIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDescription | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setWidth | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
setHeight | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
setWidthAndHeight | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
isResizeProportional | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setResizeProportional | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHashCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
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 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation\Shape; |
21 | |
22 | use PhpOffice\PhpPresentation\AbstractShape; |
23 | use PhpOffice\PhpPresentation\ComparableInterface; |
24 | |
25 | /** |
26 | * Abstract drawing. |
27 | */ |
28 | abstract class AbstractGraphic extends AbstractShape implements ComparableInterface |
29 | { |
30 | /** |
31 | * Image counter. |
32 | * |
33 | * @var int |
34 | */ |
35 | private static $imageCounter = 0; |
36 | |
37 | /** |
38 | * Image index. |
39 | * |
40 | * @var int |
41 | */ |
42 | private $imageIndex = 0; |
43 | |
44 | /** |
45 | * Description. |
46 | * |
47 | * @var string |
48 | */ |
49 | protected $description; |
50 | |
51 | /** |
52 | * Proportional resize. |
53 | * |
54 | * @var bool |
55 | */ |
56 | protected $resizeProportional; |
57 | |
58 | /** |
59 | * Slide relation ID (should not be used by user code!). |
60 | * |
61 | * @var string |
62 | */ |
63 | public $relationId; |
64 | |
65 | /** |
66 | * Create a new \PhpOffice\PhpPresentation\Slide\AbstractDrawing. |
67 | */ |
68 | public function __construct() |
69 | { |
70 | // Initialise values |
71 | $this->name = ''; |
72 | $this->description = ''; |
73 | $this->resizeProportional = true; |
74 | |
75 | // Set image index |
76 | ++self::$imageCounter; |
77 | $this->imageIndex = self::$imageCounter; |
78 | |
79 | // Initialize parent |
80 | parent::__construct(); |
81 | } |
82 | |
83 | public function __clone() |
84 | { |
85 | parent::__clone(); |
86 | |
87 | ++self::$imageCounter; |
88 | $this->imageIndex = self::$imageCounter; |
89 | } |
90 | |
91 | /** |
92 | * Get image index. |
93 | * |
94 | * @return int |
95 | */ |
96 | public function getImageIndex() |
97 | { |
98 | return $this->imageIndex; |
99 | } |
100 | |
101 | /** |
102 | * Get Description. |
103 | * |
104 | * @return string |
105 | */ |
106 | public function getDescription() |
107 | { |
108 | return $this->description; |
109 | } |
110 | |
111 | /** |
112 | * Set Description. |
113 | * |
114 | * @param string $pValue |
115 | * |
116 | * @return $this |
117 | */ |
118 | public function setDescription($pValue = '') |
119 | { |
120 | $this->description = $pValue; |
121 | |
122 | return $this; |
123 | } |
124 | |
125 | /** |
126 | * Set Width. |
127 | * |
128 | * @return self |
129 | */ |
130 | public function setWidth(int $pValue = 0) |
131 | { |
132 | // Resize proportional? |
133 | if ($this->resizeProportional && 0 != $pValue && 0 != $this->width) { |
134 | $ratio = $this->height / $this->width; |
135 | $this->height = (int) round($ratio * $pValue); |
136 | } |
137 | |
138 | // Set width |
139 | $this->width = $pValue; |
140 | |
141 | return $this; |
142 | } |
143 | |
144 | /** |
145 | * Set Height. |
146 | * |
147 | * @return self |
148 | */ |
149 | public function setHeight(int $pValue = 0) |
150 | { |
151 | // Resize proportional? |
152 | if ($this->resizeProportional && 0 != $pValue && 0 != $this->height) { |
153 | $ratio = $this->width / $this->height; |
154 | $this->width = (int) round($ratio * $pValue); |
155 | } |
156 | |
157 | // Set height |
158 | $this->height = $pValue; |
159 | |
160 | return $this; |
161 | } |
162 | |
163 | /** |
164 | * Set width and height with proportional resize. |
165 | * |
166 | * @author Vincent@luo MSN:kele_100@hotmail.com |
167 | * |
168 | * @return self |
169 | */ |
170 | public function setWidthAndHeight(int $width = 0, int $height = 0) |
171 | { |
172 | $xratio = $width / $this->width; |
173 | $yratio = $height / $this->height; |
174 | if ($this->resizeProportional && !(0 == $width || 0 == $height)) { |
175 | if (($xratio * $this->height) < $height) { |
176 | $this->height = (int) ceil($xratio * $this->height); |
177 | $this->width = $width; |
178 | } else { |
179 | $this->width = (int) ceil($yratio * $this->width); |
180 | $this->height = $height; |
181 | } |
182 | } |
183 | |
184 | return $this; |
185 | } |
186 | |
187 | /** |
188 | * Get ResizeProportional. |
189 | * |
190 | * @return bool |
191 | */ |
192 | public function isResizeProportional() |
193 | { |
194 | return $this->resizeProportional; |
195 | } |
196 | |
197 | /** |
198 | * Set ResizeProportional. |
199 | * |
200 | * @param bool $pValue |
201 | */ |
202 | public function setResizeProportional($pValue = true): self |
203 | { |
204 | $this->resizeProportional = $pValue; |
205 | |
206 | return $this; |
207 | } |
208 | |
209 | /** |
210 | * Get hash code. |
211 | * |
212 | * @return string Hash code |
213 | */ |
214 | public function getHashCode(): string |
215 | { |
216 | return md5($this->name . $this->description . parent::getHashCode() . __CLASS__); |
217 | } |
218 | } |