示例#1
0
            //绘制标准条形码。
            public void DrawBarCode_old(Graphics g, RptBarCode codeInfo)
            {
                float wid = codeInfo.WID;

                Barcode.IBarcode barCode = null;
                if (codeInfo.CodeType == BarCodeType.Code128)
                {
                    barCode = new DIYReport.Barcode.Code128(codeInfo.BarCode);
                }
                else
                {
                    barCode = new DIYReport.Barcode.Code39(codeInfo.BarCode);
                }
                string encodedString = barCode.Encoded_Value;

                if (encodedString == null || encodedString.Length == 0)
                {
                    g.DrawString("INVALID BAR CODE TEXT", codeInfo.HeaderFont, Brushes.Red, 10, 10);
                    return;
                }
                int    encodedStringLength  = encodedString.Length;
                int    widthOfBarCodeString = 0;
                double wideToNarrowRatio    = 1.67;


                if (codeInfo.VertAlign != AlignType.Left)
                {
                    for (int i = 0; i < encodedStringLength; i++)
                    {
                        if (encodedString[i] == '1')
                        {
                            widthOfBarCodeString += (int)(wideToNarrowRatio * (int)codeInfo.Weight);
                        }
                        else
                        {
                            widthOfBarCodeString += (int)codeInfo.Weight;
                        }
                    }
                    //widthOfBarCodeString = System.Convert.ToInt32(encodedStringLength * 2) ;
                }

                float x = 0f;
                //int wid=0;
                int   yTop  = 0;
                SizeF hSize = g.MeasureString(codeInfo.HeaderText, codeInfo.HeaderFont);
                SizeF fSize = g.MeasureString(codeInfo.BarCode, codeInfo.FooterFont);

                float headerX = 0f;
                float footerX = 0f;

                if (codeInfo.VertAlign == AlignType.Left)
                {
                    x       = codeInfo.LeftMargin;
                    headerX = codeInfo.LeftMargin;
                    footerX = codeInfo.LeftMargin;
                }
                else if (codeInfo.VertAlign == AlignType.Center)
                {
                    x       = (codeInfo.InnerRect.Width - widthOfBarCodeString * wid) / 2;
                    headerX = (codeInfo.InnerRect.Width - hSize.Width) / 2;
                    footerX = (codeInfo.InnerRect.Width - fSize.Width) / 2;
                }
                else
                {
                    x       = codeInfo.InnerRect.Width - widthOfBarCodeString * wid - codeInfo.LeftMargin;
                    headerX = codeInfo.InnerRect.Width - hSize.Width - codeInfo.LeftMargin;
                    footerX = codeInfo.InnerRect.Width - fSize.Width - codeInfo.LeftMargin;
                }

                if (codeInfo.ShowHeader)
                {
                    yTop = (int)hSize.Height + codeInfo.TopMargin;
                    g.DrawString(codeInfo.HeaderText, codeInfo.HeaderFont, Brushes.Black, headerX, codeInfo.TopMargin);
                }
                else
                {
                    yTop = codeInfo.TopMargin;
                }

                for (int i = 0; i < encodedStringLength; i++)
                {
                    Color c = encodedString[i] == '1'? Color.Black : Color.White;

                    g.DrawLine(new Pen(c, (float)wid), new PointF(x + wid, 0), new PointF(x + wid, codeInfo.BarCodeHeight));

                    x += wid;
                }

                yTop += codeInfo.BarCodeHeight;

                if (codeInfo.ShowFooter)
                {
                    g.DrawString(codeInfo.BarCode, codeInfo.FooterFont, Brushes.Black, footerX, yTop);
                }
            }
