yh-hiprint 2.3.6 → 2.4.1
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 +494 -86
- package/hooks/useHiprint.js +48 -27
- package/libs/hiprint.bundle.js +11 -1
- package/libs/jquery.js +1 -0
- package/libs/jsbarcode/JsBarcode.js +64 -72
- package/libs/jsbarcode/barcodes/Barcode.js +9 -17
- package/libs/jsbarcode/barcodes/CODE128/CODE128.js +93 -133
- package/libs/jsbarcode/barcodes/CODE128/CODE128A.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128B.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128C.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128_AUTO.js +10 -36
- package/libs/jsbarcode/barcodes/CODE128/auto.js +32 -37
- package/libs/jsbarcode/barcodes/CODE128/constants.js +47 -30
- package/libs/jsbarcode/barcodes/CODE128/index.js +5 -28
- package/libs/jsbarcode/barcodes/CODE39/index.js +61 -61
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN.js +58 -78
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN13.js +66 -95
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN2.js +22 -50
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN5.js +29 -54
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN8.js +42 -66
- package/libs/jsbarcode/barcodes/EAN_UPC/UPC.js +92 -125
- package/libs/jsbarcode/barcodes/EAN_UPC/UPCE.js +134 -142
- package/libs/jsbarcode/barcodes/EAN_UPC/constants.js +32 -21
- package/libs/jsbarcode/barcodes/EAN_UPC/encoder.js +11 -18
- package/libs/jsbarcode/barcodes/EAN_UPC/index.js +8 -39
- package/libs/jsbarcode/barcodes/GenericBarcode/index.js +16 -49
- package/libs/jsbarcode/barcodes/ITF/ITF.js +31 -63
- package/libs/jsbarcode/barcodes/ITF/ITF14.js +18 -40
- package/libs/jsbarcode/barcodes/ITF/constants.js +6 -8
- package/libs/jsbarcode/barcodes/ITF/index.js +3 -18
- package/libs/jsbarcode/barcodes/MSI/MSI.js +31 -57
- package/libs/jsbarcode/barcodes/MSI/MSI10.js +7 -30
- package/libs/jsbarcode/barcodes/MSI/MSI1010.js +10 -33
- package/libs/jsbarcode/barcodes/MSI/MSI11.js +7 -30
- package/libs/jsbarcode/barcodes/MSI/MSI1110.js +10 -33
- package/libs/jsbarcode/barcodes/MSI/checksums.js +11 -17
- package/libs/jsbarcode/barcodes/MSI/index.js +6 -33
- package/libs/jsbarcode/barcodes/codabar/index.js +49 -78
- package/libs/jsbarcode/barcodes/index.js +20 -33
- package/libs/jsbarcode/barcodes/pharmacode/index.js +32 -62
- package/libs/jsbarcode/exceptions/ErrorHandler.js +28 -43
- package/libs/jsbarcode/exceptions/exceptions.js +21 -59
- package/libs/jsbarcode/help/fixOptions.js +3 -9
- package/libs/jsbarcode/help/getOptionsFromElement.js +10 -23
- package/libs/jsbarcode/help/getRenderProperties.js +63 -69
- package/libs/jsbarcode/help/linearizeEncodings.js +8 -13
- package/libs/jsbarcode/help/merge.js +1 -11
- package/libs/jsbarcode/help/optionsFromStrings.js +19 -15
- package/libs/jsbarcode/options/defaults.js +2 -7
- package/libs/jsbarcode/renderers/canvas.js +106 -127
- package/libs/jsbarcode/renderers/index.js +4 -20
- package/libs/jsbarcode/renderers/object.js +7 -23
- package/libs/jsbarcode/renderers/shared.js +32 -39
- package/libs/jsbarcode/renderers/svg.js +136 -154
- package/package.json +1 -1
- package/libs/jsbarcode/barcodes/index.tmp.js +0 -33
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = optionsFromStrings;
|
|
1
|
+
export default optionsFromStrings;
|
|
7
2
|
|
|
8
3
|
// Convert string to integers/booleans where it should be
|
|
4
|
+
function optionsFromStrings(options){
|
|
5
|
+
var intOptions = [
|
|
6
|
+
"width",
|
|
7
|
+
"height",
|
|
8
|
+
"textMargin",
|
|
9
|
+
"fontSize",
|
|
10
|
+
"margin",
|
|
11
|
+
"marginTop",
|
|
12
|
+
"marginBottom",
|
|
13
|
+
"marginLeft",
|
|
14
|
+
"marginRight"
|
|
15
|
+
];
|
|
9
16
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var intOption in intOptions) {
|
|
14
|
-
if (intOptions.hasOwnProperty(intOption)) {
|
|
17
|
+
for(var intOption in intOptions){
|
|
18
|
+
if(intOptions.hasOwnProperty(intOption)){
|
|
15
19
|
intOption = intOptions[intOption];
|
|
16
|
-
if
|
|
20
|
+
if(typeof options[intOption] === "string"){
|
|
17
21
|
options[intOption] = parseInt(options[intOption], 10);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
if
|
|
23
|
-
options["displayValue"] = options["displayValue"] != "false";
|
|
26
|
+
if(typeof options["displayValue"] === "string"){
|
|
27
|
+
options["displayValue"] = (options["displayValue"] != "false");
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
return options;
|
|
27
|
-
}
|
|
31
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
1
|
var defaults = {
|
|
7
2
|
width: 2,
|
|
8
3
|
height: 100,
|
|
@@ -22,7 +17,7 @@ var defaults = {
|
|
|
22
17
|
marginBottom: undefined,
|
|
23
18
|
marginLeft: undefined,
|
|
24
19
|
marginRight: undefined,
|
|
25
|
-
valid: function
|
|
20
|
+
valid: function(){}
|
|
26
21
|
};
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
export default defaults;
|
|
@@ -1,158 +1,137 @@
|
|
|
1
|
-
|
|
1
|
+
import merge from "../help/merge.js";
|
|
2
|
+
import {calculateEncodingAttributes, getTotalWidthOfEncodings, getMaximumHeightOfEncodings} from "./shared.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class CanvasRenderer{
|
|
5
|
+
constructor(canvas, encodings, options){
|
|
6
|
+
this.canvas = canvas;
|
|
7
|
+
this.encodings = encodings;
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
render(){
|
|
12
|
+
// Abort if the browser does not support HTML5 canvas
|
|
13
|
+
if (!this.canvas.getContext) {
|
|
14
|
+
throw new Error('The browser does not support canvas.');
|
|
15
|
+
}
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
this.prepareCanvas();
|
|
18
|
+
for(let i = 0; i < this.encodings.length; i++){
|
|
19
|
+
var encodingOptions = merge(this.options, this.encodings[i].options);
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
this.drawCanvasBarcode(encodingOptions, this.encodings[i]);
|
|
22
|
+
this.drawCanvasText(encodingOptions, this.encodings[i]);
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
this.moveCanvasDrawing(this.encodings[i]);
|
|
25
|
+
}
|
|
14
26
|
|
|
15
|
-
|
|
27
|
+
this.restoreCanvas();
|
|
28
|
+
}
|
|
16
29
|
|
|
17
|
-
|
|
30
|
+
prepareCanvas(){
|
|
31
|
+
// Get the canvas context
|
|
32
|
+
var ctx = this.canvas.getContext("2d");
|
|
18
33
|
|
|
19
|
-
|
|
20
|
-
function CanvasRenderer(canvas, encodings, options) {
|
|
21
|
-
_classCallCheck(this, CanvasRenderer);
|
|
34
|
+
ctx.save();
|
|
22
35
|
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
36
|
+
calculateEncodingAttributes(this.encodings, this.options, ctx);
|
|
37
|
+
var totalWidth = getTotalWidthOfEncodings(this.encodings);
|
|
38
|
+
var maxHeight = getMaximumHeightOfEncodings(this.encodings);
|
|
27
39
|
|
|
28
|
-
|
|
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
|
-
}
|
|
40
|
+
this.canvas.width = totalWidth + this.options.marginLeft + this.options.marginRight;
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
for (var i = 0; i < this.encodings.length; i++) {
|
|
38
|
-
var encodingOptions = (0, _merge2.default)(this.options, this.encodings[i].options);
|
|
42
|
+
this.canvas.height = maxHeight;
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
// Paint the canvas
|
|
45
|
+
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
46
|
+
if(this.options.background){
|
|
47
|
+
ctx.fillStyle = this.options.background;
|
|
48
|
+
ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
|
49
|
+
}
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
ctx.translate(this.options.marginLeft, 0);
|
|
52
|
+
}
|
|
45
53
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
key: "prepareCanvas",
|
|
50
|
-
value: function prepareCanvas() {
|
|
51
|
-
// Get the canvas context
|
|
52
|
-
var ctx = this.canvas.getContext("2d");
|
|
54
|
+
drawCanvasBarcode(options, encoding){
|
|
55
|
+
// Get the canvas context
|
|
56
|
+
var ctx = this.canvas.getContext("2d");
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
var binary = encoding.data;
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
// Creates the barcode out of the encoded binary
|
|
61
|
+
var yFrom;
|
|
62
|
+
if(options.textPosition == "top"){
|
|
63
|
+
yFrom = options.marginTop + options.fontSize + options.textMargin;
|
|
64
|
+
}
|
|
65
|
+
else{
|
|
66
|
+
yFrom = options.marginTop;
|
|
67
|
+
}
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
ctx.fillStyle = options.lineColor;
|
|
61
70
|
|
|
62
|
-
|
|
71
|
+
for(var b = 0; b < binary.length; b++){
|
|
72
|
+
var x = b * options.width + encoding.barcodePadding;
|
|
63
73
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (this.options.background) {
|
|
67
|
-
ctx.fillStyle = this.options.background;
|
|
68
|
-
ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
|
74
|
+
if(binary[b] === "1"){
|
|
75
|
+
ctx.fillRect(x, yFrom, options.width, options.height);
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
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;
|
|
77
|
+
else if(binary[b]){
|
|
78
|
+
ctx.fillRect(x, yFrom, options.width, options.height * binary[b]);
|
|
87
79
|
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
88
82
|
|
|
89
|
-
|
|
83
|
+
drawCanvasText(options, encoding){
|
|
84
|
+
// Get the canvas context
|
|
85
|
+
var ctx = this.canvas.getContext("2d");
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
var x = b * options.width + encoding.barcodePadding;
|
|
87
|
+
var font = options.fontOptions + " " + options.fontSize + "px " + options.font;
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
// Draw the text if displayValue is set
|
|
90
|
+
if(options.displayValue){
|
|
91
|
+
var x, y;
|
|
92
|
+
|
|
93
|
+
if(options.textPosition == "top"){
|
|
94
|
+
y = options.marginTop + options.fontSize - options.textMargin;
|
|
99
95
|
}
|
|
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);
|
|
96
|
+
else{
|
|
97
|
+
y = options.height + options.textMargin + options.marginTop + options.fontSize;
|
|
136
98
|
}
|
|
137
|
-
}
|
|
138
|
-
}, {
|
|
139
|
-
key: "moveCanvasDrawing",
|
|
140
|
-
value: function moveCanvasDrawing(encoding) {
|
|
141
|
-
var ctx = this.canvas.getContext("2d");
|
|
142
99
|
|
|
143
|
-
ctx.
|
|
144
|
-
}
|
|
145
|
-
}, {
|
|
146
|
-
key: "restoreCanvas",
|
|
147
|
-
value: function restoreCanvas() {
|
|
148
|
-
// Get the canvas context
|
|
149
|
-
var ctx = this.canvas.getContext("2d");
|
|
100
|
+
ctx.font = font;
|
|
150
101
|
|
|
151
|
-
|
|
102
|
+
// Draw the text in the correct X depending on the textAlign option
|
|
103
|
+
if(options.textAlign == "left" || encoding.barcodePadding > 0){
|
|
104
|
+
x = 0;
|
|
105
|
+
ctx.textAlign = 'left';
|
|
106
|
+
}
|
|
107
|
+
else if(options.textAlign == "right"){
|
|
108
|
+
x = encoding.width - 1;
|
|
109
|
+
ctx.textAlign = 'right';
|
|
110
|
+
}
|
|
111
|
+
// In all other cases, center the text
|
|
112
|
+
else{
|
|
113
|
+
x = encoding.width / 2;
|
|
114
|
+
ctx.textAlign = 'center';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
ctx.fillText(encoding.text, x, y);
|
|
152
118
|
}
|
|
153
|
-
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
moveCanvasDrawing(encoding){
|
|
124
|
+
var ctx = this.canvas.getContext("2d");
|
|
154
125
|
|
|
155
|
-
|
|
156
|
-
}
|
|
126
|
+
ctx.translate(encoding.width, 0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
restoreCanvas(){
|
|
130
|
+
// Get the canvas context
|
|
131
|
+
var ctx = this.canvas.getContext("2d");
|
|
132
|
+
|
|
133
|
+
ctx.restore();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
157
136
|
|
|
158
|
-
|
|
137
|
+
export default CanvasRenderer;
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import CanvasRenderer from './canvas.js';
|
|
2
|
+
import SVGRenderer from './svg.js';
|
|
3
|
+
import ObjectRenderer from './object.js';
|
|
2
4
|
|
|
3
|
-
|
|
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 };
|
|
5
|
+
export default {CanvasRenderer, SVGRenderer, ObjectRenderer};
|
|
@@ -1,30 +1,14 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
1
|
+
class ObjectRenderer {
|
|
2
|
+
constructor(object, encodings, options) {
|
|
15
3
|
this.object = object;
|
|
16
4
|
this.encodings = encodings;
|
|
17
5
|
this.options = options;
|
|
18
6
|
}
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}]);
|
|
8
|
+
render() {
|
|
9
|
+
this.object.encodings = this.encodings;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
26
12
|
|
|
27
|
-
return ObjectRenderer;
|
|
28
|
-
}();
|
|
29
13
|
|
|
30
|
-
|
|
14
|
+
export default ObjectRenderer;
|
|
@@ -1,48 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import merge from "../help/merge.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
3
|
+
function getEncodingHeight(encoding, options){
|
|
4
|
+
return options.height +
|
|
5
|
+
((options.displayValue && encoding.text.length > 0) ? options.fontSize + options.textMargin : 0) +
|
|
6
|
+
options.marginTop +
|
|
7
|
+
options.marginBottom;
|
|
16
8
|
}
|
|
17
9
|
|
|
18
|
-
function getBarcodePadding(textWidth, barcodeWidth, options)
|
|
19
|
-
if
|
|
20
|
-
if
|
|
10
|
+
function getBarcodePadding(textWidth, barcodeWidth, options){
|
|
11
|
+
if(options.displayValue && barcodeWidth < textWidth){
|
|
12
|
+
if(options.textAlign == "center"){
|
|
21
13
|
return Math.floor((textWidth - barcodeWidth) / 2);
|
|
22
|
-
}
|
|
14
|
+
}
|
|
15
|
+
else if(options.textAlign == "left"){
|
|
23
16
|
return 0;
|
|
24
|
-
}
|
|
17
|
+
}
|
|
18
|
+
else if(options.textAlign == "right"){
|
|
25
19
|
return Math.floor(textWidth - barcodeWidth);
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
22
|
return 0;
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
function calculateEncodingAttributes(encodings, barcodeOptions, context)
|
|
32
|
-
for
|
|
25
|
+
function calculateEncodingAttributes(encodings, barcodeOptions, context){
|
|
26
|
+
for(let i = 0; i < encodings.length; i++){
|
|
33
27
|
var encoding = encodings[i];
|
|
34
|
-
var options = (
|
|
28
|
+
var options = merge(barcodeOptions, encoding.options);
|
|
35
29
|
|
|
36
30
|
// Calculate the width of the encoding
|
|
37
31
|
var textWidth;
|
|
38
|
-
if
|
|
32
|
+
if(options.displayValue){
|
|
39
33
|
textWidth = messureText(encoding.text, options, context);
|
|
40
|
-
}
|
|
34
|
+
}
|
|
35
|
+
else{
|
|
41
36
|
textWidth = 0;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
var barcodeWidth = encoding.data.length * options.width;
|
|
45
|
-
encoding.width =
|
|
40
|
+
encoding.width = Math.ceil(Math.max(textWidth, barcodeWidth));
|
|
46
41
|
|
|
47
42
|
encoding.height = getEncodingHeight(encoding, options);
|
|
48
43
|
|
|
@@ -50,32 +45,34 @@ function calculateEncodingAttributes(encodings, barcodeOptions, context) {
|
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
function getTotalWidthOfEncodings(encodings)
|
|
48
|
+
function getTotalWidthOfEncodings(encodings){
|
|
54
49
|
var totalWidth = 0;
|
|
55
|
-
for
|
|
50
|
+
for(let i = 0; i < encodings.length; i++){
|
|
56
51
|
totalWidth += encodings[i].width;
|
|
57
52
|
}
|
|
58
53
|
return totalWidth;
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
function getMaximumHeightOfEncodings(encodings)
|
|
56
|
+
function getMaximumHeightOfEncodings(encodings){
|
|
62
57
|
var maxHeight = 0;
|
|
63
|
-
for
|
|
64
|
-
if
|
|
58
|
+
for(let i = 0; i < encodings.length; i++){
|
|
59
|
+
if(encodings[i].height > maxHeight){
|
|
65
60
|
maxHeight = encodings[i].height;
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
return maxHeight;
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
function messureText(string, options, context)
|
|
66
|
+
function messureText(string, options, context){
|
|
72
67
|
var ctx;
|
|
73
68
|
|
|
74
|
-
if
|
|
69
|
+
if(context){
|
|
75
70
|
ctx = context;
|
|
76
|
-
}
|
|
71
|
+
}
|
|
72
|
+
else if(typeof document !== "undefined"){
|
|
77
73
|
ctx = document.createElement("canvas").getContext("2d");
|
|
78
|
-
}
|
|
74
|
+
}
|
|
75
|
+
else{
|
|
79
76
|
// If the text cannot be messured we will return 0.
|
|
80
77
|
// This will make some barcode with big text render incorrectly
|
|
81
78
|
return 0;
|
|
@@ -94,8 +91,4 @@ function messureText(string, options, context) {
|
|
|
94
91
|
return size;
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
|
|
98
|
-
exports.getEncodingHeight = getEncodingHeight;
|
|
99
|
-
exports.getBarcodePadding = getBarcodePadding;
|
|
100
|
-
exports.calculateEncodingAttributes = calculateEncodingAttributes;
|
|
101
|
-
exports.getTotalWidthOfEncodings = getTotalWidthOfEncodings;
|
|
94
|
+
export {getMaximumHeightOfEncodings, getEncodingHeight, getBarcodePadding, calculateEncodingAttributes, getTotalWidthOfEncodings};
|