Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ForeignObject | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| x | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| y | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| width | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| height | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 §11.6 — `<foreignObject>` embeds non-SVG content |
| 9 | * (HTML, MathML, etc.) inside an SVG fragment. The element |
| 10 | * carries a target rectangle (`x`, `y`, `width`, `height`) |
| 11 | * for laying out the foreign content, but the content itself |
| 12 | * is in another XML namespace and isn't part of the SVG |
| 13 | * painting tree. |
| 14 | * |
| 15 | * For the static print renderer we recognise the element so |
| 16 | * it parses to a typed class, but its descendants are not |
| 17 | * walked by the SVG dispatch — rendering nested HTML/MathML |
| 18 | * needs a separate pipeline that this typed class lets the |
| 19 | * caller wire up explicitly. |
| 20 | */ |
| 21 | final class ForeignObject extends Element |
| 22 | { |
| 23 | public function __construct() |
| 24 | { |
| 25 | parent::__construct('foreignObject'); |
| 26 | } |
| 27 | |
| 28 | public function x(): float |
| 29 | { |
| 30 | return (float) ($this->getAttribute('x') ?? 0); |
| 31 | } |
| 32 | |
| 33 | public function y(): float |
| 34 | { |
| 35 | return (float) ($this->getAttribute('y') ?? 0); |
| 36 | } |
| 37 | |
| 38 | public function width(): ?float |
| 39 | { |
| 40 | $w = $this->getAttribute('width'); |
| 41 | return $w !== null ? (float) $w : null; |
| 42 | } |
| 43 | |
| 44 | public function height(): ?float |
| 45 | { |
| 46 | $h = $this->getAttribute('height'); |
| 47 | return $h !== null ? (float) $h : null; |
| 48 | } |
| 49 | } |