jsBarcode生成条形码

1.pc端/移动端生成条形码

html

 <svg id="svgcode">svg>
  <canvas id="canvascode">canvas>
  <img id="imgcode" />

js

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js">script>
<script src="./jsBarcode.js">script>

<script type="text/javascript">
  $("#svgcode").JsBarcode('123333'); 

  $("#canvascode").JsBarcode('234234234');

  $("#imgcode").JsBarcode("11111111");

script>

条形码样式设置

  JsBarcode("#barcode", "11111", {
    format: "pharmacode",
    lineColor: "red",
    width: 2,
    height: 40,
    displayValue: true
  });

2.小程序端生成条形码


<canvas canvas-id="barcode" />

var wxbarcode = require('../../utils/barcode.js');//文章底部有补充代码
Page({
    data: {
        code: '121211212',
    },
    onLoad: function (options) {
        this.barc('barcode', this.data.code, 680, 200);
    },
    barc(id, code, width, height) {
        wxbarcode.code128(wx.createCanvasContext(id), code, this.convert_length(width), this.convert_length(height))
    },
    convert_length(length) {
        return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
    },
})

补充说明

生成的条形码不能使用微信进行扫描使用,只能自己编写扫码功能,扫描携带的内容
如果要使用微信进行扫描显示商品需要:
1、去国家物品编码中心申请69商品条形码,费用自行查看。
2、申请好了之后,编码中心会给条码卡账号和密码,登陆国家后台进行备案。
3、1-2个工作日微信可以扫描出来,如果没显示,需要联系第3方。
#链接地址
##jsBarcode.js【pc/移动端】

