Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| FeDisplacementMap | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| in2 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| xChannelSelector | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| yChannelSelector | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| channel | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg\Filter; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 Filter Effects §15.8 — `<feDisplacementMap>`. Uses one |
| 9 | * input's pixel values to spatially offset another input. Common |
| 10 | * pairing with feTurbulence to "wobble" content. |
| 11 | * |
| 12 | * in / in2: primary + displacement source |
| 13 | * scale: displacement magnitude (default 0) |
| 14 | * xChannelSelector: R | G | B | A (default A) |
| 15 | * yChannelSelector: R | G | B | A (default A) |
| 16 | */ |
| 17 | final class FeDisplacementMap extends FilterPrimitive |
| 18 | { |
| 19 | public function __construct() |
| 20 | { |
| 21 | parent::__construct('feDisplacementMap'); |
| 22 | } |
| 23 | |
| 24 | public function in2(): ?string |
| 25 | { |
| 26 | return $this->getAttribute('in2'); |
| 27 | } |
| 28 | |
| 29 | public function scale(): float |
| 30 | { |
| 31 | return (float) ($this->getAttribute('scale') ?? 0); |
| 32 | } |
| 33 | |
| 34 | public function xChannelSelector(): string |
| 35 | { |
| 36 | return $this->channel('xChannelSelector'); |
| 37 | } |
| 38 | |
| 39 | public function yChannelSelector(): string |
| 40 | { |
| 41 | return $this->channel('yChannelSelector'); |
| 42 | } |
| 43 | |
| 44 | private function channel(string $attr): string |
| 45 | { |
| 46 | $v = strtoupper($this->getAttribute($attr) ?? 'A'); |
| 47 | return in_array($v, ['R', 'G', 'B', 'A'], true) ? $v : 'A'; |
| 48 | } |
| 49 | } |