UNPKG

red-agate-barcode

Version:

red-agate barcode tag library.

64 lines 2.43 kB
"use strict"; // Copyright (c) 2017, Shellyl_N and Authors // license: ISC // https://github.com/shellyln Object.defineProperty(exports, "__esModule", { value: true }); exports.Itf = exports.itfPropsDefault = void 0; const BarcodeBase_1 = require("./BarcodeBase"); const Itf_data_1 = require("./data/Itf.data"); exports.itfPropsDefault = Object.assign({}, BarcodeBase_1.barcodeBasePropsDefault, { addCheckDigit: true, narrowWidth: 0.33, wideWidth: 0.66 }); class Itf extends BarcodeBase_1.BarcodeBase { constructor(props) { super(Object.assign({}, exports.itfPropsDefault, props), Itf_data_1.charactersMap); } calcSymbolSize(data, startChar, stopChar, cdChar) { const props = this.props; // module width (bar + space + gap) const mw = props.narrowWidth * 3 + props.wideWidth * 2; return { // total width (quiet + data + start + stop + cd) tw: props.quietWidth * 2 + (props.narrowWidth * 8) + mw * data.length * 2, // total height (quiet + bar + text) th: props.quietHeight * 2 + props.height + (props.drawText ? props.textHeight : 0) }; } calcItfMod10W3Checksum(data) { let odd = 0, even = 0; for (let i = 0; i < data.length; i++) { // most right -> odd if ((i + 1) % 2) { odd = (odd + Number.parseInt(data[data.length - 1 - i], 10)) % 10; } else { even = (even + Number.parseInt(data[data.length - 1 - i], 10)) % 10; } } return String((10 - ((odd * 3 + even) % 10)) % 10); } encodeData(data) { let labelText = data; if (this.props.addCheckDigit) { const cd = this.calcItfMod10W3Checksum(data); labelText += cd; } let d = ""; if (labelText.length % 2) { throw new Error("bad data length"); } for (let i = 0; i < labelText.length; i += 2) { const c = Number.parseInt(labelText.slice(i, i + 2), 10); d += String.fromCharCode(c); } return { data: d, labelText, startChar: "\x64", stopChar: "\x65" }; } getBarSpaceWidth() { const props = this.props; return [0, props.narrowWidth, props.wideWidth]; } } exports.Itf = Itf; //# sourceMappingURL=Itf.js.map