/// <summary> /// Checks the overflow style and if new pages are supported closes the current page layout and /// creates a new page layout (becomming the current page) and returns true. /// If overflow is not supported - returns false /// </summary> /// <param name="region">If there is a change in current page, this is set to the new region</param> /// <param name="block">If there is a change in current page, this is set to the new block</param> /// <returns></returns> public override bool MoveToNextPage(IPDFComponent initiator, Style initiatorStyle, Stack <PDFLayoutBlock> depth, ref PDFLayoutRegion region, ref PDFLayoutBlock block) { StyleValue <OverflowAction> action; if (this.FullStyle.TryGetValue(StyleKeys.OverflowActionKey, out action) && action.Value == OverflowAction.NewPage) { PDFLayoutPage lastpage = this.DocumentLayout.CurrentPage; PDFLayoutBlock open = lastpage.ContentBlock; if (open.IsClosed) { open = null; } else { open = open.LastOpenBlock(); } List <PDFLayoutBlock> toclose = new List <PDFLayoutBlock>(depth); for (int i = toclose.Count - 1; i >= 0; i--) { open = toclose[i]; if (open.CurrentRegion != null && open.CurrentRegion.IsClosed == false) { PDFLayoutRegion openRegion = open.CurrentRegion; openRegion.Close(); } PDFLayoutBlock parent = open.Parent as PDFLayoutBlock; if (null != parent) { PDFLayoutRegion parentRegion = parent.CurrentRegion; if (null != parentRegion) { open.Close(); parentRegion.AddToSize(open); } } //open = parent; } lastpage.Close(); var pgSize = this.GetNextPageSize(initiator, initiatorStyle, lastpage.Size); PDFLayoutPage page = BuildContinuationPage(lastpage, pgSize); block = page.CurrentBlock; region = block.CurrentRegion; if (this.Context.ShouldLogVerbose) { this.Context.TraceLog.Add(TraceLevel.Verbose, LOG_CATEGORY, "Built a new continuation page for " + this.Component + " and recreated the " + toclose.Count + " blocks and regions on the new page"); } return(true); } else { if (this.Context.ShouldLogVerbose) { this.Context.TraceLog.Add(TraceLevel.Verbose, LOG_CATEGORY, "Cannot overflow content for page " + this.Component + " halting the continued layout by returning false"); } return(false); //Cannot overflow } }
protected void EnsureContentsFit() { bool newPage; PDFLayoutBlock block = this.CurrentBlock; //re-retrieve our container block and region //it could have changed whilst laying out other regions / pages. PDFLayoutBlock containerBlock = block.Parent as PDFLayoutBlock; if (block.IsClosed == false) { block.Close(); } bool updateSize = false; PDFSize updated = block.Size; if (block.Position.MinimumHeight.HasValue && block.Height < block.Position.MinimumHeight.Value) { updated.Height = block.Position.MinimumHeight.Value - (block.Position.Padding.Top + block.Position.Padding.Bottom); updateSize = true; } if (block.Position.MinimumWidth.HasValue && block.Width < block.Position.MinimumWidth.Value) { updated.Width = block.Position.MinimumWidth.Value - (block.Position.Padding.Left + block.Position.Padding.Right); updateSize = true; } if (updateSize) { block.SetContentSize(updated.Width, updated.Height); } PDFLayoutRegion containerRegion = containerBlock.CurrentRegion; //ADDED to support blocks flowing to the next region or page PDFUnit vspace = containerRegion.TotalBounds.Height - containerRegion.UsedSize.Height; PDFUnit req = block.Height; bool canfitvertical = req <= vspace; if (!canfitvertical && containerRegion.Contents.Count > 1) { PDFLayoutRegion prev = containerRegion; if (this.MoveToNextRegion(req, ref containerRegion, ref containerBlock, out newPage)) { prev.Contents.Remove(block); containerRegion.AddExistingItem(block); } else { this.Context.TraceLog.Add(TraceLevel.Warning, LOG_CATEGORY, "Cannot fit the block for component " + this.Component.UniqueID + " in the avilable height (required = '" + req + "', available = '" + vspace + "'), and we cannot overflow to a new region. Layout of component stopped and returning."); this.ContinueLayout = false; } } else { //Region has not updated its size as the block was directly closed. containerRegion.AddToSize(block); } }