Beispiel #1
0
 public virtual Waypoint PeekNextWaypoint()
 {
     if (_waypoints == null || _waypoints.Count == 0)
     {
         return(null);
     }
     return(_waypoints.Peek());
 }
Beispiel #2
0
        public void Arrange(Document document)
        {
            var pageSize = document.Variables["page"]["size"].GetValue <Size>();
            var margin   = document.Variables["page"]["margin"].GetValue <Thickness>();
            var boxSize  = pageSize;

            boxSize.Height -= margin.Height;
            boxSize.Width  -= margin.Width;

            var startOffset = new Position(margin.Left, margin.Top);
            var contentArea = new Rectangle(startOffset, boxSize);

            var    curPage   = AddPage(document, pageSize, contentArea);
            double curHeight = boxSize.Height;

            var flexQueue   = new FlexQueue <Measurement>(); //new Queue<Measurement>();
            var enqueueNext = false;

            // Stage one:
            // Add measurements to pages
            foreach (var measurement in document.Measurements)
            {
                if (enqueueNext)
                {
                    flexQueue.Enqueue(measurement, measurement.Flexible);
                    enqueueNext = measurement.PagebreakPenalty > 0;
                }
                else if (measurement.PagebreakPenalty > 0)
                {
                    flexQueue.Enqueue(measurement.Flexible);
                    flexQueue.Enqueue(measurement, measurement.Flexible);
                    enqueueNext = true;
                }
                else
                {
                    while (flexQueue.Count > 0)
                    {
                        var peeked = flexQueue.Peek();
                        if (FitAll(peeked, curHeight))
                        {
                            foreach (var ms in peeked)
                            {
                                TryFitMeasurement(curPage, ms, flexQueue, true, ref curHeight);
                            }
                            flexQueue.Dequeue();
                        }
                        else if (!flexQueue.IsFlex)
                        {
                            curHeight      = boxSize.Height;
                            curPage.Filled = true;
                            curPage        = AddPage(document, pageSize, contentArea);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (TryFitMeasurement(curPage, measurement, flexQueue, false, ref curHeight) == FitResult.AddPage)
                    {
                        curHeight      = boxSize.Height;
                        curPage.Filled = true;
                        curPage        = AddPage(document, pageSize, contentArea);
                    }
                }
            }

            // Add leftover flexible items
            while (flexQueue.Count > 0)
            {
                var ms = flexQueue.Dequeue();
                foreach (var m in ms)
                {
                    m.Flexible = false;

                    if (TryFitMeasurement(curPage, m, flexQueue, false, ref curHeight) == FitResult.AddPage)
                    {
                        curHeight      = boxSize.Height;
                        curPage.Filled = true;
                        curPage        = AddPage(document, pageSize, contentArea);
                    }
                }
            }

            // Stage two:
            // Layout measurements on each page
            foreach (var page in document.Pages)
            {
                var currentOffset = startOffset;

                foreach (var measurement in page.Measurements)
                {
                    var size = measurement.Size;

                    currentOffset.Y += measurement.Margin.Top;

                    var visualOffset = currentOffset;
                    visualOffset.X += measurement.Margin.Left;

                    measurement.Position = visualOffset;
                    Realign(measurement, boxSize, pageSize, measurement.Element.HorizontalAlignment);
                    measurement.Element.Arrange(measurement);

                    currentOffset.Y += size.Height;
                    currentOffset.Y += measurement.Margin.Bottom;
                }

                // Set number at the end of the page layouting
                // so that any number changing elements can take effect
                page.Number = document.PageNumbering.Next();
                page.AddPageItems();
            }
        }
Beispiel #3
0
        public void PeekAtNextItemInFlexQueue()
        {
            // Arrange
            var queue = new FlexQueue<Tuple<string,int>>();
            queue.Enqueue(new Tuple<string, int>("Entry1", 11111));
            queue.Enqueue(new Tuple<string, int>("Entry2", 22222));
            queue.Enqueue(new Tuple<string, int>("Entry3", 33333));
            queue.Enqueue(new Tuple<string, int>("Entry4", 44444));
            queue.Enqueue(new Tuple<string, int>("Entry5", 55555));

            // Assert
            Assert.AreEqual(5, queue.Count);
            var nextItem = queue.Peek();
            Assert.AreEqual(5, queue.Count);
            Assert.AreEqual("Entry1", nextItem.Item1);
            Assert.AreEqual(11111, nextItem.Item2);
        }