red-agate-barcode
Version:
red-agate barcode tag library.
79 lines • 2.85 kB
JavaScript
;
// Copyright (c) 2017, Shellyl_N and Authors
// license: ISC
// https://github.com/shellyln
Object.defineProperty(exports, "__esModule", { value: true });
exports.JapanPostal = exports.japanPostalPropsDefault = void 0;
const BarcodeBase_1 = require("./BarcodeBase");
const JapanPostal_data_1 = require("./data/JapanPostal.data");
exports.japanPostalPropsDefault = Object.assign({}, BarcodeBase_1.barcodeBasePropsDefault, {
elementWidth: 0.6,
height: 1.2 * 3
});
class JapanPostal extends BarcodeBase_1.BarcodeBase {
constructor(props) {
super(Object.assign({}, exports.japanPostalPropsDefault, props), JapanPostal_data_1.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 = JapanPostal_data_1.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 = JapanPostal_data_1.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) {
}
}
exports.JapanPostal = JapanPostal;
//# sourceMappingURL=JapanPostal.js.map