Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OCG | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
4.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| 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\PdfObject; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * PDF Optional Content Group (ISO 32000-2 Table 96). |
| 15 | * |
| 16 | * Represents a layer in the PDF document that can be shown or hidden. |
| 17 | * |
| 18 | * Example: |
| 19 | * $ocg = new OCG('Watermark'); |
| 20 | * $writer->register($ocg); |
| 21 | */ |
| 22 | #[RequiresPdfVersion(PdfVersion::V1_5)] |
| 23 | class OCG extends PdfObject |
| 24 | { |
| 25 | public const PDF_TYPE = 'OCG'; |
| 26 | |
| 27 | public PdfName $name; // /Name - required |
| 28 | public ?PdfName $intent = null; // /Intent |
| 29 | public ?PdfDictionary $usage = null; // /Usage |
| 30 | |
| 31 | public function __construct(string $name) |
| 32 | { |
| 33 | $this->name = new PdfName($name); |
| 34 | } |
| 35 | |
| 36 | public function toPdf(): string |
| 37 | { |
| 38 | $dict = new PdfDictionary(); |
| 39 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 40 | $dict->set('Name', $this->name); |
| 41 | |
| 42 | if ($this->intent !== null) { |
| 43 | $dict->set('Intent', $this->intent); |
| 44 | } |
| 45 | if ($this->usage !== null) { |
| 46 | $dict->set('Usage', $this->usage); |
| 47 | } |
| 48 | |
| 49 | return $dict->toPdf(); |
| 50 | } |
| 51 | } |