iTextSharp.text.pdf.BarcodeDatamatrix.C40OrTextEncodation C# (CSharp) Метод

C40OrTextEncodation() приватный статический Метод

private static C40OrTextEncodation ( byte text, int textOffset, int textLength, byte data, int dataOffset, int dataLength, bool c40 ) : int
text byte
textOffset int
textLength int
data byte
dataOffset int
dataLength int
c40 bool
Результат int
        private static int C40OrTextEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, bool 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{|}~\u007f";
            }
            else {
                basic = " 0123456789abcdefghijklmnopqrstuvwxyz";
                shift3 = "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\u007f";
            }
            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;
        }