Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PathShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
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\Css\Value;
6
7/**
8 * `path([<fill-rule>?] <string>)` per CSS Shapes 1 ยง3.5. Defines
9 * a clip / offset region via an SVG path data string. The path
10 * string is stored verbatim; the painter parses it through the
11 * existing SVG path-grammar parser at render time.
12 *
13 *   clip-path: path('M 0 0 L 100 100 Z');
14 *   offset-path: path('M 0,0 C 50,50 100,0 100,100');
15 *   shape-outside: path(evenodd, 'M 0 0 L 100 0 L 0 100 Z');
16 */
17final readonly class PathShape extends BasicShape
18{
19    public function __construct(
20        public string $fillRule,
21        public string $pathData,
22    ) {}
23
24    public function toCss(): string
25    {
26        $head = $this->fillRule === 'nonzero' ? '' : $this->fillRule . ', ';
27        // String literal with escaped quotes.
28        return 'path(' . $head . '"' . str_replace('"', '\\"', $this->pathData) . '")';
29    }
30}