Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
78.95% covered (warning)
78.95%
15 / 19
57.14% covered (warning)
57.14%
4 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeFunc
78.95% covered (warning)
78.95%
15 / 19
57.14% covered (warning)
57.14%
4 / 7
14.58
0.00% covered (danger)
0.00%
0 / 1
 type
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 tableValues
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
5.20
 slope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 intercept
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 amplitude
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 exponent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Filter;
6
7use Phpdftk\Svg\Element;
8
9/**
10 * SVG 2 Filter Effects §15.14 — common base for `feFuncR`,
11 * `feFuncG`, `feFuncB`, `feFuncA`. Each defines a transfer
12 * function for one colour channel.
13 *
14 * `type` chooses the function shape:
15 *
16 *   identity (default) — `out = in`
17 *   table              — piecewise-linear lookup table
18 *   discrete           — step function
19 *   linear             — `out = slope·in + intercept`
20 *   gamma              — `out = amplitude · in^exponent + offset`
21 */
22abstract class FeFunc extends Element
23{
24    public function type(): string
25    {
26        $v = strtolower($this->getAttribute('type') ?? 'identity');
27        return match ($v) {
28            'identity', 'table', 'discrete', 'linear', 'gamma' => $v,
29            default => 'identity',
30        };
31    }
32
33    /**
34     * @return list<float>
35     */
36    public function tableValues(): array
37    {
38        $raw = trim($this->getAttribute('tableValues') ?? '');
39        if ($raw === '') {
40            return [];
41        }
42        $parts = preg_split('/[\s,]+/', $raw) ?: [];
43        $out = [];
44        foreach ($parts as $p) {
45            if ($p === '') {
46                continue;
47            }
48            $out[] = (float) $p;
49        }
50        return $out;
51    }
52
53    public function slope(): float
54    {
55        return (float) ($this->getAttribute('slope') ?? 1);
56    }
57
58    public function intercept(): float
59    {
60        return (float) ($this->getAttribute('intercept') ?? 0);
61    }
62
63    public function amplitude(): float
64    {
65        return (float) ($this->getAttribute('amplitude') ?? 1);
66    }
67
68    public function exponent(): float
69    {
70        return (float) ($this->getAttribute('exponent') ?? 1);
71    }
72
73    public function offset(): float
74    {
75        return (float) ($this->getAttribute('offset') ?? 0);
76    }
77}