Exemple #1
0
 private void RenderStart(BarCodeRenderInfo info)
 {
     RenderBar(info, false);
     RenderGap(info, false);
     RenderBar(info, false);
     RenderGap(info, false);
 }
Exemple #2
0
        /// <summary>
        /// Renders the bar code.
        /// </summary>
        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 = info.Center - Size / 2;
            info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);

            if (TurboBit)
            {
                RenderTurboBit(info, true);
            }
            RenderStart(info);
            while (info.CurrPosInString < Text.Length)
            {
                RenderNextPair(info);
            }
            RenderStop(info);
            if (TurboBit)
            {
                RenderTurboBit(info, false);
            }
            if (TextLocation != TextLocation.None)
            {
                RenderText(info);
            }

            gfx.Restore(state);
        }
        internal void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
            {
                info.Font = new XFont("Courier New", Size.Height / 6);
            }
            XPoint center = info.Position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            switch (TextLocation)
            {
            case TextLocation.Above:
                center = new XPoint(center.X, center.Y - info.Gfx.MeasureString(Text, info.Font).Height);
                info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
                break;

            case TextLocation.AboveEmbedded:
                info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
                break;

            case TextLocation.Below:
                center = new XPoint(center.X, info.Gfx.MeasureString(Text, info.Font).Height + center.Y);
                info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
                break;

            case TextLocation.BelowEmbedded:
                info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
                break;
            }
        }
        internal override void InitRendering(BarCodeRenderInfo info)
        {
            base.InitRendering(info);
            CalcThinBarWidth(info);
            info.BarHeight = Size.Height;
            // HACK in ThickThinBarCode
            if (this.textLocation != TextLocation.None)
            {
                info.BarHeight *= 4.0 / 5;
            }

#if DEBUG_
            XColor back = XColors.LightSalmon;
            back.A = 0.3;
            XSolidBrush brush = new XSolidBrush(back);
            info.Gfx.DrawRectangle(brush, new XRect(info.Center - this.size / 2, this.size));
#endif
            switch (this.direction)
            {
            case CodeDirection.RightToLeft:
                info.Gfx.RotateAtTransform(180, info.Position);
                break;

            case CodeDirection.TopToBottom:
                info.Gfx.RotateAtTransform(90, info.Position);
                break;

            case CodeDirection.BottomToTop:
                info.Gfx.RotateAtTransform(-90, info.Position);
                break;
            }
        }
Exemple #5
0
        /// <summary>
        /// Renders a single line of the character. Each character has three lines and three spaces
        /// </summary>
        /// <param name="info">
        /// </param>
        /// <param name="barWidth">
        /// Indicates the thickness of the line/bar to be rendered.
        /// </param>
        /// <param name="brush">
        /// Indicates the brush to use to render the line/bar.
        /// </param>
        private void RenderBar(BarCodeRenderInfo info, double barWidth, XBrush brush)
        {
            double height = this.Size.Height;
            double yPos   = info.CurrPos.Y;

            switch (this.TextLocation)
            {
            case TextLocation.Above:
                yPos    = info.CurrPos.Y + (height / 5);
                height *= 4.0 / 5;
                break;

            case TextLocation.Below:
                height *= 4.0 / 5;
                break;

            case TextLocation.AboveEmbedded:
            case TextLocation.BelowEmbedded:
            case TextLocation.None:
                break;
            }
            XRect rect = new XRect(info.CurrPos.X, yPos, barWidth, height);

            info.Gfx.DrawRectangle(brush, rect);
            info.CurrPos.X += barWidth;
        }
    internal override void InitRendering(BarCodeRenderInfo info)
    {
      base.InitRendering(info);
      CalcThinBarWidth(info);
      info.BarHeight = Size.Height;
      // HACK in ThickThinBarCode
      if (this.textLocation != TextLocation.None)
        info.BarHeight *= 4.0 / 5;

#if DEBUG_
      XColor back = XColors.LightSalmon;
      back.A = 0.3;
      XSolidBrush brush = new XSolidBrush(back);
      info.Gfx.DrawRectangle(brush, new XRect(info.Center - this.size / 2, this.size));
#endif
      switch (this.direction)
      {
        case CodeDirection.RightToLeft:
          info.Gfx.RotateAtTransform(180, info.Position);
          break;

        case CodeDirection.TopToBottom:
          info.Gfx.RotateAtTransform(90, info.Position);
          break;

        case CodeDirection.BottomToTop:
          info.Gfx.RotateAtTransform(-90, info.Position);
          break;
      }
    }
 /// <summary>
 /// Gets the width of a thick or a thin line (or gap). CalcLineWidth must have been called before.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="isThick">Determines whether a thick line's with shall be returned.</param>
 internal double GetBarWidth(BarCodeRenderInfo info, bool isThick)
 {
     if (isThick)
     {
         return(info.ThinBarWidth * _wideNarrowRatio);
     }
     return(info.ThinBarWidth);
 }
        internal 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);

            //center.Y += info.Font.Size;
            info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
        }
