Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ThreeDContentConstraint
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
9
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\Result\ConformanceViolation;
10use Phpdftk\Pdf\Conformance\Result\ViolationSeverity;
11use Phpdftk\Pdf\Core\Annotation\ThreeDAnnotation;
12
13/**
14 * ISO 24517-1 (PDF/E-1): 3D content validation.
15 *
16 * Validates that 3D annotations reference valid 3D streams with a recognized
17 * subtype (U3D or PRC) and at least one view definition.
18 */
19final class ThreeDContentConstraint implements ConformanceConstraint
20{
21    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
22    {
23        $violations = [];
24
25        // Check 3D annotations have a /3DD reference
26        foreach ($inspector->getRegisteredObjects() as $object) {
27            if ($object instanceof ThreeDAnnotation && $object->dd === null) {
28                $violations[] = new ConformanceViolation(
29                    clause: '13.6.3',
30                    message: '3D annotation is missing required /3DD stream reference',
31                    severity: ViolationSeverity::Error,
32                    objectPath: 'Annotation[3D]',
33                );
34            }
35        }
36
37        // Check 3D streams have a valid subtype and at least one view
38        foreach ($inspector->getThreeDStreams() as $stream) {
39            $subtype = $stream->subtype->value;
40            if ($subtype !== 'U3D' && $subtype !== 'PRC') {
41                $violations[] = new ConformanceViolation(
42                    clause: '13.6.3',
43                    message: sprintf(
44                        '3D stream has invalid subtype "%s"; must be U3D or PRC',
45                        $subtype,
46                    ),
47                    severity: ViolationSeverity::Error,
48                    objectPath: 'ThreeDStream',
49                );
50            }
51
52            if ($stream->va === null && $stream->dv === null) {
53                $violations[] = new ConformanceViolation(
54                    clause: '13.6.3',
55                    message: '3D stream has no views defined (/VA or /DV required)',
56                    severity: ViolationSeverity::Warning,
57                    objectPath: 'ThreeDStream',
58                );
59            }
60        }
61
62        return $violations;
63    }
64}