Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
PageBox
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
4
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
 contentArea
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 letter
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 a4
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\PagedMedia;
6
7use Phpdftk\Geometry\Rectangle;
8
9/**
10 * Concrete page geometry for one rendered page — size, margins, and
11 * the resolved content area where the document flow lives.
12 *
13 * CSS Paged Media 3 §3 defines the page model: the page sheet (the
14 * physical PDF page) contains the page area (everything inside
15 * page-margin minus marginalia), which contains the page content
16 * area where document flow renders.
17 *
18 *   page sheet     = full PDF page (size from @page { size })
19 *   page area      = sheet minus page-margin
20 *   content area   = page area; the box document content flows into
21 *
22 * Margin boxes occupy the band between the sheet edge and the
23 * content area, positioned per {@see MarginBoxPosition}.
24 *
25 * Phase 4G.1 (extraction) constructs PageBox instances from the
26 * resolved `@page` cascade, then passes them to the painter.
27 */
28final readonly class PageBox
29{
30    public function __construct(
31        public Rectangle $size,
32        public PageMargin $margin,
33    ) {}
34
35    /**
36     * The content area — page sheet minus the four margins. This
37     * is where document flow renders; everything outside is the
38     * marginalia band.
39     */
40    public function contentArea(): Rectangle
41    {
42        return new Rectangle(
43            $this->margin->left,
44            $this->margin->bottom,
45            $this->size->width - $this->margin->left - $this->margin->right,
46            $this->size->height - $this->margin->top - $this->margin->bottom,
47        );
48    }
49
50    /**
51     * Letter (US default) — 612 × 792 PDF points, 72-point margins
52     * on every edge.
53     */
54    public static function letter(): self
55    {
56        return new self(
57            new Rectangle(0.0, 0.0, 612.0, 792.0),
58            PageMargin::uniform(72.0),
59        );
60    }
61
62    /**
63     * A4 — 595 × 842 PDF points, 72-point margins on every edge.
64     */
65    public static function a4(): self
66    {
67        return new self(
68            new Rectangle(0.0, 0.0, 595.0, 842.0),
69            PageMargin::uniform(72.0),
70        );
71    }
72}