Exemple #9
0
        /// <summary>
        /// Renders a thick or thin line for the bar code.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="isThick">Determines whether a thick or a thin line is about to be rendered.</param>
        internal void RenderBar(BarCodeRenderInfo info, bool isThick)
        {
            double barWidth = GetBarWidth(info, isThick);
            double height   = Size.Height;
            //if (TextLocation != TextLocation.None)
            //  height *= 4.0 / 5;
            XRect rect = new XRect(info.CurrPos.X, info.CurrPos.Y, barWidth, height);

            info.Gfx.DrawRectangle(info.Brush, rect);
            info.CurrPos.X += barWidth;
        }
Exemple #10
0
 private void RenderValue(BarCodeRenderInfo info, bool[] value)
 {
     foreach (bool bar in value)
     {
         if (bar)
         {
             XRect rect = new XRect(info.CurrPos.X, info.CurrPos.Y, info.ThinBarWidth, Size.Height);
             info.Gfx.DrawRectangle(info.Brush, rect);
         }
         info.CurrPos.X += info.ThinBarWidth;
     }
 }
Exemple #11
0
 private void RenderChar(BarCodeRenderInfo info, char ch)
 {
     bool[] thickThinLines = ThickThinLines(ch);
     int idx = 0;
     while (idx < 9)
     {
         RenderBar(info, thickThinLines[idx]);
         if (idx < 8)
             RenderGap(info, thickThinLines[idx + 1]);
         idx += 2;
     }
 }
Exemple #12
0
        internal virtual void InitRendering(BarCodeRenderInfo info)
        {
            if (Text == null)
            {
                throw new InvalidOperationException(BcgSR.BarCodeNotSet);
            }

            if (Size.IsEmpty)
            {
                throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
            }
        }
Exemple #13
0
        private void RenderRight(BarCodeRenderInfo info)
        {
            string text = this.text.Substring(7);

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

            foreach (char ch in text)
            {
                RenderDigit(info, ch, RightLines);
            }
        }
Exemple #14
0
        /// <summary>
        /// Renders the next digit pair as bar code element.
        /// </summary>
        private void RenderNextPair(BarCodeRenderInfo info)
        {
            int digitForLines = int.Parse(Text[info.CurrPosInString].ToString());
            int digitForGaps  = int.Parse(Text[info.CurrPosInString + 1].ToString());

            bool[] linesArray = Lines[digitForLines];
            bool[] gapsArray  = Lines[digitForGaps];
            for (int idx = 0; idx < 5; ++idx)
            {
                RenderBar(info, linesArray[idx]);
                RenderGap(info, gapsArray[idx]);
            }
            info.CurrPosInString += 2;
        }
        /// <summary>
        /// Renders a thick bar before or behind the code.
        /// </summary>
        internal void RenderTurboBit(BarCodeRenderInfo info, bool startBit)
        {
            if (startBit)
            {
                info.CurrPos.X -= 0.5 + GetBarWidth(info, true);
            }
            else
            {
                info.CurrPos.X += 0.5; //GetBarWidth(info, true);
            }
            RenderBar(info, true);

            if (startBit)
            {
                info.CurrPos.X += 0.5; //GetBarWidth(info, true);
            }
        }
