Exemple #1
0
        private static char GetStartSymbol(Barcode128.Barcode128CodeSet codeSet)
        {
            switch (codeSet)
            {
            case Barcode128.Barcode128CodeSet.A: {
                return(START_A);
            }

            case Barcode128.Barcode128CodeSet.B: {
                return(START_B);
            }

            case Barcode128.Barcode128CodeSet.C: {
                return(START_C);
            }

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

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

            for (int k = 0; k < tLen; ++k)
            {
                c = text[k];
                if (c > 127 && c != FNC1)
                {
                    throw new PdfException(PdfException.ThereAreIllegalCharactersForBarcode128In1);
                }
            }
            c = text[0];
            char currentCode = GetStartSymbol(codeSet);
            int  index       = 0;

            if ((codeSet == Barcode128.Barcode128CodeSet.AUTO || codeSet == Barcode128.Barcode128CodeSet.C) && IsNextDigits
                    (text, index, 2))
            {
                currentCode = START_C;
                @out       += currentCode;
                if (ucc)
                {
                    @out += FNC1_INDEX;
                }
                String out2 = GetPackedRawDigits(text, index, 2);
                index += out2[0];
                @out  += out2.Substring(1);
            }
            else
            {
                if (c < ' ')
                {
                    currentCode = START_A;
                    @out       += currentCode;
                    if (ucc)
                    {
                        @out += FNC1_INDEX;
                    }
                    @out += (char)(c + 64);
                    ++index;
                }
                else
                {
                    @out += currentCode;
                    if (ucc)
                    {
                        @out += FNC1_INDEX;
                    }
                    if (c == FNC1)
                    {
                        @out += FNC1_INDEX;
                    }
                    else
                    {
                        @out += (char)(c - ' ');
                    }
                    ++index;
                }
            }
            if (codeSet != Barcode128.Barcode128CodeSet.AUTO && currentCode != GetStartSymbol(codeSet))
            {
                throw new PdfException(PdfException.ThereAreIllegalCharactersForBarcode128In1);
            }
            while (index < tLen)
            {
                switch (currentCode)
                {
                case START_A: {
                    if (codeSet == Barcode128.Barcode128CodeSet.AUTO && IsNextDigits(text, index, 4))
                    {
                        currentCode = START_C;
                        @out       += CODE_AB_TO_C;
                        String out2 = GetPackedRawDigits(text, index, 4);
                        index += out2[0];
                        @out  += out2.Substring(1);
                    }
                    else
                    {
                        c = text[index++];
                        if (c == FNC1)
                        {
                            @out += FNC1_INDEX;
                        }
                        else
                        {
                            if (c > '_')
                            {
                                currentCode = START_B;
                                @out       += CODE_AC_TO_B;
                                @out       += (char)(c - ' ');
                            }
                            else
                            {
                                if (c < ' ')
                                {
                                    @out += (char)(c + 64);
                                }
                                else
                                {
                                    @out += (char)(c - ' ');
                                }
                            }
                        }
                    }
                    break;
                }

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

                case START_C: {
                    if (IsNextDigits(text, index, 2))
                    {
                        String out2 = GetPackedRawDigits(text, index, 2);
                        index += out2[0];
                        @out  += out2.Substring(1);
                    }
                    else
                    {
                        c = text[index++];
                        if (c == FNC1)
                        {
                            @out += FNC1_INDEX;
                        }
                        else
                        {
                            if (c < ' ')
                            {
                                currentCode = START_A;
                                @out       += CODE_BC_TO_A;
                                @out       += (char)(c + 64);
                            }
                            else
                            {
                                currentCode = START_B;
                                @out       += CODE_AC_TO_B;
                                @out       += (char)(c - ' ');
                            }
                        }
                    }
                    break;
                }
                }
                if (codeSet != Barcode128.Barcode128CodeSet.AUTO && currentCode != GetStartSymbol(codeSet))
                {
                    throw new PdfException(PdfException.ThereAreIllegalCharactersForBarcode128In1);
                }
            }
            return(@out);
        }
Exemple #3
0
 public virtual void SetCodeSet(Barcode128.Barcode128CodeSet codeSet)
 {
     this.codeSet = codeSet;
 }