UNPKG

red-agate-barcode

Version:

red-agate barcode tag library.

75 lines 2.63 kB
// Copyright (c) 2017, Shellyl_N and Authors // license: ISC // https://github.com/shellyln import { barcodeBasePropsDefault, BarcodeBase } from './BarcodeBase'; import { charactersMap, reverseMap, fullAsciiMap } from './data/JapanPostal.data'; export const japanPostalPropsDefault = Object.assign({}, barcodeBasePropsDefault, { elementWidth: 0.6, height: 1.2 * 3 }); export class JapanPostal extends BarcodeBase { constructor(props) { super(Object.assign({}, japanPostalPropsDefault, props), charactersMap); } calcSymbolSize(data, startChar, stopChar, cdChar) { const props = this.props; // module width (bar + space) const mw = props.elementWidth * 6; return { // total width (quiet + data + start + stop + cd) tw: props.quietWidth * 2 + mw * 21 + props.elementWidth * (4 + 3), // total height (quiet + bar) th: props.quietHeight * 2 + props.height }; } calcCheckDigit(data) { let cdChar = ""; let cd = 0; for (let i = 0; i < data.length; i++) { const z = this.charactersMap.get(data[i]); if (z === void 0) { throw new Error("Japan Post: character is out of range."); } cd = (cd + z.index) % 19; } const cdch = reverseMap.get(cd); if (cdch === void 0) { throw new Error("Japan Post: check digit is out of range."); } cdChar = cdch; return cdChar; } encodeData(data) { let d = ""; for (let i = 0; i < data.length; i++) { const c = fullAsciiMap.get(data.charCodeAt(i)); if (c === void 0) { throw new Error("Japan Post: character is out of range."); } d += c; } d += "DDDDDDDDDDDDDDDDD"; return { data: d.slice(0, 20), startChar: "[", stopChar: "]" }; } getBarSpaceWidth() { const props = this.props; return [0, props.elementWidth]; } getBarSpaceHeight() { const props = this.props; const h = props.height; return [ [{ offset: 0, height: h }], [{ offset: 0, height: h }], [{ offset: 0, height: h * 2 / 3 }], [{ offset: h / 3, height: h * 2 / 3 }], [{ offset: h / 3, height: h / 3 }] // 4: timing ]; } get isHeightModulated() { return true; } renderText(canvas, tw, th, data, text) { } } //# sourceMappingURL=JapanPostal.js.map