Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FeMorphology | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
7.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| operator | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| radius | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
4.05 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg\Filter; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 Filter Effects §15.11 — `<feMorphology operator radius>`. |
| 9 | * Erodes or dilates the input by the given radius. Used to thicken |
| 10 | * or thin shapes (text outlines, icon strokes, etc.). |
| 11 | * |
| 12 | * operator: erode | dilate (default) |
| 13 | * radius: single value (isotropic) or two values (rx, ry) |
| 14 | */ |
| 15 | final class FeMorphology extends FilterPrimitive |
| 16 | { |
| 17 | public function __construct() |
| 18 | { |
| 19 | parent::__construct('feMorphology'); |
| 20 | } |
| 21 | |
| 22 | public function operator(): string |
| 23 | { |
| 24 | $v = strtolower($this->getAttribute('operator') ?? 'erode'); |
| 25 | return $v === 'dilate' ? 'dilate' : 'erode'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return array{0: float, 1: float} [rx, ry] — both non-negative. |
| 30 | */ |
| 31 | public function radius(): array |
| 32 | { |
| 33 | $raw = trim($this->getAttribute('radius') ?? ''); |
| 34 | if ($raw === '') { |
| 35 | return [0.0, 0.0]; |
| 36 | } |
| 37 | $parts = preg_split('/[\s,]+/', $raw) ?: []; |
| 38 | $rx = max(0.0, (float) ($parts[0] ?? 0)); |
| 39 | $ry = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $rx; |
| 40 | return [$rx, $ry]; |
| 41 | } |
| 42 | } |