Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
DisplayDocTitleConstraint
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
18 / 18
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\Document\ViewerPreferences;
12
13/**
14 * PDF/UA-1 clause 7.18.1: ViewerPreferences /DisplayDocTitle must be true.
15 *
16 * The document title (from /Info /Title or XMP dc:title) must be
17 * displayed in the viewer title bar rather than the filename.
18 */
19final class DisplayDocTitleConstraint implements ConformanceConstraint
20{
21    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
22    {
23        // Check registered objects for a ViewerPreferences with displayDocTitle
24        $found = false;
25        foreach ($inspector->getRegisteredObjects() as $object) {
26            if ($object instanceof ViewerPreferences) {
27                if ($object->displayDocTitle === true) {
28                    return [];
29                }
30                $found = true;
31            }
32        }
33
34        // Also check if Catalog has viewerPreferences as inline dict
35        $catalog = $inspector->getCatalog();
36        if ($catalog->viewerPreferences !== null && !$found) {
37            // Inline PdfDictionary — check for DisplayDocTitle key
38            if ($catalog->viewerPreferences->has('DisplayDocTitle')) {
39                $val = $catalog->viewerPreferences->get('DisplayDocTitle');
40                if ($val instanceof \Phpdftk\Pdf\Core\PdfBoolean && $val->value === true) {
41                    return [];
42                }
43            }
44        }
45
46        return [new ConformanceViolation(
47            clause: '7.18.1',
48            message: 'ViewerPreferences /DisplayDocTitle must be true — the document title must appear in the viewer title bar',
49            severity: ViolationSeverity::Error,
50            objectPath: 'Catalog.ViewerPreferences.DisplayDocTitle',
51        )];
52    }
53}