Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| PageMargin | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
5 | |||
| uniform | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| symmetric | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\PagedMedia; |
| 6 | |
| 7 | /** |
| 8 | * The four edges of the page margin area in PDF points. |
| 9 | * |
| 10 | * CSS Paged Media 3 §6.2 declares page margins via the `margin` |
| 11 | * shorthand inside an `@page` rule. The shorthand follows CSS |
| 12 | * Box 3 §4 conventions (1 / 2 / 3 / 4 values → top / right / |
| 13 | * bottom / left). |
| 14 | * |
| 15 | * Immutable; build via `new PageMargin(...)` or the convenience |
| 16 | * factories `uniform()` (single value), `horizontal()` / |
| 17 | * `vertical()` (two values). |
| 18 | */ |
| 19 | final readonly class PageMargin |
| 20 | { |
| 21 | public function __construct( |
| 22 | public float $top, |
| 23 | public float $right, |
| 24 | public float $bottom, |
| 25 | public float $left, |
| 26 | ) { |
| 27 | if ($top < 0 || $right < 0 || $bottom < 0 || $left < 0) { |
| 28 | throw new \InvalidArgumentException(sprintf( |
| 29 | 'PageMargin values must be non-negative; got (%g, %g, %g, %g)', |
| 30 | $top, |
| 31 | $right, |
| 32 | $bottom, |
| 33 | $left, |
| 34 | )); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * `margin: 72pt` → 72-point margin on every edge. |
| 40 | */ |
| 41 | public static function uniform(float $value): self |
| 42 | { |
| 43 | return new self($value, $value, $value, $value); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * `margin: 72pt 36pt` → vertical 72 / horizontal 36. |
| 48 | */ |
| 49 | public static function symmetric(float $vertical, float $horizontal): self |
| 50 | { |
| 51 | return new self($vertical, $horizontal, $vertical, $horizontal); |
| 52 | } |
| 53 | } |