/*! JsBarcode v3.11.0 | (c) Johan Lindell | MIT license */
!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=20)}([function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function t(e,n){r(this,t),this.data=e,this.text=n.text||e,this.options=n};e.default=o},function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}Object.defineProperty(e,"__esModule",{value:!0});var o,i=e.SET_A=0,u=e.SET_B=1,a=e.SET_C=2,f=(e.SHIFT=98,e.START_A=103),c=e.START_B=104,s=e.START_C=105;e.MODULO=103,e.STOP=106,e.FNC1=207,e.SET_BY_CODE=(o={},r(o,f,i),r(o,c,u),r(o,s,a),o),e.SWAP={101:i,100:u,99:a},e.A_START_CHAR=String.fromCharCode(208),e.B_START_CHAR=String.fromCharCode(209),e.C_START_CHAR=String.fromCharCode(210),e.A_CHARS="[\0-_È-Ï]",e.B_CHARS="[ -È-Ï]",e.C_CHARS="(Ï*[0-9]{2}Ï*)",e.BARS=[11011001100,11001101100,11001100110,10010011e3,10010001100,10001001100,10011001e3,10011000100,10001100100,11001001e3,11001000100,11000100100,10110011100,10011011100,10011001110,10111001100,10011101100,10011100110,11001110010,11001011100,11001001110,11011100100,11001110100,11101101110,11101001100,11100101100,11100100110,11101100100,11100110100,11100110010,11011011e3,11011000110,11000110110,10100011e3,10001011e3,10001000110,10110001e3,10001101e3,10001100010,11010001e3,11000101e3,11000100010,10110111e3,10110001110,10001101110,10111011e3,10111000110,10001110110,11101110110,11010001110,11000101110,11011101e3,11011100010,11011101110,11101011e3,11101000110,11100010110,11101101e3,11101100010,11100011010,11101111010,11001000010,11110001010,1010011e4,10100001100,1001011e4,10010000110,10000101100,10000100110,1011001e4,10110000100,1001101e4,10011000010,10000110100,10000110010,11000010010,1100101e4,11110111010,11000010100,10001111010,10100111100,10010111100,10010011110,10111100100,10011110100,10011110010,11110100100,11110010100,11110010010,11011011110,11011110110,11110110110,10101111e3,10100011110,10001011110,10111101e3,10111100010,11110101e3,11110100010,10111011110,10111101110,11101011110,11110101110,11010000100,1101001e4,11010011100,1100011101011]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.SIDE_BIN="101",e.MIDDLE_BIN="01010",e.BINARIES={L:["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],G:["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],R:["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],O:["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],E:["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"]},e.EAN2_STRUCTURE=["LL","LG","GL","GG"],e.EAN5_STRUCTURE=["GGLLL","GLGLL","GLLGL","GLLLG","LGGLL","LLGGL","LLLGG","LGLGL","LGLLG","LLGLG"],e.EAN13_STRUCTURE=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=function(t,e,n){var o=t.split("").map(function(t,n){return r.BINARIES[e[n]]}).map(function(e,n){return e?e[t[n]]:""});if(n){var i=t.length-1;o=o.map(function(t,e){return e=200){i=t.shift()-105;var u=c.SWAP[i];void 0!==u?o=e.next(t,n+1,u):(r!==c.SET_A&&r!==c.SET_B||i!==c.SHIFT||(t[0]=r===c.SET_A?t[0]>95?t[0]-96:t[0]:t[0]<32?t[0]+96:t[0]),o=e.next(t,n+1,r))}else i=e.correctIndex(t,r),o=e.next(t,n+1,r);var a=e.getBar(i),f=i*n;return{result:a+o.result,checksum:f+o.checksum}}}]),e}(f.default);e.default=s},function(t,e,n){"use strict";function r(t){for(var e=0,n=0;n10*n.width?10*n.width:n.fontSize,r.guardHeight=n.height+r.fontSize/2+n.textMargin,r}return u(e,t),a(e,[{key:"encode",value:function(){return this.options.flat?this.encodeFlat():this.encodeGuarded()}},{key:"leftText",value:function(t,e){return this.text.substr(t,e)}},{key:"leftEncode",value:function(t,e){return(0,s.default)(t,e)}},{key:"rightText",value:function(t,e){return this.text.substr(t,e)}},{key:"rightEncode",value:function(t,e){return(0,s.default)(t,e)}},{key:"encodeGuarded",value:function(){var t={fontSize:this.fontSize},e={height:this.guardHeight};return[{data:f.SIDE_BIN,options:e},{data:this.leftEncode(),text:this.leftText(),options:t},{data:f.MIDDLE_BIN,options:e},{data:this.rightEncode(),text:this.rightText(),options:t},{data:f.SIDE_BIN,options:e}]}},{key:"encodeFlat",value:function(){return{data:[f.SIDE_BIN,this.leftEncode(),f.MIDDLE_BIN,this.rightEncode(),f.SIDE_BIN].join(""),text:this.text}}}]),e}(p.default);e.default=d},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(t){var e,n=0;for(e=1;e<11;e+=2)n+=parseInt(t[e]);for(e=0;e<11;e+=2)n+=3*parseInt(t[e]);return(10-n%10)%10}Object.defineProperty(e,"__esModule",{value:!0});var f=function(){function t(t,e){for(var n=0;n10*n.width?r.fontSize=10*n.width:r.fontSize=n.fontSize,r.guardHeight=n.height+r.fontSize/2+n.textMargin,r}return u(e,t),f(e,[{key:"valid",value:function(){return-1!==this.data.search(/^[0-9]{12}$/)&&this.data[11]==a(this.data)}},{key:"encode",value:function(){return this.options.flat?this.flatEncoding():this.guardedEncoding()}},{key:"flatEncoding",value:function(){var t="";return t+="101",t+=(0,s.default)(this.data.substr(0,6),"LLLLLL"),t+="01010",t+=(0,s.default)(this.data.substr(6,6),"RRRRRR"),t+="101",{data:t,text:this.text}}},{key:"guardedEncoding",value:function(){var t=[];return this.displayValue&&t.push({data:"00000000",text:this.text.substr(0,1),options:{textAlign:"left",fontSize:this.fontSize}}),t.push({data:"101"+(0,s.default)(this.data[0],"L"),options:{height:this.guardHeight}}),t.push({data:(0,s.default)(this.data.substr(1,5),"LLLLL"),text:this.text.substr(1,5),options:{fontSize:this.fontSize}}),t.push({data:"01010",options:{height:this.guardHeight}}),t.push({data:(0,s.default)(this.data.substr(6,5),"RRRRR"),text:this.text.substr(6,5),options:{fontSize:this.fontSize}}),t.push({data:(0,s.default)(this.data[11],"R")+"101",options:{height:this.guardHeight}}),this.displayValue&&t.push({data:"00000000",text:this.text.substr(11,1),options:{textAlign:"right",fontSize:this.fontSize}}),t}}]),e}(p.default);e.default=d},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var u=function(){function t(t,e){for(var n=0;n0?e.fontSize+e.textMargin:0)+e.marginTop+e.marginBottom}function o(t,e,n){if(n.displayValue&&e<t.length;n++)t[n].height>e&&(e=t[n].height);return e}function f(t,e,n){var r;if(n)r=n;else{if("undefined"==typeof document)return 0;r=document.createElement("canvas").getContext("2d")}return r.font=e.fontOptions+" "+e.fontSize+"px "+e.font,r.measureText(t).width}Object.defineProperty(e,"__esModule",{value:!0}),e.getTotalWidthOfEncodings=e.calculateEncodingAttributes=e.getBarcodePadding=e.getEncodingHeight=e.getMaximumHeightOfEncodings=void 0;var c=n(5),s=function(t){return t&&t.__esModule?t:{default:t}}(c);e.getMaximumHeightOfEncodings=a,e.getEncodingHeight=r,e.getBarcodePadding=o,e.calculateEncodingAttributes=i,e.getTotalWidthOfEncodings=u},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(27),o=n(26),i=n(33),u=n(37),a=n(42),f=n(44),c=n(43),s=n(34);e.default={CODE39:r.CODE39,CODE128:o.CODE128,CODE128A:o.CODE128A,CODE128B:o.CODE128B,CODE128C:o.CODE128C,EAN13:i.EAN13,EAN8:i.EAN8,EAN5:i.EAN5,EAN2:i.EAN2,UPC:i.UPC,UPCE:i.UPCE,ITF14:u.ITF14,ITF:u.ITF,MSI:a.MSI,MSI10:a.MSI10,MSI11:a.MSI11,MSI1010:a.MSI1010,MSI1110:a.MSI1110,pharmacode:f.pharmacode,codabar:c.codabar,GenericBarcode:s.GenericBarcode}},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n=a(t);return e+String.fromCharCode(o?206:205)+r(t,o)}Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),u=function(t){return t.match(new RegExp("^"+i.A_CHARS+"*"))[0].length},a=function(t){return t.match(new RegExp("^"+i.B_CHARS+"*"))[0].length},f=function(t){return t.match(new RegExp("^"+i.C_CHARS+"*"))[0]};e.default=function(t){var e=void 0;if(f(t).length>=2)e=i.C_START_CHAR+o(t);else{var n=u(t)>a(t);e=(n?i.A_START_CHAR:i.B_START_CHAR)+r(t,n)}return e.replace(/[\xCD\xCE]([^])[\xCD\xCE]/,function(t,e){return String.fromCharCode(203)+e})}},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.CODE128C=e.CODE128B=e.CODE128A=e.CODE128=void 0;var o=n(24),i=r(o),u=n(21),a=r(u),f=n(22),c=r(f),s=n(23),l=r(s);e.CODE128=i.default,e.CODE128A=a.default,e.CODE128B=c.default,e.CODE128C=l.default},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function u(t){return a(c(t))}function a(t){return b[t].toString(2)}function f(t){return y[t]}function c(t){return y.indexOf(t)}function s(t){for(var e=0,n=0;n10*n.width?r.fontSize=10*n.width:r.fontSize=n.fontSize,r.guardHeight=n.height+r.fontSize/2+n.textMargin,r}return u(e,t),f(e,[{key:"valid",value:function(){return this.isValid}},{key:"encode",value:function(){return this.options.flat?this.flatEncoding():this.guardedEncoding()}},{key:"flatEncoding",value:function(){var t="";return t+="101",t+=this.encodeMiddleDigits(),t+="010101",{data:t,text:this.text}}},{key:"guardedEncoding",value:function(){var t=[];return this.displayValue&&t.push({data:"00000000",text:this.text[0],options:{textAlign:"left",fontSize:this.fontSize}}),t.push({data:"101",options:{height:this.guardHeight}}),t.push({data:this.encodeMiddleDigits(),text:this.text.substring(1,7),options:{fontSize:this.fontSize}}),t.push({data:"010101",options:{height:this.guardHeight}}),this.displayValue&&t.push({data:"00000000",text:this.text[7],options:{textAlign:"right",fontSize:this.fontSize}}),t}},{key:"encodeMiddleDigits",value:function(){var t=this.upcA[0],e=this.upcA[this.upcA.length-1],n=y[parseInt(e)][parseInt(t)];return(0,s.default)(this.middleDigits,n)}}]),e}(p.default);e.default=b},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.UPCE=e.UPC=e.EAN2=e.EAN5=e.EAN8=e.EAN13=void 0;var o=n(28),i=r(o),u=n(31),a=r(u),f=n(30),c=r(f),s=n(29),l=r(s),p=n(12),d=r(p),h=n(32),y=r(h);e.EAN13=i.default,e.EAN8=a.default,e.EAN5=c.default,e.EAN2=l.default,e.UPC=d.default,e.UPCE=y.default},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),e.GenericBarcode=void 0;var u=function(){function t(t,e){for(var n=0;n=3&&this.number<=131070}}]),e}(f.default);e.pharmacode=c},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t){var e={};for(var n in f.default)f.default.hasOwnProperty(n)&&(t.hasAttribute("jsbarcode-"+n.toLowerCase())&&(e[n]=t.getAttribute("jsbarcode-"+n.toLowerCase())),t.hasAttribute("data-"+n.toLowerCase())&&(e[n]=t.getAttribute("data-"+n.toLowerCase())));return e.value=t.getAttribute("jsbarcode-value")||t.getAttribute("data-value"),e=(0,u.default)(e)}Object.defineProperty(e,"__esModule",{value:!0});var i=n(9),u=r(i),a=n(10),f=r(a);e.default=o},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n0?(o=0,n.textAlign="left"):"right"==t.textAlign?(o=e.width-1,n.textAlign="right"):(o=e.width/2,n.textAlign="center"),n.fillText(e.text,o,i)}}},{key:"moveCanvasDrawing",value:function(t){this.canvas.getContext("2d").translate(t.width,0)}},{key:"restoreCanvas",value:function(){this.canvas.getContext("2d").restore()}}]),t}();e.default=f},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(46),i=r(o),u=n(49),a=r(u),f=n(48),c=r(f);e.default={CanvasRenderer:i.default,SVGRenderer:a.default,ObjectRenderer:c.default}},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n0&&(this.drawRect(u-e.width*i,r,e.width*i,e.height,t),i=0);i>0&&this.drawRect(u-e.width*(i-1),r,e.width*i,e.height,t)}},{key:"drawSVGText",value:function(t,e,n){var r=this.document.createElementNS(f,"text");if(e.displayValue){var o,i;r.setAttribute("style","font:"+e.fontOptions+" "+e.fontSize+"px "+e.font),i="top"==e.textPosition?e.fontSize-e.textMargin:e.height+e.textMargin+e.fontSize,"left"==e.textAlign||n.barcodePadding>0?(o=0,r.setAttribute("text-anchor","start")):"right"==e.textAlign?(o=n.width-1,r.setAttribute("text-anchor","end")):(o=n.width/2,r.setAttribute("text-anchor","middle")),r.setAttribute("x",o),r.setAttribute("y",i),r.appendChild(this.document.createTextNode(n.text)),t.appendChild(r)}}},{key:"setSvgAttributes",value:function(t,e){var n=this.svg;n.setAttribute("width",t+"px"),n.setAttribute("height",e+"px"),n.setAttribute("x","0px"),n.setAttribute("y","0px"),n.setAttribute("viewBox","0 0 "+t+" "+e),n.setAttribute("xmlns",f),n.setAttribute("version","1.1"),n.setAttribute("style","transform: translate(0,0)")}},{key:"createGroup",value:function(t,e,n){var r=this.document.createElementNS(f,"g");return r.setAttribute("transform","translate("+t+", "+e+")"),n.appendChild(r),r}},{key:"setGroupOptions",value:function(t,e){t.setAttribute("style","fill:"+e.lineColor+";")}},{key:"drawRect",value:function(t,e,n,r,o){var i=this.document.createElementNS(f,"rect");return i.setAttribute("x",t),i.setAttribute("y",e),i.setAttribute("width",n),i.setAttribute("height",r),o.appendChild(i),i}}]),t}();e.default=c}]);

