github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/creator/toc.go (about)

     1  /*
     2   * This file is subject to the terms and conditions defined in
     3   * file 'LICENSE.md', which is part of this source code package.
     4   */
     5  
     6  package creator
     7  
     8  // TableOfContents provides an overview over chapters and subchapters when creating a document with Creator.
     9  type TableOfContents struct {
    10  	entries []TableOfContentsEntry
    11  }
    12  
    13  // Make a new table of contents.
    14  func newTableOfContents() *TableOfContents {
    15  	toc := TableOfContents{}
    16  	toc.entries = []TableOfContentsEntry{}
    17  	return &toc
    18  }
    19  
    20  // Entries returns the table of content entries.
    21  func (toc *TableOfContents) Entries() []TableOfContentsEntry {
    22  	return toc.entries
    23  }
    24  
    25  // Add a TOC entry.
    26  func (toc *TableOfContents) add(title string, chapter, subchapter, pageNum int) {
    27  	entry := TableOfContentsEntry{}
    28  	entry.Title = title
    29  	entry.Chapter = chapter
    30  	entry.Subchapter = subchapter
    31  	entry.PageNumber = pageNum
    32  
    33  	toc.entries = append(toc.entries, entry)
    34  }
    35  
    36  // TableOfContentsEntry defines a single entry in the TableOfContents.
    37  // Each entry has a title, chapter number, sub chapter (0 if chapter) and the page number.
    38  type TableOfContentsEntry struct {
    39  	Title      string
    40  	Chapter    int
    41  	Subchapter int // 0 if chapter
    42  	PageNumber int // Page number
    43  }