Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MediaCriteria
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
11
100.00% covered (success)
100.00%
1 / 1
 toPdf
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
11
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Multimedia;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfBoolean;
9use Phpdftk\Pdf\Core\PdfDictionary;
10use Phpdftk\Pdf\Core\PdfName;
11use Phpdftk\Pdf\Core\PdfNumber;
12use Phpdftk\Pdf\Core\PdfObject;
13use Phpdftk\Pdf\Core\PdfString;
14use Phpdftk\Pdf\Core\PdfVersion;
15use Phpdftk\Pdf\Core\RequiresPdfVersion;
16
17/**
18 * Media criteria dictionary (/Type /MediaCriteria) —
19 * ISO 32000-2 §13.2.3.6.
20 *
21 * Inside a rendition's /MH (must-honor) or /BE (best-effort) dictionary
22 * to restrict when a rendition is allowed to play: audio support,
23 * closed caption presence, locale, bit depth, screen size, etc.
24 */
25#[RequiresPdfVersion(PdfVersion::V1_5)]
26class MediaCriteria extends PdfObject
27{
28    public const PDF_TYPE = 'MediaCriteria';
29
30    public ?bool $a = null;              // /A audio
31    public ?bool $c = null;              // /C captions
32    public ?bool $o = null;              // /O overdub
33    public ?bool $s = null;              // /S subtitles
34    public ?int $r = null;               // /R bit rate (kbps)
35    public ?PdfDictionary $d = null;     // /D min bit depth (MinBitDepth)
36    public ?PdfDictionary $z = null;     // /Z min screen size (MinScreenSize)
37    public ?PdfArray $v = null;          // /V version array
38    public ?PdfArray $p = null;          // /P permissions array
39    public ?PdfArray $l = null;          // /L languages array
40
41    public function toPdf(): string
42    {
43        $dict = new PdfDictionary();
44        $dict->set('Type', new PdfName(self::PDF_TYPE));
45        if ($this->a !== null) {
46            $dict->set('A', new PdfBoolean($this->a));
47        }
48        if ($this->c !== null) {
49            $dict->set('C', new PdfBoolean($this->c));
50        }
51        if ($this->o !== null) {
52            $dict->set('O', new PdfBoolean($this->o));
53        }
54        if ($this->s !== null) {
55            $dict->set('S', new PdfBoolean($this->s));
56        }
57        if ($this->r !== null) {
58            $dict->set('R', new PdfNumber($this->r));
59        }
60        if ($this->d !== null) {
61            $dict->set('D', $this->d);
62        }
63        if ($this->z !== null) {
64            $dict->set('Z', $this->z);
65        }
66        if ($this->v !== null) {
67            $dict->set('V', $this->v);
68        }
69        if ($this->p !== null) {
70            $dict->set('P', $this->p);
71        }
72        if ($this->l !== null) {
73            $dict->set('L', $this->l);
74        }
75        return $dict->toPdf();
76    }
77}