Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.82% covered (warning)
81.82%
9 / 11
87.50% covered (warning)
87.50%
7 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Filter
81.82% covered (warning)
81.82%
9 / 11
87.50% covered (warning)
87.50%
7 / 8
10.60
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
 x
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 y
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 width
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 height
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 filterUnits
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 primitiveUnits
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 href
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg;
6
7/**
8 * SVG 2 Filter Effects §6.1 — `<filter>` element. Defines a
9 * filter graph (list of primitive `<fe*>` operations) applied
10 * to any shape that references it via `filter="url(#filterId)"`
11 * or the CSS `filter` property.
12 *
13 *   <defs>
14 *     <filter id="blur">
15 *       <feGaussianBlur stdDeviation="2"/>
16 *     </filter>
17 *   </defs>
18 *   <rect filter="url(#blur)" width="100" height="100"/>
19 *
20 * The element itself never paints — like marker / pattern /
21 * gradient, it's a referenceable definition. PDF SoftMask-based
22 * filter rendering (CSS Filter Effects 1 §4) needs the raster
23 * pipeline and is a future deliverable.
24 */
25final class Filter extends Element
26{
27    public function __construct()
28    {
29        parent::__construct('filter');
30    }
31
32    public function x(): float
33    {
34        return (float) ($this->getAttribute('x') ?? -0.1);
35    }
36
37    public function y(): float
38    {
39        return (float) ($this->getAttribute('y') ?? -0.1);
40    }
41
42    public function width(): float
43    {
44        return (float) ($this->getAttribute('width') ?? 1.2);
45    }
46
47    public function height(): float
48    {
49        return (float) ($this->getAttribute('height') ?? 1.2);
50    }
51
52    public function filterUnits(): string
53    {
54        $u = strtolower($this->getAttribute('filterUnits') ?? 'objectboundingbox');
55        return $u === 'userspaceonuse' ? 'userSpaceOnUse' : 'objectBoundingBox';
56    }
57
58    public function primitiveUnits(): string
59    {
60        $u = strtolower($this->getAttribute('primitiveUnits') ?? 'userspaceonuse');
61        return $u === 'objectboundingbox' ? 'objectBoundingBox' : 'userSpaceOnUse';
62    }
63
64    public function href(): ?string
65    {
66        return $this->getAttribute('href')
67            ?? $this->getAttribute('xlink:href');
68    }
69}