barcode.js【小程序】

var CHAR_TILDE=126;var CODE_FNC1=102;var SET_STARTA=103;var SET_STARTB=104;var SET_STARTC=105;var SET_SHIFT=98;var SET_CODEA=101;var SET_CODEB=100;var SET_STOP=106;var REPLACE_CODES={CHAR_TILDE:CODE_FNC1};var CODESET={ANY:1,AB:2,A:3,B:4,C:5};function getBytes(str){var bytes=[];for(var i=0;i0){g.fillFgRect(x,y,barW,barH)}x+=barW+spcW}}ctx.draw()};function stringToCode128(text){var barc={currcs:CODESET.C};var bytes=getBytes(text);var index=bytes[0]==CHAR_TILDE?1:0;var csa1=bytes.length>0?codeSetAllowedFor(bytes[index++]):CODESET.AB;var csa2=bytes.length>0?codeSetAllowedFor(bytes[index++]):CODESET.AB;barc.currcs=getBestStartSet(csa1,csa2);barc.currcs=perhapsCodeC(bytes,barc.currcs);var codes=new Array();switch(barc.currcs){case CODESET.A:codes.push(SET_STARTA);break;case CODESET.B:codes.push(SET_STARTB);break;default:codes.push(SET_STARTC);break}for(var i=0;i<bytes.length;i++){var b1=bytes[i];if(b1 in REPLACE_CODES){codes.push(REPLACE_CODES[b1]);i++;b1=bytes[i]}var b2=bytes.length>(i+1)?bytes[i+1]:-1;codes=codes.concat(codesForChar(b1,b2,barc.currcs));if(barc.currcs==CODESET.C){i++}}var checksum=codes[0];for(var weight=1;weight0?CODESET.A:CODESET.B}function perhapsCodeC(bytes,codeset){for(var i=0;i<bytes.length;i++){var b=bytes[i];if((b<48||b>57)&&b!=CHAR_TILDE){return codeset}}return CODESET.C}function codesForChar(chr1,chr2,currcs){var result=[];var shifter=-1;if(charCompatible(chr1,currcs)){if(currcs==CODESET.C){if(chr2==-1){shifter=SET_CODEB;currcs=CODESET.B}else{if((chr2!=-1)&&!charCompatible(chr2,currcs)){if(charCompatible(chr2,CODESET.A)){shifter=SET_CODEA;currcs=CODESET.A}else{shifter=SET_CODEB;currcs=CODESET.B}}}}}else{if((chr2!=-1)&&!charCompatible(chr2,currcs)){switch(currcs){case CODESET.A:shifter=SET_CODEB;currcs=CODESET.B;break;case CODESET.B:shifter=SET_CODEA;currcs=CODESET.A;break}}else{shifter=SET_SHIFT}}if(shifter!=-1){result.push(shifter);result.push(codeValue(chr1))}else{if(currcs==CODESET.C){result.push(codeValue(chr1,chr2))}else{result.push(codeValue(chr1))}}barc.currcs=currcs;return result}}function codeValue(chr1,chr2){if(typeof chr2=="undefined"){return chr1>=32?chr1-32:chr1+64}else{return parseInt(String.fromCharCode(chr1)+String.fromCharCode(chr2))}}function charCompatible(chr,codeset){var csa=codeSetAllowedFor(chr);if(csa==CODESET.ANY){return true}if(csa==CODESET.AB){return true}if(csa==CODESET.A&&codeset==CODESET.A){return true}if(csa==CODESET.B&&codeset==CODESET.B){return true}return false}function codeSetAllowedFor(chr){if(chr>=48&&chr<=57){return CODESET.ANY}else{if(chr>=32&&chr<=95){return CODESET.AB}else{return chr<32?CODESET.A:CODESET.B}}}var Graphics=function(ctx,width,height){this.width=width;this.height=height;this.quiet=Math.round(this.width/40);this.border_size=0;this.padding_width=0;this.area={width:width-this.padding_width*2-this.quiet*2,height:height-this.border_size*2,top:this.border_size-4,left:this.padding_width+this.quiet};this.ctx=ctx;this.fg="#000000";this.bg="#ffffff";this.fillBgRect(0,0,width,height);this.fillBgRect(0,this.border_size,width,height-this.border_size*2)};Graphics.prototype._fillRect=function(x,y,width,height,color){this.ctx.setFillStyle(color);this.ctx.fillRect(x,y,width,height)};Graphics.prototype.fillFgRect=function(x,y,width,height){this._fillRect(x,y,width,height,this.fg)};Graphics.prototype.fillBgRect=function(x,y,width,height){this._fillRect(x,y,width,height,this.bg)};var PATTERNS=[[2,1,2,2,2,2,0,0],[2,2,2,1,2,2,0,0],[2,2,2,2,2,1,0,0],[1,2,1,2,2,3,0,0],[1,2,1,3,2,2,0,0],[1,3,1,2,2,2,0,0],[1,2,2,2,1,3,0,0],[1,2,2,3,1,2,0,0],[1,3,2,2,1,2,0,0],[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