UNPKG

red-agate-barcode

Version:

red-agate barcode tag library.

70 lines 2.65 kB
// Copyright (c) 2017, Shellyl_N and Authors // license: ISC // https://github.com/shellyln import { barcodeBasePropsDefault, BarcodeBase } from './BarcodeBase'; import { charactersMap, reverseMap } from './data/Nw7.data'; export const nw7PropsDefault = Object.assign({}, barcodeBasePropsDefault, { useRawDataAsText: true, addCheckDigit: true, narrowWidth: 0.33, wideWidth: 0.66, charGapWidth: void 0, startChar: "", stopChar: "" }); export class Nw7 extends BarcodeBase { constructor(props) { super(Object.assign({}, nw7PropsDefault, props), 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 = 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 = charactersMap.get(data[i]); if (z === void 0) { throw new Error("NW7: character is out of range."); } cd = (cd + z.index) % 16; } const cdch = 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]; } } //# sourceMappingURL=Nw7.js.map