Readium Logo

Publication Encapsulation

Summary

We can make the Readium toolkit simpler and safer to use by exposing a single encapsulated Publication, encompassing resources access and services.

Motivation

For a given publication, we currently have several free-floating objects that a reading app needs to manipulate, such as DRMLicense, Fetcher/Container and Publication. This leads to a lot of housekeeping and fragile code in reading apps.

By exposing a single Publication object as the entry-point for everything related to the publication, we can:

Developer Guide

The Publication object is the entry-point for all metadata and services related to a publication. You can use it to:

Obtaining a Publication

The Publication object is usually created by the Readium toolkit, either from:

You are free to create a Publication manually to fit custom needs.

Getting Manifest Metadata

Publication provides access to a publication’s metadata. You can use them, for example, to import a publication in the user’s bookshelf or to browse its table of contents.

database.addPublication({
  "title": publication.metadata.title,
  "authors": publication.metadata.authors
    .map(author => author.name).join(", ")
})

Reading Publication Resources

Once you have a Link object targeting a resource, you can call Publication::get() to read it.

let coverLink = publication.linkWithRel("cover")
if (coverLink) {
  let coverBytes = publication.get(coverLink).read()
}

Presenting the Publication

To present the publication, create a navigator with the Publication object. It contains everything the navigator needs to render the publication.

Using Publication Services

While out of scope for this proposal, this example illustrates the feature-rich API we can get from an encapsulated Publication object.

Given a SearchService providing a Publication::search() helper, we can do:

let results = await publication.search("banana")
navigator.goTo(results[0])

Backward Compatibility and Migration

Mobile (Swift & Kotlin)

This proposal should be a non-breaking change, since it is merely additive.

Reference Guide

Manifest Class

Holds the metadata of a Readium publication, as described in the Readium Web Publication Manifest.

Constructors

Properties

The readingOrder, resources and tableOfContents properties may be implemented as computed properties using subcollections.

var readingOrder: [Link] {
    subcollections["readingOrder"]?.firstOrNull?.links ?? []
}

Methods

Publication Class

The Publication shared model is the entry-point for all the metadata and services related to a Readium publication.

It is constructed from a group of objects with clear responsibilities:

Constructors

Properties

Methods