KiteDocument

interface 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

Link copied to clipboard
open val chapterCount: Int

How many chapters. One for a document that does not have them.

Link copied to clipboard

True once every chapter is laid out, so global page indices are final.

Link copied to clipboard

Pages laid out so far. Equals pageCount once isComplete.

Link copied to clipboard

Title/authors/language; defaults empty so third-party implementors don't break.

Link copied to clipboard

The navigation tree (PDF bookmarks / EPUB table of contents) with destinations resolved to page indices; empty when the document has none.

Link copied to clipboard
abstract val pageCount: Int

Number of pages in the whole document.

Link copied to clipboard
abstract val pages: List<KitePage>

The pages, in reading order.

Functions

Link copied to clipboard
open fun bookmarkOf(location: KiteLocation): KiteBookmark

A re-flow-proof position for location. Prepares its chapter first.

Link copied to clipboard
open fun isChapterReady(chapter: Int): Boolean

True when chapter is laid out and its pages can be read.

Link copied to clipboard
open fun locate(bookmark: KiteBookmark): KiteLocation

Where bookmark sits in the current layout. Prepares that chapter, and only that chapter. Clamps into range rather than failing.

Link copied to clipboard
open fun locationOf(pageIndex: Int): KiteLocation?

The location of a global page index, or null when the index is out of range or not reached yet.

Link copied to clipboard
open fun page(location: KiteLocation): KitePage

The page at location. Prepares its chapter first.

Link copied to clipboard
open fun pageCountIn(chapter: Int): Int

Pages in chapter. Prepares it first. Zero for an empty chapter.

Link copied to clipboard
open fun pageIndexOf(location: KiteLocation): Int?

The global index of location, or null while an earlier chapter is not ready yet and the index cannot be known.

Link copied to clipboard
open fun prepareChapter(chapter: Int)

Lays out chapter if it is not ready yet. The one expensive call.