Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Shading
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 getShadingType
n/a
0 / 0
n/a
0 / 0
0
 baseDictionary
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\Graphics\Shading;
6
7use Phpdftk\Pdf\Core\Graphics\ColorSpace\ColorSpace;
8use Phpdftk\Pdf\Core\PdfArray;
9use Phpdftk\Pdf\Core\PdfBoolean;
10use Phpdftk\Pdf\Core\PdfDictionary;
11use Phpdftk\Pdf\Core\PdfName;
12use Phpdftk\Pdf\Core\PdfNumber;
13use Phpdftk\Pdf\Core\PdfObject;
14use Phpdftk\Pdf\Core\PdfVersion;
15use Phpdftk\Pdf\Core\RequiresPdfVersion;
16
17/**
18 * Abstract base for PDF shading dictionaries โ€” ISO 32000-2 ยง8.7.4.
19 *
20 * Common entries: ShadingType, ColorSpace, Background, BBox, AntiAlias.
21 * Shading types 1โ€“3 are dictionaries and extend this class directly.
22 * Types 4โ€“7 must be streams (see ShadingType4..7).
23 */
24#[RequiresPdfVersion(PdfVersion::V1_3)]
25abstract class Shading extends PdfObject
26{
27    public ColorSpace|PdfName|PdfArray $colorSpace;
28    public ?PdfArray $background = null;     // /Background
29    public ?PdfArray $bbox = null;           // /BBox
30    public ?bool $antiAlias = null;          // /AntiAlias
31
32    abstract public function getShadingType(): int;
33
34    protected function baseDictionary(): PdfDictionary
35    {
36        $dict = new PdfDictionary();
37        $dict->set('ShadingType', new PdfNumber($this->getShadingType()));
38        $dict->set('ColorSpace', $this->colorSpace);
39        if ($this->background !== null) {
40            $dict->set('Background', $this->background);
41        }
42        if ($this->bbox !== null) {
43            $dict->set('BBox', $this->bbox);
44        }
45        if ($this->antiAlias !== null) {
46            $dict->set('AntiAlias', new PdfBoolean($this->antiAlias));
47        }
48        return $dict;
49    }
50}