Example #1
0
        public Tools.Rectangle GetLabelRectangle(int HorizontalIndex, int VerticalIndex)
        {
            if (labelLayout == null)
            {
                throw new ApplicationException("Please, parse a paper definition first");
            }

            Tools.Length Left = GetLeftMargin() + ((GetLabelSize().Width + GetHorizontalInterlabelGap()) * HorizontalIndex);
            Tools.Length Top  = GetTopMargin() + ((GetLabelSize().Height + GetVerticalInterlabelGap()) * VerticalIndex);

            Tools.Rectangle rect = new Tools.Rectangle(Left, Top, GetLabelSize());
            return(rect);
        }
Example #2
0
        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            Length LeftMargin;
            Length TopMargin;

            //The labelnumber of the first label to be printed on this page!
            //This is NOT necessary the index of the labelnumer in the list as
            //each label can have a quantity to be printed of more than one.

            //Euhhh NextPage contains the number of the page to be drawn next.
            //But because we a now drawing it... it's the page to be drawn now.
            //Upon leave we increase this number. We work zero based, to the first page
            //actually has numbe 0
            uint FirstLabel = NextPage * LabelsPerPage;

            //LastLabel = the labelnumber of the max last label on THIS page,
            //(thus not the end of the document)
            uint LastLabel = ((NextPage + 1) * LabelsPerPage) - 1;

            //A limit can be given bij pages (print page 5 to 7) or
            //by reaching the last label.
            //So the number labels max to go is:
            uint LastLabelOfJob;

            if (ToPage == uint.MaxValue)
            {
                LastLabelOfJob = uint.MaxValue;
            }
            else
            {
                LastLabelOfJob = (ToPage + 1) * LabelsPerPage - 1;
            }
            //uint LastLabelOfJob = ((ToPage+1) * LabelsPerPage) - 1;
            uint AllLabelsCount;

            AllLabelsCount = Labels.CountAll - 1; //make this max also zero based

            //If we requested pages 0 to n but we need less than n pages to
            //print all labels, we limit to the last label.
            if (LastLabelOfJob > AllLabelsCount)
            {
                LastLabelOfJob = AllLabelsCount;
            }

            //If we have less labels than would fit the page, will still need to
            //stop at the last label...
            if (LastLabel > AllLabelsCount)
            {
                LastLabel = AllLabelsCount;
            }

            //Adjust for physical margings of the printer in respect to
            //paperdefinitions.
            //test
            //PrinterBounds theBounds;
            //theBounds = new PrinterBounds(ev);
            if (!theBoundsCached)
            {
                theBounds       = new PrinterBounds(ev);
                theBoundsCached = true;
            }
            //*
            LeftMargin = theBounds.HardMarginLeft;
            TopMargin  = theBounds.HardMarginTop;

            PaperDef.PhysicalLeftMargin = LeftMargin;
            PaperDef.PhysicalTopMargin  = TopMargin;

            ev.Graphics.PageUnit = GraphicsUnit.Pixel;
            float dpiX = ev.Graphics.DpiX;
            float dpiY = ev.Graphics.DpiY;

            uint LabelIndex      = 0;
            uint HorizontalIndex = 0;
            uint VerticalIndex   = 0;
            uint QuantityCount   = 0;

            foreach (Label.Label CurrentLabel in Labels)
            {
                if (LabelIndex + CurrentLabel.Quantity < FirstLabel)
                {
                    LabelIndex += CurrentLabel.Quantity;
                    continue;
                }

                // Stop if we don't need any more labels
                if (LabelIndex > LastLabel)
                {
                    break;
                }

                for (QuantityCount = 0; QuantityCount < CurrentLabel.Quantity; QuantityCount++)
                {
                    // skip labels that don't need printing..
                    if (LabelIndex < FirstLabel)
                    {
                        LabelIndex++;
                        continue;
                    }

                    // Stop if we don't need any more labels
                    if (LabelIndex > LastLabel)
                    {
                        break;
                    }

                    Tools.Rectangle          rect     = PaperDef.GetLabelRectangle((int)HorizontalIndex, (int)VerticalIndex);
                    System.Drawing.Rectangle convRect = new System.Drawing.Rectangle((int)rect.Left.InPixels(dpiX), (int)rect.Top.InPixels(dpiY), (int)rect.Size.Width.InPixels(dpiX), (int)rect.Size.Height.InPixels(dpiY));

                    ACA.LabelX.Label.LabelSet labelset = new ACA.LabelX.Label.LabelSet();

                    labelset.CurrentLabel    = CurrentLabel;
                    labelset.DefaultLabel    = DefaultLabel;
                    labelset.BaseLabel       = LabelDef.DefaultLabel;
                    labelset.StaticVarsLabel = StaticVarslabel;


                    executeLua(labelset.CurrentLabel, labelset.DefaultLabel, labelset.BaseLabel, labelset.StaticVarsLabel);

                    CurrentLabel.Draw(ev.Graphics, convRect, LabelDef, labelset, Language, DrawBorders);
                    counter++;
                    if (counter > 200)
                    {
                        GC.Collect();
                        counter = 0;
                    }
                    HorizontalIndex++;

                    if (HorizontalIndex >= PaperDef.labelLayout.HorizontalCount)
                    {
                        HorizontalIndex = 0;
                        VerticalIndex++;
                    }

                    if (VerticalIndex >= PaperDef.labelLayout.VerticalCount)
                    {
                        VerticalIndex = 0;
                    }

                    LabelIndex++;
                }
            }

            if (LabelIndex <= LastLabelOfJob)
            {
                NextPage++;
                ev.HasMorePages = true;
            }
            else
            {
                NextPage        = 0;
                ev.HasMorePages = false;
            }
        }