Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
86.67% |
13 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| FontEmbeddingConstraint | |
86.67% |
13 / 15 |
|
0.00% |
0 / 1 |
5.06 | |
0.00% |
0 / 1 |
| check | |
86.67% |
13 / 15 |
|
0.00% |
0 / 1 |
5.06 | |||
| 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 | use Phpdftk\Pdf\Core\Font\Font; |
| 12 | use Phpdftk\Pdf\Core\Font\Type0Font; |
| 13 | |
| 14 | /** |
| 15 | * PDF/A clause 6.3: All fonts must be embedded. |
| 16 | * |
| 17 | * Every font used in the document must have a FontDescriptor with a |
| 18 | * font program reference (/FontFile, /FontFile2, or /FontFile3). |
| 19 | * Type 0 composite fonts are checked via their descendant CID font. |
| 20 | */ |
| 21 | final class FontEmbeddingConstraint implements ConformanceConstraint |
| 22 | { |
| 23 | public function check(DocumentInspector $inspector, ConformanceProfile $profile): array |
| 24 | { |
| 25 | $violations = []; |
| 26 | |
| 27 | foreach ($inspector->getFonts() as $font) { |
| 28 | // Type0 fonts embed via their descendant — skip the wrapper |
| 29 | if ($font instanceof Type0Font) { |
| 30 | continue; |
| 31 | } |
| 32 | |
| 33 | if (!$font instanceof Font) { |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | $name = $font->baseFont?->value ?? 'unknown'; |
| 38 | |
| 39 | if ($font->fontDescriptor === null) { |
| 40 | $violations[] = new ConformanceViolation( |
| 41 | clause: '6.3.4', |
| 42 | message: "Font '{$name}' has no FontDescriptor — all fonts must be embedded", |
| 43 | severity: ViolationSeverity::Error, |
| 44 | objectPath: "Font[{$name}]", |
| 45 | ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return $violations; |
| 50 | } |
| 51 | } |