red-agate-barcode
Version:
red-agate barcode tag library.
74 lines • 2.83 kB
JavaScript
;
// Copyright (c) 2017, Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
Object.defineProperty(exports, "__esModule", { value: true });
exports.Nw7 = exports.nw7PropsDefault = void 0;
const BarcodeBase_1 = require("./BarcodeBase");
const Nw7_data_1 = require("./data/Nw7.data");
exports.nw7PropsDefault = Object.assign({}, BarcodeBase_1.barcodeBasePropsDefault, {
useRawDataAsText: true,
addCheckDigit: true,
narrowWidth: 0.33,
wideWidth: 0.66,
charGapWidth: void 0,
startChar: "",
stopChar: ""
});
class Nw7 extends BarcodeBase_1.BarcodeBase {
constructor(props) {
super(Object.assign({}, exports.nw7PropsDefault, props), Nw7_data_1.charactersMap);
}
calcSymbolSize(data, startChar, stopChar, cdChar) {
const props = this.props;
const gw = props.charGapWidth || props.narrowWidth;
// module width (bar + space + gap)
const mw = props.narrowWidth * 4 + props.wideWidth * 3 + gw;
let tw = props.quietWidth * 2 - gw;
const data2 = `${startChar}${data}${cdChar}${stopChar}`;
for (const c of data2) {
const z = Nw7_data_1.charactersMap.get(c);
if (z === void 0) {
throw new Error("NW7: character is out of range.");
}
const wide = z.width - 7;
const narrow = 7 - wide;
tw += props.narrowWidth * narrow + props.wideWidth * wide + gw;
}
return {
// total width (quiet + data + start + stop + cd)
tw,
// total height (quiet + bar + text)
th: props.quietHeight * 2 + props.height + (props.drawText ? props.textHeight : 0)
};
}
calcCheckDigit(data) {
let cdChar = "";
if (this.props.addCheckDigit) {
let cd = 0;
for (let i = 0; i < data.length; i++) {
const z = Nw7_data_1.charactersMap.get(data[i]);
if (z === void 0) {
throw new Error("NW7: character is out of range.");
}
cd = (cd + z.index) % 16;
}
const cdch = Nw7_data_1.reverseMap.get((16 - cd) % 16);
if (cdch === void 0) {
throw new Error("NW7: check digit is out of range.");
}
cdChar = cdch;
}
return cdChar;
}
encodeData(data) {
return { data, startChar: this.props.startChar || "", stopChar: this.props.stopChar || "" };
}
getBarSpaceWidth() {
const props = this.props;
const gw = props.charGapWidth || props.narrowWidth;
return [gw, props.narrowWidth, props.wideWidth];
}
}
exports.Nw7 = Nw7;
//# sourceMappingURL=Nw7.js.map