Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ShadingPattern | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
5.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPatternType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Graphics\Pattern; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfNumber; |
| 11 | use Phpdftk\Pdf\Core\PdfObject; |
| 12 | use Phpdftk\Pdf\Core\PdfReference; |
| 13 | use Phpdftk\Pdf\Core\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * Shading pattern (/Type /Pattern /PatternType 2) — ISO 32000-2 §8.7.3.4. |
| 18 | * |
| 19 | * Paints a shading (axial, radial, mesh, etc.) as if it were a color. |
| 20 | * Required entries: Shading. Optional: Matrix, ExtGState. |
| 21 | */ |
| 22 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 23 | class ShadingPattern extends PdfObject |
| 24 | { |
| 25 | public const PDF_TYPE = 'Pattern'; |
| 26 | public const PATTERN_TYPE = 2; |
| 27 | |
| 28 | public PdfReference|PdfDictionary $shading; // /Shading |
| 29 | public ?PdfArray $matrix = null; // /Matrix |
| 30 | public ?PdfReference $extGState = null; // /ExtGState |
| 31 | |
| 32 | public function __construct(PdfReference|PdfDictionary $shading) |
| 33 | { |
| 34 | $this->shading = $shading; |
| 35 | } |
| 36 | |
| 37 | public function getPatternType(): int |
| 38 | { |
| 39 | return self::PATTERN_TYPE; |
| 40 | } |
| 41 | |
| 42 | public function toPdf(): string |
| 43 | { |
| 44 | $dict = new PdfDictionary(); |
| 45 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 46 | $dict->set('PatternType', new PdfNumber(self::PATTERN_TYPE)); |
| 47 | $dict->set('Shading', $this->shading); |
| 48 | if ($this->matrix !== null) { |
| 49 | $dict->set('Matrix', $this->matrix); |
| 50 | } |
| 51 | if ($this->extGState !== null) { |
| 52 | $dict->set('ExtGState', $this->extGState); |
| 53 | } |
| 54 | return $dict->toPdf(); |
| 55 | } |
| 56 | } |