예제 #1
0
        public static char GetStartSymbol(Barcode128CodeSet codeSet)
        {
            switch (codeSet)
            {
            case Barcode128CodeSet.A:
                return(START_A);

            case Barcode128CodeSet.B:
                return(START_B);

            case Barcode128CodeSet.C:
                return(START_C);

            default:
                return(START_B);
            }
        }
예제 #2
0
        /** Converts the human readable text to the characters needed to
         * create a barcode using the specified code set.
         * @param text the text to convert
         * @param ucc <CODE>true</CODE> if it is an UCC/EAN-128. In this case
         * the character FNC1 is added
         * @param codeSet forced code set, or AUTO for optimized barcode.
         * @return the code ready to be fed to getBarsCode128Raw()
         */
        public static string GetRawText(string text, bool ucc, Barcode128CodeSet codeSet)
        {
            String outs = "";
            int    tLen = text.Length;

            if (tLen == 0)
            {
                outs += GetStartSymbol(codeSet);
                if (ucc)
                {
                    outs += FNC1_INDEX;
                }
                return(outs);
            }
            int c = 0;

            for (int k = 0; k < tLen; ++k)
            {
                c = text[k];
                if (c > 127 && c != FNC1)
                {
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));
                }
            }
            c = text[0];
            char currentCode = START_B;
            int  index       = 0;

            if ((codeSet == Barcode128CodeSet.AUTO || codeSet == Barcode128CodeSet.C) && IsNextDigits(text, index, 2))
            {
                currentCode = START_C;
                outs       += currentCode;
                if (ucc)
                {
                    outs += FNC1_INDEX;
                }
                String out2 = GetPackedRawDigits(text, index, 2);
                index += (int)out2[0];
                outs  += out2.Substring(1);
            }
            else if (c < ' ')
            {
                currentCode = START_A;
                outs       += currentCode;
                if (ucc)
                {
                    outs += FNC1_INDEX;
                }
                outs += (char)(c + 64);
                ++index;
            }
            else
            {
                outs += currentCode;
                if (ucc)
                {
                    outs += FNC1_INDEX;
                }
                if (c == FNC1)
                {
                    outs += FNC1_INDEX;
                }
                else
                {
                    outs += (char)(c - ' ');
                }
                ++index;
            }
            if (currentCode != GetStartSymbol(codeSet))
            {
                throw new Exception(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));
            }
            while (index < tLen)
            {
                switch (currentCode)
                {
                case START_A: {
                    if (codeSet == Barcode128CodeSet.AUTO && IsNextDigits(text, index, 4))
                    {
                        currentCode = START_C;
                        outs       += CODE_AB_TO_C;
                        String out2 = GetPackedRawDigits(text, index, 4);
                        index += (int)out2[0];
                        outs  += out2.Substring(1);
                    }
                    else
                    {
                        c = text[index++];
                        if (c == FNC1)
                        {
                            outs += FNC1_INDEX;
                        }
                        else if (c > '_')
                        {
                            currentCode = START_B;
                            outs       += CODE_AC_TO_B;
                            outs       += (char)(c - ' ');
                        }
                        else if (c < ' ')
                        {
                            outs += (char)(c + 64);
                        }
                        else
                        {
                            outs += (char)(c - ' ');
                        }
                    }
                }
                break;

                case START_B: {
                    if (codeSet == Barcode128CodeSet.AUTO && IsNextDigits(text, index, 4))
                    {
                        currentCode = START_C;
                        outs       += CODE_AB_TO_C;
                        String out2 = GetPackedRawDigits(text, index, 4);
                        index += (int)out2[0];
                        outs  += out2.Substring(1);
                    }
                    else
                    {
                        c = text[index++];
                        if (c == FNC1)
                        {
                            outs += FNC1_INDEX;
                        }
                        else if (c < ' ')
                        {
                            currentCode = START_A;
                            outs       += CODE_BC_TO_A;
                            outs       += (char)(c + 64);
                        }
                        else
                        {
                            outs += (char)(c - ' ');
                        }
                    }
                }
                break;

                case START_C: {
                    if (IsNextDigits(text, index, 2))
                    {
                        String out2 = GetPackedRawDigits(text, index, 2);
                        index += (int)out2[0];
                        outs  += out2.Substring(1);
                    }
                    else
                    {
                        c = text[index++];
                        if (c == FNC1)
                        {
                            outs += FNC1_INDEX;
                        }
                        else if (c < ' ')
                        {
                            currentCode = START_A;
                            outs       += CODE_BC_TO_A;
                            outs       += (char)(c + 64);
                        }
                        else
                        {
                            currentCode = START_B;
                            outs       += CODE_AC_TO_B;
                            outs       += (char)(c - ' ');
                        }
                    }
                }
                break;
                }
                if (codeSet != Barcode128CodeSet.AUTO && currentCode != GetStartSymbol(codeSet))
                {
                    throw new Exception(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));
                }
            }
            return(outs);
        }
