internal void Add(int position, string character, int characterType, LinearPattern pattern)
        {
            int          width  = pattern.GetWidth();
            LinearSymbol symbol = new LinearSymbol(character, characterType, pattern, width);

            Symbols.Add(position, symbol);
            MinimumWidth += width;
        }
        /// <summary>
        /// Adds the check digit to the encode.
        /// </summary>
        private void AddCheckDigit()
        {
            // Return if no symbols have been encoded.
            if (LinearEncoding.Symbols.Count == 0)
            {
                return;
            }

            _checkDigit = _checkDigit % 103;
            LinearPattern symbolPattern = _patternDictionary[_checkDigit];

            AddSymbolToEncode(_checkDigit.ToString(), 1, _checkDigit, symbolPattern);
        }
        /// <summary>
        /// Adds the supplied section and control characters to the encode.
        /// </summary>
        /// <param name="lastSubset"></param>
        /// <param name="sectionSubset"></param>
        /// <param name="sectionValue"></param>
        public void EncodeSection(Code128Subset lastSubset, Code128Subset sectionSubset, string sectionValue)
        {
            // Add the subset select or change control symbol to the encode
            string        character     = GetSubsetAsString(sectionSubset);
            int           symbol        = _symbologyCharEncode[GetSubsetAsString(lastSubset) + GetSubsetAsString(sectionSubset)];
            LinearPattern symbolPattern = _patternDictionary[symbol];

            AddSymbolToEncode(character, 1, symbol, symbolPattern);
            ZplEncode += GetZplFunction(GetSubsetAsString(lastSubset) + GetSubsetAsString(sectionSubset));

            // Add FNC1 symbol if GS1-128 Barcode
            if (lastSubset == Code128Subset.Null && _isGs1)
            {
                symbol        = _symbologyCharEncode["FNC1"];
                symbolPattern = _patternDictionary[symbol];
                AddSymbolToEncode("F1", 1, symbol, symbolPattern);
                ZplEncode += GetZplFunction("FNC1");
            }

            if (sectionSubset == Code128Subset.C)    //Subset C encoder
            {
                for (int encodePosition = 0; encodePosition <= sectionValue.Length - 1; encodePosition += 2)
                {
                    // Encode the current numeric pair symbol
                    character     = sectionValue.Substring(encodePosition, 2);
                    symbol        = Convert.ToInt32(character);
                    symbolPattern = _patternDictionary[symbol];
                    AddSymbolToEncode(character, 0, symbol, symbolPattern);
                    ZplEncode += character;
                }
            }
            else
            {
                for (int encodePosition = 0; encodePosition <= sectionValue.Length - 1; encodePosition++)
                {
                    character     = sectionValue.Substring(encodePosition, 1);
                    symbol        = _symbologyCharEncode[((int)sectionValue[encodePosition]).ToString()];
                    symbolPattern = _patternDictionary[symbol];
                    AddSymbolToEncode(character, 0, symbol, symbolPattern);
                    if (sectionSubset == Code128Subset.A)
                    {
                        string subsetACode = "0" + symbol.ToString();
                        ZplEncode += subsetACode.Substring(subsetACode.Length - 2, 2);
                    }
                    else
                    {
                        ZplEncode += character;
                    }
                }
            }
        }
        /// <summary>
        /// Adds the stop symbol to the encode.
        /// </summary>
        private void AddStopSymbol()
        {
            // Return if no symbols have been encoded.
            if (LinearEncoding.Symbols.Count == 0)
            {
                return;
            }

            string        character     = "S";
            int           symbol        = _symbologyCharEncode[character];
            LinearPattern symbolPattern = _patternDictionary[symbol];

            AddSymbolToEncode(character, 1, symbol, symbolPattern);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the barcode image element.
        /// </summary>
        /// <param name="linearEncoder"></param>
        /// <param name="quietzone"></param>
        /// <returns>The generated barcode image inside an ImageElement object.</returns>
        internal static ImageElement GetBarcodeImage(LinearEncoder linearEncoder, int quietzone)
        {
            // Set the encoding image width from the minimum width multiplied by the x-dimension
            int barcodeImageWidth = linearEncoder.LinearEncoding.MinimumWidth * linearEncoder.XDimension;

            // Create a new bitmap image for the barcode based on the calculated dimensions
            ImageElement barcodeElement = new ImageElement(new Bitmap(barcodeImageWidth, linearEncoder.BarcodeHeight));

            barcodeElement.Image.SetResolution(linearEncoder.Dpi, linearEncoder.Dpi);

            //Create a new graphics to draw on the barcode image
            Graphics barcodeGraphics = Graphics.FromImage(barcodeElement.Image);

            int xPosition = 0;
            int yPosition = 0;

            barcodeGraphics.FillRectangle(Brushes.White, xPosition, yPosition, barcodeElement.Image.Width, barcodeElement.Image.Height);

            // Loop through each encoded symbol and convert to bars based on selected symbology
            for (int symbol = 0; symbol <= linearEncoder.LinearEncoding.Symbols.Count - 1; symbol++)
            {
                LinearPattern symbolPattern = linearEncoder.LinearEncoding.Symbols[symbol].Pattern;

                // Build the barcode symbol and insert
                for (int module = 0; module <= symbolPattern.Count - 1; module++)
                {
                    switch (symbolPattern[module].ModuleType)
                    {
                    case ModuleType.Bar:     // Bar
                        int barWidth = symbolPattern[module].Width * linearEncoder.XDimension;
                        barcodeGraphics.FillRectangle(Brushes.Black, xPosition, yPosition, barWidth, linearEncoder.BarcodeHeight);
                        xPosition += barWidth;
                        barcodeGraphics.Flush();
                        break;

                    case ModuleType.Space:     // Space
                        int spaceWidth = symbolPattern[module].Width * linearEncoder.XDimension;
                        xPosition += spaceWidth;
                        break;
                    }
                }
            }

            barcodeElement.Position.XPosition = quietzone;
            return(barcodeElement);
        }
        /// <summary>
        /// Adds the given symbol to the encode.
        /// </summary>
        /// <param name="character"></param>
        /// <param name="characterType"></param>
        /// <param name="symbol"></param>
        /// <param name="symbolPattern"></param>
        private void AddSymbolToEncode(string character, int characterType, int symbol, LinearPattern symbolPattern)
        {
            int barcodePosition = LinearEncoding.Symbols.Count;

            LinearEncoding.Add(character, characterType, symbolPattern);

            if (barcodePosition == 0)
            {
                _checkDigit = symbol;
            }
            else
            {
                _checkDigit += (barcodePosition * symbol);
            }
        }
        internal void Add(string character, int characterType, LinearPattern pattern)
        {
            int position = Symbols.Count;

            Add(position, character, characterType, pattern);
        }