red-agate-barcode
Version:
red-agate barcode tag library.
72 lines • 2.79 kB
JavaScript
;
// Copyright (c) 2017, Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
Object.defineProperty(exports, "__esModule", { value: true });
exports.Code39 = exports.code39PropsDefault = void 0;
const BarcodeBase_1 = require("./BarcodeBase");
const Code39_data_1 = require("./data/Code39.data");
exports.code39PropsDefault = Object.assign({}, BarcodeBase_1.barcodeBasePropsDefault, {
addCheckDigit: true,
fullAscii: false,
narrowWidth: 0.33,
wideWidth: 0.66,
charGapWidth: void 0
});
class Code39 extends BarcodeBase_1.BarcodeBase {
constructor(props) {
super(Object.assign({}, exports.code39PropsDefault, props), Code39_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 * 6 + props.wideWidth * 3 + gw;
return {
// total width (quiet + data + start + stop + cd)
tw: props.quietWidth * 2 + mw * (data.length + 2 + (props.addCheckDigit ? 1 : 0)) - gw,
// 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 v = Code39_data_1.charactersMap.get(data[i]);
if (v === void 0) {
throw new Error("code39: character is out of range.");
}
cd = (cd + v.index) % 43;
}
const cdch = Code39_data_1.reverseMap.get(cd);
if (cdch === void 0) {
throw new Error("code39 (trace): checkdigit is out of range.");
}
cdChar = cdch;
}
return cdChar;
}
encodeData(data) {
let d = data;
if (this.props.fullAscii) {
d = "";
for (let i = 0; i < data.length; i++) {
const c = Code39_data_1.fullAsciiMap.get(data.charCodeAt(i));
if (c === void 0) {
throw new Error("code39 fullascii: character is out of range.");
}
d += c;
}
}
return { data: d, startChar: "*", stopChar: "*" };
}
getBarSpaceWidth() {
const props = this.props;
const gw = props.charGapWidth || props.narrowWidth;
return [gw, props.narrowWidth, props.wideWidth];
}
}
exports.Code39 = Code39;
//# sourceMappingURL=Code39.js.map