KiteDocument
A parsed document from any handler: the fz_document equivalent. Lets a viewer treat a io.github.yuroyami.kitepdf.PdfDocument and an io.github.yuroyami.kitepdf.epub.EpubDocument uniformly.
A document is CHAPTERS of pages. A PDF is one chapter. A reflowable EPUB is one chapter per spine item, and a chapter can be laid out without the ones before it, so a reader opens at chapter 20 without paginating chapters 0 to 19 first. Everything about chapters has a one-chapter default, so a handler that does not need them implements nothing.
Two ways to address a page:
KiteLocation (chapter, page): always available for a ready chapter.
a global index into pages: only once every earlier chapter is ready.
A viewer that wants to show a page before the whole document is laid out must work in locations. pageCount and pages lay out everything.
Properties
How many chapters. One for a document that does not have them.
True once every chapter is laid out, so global page indices are final.
Pages laid out so far. Equals pageCount once isComplete.
Title/authors/language; defaults empty so third-party implementors don't break.
The navigation tree (PDF bookmarks / EPUB table of contents) with destinations resolved to page indices; empty when the document has none.
Functions
A re-flow-proof position for location. Prepares its chapter first.
True when chapter is laid out and its pages can be read.
Where bookmark sits in the current layout. Prepares that chapter, and only that chapter. Clamps into range rather than failing.
The location of a global page index, or null when the index is out of range or not reached yet.
The page at location. Prepares its chapter first.
Pages in chapter. Prepares it first. Zero for an empty chapter.
The global index of location, or null while an earlier chapter is not ready yet and the index cannot be known.
Lays out chapter if it is not ready yet. The one expensive call.