Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Rendition
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
4.13
0.00% covered (danger)
0.00%
0 / 1
 getRenditionSubtype
n/a
0 / 0
n/a
0 / 0
0
 baseDictionary
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
4.13
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Multimedia;
6
7use Phpdftk\Pdf\Core\PdfDictionary;
8use Phpdftk\Pdf\Core\PdfName;
9use Phpdftk\Pdf\Core\PdfObject;
10use Phpdftk\Pdf\Core\PdfString;
11use Phpdftk\Pdf\Core\PdfVersion;
12use Phpdftk\Pdf\Core\RequiresPdfVersion;
13
14/**
15 * Rendition (/Type /Rendition) — ISO 32000-2 §13.2.3.
16 *
17 * Abstract base for Media renditions (MR) and Selector renditions (SR).
18 * Common entries: Type, S (subtype), N (name), MH (media-handler), BE.
19 */
20#[RequiresPdfVersion(PdfVersion::V1_5)]
21abstract class Rendition extends PdfObject
22{
23    public const PDF_TYPE = 'Rendition';
24
25    public ?PdfString $n = null;              // /N   name
26    public ?PdfDictionary $mh = null;         // /MH  "must-honor" criteria
27    public ?PdfDictionary $be = null;         // /BE  "best-effort" criteria
28
29    /** Returns the /S (subtype) value, e.g. "MR" or "SR". */
30    abstract public function getRenditionSubtype(): string;
31
32    protected function baseDictionary(): PdfDictionary
33    {
34        $dict = new PdfDictionary();
35        $dict->set('Type', new PdfName(self::PDF_TYPE));
36        $dict->set('S', new PdfName($this->getRenditionSubtype()));
37        if ($this->n !== null) {
38            $dict->set('N', $this->n);
39        }
40        if ($this->mh !== null) {
41            $dict->set('MH', $this->mh);
42        }
43        if ($this->be !== null) {
44            $dict->set('BE', $this->be);
45        }
46        return $dict;
47    }
48}