Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Box
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
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
 addChild
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\Box;
6
7use Phpdftk\Css\Cascade\CascadedValues;
8use Phpdftk\Html\Dom\Element;
9use Phpdftk\HtmlToPdf\Layout\BoxGeometry;
10use Phpdftk\HtmlToPdf\Layout\LineBox;
11use Phpdftk\HtmlToPdf\Layout\MultiColumnLayout;
12
13/**
14 * Base of the box tree produced by {@see BoxGenerator}.
15 *
16 * Each non-anonymous box carries its originating DOM element + the
17 * cascade's resolved property bag for that element. Anonymous boxes
18 * (wrappers synthesised by CSS Display 3 box-generation rules) have a
19 * null `$element` but inherit a style derived from their parent.
20 *
21 * `$children` is in document / logical order; layout (Phase 1F) walks the
22 * tree to compute positions and dimensions without re-ordering.
23 *
24 * Phase 1E.1 ships the structural box tree only — every box's geometry
25 * (`x`, `y`, `width`, `height`) is layout's responsibility, not box
26 * generation's. Keep that boundary sharp; this class doesn't track
27 * positions or sizes.
28 */
29abstract class Box
30{
31    /** @var list<Box> */
32    public array $children = [];
33
34    /** Resolved geometry — populated by layout, blank until {@see \Phpdftk\HtmlToPdf\Layout\BlockLayout} runs. */
35    public BoxGeometry $geometry;
36
37    /**
38     * Line boxes produced by {@see \Phpdftk\HtmlToPdf\Layout\InlineLayout}
39     * when this box's children form an inline formatting context. Empty
40     * for block-context parents and for boxes without inline content.
41     *
42     * @var list<LineBox>
43     */
44    public array $lineBoxes = [];
45
46    /**
47     * Set by {@see \Phpdftk\HtmlToPdf\Layout\BlockLayout} when this box's
48     * cascade declares a multi-column container (CSS Multi-column 1).
49     * Null on every other box. The painter reads this to stroke
50     * `column-rule` between adjacent columns.
51     */
52    public ?MultiColumnLayout $multiColumn = null;
53
54    public function __construct(
55        public readonly ?Element $element,
56        public readonly CascadedValues $style,
57    ) {
58        $this->geometry = new BoxGeometry();
59    }
60
61    public function addChild(self $child): void
62    {
63        $this->children[] = $child;
64    }
65}