Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
FloatItem
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
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
 marginBoxLeft
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 marginBoxTop
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 marginBoxWidth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 marginBoxHeight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\HtmlToPdf\Layout;
6
7/**
8 * One active float inside a {@see FloatContext}. Stored as a value
9 * object so {@see FloatContext} stays free of mutation accidents.
10 */
11final readonly class FloatItem
12{
13    /**
14     * @param array<string, mixed>|null $shape CSS Shapes 1 §3 exclusion
15     *        shape (a kind-keyed dict: `circle` / `ellipse` / `polygon`
16     *        / `path`), or null for the float's bounding rectangle.
17     */
18    public function __construct(
19        /** `'left'` or `'right'` per CSS 2.1 §9.5. */
20        public string $side,
21        public float $left,
22        public float $top,
23        public float $width,
24        public float $height,
25        /**
26         * CSS Shapes 1 §3 — when set, describes a per-Y exclusion
27         * shape carved out of the float's box. The default `null`
28         * means "axis-aligned rectangle of width × height" (the
29         * pre-shapes behaviour). When non-null, `FloatContext`'s
30         * leftEdgeAt / rightEdgeAt evaluate the shape at the line's
31         * Y instead of using the bounding rect.
32         *
33         * `kind: 'circle'` carries center coordinates `(cx, cy)`
34         * relative to the FloatItem's top-left, plus radius `r`.
35         */
36        public ?array $shape = null,
37        /**
38         * CSS 2.1 §9.5.1 / §9.5.2 — the float's MARGIN box. Float-vs-
39         * float placement and `clear` settle against this, never
40         * against the (possibly contracted) exclusion rect above: a
41         * `shape-outside: content-box` float still occupies its full
42         * margin box as far as other floats are concerned.
43         *
44         * Null means "same as the exclusion rect", which is the case
45         * whenever `shape-outside` is absent — the overwhelming
46         * default, and byte-identical to the pre-shapes behaviour.
47         */
48        public ?float $marginLeft = null,
49        public ?float $marginTop = null,
50        public ?float $marginWidth = null,
51        public ?float $marginHeight = null,
52    ) {}
53
54    /** Margin-box left edge, falling back to the exclusion rect. */
55    public function marginBoxLeft(): float
56    {
57        return $this->marginLeft ?? $this->left;
58    }
59
60    /** Margin-box top edge, falling back to the exclusion rect. */
61    public function marginBoxTop(): float
62    {
63        return $this->marginTop ?? $this->top;
64    }
65
66    /** Margin-box width, falling back to the exclusion rect. */
67    public function marginBoxWidth(): float
68    {
69        return $this->marginWidth ?? $this->width;
70    }
71
72    /** Margin-box height, falling back to the exclusion rect. */
73    public function marginBoxHeight(): float
74    {
75        return $this->marginHeight ?? $this->height;
76    }
77}