| 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 36× 1× 32× 1× 1× 31× 28× 1× 27× 3× 1× 28× 28× 28× 28× 28× 17× 1× 30× 30× 30× 204× 204× 204× 204× 1020× 1020× 1020× 1020× 1428× 1020× 1428× 30× 30× 1× 408× 408× 1× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 17× 12× 12× 17× 17× 17× 58× 1× 29× 29× 29× 29× 377× 377× 29× 1× 4× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "../one-dimension", "../rendering/renderer", "../utility/dom-util"], function (require, exports, one_dimension_1, renderer_1, dom_util_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ITF14 = (function (_super) { __extends(ITF14, _super); function ITF14() { return _super !== null && _super.apply(this, arguments) || this; } ITF14.prototype.validateInput = function (char) { if (char.search(/^[0-9]{13}$/) !== -1) { this.value = char + this.calculateCheckDigit(char); return undefined; } else if (char.search(/^[0-9]{14}$/) !== -1) { if (Number(char[13]) !== this.calculateCheckDigit(char.substring(0, 13))) { return this.message('ITF14InvalidCheckDigit'); } return undefined; } return this.message('ITF14InvalidValue'); }; ITF14.prototype.draw = function (canvas) { var quietModules = this.bearerBar === 'Frame' ? 10 + this.bearerBarWidth : this.bearerBar === 'Horizontal' ? 10 : 0; var encoded = this.encodeValue(this.value); var code = [ new Array(quietModules + 1).join('0') + encoded + new Array(quietModules + 1).join('0') ]; this.calculateBarCodeAttributes(code, canvas); if (this.bearerBar !== 'None') { this.drawBearerBars(canvas, code[0].length); } }; ITF14.prototype.encodeValue = function (value) { var encoded = '1010'; var index; for (index = 0; index < value.length; index += 2) { var barPattern = this.getPattern(value[parseInt(index.toString(), 10)]); var spacePattern = this.getPattern(value[parseInt((index + 1).toString(), 10)]); var element = void 0; for (element = 0; element < 5; element++) { var barWidth = Number(barPattern[parseInt(element.toString(), 10)]); var spaceWidth = Number(spacePattern[parseInt(element.toString(), 10)]); var module = void 0; for (module = 0; module < barWidth; module++) { encoded += '1'; } for (module = 0; module < spaceWidth; module++) { encoded += '0'; } } } encoded += '1101'; return encoded; }; ITF14.prototype.getPattern = function (digit) { var patterns = { '0': '11221', '1': '21112', '2': '12112', '3': '22111', '4': '11212', '5': '21211', '6': '12211', '7': '11122', '8': '21121', '9': '12121' }; return patterns["" + digit]; }; ITF14.prototype.drawBearerBars = function (canvas, moduleCount) { var barcodeSize = this.getDrawableSize(this.margin, this.width, this.height); Iif (barcodeSize.height <= 0 || barcodeSize.width <= 0) { return; } var textOptions = { width: undefined, height: undefined, x: 0, y: 0, color: this.foreColor, string: this.displayText.text ? this.displayText.text : this.value, stringSize: this.displayText.size, visibility: this.displayText.visibility, fontStyle: this.displayText.font }; dom_util_1.createMeasureElements(); var textSize = dom_util_1.measureText(textOptions); var textHeight = (textSize.height / 2) + 2; var scaleValue = this.isSvgMode ? 1 : 1.5; var barTop = this.displayText.position === 'Top' ? barcodeSize.y + textHeight + this.displayText.margin.top : barcodeSize.y; var drawableHeight = (barcodeSize.height - textHeight * scaleValue) / scaleValue; var drawableWidth = barcodeSize.width / scaleValue; Iif (drawableHeight <= 0 || drawableWidth <= 0) { return; } var moduleWidth = drawableWidth / moduleCount; var barWidth = this.bearerBarWidth * moduleWidth; var options = []; options.push({ x: barcodeSize.x, y: barTop, width: drawableWidth, height: barWidth, color: this.foreColor }); options.push({ x: barcodeSize.x, y: barTop + drawableHeight - barWidth, width: drawableWidth, height: barWidth, color: this.foreColor }); if (this.bearerBar === 'Frame') { options.push({ x: barcodeSize.x, y: barTop, width: barWidth, height: drawableHeight, color: this.foreColor }); options.push({ x: barcodeSize.x + drawableWidth - barWidth, y: barTop, width: barWidth, height: drawableHeight, color: this.foreColor }); } var renderer = new renderer_1.BarcodeRenderer(canvas.id, this.isSvgMode); var index; for (index = 0; index < options.length; index++) { renderer.renderRectElement(canvas, options[parseInt(index.toString(), 10)]); } }; ITF14.prototype.calculateCheckDigit = function (digits) { var sum = 0; var weight = 3; var index; for (index = digits.length - 1; index >= 0; index--) { sum += (digits.charCodeAt(index) - 48) * weight; weight = weight === 3 ? 1 : 3; } return (10 - (sum % 10)) % 10; }; ITF14.prototype.message = function (key) { return this.locale ? (this.locale.getConstant(key) || key) : key; }; return ITF14; }(one_dimension_1.OneDimension)); exports.ITF14 = ITF14; }); |