Exemple #16
0
        /// <summary>
        /// The render value.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <param name="chVal">
        /// The ch val.
        /// </param>
        private void RenderValue(BarCodeRenderInfo info, int chVal)
        {
            byte[] pattern = this.GetPattern(chVal);
            XBrush space   = XBrushes.White;

            for (int idx = 0; idx < pattern.Length; idx++)
            {
                if ((idx % 2) == 0)
                {
                    this.RenderBar(info, info.ThinBarWidth * pattern[idx]);
                }
                else
                {
                    this.RenderBar(info, info.ThinBarWidth * pattern[idx], space);
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// The init rendering.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        internal override void InitRendering(BarCodeRenderInfo info)
        {
            if (this.Values == null)
            {
                throw new InvalidOperationException(BcgSR.BarCodeNotSet);
            }
            if (this.Values.Length == 0)
            {
                throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
            }
            int numberOfBars = this.Values.Length + 3; // The length of the string plus the start, stop, and parity value

            numberOfBars *= 11;                        // Each character has 11 bars
            numberOfBars += 2;                         // Add two more because the stop bit has two extra bars
            // Calculating the width of a bar
            info.ThinBarWidth = this.Size.Width / numberOfBars;
        }
Exemple #18
0
 /// <summary>
 /// Calculates the thick and thin line widths,
 /// taking into account the required rendering size.
 /// </summary>
 internal override void CalcThinBarWidth(BarCodeRenderInfo info)
 {
     /*
      * The total width is the sum of the following parts:
      * Starting lines      = 3 * thick + 7 * thin
      *  +
      * Code Representation = (3 * thick + 7 * thin) * code.Length
      *  +
      * Stopping lines      =  3 * thick + 6 * thin
      * 
      * with r = relation ( = thick / thin), this results in
      * 
      * Total width = (13 + 6 * r + (3 * r + 7) * code.Length) * thin
      */
     double thinLineAmount = 13 + 6 * WideNarrowRatio + (3 * WideNarrowRatio + 7) * Text.Length;
     info.ThinBarWidth = Size.Width / thinLineAmount;
 }
        /// <summary>
        /// Calculates the thick and thin line widths,
        /// taking into account the required rendering size.
        /// </summary>
        internal override void CalcThinBarWidth(BarCodeRenderInfo info)
        {
            /*
             * The total width is the sum of the following parts:
             * Starting lines      = 4 * thin
             *  +
             * Code Representation = (2 * thick + 3 * thin) * code.Length
             *  +
             * Stopping lines      =  1 * thick + 2 * thin
             *
             * with r = relation ( = thick / thin), this results in
             *
             * Total width = (6 + r + (2 * r + 3) * text.Length) * thin
             */
            double thinLineAmount = 6 + this.wideNarrowRatio + (2 * this.wideNarrowRatio + 3) * this.text.Length;

            info.ThinBarWidth = this.Size.Width / thinLineAmount;
        }
Exemple #20
0
        /// <summary>
        /// Renders the bar code.
        /// </summary>
        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);

            //   EAN13 Barcode should be a total of 113 modules wide.
            int numberOfBars = 12; // The length - country code

            numberOfBars     *= 7; // Each character has 7 bars
            numberOfBars     += 2 * (Quite.Length + Leading.Length);
            numberOfBars     += Separator.Length;
            info.ThinBarWidth = ((double)this.Size.Width / (double)numberOfBars);

            RenderStart(info);

            m_leftBlock.x = info.CurrPos.x + info.ThinBarWidth / 2;
            RenderLeft(info);
            m_leftBlock.Width = info.CurrPos.x - m_leftBlock.x;

            RenderSeparator(info);

            m_rightBlock.x = info.CurrPos.x;
            RenderRight(info);
            m_rightBlock.Width = info.CurrPos.x - m_rightBlock.x - info.ThinBarWidth / 2;

            RenderStop(info);

            if (this.TextLocation == TextLocation.BelowEmbedded)
            {
                RenderText(info);
            }

            gfx.Restore(state);
        }
Exemple #21
0
        /// <summary>
        /// The render text.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        private void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
            {
                info.Font = new XFont("Courier New", this.Size.Height / 6);
            }
            XPoint center = info.Position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);

            if (this.TextLocation == TextLocation.Above)
            {
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, this.Size), XStringFormats.TopCenter);
            }
            else if (this.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, this.Size), XStringFormats.TopCenter);
            }
            else if (this.TextLocation == TextLocation.Below)
            {
                info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, this.Size), XStringFormats.BottomCenter);
            }
            else if (this.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 += this.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, this.Size), XStringFormats.BottomCenter);
            }
        }
Exemple #22
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);
        }
