示例#1
0
        //Create a single QRLabel
        public Bitmap createQRLabel(Bitmap qrBitmap, QRLabel qrInfo)
        {
            Graphics graphics = Graphics.FromImage(qrBitmap);

            //Draw QR code image
            graphics.DrawImageUnscaled((System.Drawing.Image)qrInfo.qrImg.bmp, qrInfo.qrImg.loc.X, qrInfo.qrImg.loc.Y);

            //Draw logo image
            graphics.DrawImage((System.Drawing.Image)qrInfo.logoImg.bmp, qrInfo.logoImg.loc.X, qrInfo.logoImg.loc.Y, qrInfo.logoImg.width, qrInfo.logoImg.height);

            //Draw inner labels in loop
            for (int i = 0; i < qrInfo.innerLabels.Length; i++)
            {
                Font       font  = qrInfo.innerLabels[i].font; //new Font("Times New Roman",  fontSize, FontStyle.Regular);
                SolidBrush brush = new SolidBrush(Color.Black);
                String     text  = qrInfo.innerLabels[i].txt;

                //Set size and location of string
                SizeF reqdSize = graphics.MeasureString(text, font, qrInfo.innerLabels[i].width);
                reqdSize.Height = (float)Math.Round(reqdSize.Height);

                //Calculate the rectangle holding the string
                RectangleF strRect = new RectangleF(
                    qrInfo.innerLabels[i].loc.X,
                    qrInfo.innerLabels[i].loc.Y,
                    reqdSize.Width + 2,
                    reqdSize.Height);
                StringFormat format = new StringFormat(StringFormatFlags.NoClip);
                format.Alignment = StringAlignment.Center;

                //graphics.TranslateTransform(-20, -20);
                graphics.RotateTransform(qrInfo.innerLabels[i].rotation);

                //Draw rectangle with withe background that holds string
                graphics.FillRectangle(new SolidBrush(Color.White), strRect);

                //Draw String
                graphics.DrawString(text, font, brush, strRect, format);

                graphics.RotateTransform(qrInfo.innerLabels[i].rotation * (-1));
                //graphics.TranslateTransform(20, 20);
            }

            return(qrBitmap);
        }
示例#2
0
        public void run()
        {
            int total                    = 5;
            int txtPerQRLabel            = 3;
            int labelPerPage             = 4;
            int qrLocIndex               = 0;
            int inner_label_left         = 170;
            int inner_label_height       = 20;
            int inner_label_width        = 100;
            int inner_label_vertical_top = 30;

            //----------------------Preparing testing data
            QRPage.PageNumberLoc  = new Point(300, 950);
            QRPage.PageNumberFont = new Font("Times New Roman", 14, FontStyle.Bold);

            //Create an array of QR Label information
            QRLabel[] infos = new QRLabel[total];
            for (int i = 0; i < total; i++)
            {
                infos[i] = new QRLabel();

                //Append mockup QR Image
                infos[i].qrImg = new QRImage(new Point(10, 10),
                                             (Bitmap)System.Drawing.Image.FromFile(Environment.CurrentDirectory + @"\..\..\imgs\26.gif"));

                //Append logo image
                infos[i].logoImg = new QRImage(new Point(160, 120), 100, 46,
                                               (Bitmap)System.Drawing.Image.FromFile(Environment.CurrentDirectory + QRPageCreator.JNJLogo_GIF));

                //Create Labels
                QRInnerLabel[] labels = new QRInnerLabel[txtPerQRLabel];

                labels[0] = new QRInnerLabel(
                    "LOC: XXX",
                    Color.Black, new Font("Times New Roman", 10, FontStyle.Bold),
                    new Point(inner_label_left, 0 * inner_label_height + inner_label_vertical_top), inner_label_width, inner_label_height);
                labels[1] = new QRInnerLabel(
                    System.DateTime.Now.ToLocalTime().ToShortTimeString(),
                    Color.Black, new Font("Times New Roman", 8, FontStyle.Regular),
                    new Point(inner_label_left, 1 * inner_label_height + inner_label_vertical_top), inner_label_width, inner_label_height);
                labels[2] = new QRInnerLabel(
                    "QR CODE: XXX",
                    Color.Black, new Font("Times New Roman", 8, FontStyle.Regular),
                    new Point(inner_label_left, 2 * inner_label_height + inner_label_vertical_top), inner_label_width, inner_label_height);

                infos[i].innerLabels = labels;

                //Define top left of QR Label
                infos[i].loc = new Point(10, qrLocIndex * (192 + 20) + 50);
                if (qrLocIndex >= labelPerPage - 1)
                {
                    qrLocIndex = qrLocIndex - labelPerPage;
                }
                qrLocIndex++;
            }

            //Create a mock up page layout template
            QRPageLayoutTemplate pageLayoutTempl = new QRPageLayoutTemplate();

            pageLayoutTempl.capacity = labelPerPage;

            //----------------------Test Function
            QRPageCreator qrPageGen = new QRPageCreator();

            qrPageGen.qrLabels = infos;
            List <QRPage> pages = qrPageGen.generateLabelPages();

            outputPages(pages);
        }
