123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- function Hex2Str(num) {
- if (num.toString(16).length < 2) return "0" + num.toString(16);
- else
- return num.toString(16);
- }
- export function CreatCPCLPage(width, height, printNum, rotation = 0, offset = 0) {
- var strCmd = '! ' + offset + ' 203 203 ' + height + ' ' + printNum + '\n';
- strCmd += "PAGE-WIDTH " + width + '\n';
- if (rotation == 1)
- strCmd += "ZPROTATE90\n";
- else if (rotation == 2)
- strCmd += "ZPROTATE180\n";
- else if (rotation == 3)
- strCmd += "ZPROTATE270\n";
- else
- strCmd += "ZPROTATE0\n";
- return strCmd;
- }
- export function addCPCLText(x, y, fontName, fontSize, rotation, content) {
-
- var strCmd = '';
- if (rotation == 1) {
- strCmd += 'T90 ';
- }
- if (rotation == 2) {
- strCmd += 'T180 ';
- }
- if (rotation == 3) {
- strCmd += 'T270 ';
- } else {
- strCmd += 'T ';
- }
- strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
- return strCmd;
- };
- export function addCPCLBarCode(x, y, codeType, h, rotation, narrow, wide, content) {
- var strCmd = '';
- if (rotation == 0)
- strCmd += 'B ';
- else
- strCmd += 'VB ';
- strCmd += codeType + ' ' + narrow + ' ' + wide + ' ' + h + ' ' + x + ' ' + y + ' ' + content + '\n'
- return strCmd;
- };
- export function addCPCLQRCode(x, y, level, ver, scale, content) {
- var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
- strCmd += 'ENDQR\n';
- return strCmd;
- };
- export function addCPCLSETMAG(scaleX, scaleY) {
- var strCmd = 'SETMAG ' + scaleX + ' ' + scaleY + '\n';
- return strCmd;
- };
- export function addCPCLLocation(set) {
- var strCmd = '';
- if (set == 1) {
- strCmd += 'RIGHT\n';
- } else if (set == 2) {
- strCmd += 'CENTER\n';
- } else {
- strCmd += 'LEFT\n';
- }
- return strCmd;
- };
- export function addCPCLInverseLine(x0, y0, x1, y1, width) {
- var strCmd = 'IL ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
- return strCmd;
- };
- export function addCPCLLine(x0, y0, x1, y1, width) {
- var strCmd = 'L ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
- return strCmd;
- };
- export function addCPCLBox(x0, y0, x1, y1, width) {
- var strCmd = 'BOX ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\n';
- return strCmd;
- };
- export function addCPCLSETBOLD(bold) {
- var strCmd = 'SETBOLD ' + bold + '\n';
- return strCmd;
- };
- export function addCPCLUNDERLINE(c) {
- var strCmd = 'UNDERLINE ';
- if (c) strCmd += 'ON\n';
- else if (c) strCmd += 'OFF\n';
- return strCmd;
- };
- export function addCPCLBACKGROUND(level) {
- var strCmd = 'BACKGROUND ';
- if (level > 255 || level < 0) level = 255;
- strCmd += level + '\n';
- return strCmd;
- };
- export function addCPCLBKVText(x, y, fontName, fontSize, rotation, content) {
-
- var strCmd = '';
- if (rotation == 1) {
- strCmd += 'BKT90 ';
- }
- if (rotation == 2) {
- strCmd += 'BKT180 ';
- }
- if (rotation == 3) {
- strCmd += 'BKT270 ';
- } else {
- strCmd += 'BKT ';
- }
- strCmd += fontName + ' ' + fontSize + ' ' + x + ' ' + y + ' ' + content + '\n';
- return strCmd;
- };
- export function addCPCLGAP() {
- var strCmd = 'GAP-SENSE\nFORM\n';
- return strCmd;
- };
- export function addCPCLSENSE() {
- var strCmd = 'BAR-SENSE\nFORM\n';
- return strCmd;
- };
- export function addCPCLSENSELEFT() {
- var strCmd = 'BAR-SENSE LEFT\nFORM\n';
- return strCmd;
- };
- export function addCPCLPrint() {
- var strCmd = 'PRINT\n';
- return strCmd;
- };
- export function addCPCLImageCmd(x, y, data) {
- var strImgCmd = '';
- const threshold = data.threshold || 180;
- let myBitmapWidth = data.width,
- myBitmapHeight = data.height;
- let len = parseInt((myBitmapWidth + 7) / 8);
-
-
-
- let ndata = 0;
- let i = 0;
- let j = 0;
- let sendImageData = new ArrayBuffer(len * myBitmapHeight);
- sendImageData = new Uint8Array(sendImageData);
- let pix = data.imageData;
- console.log('pix=', pix);
- for (i = 0; i < myBitmapHeight; i++) {
- for (j = 0; j < len; j++) {
- sendImageData[ndata + j] = 0;
- }
- for (j = 0; j < myBitmapWidth; j++) {
- const grayPixle1 = grayPixle(pix.slice((i * myBitmapWidth + j) * 4, (i * myBitmapWidth + j) * 4 + 3));
- if (grayPixle1 < threshold)
- sendImageData[ndata + parseInt(j / 8)] |= (0x80 >> (j % 8));
- }
- ndata += len;
- }
-
-
- strImgCmd += 'EG ' + len + ' ' + myBitmapHeight + ' ' + x + ' ' + y + ' ';
- for (i = 0; i < sendImageData.length; i++) {
- strImgCmd += Hex2Str(sendImageData[i]);
- }
- strImgCmd += '\n';
-
- return strImgCmd;
- }
- module.exports.type = 'cpcl';
|