⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 barcodedatamatrix.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        for (; ptrIn < textLength; ++ptrIn) {            c = x[ptrIn];            if (ptrOut >= dataLength)                break;            if (c < 40) {                if (ptrIn == 0 || (ptrIn > 0 && x[ptrIn - 1] > 40))                    data[dataOffset + ptrOut++] = (byte)238;                if (ptrOut + 2 > dataLength)                    break;                n = 1600 * x[ptrIn] + 40 * x[ptrIn + 1] + x[ptrIn + 2] + 1;                data[dataOffset + ptrOut++] = (byte)(n / 256);                data[dataOffset + ptrOut++] = (byte)n;                ptrIn += 2;            }            else {                if (ptrIn > 0 && x[ptrIn - 1] < 40)                    data[dataOffset + ptrOut++] = (byte)254;                ci = text[ptrIn + textOffset] & 0xff;                if (ci > 127) {                    data[dataOffset + ptrOut++] = (byte)235;                    ci -= 128;                }                if (ptrOut >= dataLength)                    break;                data[dataOffset + ptrOut++] = (byte)(ci + 1);            }        }        c = 100;        if (textLength > 0)            c = x[textLength - 1];        if (ptrIn != textLength || (c < 40 && ptrOut >= dataLength))            return -1;        if (c < 40)            data[dataOffset + ptrOut++] = (byte)(254);        return ptrOut;    }    private static int EdifactEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength) {        int ptrIn, ptrOut, edi, pedi, c;        if (textLength == 0)            return 0;        ptrIn = 0;        ptrOut = 0;        edi = 0;        pedi = 18;        boolean ascii = true;        for (; ptrIn < textLength; ++ptrIn) {            c = text[ptrIn + textOffset] & 0xff;            if (((c & 0xe0) == 0x40 || (c & 0xe0) == 0x20) && c != '_') {                if (ascii) {                    if (ptrOut + 1 > dataLength)                        break;                    data[dataOffset + ptrOut++] = (byte)240;                    ascii = false;                }                c &= 0x3f;                edi |= c << pedi;                if (pedi == 0) {                    if (ptrOut + 3 > dataLength)                        break;                    data[dataOffset + ptrOut++] = (byte)(edi >> 16);                    data[dataOffset + ptrOut++] = (byte)(edi >> 8);                    data[dataOffset + ptrOut++] = (byte)edi;                    edi = 0;                    pedi = 18;                }                else                    pedi -= 6;            }            else {                if (!ascii) {                    edi |= ('_' & 0x3f) << pedi;                    if (ptrOut + (3 - pedi / 8) > dataLength)                        break;                    data[dataOffset + ptrOut++] = (byte)(edi >> 16);                    if (pedi <= 12)                        data[dataOffset + ptrOut++] = (byte)(edi >> 8);                    if (pedi <= 6)                        data[dataOffset + ptrOut++] = (byte)edi;                    ascii = true;                    pedi = 18;                    edi = 0;                }                if (c > 127) {                    if (ptrOut >= dataLength)                        break;                    data[dataOffset + ptrOut++] = (byte)235;                    c -= 128;                }                if (ptrOut >= dataLength)                    break;                data[dataOffset + ptrOut++] = (byte)(c + 1);            }        }        if (ptrIn != textLength)            return -1;        if (!ascii) {            edi |= ('_' & 0x3f) << pedi;            if (ptrOut + (3 - pedi / 8) > dataLength)                return -1;            data[dataOffset + ptrOut++] = (byte)(edi >> 16);            if (pedi <= 12)                data[dataOffset + ptrOut++] = (byte)(edi >> 8);            if (pedi <= 6)                data[dataOffset + ptrOut++] = (byte)edi;        }        return ptrOut;    }    private static int C40OrTextEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, boolean c40) {        int ptrIn, ptrOut, encPtr, last0, last1, i, a, c;        String basic, shift2, shift3;        if (textLength == 0)            return 0;        ptrIn = 0;        ptrOut = 0;        if (c40)            data[dataOffset + ptrOut++] = (byte)230;        else            data[dataOffset + ptrOut++] = (byte)239;        shift2 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_";        if (c40) {            basic = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";            shift3 = "`abcdefghijklmnopqrstuvwxyz{|}~\177";        }        else {            basic = " 0123456789abcdefghijklmnopqrstuvwxyz";            shift3 = "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\177";        }        int[] enc = new int[textLength * 4 + 10];        encPtr = 0;        last0 = 0;        last1 = 0;        while (ptrIn < textLength) {            if ((encPtr % 3) == 0) {                last0 = ptrIn;                last1 = encPtr;            }            c = text[textOffset + ptrIn++] & 0xff;            if (c > 127) {                c -= 128;                enc[encPtr++] = 1;                enc[encPtr++] = 30;            }            int idx = basic.indexOf((char)c);            if (idx >= 0) {                enc[encPtr++] = idx + 3;            }            else if (c < 32) {                enc[encPtr++] = 0;                enc[encPtr++] = c;            }            else if ((idx = shift2.indexOf((char)c)) >= 0) {                enc[encPtr++] = 1;                enc[encPtr++] = idx;            }            else if ((idx = shift3.indexOf((char)c)) >= 0) {                enc[encPtr++] = 2;                enc[encPtr++] = idx;            }        }        if ((encPtr % 3) != 0) {            ptrIn = last0;            encPtr = last1;        }        if (encPtr / 3 * 2 > dataLength - 2) {            return -1;        }        i = 0;        for (; i < encPtr; i += 3) {            a = 1600 * enc[i] + 40 * enc[i + 1] + enc[i + 2] + 1;            data[dataOffset + ptrOut++] = (byte)(a / 256);            data[dataOffset + ptrOut++] = (byte)a;        }        data[ptrOut++] = (byte)254;        i = asciiEncodation(text, ptrIn, textLength - ptrIn, data, ptrOut, dataLength - ptrOut);        if (i < 0)            return i;        return ptrOut + i;    }    private static int getEncodation(byte[] text, int textOffset, int textSize, byte[] data, int dataOffset, int dataSize, int options, boolean firstMatch) {        int e, j, k;        int[] e1 = new int[6];        if (dataSize < 0)            return -1;        e = -1;        options &= 7;        if (options == 0) {            e1[0] = asciiEncodation(text, textOffset, textSize, data, dataOffset, dataSize);            if (firstMatch && e1[0] >= 0)                return e1[0];            e1[1] = C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, false);            if (firstMatch && e1[1] >= 0)                return e1[1];            e1[2] = C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, true);            if (firstMatch && e1[2] >= 0)                return e1[2];            e1[3] = b256Encodation(text, textOffset, textSize, data, dataOffset, dataSize);            if (firstMatch && e1[3] >= 0)                return e1[3];            e1[4] = X12Encodation(text, textOffset, textSize, data, dataOffset, dataSize);            if (firstMatch && e1[4] >= 0)                return e1[4];            e1[5] = EdifactEncodation(text, textOffset, textSize, data, dataOffset, dataSize);            if (firstMatch && e1[5] >= 0)                return e1[5];            if (e1[0] < 0 && e1[1] < 0 && e1[2] < 0 && e1[3] < 0 && e1[4] < 0 && e1[5] < 0) {                return -1;            }            j = 0;            e = 99999;            for (k = 0; k < 6; ++k) {                if (e1[k] >= 0 && e1[k] < e) {                    e = e1[k];                    j = k;                }            }            if (j == 0)                e = asciiEncodation(text, textOffset, textSize, data, dataOffset, dataSize);            else if (j == 1)                e = C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, false);            else if (j == 2)                e = C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, true);            else if (j == 3)                e = b256Encodation(text, textOffset, textSize, data, dataOffset, dataSize);            else if (j == 4)                e = X12Encodation(text, textOffset, textSize, data, dataOffset, dataSize);            return e;        }        switch (options) {        case DM_ASCII:            return asciiEncodation(text, textOffset, textSize, data, dataOffset, dataSize);        case DM_C40:            return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, true);        case DM_TEXT:            return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, false);        case DM_B256:            return b256Encodation(text, textOffset, textSize, data, dataOffset, dataSize);        case DM_X21:            return X12Encodation(text, textOffset, textSize, data, dataOffset, dataSize);        case DM_EDIFACT:            return EdifactEncodation(text, textOffset, textSize, data, dataOffset, dataSize);        case DM_RAW:            if (textSize > dataSize)                return -1;            System.arraycopy(text, textOffset, data, dataOffset, textSize);            return textSize;        }        return -1;    }    private static int getNumber(byte[] text, int ptrIn, int n) {        int v, j, c;        v = 0;        for (j = 0; j < n; ++j) {            c = text[ptrIn++] &0xff;            if (c < '0' || c > '9')                return -1;            v = v * 10 + c - '0';        }        return v;    }    private int processExtensions(byte[] text, int textOffset, int textSize, byte[] data) {        int order, ptrIn, ptrOut, eci, fn, ft, fi, c;        if ((options & DM_EXTENSION) == 0)            return 0;        order = 0;        ptrIn = 0;        ptrOut = 0;        while (ptrIn < textSize) {            if (order > 20)                return -1;            c = text[textOffset + ptrIn++] &0xff;            ++order;            switch (c) {            case '.':                extOut = ptrIn;                return ptrOut;            case 'e':                if (ptrIn + 6 > textSize)                    return -1;                eci = getNumber(text, textOffset + ptrIn, 6);                if (eci < 0)                    return -1;                ptrIn += 6;                data[ptrOut++] = (byte)241;                if (eci < 127)                    data[ptrOut++] = (byte)(eci + 1);                else if (eci < 16383) {                    data[ptrOut++] = (byte)((eci - 127) / 254 + 128);                    data[ptrOut++] = (byte)(((eci - 127) % 254) + 1);                }                else {                    data[ptrOut++] = (byte)((eci - 16383) / 64516 + 192);                    data[ptrOut++] = (byte)((((eci - 16383) / 254) % 254) + 1);                    data[ptrOut++] = (byte)(((eci - 16383) % 254) + 1);                }                break;            case 's':                 if (order != 1)                    return -1;                if (ptrIn + 9 > textSize)                    return -1;                fn = getNumber(text, textOffset + ptrIn, 2);                if (fn <= 0 || fn > 16)                    return -1;                ptrIn += 2;                ft = getNumber(text, textOffset + ptrIn, 2);                if (ft <= 1 || ft > 16)                    return -1;                ptrIn += 2;                fi = getNumber(text, textOffset + ptrIn, 5);                if (fi < 0 || fn >= 64516)                    return -1;                ptrIn += 5;                data[ptrOut++] = (byte)(233);                data[ptrOut++] = (byte)(((fn - 1) << 4) | (17 - ft));                data[ptrOut++] = (byte)(fi / 254 + 1);                data[ptrOut++] = (byte)((fi % 254) + 1);                break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -