codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.61k stars 1.1k forks source link

SvgQRCode-Class creates invalid mirrored QR-Codes #141

Closed thomas253 closed 5 years ago

thomas253 commented 6 years ago

Type of issue

[ x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

The "SvgQRCode"-Class creates valid QR-Codes.

Current Behavior

SvgQRCode creates invalid Qr-Codes. X- and Y-Coordinates are switched in the SVG-Code-String. So the QR Code is mirrored on diagnoal axis (top left to bottom right). It is not readable with Scanners.

XamlQRCode and Bitmap-Creation works fine.

Possible Solution (optional)

Switch x and y Attributes in the SVG-String

QRCodeData data = generator.CreateQrCode("Hello World", QRCodeGenerator.ECCLevel.L, forceUtf8:true) SvgQRCode svg = new SvgQRCode(data); string svgString = svg.GetGraphic(2); -- The output svgString is invalid; Scanning fails.

// Switch Attributes X and Y svgString = svgString.Replace("x=", "temp="); svgString = svgString.Replace("y=", "x="); svgString = svgString.Replace("temp=", "y="); // Now the svgString ist valid an can be scanned.

Steps to Reproduce (for bugs)

QRCodeData data = generator.CreateQrCode("Hello World", QRCodeGenerator.ECCLevel.L, forceUtf8:true) SvgQRCode svg = new SvgQRCode(data); string svgString = svg.GetGraphic(2); // Save the output svgString in a File

Scanning fails.

Your Environment

Ruffio commented 5 years ago

@codebude is this an issue with the code or perhaps implementation?

codebude commented 5 years ago

Hi @thomas253 ,

thanks for pointing this out! I fixed it in this comment: https://github.com/codebude/QRCoder/commit/548bf170af29b733a8c7a4d7166ee8b9c7f55ca0

@Ruffio - this was a coding issue. Strange that nobody complained about it until now. Seems like the SvgQrCode isn't used much...