Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeGaussianBlur
90.00% covered (success)
90.00%
9 / 10
66.67% covered (warning)
66.67%
2 / 3
7.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 stdDeviation
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
 edgeMode
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Filter;
6
7/**
8 * SVG 2 Filter Effects §15.10 — `<feGaussianBlur stdDeviation>`.
9 * Blurs the input by a Gaussian kernel. `stdDeviation` is either
10 * a single value (isotropic blur) or two values (separate X / Y
11 * standard deviations).
12 *
13 *   <feGaussianBlur stdDeviation="3"/>      // sx = sy = 3
14 *   <feGaussianBlur stdDeviation="3 1"/>    // sx = 3, sy = 1
15 */
16final class FeGaussianBlur extends FilterPrimitive
17{
18    public function __construct()
19    {
20        parent::__construct('feGaussianBlur');
21    }
22
23    /**
24     * @return array{0: float, 1: float}
25     *   [sigmaX, sigmaY]. Defaults to [0, 0] when the attribute is
26     *   absent (no blur).
27     */
28    public function stdDeviation(): array
29    {
30        $raw = trim($this->getAttribute('stdDeviation') ?? '');
31        if ($raw === '') {
32            return [0.0, 0.0];
33        }
34        $parts = preg_split('/[\s,]+/', $raw) ?: [];
35        $sx = max(0.0, (float) ($parts[0] ?? 0));
36        $sy = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $sx;
37        return [$sx, $sy];
38    }
39
40    /**
41     * Per §15.10 the default edge mode is `duplicate` (clamp);
42     * other values are `wrap` (tile) and `none` (transparent
43     * outside).
44     */
45    public function edgeMode(): string
46    {
47        $v = strtolower($this->getAttribute('edgeMode') ?? 'duplicate');
48        return in_array($v, ['duplicate', 'wrap', 'none'], true) ? $v : 'duplicate';
49    }
50}