示例#1
0
/// <summary>Constructor</summary>
/// <param name="values">byte[] - The values to be rendered</param>
/// <param name="size">XSize - The size of the bar code</param>
/// <param name="direction">CodeDirection - Indicates the direction to draw the bar code</param>
/// <param name="code128Code">Code_128_Code_Types - Indicates which of the codes to use when rendering the bar code.
/// The options are A, B, or buffer.</param>
        public Code128(byte[] values, XSize size, CodeDirection direction, Code_128_Code_Types code128Code)
            : base(null, size, direction)
        {
            if (!Enum.IsDefined(typeof(Code_128_Code_Types), code128Code))
            {
                throw new ArgumentOutOfRangeException("Parameter code128Code (Code_128_Code_Types) is invalid");
            }
            if (Patterns == null)
            {
                Load();
            }
            Code128Code = code128Code;
            Values      = values;
        }
示例#2
0
/// <summary>Constructor</summary>
/// <param name="text">String - The text to be coded</param>
/// <param name="size">XSize - The size of the bar code</param>
/// <param name="direction">CodeDirection - Indicates the direction to draw the bar code</param>
/// <param name="code128Code">Code_128_Code_Types - Indicates which of the codes to use when rendering the bar code.
/// The options are A, B, or buffer.</param>
        public Code128(string text, XSize size, CodeDirection direction, Code_128_Code_Types code128Code)
            : this((byte[])null, size, direction, code128Code)
        {
            this.Text = text;


// Create the array to hold the values to be rendered
            if (Code128Code == Code_128_Code_Types.CodeC)
            {
// Ensure that the text is an even length
                if ((text.Length % 2) == 1)
                {
                    throw new ArgumentOutOfRangeException("Parameter text (string) must have an even length for Code 128 - Code C");
                }
                Values = new byte[text.Length / 2];
            }
            else
            {
                Values = new byte[text.Length];
            }


            String buffer = "";

            for (int x = 0; x < text.Length; x++)
            {
                switch (Code128Code)
                {
                case Code_128_Code_Types.CodeA:
                    if (text[x] < 32)
                    {
                        Values[x] = (byte)(text[x] + 64);
                    }
                    else if ((text[x] >= 32) && (text[x] < 64))
                    {
                        Values[x] = (byte)(text[x] - 32);
                    }
                    else
                    {
                        Values[x] = (byte)text[x];
                    }
                    break;

                case Code_128_Code_Types.CodeB:
                    Values[x] = (byte)(text[x] - 32);
                    break;

                case Code_128_Code_Types.CodeC:
                    if ((text[x] >= '0') && (text[x] <= '9'))
                    {
                        buffer += text[x];
                        if (buffer.Length == 2)
                        {
                            Values[x / 2] = byte.Parse(buffer);
                            buffer        = "";
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C");
                    }
                    break;
                }
            }
            CheckValues();
        }