public void EndNumbering() { while (this._route.Count > 0) { PDFPageNumberGroup grp = this._route.Pop(); if (grp.IsCounting) { grp.EndCounting(); } } }
public void PopNumberStyle(PDFPageNumberGroup grp) { if (null != grp) { if (this._route.Pop().Equals(grp) == false) { throw new InvalidOperationException("Unbalanced stack"); } grp.EndCounting(); } }
/// <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); } }
// // 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); }
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; }
// // 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); }
/// <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; }
// // 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; }
/// <summary> /// Creates a default grouping /// </summary> /// <returns></returns> private PDFPageNumberGroup GetDefaultGrouping() { PDFPageNumberGroup group = new PDFPageNumberGroup(this, string.Empty, PageNumberStyle.Decimals, 1); return(group); }
// // ctor(s) // #region public PDFPageNumbers() /// <summary> /// Default empty constructor /// </summary> public PDFPageNumbers() { _default = GetDefaultGrouping(); }