yh-hiprint 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiprintDesigner.vue +5 -5
- package/column-field.js +1 -3
- package/designer.vue +4 -4
- package/font-size.js +2 -3
- package/index.js +1 -2
- package/libs/hiprint.bundle.js +331 -335
- package/libs/jquery.js +1 -2
- package/libs/jsbarcode/JsBarcode.js +251 -0
- package/libs/jsbarcode/barcodes/Barcode.js +17 -0
- package/libs/jsbarcode/barcodes/CODE128/CODE128.js +167 -0
- package/libs/jsbarcode/barcodes/CODE128/CODE128A.js +42 -0
- package/libs/jsbarcode/barcodes/CODE128/CODE128B.js +42 -0
- package/libs/jsbarcode/barcodes/CODE128/CODE128C.js +42 -0
- package/libs/jsbarcode/barcodes/CODE128/CODE128_AUTO.js +41 -0
- package/libs/jsbarcode/barcodes/CODE128/auto.js +73 -0
- package/libs/jsbarcode/barcodes/CODE128/constants.js +54 -0
- package/libs/jsbarcode/barcodes/CODE128/index.js +29 -0
- package/libs/jsbarcode/barcodes/CODE39/index.js +105 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN.js +92 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN13.js +119 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN2.js +58 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN5.js +65 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN8.js +81 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/UPC.js +165 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/UPCE.js +185 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/constants.js +30 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/encoder.js +27 -0
- package/libs/jsbarcode/barcodes/EAN_UPC/index.js +39 -0
- package/libs/jsbarcode/barcodes/GenericBarcode/index.js +55 -0
- package/libs/jsbarcode/barcodes/ITF/ITF.js +69 -0
- package/libs/jsbarcode/barcodes/ITF/ITF14.js +55 -0
- package/libs/jsbarcode/barcodes/ITF/constants.js +9 -0
- package/libs/jsbarcode/barcodes/ITF/index.js +19 -0
- package/libs/jsbarcode/barcodes/MSI/MSI.js +74 -0
- package/libs/jsbarcode/barcodes/MSI/MSI10.js +33 -0
- package/libs/jsbarcode/barcodes/MSI/MSI1010.js +35 -0
- package/libs/jsbarcode/barcodes/MSI/MSI11.js +33 -0
- package/libs/jsbarcode/barcodes/MSI/MSI1110.js +35 -0
- package/libs/jsbarcode/barcodes/MSI/checksums.js +29 -0
- package/libs/jsbarcode/barcodes/MSI/index.js +34 -0
- package/libs/jsbarcode/barcodes/codabar/index.js +92 -0
- package/libs/jsbarcode/barcodes/index.js +33 -0
- package/libs/jsbarcode/barcodes/index.tmp.js +33 -0
- package/libs/jsbarcode/barcodes/pharmacode/index.js +73 -0
- package/libs/jsbarcode/exceptions/ErrorHandler.js +54 -0
- package/libs/jsbarcode/exceptions/exceptions.js +67 -0
- package/libs/jsbarcode/help/fixOptions.js +17 -0
- package/libs/jsbarcode/help/getOptionsFromElement.js +41 -0
- package/libs/jsbarcode/help/getRenderProperties.js +108 -0
- package/libs/jsbarcode/help/linearizeEncodings.js +27 -0
- package/libs/jsbarcode/help/merge.js +11 -0
- package/libs/jsbarcode/help/optionsFromStrings.js +27 -0
- package/libs/jsbarcode/options/defaults.js +28 -0
- package/libs/jsbarcode/renderers/canvas.js +158 -0
- package/libs/jsbarcode/renderers/index.js +21 -0
- package/libs/jsbarcode/renderers/object.js +30 -0
- package/libs/jsbarcode/renderers/shared.js +101 -0
- package/libs/jsbarcode/renderers/svg.js +189 -0
- package/libs/plugins/jquery.hiwprint.js +9 -10
- package/libs/plugins/jquery.minicolors.js +65 -66
- package/package.json +1 -3
- package/z-index.js +2 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _optionsFromStrings = require("./optionsFromStrings.js");
|
|
8
|
+
|
|
9
|
+
var _optionsFromStrings2 = _interopRequireDefault(_optionsFromStrings);
|
|
10
|
+
|
|
11
|
+
var _defaults = require("../options/defaults.js");
|
|
12
|
+
|
|
13
|
+
var _defaults2 = _interopRequireDefault(_defaults);
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
function getOptionsFromElement(element) {
|
|
18
|
+
var options = {};
|
|
19
|
+
for (var property in _defaults2.default) {
|
|
20
|
+
if (_defaults2.default.hasOwnProperty(property)) {
|
|
21
|
+
// jsbarcode-*
|
|
22
|
+
if (element.hasAttribute("jsbarcode-" + property.toLowerCase())) {
|
|
23
|
+
options[property] = element.getAttribute("jsbarcode-" + property.toLowerCase());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// data-*
|
|
27
|
+
if (element.hasAttribute("data-" + property.toLowerCase())) {
|
|
28
|
+
options[property] = element.getAttribute("data-" + property.toLowerCase());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
options["value"] = element.getAttribute("jsbarcode-value") || element.getAttribute("data-value");
|
|
34
|
+
|
|
35
|
+
// Since all atributes are string they need to be converted to integers
|
|
36
|
+
options = (0, _optionsFromStrings2.default)(options);
|
|
37
|
+
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.default = getOptionsFromElement;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /* global HTMLImageElement */
|
|
8
|
+
/* global HTMLCanvasElement */
|
|
9
|
+
/* global SVGElement */
|
|
10
|
+
|
|
11
|
+
var _getOptionsFromElement = require("./getOptionsFromElement.js");
|
|
12
|
+
|
|
13
|
+
var _getOptionsFromElement2 = _interopRequireDefault(_getOptionsFromElement);
|
|
14
|
+
|
|
15
|
+
var _renderers = require("../renderers");
|
|
16
|
+
|
|
17
|
+
var _renderers2 = _interopRequireDefault(_renderers);
|
|
18
|
+
|
|
19
|
+
var _exceptions = require("../exceptions/exceptions.js");
|
|
20
|
+
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
|
|
23
|
+
// Takes an element and returns an object with information about how
|
|
24
|
+
// it should be rendered
|
|
25
|
+
// This could also return an array with these objects
|
|
26
|
+
// {
|
|
27
|
+
// element: The element that the renderer should draw on
|
|
28
|
+
// renderer: The name of the renderer
|
|
29
|
+
// afterRender (optional): If something has to done after the renderer
|
|
30
|
+
// completed, calls afterRender (function)
|
|
31
|
+
// options (optional): Options that can be defined in the element
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
function getRenderProperties(element) {
|
|
35
|
+
// If the element is a string, query select call again
|
|
36
|
+
if (typeof element === "string") {
|
|
37
|
+
return querySelectedRenderProperties(element);
|
|
38
|
+
}
|
|
39
|
+
// If element is array. Recursivly call with every object in the array
|
|
40
|
+
else if (Array.isArray(element)) {
|
|
41
|
+
var returnArray = [];
|
|
42
|
+
for (var i = 0; i < element.length; i++) {
|
|
43
|
+
returnArray.push(getRenderProperties(element[i]));
|
|
44
|
+
}
|
|
45
|
+
return returnArray;
|
|
46
|
+
}
|
|
47
|
+
// If element, render on canvas and set the uri as src
|
|
48
|
+
else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLImageElement) {
|
|
49
|
+
return newCanvasRenderProperties(element);
|
|
50
|
+
}
|
|
51
|
+
// If SVG
|
|
52
|
+
else if (element && element.nodeName && element.nodeName.toLowerCase() === 'svg' || typeof SVGElement !== 'undefined' && element instanceof SVGElement) {
|
|
53
|
+
return {
|
|
54
|
+
element: element,
|
|
55
|
+
options: (0, _getOptionsFromElement2.default)(element),
|
|
56
|
+
renderer: _renderers2.default.SVGRenderer
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// If canvas (in browser)
|
|
60
|
+
else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLCanvasElement) {
|
|
61
|
+
return {
|
|
62
|
+
element: element,
|
|
63
|
+
options: (0, _getOptionsFromElement2.default)(element),
|
|
64
|
+
renderer: _renderers2.default.CanvasRenderer
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// If canvas (in node)
|
|
68
|
+
else if (element && element.getContext) {
|
|
69
|
+
return {
|
|
70
|
+
element: element,
|
|
71
|
+
renderer: _renderers2.default.CanvasRenderer
|
|
72
|
+
};
|
|
73
|
+
} else if (element && (typeof element === "undefined" ? "undefined" : _typeof(element)) === 'object' && !element.nodeName) {
|
|
74
|
+
return {
|
|
75
|
+
element: element,
|
|
76
|
+
renderer: _renderers2.default.ObjectRenderer
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
throw new _exceptions.InvalidElementException();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function querySelectedRenderProperties(string) {
|
|
84
|
+
var selector = document.querySelectorAll(string);
|
|
85
|
+
if (selector.length === 0) {
|
|
86
|
+
return undefined;
|
|
87
|
+
} else {
|
|
88
|
+
var returnArray = [];
|
|
89
|
+
for (var i = 0; i < selector.length; i++) {
|
|
90
|
+
returnArray.push(getRenderProperties(selector[i]));
|
|
91
|
+
}
|
|
92
|
+
return returnArray;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function newCanvasRenderProperties(imgElement) {
|
|
97
|
+
var canvas = document.createElement('canvas');
|
|
98
|
+
return {
|
|
99
|
+
element: canvas,
|
|
100
|
+
options: (0, _getOptionsFromElement2.default)(imgElement),
|
|
101
|
+
renderer: _renderers2.default.CanvasRenderer,
|
|
102
|
+
afterRender: function afterRender() {
|
|
103
|
+
imgElement.setAttribute("src", canvas.toDataURL());
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.default = getRenderProperties;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = linearizeEncodings;
|
|
7
|
+
|
|
8
|
+
// Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2]
|
|
9
|
+
// Convert to [1-1, 1-2, 2, 3-1, 3-2]
|
|
10
|
+
|
|
11
|
+
function linearizeEncodings(encodings) {
|
|
12
|
+
var linearEncodings = [];
|
|
13
|
+
function nextLevel(encoded) {
|
|
14
|
+
if (Array.isArray(encoded)) {
|
|
15
|
+
for (var i = 0; i < encoded.length; i++) {
|
|
16
|
+
nextLevel(encoded[i]);
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
encoded.text = encoded.text || "";
|
|
20
|
+
encoded.data = encoded.data || "";
|
|
21
|
+
linearEncodings.push(encoded);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
nextLevel(encodings);
|
|
25
|
+
|
|
26
|
+
return linearEncodings;
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
+
|
|
9
|
+
exports.default = function (old, replaceObj) {
|
|
10
|
+
return _extends({}, old, replaceObj);
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = optionsFromStrings;
|
|
7
|
+
|
|
8
|
+
// Convert string to integers/booleans where it should be
|
|
9
|
+
|
|
10
|
+
function optionsFromStrings(options) {
|
|
11
|
+
var intOptions = ["width", "height", "textMargin", "fontSize", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight"];
|
|
12
|
+
|
|
13
|
+
for (var intOption in intOptions) {
|
|
14
|
+
if (intOptions.hasOwnProperty(intOption)) {
|
|
15
|
+
intOption = intOptions[intOption];
|
|
16
|
+
if (typeof options[intOption] === "string") {
|
|
17
|
+
options[intOption] = parseInt(options[intOption], 10);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (typeof options["displayValue"] === "string") {
|
|
23
|
+
options["displayValue"] = options["displayValue"] != "false";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var defaults = {
|
|
7
|
+
width: 2,
|
|
8
|
+
height: 100,
|
|
9
|
+
format: "auto",
|
|
10
|
+
displayValue: true,
|
|
11
|
+
fontOptions: "",
|
|
12
|
+
font: "monospace",
|
|
13
|
+
text: undefined,
|
|
14
|
+
textAlign: "center",
|
|
15
|
+
textPosition: "bottom",
|
|
16
|
+
textMargin: 2,
|
|
17
|
+
fontSize: 20,
|
|
18
|
+
background: "#ffffff",
|
|
19
|
+
lineColor: "#000000",
|
|
20
|
+
margin: 10,
|
|
21
|
+
marginTop: undefined,
|
|
22
|
+
marginBottom: undefined,
|
|
23
|
+
marginLeft: undefined,
|
|
24
|
+
marginRight: undefined,
|
|
25
|
+
valid: function valid() {}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.default = defaults;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
var _merge = require("../help/merge.js");
|
|
10
|
+
|
|
11
|
+
var _merge2 = _interopRequireDefault(_merge);
|
|
12
|
+
|
|
13
|
+
var _shared = require("./shared.js");
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
|
+
|
|
19
|
+
var CanvasRenderer = function () {
|
|
20
|
+
function CanvasRenderer(canvas, encodings, options) {
|
|
21
|
+
_classCallCheck(this, CanvasRenderer);
|
|
22
|
+
|
|
23
|
+
this.canvas = canvas;
|
|
24
|
+
this.encodings = encodings;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_createClass(CanvasRenderer, [{
|
|
29
|
+
key: "render",
|
|
30
|
+
value: function render() {
|
|
31
|
+
// Abort if the browser does not support HTML5 canvas
|
|
32
|
+
if (!this.canvas.getContext) {
|
|
33
|
+
throw new Error('The browser does not support canvas.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.prepareCanvas();
|
|
37
|
+
for (var i = 0; i < this.encodings.length; i++) {
|
|
38
|
+
var encodingOptions = (0, _merge2.default)(this.options, this.encodings[i].options);
|
|
39
|
+
|
|
40
|
+
this.drawCanvasBarcode(encodingOptions, this.encodings[i]);
|
|
41
|
+
this.drawCanvasText(encodingOptions, this.encodings[i]);
|
|
42
|
+
|
|
43
|
+
this.moveCanvasDrawing(this.encodings[i]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.restoreCanvas();
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "prepareCanvas",
|
|
50
|
+
value: function prepareCanvas() {
|
|
51
|
+
// Get the canvas context
|
|
52
|
+
var ctx = this.canvas.getContext("2d");
|
|
53
|
+
|
|
54
|
+
ctx.save();
|
|
55
|
+
|
|
56
|
+
(0, _shared.calculateEncodingAttributes)(this.encodings, this.options, ctx);
|
|
57
|
+
var totalWidth = (0, _shared.getTotalWidthOfEncodings)(this.encodings);
|
|
58
|
+
var maxHeight = (0, _shared.getMaximumHeightOfEncodings)(this.encodings);
|
|
59
|
+
|
|
60
|
+
this.canvas.width = totalWidth + this.options.marginLeft + this.options.marginRight;
|
|
61
|
+
|
|
62
|
+
this.canvas.height = maxHeight;
|
|
63
|
+
|
|
64
|
+
// Paint the canvas
|
|
65
|
+
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
66
|
+
if (this.options.background) {
|
|
67
|
+
ctx.fillStyle = this.options.background;
|
|
68
|
+
ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ctx.translate(this.options.marginLeft, 0);
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "drawCanvasBarcode",
|
|
75
|
+
value: function drawCanvasBarcode(options, encoding) {
|
|
76
|
+
// Get the canvas context
|
|
77
|
+
var ctx = this.canvas.getContext("2d");
|
|
78
|
+
|
|
79
|
+
var binary = encoding.data;
|
|
80
|
+
|
|
81
|
+
// Creates the barcode out of the encoded binary
|
|
82
|
+
var yFrom;
|
|
83
|
+
if (options.textPosition == "top") {
|
|
84
|
+
yFrom = options.marginTop + options.fontSize + options.textMargin;
|
|
85
|
+
} else {
|
|
86
|
+
yFrom = options.marginTop;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
ctx.fillStyle = options.lineColor;
|
|
90
|
+
|
|
91
|
+
for (var b = 0; b < binary.length; b++) {
|
|
92
|
+
var x = b * options.width + encoding.barcodePadding;
|
|
93
|
+
|
|
94
|
+
if (binary[b] === "1") {
|
|
95
|
+
ctx.fillRect(x, yFrom, options.width, options.height);
|
|
96
|
+
} else if (binary[b]) {
|
|
97
|
+
ctx.fillRect(x, yFrom, options.width, options.height * binary[b]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "drawCanvasText",
|
|
103
|
+
value: function drawCanvasText(options, encoding) {
|
|
104
|
+
// Get the canvas context
|
|
105
|
+
var ctx = this.canvas.getContext("2d");
|
|
106
|
+
|
|
107
|
+
var font = options.fontOptions + " " + options.fontSize + "px " + options.font;
|
|
108
|
+
|
|
109
|
+
// Draw the text if displayValue is set
|
|
110
|
+
if (options.displayValue) {
|
|
111
|
+
var x, y;
|
|
112
|
+
|
|
113
|
+
if (options.textPosition == "top") {
|
|
114
|
+
y = options.marginTop + options.fontSize - options.textMargin;
|
|
115
|
+
} else {
|
|
116
|
+
y = options.height + options.textMargin + options.marginTop + options.fontSize;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ctx.font = font;
|
|
120
|
+
|
|
121
|
+
// Draw the text in the correct X depending on the textAlign option
|
|
122
|
+
if (options.textAlign == "left" || encoding.barcodePadding > 0) {
|
|
123
|
+
x = 0;
|
|
124
|
+
ctx.textAlign = 'left';
|
|
125
|
+
} else if (options.textAlign == "right") {
|
|
126
|
+
x = encoding.width - 1;
|
|
127
|
+
ctx.textAlign = 'right';
|
|
128
|
+
}
|
|
129
|
+
// In all other cases, center the text
|
|
130
|
+
else {
|
|
131
|
+
x = encoding.width / 2;
|
|
132
|
+
ctx.textAlign = 'center';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
ctx.fillText(encoding.text, x, y);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
key: "moveCanvasDrawing",
|
|
140
|
+
value: function moveCanvasDrawing(encoding) {
|
|
141
|
+
var ctx = this.canvas.getContext("2d");
|
|
142
|
+
|
|
143
|
+
ctx.translate(encoding.width, 0);
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "restoreCanvas",
|
|
147
|
+
value: function restoreCanvas() {
|
|
148
|
+
// Get the canvas context
|
|
149
|
+
var ctx = this.canvas.getContext("2d");
|
|
150
|
+
|
|
151
|
+
ctx.restore();
|
|
152
|
+
}
|
|
153
|
+
}]);
|
|
154
|
+
|
|
155
|
+
return CanvasRenderer;
|
|
156
|
+
}();
|
|
157
|
+
|
|
158
|
+
exports.default = CanvasRenderer;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _canvas = require('./canvas.js');
|
|
8
|
+
|
|
9
|
+
var _canvas2 = _interopRequireDefault(_canvas);
|
|
10
|
+
|
|
11
|
+
var _svg = require('./svg.js');
|
|
12
|
+
|
|
13
|
+
var _svg2 = _interopRequireDefault(_svg);
|
|
14
|
+
|
|
15
|
+
var _object = require('./object.js');
|
|
16
|
+
|
|
17
|
+
var _object2 = _interopRequireDefault(_object);
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
exports.default = { CanvasRenderer: _canvas2.default, SVGRenderer: _svg2.default, ObjectRenderer: _object2.default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
+
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
|
|
11
|
+
var ObjectRenderer = function () {
|
|
12
|
+
function ObjectRenderer(object, encodings, options) {
|
|
13
|
+
_classCallCheck(this, ObjectRenderer);
|
|
14
|
+
|
|
15
|
+
this.object = object;
|
|
16
|
+
this.encodings = encodings;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_createClass(ObjectRenderer, [{
|
|
21
|
+
key: "render",
|
|
22
|
+
value: function render() {
|
|
23
|
+
this.object.encodings = this.encodings;
|
|
24
|
+
}
|
|
25
|
+
}]);
|
|
26
|
+
|
|
27
|
+
return ObjectRenderer;
|
|
28
|
+
}();
|
|
29
|
+
|
|
30
|
+
exports.default = ObjectRenderer;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTotalWidthOfEncodings = exports.calculateEncodingAttributes = exports.getBarcodePadding = exports.getEncodingHeight = exports.getMaximumHeightOfEncodings = undefined;
|
|
7
|
+
|
|
8
|
+
var _merge = require("../help/merge.js");
|
|
9
|
+
|
|
10
|
+
var _merge2 = _interopRequireDefault(_merge);
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function getEncodingHeight(encoding, options) {
|
|
15
|
+
return options.height + (options.displayValue && encoding.text.length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getBarcodePadding(textWidth, barcodeWidth, options) {
|
|
19
|
+
if (options.displayValue && barcodeWidth < textWidth) {
|
|
20
|
+
if (options.textAlign == "center") {
|
|
21
|
+
return Math.floor((textWidth - barcodeWidth) / 2);
|
|
22
|
+
} else if (options.textAlign == "left") {
|
|
23
|
+
return 0;
|
|
24
|
+
} else if (options.textAlign == "right") {
|
|
25
|
+
return Math.floor(textWidth - barcodeWidth);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function calculateEncodingAttributes(encodings, barcodeOptions, context) {
|
|
32
|
+
for (var i = 0; i < encodings.length; i++) {
|
|
33
|
+
var encoding = encodings[i];
|
|
34
|
+
var options = (0, _merge2.default)(barcodeOptions, encoding.options);
|
|
35
|
+
|
|
36
|
+
// Calculate the width of the encoding
|
|
37
|
+
var textWidth;
|
|
38
|
+
if (options.displayValue) {
|
|
39
|
+
textWidth = messureText(encoding.text, options, context);
|
|
40
|
+
} else {
|
|
41
|
+
textWidth = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var barcodeWidth = encoding.data.length * options.width;
|
|
45
|
+
encoding.width = Math.ceil(Math.max(textWidth, barcodeWidth));
|
|
46
|
+
|
|
47
|
+
encoding.height = getEncodingHeight(encoding, options);
|
|
48
|
+
|
|
49
|
+
encoding.barcodePadding = getBarcodePadding(textWidth, barcodeWidth, options);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getTotalWidthOfEncodings(encodings) {
|
|
54
|
+
var totalWidth = 0;
|
|
55
|
+
for (var i = 0; i < encodings.length; i++) {
|
|
56
|
+
totalWidth += encodings[i].width;
|
|
57
|
+
}
|
|
58
|
+
return totalWidth;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getMaximumHeightOfEncodings(encodings) {
|
|
62
|
+
var maxHeight = 0;
|
|
63
|
+
for (var i = 0; i < encodings.length; i++) {
|
|
64
|
+
if (encodings[i].height > maxHeight) {
|
|
65
|
+
maxHeight = encodings[i].height;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return maxHeight;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function messureText(string, options, context) {
|
|
72
|
+
var ctx;
|
|
73
|
+
|
|
74
|
+
if (context) {
|
|
75
|
+
ctx = context;
|
|
76
|
+
} else if (typeof document !== "undefined") {
|
|
77
|
+
ctx = document.createElement("canvas").getContext("2d");
|
|
78
|
+
} else {
|
|
79
|
+
// If the text cannot be messured we will return 0.
|
|
80
|
+
// This will make some barcode with big text render incorrectly
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
ctx.font = options.fontOptions + " " + options.fontSize + "px " + options.font;
|
|
84
|
+
|
|
85
|
+
// Calculate the width of the encoding
|
|
86
|
+
var measureTextResult = ctx.measureText(string);
|
|
87
|
+
if (!measureTextResult) {
|
|
88
|
+
// Some implementations don't implement measureText and return undefined.
|
|
89
|
+
// If the text cannot be measured we will return 0.
|
|
90
|
+
// This will make some barcode with big text render incorrectly
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
var size = measureTextResult.width;
|
|
94
|
+
return size;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.getMaximumHeightOfEncodings = getMaximumHeightOfEncodings;
|
|
98
|
+
exports.getEncodingHeight = getEncodingHeight;
|
|
99
|
+
exports.getBarcodePadding = getBarcodePadding;
|
|
100
|
+
exports.calculateEncodingAttributes = calculateEncodingAttributes;
|
|
101
|
+
exports.getTotalWidthOfEncodings = getTotalWidthOfEncodings;
|