Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CMapStream
90.91% covered (success)
90.91%
10 / 11
50.00% covered (danger)
50.00%
1 / 2
6.03
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
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
5.03
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Font;
6
7use Phpdftk\Pdf\Core\PdfDictionary;
8use Phpdftk\Pdf\Core\PdfName;
9use Phpdftk\Pdf\Core\PdfNumber;
10use Phpdftk\Pdf\Core\PdfReference;
11use Phpdftk\Pdf\Core\PdfStream;
12use Phpdftk\Pdf\Core\PdfVersion;
13use Phpdftk\Pdf\Core\RequiresPdfVersion;
14
15/**
16 * CMap stream (/Type /CMap) — ISO 32000-2 §9.7.5.4.
17 *
18 * Maps character codes (bytes or multi-byte sequences) to CIDs for a
19 * CIDFont, or (in ToUnicode form) to Unicode code points. The stream
20 * body holds the CMap program text.
21 */
22#[RequiresPdfVersion(PdfVersion::V1_4)]
23class CMapStream extends PdfStream
24{
25    public const PDF_TYPE = 'CMap';
26
27    public ?PdfName $cMapName = null;                       // /CMapName
28    public ?CIDSystemInfo $cidSystemInfo = null;            // /CIDSystemInfo
29    public ?int $wMode = null;                              // /WMode 0=horizontal 1=vertical
30    public PdfName|PdfReference|null $useCMap = null;       // /UseCMap
31
32    public function __construct(string $cMapProgram = '')
33    {
34        parent::__construct(new PdfDictionary(), $cMapProgram);
35    }
36
37    public function toPdf(): string
38    {
39        $this->dictionary->set('Type', new PdfName(self::PDF_TYPE));
40        if ($this->cMapName !== null) {
41            $this->dictionary->set('CMapName', $this->cMapName);
42        }
43        if ($this->cidSystemInfo !== null) {
44            $this->dictionary->set('CIDSystemInfo', $this->cidSystemInfo);
45        }
46        if ($this->wMode !== null) {
47            $this->dictionary->set('WMode', new PdfNumber($this->wMode));
48        }
49        if ($this->useCMap !== null) {
50            $this->dictionary->set('UseCMap', $this->useCMap);
51        }
52        return parent::toPdf();
53    }
54}