@@ -17,6 +17,7 @@ final class SvgWriter implements WriterInterface
17
17
public const DECIMAL_PRECISION = 10 ;
18
18
public const WRITER_OPTION_BLOCK_ID = 'block_id ' ;
19
19
public const WRITER_OPTION_EXCLUDE_XML_DECLARATION = 'exclude_xml_declaration ' ;
20
+ public const WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT = 'exclude_svg_width_and_height ' ;
20
21
public const WRITER_OPTION_FORCE_XLINK_HREF = 'force_xlink_href ' ;
21
22
22
23
public function write (QrCodeInterface $ qrCode , LogoInterface $ logo = null , LabelInterface $ label = null , array $ options = []): ResultInterface
@@ -29,13 +30,19 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
29
30
$ options [self ::WRITER_OPTION_EXCLUDE_XML_DECLARATION ] = false ;
30
31
}
31
32
33
+ if (!isset ($ options [self ::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT ])) {
34
+ $ options [self ::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT ] = false ;
35
+ }
36
+
32
37
$ matrixFactory = new MatrixFactory ();
33
38
$ matrix = $ matrixFactory ->create ($ qrCode );
34
39
35
40
$ xml = new \SimpleXMLElement ('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/> ' );
36
41
$ xml ->addAttribute ('version ' , '1.1 ' );
37
- $ xml ->addAttribute ('width ' , $ matrix ->getOuterSize ().'px ' );
38
- $ xml ->addAttribute ('height ' , $ matrix ->getOuterSize ().'px ' );
42
+ if (!$ options [self ::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT ]) {
43
+ $ xml ->addAttribute ('width ' , $ matrix ->getOuterSize ().'px ' );
44
+ $ xml ->addAttribute ('height ' , $ matrix ->getOuterSize ().'px ' );
45
+ }
39
46
$ xml ->addAttribute ('viewBox ' , '0 0 ' .$ matrix ->getOuterSize ().' ' .$ matrix ->getOuterSize ());
40
47
$ xml ->addChild ('defs ' );
41
48
0 commit comments