forked from lindell/JsBarcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (40 loc) · 1.38 KB
/
Copy pathmain.js
File metadata and controls
53 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;(function(exports){
var encoders = {}
function exportEncoder(module, name) {
if (require && !exports[name]) encoders[name] = exports[name] = require(module)[name]
}
exportEncoder('./EAN_UPC.js', 'EAN')
exportEncoder('./EAN_UPC.js', 'UPC')
exportEncoder('./CODE128.js', 'CODE128')
exports.renderer = function(content, options) {
var encoder = encoders[options.format] && new encoders[options.format](content);
this._content = content;
this._options = options;
this._valid = !!encoder && encoder.valid();
this._encoded = this._valid && encoder.encoded();
this.valid = function() {
return this._valid;
}
this.length = function() {
return this._encoded ? this._encoded.length : 0
}
this.width = function(barWidth, quietWidth) {
return this.length() * barWidth + 2 * quietWidth
}
this.render = function(ctx,x,y,w,h,quiet) {
var length = this.length(),
encoded = this._encoded,
quietWidth = quiet === undefined ? (10*w)/(length+20) : quiet,
renderWidth = w - 2*quietWidth,
barWidth = renderWidth/length,
i, x
for(i=0;i<length;i++){
if(encoded[i] == "1"){
ctx.fillRect((i/length)*renderWidth+quietWidth,y,barWidth,h);
}
}
}
return this
}
})(typeof exports === 'undefined' ? this['JsBarcode']=(this['JsBarcode'] || {}) : exports)
;