Exemple #23
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);
        }
        /// <summary>
        /// Renders a thick or thin line for the bar code.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="isThick">Determines whether a thick or a thin line is about to be rendered.</param>
        internal void RenderBar(BarCodeRenderInfo info, bool isThick)
        {
            double barWidth = GetBarWidth(info, isThick);
            double height   = Size.Height;
            double xPos     = info.CurrPos.X;
            double yPos     = info.CurrPos.Y;

            switch (TextLocation)
            {
            case TextLocation.AboveEmbedded:
                height -= info.Gfx.MeasureString(Text, info.Font).Height;
                yPos   += info.Gfx.MeasureString(Text, info.Font).Height;
                break;

            case TextLocation.BelowEmbedded:
                height -= info.Gfx.MeasureString(Text, info.Font).Height;
                break;
            }

            XRect rect = new XRect(xPos, yPos, barWidth, height);

            info.Gfx.DrawRectangle(info.Brush, rect);
            info.CurrPos.X += barWidth;
        }
Exemple #25
0
 /// <summary>
 /// Renders a single line of the character. Each character has three lines and three spaces
 /// </summary>
 /// <param name="info">
 /// </param>
 /// <param name="barWidth">
 /// Indicates the thickness of the line/bar to be rendered. 
 /// </param>
 internal void RenderBar(BarCodeRenderInfo info, double barWidth) { this.RenderBar(info, barWidth, info.Brush); }
Exemple #26
0
 /// <summary>
 /// The render value.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 /// <param name="chVal">
 /// The ch val.
 /// </param>
 private void RenderValue(BarCodeRenderInfo info, int chVal)
 {
     byte[] pattern = this.GetPattern(chVal);
     XBrush space = XBrushes.White;
     for (int idx = 0; idx < pattern.Length; idx++)
         if ((idx % 2) == 0)
             this.RenderBar(info, info.ThinBarWidth * pattern[idx]);
         else
             this.RenderBar(info, info.ThinBarWidth * pattern[idx], space);
 }
Exemple #27
0
 /// <summary>
 /// The init rendering.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 /// <exception cref="InvalidOperationException">
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// </exception>
 internal override void InitRendering(BarCodeRenderInfo info)
 {
     if (this.Values == null)
         throw new InvalidOperationException(BcgSR.BarCodeNotSet);
     if (this.Values.Length == 0)
         throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
     int numberOfBars = this.Values.Length + 3; // The length of the string plus the start, stop, and parity value
     numberOfBars *= 11; // Each character has 11 bars
     numberOfBars += 2; // Add two more because the stop bit has two extra bars
     // Calculating the width of a bar
     info.ThinBarWidth = this.Size.Width / numberOfBars;
 }
Exemple #28
0
    internal virtual void InitRendering(BarCodeRenderInfo info)
    {
      if (this.text == null)
        throw new InvalidOperationException(BcgSR.BarCodeNotSet);

      if (this.Size.IsEmpty)
        throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
    }
Exemple #29
0
 /// <summary>
 /// The render stop.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void RenderStop(BarCodeRenderInfo info)
 {
     this.RenderValue(info, this.CalculateParity());
     this.RenderValue(info, CODE128_STOPCODE);
 }
 /// <summary>
 /// Gets the width of a thick or a thin line (or gap). CalcLineWidth must have been called before.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="isThick">Determines whether a thick line's with shall be returned.</param>
 internal double GetBarWidth(BarCodeRenderInfo info, bool isThick)
 {
   if (isThick)
     return info.ThinBarWidth * this.wideNarrowRatio;
   else
     return info.ThinBarWidth;
 }
 /// <summary>
 /// Renders the next digit pair as bar code element.
 /// </summary>
 private void RenderNextPair(BarCodeRenderInfo info)
 {
   int digitForLines = int.Parse(this.text[info.CurrPosInString].ToString());
   int digitForGaps = int.Parse(this.text[info.CurrPosInString + 1].ToString());
   bool[] linesArray = Lines[digitForLines];
   bool[] gapsArray = Lines[digitForGaps];
   for (int idx = 0; idx < 5; ++idx)
   {
     RenderBar(info, linesArray[idx]);
     RenderGap(info, gapsArray[idx]);
   }
   info.CurrPosInString += 2;
 }
 /// <summary>
 /// Renders a thick or thin line for the bar code.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="isThick">Determines whether a thick or a thin line is about to be rendered.</param>
 internal void RenderBar(BarCodeRenderInfo info, bool isThick)
 {
   double barWidth = GetBarWidth(info, isThick);
   double height = Size.Height;
   if (TextLocation != TextLocation.None)
     height *= 4.0 / 5;
   XRect rect = new XRect(info.CurrPos.X, info.CurrPos.Y, barWidth, height);
   info.Gfx.DrawRectangle(info.Brush, rect);
   info.CurrPos.X += barWidth;
 }
    /// <summary>
    /// Renders a thick bar before or behind the code.
    /// </summary>
    internal void RenderTurboBit(BarCodeRenderInfo info, bool startBit)
    {
      if (startBit)
        info.CurrPos.X -= 0.5 + GetBarWidth(info, true);
      else
        info.CurrPos.X += 0.5; //GetBarWidth(info, true);

      RenderBar(info, true);

      if (startBit)
        info.CurrPos.X += 0.5; //GetBarWidth(info, true);
    }
