Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| StructAttribute | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Document; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfVersion; |
| 10 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 11 | use Phpdftk\Pdf\Core\Serializable; |
| 12 | |
| 13 | /** |
| 14 | * Structure attribute object — ISO 32000-2 §14.7.5. |
| 15 | * |
| 16 | * Attribute objects carry layout, list, table, print-field, etc. properties |
| 17 | * attached to structure elements via /A. The /O entry names the owning |
| 18 | * attribute class (e.g. Layout, List, Table). |
| 19 | * |
| 20 | * Example: |
| 21 | * $attr = new StructAttribute('Layout'); |
| 22 | * $attr->entries['Placement'] = new PdfName('Block'); |
| 23 | */ |
| 24 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 25 | class StructAttribute implements Serializable |
| 26 | { |
| 27 | public PdfName $o; // /O - owner (required) |
| 28 | |
| 29 | /** @var array<string, mixed> Additional attribute entries. */ |
| 30 | public array $entries = []; |
| 31 | |
| 32 | public function __construct(string $owner) |
| 33 | { |
| 34 | $this->o = new PdfName($owner); |
| 35 | } |
| 36 | |
| 37 | public function toPdf(): string |
| 38 | { |
| 39 | $dict = new PdfDictionary(); |
| 40 | $dict->set('O', $this->o); |
| 41 | foreach ($this->entries as $key => $value) { |
| 42 | $dict->set($key, $value); |
| 43 | } |
| 44 | return $dict->toPdf(); |
| 45 | } |
| 46 | } |