|
1
|
|
|
<?php |
|
2
|
|
|
namespace nstdio\svg\filter; |
|
3
|
|
|
|
|
4
|
|
|
use nstdio\svg\container\ContainerInterface; |
|
5
|
|
|
use nstdio\svg\container\Defs; |
|
6
|
|
|
use nstdio\svg\container\SVG; |
|
7
|
|
|
use nstdio\svg\SVGElement; |
|
8
|
|
|
use nstdio\svg\util\KeyValueWriter; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class BaseFilter |
|
12
|
|
|
* |
|
13
|
|
|
* @property float x = "<coordinate>" The minimum x coordinate for the subregion which restricts |
|
14
|
|
|
* calculation and rendering of the given filter primitive. |
|
15
|
|
|
* @property float y = "<coordinate>" The minimum y coordinate for the subregion which restricts |
|
16
|
|
|
* calculation and rendering of the given filter primitive. |
|
17
|
|
|
* @property float width = "<length>" The width of the subregion which restricts calculation and |
|
18
|
|
|
* rendering of the given filter primitive. See filter primitive subregion. A negative value is an error. A |
|
19
|
|
|
* value of zero disables the effect of the given filter primitive (i.e., the result is a transparent black |
|
20
|
|
|
* image). |
|
21
|
|
|
* @property float height = "<length>" The height of the subregion which restricts calculation and rendering of |
|
22
|
|
|
* the given filter primitive. See filter primitive subregion. A negative value is an error (see Error |
|
23
|
|
|
* processing). A value of zero disables the effect of the given filter primitive (i.e., the result is a |
|
24
|
|
|
* transparent black image). |
|
25
|
|
|
* @property string result = "<filter-primitive-reference>" Assigned name for this filter primitive. If supplied, |
|
26
|
|
|
* then graphics that result from processing this filter primitive can be referenced by an 'in' attribute on |
|
27
|
|
|
* a subsequent filter primitive within the same 'filter' element. If no value is provided, the output will |
|
28
|
|
|
* only be available for re-use as the implicit input into the next filter primitive if that filter primitive |
|
29
|
|
|
* provides no value for its 'in' attribute. Note that a <filter-primitive-reference> is not an XML ID; |
|
30
|
|
|
* instead, a <filter-primitive-reference> is only meaningful within a given 'filter' element and thus have |
|
31
|
|
|
* only local scope. It is legal for the same <filter-primitive-reference> to appear multiple times within |
|
32
|
|
|
* the same 'filter' element. When referenced, the <filter-primitive-reference> will use the closest |
|
33
|
|
|
* preceding filter primitive with the given result. |
|
34
|
|
|
* @property string in = "SourceGraphic | SourceAlpha | BackgroundImage | BackgroundAlpha | FillPaint | |
|
35
|
|
|
* StrokePaint | <filter-primitive-reference>" Identifies input for the given filter primitive. The value can |
|
36
|
|
|
* be either one of six keywords or can be a string which matches a previous 'result' attribute value within |
|
37
|
|
|
* the same 'filter' element. If no value is provided and this is the first filter primitive, then this |
|
38
|
|
|
* filter primitive will use SourceGraphic as its input. If no value is provided and this is a subsequent |
|
39
|
|
|
* filter primitive, then this filter primitive will use the result from the previous filter primitive as its |
|
40
|
|
|
* input. {@link https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveInAttribute} |
|
41
|
|
|
* @package nstdio\svg\filter |
|
42
|
|
|
* @author Edgar Asatryan <[email protected]> |
|
43
|
|
|
*/ |
|
44
|
|
|
abstract class BaseFilter extends SVGElement |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* @param ContainerInterface $container |
|
48
|
|
|
* @param $filterId |
|
49
|
|
|
* |
|
50
|
|
|
* @return Filter |
|
51
|
|
|
*/ |
|
52
|
10 |
|
protected static function defaultFilter(ContainerInterface $container, $filterId) |
|
53
|
|
|
{ |
|
54
|
10 |
|
return self::filterWithOptions($container, [ |
|
55
|
10 |
|
'id' => $filterId, |
|
56
|
10 |
|
'filterUnits' => 'objectBoundingBox', |
|
57
|
10 |
|
'x' => '0%', |
|
58
|
10 |
|
'y' => '0%', |
|
59
|
10 |
|
'width' => '100%', |
|
60
|
10 |
|
'height' => '100%', |
|
61
|
10 |
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
11 |
|
protected static function filterWithOptions(ContainerInterface $container, array $options) |
|
65
|
|
|
{ |
|
66
|
11 |
|
if ($container instanceof SVGElement) { |
|
67
|
10 |
|
$defs = $container->getSVG()->getFirstChild(); |
|
68
|
11 |
|
} elseif ($container instanceof SVG) { |
|
69
|
1 |
|
$defs = $container->getFirstChild(); |
|
70
|
1 |
|
} else { |
|
71
|
|
|
$defs = new Defs($container); |
|
72
|
|
|
} |
|
73
|
11 |
|
$filter = new Filter($defs, $options['id']); |
|
74
|
11 |
|
unset($options['id']); |
|
75
|
11 |
|
KeyValueWriter::apply($filter->getElement(), $options); |
|
76
|
|
|
|
|
77
|
11 |
|
return $filter; |
|
78
|
|
|
} |
|
79
|
|
|
} |