g0dkar / qrcode-kotlin

QRCode Generator implemented in pure Kotlin
https://qrcodekotlin.com/
MIT License
193 stars 20 forks source link

Fix size for drawing margin square #107

Closed chphmh closed 11 months ago

chphmh commented 12 months ago

Currently in QRCodeProcessor.render() the method renderShaded() is called with a provided renderer function. When this renderer function draws the square for the margin of the QR code, cellSize is used for its width and height. This has the result that the margin appears just as a small square in the upper left corner of the QR code image.

The QR code graphic itself has the correct dimensions (including margins), so on a white background it looks fine, but on a dark background, only the upper left corner of the margin space is colored in white, the rest is transparent, showing the dark background.

The fix replaces the width/height properties cellSize, cellSizes with a call to qrCodeGraphics.dimensions() getting the actual width and height of the graphic, so the margin fills the whole square.

(Alternatively, instead of that computeImageSize(cellSize, margin, rawData) could be used again for these two arguments.)

chphmh commented 12 months ago

We encountered this issue when using the QR code library in an Android project with a dark mode / dark background, in which the white QR code margin was missing everywhere except in the left upper corner, because wrong size is provided. We could fix it by calling QRCodeProcessor.renderShaded() directly with a custom renderer function, but this merge request should fix it in QRCodeProcessor.render().

g0dkar commented 11 months ago

Heya, just a kind of late heads up: I'm on a business trip, so I'm a bit off. I'll be able to review and merge everything next week ^^

g0dkar commented 11 months ago

Heya, I'll close this one since it should be fixed by #109 :)