示例#1
0
        /// <summary>
        /// Checks the code to be convertible into an interleaved 2 of 5 bar code.
        /// </summary>
        /// <param name="text">The code to be checked.</param>
        protected override void CheckCode(string text)
        {
//#if true_
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            if (text == "")
            {
                throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
            }

            if (text.Length % 2 != 0)
            {
                throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
            }

            foreach (char ch in text)
            {
                if (!Char.IsDigit(ch))
                {
                    throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
                }
            }
//#endif
        }
示例#2
0
        /// <summary>
        /// Checks the code to be convertible into an interleaved 2 of 5 bar code.
        /// </summary>
        /// <param name="text">The code to be checked.</param>
        protected override void CheckCode(string text)
        {
            // NOTE: this was commented out in the original source
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (text == "")
            {
                throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
            }

            if (text.Length % 2 != 0)
            {
                throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
            }

            foreach (char ch in text)
            {
                if (!Char.IsDigit(ch))
                {
                    throw new ArgumentException(BcgSR.Invalid2Of5Code(text));
                }
            }
        }
示例#3
0
        /// <summary>
        /// Checks the code to be convertible into an standard 3 of 9 bar code.
        /// </summary>
        /// <param name="text">The code to be checked.</param>
        protected override void CheckCode(string text)
        {
            if (text == null)
                throw new ArgumentNullException("text");

            if (text.Length == 0)
                throw new ArgumentException(BcgSR.Invalid3Of9Code(text));

            foreach (char ch in text)
            {
                if ("0123456789ABCDEFGHIJKLMNOP'QRSTUVWXYZ-. $/+%*".IndexOf(ch) < 0)
                    throw new ArgumentException(BcgSR.Invalid3Of9Code(text));
            }
        }
示例#4
0
        private int FindIndex(string name)
        {
            if (!this.marksInitialized)
            {
                InitMarks();
            }

            if (!this.nameToIndex.Contains(name))
            {
                throw new ArgumentException(BcgSR.InvalidMarkName(name));
            }

            return((int)this.nameToIndex[name]);
        }
示例#5
0
        private void CheckValues()
        {
            if (Values == null)
            {
                throw new InvalidOperationException("Text or Values must be set");
            }
            if (Values.Length == 0)
            {
                throw new InvalidOperationException("Text or Values must have content");
            }

            for (int x = 0; x < Values.Length; x++)
            {
                if (Values[x] > 102)
                {
                    throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
                }
            }
        }
示例#6
0
        private void CheckValues()
        {
            if (BarCode == null)
            {
                throw new InvalidOperationException("Text or Values must be set");
            }
            if (BarCode.Length == 0)
            {
                throw new InvalidOperationException("Text or Values must have content");
            }

            for (int x = 0; x < BarCode.Length; x++)
            {
                var charNumber = BarCode[x];
                if (charNumber > 127 && charNumber != FNC1)
                {
                    throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
                }
            }
        }
