Ejemplo n.º 1
0
 public void EndNumbering()
 {
     while (this._route.Count > 0)
     {
         PDFPageNumberGroup grp = this._route.Pop();
         if (grp.IsCounting)
         {
             grp.EndCounting();
         }
     }
 }
Ejemplo n.º 2
0
 public void PopNumberStyle(PDFPageNumberGroup grp)
 {
     if (null != grp)
     {
         if (this._route.Pop().Equals(grp) == false)
         {
             throw new InvalidOperationException("Unbalanced stack");
         }
         grp.EndCounting();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Extracts out the relevant information from the style and builds a group
        /// or returns the DefaultGrouping if there is no relevant information
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        private static bool GetGroupingFromOptions(PDFPageNumberGroup template, PDFPageNumberOptions opts, out PDFPageNumberGroup updated)
        {
            if (null == opts)
            {
                throw new ArgumentNullException("opts");
            }
            if (null == template)
            {
                throw new ArgumentNullException("template");
            }

            bool            modified = false;
            PageNumberStyle numStyle = template.NumberStyle;
            int             numStart = template.NumberStart;
            string          grpName  = template.GroupName;


            if (!string.IsNullOrEmpty(opts.NumberGroup))
            {
                if (opts.NumberGroup == template.GroupName)
                {
                    throw new InvalidOperationException("The new style and the template have the same name - they should use the same options");
                }
                grpName  = opts.NumberGroup;
                modified = true;
            }


            if (opts.NumberStyle.HasValue)// && style.NumberStyle != numStyle)
            {
                modified = true;
                numStyle = opts.NumberStyle.Value;
            }

            if (opts.StartIndex.HasValue)// && style.NumberStartIndex != numStart)
            {
                modified = true;
                numStart = opts.StartIndex.Value;
            }

            if (modified)
            {
                updated = new PDFPageNumberGroup(template.Owner, grpName, numStyle, numStart);
                return(modified);
            }
            else
            {
                updated = null;
                return(false);
            }
        }
Ejemplo n.º 4
0
        //
        // private implementation
        //

        private PDFPageNumberData GetPageDataWithGroup(int pageIndex, PDFPageNumberGroup grp)
        {
            string label             = grp.GetPageLabel(pageIndex);
            string lastLabel         = grp.GetPageLabel(this.TotalPages);
            int    grpNum            = pageIndex + grp.NumberStart;
            int    lastGrpNum        = this.TotalPages + 1;
            int    globalPageNum     = pageIndex + 1;
            int    globalLastPageNum = _totalpages + 1;

            PDFPageNumberData data = new PDFPageNumberData(grp)
            {
                Label           = label,
                LastLabel       = lastLabel,
                GroupNumber     = grpNum,
                GroupLastNumber = lastGrpNum,
                PageNumber      = globalPageNum,
                LastPageNumber  = globalLastPageNum
            };

            return(data);
        }
Ejemplo n.º 5
0
        public void UnRegister(int pageIndex)
        {
            this._totalpages = Math.Max(this._totalpages, pageIndex);
            if (this._route.Count == 0)
            {
                throw new ArgumentNullException("No Current group on the stack to unregister. Make sure Register is always called first");
            }

            PDFPageNumberGroup grp = this._route.Peek();

            //If this is an unregister following a nested unregister then we won't be counting
            //But we know the previous page index, so we start from the one after
            if (!grp.IsCounting)
            {
                grp.BeginCounting(this._lastPageIndex + 1);
            }


            this.CurrentGroup.IncludePage(pageIndex);
            this._lastPageIndex = pageIndex;
        }
Ejemplo n.º 6
0
        //
        // public methods
        //

        public PDFPageNumberGroup PushPageNumber(PDFPageNumberOptions opts)
        {
            if (null != opts && opts.HasPageNumbering)
            {
                PDFPageNumberGroup grp;

                if (string.IsNullOrEmpty(opts.NumberGroup) || !_namedGroups.TryGetValue(opts.NumberGroup, out grp))
                {
                    if (this._route.Count == 0)
                    {
                        GetGroupingFromOptions(this._default, opts, out grp);
                    }

                    else
                    {
                        GetGroupingFromOptions(this._route.Peek(), opts, out grp);
                    }
                }

                //check if the pushed style is different from the current group or we don't have anything on the stack.
                if (null != grp)
                {
                    if (this._route.Count > 0 && _route.Peek().IsCounting)
                    {
                        this._lastGroup = this._route.Peek();
                    }

                    this._route.Push(grp);

                    if (!string.IsNullOrEmpty(grp.GroupName))
                    {
                        this._namedGroups.Add(grp.GroupName, grp);
                    }

                    return(grp);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the current page number grouping based on the provided style. If this is different from the current style
        /// then the new grouping is returned. This should then be passed to Unregister when finished with.
        /// </summary>
        /// <param name="pgStyle"></param>
        /// <returns></returns>
        public void Register(int pageIndex)
        {
            this._totalpages = Math.Max(this._totalpages, pageIndex);

            //If we have an unclosed last group - after beginning a new group, then we need to close it.
            if (this._lastGroup != null && this._lastGroup.IsCounting)
            {
                this._lastGroup.IncludePage(pageIndex - 1);
                this._lastGroup.EndCounting();
                this._lastGroup = null;
            }

            if (this._route.Count == 0)
            {
                this._route.Push(GetDefaultGrouping());
            }

            PDFPageNumberGroup grp;

            if (this._route.Count > 0)
            {
                grp = this._route.Peek();
            }
            else
            {
                grp = this._default;
            }

            if (!grp.IsCounting)
            {
                grp.BeginCounting(pageIndex);
            }

            grp.IncludePage(pageIndex);
            this._lastPageIndex = pageIndex;
        }
Ejemplo n.º 8
0
        //
        // ctor
        //

        /// <summary>
        /// Creates and returns a new PDFPageNumber instance
        /// </summary>
        public PDFPageNumberData(PDFPageNumberGroup group)
        {
            this._group = group;
        }
 /// <summary>
 /// Create an new registration of the page numbering group
 /// </summary>
 /// <param name="index"></param>
 /// <param name="grp"></param>
 public PDFPageNumberRegistration(int startindex, int endindex, PDFPageNumberGroup grp)
 {
     this.FirstPageIndex = startindex;
     this.Group          = grp;
     this.LastPageIndex  = endindex;
 }
        //
        // ctor
        //

        #region public PDFPageNumberRegistration(int index, PDFPageNumberingGroup grp)

        /// <summary>
        /// Create an new registration of the page numbering group
        /// </summary>
        /// <param name="index"></param>
        /// <param name="grp"></param>
        public PDFPageNumberRegistration(int index, PDFPageNumberGroup grp)
        {
            this.FirstPageIndex = index;
            this.Group          = grp;
            this.LastPageIndex  = UNCLOSED;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a default grouping
        /// </summary>
        /// <returns></returns>
        private PDFPageNumberGroup GetDefaultGrouping()
        {
            PDFPageNumberGroup group = new PDFPageNumberGroup(this, string.Empty, PageNumberStyle.Decimals, 1);

            return(group);
        }
Ejemplo n.º 12
0
        //
        // ctor(s)
        //

        #region public PDFPageNumbers()

        /// <summary>
        /// Default empty constructor
        /// </summary>
        public PDFPageNumbers()
        {
            _default = GetDefaultGrouping();
        }