Exemplo n.º 1
0
        internal override void InitRendering(BarCodeRenderInfo info)
        {
            base.InitRendering(info);
            CalcThinBarWidth(info);
            info.BarHeight = Size.Height;
            // HACK in ThickThinBarCode
            if (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 - size / 2, size));
#endif
            switch (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;
            }
        }
Exemplo n.º 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 = Center - Size / 2;
            info.CurrPos = position - CalcDistance(AnchorType.TopLeft, Anchor, Size);

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

            gfx.Restore(state);
        }
Exemplo n.º 3
0
        internal void RenderText(BarCodeRenderInfo info)
        {
            if (info.Font == null)
            {
                info.Font = new XFont(GlobalFontSettings.FontResolver.DefaultFontName, 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;
            }
        }
Exemplo n.º 4
0
 /// <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);
 }
Exemplo n.º 5
0
        internal virtual void InitRendering(BarCodeRenderInfo info)
        {
            if (Text == null)
            {
                throw new InvalidOperationException(BcgSR.BarCodeNotSet);
            }

            if (Size.IsEmpty)
            {
                throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
            }
        }
Exemplo n.º 6
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;
            }
        }
Exemplo n.º 7
0
        /// <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);
            }
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 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;
            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;
        }
Exemplo n.º 10
0
 internal abstract void CalcThinBarWidth(BarCodeRenderInfo info);
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 12
0
 private void RenderStop(BarCodeRenderInfo info)
 {
     RenderChar(info, '*');
 }
Exemplo n.º 13
0
 private void RenderStart(BarCodeRenderInfo info)
 {
     RenderChar(info, '*');
     RenderGap(info, false);
 }
Exemplo n.º 14
0
 private void RenderNextChar(BarCodeRenderInfo info)
 {
     RenderChar(info, Text[info.CurrPosInString]);
     ++info.CurrPosInString;
 }