示例#7
0
        /// <summary>
        /// Encodes the DataMatrix.
        /// </summary>
        internal char[] Iec16022Ecc200(int columns, int rows, string encoding, int barcodeLength, string barcode, int len, int max, int ecc)
        {
            char[]      binary = new char[3000]; // encoded raw data and ecc to place in barcode
            Ecc200Block matrix = new Ecc200Block(0, 0, 0, 0, 0, 0, 0);

            for (int i = 0; i < 3000; i++)
            {
                binary[i] = (char)0;
            }

            foreach (Ecc200Block eccmatrix in ecc200Sizes)
            {
                matrix = eccmatrix;
                if (matrix.Width == columns && matrix.Height == rows)
                {
                    break;
                }
            }

            if (matrix.Width == 0)
            {
                throw new ArgumentException(BcgSR.DataMatrixInvalid(columns, rows));
            }

            if (!Ecc200Encode(ref binary, matrix.Bytes, barcode, barcodeLength, encoding, ref len))
            {
                throw new ArgumentException(BcgSR.DataMatrixTooBig);
            }

            // ecc code
            Ecc200(binary, matrix.Bytes, matrix.DataBlock, matrix.RSBlock);
            // placement
            int x;
            int y;
            int NR;

            int[] places;
            int   NC = columns - 2 * (columns / matrix.CellWidth);

            NR     = rows - 2 * (rows / matrix.CellHeight);
            places = new int[NC * NR];
            Ecc200Placement(ref places, NR, NC);
            char[] grid = new char[columns * rows];
            for (y = 0; y < rows; y += matrix.CellHeight)
            {
                for (x = 0; x < columns; x++)
                {
                    grid[y * columns + x] = (char)1;
                }
                for (x = 0; x < columns; x += 2)
                {
                    grid[(y + matrix.CellHeight - 1) * columns + x] = (char)1;
                }
            }

            for (x = 0; x < columns; x += matrix.CellWidth)
            {
                for (y = 0; y < rows; y++)
                {
                    grid[y * columns + x] = (char)1;
                }
                for (y = 0; y < rows; y += 2)
                {
                    grid[y * columns + x + matrix.CellWidth - 1] = (char)1;
                }
            }

            for (y = 0; y < NR; y++)
            {
                for (x = 0; x < NC; x++)
                {
                    int v = places[(NR - y - 1) * NC + x];
                    if (v == 1 || v > 7 && ((binary[(v >> 3) - 1] & (1 << (v & 7))) != 0))
                    {
                        grid[(1 + y + 2 * (y / (matrix.CellHeight - 2))) * columns + 1 + x + 2 * (x / (matrix.CellWidth - 2))] = (char)1;
                    }
                }
            }
            return(grid);
        }
示例#8
0
        /// <summary>
        /// Renders the content found in Text
        /// </summary>
        /// <param name="gfx">
        /// XGraphics - Instance of the drawing surface
        /// </param>
        /// <param name="brush">
        /// XBrush - Line and Color to draw the bar code
        /// </param>
        /// <param name="font">
        /// XFont - Font to use to draw the text string
        /// </param>
        /// <param name="position">
        /// XPoint - Location to render the bar code
        /// </param>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            // Create the array to hold the values to be rendered
            this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length];
            String buffer = String.Empty;

            for (Int32 index = 0; index < text.Length; index++)
            {
                switch (this.Code128Code)
                {
                case Code128Type.A:
                    if (text[index] < 32)
                    {
                        this.Values[index] = (byte)(text[index] + 64);
                    }
                    else if ((text[index] >= 32) && (text[index] < 64))
                    {
                        this.Values[index] = (byte)(text[index] - 32);
                    }
                    else
                    {
                        this.Values[index] = (byte)text[index];
                    }
                    break;

                case Code128Type.B:
                    this.Values[index] = (byte)(text[index] - 32);
                    break;

                case Code128Type.C:
                    if ((text[index] >= '0') && (text[index] <= '9'))
                    {
                        buffer += text[index];
                        if (buffer.Length == 2)
                        {
                            this.Values[index / 2] = byte.Parse(buffer);
                            buffer = String.Empty;
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C");
                    }
                    break;
                }
            }
            if (this.Values == null)
            {
                throw new InvalidOperationException("Text or Values must be set");
            }
            if (this.Values.Length == 0)
            {
                throw new InvalidOperationException("Text or Values must have content");
            }
            for (int x = 0; x < this.Values.Length; x++)
            {
                if (this.Values[x] > 102)
                {
                    throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
                }
            }
            XGraphicsState    state = gfx.Save();
            BarCodeRenderInfo info  = new BarCodeRenderInfo(gfx, brush, font, position);

            this.InitRendering(info);
            info.CurrPosInString = 0;
            info.CurrPos         = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
            this.RenderStart(info);
            foreach (byte c in this.Values)
            {
                this.RenderValue(info, c);
            }
            this.RenderStop(info);
            if (this.TextLocation != TextLocation.None)
            {
                this.RenderText(info);
            }
            gfx.Restore(state);
        }