dagronf / QRCode

A quick and beautiful macOS/iOS/tvOS/watchOS QR Code generator/detector library for SwiftUI, Swift and Objective-C.
MIT License
438 stars 57 forks source link

SVG output creating unusable images when using shapes other than defaults #19

Closed keremerkan closed 1 year ago

keremerkan commented 1 year ago

Hi Darren,

Just discovered your project and it is incredible, thank you for such an awesome library. However I have encountered a problem with SVG generation. With shapes other than the default squares, SVG output creates unusable images.

I tried it on both my project and an app I found on the App Store, that uses your library. Attached are 2 images for the same QR Code. The SVG is unusable. PNG has no problems. I also tested PDF, and it does not have any problems.

Is this a known issue so we should avoid SVG for designs other than default, or is this a bug?

Best regards.

Code Code

dagronf commented 1 year ago

Hey mate, sorry to hear you're having issues.

I can see the same issues when trying to open your svg on my machine here. Very odd!

I just tried making the same style of QR code that you're showing and exported it to SVG using this code...

func testIssue19ExportSVGIssue() throws {
   let d = QRCode.Document(utf8String: "This is a test")
   d.design.shape.eye = QRCode.EyeShape.RoundedOuter()
   d.design.shape.onPixels = QRCode.PixelShape.Circle()

   let str = d.svg(dimension: 600)
   try str.write(
      to: URL(fileURLWithPath: "/tmp/qrcode.svg"),
      atomically: true,
      encoding: .utf8
   )
}

which generated this file :-

qrcode

Interestingly, I can view this file correctly in Finder (quicklook), Firefox, Inkscape, Safari and Sketch... these are the apps that I was using to test SVG export.

Can you tell me the settings you're using to generate the QR Code? What pixel style, what eye style? Even better, can you share your code that you're using to create the qr code?

dagronf commented 1 year ago

Here's an exact replica of your QR Code in svg (down to the pixels) generated using the current version of the library...

qrcode19

It's very odd. I'm wondering whether there's some combination of settings which is triggering the issue

dagronf commented 1 year ago

Ah! Would you possibly be located in a country that uses ',' as the decimal separator?

Because I believe thats the issue with the SVG export. SVG expects '.' as the decimal separator - and I'm using a NumberFormatter to format the float values in the SVG export. The NumberSeparator always uses the Locale to determine the decimal separator, thus it uses ',' which breaks the svg output

Give me a moment...

keremerkan commented 1 year ago

Hi Darren,

Yes, that's the exact problem. I just came here to write that to say that I found the issue and you are a step ahead of me. My region uses "," instead of "." and the svg was becoming corrupt because of that. I changed the region to US to verify the issue was fixed before even touching my code.

dagronf commented 1 year ago

@keremerkan Okey - I've pushed up a new version (13.10.0) which should fix the issue.

Would you mind checking out the new release and see if it fixes your issue please?

keremerkan commented 1 year ago

Just updated and checked. Opened the file in Adobe Illustrator for good measure. Works perfectly. Thanks!

dagronf commented 1 year ago

Brilliant mate. Thank you for reporting it - so glad I can help out.

Apologies for the inconvenience.

Oh and btw. which program in the App Store is using the library? Would be interested in having a look...

keremerkan commented 1 year ago

The app I used is called QR Pop. The developer seems to utilize your library very well.

BTW, I am adding your library to my app Qrafter which is probably the oldest QR Code app on App Store that still gets regular updates. I just rewrote it using Swift, and your library was the last piece to make it perfect. :) Thank you very much again for creating such an awesome tool.

dagronf commented 1 year ago

Always great to hear that. Thank you so much!