Skip to content

Commit 9cb9629

Browse files
committed
Add output method for PDF XOBjects
1 parent 289dd40 commit 9cb9629

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.9
1+
2.1.0

src/Spot.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,34 @@ public function getPdfSpotResources(): string
285285
return '';
286286
}
287287

288-
$out = '/ColorSpace << ';
288+
$out = '/ColorSpace <<';
289+
289290
foreach ($this->spot_colors as $spot_color) {
290-
$out .= '/CS' . $spot_color['i'] . ' ' . $spot_color['n'] . ' 0 R ';
291+
$out .= ' /CS' . $spot_color['i'] . ' ' . $spot_color['n'] . ' 0 R';
292+
}
293+
294+
return $out . ' >>' . "\n";
295+
}
296+
297+
/**
298+
* Returns the PDF command to output Spot color resources.
299+
*
300+
* @param array<string> $keys Array of font keys.
301+
*
302+
* @return string PDF command
303+
*/
304+
public function getPdfSpotResourcesByKeys(array $keys): string
305+
{
306+
if (empty($keys)) {
307+
return '';
308+
}
309+
310+
$out = '/ColorSpace <<';
311+
312+
foreach ($keys as $key) {
313+
$out .= ' /CS' . $this->spot_colors[$key]['i'] . ' ' . $this->spot_colors[$key]['n'] . ' 0 R';
291314
}
292315

293-
return $out . ('>>' . "\n");
316+
return $out . ' >>' . "\n";
294317
}
295318
}

test/SpotTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ public function testGetPdfSpotObjects(): void
170170

171171
$res = $spot->getPdfSpotResources();
172172
$this->assertEquals('/ColorSpace << /CS1 2 0 R /CS2 3 0 R /CS3 4 0 R /CS4 5 0 R /CS5 6 0 R >>' . "\n", $res);
173+
174+
$resk = $spot->getPdfSpotResourcesByKeys(['cyan','yellow']);
175+
$this->assertEquals('/ColorSpace << /CS2 3 0 R /CS4 5 0 R >>' . "\n", $resk);
173176
}
174177
}

0 commit comments

Comments
 (0)