@@ -48,8 +48,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
48
48
49
49
$ blockDefinition = $ xml ->defs ->addChild ('rect ' );
50
50
$ blockDefinition ->addAttribute ('id ' , strval ($ options [self ::WRITER_OPTION_BLOCK_ID ]));
51
- $ blockDefinition ->addAttribute ('width ' , number_format ($ matrix ->getBlockSize (), self :: DECIMAL_PRECISION , ' . ' , '' ));
52
- $ blockDefinition ->addAttribute ('height ' , number_format ($ matrix ->getBlockSize (), self :: DECIMAL_PRECISION , ' . ' , '' ));
51
+ $ blockDefinition ->addAttribute ('width ' , $ this -> formatNumber ($ matrix ->getBlockSize ()));
52
+ $ blockDefinition ->addAttribute ('height ' , $ this -> formatNumber ($ matrix ->getBlockSize ()));
53
53
$ blockDefinition ->addAttribute ('fill ' , '# ' .sprintf ('%02x%02x%02x ' , $ qrCode ->getForegroundColor ()->getRed (), $ qrCode ->getForegroundColor ()->getGreen (), $ qrCode ->getForegroundColor ()->getBlue ()));
54
54
$ blockDefinition ->addAttribute ('fill-opacity ' , strval ($ qrCode ->getForegroundColor ()->getOpacity ()));
55
55
@@ -65,8 +65,8 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
65
65
for ($ columnIndex = 0 ; $ columnIndex < $ matrix ->getBlockCount (); ++$ columnIndex ) {
66
66
if (1 === $ matrix ->getBlockValue ($ rowIndex , $ columnIndex )) {
67
67
$ block = $ xml ->addChild ('use ' );
68
- $ block ->addAttribute ('x ' , number_format ($ matrix ->getMarginLeft () + $ matrix ->getBlockSize () * $ columnIndex, self :: DECIMAL_PRECISION , ' . ' , '' ));
69
- $ block ->addAttribute ('y ' , number_format ($ matrix ->getMarginLeft () + $ matrix ->getBlockSize () * $ rowIndex, self :: DECIMAL_PRECISION , ' . ' , '' ));
68
+ $ block ->addAttribute ('x ' , $ this -> formatNumber ($ matrix ->getMarginLeft () + $ matrix ->getBlockSize () * $ columnIndex ));
69
+ $ block ->addAttribute ('y ' , $ this -> formatNumber ($ matrix ->getMarginLeft () + $ matrix ->getBlockSize () * $ rowIndex ));
70
70
$ block ->addAttribute ('xlink:href ' , '# ' .$ options [self ::WRITER_OPTION_BLOCK_ID ], 'http://www.w3.org/1999/xlink ' );
71
71
}
72
72
}
@@ -111,4 +111,12 @@ private function addLogo(LogoInterface $logo, SvgResult $result, array $options)
111
111
$ imageDefinition ->addAttribute ('href ' , $ logoImageData ->createDataUri ());
112
112
}
113
113
}
114
+
115
+ private function formatNumber (float $ number ): string
116
+ {
117
+ $ string = number_format ($ number , self ::DECIMAL_PRECISION , '. ' , '' );
118
+ $ string = rtrim ($ string , '0 ' );
119
+ $ string = rtrim ($ string , '. ' );
120
+ return $ string ;
121
+ }
114
122
}
0 commit comments