Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TransparencyConstraint
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
6.03
0.00% covered (danger)
0.00%
0 / 1
 check
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
6.03
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Conformance\Constraint;
6
7use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector;
8use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile;
9use Phpdftk\Pdf\Conformance\Profile\PdfAProfile;
10use Phpdftk\Pdf\Conformance\Profile\PdfXProfile;
11use Phpdftk\Pdf\Conformance\Result\ConformanceViolation;
12use Phpdftk\Pdf\Conformance\Result\ViolationSeverity;
13
14/**
15 * Transparency prohibition for PDF/A-1 (clause 6.4) and PDF/X-1a/X-3.
16 *
17 * Only applies to profiles that prohibit transparency.
18 */
19final class TransparencyConstraint implements ConformanceConstraint
20{
21    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
22    {
23        // Check if this profile prohibits transparency
24        if ($profile instanceof PdfAProfile && !$profile->prohibitsTransparency()) {
25            return [];
26        }
27        if ($profile instanceof PdfXProfile && !$profile->prohibitsTransparency()) {
28            return [];
29        }
30
31        if ($inspector->hasTransparency()) {
32            return [new ConformanceViolation(
33                clause: '6.4',
34                message: 'Transparency (page groups with /S /Transparency) is prohibited in ' . $profile->getFamily() . '-' . $profile->getLevel(),
35                severity: ViolationSeverity::Error,
36            )];
37        }
38
39        return [];
40    }
41}