Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MarginBoxPosition
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
9
100.00% covered (success)
100.00%
1 / 1
 isCorner
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 edge
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\PagedMedia;
6
7/**
8 * CSS Paged Media 3 §5.2 — the 16 page-margin box positions.
9 *
10 * A `@page` rule may contain up to 16 nested at-rules, one per box
11 * position. Each one is a generated-content box positioned in the
12 * page margin area; the content is set via the `content:` property.
13 *
14 * Layout:
15 *
16 *   ┌─────────┬────────────┬────────────┬────────────┬─────────┐
17 *   │ TL-Corner│   T-Left   │   T-Center │   T-Right  │TR-Corner│
18 *   ├─────────┼────────────┴────────────┴────────────┼─────────┤
19 *   │  L-Top  │                                       │  R-Top  │
20 *   ├─────────┤                                       ├─────────┤
21 *   │L-Middle │           Page content box            │R-Middle │
22 *   ├─────────┤                                       ├─────────┤
23 *   │L-Bottom │                                       │R-Bottom │
24 *   ├─────────┼────────────┬────────────┬────────────┼─────────┤
25 *   │BL-Corner│   B-Left   │  B-Center  │   B-Right  │BR-Corner│
26 *   └─────────┴────────────┴────────────┴────────────┴─────────┘
27 *
28 * The four corners are box positions but typically used for
29 * decoration. The four edges hold the running headers and footers
30 * (`@top-center`, `@bottom-center` are the most common).
31 *
32 * Phase 4G.1 (extraction) maps each position to its at-rule prelude
33 * keyword (`@top-left`, `@top-center`, …) and its spatial
34 * coordinates within the page margin area.
35 */
36enum MarginBoxPosition: string
37{
38    case TopLeftCorner = 'top-left-corner';
39    case TopLeft = 'top-left';
40    case TopCenter = 'top-center';
41    case TopRight = 'top-right';
42    case TopRightCorner = 'top-right-corner';
43
44    case LeftTop = 'left-top';
45    case LeftMiddle = 'left-middle';
46    case LeftBottom = 'left-bottom';
47
48    case RightTop = 'right-top';
49    case RightMiddle = 'right-middle';
50    case RightBottom = 'right-bottom';
51
52    case BottomLeftCorner = 'bottom-left-corner';
53    case BottomLeft = 'bottom-left';
54    case BottomCenter = 'bottom-center';
55    case BottomRight = 'bottom-right';
56    case BottomRightCorner = 'bottom-right-corner';
57
58    /**
59     * True for the four corner boxes. Corners have a single
60     * dimension determined by the adjacent margins (the top margin
61     * for top corners, etc.) rather than flowing along an edge.
62     */
63    public function isCorner(): bool
64    {
65        return match ($this) {
66            self::TopLeftCorner, self::TopRightCorner,
67            self::BottomLeftCorner, self::BottomRightCorner => true,
68            default => false,
69        };
70    }
71
72    /**
73     * The page edge this box sits along (`top` / `right` / `bottom`
74     * / `left`). Corner boxes return `null` (they sit at the
75     * intersection of two edges).
76     */
77    public function edge(): ?string
78    {
79        return match ($this) {
80            self::TopLeft, self::TopCenter, self::TopRight => 'top',
81            self::RightTop, self::RightMiddle, self::RightBottom => 'right',
82            self::BottomLeft, self::BottomCenter, self::BottomRight => 'bottom',
83            self::LeftTop, self::LeftMiddle, self::LeftBottom => 'left',
84            default => null,
85        };
86    }
87}