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 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 3× 1× 3× 2× 1× 1× 1× 1× 1× 5× 1× 6× 1× 1× 2× 1× 2× 1× 2× 2× 1× 2× 2× 2× 2× 2× 20× 20× 10× 10× 2× 2× 2× 1× 2× 1× 2× 1× 2× 2× 2× 2× 12× 12× 2× 10× 2× 1× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 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"], function (require, exports, one_dimension_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var UpcE = (function (_super) { __extends(UpcE, _super); function UpcE() { return _super !== null && _super.apply(this, arguments) || this; } UpcE.prototype.validateInput = function (value) { if (value.search(/^[0-9]{6}$/) !== -1) { return undefined; } else { return 'Accepts 6 numeric characters.'; } }; UpcE.prototype.checkSum = function (value) { var result = 0; var i; for (i = 1; i < 11; i += 2) { result += parseInt(value[i], undefined); } for (i = 0; i < 11; i += 2) { result += parseInt(value[i], undefined) * 3; } return (10 - (result % 10)) % 10; }; UpcE.prototype.getStructure = function () { return { '0': 'EEEOOO', '1': 'EEOEOO', '2': 'EEOOEO', '3': 'EEOOOE', '4': 'EOEEOO', '5': 'EOOEEO', '6': 'EOOOEE', '7': 'EOEOEO', '8': 'EOEOOE', '9': 'EOOEOE' }; }; UpcE.prototype.getValue = function () { return ['XX00000XXX', 'XX10000XXX', 'XX20000XXX', 'XXX00000XX', 'XXXX00000X', 'XXXXX00005', 'XXXXX00006', 'XXXXX00007', 'XXXXX00008', 'XXXXX00009']; }; UpcE.prototype.getExpansion = function (lastDigit) { var value = this.getValue(); return value["" + lastDigit]; }; UpcE.prototype.getUpcValue = function () { var lastDigit = this.value[this.value.length - 1]; var expansionValue = this.getExpansion(lastDigit); var result = ''; var index = 0; for (var i = 0; i < expansionValue.length; i++) { var value = expansionValue[parseInt(i.toString(), 10)]; if (value === 'X') { result += this.value[index++]; } else { result += value; } } result = '' + '0' + result; var encodingValue = '' + result; if (this.enableCheckSum) { encodingValue += this.checkSum(result); } return encodingValue; }; UpcE.prototype.getBinaries = function () { return { 'O': [ '0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011' ], 'E': [ '0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111' ] }; }; UpcE.prototype.encoding = function (upcAValue, string, structure) { var code; var tempValue; var codes = this.getBinaries(); for (var i = 0; i < string.length; i++) { tempValue = codes[structure[parseInt(i.toString(), 10)]]; if (i === 0) { code = tempValue[string[parseInt(i.toString(), 10)]]; } else { code += tempValue[string[parseInt(i.toString(), 10)]]; } } return code; }; UpcE.prototype.draw = function (canvas) { var endBars = '101'; var middleBar = '010101'; var endDigits = '00000000'; var code = []; var upcAValue = this.getUpcValue(); var structureValue = this.getStructure(); var structure = structureValue[upcAValue[upcAValue.length - 1]]; code.push(endDigits); code.push(endBars); code.push(this.encoding(upcAValue, this.value, structure)); code.push(middleBar); code.push(endDigits); var renderText = upcAValue[0] + this.value + upcAValue[upcAValue.length - 1]; this.calculateBarCodeAttributes(code, canvas, this.displayText.text === '' ? renderText : undefined); }; return UpcE; }(one_dimension_1.OneDimension)); exports.UpcE = UpcE; }); |