Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.74% covered (success)
94.74%
18 / 19
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TilingPattern
94.74% covered (success)
94.74%
18 / 19
66.67% covered (warning)
66.67%
2 / 3
4.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getPatternType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toPdf
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
2.00
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Core\Graphics\Pattern;
6
7use Phpdftk\Pdf\Core\Content\Resources;
8use Phpdftk\Pdf\Core\PdfArray;
9use Phpdftk\Pdf\Core\PdfDictionary;
10use Phpdftk\Pdf\Core\PdfName;
11use Phpdftk\Pdf\Core\PdfNumber;
12use Phpdftk\Pdf\Core\PdfStream;
13use Phpdftk\Pdf\Core\PdfVersion;
14use Phpdftk\Pdf\Core\RequiresPdfVersion;
15
16/**
17 * Tiling pattern (/Type /Pattern /PatternType 1) — ISO 32000-2 §8.7.3.
18 *
19 * A stream whose body is a PDF content stream painting one cell of the
20 * pattern. The cell is tiled across the target area using XStep/YStep.
21 *
22 * Required entries: PaintType, TilingType, BBox, XStep, YStep, Resources.
23 */
24#[RequiresPdfVersion(PdfVersion::V1_2)]
25class TilingPattern extends PdfStream
26{
27    public const PDF_TYPE = 'Pattern';
28    public const PATTERN_TYPE = 1;
29
30    public int $paintType;      // /PaintType  1 = colored, 2 = uncolored
31    public int $tilingType;     // /TilingType 1..3
32    public PdfArray $bbox;      // /BBox
33    public float $xStep;        // /XStep
34    public float $yStep;        // /YStep
35    public Resources|PdfDictionary $resources;   // /Resources
36    public ?PdfArray $matrix = null;             // /Matrix
37
38    public function __construct(
39        int $paintType,
40        int $tilingType,
41        PdfArray $bbox,
42        float $xStep,
43        float $yStep,
44        Resources|PdfDictionary $resources,
45        string $contentStream = '',
46    ) {
47        parent::__construct(new PdfDictionary(), $contentStream);
48        $this->paintType = $paintType;
49        $this->tilingType = $tilingType;
50        $this->bbox = $bbox;
51        $this->xStep = $xStep;
52        $this->yStep = $yStep;
53        $this->resources = $resources;
54    }
55
56    public function getPatternType(): int
57    {
58        return self::PATTERN_TYPE;
59    }
60
61    public function toPdf(): string
62    {
63        $this->dictionary->set('Type', new PdfName(self::PDF_TYPE));
64        $this->dictionary->set('PatternType', new PdfNumber(self::PATTERN_TYPE));
65        $this->dictionary->set('PaintType', new PdfNumber($this->paintType));
66        $this->dictionary->set('TilingType', new PdfNumber($this->tilingType));
67        $this->dictionary->set('BBox', $this->bbox);
68        $this->dictionary->set('XStep', new PdfNumber($this->xStep));
69        $this->dictionary->set('YStep', new PdfNumber($this->yStep));
70        $this->dictionary->set('Resources', $this->resources);
71        if ($this->matrix !== null) {
72            $this->dictionary->set('Matrix', $this->matrix);
73        }
74        return parent::toPdf();
75    }
76}