diff --git a/HISTORY.md b/HISTORY.md index 607068e..43e96c5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,9 @@ # History - --- +## 3.0.6 + +`tag:fixed` 修复不能渲染小数点像素值问题 + ## 3.0.5 `tag:fixed` canvas 模式在 Retina 下显示模糊 diff --git a/dist/arale-qrcode/3.0.5/index.js b/dist/arale-qrcode/3.0.5/index.js deleted file mode 100644 index 4f08742..0000000 --- a/dist/arale-qrcode/3.0.5/index.js +++ /dev/null @@ -1 +0,0 @@ -this.AraleQRCode=function(t){function e(o){if(r[o])return r[o].exports;var i=r[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";t.exports=r(2)},function(t,e,r){"use strict";var o=r(4),i=[],n=r(3),s=function(t){var e=t.options;return e.pdground&&(t.row>1&&t.row<5&&t.col>1&&t.col<5||t.row>t.count-6&&t.row1&&t.col<5||t.row>1&&t.row<5&&t.col>t.count-6&&t.colr;r++)if(i[r].text==this.options.text&&i[r].text.correctLevel==this.options.correctLevel){e=i[r].obj;break}if(r==s&&(e=new n(this.options.text,this.options.correctLevel),i.push({text:this.options.text,correctLevel:this.options.correctLevel,obj:e})),this.options.render)switch(this.options.render){case"canvas":return this.createCanvas(e);case"table":return this.createTable(e);case"svg":return this.createSVG(e);default:return this.createDefault(e)}return this.createDefault(e)};o(a.prototype,{createDefault:function(t){var e=document.createElement("canvas");if(e.getContext)return this.createCanvas(t);var r="http://www.w3.org/2000/svg";return document.createElementNS&&document.createElementNS(r,"svg").createSVGRect?this.createSVG(t):this.createTable(t)},createCanvas:function(t){var e=this.options,r=document.createElement("canvas"),o=r.getContext("2d"),i=t.getModuleCount(),n=u(o),a=e.size,l=a*n,h=e.imageSize*n,g=function(t,e){var r=new Image;r.src=t,r.onload=function(){e(this),r.onload=null}},c=(l/i).toPrecision(4),f=(l/i).toPrecision(4);r.width=l,r.height=l;for(var d=0;i>d;d++)for(var m=0;i>m;m++){var p=Math.ceil((m+1)*c)-Math.floor(m*c),v=Math.ceil((d+1)*c)-Math.floor(d*c),b=s({row:d,col:m,count:i,options:e});o.fillStyle=t.modules[d][m]?b:e.background,o.fillRect(Math.round(m*c),Math.round(d*f),p,v)}return e.image&&g(e.image,function(t){var e=((l-h)/2).toFixed(2),r=((l-h)/2).toFixed(2);o.drawImage(t,e,r,h,h)}),r.style.width=a+"px",r.style.height=a+"px",r},createTable:function(t){var e=this.options,r=t.getModuleCount(),o=Math.floor(e.size/r),i=Math.floor(e.size/r);0>=o&&(o=80>r?2:1),0>=i&&(i=80>r?2:1);var n=[];n.push('');for(var u=0;r>u;u++){n.push('');for(var a=0;r>a;a++){var l=s({row:u,col:a,count:r,options:e});t.modules[u][a]?n.push(''):n.push('')}n.push("")}if(n.push("
"),e.image){var h=o*r,g=i*r,c=((h-e.imageSize)/2).toFixed(2),f=((g-e.imageSize)/2).toFixed(2);n.unshift("
"),n.push(""),n.push("
")}var d=document.createElement("span");return d.innerHTML=n.join(""),d.firstChild},createSVG:function(t){var e=this.options,r=t.getModuleCount(),o=r/e.size,i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width",e.size),i.setAttribute("height",e.size),i.setAttribute("viewBox","0 0 "+r+" "+r);for(var n=0;r>n;n++)for(var u=0;r>u;u++){var a=document.createElementNS("http://www.w3.org/2000/svg","rect"),l=s({row:n,col:u,count:r,options:e});a.setAttribute("x",u),a.setAttribute("y",n),a.setAttribute("width",1),a.setAttribute("height",1),a.setAttribute("stroke-width",0),t.modules[n][u]?a.setAttribute("fill",l):a.setAttribute("fill",e.background),i.appendChild(a)}if(e.image){var h=document.createElementNS("http://www.w3.org/2000/svg","image");h.setAttributeNS("http://www.w3.org/1999/xlink","href",e.image),h.setAttribute("x",((r-e.imageSize*o)/2).toFixed(2)),h.setAttribute("y",((r-e.imageSize*o)/2).toFixed(2)),h.setAttribute("width",e.imageSize*o),h.setAttribute("height",e.imageSize*o),i.appendChild(h)}return i}}),t.exports=a},function(t,e){"use strict";function r(t){var e,r,o;return 128>t?[t]:2048>t?(e=192+(t>>6),r=128+(63&t),[e,r]):(e=224+(t>>12),r=128+(t>>6&63),o=128+(63&t),[e,r,o])}function o(t){for(var e=[],o=0;o=7&&this.setupTypeNumber(!0),this.mapData(this.dataCache,t)},setupPositionProbePattern:function(t,e){for(var r=-1;7>=r;r++)if(!(-1>=t+r||this.moduleCount<=t+r))for(var o=-1;7>=o;o++)-1>=e+o||this.moduleCount<=e+o||(r>=0&&6>=r&&(0==o||6==o)||o>=0&&6>=o&&(0==r||6==r)||r>=2&&4>=r&&o>=2&&4>=o?this.modules[t+r][e+o]=!0:this.modules[t+r][e+o]=!1)},createQrcode:function(){for(var t=0,e=0,r=null,o=0;8>o;o++){this.makeImpl(o);var i=l.getLostPoint(this);(0==o||t>i)&&(t=i,e=o,r=this.modules)}this.modules=r,this.setupTypeInfo(!1,e),this.typeNumber>=7&&this.setupTypeNumber(!1)},setupTimingPattern:function(){for(var t=8;t=n;n++)for(var s=-2;2>=s;s++)-2==n||2==n||-2==s||2==s||0==n&&0==s?this.modules[o+n][i+s]=!0:this.modules[o+n][i+s]=!1}},setupTypeNumber:function(t){for(var e=l.getBCHTypeNumber(this.typeNumber),r=0;18>r;r++){var o=!t&&1==(e>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o,this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},setupTypeInfo:function(t,e){for(var r=u[this.errorCorrectLevel]<<3|e,o=l.getBCHTypeInfo(r),i=0;15>i;i++){var n=!t&&1==(o>>i&1);6>i?this.modules[i][8]=n:8>i?this.modules[i+1][8]=n:this.modules[this.moduleCount-15+i][8]=n;var n=!t&&1==(o>>i&1);8>i?this.modules[8][this.moduleCount-i-1]=n:9>i?this.modules[8][15-i-1+1]=n:this.modules[8][15-i-1]=n}this.modules[this.moduleCount-8][8]=!t},createData:function(){var t=new s,e=this.typeNumber>9?16:8;t.put(4,4),t.put(this.utf8bytes.length,e);for(var r=0,o=this.utf8bytes.length;o>r;r++)t.put(this.utf8bytes[r],8);for(t.length+4<=8*this.totalDataCount&&t.put(0,4);t.length%8!=0;)t.putBit(!1);for(;;){if(t.length>=8*this.totalDataCount)break;if(t.put(i.PAD0,8),t.length>=8*this.totalDataCount)break;t.put(i.PAD1,8)}return this.createBytes(t)},createBytes:function(t){for(var e=0,r=0,o=0,i=this.rsBlock.length/3,s=new Array,u=0;i>u;u++)for(var a=this.rsBlock[3*u+0],h=this.rsBlock[3*u+1],g=this.rsBlock[3*u+2],c=0;a>c;c++)s.push([g,h]);for(var f=new Array(s.length),d=new Array(s.length),m=0;m=0?A.get(T):0}}for(var P=new Array(this.totalDataCount),y=0,u=0;r>u;u++)for(var m=0;mu;u++)for(var m=0;m0;s-=2)for(6==s&&s--;;){for(var u=0;2>u;u++)if(null==this.modules[o][s-u]){var a=!1;n>>i&1));var h=l.getMask(e,o,s-u);h&&(a=!a),this.modules[o][s-u]=a,i--,-1==i&&(n++,i=7)}if(o+=r,0>o||this.moduleCount<=o){o-=r,r=-r;break}}}},i.PAD0=236,i.PAD1=17;for(var u=[1,0,3,2],a={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},l={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(t){for(var e=t<<10;l.getBCHDigit(e)-l.getBCHDigit(l.G15)>=0;)e^=l.G15<=0;)e^=l.G18<>>=1;return e},getPatternPosition:function(t){return l.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case a.PATTERN000:return(e+r)%2==0;case a.PATTERN001:return e%2==0;case a.PATTERN010:return r%3==0;case a.PATTERN011:return(e+r)%3==0;case a.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case a.PATTERN101:return e*r%2+e*r%3==0;case a.PATTERN110:return(e*r%2+e*r%3)%2==0;case a.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new n([1],0),r=0;t>r;r++)e=e.multiply(new n([1,h.gexp(r)],0));return e},getLostPoint:function(t){for(var e=t.getModuleCount(),r=0,o=0,i=0;e>i;i++)for(var n=0,s=t.modules[i][0],u=0;e>u;u++){var a=t.modules[i][u];if(e-6>u&&a&&!t.modules[i][u+1]&&t.modules[i][u+2]&&t.modules[i][u+3]&&t.modules[i][u+4]&&!t.modules[i][u+5]&&t.modules[i][u+6]&&(e-10>u?t.modules[i][u+7]&&t.modules[i][u+8]&&t.modules[i][u+9]&&t.modules[i][u+10]&&(r+=40):u>3&&t.modules[i][u-1]&&t.modules[i][u-2]&&t.modules[i][u-3]&&t.modules[i][u-4]&&(r+=40)),e-1>i&&e-1>u){var l=0;a&&l++,t.modules[i+1][u]&&l++,t.modules[i][u+1]&&l++,t.modules[i+1][u+1]&&l++,(0==l||4==l)&&(r+=3)}s^a?n++:(s=a,n>=5&&(r+=3+n-5),n=1),a&&o++}for(var u=0;e>u;u++)for(var n=0,s=t.modules[0][u],i=0;e>i;i++){var a=t.modules[i][u];e-6>i&&a&&!t.modules[i+1][u]&&t.modules[i+2][u]&&t.modules[i+3][u]&&t.modules[i+4][u]&&!t.modules[i+5][u]&&t.modules[i+6][u]&&(e-10>i?t.modules[i+7][u]&&t.modules[i+8][u]&&t.modules[i+9][u]&&t.modules[i+10][u]&&(r+=40):i>3&&t.modules[i-1][u]&&t.modules[i-2][u]&&t.modules[i-3][u]&&t.modules[i-4][u]&&(r+=40)),s^a?n++:(s=a,n>=5&&(r+=3+n-5),n=1)}var h=Math.abs(100*o/e/e-50)/5;return r+=10*h}},h={glog:function(t){if(1>t)throw new Error("glog("+t+")");return h.LOG_TABLE[t]},gexp:function(t){for(;0>t;)t+=255;for(;t>=256;)t-=255;return h.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},g=0;8>g;g++)h.EXP_TABLE[g]=1<g;g++)h.EXP_TABLE[g]=h.EXP_TABLE[g-4]^h.EXP_TABLE[g-5]^h.EXP_TABLE[g-6]^h.EXP_TABLE[g-8];for(var g=0;255>g;g++)h.LOG_TABLE[h.EXP_TABLE[g]]=g;n.prototype={get:function(t){return this.num[t]},getLength:function(){return this.num.length},multiply:function(t){for(var e=new Array(this.getLength()+t.getLength()-1),r=0;re-r)return this;for(var o=new Array(e),i=0;e>i;i++)o[i]=this.get(i);for(;o.length>=r;){for(var s=h.glog(o[0])-h.glog(t.get(0)),i=0;it;t++){var e=c[4*(t-1)+this.errorCorrectLevel];if(void 0==e)throw new Error("bad rs block @ typeNumber:"+t+"/errorCorrectLevel:"+this.errorCorrectLevel);for(var r=e.length/3,o=0,i=0;r>i;i++){var n=e[3*i+0],s=e[3*i+2];o+=s*n}var u=t>9?2:1;if(this.utf8bytes.length+u>>7-t%8&1},put:function(t,e){for(var r=0;e>r;r++)this.putBit(t>>>e-r-1&1)},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}},t.exports=i},function(t,e){t.exports=function(t){for(var e,r=Array.prototype.slice.call(arguments,1),o=0;e=r[o];o++)if(e)for(var i in e)t[i]=e[i];return t}}]); \ No newline at end of file diff --git a/dist/arale-qrcode/3.0.6/index.js b/dist/arale-qrcode/3.0.6/index.js new file mode 100644 index 0000000..6e54e5a --- /dev/null +++ b/dist/arale-qrcode/3.0.6/index.js @@ -0,0 +1 @@ +this.AraleQRCode=function(t){function e(o){if(r[o])return r[o].exports;var i=r[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";t.exports=r(2)},function(t,e,r){"use strict";var o=r(4),i=[],n=r(3),s=function(t){var e=t.options;return e.pdground&&(t.row>1&&t.row<5&&t.col>1&&t.col<5||t.row>t.count-6&&t.row1&&t.col<5||t.row>1&&t.row<5&&t.col>t.count-6&&t.colr;r++)if(i[r].text==this.options.text&&i[r].text.correctLevel==this.options.correctLevel){e=i[r].obj;break}if(r==s&&(e=new n(this.options.text,this.options.correctLevel),i.push({text:this.options.text,correctLevel:this.options.correctLevel,obj:e})),this.options.render)switch(this.options.render){case"canvas":return this.createCanvas(e);case"table":return this.createTable(e);case"svg":return this.createSVG(e);default:return this.createDefault(e)}return this.createDefault(e)};o(a.prototype,{createDefault:function(t){var e=document.createElement("canvas");if(e.getContext)return this.createCanvas(t);var r="http://www.w3.org/2000/svg";return document.createElementNS&&document.createElementNS(r,"svg").createSVGRect?this.createSVG(t):this.createTable(t)},createCanvas:function(t){var e=this.options,r=document.createElement("canvas"),o=r.getContext("2d"),i=t.getModuleCount(),n=u(o),a=e.size,l=a*n,h=e.imageSize*n,g=function(t,e){var r=new Image;r.src=t,r.onload=function(){e(this),r.onload=null}},c=Math.floor(a/i),d=Math.floor(a/i);0>=c&&(c=80>i?2:1),0>=d&&(d=80>i?2:1);var f=c*n,m=d*n;r.width=f*i,r.height=m*i;for(var p=Math.floor(h*(r.width/l)),v=0;i>v;v++)for(var b=0;i>b;b++){var w=Math.ceil((b+1)*f)-Math.floor(b*f),A=Math.ceil((v+1)*m)-Math.floor(v*m),T=s({row:v,col:b,count:i,options:e});o.fillStyle=t.modules[v][b]?T:e.background,o.fillRect(Math.round(b*f),Math.round(v*m),w,A)}e.image&&g(e.image,function(t){var e=((r.width-p)/2).toFixed(2),i=((r.height-p)/2).toFixed(2);o.drawImage(t,e,i,p,p)}),r.style.width=c*i+"px",r.style.height=d*i+"px";var C=[];C.push(''),C.push("");var x=document.createElement("span");return x.innerHTML=C.join(""),x.firstChild.appendChild(r),x.firstChild},createTable:function(t){var e=this.options,r=t.getModuleCount(),o=Math.floor(e.size/r),i=Math.floor(e.size/r);0>=o&&(o=80>r?2:1),0>=i&&(i=80>r?2:1);var n=[];n.push('');for(var u=0;r>u;u++){n.push('');for(var a=0;r>a;a++){var l=s({row:u,col:a,count:r,options:e});t.modules[u][a]?n.push(''):n.push('')}n.push("")}if(n.push("
"),e.image){var h=o*r,g=i*r,c=((h-e.imageSize)/2).toFixed(2),d=((g-e.imageSize)/2).toFixed(2);n.unshift("
"),n.push(""),n.push("
")}var f=document.createElement("span");return f.innerHTML=n.join(""),f.firstChild},createSVG:function(t){var e=this.options,r=t.getModuleCount(),o=r/e.size,i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width",e.size),i.setAttribute("height",e.size),i.setAttribute("viewBox","0 0 "+r+" "+r);for(var n=0;r>n;n++)for(var u=0;r>u;u++){var a=document.createElementNS("http://www.w3.org/2000/svg","rect"),l=s({row:n,col:u,count:r,options:e});a.setAttribute("x",u),a.setAttribute("y",n),a.setAttribute("width",1),a.setAttribute("height",1),a.setAttribute("stroke-width",0),t.modules[n][u]?a.setAttribute("fill",l):a.setAttribute("fill",e.background),i.appendChild(a)}if(e.image){var h=document.createElementNS("http://www.w3.org/2000/svg","image");h.setAttributeNS("http://www.w3.org/1999/xlink","href",e.image),h.setAttribute("x",((r-e.imageSize*o)/2).toFixed(2)),h.setAttribute("y",((r-e.imageSize*o)/2).toFixed(2)),h.setAttribute("width",e.imageSize*o),h.setAttribute("height",e.imageSize*o),i.appendChild(h)}return i}}),t.exports=a},function(t,e){"use strict";function r(t){var e,r,o;return 128>t?[t]:2048>t?(e=192+(t>>6),r=128+(63&t),[e,r]):(e=224+(t>>12),r=128+(t>>6&63),o=128+(63&t),[e,r,o])}function o(t){for(var e=[],o=0;o=7&&this.setupTypeNumber(!0),this.mapData(this.dataCache,t)},setupPositionProbePattern:function(t,e){for(var r=-1;7>=r;r++)if(!(-1>=t+r||this.moduleCount<=t+r))for(var o=-1;7>=o;o++)-1>=e+o||this.moduleCount<=e+o||(r>=0&&6>=r&&(0==o||6==o)||o>=0&&6>=o&&(0==r||6==r)||r>=2&&4>=r&&o>=2&&4>=o?this.modules[t+r][e+o]=!0:this.modules[t+r][e+o]=!1)},createQrcode:function(){for(var t=0,e=0,r=null,o=0;8>o;o++){this.makeImpl(o);var i=l.getLostPoint(this);(0==o||t>i)&&(t=i,e=o,r=this.modules)}this.modules=r,this.setupTypeInfo(!1,e),this.typeNumber>=7&&this.setupTypeNumber(!1)},setupTimingPattern:function(){for(var t=8;t=n;n++)for(var s=-2;2>=s;s++)-2==n||2==n||-2==s||2==s||0==n&&0==s?this.modules[o+n][i+s]=!0:this.modules[o+n][i+s]=!1}},setupTypeNumber:function(t){for(var e=l.getBCHTypeNumber(this.typeNumber),r=0;18>r;r++){var o=!t&&1==(e>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o,this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},setupTypeInfo:function(t,e){for(var r=u[this.errorCorrectLevel]<<3|e,o=l.getBCHTypeInfo(r),i=0;15>i;i++){var n=!t&&1==(o>>i&1);6>i?this.modules[i][8]=n:8>i?this.modules[i+1][8]=n:this.modules[this.moduleCount-15+i][8]=n;var n=!t&&1==(o>>i&1);8>i?this.modules[8][this.moduleCount-i-1]=n:9>i?this.modules[8][15-i-1+1]=n:this.modules[8][15-i-1]=n}this.modules[this.moduleCount-8][8]=!t},createData:function(){var t=new s,e=this.typeNumber>9?16:8;t.put(4,4),t.put(this.utf8bytes.length,e);for(var r=0,o=this.utf8bytes.length;o>r;r++)t.put(this.utf8bytes[r],8);for(t.length+4<=8*this.totalDataCount&&t.put(0,4);t.length%8!=0;)t.putBit(!1);for(;;){if(t.length>=8*this.totalDataCount)break;if(t.put(i.PAD0,8),t.length>=8*this.totalDataCount)break;t.put(i.PAD1,8)}return this.createBytes(t)},createBytes:function(t){for(var e=0,r=0,o=0,i=this.rsBlock.length/3,s=new Array,u=0;i>u;u++)for(var a=this.rsBlock[3*u+0],h=this.rsBlock[3*u+1],g=this.rsBlock[3*u+2],c=0;a>c;c++)s.push([g,h]);for(var d=new Array(s.length),f=new Array(s.length),m=0;m=0?A.get(T):0}}for(var C=new Array(this.totalDataCount),x=0,u=0;r>u;u++)for(var m=0;mu;u++)for(var m=0;m0;s-=2)for(6==s&&s--;;){for(var u=0;2>u;u++)if(null==this.modules[o][s-u]){var a=!1;n>>i&1));var h=l.getMask(e,o,s-u);h&&(a=!a),this.modules[o][s-u]=a,i--,-1==i&&(n++,i=7)}if(o+=r,0>o||this.moduleCount<=o){o-=r,r=-r;break}}}},i.PAD0=236,i.PAD1=17;for(var u=[1,0,3,2],a={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},l={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(t){for(var e=t<<10;l.getBCHDigit(e)-l.getBCHDigit(l.G15)>=0;)e^=l.G15<=0;)e^=l.G18<>>=1;return e},getPatternPosition:function(t){return l.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case a.PATTERN000:return(e+r)%2==0;case a.PATTERN001:return e%2==0;case a.PATTERN010:return r%3==0;case a.PATTERN011:return(e+r)%3==0;case a.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case a.PATTERN101:return e*r%2+e*r%3==0;case a.PATTERN110:return(e*r%2+e*r%3)%2==0;case a.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new n([1],0),r=0;t>r;r++)e=e.multiply(new n([1,h.gexp(r)],0));return e},getLostPoint:function(t){for(var e=t.getModuleCount(),r=0,o=0,i=0;e>i;i++)for(var n=0,s=t.modules[i][0],u=0;e>u;u++){var a=t.modules[i][u];if(e-6>u&&a&&!t.modules[i][u+1]&&t.modules[i][u+2]&&t.modules[i][u+3]&&t.modules[i][u+4]&&!t.modules[i][u+5]&&t.modules[i][u+6]&&(e-10>u?t.modules[i][u+7]&&t.modules[i][u+8]&&t.modules[i][u+9]&&t.modules[i][u+10]&&(r+=40):u>3&&t.modules[i][u-1]&&t.modules[i][u-2]&&t.modules[i][u-3]&&t.modules[i][u-4]&&(r+=40)),e-1>i&&e-1>u){var l=0;a&&l++,t.modules[i+1][u]&&l++,t.modules[i][u+1]&&l++,t.modules[i+1][u+1]&&l++,(0==l||4==l)&&(r+=3)}s^a?n++:(s=a,n>=5&&(r+=3+n-5),n=1),a&&o++}for(var u=0;e>u;u++)for(var n=0,s=t.modules[0][u],i=0;e>i;i++){var a=t.modules[i][u];e-6>i&&a&&!t.modules[i+1][u]&&t.modules[i+2][u]&&t.modules[i+3][u]&&t.modules[i+4][u]&&!t.modules[i+5][u]&&t.modules[i+6][u]&&(e-10>i?t.modules[i+7][u]&&t.modules[i+8][u]&&t.modules[i+9][u]&&t.modules[i+10][u]&&(r+=40):i>3&&t.modules[i-1][u]&&t.modules[i-2][u]&&t.modules[i-3][u]&&t.modules[i-4][u]&&(r+=40)),s^a?n++:(s=a,n>=5&&(r+=3+n-5),n=1)}var h=Math.abs(100*o/e/e-50)/5;return r+=10*h}},h={glog:function(t){if(1>t)throw new Error("glog("+t+")");return h.LOG_TABLE[t]},gexp:function(t){for(;0>t;)t+=255;for(;t>=256;)t-=255;return h.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},g=0;8>g;g++)h.EXP_TABLE[g]=1<g;g++)h.EXP_TABLE[g]=h.EXP_TABLE[g-4]^h.EXP_TABLE[g-5]^h.EXP_TABLE[g-6]^h.EXP_TABLE[g-8];for(var g=0;255>g;g++)h.LOG_TABLE[h.EXP_TABLE[g]]=g;n.prototype={get:function(t){return this.num[t]},getLength:function(){return this.num.length},multiply:function(t){for(var e=new Array(this.getLength()+t.getLength()-1),r=0;re-r)return this;for(var o=new Array(e),i=0;e>i;i++)o[i]=this.get(i);for(;o.length>=r;){for(var s=h.glog(o[0])-h.glog(t.get(0)),i=0;it;t++){var e=c[4*(t-1)+this.errorCorrectLevel];if(void 0==e)throw new Error("bad rs block @ typeNumber:"+t+"/errorCorrectLevel:"+this.errorCorrectLevel);for(var r=e.length/3,o=0,i=0;r>i;i++){var n=e[3*i+0],s=e[3*i+2];o+=s*n}var u=t>9?2:1;if(this.utf8bytes.length+u>>7-t%8&1},put:function(t,e){for(var r=0;e>r;r++)this.putBit(t>>>e-r-1&1)},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}},t.exports=i},function(t,e){t.exports=function(t){for(var e,r=Array.prototype.slice.call(arguments,1),o=0;e=r[o];o++)if(e)for(var i in e)t[i]=e[i];return t}}]); \ No newline at end of file diff --git a/examples/index.md b/examples/index.md index 743ce9d..dc813ed 100644 --- a/examples/index.md +++ b/examples/index.md @@ -2,7 +2,7 @@ --- -## 采用默认方式画二维码" +## 采用默认方式画二维码 ````html diff --git a/package.json b/package.json index ae027f7..b1d3a4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arale-qrcode", - "version": "3.0.5", + "version": "3.0.6", "description": "二维码绘制模块", "homepage": "http://aralejs.org/qrcode/", "author": "倚松 ", diff --git a/src/index.js b/src/index.js index c2ef794..fe59757 100644 --- a/src/index.js +++ b/src/index.js @@ -28,7 +28,7 @@ var getForeGround = function(config){ * @param {col} 矩阵列 * @param {count} 矩阵大小 * @return {Boolean} -*/ + var inPositionDetection = function(row, col, count){ if( (row<7 && col<7) @@ -39,6 +39,7 @@ var inPositionDetection = function(row, col, count){ } return false; } +*/ /** * 获取当前屏幕的设备像素比 devicePixelRatio/backingStore * @param {context} 当前 canvas 上下文,可以为 window @@ -75,7 +76,8 @@ var qrcode = function(opt) { background: '#ffffff', foreground: '#000000', image : '', - imageSize: 30 + imageSize: 30, + canvasClass: 'canvas-qrcode' }, opt); //使用QRCodeAlg创建二维码结构 @@ -140,18 +142,28 @@ extend(qrcode.prototype,{ }; } - //计算每个点的长宽 - var tileW = (ratioSize / count).toPrecision(4); - var tileH = (ratioSize / count).toPrecision(4); + // 计算每个节点的长宽;取整,防止点之间出现分离 + var tileW = Math.floor(size / count); + var tileH = Math.floor(size / count); + if(tileW <= 0){ + tileW = count < 80 ? 2 : 1; + } + if(tileH <= 0){ + tileH = count < 80 ? 2 : 1; + } - canvas.width = ratioSize; - canvas.height = ratioSize; + var ratioTileW = tileW * ratio; + var ratioTileH = tileH * ratio; + canvas.width = ratioTileW * count; + canvas.height = ratioTileH * count; + + var currImageSize = Math.floor(ratioImgSize * (canvas.width / ratioSize)); //绘制 for (var row = 0; row < count; row++) { for (var col = 0; col < count; col++) { - var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW)); - var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW)); + var w = (Math.ceil((col + 1) * ratioTileW) - Math.floor(col * ratioTileW)); + var h = (Math.ceil((row + 1) * ratioTileH) - Math.floor(row * ratioTileH)); var foreground = getForeGround({ row : row, col : col, @@ -159,19 +171,27 @@ extend(qrcode.prototype,{ options : options }); ctx.fillStyle = qrCodeAlg.modules[row][col] ? foreground : options.background; - ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h); + ctx.fillRect(Math.round(col * ratioTileW), Math.round(row * ratioTileH), w, h); } } if(options.image){ loadImage(options.image, function(img){ - var x = ((ratioSize - ratioImgSize)/2).toFixed(2); - var y = ((ratioSize - ratioImgSize)/2).toFixed(2); - ctx.drawImage(img, x, y, ratioImgSize, ratioImgSize); + var x = ((canvas.width - currImageSize)/2).toFixed(2); + var y = ((canvas.height - currImageSize)/2).toFixed(2); + ctx.drawImage(img, x, y, currImageSize, currImageSize); }); } - canvas.style.width = size + 'px'; - canvas.style.height = size + 'px'; - return canvas; + canvas.style.width = tileW * count + 'px'; + canvas.style.height = tileH * count + 'px'; + var s = []; + s.push(``); + s.push(''); + var span = document.createElement('span'); + span.innerHTML = s.join(''); + span.firstChild.appendChild(canvas); + + return span.firstChild; }, // table create createTable (qrCodeAlg) { diff --git a/tests/qrcode-spec.js b/tests/qrcode-spec.js index c1677eb..690c016 100644 --- a/tests/qrcode-spec.js +++ b/tests/qrcode-spec.js @@ -39,6 +39,16 @@ describe('qrcode', function() { foreground:'#011' }); }); + it('设置二维码容错水平', function() { + var qrnode = new qrcode({ + correctLevel: 2 + }); + }); + it('设置二维码className', function() { + var qrnode = new qrcode({ + canvasClass: 'test-class' + }); + }); it('以table来显示', function() { var qrnode = new qrcode({ render:'table' @@ -60,10 +70,11 @@ describe('qrcode', function() { }); }); it('最长字符串', function() { - var s = ''; - for(var i = 0; i < 2953; i++){ + var s = '0123456789'; + for(var i = 0; i < 295; i+=10){ s += i%10; } + s+='012'; var qrnode = new qrcode({ width:500, height:500, @@ -73,8 +84,9 @@ describe('qrcode', function() { }); it('超过最长字符串容错处理,截取前2953个字符', function() { var s = ''; - for(var i = 0; i < 3000; i++){ - s += i%10; + var t = '01234567890123456789'; + for(var i = 0; i < 150; i+=20){ + s += t; } var qrnode = new qrcode({ width:500,