Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SoftMask | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
5.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
4.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Graphics; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfReference; |
| 11 | use Phpdftk\Pdf\Core\PdfVersion; |
| 12 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 13 | use Phpdftk\Pdf\Core\Serializable; |
| 14 | |
| 15 | /** |
| 16 | * Soft Mask dictionary (ISO 32000-2 Table 131). |
| 17 | */ |
| 18 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 19 | class 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 | } |