Skip to content

Commit b6d91aa

Browse files
committed
fix: disallow logo punchout background in SVG writer (not supported)
1 parent bdbb06e commit b6d91aa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Writer/SvgWriter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ private function writeBlockDefinitions(\SimpleXMLElement $xml, QrCodeInterface $
132132
/** @param array<string, mixed> $options */
133133
private function addLogo(LogoInterface $logo, SvgResult $result, array $options): void
134134
{
135+
if ($logo->getPunchoutBackground()) {
136+
throw new \Exception('The SVG writer does not support logo punchout background');
137+
}
138+
135139
$logoImageData = LogoImageData::createForLogo($logo);
136140

137141
if (!isset($options[self::WRITER_OPTION_FORCE_XLINK_HREF])) {

tests/QrCodeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,20 @@ public function testSvgCompactOption(): void
233233
$result = $svgWriter->write(qrCode: $qrCode, options: [SvgWriter::WRITER_OPTION_COMPACT => false]);
234234
$this->assertInstanceOf(SvgResult::class, $result);
235235
}
236+
237+
#[TestDox('Logo punchout background is only available for GD writers')]
238+
public function testLogoPunchoutBackgroundAvailability(): void
239+
{
240+
$qrCode = new QrCode('QR Code');
241+
$logo = new Logo(
242+
path: __DIR__.'/assets/symfony.svg',
243+
resizeToWidth: 100,
244+
resizeToHeight: 50,
245+
punchoutBackground: true
246+
);
247+
248+
$svgWriter = new SvgWriter();
249+
$this->expectExceptionMessageMatches('#The SVG writer does not support logo punchout background#');
250+
$svgWriter->write($qrCode, $logo);
251+
}
236252
}

0 commit comments

Comments
 (0)