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\SVGElement; |
15
|
|
|
use nstdio\svg\traits\StyleTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Shape |
19
|
|
|
* |
20
|
|
|
* @property float height The height of shape. |
21
|
|
|
* @property float width The width of shape. |
22
|
|
|
* @property string stroke Stroke color. |
23
|
|
|
* @property float strokeWidth Width of stroke. |
24
|
|
|
* @property string strokeLocation |
25
|
|
|
* @property string style |
26
|
|
|
* @property string fill |
27
|
|
|
* @property float fillOpacity specifies the opacity of the painting operation used to paint the interior the |
28
|
|
|
* current |
29
|
|
|
* @property string filter |
30
|
|
|
* @property string|null filterUrl The url part of 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 |
36
|
|
|
{ |
37
|
|
|
use StyleTrait; |
38
|
|
|
|
39
|
|
|
public function applyGradient(Gradient $gradient) |
40
|
|
|
{ |
41
|
|
|
$this->fill = "url(#{$gradient->id})"; |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function animate(BaseAnimation $animation) |
47
|
|
|
{ |
48
|
|
|
$this->element->appendChild($animation->getElement()); |
|
|
|
|
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function filterGaussianBlur($stdDeviation, $in = null, $filterId = null) |
54
|
|
|
{ |
55
|
|
|
$filter = new Filter($this->getRoot(), $filterId); |
56
|
|
|
$blur = new GaussianBlur($filter); |
57
|
|
|
$blur->stdDeviation = $stdDeviation; |
58
|
|
|
$blur->in = $in; |
59
|
|
|
|
60
|
|
|
$this->applyFilter($filter); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function diffusePointLight(array $pointLightConfig = [], array $diffuseLightingConfig = [], $filterId = null) |
66
|
|
|
{ |
67
|
|
|
$pointConfig = [ |
68
|
|
|
'x' => $this->x, |
|
|
|
|
69
|
|
|
'y' => $this->y, |
|
|
|
|
70
|
|
|
'z' => 10, |
71
|
|
|
]; |
72
|
|
|
foreach ($pointConfig as $key => $value) { |
73
|
|
|
if (isset($pointLightConfig[$key])) { |
74
|
|
|
$pointConfig[$key] = $this->{$key} + $pointLightConfig[$key]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
$filter = DiffuseLighting::diffusePointLight($this->getRoot(), $pointConfig, $diffuseLightingConfig, $filterId); |
|
|
|
|
78
|
|
|
$this->applyFilter($filter); |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function applyFilter(BaseFilter $filter) |
84
|
|
|
{ |
85
|
|
|
if ($this->filter === null) { |
86
|
|
|
$this->filter = "url(#$filter->id)"; |
87
|
|
|
} else { |
88
|
|
|
$value = str_replace(['url(#', ')'], '', $this->filter); |
89
|
|
|
$svg = $this->getSVG(); |
90
|
|
|
$currentFilter = $svg->getChildById($value); |
91
|
|
|
if ($currentFilter !== null) { |
92
|
|
|
foreach ($filter->getChildren() as $child) { |
93
|
|
|
$currentFilter->append($child); |
94
|
|
|
} |
95
|
|
|
$filterRoot = $filter->getRoot(); |
96
|
|
|
$filterRoot->removeChild($filter); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function linearGradientFromTop(array $colors, $id = null) |
104
|
|
|
{ |
105
|
|
|
return $this->applyGradient(UniformGradient::verticalFromTop($this->getRoot(), $colors, $id)); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function linearGradientFromBottom(array $colors, $id = null) |
109
|
|
|
{ |
110
|
|
|
return $this->applyGradient(UniformGradient::verticalFromBottom($this->getRoot(), $colors, $id)); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function linearGradientFromLeft(array $colors, $id = null) |
114
|
|
|
{ |
115
|
|
|
return $this->applyGradient(UniformGradient::horizontalFromLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function linearGradientFromRight(array $colors, $id = null) |
119
|
|
|
{ |
120
|
|
|
return $this->applyGradient(UniformGradient::horizontalFromRight($this->getRoot(), $colors, $id)); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function linearGradientFromTopLeft(array $colors, $id = null) |
124
|
|
|
{ |
125
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromTopLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function linearGradientFromTopRight(array $colors, $id = null) |
129
|
|
|
{ |
130
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromTopRight($this->getRoot(), $colors, $id)); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function linearGradientFromBottomLeft(array $colors, $id = null) |
134
|
|
|
{ |
135
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromBottomLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function linearGradientFromBottomRight(array $colors, $id = null) |
139
|
|
|
{ |
140
|
|
|
return $this->applyGradient(UniformGradient::diagonalFromBottomRight($this->getRoot(), $colors, $id)); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function radialGradientFromTopLeft(array $colors, $id = null) |
144
|
|
|
{ |
145
|
|
|
return $this->applyGradient(UniformGradient::radialTopLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function radialGradientFromTopRight(array $colors, $id = null) |
149
|
|
|
{ |
150
|
|
|
return $this->applyGradient(UniformGradient::radialTopRight($this->getRoot(), $colors, $id)); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function radialGradientFromBottomLeft(array $colors, $id = null) |
154
|
|
|
{ |
155
|
|
|
return $this->applyGradient(UniformGradient::radialBottomLeft($this->getRoot(), $colors, $id)); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function radialGradientFromBottomRight(array $colors, $id = null) |
159
|
|
|
{ |
160
|
|
|
return $this->applyGradient(UniformGradient::radialBottomRight($this->getRoot(), $colors, $id)); |
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function radialGradientFromTopCenter(array $colors, $id = null) |
164
|
|
|
{ |
165
|
|
|
return $this->applyGradient(UniformGradient::radialTopCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function radialGradientFromLeftCenter(array $colors, $id = null) |
169
|
|
|
{ |
170
|
|
|
return $this->applyGradient(UniformGradient::radialLeftCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function radialGradientFromBottomCenter(array $colors, $id = null) |
174
|
|
|
{ |
175
|
|
|
return $this->applyGradient(UniformGradient::radialBottomCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function radialGradientFromRightCenter(array $colors, $id = null) |
179
|
|
|
{ |
180
|
|
|
return $this->applyGradient(UniformGradient::radialRightCenter($this->getRoot(), $colors, $id)); |
|
|
|
|
181
|
|
|
} |
182
|
|
|
} |
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.