Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
BoxGeometry
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 outerWidth
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 outerHeight
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\HtmlToPdf\Layout;
6
7/**
8 * Resolved geometry for a box after layout: the content rectangle plus
9 * the surrounding margin / border / padding edges.
10 *
11 * Coordinates are in PDF user-space units (1pt = 1/72in), with the
12 * top-left of the page box at (0, 0) and Y increasing downward — layout's
13 * own convention. The painter flips Y when emitting to PDF's bottom-left
14 * coordinate system.
15 *
16 * `x` / `y` mark the top-left of the **content** area. `width` / `height`
17 * are the content-box dimensions. The other fields are the four edges of
18 * margin, border, and padding, in CSS order (top, right, bottom, left).
19 */
20final class BoxGeometry
21{
22    public float $x = 0.0;
23    public float $y = 0.0;
24    public float $width = 0.0;
25    public float $height = 0.0;
26    public float $marginTop = 0.0;
27    public float $marginRight = 0.0;
28    public float $marginBottom = 0.0;
29    public float $marginLeft = 0.0;
30    public float $borderTop = 0.0;
31    public float $borderRight = 0.0;
32    public float $borderBottom = 0.0;
33    public float $borderLeft = 0.0;
34    public float $paddingTop = 0.0;
35    public float $paddingRight = 0.0;
36    public float $paddingBottom = 0.0;
37    public float $paddingLeft = 0.0;
38
39    /** Total horizontal space occupied by the box, including margins / borders / padding. */
40    public function outerWidth(): float
41    {
42        return $this->marginLeft + $this->borderLeft + $this->paddingLeft
43            + $this->width
44            + $this->paddingRight + $this->borderRight + $this->marginRight;
45    }
46
47    public function outerHeight(): float
48    {
49        return $this->marginTop + $this->borderTop + $this->paddingTop
50            + $this->height
51            + $this->paddingBottom + $this->borderBottom + $this->marginBottom;
52    }
53}