예제 #3
0
        /** Converts the human readable text to the characters needed to
         * create a barcode using the specified code set.
         * @param text the text to convert
         * @param ucc <CODE>true</CODE> if it is an UCC/EAN-128. In this case
         * the character FNC1 is added
         * @param codeSet forced code set, or AUTO for optimized barcode.
         * @return the code ready to be fed to getBarsCode128Raw()
         */
        public static string GetRawText(string text, bool ucc, Barcode128CodeSet codeSet) {
            String outs = "";
            int tLen = text.Length;
            if (tLen == 0) {
                outs += GetStartSymbol(codeSet);
                if (ucc)
                    outs += FNC1_INDEX;
                return outs;
            }
            int c = 0;
            for (int k = 0; k < tLen; ++k) {
                c = text[k];
                if (c > 127 && c != FNC1)
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));
            }
            c = text[0];
            char currentCode = START_B;
            int index = 0;
            if ((codeSet == Barcode128CodeSet.AUTO || codeSet == Barcode128CodeSet.C) && IsNextDigits(text, index, 2)) {
                currentCode = START_C;
                outs += currentCode;
                if (ucc)
                    outs += FNC1_INDEX;
                String out2 = GetPackedRawDigits(text, index, 2);
                index += (int)out2[0];
                outs += out2.Substring(1);
            }
            else if (c < ' ') {
                currentCode = START_A;
                outs += currentCode;
                if (ucc)
                    outs += FNC1_INDEX;
                outs += (char)(c + 64);
                ++index;
            }
            else {
                outs += currentCode;
                if (ucc)
                    outs += FNC1_INDEX;
                if (c == FNC1)
                    outs += FNC1_INDEX;
                else
                    outs += (char)(c - ' ');
                ++index;
            }
            if (codeSet != Barcode128CodeSet.AUTO && currentCode != GetStartSymbol(codeSet))
                throw new Exception(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));
            while (index < tLen) {
                switch (currentCode) {
                    case START_A: {
                        if (codeSet == Barcode128CodeSet.AUTO && IsNextDigits(text, index, 4)) {
                            currentCode = START_C;
                            outs += CODE_AB_TO_C;
                            String out2 = GetPackedRawDigits(text, index, 4);
                            index += (int) out2[0];
                            outs += out2.Substring(1);
                        } else {
                            c = text[index++];
                            if (c == FNC1)
                                outs += FNC1_INDEX;
                            else if (c > '_') {
                                currentCode = START_B;
                                outs += CODE_AC_TO_B;
                                outs += (char) (c - ' ');
                            } else if (c < ' ')
                                outs += (char) (c + 64);
                            else
                                outs += (char) (c - ' ');
                        }
                    }
                        break;
                    case START_B: {
                        if (codeSet == Barcode128CodeSet.AUTO && IsNextDigits(text, index, 4)) {
                            currentCode = START_C;
                            outs += CODE_AB_TO_C;
                            String out2 = GetPackedRawDigits(text, index, 4);
                            index += (int) out2[0];
                            outs += out2.Substring(1);
                        } else {
                            c = text[index++];
                            if (c == FNC1)
                                outs += FNC1_INDEX;
                            else if (c < ' ') {
                                currentCode = START_A;
                                outs += CODE_BC_TO_A;
                                outs += (char) (c + 64);
                            } else {
                                outs += (char) (c - ' ');
                            }
                        }
                    }
                        break;
                    case START_C: {
                        if (IsNextDigits(text, index, 2)) {
                            String out2 = GetPackedRawDigits(text, index, 2);
                            index += (int) out2[0];
                            outs += out2.Substring(1);
                        } else {
                            c = text[index++];
                                if (c == FNC1)
                                    outs += FNC1_INDEX;
                                else if (c < ' ') {
                                    currentCode = START_A;
                                    outs += CODE_BC_TO_A;
                                    outs += (char)(c + 64);
                                }
                                else {
                                    currentCode = START_B;
                                    outs += CODE_AC_TO_B;
                                    outs += (char) (c - ' ');
                                }
                        }
                    }
                        break;
                }
                if (codeSet != Barcode128CodeSet.AUTO && currentCode != GetStartSymbol(codeSet))
                    throw new Exception(MessageLocalization.GetComposedMessage("there.are.illegal.characters.for.barcode.128.in.1", text));

            }
            return outs;
        }
예제 #4
0
 public static char GetStartSymbol(Barcode128CodeSet codeSet) {
     switch (codeSet) {
         case Barcode128CodeSet.A:
             return START_A;
         case Barcode128CodeSet.B:
             return START_B;
         case Barcode128CodeSet.C:
             return START_C;
         default:
             return START_B;
     }
 }