示例#2
0
        //绘制标准 条形码。
        public void DrawBarCode(DevExpress.XtraPrinting.BrickGraphics g, RptBarCode codeInfo, string barCode, Rectangle realDrawRect)
        {
            if (barCode == null || barCode.Length == 0)
            {
                return;
            }
            DevExpress.XtraPrinting.BorderSide borSide = DevExpress.XtraPrinting.BorderSide.None;
            Barcode.IBarcode barCodeObj = null;
            if (codeInfo.CodeType == BarCodeType.Code128)
            {
                barCodeObj = new DIYReport.Barcode.Code128(barCode);
            }
            else
            {
                barCodeObj = new DIYReport.Barcode.Code39(barCode);
            }


            string encodedString = barCodeObj.Encoded_Value;

            if (encodedString == null || encodedString.Length == 0)
            {
                g.DrawString("INVALID BAR CODE TEXT", Color.Red, new RectangleF(realDrawRect.X, realDrawRect.Y, realDrawRect.Width, realDrawRect.Height), borSide);
            }


            int   encodedStringLength  = encodedString.Length;
            float widthOfBarCodeString = 0f;
            //float wideToNarrowRatio = 1.67f;
            //float wid = codeInfo.WID * wideToNarrowRatio;
            float pound = codeInfo.LinePound;

            if (codeInfo.VertAlign != AlignType.Left)
            {
                for (int i = 0; i < encodedStringLength; i++)
                {
                    //if ( encodedString[i]=='1' )
                    widthOfBarCodeString += pound;
                }
            }

            float xLeft = 0f;
            int   yTop  = 0;

            g.Font = codeInfo.HeaderFont;
            SizeF hSize = g.MeasureString(codeInfo.HeaderText);

            g.Font = codeInfo.FooterFont;
            SizeF fSize = g.MeasureString(barCode);

            int headerX = 0;
            int footerX = 0;

            if (codeInfo.VertAlign == AlignType.Left)
            {
                xLeft   = realDrawRect.X + codeInfo.LeftMargin;
                headerX = realDrawRect.X + codeInfo.LeftMargin;
                footerX = realDrawRect.X + codeInfo.LeftMargin;
            }
            else if (codeInfo.VertAlign == AlignType.Center)
            {
                // xLeft = realDrawRect.X + (realDrawRect.Width - widthOfBarCodeString * pound) / 2;
                xLeft   = realDrawRect.X + (realDrawRect.Width - widthOfBarCodeString) / 2;
                headerX = realDrawRect.X + (realDrawRect.Width - (int)hSize.Width) / 2;
                footerX = realDrawRect.X + (realDrawRect.Width - (int)fSize.Width) / 2;
            }
            else
            {
                xLeft   = realDrawRect.X + realDrawRect.Width - widthOfBarCodeString * pound - codeInfo.LeftMargin;
                headerX = realDrawRect.X + realDrawRect.Width - (int)hSize.Width - codeInfo.LeftMargin;
                footerX = realDrawRect.X + realDrawRect.Width - (int)fSize.Width - codeInfo.LeftMargin;
            }

            if (codeInfo.ShowHeader)
            {
                yTop   = (int)hSize.Height + codeInfo.TopMargin;
                g.Font = codeInfo.HeaderFont;
                g.DrawString(codeInfo.HeaderText, Color.Black, new RectangleF(headerX, realDrawRect.Y + codeInfo.TopMargin, realDrawRect.Width, hSize.Height - 4), borSide);
            }
            else
            {
                yTop = codeInfo.TopMargin;
            }
            float px = xLeft;    // +realDrawRect.X;

            for (int i = 0; i < encodedStringLength; i++)
            {
                Color c = encodedString[i] == '1' ? Color.Black : Color.White;

                px += pound;
                var brick = g.DrawLine(new PointF(px, yTop + realDrawRect.Y),
                                       new PointF(px, yTop + realDrawRect.Y + codeInfo.BarCodeHeight), c, pound);

                brick.Sides = DevExpress.XtraPrinting.BorderSide.None;
                //x++;
            }

            yTop += codeInfo.BarCodeHeight;

            if (codeInfo.ShowFooter)
            {
                //g.BackColor = codeInfo.BackgroundColor ;
                g.Font = codeInfo.FooterFont;
                //g.DrawString(codeInfo.BarCode, codeInfo.FooterFont, Brushes.Black, footerX, yTop);
                var rec = g.DrawString(barCode, codeInfo.ForeColor, new RectangleF(footerX, realDrawRect.Y + yTop, realDrawRect.Width, hSize.Height - 4), borSide);
                //rec.HorzAlignment = DevExpress.Utils.HorzAlignment.Center;
            }
        }