Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
GroupAttributes
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Document;
6
7use Phpdftk\Pdf\Core\PdfBoolean;
8use Phpdftk\Pdf\Core\PdfDictionary;
9use Phpdftk\Pdf\Core\PdfName;
10use Phpdftk\Pdf\Core\PdfVersion;
11use Phpdftk\Pdf\Core\RequiresPdfVersion;
12use Phpdftk\Pdf\Core\Serializable;
13
14/**
15 * Transparency group attributes dictionary (ISO 32000-2).
16 *
17 * Implements Serializable for inline use within Page or FormXObject.
18 */
19#[RequiresPdfVersion(PdfVersion::V1_4)]
20class GroupAttributes implements Serializable
21{
22    public PdfName $s;                   // /S - subtype (always /Transparency for transparency groups)
23    public ?PdfName $cs = null;          // /CS - color space name
24    public ?PdfBoolean $i = null;        // /I - isolated
25    public ?PdfBoolean $k = null;        // /K - knockout
26
27    public function __construct(string $subtype = 'Transparency')
28    {
29        $this->s = new PdfName($subtype);
30    }
31
32    public function toPdf(): string
33    {
34        $dict = new PdfDictionary();
35        $dict->set('Type', new PdfName('Group'));
36        $dict->set('S', $this->s);
37
38        if ($this->cs !== null) {
39            $dict->set('CS', $this->cs);
40        }
41        if ($this->i !== null) {
42            $dict->set('I', $this->i);
43        }
44        if ($this->k !== null) {
45            $dict->set('K', $this->k);
46        }
47
48        return $dict->toPdf();
49    }
50}