Skip to content

Commit 1249a2b

Browse files
jakejackson1claude
andcommitted
Check that a form drawn as a background finds the colour spaces it sets in its own resources
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 0ba18da commit 1249a2b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎tests/Mpdf/PdfX4Test.php‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,33 @@ public function testEachPageAndFormStartsInTheIccBasedGreyColourSpace()
16111611
$this->assertSame(1, preg_match('/\/XObject <<\/FO\d+ \d+ 0 R >>\n\/ColorSpace <<\/CSGRAY \d+ 0 R >>/', $pdf), 'the background pattern\'s resources');
16121612
}
16131613

1614+
/**
1615+
* Printing to CMYK, an SVG drawn as a background sets its RGB in the ICC-based sRGB colour space and
1616+
* its spot colour by name. The form names the resources the pages share, and they name both; the
1617+
* pattern's own content draws the form and nothing else.
1618+
*/
1619+
public function testAFormDrawnAsABackgroundFindsTheColourSpacesItSetsInItsResources()
1620+
{
1621+
$svg = 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" width="40" height="20"><rect width="20" height="20" fill="#ff0000"/><rect x="20" width="20" height="20" fill="spot(PANTONE 300 C, 50%)"/></svg>');
1622+
1623+
$pdf = $this->pdf(['PDFX' => true], '<div style="background: url(' . $svg . '); height: 20mm"></div>', function (Mpdf $mpdf) {
1624+
$mpdf->AddSpotColor('PANTONE 300 C', 100, 44, 0, 0);
1625+
});
1626+
1627+
$this->assertSame(1, preg_match('/(\d+) 0 obj\n<<\/Type \/XObject\n\/Subtype \/Form\n.*?\/Resources (\d+) 0 R\n/s', $pdf, $form));
1628+
$content = $this->stream($pdf, $form[1]);
1629+
$this->assertStringContainsString('/CSRGB cs 1.000 0.000 0.000 sc', $content);
1630+
$this->assertStringContainsString('/CS1 cs 0.500 scn', $content);
1631+
1632+
$this->assertSame(1, preg_match('/\/ColorSpace <<\n(.*?)>>/s', $this->object($pdf, $form[2]), $spaces));
1633+
$this->assertSame(1, preg_match('/^\/CSRGB (\d+) 0 R$/m', $spaces[1], $rgb), 'the ICC-based sRGB colour space');
1634+
$this->assertStringStartsWith('[/ICCBased ', $this->object($pdf, $rgb[1]));
1635+
$this->assertSame(1, preg_match('/^\/CS1 \d+ 0 R$/m', $spaces[1]), 'the spot colour');
1636+
1637+
$this->assertSame(1, preg_match('/\/PatternType 1 .*?stream\n(.*?)\nendstream/s', $pdf, $pattern));
1638+
$this->assertSame(1, preg_match('/^q [\d. -]+ cm \/FO\d+ Do Q$/', $pattern[1]), 'the pattern draws the form alone');
1639+
}
1640+
16141641
/**
16151642
* Grey in the ICC-based colour space draws as it did in DeviceGray, pixel for pixel
16161643
*/

0 commit comments

Comments
 (0)