diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index d329934..de8523d 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -30,16 +30,22 @@ var ctx = canvas.getContext('2d'); // compute tileW/tileH based on options.width/options.height - var tileW = options.width / qrcode.getModuleCount(); - var tileH = options.height / qrcode.getModuleCount(); + var tileW = options.width / (qrcode.getModuleCount() + 8); + var tileH = options.height / (qrcode.getModuleCount() + 8); // draw in the canvas - for( var row = 0; row < qrcode.getModuleCount(); row++ ){ - for( var col = 0; col < qrcode.getModuleCount(); col++ ){ - ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background; - var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); - var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH)); - ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h); + for (var row = 0; row < (qrcode.getModuleCount() + 8); row++) { + for (var col = 0; col < (qrcode.getModuleCount() + 8); col++) { + if ((row < 4) || (row >= (qrcode.getModuleCount() + 4))) { + ctx.fillStyle = options.background; + } else if ((col < 4) || (col >= (qrcode.getModuleCount() + 4))) { + ctx.fillStyle = options.background; + } else { + ctx.fillStyle = qrcode.isDark(row - 4, col - 4) ? options.foreground : options.background; + } + var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW)); + var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH)); + ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h); } } // return just built canvas