Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Engine
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 resolvePageBox
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 findBreak
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 stylesheets
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\PagedMedia;
6
7use Phpdftk\PagedMedia\Fragmentation\BreakRule;
8
9/**
10 * Paged-media engine — the consumer-facing entry point.
11 *
12 * Phase 4G scaffold. The engine's concrete behaviour lands in
13 * sub-phases:
14 *
15 *   4G.1  Extract `@page` selector resolution, margin-box
16 *         collection, page-background painter, fragmentation
17 *         primitives from `phpdftk/html-to-pdf` (no semantic
18 *         change)
19 *   4G.2  Named pages — `page: foo` property + `@page foo` selector
20 *   4G.3  Running elements — `position: running()` + `running()`
21 *         in `content:` + cross-page reuse
22 *   4G.4  `string-set` + `content: string(name)` named strings
23 *   4G.5  Cross-references — `target-counter()`, `target-text()`,
24 *         leaders, lists of figures / tables
25 *   4G.6  Page floats — `float: top` / `bottom` / column floats,
26 *         float-defer model
27 *
28 * The public API surface is stable from this scaffold so call sites
29 * in html-to-pdf, svg-to-pdf, and the high-level Pdf API can be
30 * written against it now.
31 */
32final class Engine
33{
34    /**
35     * @param list<object> $stylesheets Parsed CSS stylesheets
36     *                                  (typed as `phpdftk/css`
37     *                                  `Stylesheet`; declared as
38     *                                  `list<object>` here to avoid
39     *                                  the scaffold importing the
40     *                                  full css type tree).
41     */
42    public function __construct(
43        private readonly array $stylesheets = [],
44    ) {}
45
46    /**
47     * Resolve the page box for one rendered page. Walks the
48     * `@page` cascade applying named-page + pseudo-class selectors,
49     * resolves `size` + `margin` + `background-*`, collects the
50     * 16 margin boxes.
51     *
52     * @param list<PageSelector> $pseudoClasses
53     */
54    public function resolvePageBox(
55        int $pageIndex,
56        ?string $namedPage = null,
57        array $pseudoClasses = [],
58    ): PageBox {
59        unset($pageIndex, $namedPage, $pseudoClasses);
60        throw new \RuntimeException('4G.1 not yet implemented');
61    }
62
63    /**
64     * Decide where to break a flowed block.
65     *
66     * `$blockHeight`        the block's measured height in points
67     * `$availableHeight`    space left in the current page area
68     * `$breakBefore`        `break-before` value on the block
69     * `$breakAfter`         `break-after` value on the next sibling
70     * `$breakInsideAvoid`   `break-inside: avoid` on this block?
71     *
72     * Returns the y-coordinate (in content-area space) where the
73     * break should occur, or `null` to indicate the block fits on
74     * the current page and no break is needed.
75     */
76    public function findBreak(
77        float $blockHeight,
78        float $availableHeight,
79        BreakRule $breakBefore = BreakRule::Auto,
80        BreakRule $breakAfter = BreakRule::Auto,
81        bool $breakInsideAvoid = false,
82    ): ?float {
83        unset($blockHeight, $availableHeight, $breakBefore, $breakAfter, $breakInsideAvoid);
84        throw new \RuntimeException('4G.1 not yet implemented');
85    }
86
87    /**
88     * @return list<object>
89     */
90    public function stylesheets(): array
91    {
92        return $this->stylesheets;
93    }
94}