Пример #1
0
        private void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
            {
                info.Font = new XFont("Courier New", Size.Height / 6);
            }
            XPoint center = info.Position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);

            if (TextLocation == TextLocation.Above)
            {
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormat.TopCenter);
            }
            else if (TextLocation == TextLocation.AboveEmbedded)
            {
                XSize textSize = info.Gfx.MeasureString(this.text, info.Font);
                textSize.Width += this.Size.Width * .15;
                XPoint point = info.Position;
                point.X += (this.Size.Width - textSize.Width) / 2;
                XRect rect = new XRect(point, textSize);
                info.Gfx.DrawRectangle(XBrushes.White, rect);
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormat.TopCenter);
            }
            else if (TextLocation == TextLocation.Below)
            {
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormat.BottomCenter);
            }
            else if (TextLocation == TextLocation.BelowEmbedded)
            {
                XSize textSize = info.Gfx.MeasureString(this.text, info.Font);
                textSize.Width += this.Size.Width * .15;
                XPoint point = info.Position;
                point.X += (this.Size.Width - textSize.Width) / 2;
                point.Y += Size.Height - textSize.height;
                XRect rect = new XRect(point, textSize);
                info.Gfx.DrawRectangle(XBrushes.White, rect);
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormat.BottomCenter);
            }
        }
Пример #2
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)
        {
            XGraphicsState state = gfx.Save();

            BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);

            InitRendering(info);
            info.CurrPosInString = 0;
            info.CurrPos         = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);

            RenderStart(info);
            foreach (byte c in Values)
            {
                RenderValue(info, (int)c);
            }
            RenderStop(info);
            if (TextLocation != TextLocation.None)
            {
                RenderText(info);
            }

            gfx.Restore(state);
        }
Пример #3
0
        private void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
            {
                info.Font = new XFont("Courier New", Size.Height / 4);
            }
            XPoint center   = info.Position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);
            XSize  textSize = info.Gfx.MeasureString(this.text, info.Font);

            double height = textSize.height;
            double y      = info.Position.y + Size.Height - textSize.height;

            m_leftBlock.Height = height;
            m_leftBlock.y      = y;

            m_rightBlock.Height = height;
            m_rightBlock.y      = y;

            XPoint pos = new XPoint(info.Position.x, y);

            info.Gfx.DrawString(this.text.Substring(0, 1), info.Font, info.Brush, new XRect(pos, Size), XStringFormats.TopLeft);

            info.Gfx.DrawRectangle(XBrushes.White, m_leftBlock);
            info.Gfx.DrawString(this.text.Substring(1, 6), info.Font, info.Brush, m_leftBlock, XStringFormats.TopCenter);

            info.Gfx.DrawRectangle(XBrushes.White, m_rightBlock);

            string text = this.text.Substring(7);

            if (this.text.Length == 12)
            {
                text += CalculateChecksumDigit(this.text);
            }

            info.Gfx.DrawString(text, info.Font, info.Brush, m_rightBlock, XStringFormats.TopCenter);
        }
Пример #4
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);
        }