Exemple #34
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);
 }
Exemple #35
0
 private void RenderStop(BarCodeRenderInfo info)
 {
     RenderChar(info, '*');
 }
 /// <summary>
 /// Calculates the thick and thin line widths,
 /// taking into account the required rendering size.
 /// </summary>
 internal override void CalcThinBarWidth(BarCodeRenderInfo info)
 {
   /*
    * The total width is the sum of the following parts:
    * Starting lines      = 3 * thick + 7 * thin
    *  +
    * Code Representation = (3 * thick + 7 * thin) * code.Length
    *  +
    * Stopping lines      =  3 * thick + 6 * thin
    * 
    * with r = relation ( = thick / thin), this results in
    * 
    * Total width = (13 + 6 * r + (3 * r + 7) * code.Length) * thin
    */
   double thinLineAmount = 13 + 6 * this.wideNarrowRatio + (3 * this.wideNarrowRatio + 7) * this.text.Length;
   info.ThinBarWidth = this.Size.Width / thinLineAmount;
 }
Exemple #37
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);
        }
Exemple #38
0
 /// <summary>
 /// Renders a single line of the character. Each character has three lines and three spaces
 /// </summary>
 /// <param name="info">
 /// </param>
 /// <param name="barWidth">
 /// Indicates the thickness of the line/bar to be rendered.
 /// </param>
 internal void RenderBar(BarCodeRenderInfo info, double barWidth)
 {
     this.RenderBar(info, barWidth, info.Brush);
 }
Exemple #39
0
 /// <summary>
 /// Renders a single line of the character. Each character has three lines and three spaces
 /// </summary>
 /// <param name="info">
 /// </param>
 /// <param name="barWidth">
 /// Indicates the thickness of the line/bar to be rendered. 
 /// </param>
 /// <param name="brush">
 /// Indicates the brush to use to render the line/bar. 
 /// </param>
 private void RenderBar(BarCodeRenderInfo info, double barWidth, XBrush brush)
 {
     double height = this.Size.Height;
     double yPos = info.CurrPos.Y;
     switch (this.TextLocation)
     {
         case TextLocation.Above:
             yPos = info.CurrPos.Y + (height / 5);
             height *= 4.0 / 5;
             break;
         case TextLocation.Below:
             height *= 4.0 / 5;
             break;
         case TextLocation.AboveEmbedded:
         case TextLocation.BelowEmbedded:
         case TextLocation.None:
             break;
     }
     XRect rect = new XRect(info.CurrPos.X, yPos, barWidth, height);
     info.Gfx.DrawRectangle(brush, rect);
     info.CurrPos.X += barWidth;
 }
 private void RenderChar(BarCodeRenderInfo info, char ch)
 {
   bool[] thickThinLines = ThickThinLines(ch);
   int idx = 0;
   while (idx < 9)
   {
     RenderBar(info, thickThinLines[idx]);
     if (idx < 8)
       RenderGap(info, thickThinLines[idx + 1]);
     idx += 2;
   }
 }
 /// <summary>
 /// Renders a thick or thin gap for the bar code.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="isThick">Determines whether a thick or a thin gap is about to be rendered.</param>
 internal void RenderGap(BarCodeRenderInfo info, bool isThick)
 {
   info.CurrPos.X += GetBarWidth(info, isThick);
 }
 private void RenderStart(BarCodeRenderInfo info)
 {
   RenderChar(info, '*');
   RenderGap(info, false);
 }
 internal 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);
   //center.Y += info.Font.Size;
   info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
 }
