예제 #1
0
파일: Form1.cs 프로젝트: tomvd/ZPLViewer
        private void parseAndPaint(string p_strIn)
        {
            string strCom;
            string strParams;
            char[] delimiterChars = {','};
            int x=0, y=0;
            int type=0,next;
            int w=100, h=100, t=1;
            Graphics g = pictureBox1.CreateGraphics();

            p_strIn = p_strIn.Remove(0, 1);
            strCom = p_strIn.Substring(0, p_strIn.IndexOf("^"));
            while (strCom.Length > 0)
            {

                if (strCom.Substring(0,2).Equals("FT"))
                {
                    strParams = strCom.Remove(0, 2);
                    string[] coords = strParams.Split(delimiterChars);
                    x = int.Parse(coords[0])/2;
                    y = int.Parse(coords[1])/2;
                    type = 0;
                }else
                if (strCom.Substring(0, 2).Equals("FO"))
                {
                    strParams = strCom.Remove(0, 2);
                    string[] coords = strParams.Split(delimiterChars);
                    x = int.Parse(coords[0]) / 2;
                    y = int.Parse(coords[1]) / 2;
                    type = 1;
                }
                else
                if (strCom.Substring(0,2).Equals("FT"))
                {
                    strParams = strCom.Remove(0, 2);
                    string[] coords = strParams.Split(delimiterChars);
                    x = int.Parse(coords[0])/2;
                    y = int.Parse(coords[1])/2;
                    type = 0;
                }else
                if (strCom.Substring(0,2).Equals("GB"))
                {
                    strParams = strCom.Remove(0, 2);
                    string[] coords = strParams.Split(delimiterChars);
                    w = int.Parse(coords[0]) / 2;
                    h = int.Parse(coords[1]) / 2;
                    t = int.Parse(coords[2]) / 2;
                    if (type == 0)
                        y -= h;

                    g.DrawRectangle(new Pen(Color.Black,(float)t),x,y,w,h);
                }
                else
                if (strCom.Substring(0, 2).Equals("B3"))
                {
                    strParams = strCom.Remove(0, 2);
                    string[] coords = strParams.Split(delimiterChars);
                    h = int.Parse(coords[2]) / 2;
                    if (type == 0)
                        y -= h;
                    type = 2;
                }
                else
                if (strCom.Substring(0, 1).Equals("A"))
                {
                    strParams = strCom.Remove(0, 1);
                    string[] coords = strParams.Split(delimiterChars);
                    h = int.Parse(coords[1]) / 2;
                    w = int.Parse(coords[2]) / 2;
                    type = 3;
                }
                else
                    if (strCom.Substring(0, 2).Equals("BY"))
                    {
                        strParams = strCom.Remove(0, 2);
                        string[] coords = strParams.Split(delimiterChars);
                        w = int.Parse(coords[0]) /2;
                    }
                else
                    if (strCom.Substring(0, 2).Equals("FD"))
                    {
                        strParams = strCom.Remove(0, 2);
                        if (type == 2)
                        {
                            Code39Settings cs = new Code39Settings();
                            cs.BarCodeHeight = h;
                            cs.NarrowWidth = w;
                            cs.WideWidth = 4;
                            cs.LeftMargin = x;
                            cs.TopMargin = y;
                            Code39 code = new Code39(strParams, cs);
                            code.Paint(g);
                        }
                        if (type == 3)
                        {
                            Font font = new Font(FontFamily.GenericSansSerif,12);
                            g.DrawString(strParams, font, Brushes.Black, x, y);
                        }
                    }

                p_strIn = p_strIn.Remove(0, strCom.Length + 1);
                next = p_strIn.IndexOf("^");
                if (next > 0)
                    strCom = p_strIn.Substring(0, next);
                else
                    break;
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: tomvd/ZPLViewer
            public int GetWidth(Code39Settings settings)
            {
                int width = 0;

                for (int i = 0; i < 9; i++)
                    width += (nw[i] ? settings.WideWidth : settings.NarrowWidth);

                return width;
            }
예제 #3
0
파일: Form1.cs 프로젝트: tomvd/ZPLViewer
            public int Paint(Code39Settings settings, Graphics g, int left)
            {
                int x = left;

                int w = 0;
                for (int i = 0; i < 9; i++)
                {
                    int width = (nw[i] ? settings.WideWidth : settings.NarrowWidth);

                    if (i % 2 == 0)
                    {
                        Rectangle r = new Rectangle(x, settings.TopMargin, width, settings.BarCodeHeight);
                        g.FillRectangle(brush, r);
                    }

                    x += width;
                    w += width;
                }

                return w;
            }
예제 #4
0
파일: Form1.cs 프로젝트: tomvd/ZPLViewer
        public Code39(string code, Code39Settings settings)
        {
            foreach (char c in code)
                if (!codes.ContainsKey(c))
                    throw new ArgumentException("Invalid character encountered in specified code.");

            if (!code.StartsWith("*"))
                code = "*" + code;
            if (!code.EndsWith("*"))
                code = code + "*";

            this.code = code;
            this.settings = settings;
        }