Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SoftMask
92.31% covered (success)
92.31%
12 / 13
50.00% covered (danger)
50.00%
1 / 2
5.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
4.01
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Graphics;
6
7use Phpdftk\Pdf\Core\PdfArray;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfReference;
11use Phpdftk\Pdf\Core\PdfVersion;
12use Phpdftk\Pdf\Core\RequiresPdfVersion;
13use Phpdftk\Pdf\Core\Serializable;
14
15/**
16 * Soft Mask dictionary (ISO 32000-2 Table 131).
17 */
18#[RequiresPdfVersion(PdfVersion::V1_4)]
19class SoftMask implements Serializable
20{
21    public PdfName $s;              // /S - required (Alpha or Luminosity)
22    public PdfReference $g;         // /G - required (transparency group XObject)
23    public ?PdfArray $bc = null;    // /BC - backdrop color
24    public mixed $tr = null;        // /TR - transfer function
25
26    public function __construct(string $subtype, PdfReference $group)
27    {
28        $this->s = new PdfName($subtype);
29        $this->g = $group;
30    }
31
32    public function toPdf(): string
33    {
34        $dict = new PdfDictionary();
35        $dict->set('Type', new PdfName('Mask'));
36        $dict->set('S', $this->s);
37        $dict->set('G', $this->g);
38
39        if ($this->bc !== null) {
40            $dict->set('BC', $this->bc);
41        }
42        if ($this->tr !== null) {
43            if ($this->tr instanceof Serializable) {
44                $dict->set('TR', $this->tr);
45            } else {
46                $dict->set('TR', new PdfName((string) $this->tr));
47            }
48        }
49
50        return $dict->toPdf();
51    }
52}