-
Notifications
You must be signed in to change notification settings - Fork 10
/
codes.js
44 lines (33 loc) · 966 Bytes
/
codes.js
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
// BARCODE Writer (in pure postscript)
var BWIPJS = require("./bwip.js");
// CONFIGURE IN index.js
var types = require("./bwipp");
// ADAPTER png || canvas
var adapter = require("./png");
// FONTS
var fonts = require("./fonts");
exports.loadModules = function(modules, opts)
{
modules.forEach(function(m) {
types.addExport(m, opts ? opts : { "includetext":true, "guardwhitespace":false, "inkspread":0, scaleX:2, textyoffset:-15 });
});
}
exports.create = function( type, text, options )
{
// CODER AVAILABLE
var opts = ( types[ type ] ) ? options || types[ type ] : null;
// BAD REQUEST
if( !type || !text || !opts ) return null;
// DEFAULTS
var rot = opts.rot || "N";
var scaleX = opts.scaleX || 1;
var scaleY = opts.scaleY || 1;
// GENERATE
var bw = new BWIPJS();
bw.bitmap(new adapter);
bw.push(text);
bw.push(opts);
bw.scale(scaleX, scaleY);
bw.call(type);
return bw.bitmap().create(rot);
};