Beispiel #1
0
        private PageRowBound[] CalculatePageRowBounds(Size[] singlePageBounds, ViewType viewType)
        {
            var pagesPerRow = Math.Min(GetPagesPerRow(), singlePageBounds.Length); // if multiple page-view, but pdf contains less pages than the pages per row
            var finalBounds = new List<PageRowBound>();
            var verticalBorderOffset = (this.PageMargin.Top + this.PageMargin.Bottom);

            if (viewType == MoonPdfLib.ViewType.SinglePage)
            {
                finalBounds.AddRange(singlePageBounds.Select(p => new PageRowBound( p, verticalBorderOffset, 0)));
            }
            else
            {
                var horizontalBorderOffset = this.HorizontalMargin;

                for (int i = 0; i < singlePageBounds.Length; i++)
                {
                    if (i == 0 && viewType == MoonPdfLib.ViewType.BookView)
                    {
                        finalBounds.Add(new PageRowBound(singlePageBounds[0], verticalBorderOffset, 0));
                        continue;
                    }

                    var subset = singlePageBounds.Take(i, pagesPerRow).ToArray();

                    // we get the max page-height from all pages in the subset and the sum of all page widths of the subset plus the offset between the pages
                    finalBounds.Add(new PageRowBound(new Size(subset.Sum(f => f.Width), subset.Max(f => f.Height)), verticalBorderOffset, horizontalBorderOffset * (subset.Length - 1)));
                    i += (pagesPerRow - 1);
                }
            }

            return finalBounds.ToArray();
        }