Skip to content

Commit

Permalink
fix: disallow logo punchout background in SVG writer (not supported)
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Nov 14, 2024
1 parent bdbb06e commit b6d91aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Writer/SvgWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ private function writeBlockDefinitions(\SimpleXMLElement $xml, QrCodeInterface $
/** @param array<string, mixed> $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])) {
Expand Down
16 changes: 16 additions & 0 deletions tests/QrCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit b6d91aa

Please sign in to comment.