1
|
|
|
<?php |
2
|
|
|
namespace nstdio\svg\shape; |
3
|
|
|
|
4
|
|
|
use nstdio\svg\Animatable; |
5
|
|
|
use nstdio\svg\animation\BaseAnimation; |
6
|
|
|
use nstdio\svg\attributes\Styleable; |
7
|
|
|
use nstdio\svg\filter\BaseFilter; |
8
|
|
|
use nstdio\svg\filter\DiffuseLighting; |
9
|
|
|
use nstdio\svg\filter\Filter; |
10
|
|
|
use nstdio\svg\filter\GaussianBlur; |
11
|
|
|
use nstdio\svg\Filterable; |
12
|
|
|
use nstdio\svg\gradient\Gradient; |
13
|
|
|
use nstdio\svg\gradient\UniformGradient; |
14
|
|
|
use nstdio\svg\GradientInterface; |
15
|
|
|
use nstdio\svg\SVGElement; |
16
|
|
|
use nstdio\svg\traits\StyleTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Shape |
20
|
|
|
* |
21
|
|
|
* @property float height The height of shape. |
22
|
|
|
* @property float width The width of shape. |
23
|
|
|
* @property string stroke Stroke color. |
24
|
|
|
* @property float strokeWidth Width of stroke. |
25
|
|
|
* @property string strokeLocation |
26
|
|
|
* @property string style |
27
|
|
|
* @property string fill |
28
|
|
|
* @property float fillOpacity specifies the opacity of the painting operation used to paint the interior the |
29
|
|
|
* current |
30
|
|
|
* @property string filter |
31
|
|
|
* @property string transform |
32
|
|
|
* @package nstdio\svg\shape |
33
|
|
|
* @author Edgar Asatryan <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
abstract class Shape extends SVGElement implements Styleable, Animatable, Filterable, GradientInterface |
36
|
|
|
{ |
37
|
|
|
use StyleTrait; |
38
|
|
|
|
39
|
|
|
abstract protected function getCenterX(); |
40
|
|
|
|
41
|
|
|
abstract protected function getCenterY(); |
42
|
|
|
|
43
|
|
|
public function applyGradient(Gradient $gradient) |
44
|
|
|
{ |
45
|
|
|
$this->fill = "url(#{$gradient->id})"; |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function animate(BaseAnimation $animation) |
51
|
|
|
{ |
52
|
|
|
$this->element->appendChild($animation->getElement()); |
|
|
|
|
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function filterGaussianBlur($stdDeviation, $in = null, $filterId = null) |
58
|
|
|
{ |
59
|
|
|
$filter = new Filter($this->getRoot(), $filterId); |
60
|
|
|
$blur = new GaussianBlur($filter); |
61
|
|
|
$blur->stdDeviation = $stdDeviation; |
62
|
|
|
$blur->in = $in; |
63
|
|
|
|
64
|
|
|
$this->applyFilter($filter); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function diffusePointLight(array $pointLightConfig = [], array $diffuseLightingConfig = [], $filterId = null) |
70
|
|
|
{ |
71
|
|
|
$pointConfig = [ |
72
|
|
|
'x' => $this->getCenterX(), |
73
|
|
|
'y' => $this->getCenterY(), |
74
|
|
|
'z' => 25, |
75
|
|
|
]; |
76
|
|
|
foreach ($pointConfig as $key => $value) { |
77
|
|
|
if (isset($pointLightConfig[$key])) { |
78
|
|
|
$pointConfig[$key] = $value + $pointLightConfig[$key]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
$filter = DiffuseLighting::diffusePointLight($this->getRoot(), $pointConfig, $diffuseLightingConfig, $filterId); |
|
|
|
|
82
|
|
|
$this->applyFilter($filter); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function applyFilter(BaseFilter $filter) |
88
|
|
|
{ |
89
|
|
|
if ($this->filter === null) { |
90
|
|
|
$this->filter = "url(#$filter->id)"; |
91
|
|
|
} else { |
92
|
|
|
$value = str_replace(['url(#', ')'], '', $this->filter); |
93
|
|
|
$svg = $this->getSVG(); |
94
|
|
|
$currentFilter = $svg->getChildById($value); |
95
|
|
|
if ($currentFilter !== null) { |
96
|
|
|
foreach ($filter->getChildren() as $child) { |
97
|
|
|
$currentFilter->append($child); |
98
|
|
|
} |
99
|
|
|
$filterRoot = $filter->getRoot(); |
100
|
|
|
$filterRoot->removeChild($filter); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function linearGradientFromTop(array $colors, $id = null) |
108
|
|
|
{ |
109
|
|
|
return $this->applyGradient(UniformGradient::verticalFromTop($this->getRoot(), $colors, $id)); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function linearGradientFromBottom(array $colors, $id = null) |
113
|
|
|
{ |
114
|
|
|
return $this->applyGradient(UniformGradient::verticalFromBottom($this->getRoot(), $colors, $id)); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function linearGradientFromLeft(array $colors, $id = null) |
118
|
|
|
{ |
119
|
|
|
return $this->applyGradient(UniformGradient::horizontalFromLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function linearGradientFromRight(array $colors, $id = null) |
123
|
|
|
{ |
124
|
|
|
return $this->applyGradient(UniformGradient::horizontalFromRight($this->getRoot(), $colors, $id)); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function linearGradientFromTopLeft(array $colors, $id = null) |
128
|
|
|
{ |
129
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromTopLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function linearGradientFromTopRight(array $colors, $id = null) |
133
|
|
|
{ |
134
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromTopRight($this->getRoot(), $colors, $id)); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function linearGradientFromBottomLeft(array $colors, $id = null) |
138
|
|
|
{ |
139
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromBottomLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function linearGradientFromBottomRight(array $colors, $id = null) |
143
|
|
|
{ |
144
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromBottomRight($this->getRoot(), $colors, $id)); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function radialGradientFromTopLeft(array $colors, $id = null) |
148
|
|
|
{ |
149
|
|
|
return $this->applyGradient(UniformGradient::radialTopLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function radialGradientFromTopRight(array $colors, $id = null) |
153
|
|
|
{ |
154
|
|
|
return $this->applyGradient(UniformGradient::radialTopRight($this->getRoot(), $colors, $id)); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function radialGradientFromBottomLeft(array $colors, $id = null) |
158
|
|
|
{ |
159
|
|
|
return $this->applyGradient(UniformGradient::radialBottomLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function radialGradientFromBottomRight(array $colors, $id = null) |
163
|
|
|
{ |
164
|
|
|
return $this->applyGradient(UniformGradient::radialBottomRight($this->getRoot(), $colors, $id)); |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function radialGradientFromTopCenter(array $colors, $id = null) |
168
|
|
|
{ |
169
|
|
|
return $this->applyGradient(UniformGradient::radialTopCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function radialGradientFromLeftCenter(array $colors, $id = null) |
173
|
|
|
{ |
174
|
|
|
return $this->applyGradient(UniformGradient::radialLeftCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function radialGradientFromBottomCenter(array $colors, $id = null) |
178
|
|
|
{ |
179
|
|
|
return $this->applyGradient(UniformGradient::radialBottomCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function radialGradientFromRightCenter(array $colors, $id = null) |
183
|
|
|
{ |
184
|
|
|
return $this->applyGradient(UniformGradient::radialRightCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
185
|
|
|
} |
186
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.