Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.01% |
67 / 77 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ExtGState | |
87.01% |
67 / 77 |
|
0.00% |
0 / 1 |
41.16 | |
0.00% |
0 / 1 |
| toPdf | |
87.01% |
67 / 77 |
|
0.00% |
0 / 1 |
41.16 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Graphics; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfArray; |
| 8 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 9 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 10 | use Phpdftk\Pdf\Core\PdfName; |
| 11 | use Phpdftk\Pdf\Core\PdfNumber; |
| 12 | use Phpdftk\Pdf\Core\PdfObject; |
| 13 | use Phpdftk\Pdf\Core\PdfVersion; |
| 14 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 15 | |
| 16 | /** |
| 17 | * External Graphics State parameter dictionary (/Type /ExtGState). |
| 18 | */ |
| 19 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 20 | class ExtGState extends PdfObject |
| 21 | { |
| 22 | public const PDF_TYPE = 'ExtGState'; |
| 23 | |
| 24 | public ?float $lw = null; // /LW - line width |
| 25 | public ?int $lc = null; // /LC - line cap style |
| 26 | public ?int $lj = null; // /LJ - line join style |
| 27 | public ?float $ml = null; // /ML - miter limit |
| 28 | public ?PdfArray $d = null; // /D - dash pattern |
| 29 | public ?PdfName $ri = null; // /RI - rendering intent |
| 30 | public ?bool $op = null; // /OP - overprint stroke |
| 31 | public ?bool $opLower = null; // /op - overprint fill |
| 32 | public ?int $opm = null; // /OPM - overprint mode |
| 33 | public ?PdfArray $font = null; // /Font |
| 34 | public ?float $fl = null; // /FL - flatness |
| 35 | public ?float $sm = null; // /SM - smoothness |
| 36 | public ?bool $sa = null; // /SA - stroke adjustment |
| 37 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 38 | public mixed $bm = null; // /BM - blend mode |
| 39 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 40 | public mixed $sMask = null; // /SMask - soft mask |
| 41 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 42 | public ?float $ca = null; // /CA - stroke alpha |
| 43 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 44 | public ?float $caLower = null; // /ca - fill alpha |
| 45 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 46 | public ?bool $ais = null; // /AIS - alpha is shape |
| 47 | #[RequiresPdfVersion(PdfVersion::V1_4)] |
| 48 | public ?bool $tk = null; // /TK - text knockout |
| 49 | public mixed $bg = null; // /BG - black generation function |
| 50 | public mixed $bg2 = null; // /BG2 - black generation (PDF 1.3+) |
| 51 | public mixed $ucr = null; // /UCR - undercolor removal |
| 52 | public mixed $ucr2 = null; // /UCR2 - undercolor removal (PDF 1.3+) |
| 53 | public mixed $tr = null; // /TR - transfer function |
| 54 | public mixed $tr2 = null; // /TR2 - transfer function (PDF 1.3+) |
| 55 | public mixed $ht = null; // /HT - halftone dict/stream or /Default |
| 56 | public ?PdfName $useBlackPtComp = null; // /UseBlackPtComp - black point compensation |
| 57 | public ?PdfArray $hto = null; // /HTO - halftone origin [x, y] |
| 58 | |
| 59 | public function toPdf(): string |
| 60 | { |
| 61 | $dict = new PdfDictionary(); |
| 62 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 63 | |
| 64 | if ($this->lw !== null) { |
| 65 | $dict->set('LW', new PdfNumber($this->lw)); |
| 66 | } |
| 67 | if ($this->lc !== null) { |
| 68 | $dict->set('LC', new PdfNumber($this->lc)); |
| 69 | } |
| 70 | if ($this->lj !== null) { |
| 71 | $dict->set('LJ', new PdfNumber($this->lj)); |
| 72 | } |
| 73 | if ($this->ml !== null) { |
| 74 | $dict->set('ML', new PdfNumber($this->ml)); |
| 75 | } |
| 76 | if ($this->d !== null) { |
| 77 | $dict->set('D', $this->d); |
| 78 | } |
| 79 | if ($this->ri !== null) { |
| 80 | $dict->set('RI', $this->ri); |
| 81 | } |
| 82 | if ($this->op !== null) { |
| 83 | $dict->set('OP', new PdfBoolean($this->op)); |
| 84 | } |
| 85 | if ($this->opLower !== null) { |
| 86 | $dict->set('op', new PdfBoolean($this->opLower)); |
| 87 | } |
| 88 | if ($this->opm !== null) { |
| 89 | $dict->set('OPM', new PdfNumber($this->opm)); |
| 90 | } |
| 91 | if ($this->font !== null) { |
| 92 | $dict->set('Font', $this->font); |
| 93 | } |
| 94 | if ($this->fl !== null) { |
| 95 | $dict->set('FL', new PdfNumber($this->fl)); |
| 96 | } |
| 97 | if ($this->sm !== null) { |
| 98 | $dict->set('SM', new PdfNumber($this->sm)); |
| 99 | } |
| 100 | if ($this->sa !== null) { |
| 101 | $dict->set('SA', new PdfBoolean($this->sa)); |
| 102 | } |
| 103 | if ($this->bm !== null) { |
| 104 | if ($this->bm instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 105 | $dict->set('BM', $this->bm); |
| 106 | } else { |
| 107 | $dict->set('BM', new PdfName((string) $this->bm)); |
| 108 | } |
| 109 | } |
| 110 | if ($this->sMask !== null) { |
| 111 | if ($this->sMask instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 112 | $dict->set('SMask', $this->sMask); |
| 113 | } else { |
| 114 | $dict->set('SMask', new PdfName((string) $this->sMask)); |
| 115 | } |
| 116 | } |
| 117 | if ($this->ca !== null) { |
| 118 | $dict->set('CA', new PdfNumber($this->ca)); |
| 119 | } |
| 120 | if ($this->caLower !== null) { |
| 121 | $dict->set('ca', new PdfNumber($this->caLower)); |
| 122 | } |
| 123 | if ($this->ais !== null) { |
| 124 | $dict->set('AIS', new PdfBoolean($this->ais)); |
| 125 | } |
| 126 | if ($this->tk !== null) { |
| 127 | $dict->set('TK', new PdfBoolean($this->tk)); |
| 128 | } |
| 129 | if ($this->bg !== null) { |
| 130 | if ($this->bg instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 131 | $dict->set('BG', $this->bg); |
| 132 | } else { |
| 133 | $dict->set('BG', new PdfName((string) $this->bg)); |
| 134 | } |
| 135 | } |
| 136 | if ($this->bg2 !== null) { |
| 137 | if ($this->bg2 instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 138 | $dict->set('BG2', $this->bg2); |
| 139 | } else { |
| 140 | $dict->set('BG2', new PdfName((string) $this->bg2)); |
| 141 | } |
| 142 | } |
| 143 | if ($this->ucr !== null) { |
| 144 | if ($this->ucr instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 145 | $dict->set('UCR', $this->ucr); |
| 146 | } else { |
| 147 | $dict->set('UCR', new PdfName((string) $this->ucr)); |
| 148 | } |
| 149 | } |
| 150 | if ($this->ucr2 !== null) { |
| 151 | if ($this->ucr2 instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 152 | $dict->set('UCR2', $this->ucr2); |
| 153 | } else { |
| 154 | $dict->set('UCR2', new PdfName((string) $this->ucr2)); |
| 155 | } |
| 156 | } |
| 157 | if ($this->tr !== null) { |
| 158 | if ($this->tr instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 159 | $dict->set('TR', $this->tr); |
| 160 | } else { |
| 161 | $dict->set('TR', new PdfName((string) $this->tr)); |
| 162 | } |
| 163 | } |
| 164 | if ($this->tr2 !== null) { |
| 165 | if ($this->tr2 instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 166 | $dict->set('TR2', $this->tr2); |
| 167 | } else { |
| 168 | $dict->set('TR2', new PdfName((string) $this->tr2)); |
| 169 | } |
| 170 | } |
| 171 | if ($this->ht !== null) { |
| 172 | if ($this->ht instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 173 | $dict->set('HT', $this->ht); |
| 174 | } else { |
| 175 | $dict->set('HT', new PdfName((string) $this->ht)); |
| 176 | } |
| 177 | } |
| 178 | if ($this->useBlackPtComp !== null) { |
| 179 | $dict->set('UseBlackPtComp', $this->useBlackPtComp); |
| 180 | } |
| 181 | if ($this->hto !== null) { |
| 182 | $dict->set('HTO', $this->hto); |
| 183 | } |
| 184 | |
| 185 | return $dict->toPdf(); |
| 186 | } |
| 187 | } |