Exemple #44
0
 private void RenderNextChar(BarCodeRenderInfo info)
 {
     RenderChar(info, Text[info.CurrPosInString]);
     ++info.CurrPosInString;
 }
 internal abstract void CalcThinBarWidth(BarCodeRenderInfo info);
 private void RenderStop(BarCodeRenderInfo info)
 {
   RenderBar(info, true);
   RenderGap(info, false);
   RenderBar(info, false);
 }
 internal abstract void CalcThinBarWidth(BarCodeRenderInfo info);
Exemple #48
0
 /// <summary>
 /// The render text.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void RenderText(BarCodeRenderInfo info)
 {
     if (info.Font == null)
         info.Font = new XFont("Courier New", this.Size.Height / 6);
     XPoint center = info.Position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);
     if (this.TextLocation == TextLocation.Above)
         info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, this.Size), XStringFormats.TopCenter);
     else if (this.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, this.Size), XStringFormats.TopCenter);
     }
     else if (this.TextLocation == TextLocation.Below)
         info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, this.Size), XStringFormats.BottomCenter);
     else if (this.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 += this.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, this.Size), XStringFormats.BottomCenter);
     }
 }
Exemple #49
0
 /// <summary>
 /// The render start.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void RenderStart(BarCodeRenderInfo info) { this.RenderValue(info, (int)this.Code128Code); }
Exemple #50
0
 /// <summary>
 /// The render start.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void RenderStart(BarCodeRenderInfo info)
 {
     this.RenderValue(info, (int)this.Code128Code);
 }
 private void RenderStop(BarCodeRenderInfo info)
 {
   RenderChar(info, '*');
 }
Exemple #52
0
 /// <summary>
 /// The render stop.
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void RenderStop(BarCodeRenderInfo info)
 {
     this.RenderValue(info, this.CalculateParity());
     this.RenderValue(info, CODE128_STOPCODE);
 }
    /// <summary>
    /// Renders the bar code.
    /// </summary>
    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 = info.Center - this.size / 2;
      info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);

      if (TurboBit)
        RenderTurboBit(info, true);
      RenderStart(info);
      while (info.CurrPosInString < this.text.Length)
      {
        RenderNextChar(info);
        RenderGap(info, false);
      }
      RenderStop(info);
      if (TurboBit)
        RenderTurboBit(info, false);
      if (TextLocation != TextLocation.None)
        RenderText(info);

      gfx.Restore(state);
    }
        /// <summary>
        /// Renders a thick or thin line for the bar code.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="isThick">Determines whether a thick or a thin line is about to be rendered.</param>
        internal void RenderBar(BarCodeRenderInfo info, bool isThick)
        {
            double barWidth = GetBarWidth(info, isThick);
            double height = Size.Height;
            double xPos = info.CurrPos.X;
            double yPos = info.CurrPos.Y;

            switch (TextLocation)
            {
                case TextLocation.AboveEmbedded:
                    height -= info.Gfx.MeasureString(Text, info.Font).Height;
                    yPos += info.Gfx.MeasureString(Text, info.Font).Height;
                    break;
                case TextLocation.BelowEmbedded:
                    height -= info.Gfx.MeasureString(Text, info.Font).Height;
                    break;
            }

            XRect rect = new XRect(xPos, yPos, barWidth, height);
            info.Gfx.DrawRectangle(info.Brush, rect);
            info.CurrPos.X += barWidth;
        }
 private void RenderNextChar(BarCodeRenderInfo info)
 {
   RenderChar(info, this.text[info.CurrPosInString]);
   ++info.CurrPosInString;
 }
        internal void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
                info.Font = new XFont("Courier New", Size.Height / 6);
            XPoint center = info.Position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            switch (TextLocation)
            {
                case TextLocation.Above:
                    center = new XPoint(center.X, center.Y - info.Gfx.MeasureString(Text, info.Font).Height);
                    info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
                    break;
                case TextLocation.AboveEmbedded:
                    info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
                    break;
                case TextLocation.Below:
                    center = new XPoint(center.X, info.Gfx.MeasureString(Text, info.Font).Height + center.Y);
                    info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
                    break;
                case TextLocation.BelowEmbedded:
                    info.Gfx.DrawString(Text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
                    break;
            }
        }