From b6d91aaf63209e48541a40f3f103de0f67e8115b Mon Sep 17 00:00:00 2001 From: Jeroen van den Enden Date: Thu, 14 Nov 2024 10:31:37 +0000 Subject: [PATCH] fix: disallow logo punchout background in SVG writer (not supported) --- src/Writer/SvgWriter.php | 4 ++++ tests/QrCodeTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Writer/SvgWriter.php b/src/Writer/SvgWriter.php index 11dd42c..9001279 100644 --- a/src/Writer/SvgWriter.php +++ b/src/Writer/SvgWriter.php @@ -132,6 +132,10 @@ private function writeBlockDefinitions(\SimpleXMLElement $xml, QrCodeInterface $ /** @param array $options */ private function addLogo(LogoInterface $logo, SvgResult $result, array $options): void { + if ($logo->getPunchoutBackground()) { + throw new \Exception('The SVG writer does not support logo punchout background'); + } + $logoImageData = LogoImageData::createForLogo($logo); if (!isset($options[self::WRITER_OPTION_FORCE_XLINK_HREF])) { diff --git a/tests/QrCodeTest.php b/tests/QrCodeTest.php index b708a7a..e3171b7 100644 --- a/tests/QrCodeTest.php +++ b/tests/QrCodeTest.php @@ -233,4 +233,20 @@ public function testSvgCompactOption(): void $result = $svgWriter->write(qrCode: $qrCode, options: [SvgWriter::WRITER_OPTION_COMPACT => false]); $this->assertInstanceOf(SvgResult::class, $result); } + + #[TestDox('Logo punchout background is only available for GD writers')] + public function testLogoPunchoutBackgroundAvailability(): void + { + $qrCode = new QrCode('QR Code'); + $logo = new Logo( + path: __DIR__.'/assets/symfony.svg', + resizeToWidth: 100, + resizeToHeight: 50, + punchoutBackground: true + ); + + $svgWriter = new SvgWriter(); + $this->expectExceptionMessageMatches('#The SVG writer does not support logo punchout background#'); + $svgWriter->write($qrCode, $logo); + } }