diff --git a/src/Writer/SvgWriter.php b/src/Writer/SvgWriter.php index 02481b4..88665af 100644 --- a/src/Writer/SvgWriter.php +++ b/src/Writer/SvgWriter.php @@ -14,6 +14,7 @@ final class SvgWriter implements WriterInterface { + public const DECIMAL_PRECISION = 10; public const WRITER_OPTION_BLOCK_ID = 'block_id'; public const WRITER_OPTION_EXCLUDE_XML_DECLARATION = 'exclude_xml_declaration'; public const WRITER_OPTION_FORCE_XLINK_HREF = 'force_xlink_href'; @@ -40,8 +41,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label $blockDefinition = $xml->defs->addChild('rect'); $blockDefinition->addAttribute('id', $options[self::WRITER_OPTION_BLOCK_ID]); - $blockDefinition->addAttribute('width', strval($matrix->getBlockSize())); - $blockDefinition->addAttribute('height', strval($matrix->getBlockSize())); + $blockDefinition->addAttribute('width', number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION, '.', '')); + $blockDefinition->addAttribute('height', number_format($matrix->getBlockSize(), self::DECIMAL_PRECISION, '.', '')); $blockDefinition->addAttribute('fill', '#'.sprintf('%02x%02x%02x', $qrCode->getForegroundColor()->getRed(), $qrCode->getForegroundColor()->getGreen(), $qrCode->getForegroundColor()->getBlue())); $blockDefinition->addAttribute('fill-opacity', strval($qrCode->getForegroundColor()->getOpacity())); @@ -57,8 +58,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) { if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) { $block = $xml->addChild('use'); - $block->addAttribute('x', strval($matrix->getMarginLeft() + $matrix->getBlockSize() * $columnIndex)); - $block->addAttribute('y', strval($matrix->getMarginLeft() + $matrix->getBlockSize() * $rowIndex)); + $block->addAttribute('x', number_format($matrix->getMarginLeft() + $matrix->getBlockSize() * $columnIndex, self::DECIMAL_PRECISION, '.', '')); + $block->addAttribute('y', number_format($matrix->getMarginLeft() + $matrix->getBlockSize() * $rowIndex, self::DECIMAL_PRECISION, '.', '')); $block->addAttribute('xlink:href', '#'.$options[self::WRITER_OPTION_BLOCK_ID], 'http://www.w3.org/1999/xlink'); } }