private PageContext CreateContextForPagePosition( PagePosition pagePosition, Rectangle occupiedRegion, double spaceAfterPrevious, Func <PageNumber, IPage> pageFactory) { var page = pageFactory(pagePosition.PageNumber); var columnSpace = _columnsConfiguration.CalculateColumnSpace(pagePosition.PageColumnIndex); var region = page .GetContentRegion() .CropHorizontal(columnSpace.X, columnSpace.Width); var context = new PageContext( pagePosition, region, page.DocumentVariables); var cropTop = occupiedRegion.BottomY == 0 ? spaceAfterPrevious : occupiedRegion.BottomY + spaceAfterPrevious - page.Margin.Top; // TODO: check -0.001 context = context.CropFromTop(Math.Min(cropTop, context.Region.Height - 0.001)); return(context); }
public override void Prepare(IPage page) { var pagePosition = new PagePosition(page.PageNumber); var region = page .GetPageRegion() .Crop(page.Margin.Top, this.PageMargin.Right, this.PageMargin.Footer, this.PageMargin.Left); var context = new PageContext(pagePosition, region, page.DocumentVariables); PageContext childContextRequest(PagePosition pagePosition, PageContextElement child) => this.OutOfPageContextFactory(page); var absoluteHeight = page.Configuration.Height; var spaceAfterPrevious = 0.0; foreach (var child in _childs) { child.Prepare(context, childContextRequest); var lastRegion = child.LastPageRegion; spaceAfterPrevious = child.CalculateSpaceAfter(_childs); var cropFromTop = Math.Min(lastRegion.Region.Height + spaceAfterPrevious, absoluteHeight - 0.001); context = context.CropFromTop(cropFromTop); } var boundingRegion = _childs .SelectMany(c => c.PageRegions.Where(pr => pr.PagePosition.PageNumber == page.PageNumber)) .UnionPageRegions(Margin.None) .ToArray() .Single(); var offsetY = page.Configuration.Height - page.Margin.Top - Math.Max(boundingRegion.Region.Height, this.PageMargin.FooterHeight) - this.PageMargin.Footer; _pageOffset = new Point(0, offsetY); foreach (var child in _childs) { child.SetPageOffset(_pageOffset); } if (boundingRegion.Region.Height < this.PageMargin.FooterHeight) { var resized = new Rectangle(boundingRegion.Region.TopLeft, boundingRegion.Region.Width, this.PageMargin.FooterHeight); boundingRegion = new PageRegion(boundingRegion.PagePosition, resized); } this.ResetPageRegions(new[] { boundingRegion }); }