Beispiel #1
0
        /// <summary>
        /// Returns implementation of "Code 128" barcode drawing.
        /// Supported characters are all from 7-bit ASCII.
        /// No start/end characters are supported.
        /// </summary>
        /// <param name="value">Value.</param>
        public static BarcodeImage GetNewCode128(string value)
        {
            BarcodeImage barcode = new BarcodeImage();

            barcode.InitCode128();
            barcode.Value        = value;
            barcode.ValueEncoder = Code128ValueEncoder;
            barcode.ValueEncoder.Invoke(barcode);
            return(barcode);
        }
Beispiel #2
0
        /// <summary>
        /// Returns implementation of "Codabar" barcode drawing.
        /// Also known as "NW-7", "USD-4" and "Code 2 of 7".
        /// Supported characters are: 0-9 - $ : / . +.
        /// Supported start/end characters are: A-D.
        /// </summary>
        /// <param name="startCharacter">Starting character.</param>
        /// <param name="value">Value.</param>
        /// <param name="endCharacter">Ending character.</param>
        public static BarcodeImage GetNewCodabar(char startCharacter, string value, char endCharacter)
        {
            BarcodeImage barcode = new BarcodeImage();

            barcode.InitCodabar();
            barcode.StartCharacter = startCharacter;
            barcode.EndCharacter   = endCharacter;
            barcode.Value          = value;
            barcode.ValueEncoder   = CodabarValueEncoder;
            barcode.ValueEncoder.Invoke(barcode);
            return(barcode);
        }
Beispiel #3
0
        }//GetCode128BestCodeSet

        private static int GetCode128CharPos(BarcodeImage barcode, string value, int codeTableIndex)
        {
            System.Collections.Generic.Dictionary <int, string> .Enumerator iMapping = barcode._code128MappingLookup[codeTableIndex].GetEnumerator();
            while (iMapping.MoveNext())
            {
                if (iMapping.Current.Value == value)
                {
                    return(iMapping.Current.Key);
                } //if
            }     //while
            return(-1);
        }         //GetCode128CharPos
Beispiel #4
0
        private static void Code128ValueEncoder(BarcodeImage barcode)
        {
            List <int> ev = new List <int>();

            int startCodeSet = GetCode128BestCodeSet(barcode, barcode.Value, -1);
            int checksum     = A_STARTA + startCodeSet;

            ev.AddRange(barcode._code128EncodingLookup[(byte)(A_STARTA + startCodeSet)]);

            int codeSet = startCodeSet;
            int j       = 1;

            for (int i = 0; i < barcode.Value.Length; i++)
            {
                int tmpCharIndex;

                int tmpOldCodeSet = codeSet;
                codeSet = GetCode128BestCodeSet(barcode, barcode.Value.Substring(i, barcode._value.Length - i), tmpOldCodeSet);
                if (codeSet == 2)
                {
                    tmpCharIndex = GetCode128CharPos(barcode, barcode.Value.Substring(i, 2), codeSet);
                }
                else
                {
                    tmpCharIndex = GetCode128CharPos(barcode, barcode.Value.Substring(i, 1), codeSet);
                }//if

                if (codeSet != tmpOldCodeSet)
                {
                    ev.AddRange(barcode._code128EncodingLookup[101 - codeSet]);
                    checksum += j * (101 - codeSet);
                    j        += 1;
                }//if

                ev.AddRange(barcode._code128EncodingLookup[tmpCharIndex]);
                checksum += j * tmpCharIndex;

                if (codeSet == 2)
                {
                    i++;
                }
                j += 1;
            }//for(i)

            ev.AddRange(barcode._code128EncodingLookup[checksum % 103]);
            ev.AddRange(barcode._code128EncodingLookup[A_STOP]);

            barcode.EncodedValue = ev.ToArray();
        }
Beispiel #5
0
        private static void CodabarValueEncoder(BarcodeImage barcode)
        {
            var ev = new List <int>();

            ev.AddRange(barcode._codabarStartStopEncoding[barcode.StartCharacter]);
            ev.Add(0);
            for (int i = 0; i < barcode.Value.Length; i++)
            {
                ev.AddRange(barcode._codabarValueEncoding[barcode.Value[i]]);
                ev.Add(0);
            }
            ev.AddRange(barcode._codabarStartStopEncoding[barcode.EndCharacter]);

            barcode.EncodedValue = ev.ToArray();
        }
Beispiel #6
0
        private static int GetCode128BestCodeSet(BarcodeImage barcode, string value, int currentCodeSetIndex)
        {
            int[] tmpCount = { 0, 0, 0 };

            int i;

            for (i = 0; i < value.Length; i++)
            {
                if (GetCode128CharPos(barcode, value.Substring(i, 1), 0) == -1)
                {
                    break;
                }
            }//for i
            tmpCount[0] = i;

            for (i = 0; i < value.Length; i++)
            {
                if (GetCode128CharPos(barcode, value.Substring(i, 1), 1) == -1)
                {
                    break;
                }
            }//for i
            tmpCount[1] = i;

            for (i = 0; i < value.Length - 1; i++)
            {
                if (GetCode128CharPos(barcode, value.Substring(i, 2), 2) == -1)
                {
                    break;
                }
            }//for i
            tmpCount[2] = i * 2;

            switch (currentCodeSetIndex)
            {
            case 0:
                if (tmpCount[0] > 0)
                {
                    tmpCount[0] += 1;
                }
                break;

            case 1:
                if (tmpCount[1] > 0)
                {
                    tmpCount[1] += 1;
                }
                break;

            case 2:
                if (tmpCount[2] > 0)
                {
                    tmpCount[2] += 2;
                }
                break;
            }//switch

            int tmpCountMax      = tmpCount[0];
            int tmpCountMaxIndex = 0;

            if (tmpCount[1] > tmpCountMax)
            {
                tmpCountMax = tmpCount[1]; tmpCountMaxIndex = 1;
            }
            if (tmpCount[2] > tmpCountMax)
            {
                tmpCountMax = tmpCount[2]; tmpCountMaxIndex = 2;
            }

            return(tmpCountMaxIndex);
        }//GetCode128BestCodeSet