Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c2212a48a | ||
|
|
2d05056217 | ||
|
|
5fc6af970b | ||
|
|
590d78f921 |
2 changed files with 32 additions and 13 deletions
|
|
@ -9,7 +9,7 @@ It is based on a <a href='http://www.d-project.com/qrcode/index.html'>library</a
|
||||||
which build qrcode in various language. <a href='http://jeromeetienne.github.com/jquery-qrcode'>jquery.qrcode.js</a> wraps
|
which build qrcode in various language. <a href='http://jeromeetienne.github.com/jquery-qrcode'>jquery.qrcode.js</a> wraps
|
||||||
it to make it easy to include in your own code.
|
it to make it easy to include in your own code.
|
||||||
|
|
||||||
Show, dont tell, here is a <a href='examples/basic.html'>example</a>
|
Show, dont tell, here is a <a href='https://github.com/jeromeetienne/jquery-qrcode/blob/master/examples/basic.html'>example</a>
|
||||||
|
|
||||||
## How to Use It
|
## How to Use It
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
render : "canvas",
|
render : "canvas",
|
||||||
width : 256,
|
width : 256,
|
||||||
height : 256,
|
height : 256,
|
||||||
|
margin : 4,
|
||||||
typeNumber : -1,
|
typeNumber : -1,
|
||||||
correctLevel : QRErrorCorrectLevel.H,
|
correctLevel : QRErrorCorrectLevel.H,
|
||||||
background : "#ffffff",
|
background : "#ffffff",
|
||||||
|
|
@ -30,15 +31,24 @@
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
// compute tileW/tileH based on options.width/options.height
|
// compute tileW/tileH based on options.width/options.height
|
||||||
var tileW = options.width / qrcode.getModuleCount();
|
var margin = options.margin;
|
||||||
var tileH = options.height / qrcode.getModuleCount();
|
var tileW = options.width / (qrcode.getModuleCount() + 2*options.margin);
|
||||||
|
var tileH = options.height / (qrcode.getModuleCount() + 2*options.margin);
|
||||||
|
|
||||||
|
var isDark = function(x, y) {
|
||||||
|
x -= margin; y -= margin;
|
||||||
|
if(x < 0 || x >= qrcode.getModuleCount() || y < 0 || y >= qrcode.getModuleCount())
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return qrcode.isDark(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
// draw in the canvas
|
// draw in the canvas
|
||||||
for( var row = 0; row < qrcode.getModuleCount(); row++ ){
|
for( var row = 0; row < qrcode.getModuleCount()+2*margin; row++ ){
|
||||||
for( var col = 0; col < qrcode.getModuleCount(); col++ ){
|
for( var col = 0; col < qrcode.getModuleCount()+2*margin; col++ ){
|
||||||
ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background;
|
ctx.fillStyle = isDark(row, col) ? options.foreground : options.background;
|
||||||
var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
|
var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
|
||||||
var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW));
|
var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH));
|
||||||
ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h);
|
ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,17 +72,26 @@
|
||||||
.css('background-color', options.background);
|
.css('background-color', options.background);
|
||||||
|
|
||||||
// compute tileS percentage
|
// compute tileS percentage
|
||||||
var tileW = options.width / qrcode.getModuleCount();
|
var margin = options.margin;
|
||||||
var tileH = options.height / qrcode.getModuleCount();
|
var tileW = options.width / (qrcode.getModuleCount() + 2*margin);
|
||||||
|
var tileH = options.height / (qrcode.getModuleCount() + 2*margin);
|
||||||
|
|
||||||
|
var isDark = function(x, y) {
|
||||||
|
x -= margin; y -= margin;
|
||||||
|
if(x < 0 || x >= qrcode.getModuleCount() || y < 0 || y >= qrcode.getModuleCount())
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return qrcode.isDark(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
// draw in the table
|
// draw in the table
|
||||||
for(var row = 0; row < qrcode.getModuleCount(); row++ ){
|
for(var row = 0; row < (qrcode.getModuleCount() + 2*margin); row++ ){
|
||||||
var $row = $('<tr></tr>').css('height', tileH+"px").appendTo($table);
|
var $row = $('<tr></tr>').css('height', tileH+"px").appendTo($table);
|
||||||
|
|
||||||
for(var col = 0; col < qrcode.getModuleCount(); col++ ){
|
for(var col = 0; col < (qrcode.getModuleCount() + 2*margin); col++ ){
|
||||||
$('<td></td>')
|
$('<td></td>')
|
||||||
.css('width', tileW+"px")
|
.css('width', tileW+"px")
|
||||||
.css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background)
|
.css('background-color', isDark(row, col) ? options.foreground : options.background)
|
||||||
.appendTo($row);
|
.appendTo($row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +102,7 @@
|
||||||
|
|
||||||
return this.each(function(){
|
return this.each(function(){
|
||||||
var element = options.render == "canvas" ? createCanvas() : createTable();
|
var element = options.render == "canvas" ? createCanvas() : createTable();
|
||||||
jQuery(element).appendTo(this);
|
$(element).appendTo(this);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue