//
        // methods
        //

        #region public PDFLayoutBlock LastOpenBlock()

        /// <summary>
        /// Returns the last block in this region that is open.
        /// Returns null if this region does not contain any blocks, or the last block is closed.
        /// </summary>
        /// <returns></returns>
        public PDFLayoutBlock LastOpenBlock()
        {
            if (null != this.Contents && this.Contents.Count > 0)
            {
                PDFLayoutItem item = this.Contents[this.Contents.Count - 1];
                if (item is PDFLayoutBlock)
                {
                    PDFLayoutBlock block = item as PDFLayoutBlock;
                    if (block.IsClosed == false)
                    {
                        return(block.LastOpenBlock());
                    }
                }
                else
                {
                    //the last item is not a block, so any previous blocks must be closed.
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the last open block in the hierarchy of layout blocks and regions.
        /// If there are no open blocks then returns null.
        /// </summary>
        /// <returns></returns>
        internal PDFLayoutBlock LastOpenBlock()
        {
            PDFLayoutBlock last = this.CurrentBlock;

            if (this.HeaderBlock != null && this.HeaderBlock.IsClosed == false)
            {
                last = this.HeaderBlock;
            }
            else if (this.FooterBlock != null && this.FooterBlock.IsClosed == false)
            {
                last = this.FooterBlock;
            }


            if (last.IsClosed)
            {
                last = null;
            }
            else
            {
                last = last.LastOpenBlock();
            }
            return(last);
        }
        /// <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
            }
        }