Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ThreeDView | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
28 / 28 |
|
100.00% |
1 / 1 |
13 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\ThreeD; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 9 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 10 | use Phpdftk\Pdf\Core\PdfName; |
| 11 | use Phpdftk\Pdf\Core\PdfNumber; |
| 12 | use Phpdftk\Pdf\Core\PdfObject; |
| 13 | use Phpdftk\Pdf\Core\PdfReference; |
| 14 | use Phpdftk\Pdf\Core\PdfString; |
| 15 | use Phpdftk\Pdf\Core\PdfVersion; |
| 16 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 17 | |
| 18 | /** |
| 19 | * 3D view dictionary (/Type /3DView) — ISO 32000-2 §13.6.4. |
| 20 | * |
| 21 | * Describes a named camera view of a 3D model. |
| 22 | */ |
| 23 | #[RequiresPdfVersion(PdfVersion::V1_6)] |
| 24 | class ThreeDView extends PdfObject |
| 25 | { |
| 26 | public const PDF_TYPE = '3DView'; |
| 27 | |
| 28 | public PdfString $xn; // /XN external name (required) |
| 29 | public ?PdfString $in = null; // /IN internal name |
| 30 | public ?PdfName $ms = null; // /MS matrix source (M, U3D) |
| 31 | public ?PdfArray $c2w = null; // /C2W camera-to-world matrix |
| 32 | public ?float $co = null; // /CO center-of-orbit distance |
| 33 | public ?PdfDictionary $p = null; // /P projection dict |
| 34 | public ?PdfArray $o = null; // /O overlay array |
| 35 | public ThreeDBackground|PdfReference|null $bg = null; // /BG background |
| 36 | public ThreeDRenderMode|PdfReference|null $rm = null; // /RM render mode |
| 37 | public ThreeDLightingScheme|PdfReference|null $ls = null; // /LS lighting |
| 38 | public ?PdfArray $sa = null; // /SA cross sections |
| 39 | public ?PdfArray $na = null; // /NA node overrides |
| 40 | public ?bool $nr = null; // /NR render rail |
| 41 | |
| 42 | public function __construct(string $externalName) |
| 43 | { |
| 44 | $this->xn = new PdfString($externalName); |
| 45 | } |
| 46 | |
| 47 | public function toPdf(): string |
| 48 | { |
| 49 | $dict = new PdfDictionary(); |
| 50 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 51 | $dict->set('XN', $this->xn); |
| 52 | if ($this->in !== null) { |
| 53 | $dict->set('IN', $this->in); |
| 54 | } |
| 55 | if ($this->ms !== null) { |
| 56 | $dict->set('MS', $this->ms); |
| 57 | } |
| 58 | if ($this->c2w !== null) { |
| 59 | $dict->set('C2W', $this->c2w); |
| 60 | } |
| 61 | if ($this->co !== null) { |
| 62 | $dict->set('CO', new PdfNumber($this->co)); |
| 63 | } |
| 64 | if ($this->p !== null) { |
| 65 | $dict->set('P', $this->p); |
| 66 | } |
| 67 | if ($this->o !== null) { |
| 68 | $dict->set('O', $this->o); |
| 69 | } |
| 70 | if ($this->bg !== null) { |
| 71 | $dict->set('BG', $this->bg); |
| 72 | } |
| 73 | if ($this->rm !== null) { |
| 74 | $dict->set('RM', $this->rm); |
| 75 | } |
| 76 | if ($this->ls !== null) { |
| 77 | $dict->set('LS', $this->ls); |
| 78 | } |
| 79 | if ($this->sa !== null) { |
| 80 | $dict->set('SA', $this->sa); |
| 81 | } |
| 82 | if ($this->na !== null) { |
| 83 | $dict->set('NA', $this->na); |
| 84 | } |
| 85 | if ($this->nr !== null) { |
| 86 | $dict->set('NR', new PdfBoolean($this->nr)); |
| 87 | } |
| 88 | return $dict->toPdf(); |
| 89 | } |
| 90 | } |