Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
StampPosition
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
8
100.00% covered (success)
100.00%
1 / 1
 computeCoordinates
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
8
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Toolkit\Stamper;
6
7/**
8 * Predefined stamp positions on a page.
9 */
10enum StampPosition
11{
12    case TopLeft;
13    case TopCenter;
14    case TopRight;
15    case Center;
16    case BottomLeft;
17    case BottomCenter;
18    case BottomRight;
19
20    /**
21     * Compute X/Y coordinates for text placement given page dimensions and margins.
22     *
23     * @return array{float, float} [x, y]
24     */
25    public function computeCoordinates(
26        float $pageWidth,
27        float $pageHeight,
28        float $contentWidth,
29        float $contentHeight,
30        float $margin = 36.0,
31    ): array {
32        return match ($this) {
33            self::TopLeft => [$margin, $pageHeight - $margin - $contentHeight],
34            self::TopCenter => [($pageWidth - $contentWidth) / 2, $pageHeight - $margin - $contentHeight],
35            self::TopRight => [$pageWidth - $margin - $contentWidth, $pageHeight - $margin - $contentHeight],
36            self::Center => [($pageWidth - $contentWidth) / 2, ($pageHeight - $contentHeight) / 2],
37            self::BottomLeft => [$margin, $margin],
38            self::BottomCenter => [($pageWidth - $contentWidth) / 2, $margin],
39            self::BottomRight => [$pageWidth - $margin - $contentWidth, $margin],
40        };
41    }
42}