/// <summary>
        /// Registers the current page numbering options for the specified page at the specified index
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="page"></param>
        /// <param name="num"></param>
        public PDFPageNumberGroup RegisterPageNumbering(PDFLayoutPage page, PDFPageNumberOptions options)
        {
            PDFPageNumberGroup grp = this.Numbers.PushPageNumber(options);

            this.Numbers.Register(page.PageIndex);
            return(grp);
        }
        protected virtual PDFLayoutPage CreateNewPageInstance(PageBase owner, IPDFLayoutEngine engine, Style full, OverflowAction action, int pageIndex)
        {
            PDFLayoutPage pg = new PDFLayoutPage(this, owner, engine, full, action);

            pg.PageIndex = pageIndex;
            return(pg);
        }
        //
        // public methods
        //

        #region public PDFLayoutPage BeginNewContinuationPage()

        /// <summary>
        /// Begins a new page based on the current page's size and content rect. This will then be the current page
        /// </summary>
        /// <returns></returns>
        public PDFLayoutPage BeginNewContinuationPage()
        {
            if (CurrentPageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("Cannot begin a new page based on previous page if there are no previous pages");
            }
            PDFLayoutPage pg = this.CurrentPage;

            PDFTraceLog log = this.DocumentComponent.TraceLog;

            if (log.ShouldLog(TraceLevel.Verbose))
            {
                log.Add(TraceLevel.Verbose, "LAYOUT", "Beginning a new continuation page for '" + pg + "'");
            }

            if (!pg.IsClosed)
            {
                pg.Close();
            }

            PDFSize        size     = pg.Size;
            Style          style    = pg.FullStyle;
            Page           owner    = pg.Owner as Page;
            OverflowAction overflow = pg.OverflowAction;

            PDFLayoutPage newpg = this.BeginNewPage(owner, this.Engine, style, overflow);

            return(newpg);
        }
Пример #4
0
 public void SetAppearance(FormFieldAppearanceState state, Layout.PDFLayoutXObject xObject, Layout.PDFLayoutPage page, Styles.Style style)
 {
     this._states[state] = xObject;
     if (state == FormFieldAppearanceState.Normal)
     {
         this._style = style;
     }
     this._page = page;
 }
        //
        // support methods
        //

        #region protected virtual void BuildNewPage(PDFPageSize pgsize, PDFPositionOptions options ...)

        /// <summary>
        /// Creates a new page with the specified options and adds it to the current layout
        /// </summary>
        /// <param name="pgsize"></param>
        /// <param name="options"></param>
        /// <param name="alley"></param>
        /// <param name="colcount"></param>
        /// <param name="action"></param>
        protected virtual PDFLayoutPage BuildNewPage(PDFSize pgsize, PDFPositionOptions options, PDFColumnOptions colOpts, OverflowAction action)
        {
            PDFLayoutDocument doclayout = this.DocumentLayout;
            PDFLayoutPage     pg        = doclayout.BeginNewPage(this.Page, this, this.FullStyle, action);

            pg.InitPage(pgsize, options, colOpts, this.Context);

            return(pg);
        }
        protected virtual void UnRegisterPageNumbering(PDFLayoutPage last, PDFPageNumberOptions options)
        {
            this.DocumentLayout.UnRegisterPageNumbering(last, _numbergroup);

            if (this.Context.ShouldLogDebug)
            {
                this.Context.TraceLog.Add(TraceLevel.Debug, LayoutEnginePage.LOG_CATEGORY, "Un-registered the page numbering");
            }
        }
        protected virtual void RegisterPageNumbering(PDFLayoutPage page, PDFPageNumberOptions options)
        {
            this._numbergroup = this.DocumentLayout.RegisterPageNumbering(page, options);
            _firstpageIndex   = page.PageIndex;

            if (this.Context.ShouldLogDebug)
            {
                this.Context.TraceLog.Add(TraceLevel.Debug, LayoutEnginePage.LOG_CATEGORY, "Registered the page numbering");
            }
        }
        /// <summary>
        /// Begins a new page of the requested size and with the specified bounds. This will then be the current page
        /// </summary>
        /// <param name="size">The actual size of the page</param>
        /// <param name="full">The full style of the page</param>
        /// <returns></returns>
        public PDFLayoutPage BeginNewPage(PageBase owner, IPDFLayoutEngine engine, Style full, OverflowAction action)
        {
            int           pgIndex = this.AllPages.Count;
            PDFLayoutPage pg      = CreateNewPageInstance(owner, engine, full, action, pgIndex);

            this.CurrentPageIndex = pg.PageIndex;
            this.CurrentPage      = pg;
            this.AllPages.Add(pg);

            return(pg);
        }
