Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TrimBoxConstraint | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| check | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Conformance\Constraint; |
| 6 | |
| 7 | use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector; |
| 8 | use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile; |
| 9 | use Phpdftk\Pdf\Conformance\Result\ConformanceViolation; |
| 10 | use Phpdftk\Pdf\Conformance\Result\ViolationSeverity; |
| 11 | |
| 12 | /** |
| 13 | * PDF/X: All pages must have /TrimBox (or /ArtBox as fallback). |
| 14 | * |
| 15 | * The TrimBox defines the intended finished dimensions of the printed |
| 16 | * page after trimming. This is mandatory for all PDF/X levels. |
| 17 | */ |
| 18 | final class TrimBoxConstraint implements ConformanceConstraint |
| 19 | { |
| 20 | public function check(DocumentInspector $inspector, ConformanceProfile $profile): array |
| 21 | { |
| 22 | $violations = []; |
| 23 | $pageIndex = 0; |
| 24 | |
| 25 | foreach ($inspector->getPages() as $page) { |
| 26 | if ($page->trimBox === null && $page->artBox === null) { |
| 27 | $violations[] = new ConformanceViolation( |
| 28 | clause: '6.2', |
| 29 | message: sprintf( |
| 30 | 'Page %d must have /TrimBox (or /ArtBox) for %s conformance', |
| 31 | $pageIndex, |
| 32 | $profile->getFamily() . '-' . $profile->getLevel(), |
| 33 | ), |
| 34 | severity: ViolationSeverity::Error, |
| 35 | objectPath: "Page[{$pageIndex}].TrimBox", |
| 36 | ); |
| 37 | } |
| 38 | $pageIndex++; |
| 39 | } |
| 40 | |
| 41 | return $violations; |
| 42 | } |
| 43 | } |