Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ThreeDMeasure
84.62% covered (warning)
84.62%
11 / 13
50.00% covered (danger)
50.00%
1 / 2
6.13
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
83.33% covered (warning)
83.33%
10 / 12
0.00% covered (danger)
0.00%
0 / 1
5.12
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\ThreeD;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfObject;
11use Phpdftk\Pdf\Core\PdfReference;
12use Phpdftk\Pdf\Core\PdfString;
13use Phpdftk\Pdf\Core\PdfVersion;
14use Phpdftk\Pdf\Core\RequiresPdfVersion;
15
16/**
17 * 3D measurement dictionary (/Type /3DMeasure) —
18 * ISO 32000-2 §13.6.4.6.
19 *
20 * Describes a linear, radial, angular, perpendicular, or
21 * point-coordinate measurement annotation inside a 3D view. The
22 * /Subtype selects one of six flavors: 3DC (basic), LD (linear),
23 * PD3 (perpendicular), RD3 (radial), AD3 (angular), 3DM (point).
24 *
25 * Represented here as a single class with `$subtype`; callers choose
26 * the subtype and populate the fields appropriate to it.
27 */
28#[RequiresPdfVersion(PdfVersion::V1_6)]
29class ThreeDMeasure extends PdfObject
30{
31    public const PDF_TYPE = '3DMeasure';
32
33    public PdfName $subtype;                       // /Subtype
34    public ?PdfArray $anchors = null;              // /A - anchors
35    public ?PdfReference $target = null;           // /TRL
36    public ?PdfString $text = null;                // /V - value string
37    public ?PdfDictionary $textProperties = null;  // /TP
38
39    public function __construct(string $subtype)
40    {
41        $this->subtype = new PdfName($subtype);
42    }
43
44    public function toPdf(): string
45    {
46        $dict = new PdfDictionary();
47        $dict->set('Type', new PdfName(self::PDF_TYPE));
48        $dict->set('Subtype', $this->subtype);
49        if ($this->anchors !== null) {
50            $dict->set('A', $this->anchors);
51        }
52        if ($this->target !== null) {
53            $dict->set('TRL', $this->target);
54        }
55        if ($this->text !== null) {
56            $dict->set('V', $this->text);
57        }
58        if ($this->textProperties !== null) {
59            $dict->set('TP', $this->textProperties);
60        }
61        return $dict->toPdf();
62    }
63}