Пример #9
0
 /// <summary>
 /// Overrides the move to the next region - not complete
 /// </summary>
 /// <returns></returns>
 public override bool MoveToNextRegion(PDFUnit requiredHeight, PDFLayoutContext context)
 {
     if (this.ContentBlock.Position.OverflowAction == OverflowAction.NewPage)
     {
         PDFLayoutPage cont = this.Document.BeginNewContinuationPage();
         cont.InitPage(this.Size, this.ContentBlock.Position, this.ContentBlock.ColumnOptions, context);
         return(cont != null);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Based on the sizeing and style of the last page buids a continuation page that content can flow into
        /// </summary>
        /// <param name="copyfrom"></param>
        /// <returns></returns>
        protected virtual PDFLayoutPage BuildContinuationPage(PDFLayoutPage copyfrom, PDFSize size)
        {
            //Take a reference of the current stack and replace with the page stack from first page
            StyleStack orig = this.Context.StyleStack;

            this.Context.StyleStack = this.PageStyleStack;



            PDFLayoutPage page = this.BuildNewPage(size, copyfrom.PositionOptions, copyfrom.ContentBlock.ColumnOptions, copyfrom.OverflowAction);

            //becasue we are a continuation page, we have the same number style, so let's just register it with null
            this.DocumentLayout.RegisterPageNumbering(page, null);

            this.LayoutPageHeaderAndFooter();

            //Restore the context stack with the reference
            this.Context.StyleStack = orig;

            return(page);
        }
        /// <summary>
        /// If there is no open line at the start, or after a hard return, then this created a new one (adding inset as required)
        /// </summary>
        /// <returns></returns>
        private PDFLayoutLine EnsureFirstLineAvailable(out bool startedLine)
        {
            startedLine = false;
            PDFLayoutPage  pg    = this.Context.DocumentLayout.CurrentPage;
            PDFLayoutBlock block = pg.LastOpenBlock();

            if (null == block || block.IsClosed)
            {
                this.Context.TraceLog.Add(TraceLevel.Error, LOG_CATEGORY, "There is no open block on page '" + pg.ToString() + "' to add content to.");
                return(null);

                throw new InvalidOperationException("There is no open block to add the textual content to.");
            }
            PDFLayoutRegion reg = block.CurrentRegion;

            if (null == reg || reg.IsClosed)
            {
                this.Context.TraceLog.Add(TraceLevel.Error, LOG_CATEGORY, "There is no open region in block '" + block.ToString() + "' on page '" + pg.ToString() + "' to add content to.");
                return(null);

                throw new InvalidOperationException("There is no open block to add the textual content to.");
            }
            PDFLayoutLine line;

            if (reg.HasOpenItem)
            {
                line = (PDFLayoutLine)reg.CurrentItem;
            }
            else
            {
                line        = reg.BeginNewLine();
                startedLine = true;
                //No Inset spacer as this will be handled by the begin run
            }

            return(line);
        }
Пример #12
0
 protected override void DoPushComponentLayout(PDFLayoutContext context, int pageIndex, PDFUnit xoffset, PDFUnit yoffset)
 {
     this._page = context.DocumentLayout.CurrentPage;
     this._childContainer.PushComponentLayout(context, pageIndex, xoffset, yoffset);
 }
        //
        // overrides
        //


        /// <summary>
        /// Main overridden method
        /// </summary>
        protected override void DoLayoutComponent()
        {
            IDisposable record = this.Context.PerformanceMonitor.Record(PerformanceMonitorType.Layout_Pages, "Page " + this.Component.ID);

            //Take a copy of the style stack for the header and footer
            this.PageStyleStack = this.Context.StyleStack.Clone();


            //Get the page size and position options
            PageSize pgsize = this.FullStyle.CreatePageSize();

            pgsize.Size = this.GetNextPageSize(this.Component, this.FullStyle, pgsize.Size);

            PDFPositionOptions options = this.FullStyle.CreatePostionOptions();



            //Graphics
            PDFGraphics g = this.Page.CreateGraphics(this.StyleStack, this.Context);

            this.Context.Graphics = g;


            //Size, border, margins
            PDFRect bounds      = new PDFRect(PDFPoint.Empty, pgsize.Size);
            PDFRect contentrect = GetContentRectFromBounds(bounds, options.Margins, options.Padding);


            //Columns
            PDFColumnOptions colOpts = this.FullStyle.CreateColumnOptions();

            //Overflow
            OverflowAction action = options.OverflowAction;



            PDFLayoutPage pg = BuildNewPage(pgsize.Size, options, colOpts, action);

            //Register page numbering
            PDFPageNumberOptions numbers = this.GetPageNumbering(this.FullStyle);

            this.RegisterPageNumbering(pg, numbers);

            this.LayoutPageContent();



            //close the last page
            PDFLayoutPage last = this.DocumentLayout.CurrentPage;

            if (last.IsClosed == false)
            {
                last.Close();
            }

            //Unregister the page numbers.
            this.UnRegisterPageNumbering(last, numbers);

            //release graphics
            this.Context.Graphics = null;

            g.Dispose();
            record.Dispose();
        }
        /// <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
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="currentPageIndex"></param>
 /// <param name="page"></param>
 /// <param name="numbering"></param>
 public void UnRegisterPageNumbering(PDFLayoutPage page, PDFPageNumberGroup group)
 {
     this.Numbers.UnRegister(page.PageIndex);
     this.Numbers.PopNumberStyle(group);
 }
        protected virtual PDFObjectRef OutputAPage(PDFRenderContext context, PDFWriter writer, PDFLayoutPage ppe)
        {
            PDFObjectRef oref = ppe.OutputToPDF(context, writer);

            return(oref);
        }