Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ColorSpaceConstraint | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| check | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| 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/A clause 6.2: Device-dependent color spaces are only allowed |
| 14 | * when a matching OutputIntent is present. |
| 15 | * |
| 16 | * This is an advisory check: the constraint verifies that either the |
| 17 | * document uses only device-independent color spaces (CalGray, CalRGB, |
| 18 | * Lab, ICCBased) or has an OutputIntent with an embedded ICC profile |
| 19 | * to anchor device-dependent color (DeviceRGB, DeviceCMYK, DeviceGray). |
| 20 | * |
| 21 | * A full check would require parsing every content stream operator for |
| 22 | * color space usage — this constraint checks at the structural level. |
| 23 | */ |
| 24 | final class ColorSpaceConstraint implements ConformanceConstraint |
| 25 | { |
| 26 | public function check(DocumentInspector $inspector, ConformanceProfile $profile): array |
| 27 | { |
| 28 | // If an OutputIntent with ICC profile exists, device color is anchored |
| 29 | if ($inspector->hasOutputIntents()) { |
| 30 | return []; |
| 31 | } |
| 32 | |
| 33 | // Without an OutputIntent, warn that device color may not be conformant |
| 34 | return [new ConformanceViolation( |
| 35 | clause: '6.2.3', |
| 36 | message: 'Device-dependent color spaces (DeviceRGB, DeviceCMYK, DeviceGray) ' |
| 37 | . 'require an OutputIntent with an embedded ICC profile, ' |
| 38 | . 'or all color must use device-independent spaces (CalRGB, ICCBased, etc.)', |
| 39 | severity: ViolationSeverity::Warning, |
| 40 | )]; |
| 41 | } |
| 42 | } |