Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
82.35% covered (warning)
82.35%
14 / 17
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ThreeDStream
82.35% covered (warning)
82.35%
14 / 17
50.00% covered (danger)
50.00%
1 / 2
8.35
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
80.00% covered (warning)
80.00%
12 / 15
0.00% covered (danger)
0.00%
0 / 1
7.39
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\ThreeD;
6
7use Phpdftk\Pdf\Core\Graphics\ColorSpace\ColorSpace;
8use Phpdftk\Pdf\Core\PdfArray;
9use Phpdftk\Pdf\Core\PdfDictionary;
10use Phpdftk\Pdf\Core\PdfName;
11use Phpdftk\Pdf\Core\PdfStream;
12use Phpdftk\Pdf\Core\PdfString;
13use Phpdftk\Pdf\Core\PdfVersion;
14use Phpdftk\Pdf\Core\RequiresPdfVersion;
15
16/**
17 * 3D stream (/Type /3D) — ISO 32000-2 §13.6.3.
18 *
19 * Carries the 3D artwork (U3D or PRC bytes) referenced by a 3D annotation.
20 *
21 * Required: Subtype (U3D or PRC). Optional: VA (views), DV (default view),
22 * AN (animation style), ColorSpace, Resources.
23 */
24#[RequiresPdfVersion(PdfVersion::V1_6)]
25class ThreeDStream extends PdfStream
26{
27    public const PDF_TYPE = '3D';
28
29    public PdfName $subtype;                           // /Subtype
30    public ?PdfArray $va = null;                       // /VA views
31    public mixed $dv = null;                           // /DV default view
32    public ?PdfDictionary $an = null;                  // /AN animation
33    public ColorSpace|PdfName|PdfArray|null $colorSpace = null; // /ColorSpace
34    public ?PdfDictionary $resources = null;           // /Resources
35    public ?PdfString $oncInstantiate = null;          // /OnInstantiate — callback JS
36
37    public function __construct(string $subtype, string $bytes = '')
38    {
39        parent::__construct(new PdfDictionary(), $bytes);
40        $this->subtype = new PdfName($subtype);
41    }
42
43    public function toPdf(): string
44    {
45        $this->dictionary->set('Type', new PdfName(self::PDF_TYPE));
46        $this->dictionary->set('Subtype', $this->subtype);
47        if ($this->va !== null) {
48            $this->dictionary->set('VA', $this->va);
49        }
50        if ($this->dv !== null) {
51            $this->dictionary->set('DV', $this->dv);
52        }
53        if ($this->an !== null) {
54            $this->dictionary->set('AN', $this->an);
55        }
56        if ($this->colorSpace !== null) {
57            $this->dictionary->set('ColorSpace', $this->colorSpace);
58        }
59        if ($this->resources !== null) {
60            $this->dictionary->set('Resources', $this->resources);
61        }
62        if ($this->oncInstantiate !== null) {
63            $this->dictionary->set('OnInstantiate', $this->oncInstantiate);
64        }
65        return parent::toPdf();
66    }
67}