示例#3
0
        //Construct QRLabels by combine print data and template
        public QRLabel[] parseData()
        {
            qrLabels = new QRLabel[qrPrintData.Length];
            QRLabel             qrLabel  = null;
            List <QRInnerLabel> qInnerLs = null;
            String       curValue        = "";
            MemoryStream memStream       = null;
            int          tempIndex       = 0;

            //Collection information label by label
            for (int i = 0; i < qrPrintData.Length; i++)
            {
                qrLabel   = new QRLabel();
                tempIndex = tempIndex >= template.Labels.Count ? tempIndex - template.Labels.Count : tempIndex;
                //Collection template information for each QRLabel
                Label labelTempl = template.Labels[tempIndex];

                qInnerLs = new List <QRInnerLabel>();
                foreach (Item item in labelTempl.Items)
                {
                    if (typeof(DynamicText).IsInstanceOfType(item))
                    {
                        if (qrPrintData[i].labels.TryGetValue(((DynamicText)item)._InputKey, out curValue))
                        {
                            qInnerLs.Add(new QRInnerLabel(curValue, new Point(item.X, item.Y), item.Width, item.Height, (float)item.Rotation));
                        }
                    }
                    else if (typeof(StaticText).IsInstanceOfType(item))
                    {
                        if (qrPrintData[i].labels.TryGetValue(((StaticText)item)._Text, out curValue))
                        {
                            qInnerLs.Add(new QRInnerLabel(curValue, new Point(item.X, item.Y), item.Width, item.Height, (float)item.Rotation));
                        }
                    }
                    else if (typeof(XMLLayoutClassTest.Image).IsInstanceOfType(item))
                    {
                        memStream = null;
                        if (qrPrintData[i].imgs.TryGetValue(((XMLLayoutClassTest.Image)item)._InputKey, out memStream))
                        {
                            qrLabel.logoImg = new QRImage(new Point(item.X, item.Y), item.Width, item.Height, (Bitmap)System.Drawing.Image.FromStream(memStream));
                        }
                    }
                    else if (typeof(XMLLayoutClassTest.QRCode).IsInstanceOfType(item))
                    {
                        memStream = null;
                        if (qrPrintData[i].imgs.TryGetValue(((XMLLayoutClassTest.QRCode)item)._InputKey, out memStream))
                        {
                            qrLabel.qrImg = new QRImage(new Point(item.X, item.Y), item.Width, item.Height, (Bitmap)System.Drawing.Image.FromStream(memStream));
                        }
                    }
                    else
                    {
                        //Unknown type
                    }
                }
                qrLabel.innerLabels = qInnerLs.ToArray();
                qrLabel.loc         = new Point(labelTempl.X, labelTempl.Y);
                qrLabels[i]         = qrLabel;
                tempIndex++;
            }
            return(qrLabels);
        }