Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MeshShading | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getShadingType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| populateCommon | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Graphics\Shading; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\Graphics\ColorSpace\ColorSpace; |
| 8 | use Phpdftk\Pdf\Core\PdfArray; |
| 9 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 10 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 11 | use Phpdftk\Pdf\Core\PdfName; |
| 12 | use Phpdftk\Pdf\Core\PdfNumber; |
| 13 | use Phpdftk\Pdf\Core\PdfReference; |
| 14 | use Phpdftk\Pdf\Core\PdfStream; |
| 15 | |
| 16 | /** |
| 17 | * Abstract base for stream-based shading types 4–7. |
| 18 | * |
| 19 | * All mesh-based shadings share: BitsPerCoordinate, BitsPerComponent, |
| 20 | * BitsPerFlag (types 4, 6, 7 only), Decode, Function (optional). |
| 21 | * Subclasses contribute their own required entries. |
| 22 | */ |
| 23 | abstract class MeshShading extends PdfStream |
| 24 | { |
| 25 | public ColorSpace|PdfName|PdfArray $colorSpace; |
| 26 | public ?PdfArray $background = null; |
| 27 | public ?PdfArray $bbox = null; |
| 28 | public ?bool $antiAlias = null; |
| 29 | |
| 30 | public int $bitsPerCoordinate; |
| 31 | public int $bitsPerComponent; |
| 32 | public PdfArray $decode; |
| 33 | public PdfReference|PdfArray|null $function = null; |
| 34 | |
| 35 | public function __construct( |
| 36 | ColorSpace|PdfName|PdfArray $colorSpace, |
| 37 | int $bitsPerCoordinate, |
| 38 | int $bitsPerComponent, |
| 39 | PdfArray $decode, |
| 40 | string $meshData = '', |
| 41 | ) { |
| 42 | parent::__construct(new PdfDictionary(), $meshData); |
| 43 | $this->colorSpace = $colorSpace; |
| 44 | $this->bitsPerCoordinate = $bitsPerCoordinate; |
| 45 | $this->bitsPerComponent = $bitsPerComponent; |
| 46 | $this->decode = $decode; |
| 47 | } |
| 48 | |
| 49 | abstract public function getShadingType(): int; |
| 50 | |
| 51 | protected function populateCommon(): void |
| 52 | { |
| 53 | $this->dictionary->set('ShadingType', new PdfNumber($this->getShadingType())); |
| 54 | $this->dictionary->set('ColorSpace', $this->colorSpace); |
| 55 | if ($this->background !== null) { |
| 56 | $this->dictionary->set('Background', $this->background); |
| 57 | } |
| 58 | if ($this->bbox !== null) { |
| 59 | $this->dictionary->set('BBox', $this->bbox); |
| 60 | } |
| 61 | if ($this->antiAlias !== null) { |
| 62 | $this->dictionary->set('AntiAlias', new PdfBoolean($this->antiAlias)); |
| 63 | } |
| 64 | $this->dictionary->set('BitsPerCoordinate', new PdfNumber($this->bitsPerCoordinate)); |
| 65 | $this->dictionary->set('BitsPerComponent', new PdfNumber($this->bitsPerComponent)); |
| 66 | $this->dictionary->set('Decode', $this->decode); |
| 67 | if ($this->function !== null) { |
| 68 | $this->dictionary->set('Function', $this->function); |
| 69 | } |
| 70 | } |
| 71 | } |