Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:

env:
platform: ${{ 'iOS Simulator' }}
device: ${{ 'iPhone SE (3rd generation)' }}
device: ${{ 'iPhone 17' }}
commit_sha: ${{ github.sha }}
DEVELOPER_DIR: /Applications/Xcode_16.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer

jobs:
build:
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ All notable changes to this project will be documented in this file. Take a look
#### Navigator

* Support for displaying Divina (image-based publications like CBZ) in the fixed-layout EPUB navigator.
* Bitmap images in the EPUB reading order are now supported as a fixed layout resource.

#### Streamer

* The `ImageParser` now extracts metadata from `ComicInfo.xml` files in CBZ archives.
* EPUB manifest item fallbacks are now exposed as `alternates` in the corresponding `Link`.
* EPUBs with only bitmap images in the spine are now treated as Divina publications with fixed layout.
* When an EPUB spine item is HTML with a bitmap image fallback (or vice versa), the image is preferred as the primary link.

### Deprecated

#### Streamer

* The EPUB manifest item `id` attribute is no longer exposed in `Link.properties`.

### Fixed

#### Navigator

* PDF documents are now opened off the main thread, preventing UI freezes with large files.


## [3.6.0]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 58 additions & 3 deletions Sources/Navigator/EPUB/Scripts/src/fixed-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ export function FixedPage(iframeId, pageType) {
viewport.content = "initial-scale=" + scale + ", minimum-scale=" + scale;
}

// Sets the iframe source URL.
function setIframeSrc(url) {
// Release the memory of a previously created blob URL, if needed.
if (_iframe.src.startsWith("blob:")) {
URL.revokeObjectURL(_iframe.src);
}
_iframe.src = url;
}

return {
// Returns whether the page is currently loading its contents.
isLoading: false,
Expand Down Expand Up @@ -194,17 +203,20 @@ export function FixedPage(iframeId, pageType) {
}

_iframe.addEventListener("load", loaded);
_iframe.src = resource.url;

var url = resourceUrl(resource);
setIframeSrc(url);
},

// Resets the page and empty its contents.
// Resets the page and empties its contents.
reset: function () {
if (!this.link) {
return;
}
this.link = null;
_pageSize = null;
_iframe.src = "about:blank";

setIframeSrc("about:blank");
},

// Evaluates a script in the context of the page.
Expand Down Expand Up @@ -236,3 +248,46 @@ export function FixedPage(iframeId, pageType) {
},
};
}

// Returns the URL to load for the given resource.
// Bitmap images are wrapped in an HTML document with alt text for accessibility.
function resourceUrl(resource) {
if (isBitmapMediaType(resource.link.type)) {
let html = generateImageWrapper(resource.url, resource.link.title);
let blob = new Blob([html], { type: "text/html" });
return URL.createObjectURL(blob);
} else {
return resource.url;
}
}

// Helper to detect bitmap media types.
function isBitmapMediaType(type) {
if (!type) return false;
return type.startsWith("image/") && !type.includes("svg");
}

// Generate an HTML wrapper with alt text for the bitmap at `imageUrl`.
function generateImageWrapper(imageUrl, altText) {
let doc = document.implementation.createHTMLDocument("");

let meta = doc.createElement("meta");
meta.name = "viewport";
meta.content = "width=device-width, height=device-height";
doc.head.appendChild(meta);

let style = doc.createElement("style");
style.textContent =
"body { margin: 0; }\n" +
"img { display: block; width: 100%; height: 100%; object-fit: contain; }";
doc.head.appendChild(style);

let img = doc.createElement("img");
img.src = imageUrl;
if (altText) {
img.alt = altText;
}
doc.body.appendChild(img);

return "<!DOCTYPE html>\n" + doc.documentElement.outerHTML;
}
9 changes: 8 additions & 1 deletion Sources/Navigator/PDF/PDFNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ open class PDFNavigatorViewController:
}

if currentResourceIndex != index {
guard let document = PDFDocument(url: url.url) else {
guard let document = await makeDocument(at: url) else {
log(.error, "Can't open PDF document at \(url)")
return false
}
Expand Down Expand Up @@ -483,6 +483,13 @@ open class PDFNavigatorViewController:
return true
}

private func makeDocument(at url: AbsoluteURL) async -> PDFKit.PDFDocument? {
let task = Task.detached(priority: .userInitiated) {
PDFDocument(url: url.url)
}
return await task.value
}

/// Updates the scale factors to match the currently visible pages.
///
/// - Parameter zoomToFit: When true, the document will be zoomed to fit the
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/Publication/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public struct Manifest: JSONEquatable, Hashable, Sendable {
case .epub:
// EPUB needs to be explicitly indicated in `conformsTo`, otherwise
// it could be a regular Web Publication.
return readingOrder.allAreHTML && metadata.conformsTo.contains(.epub)
return metadata.conformsTo.contains(.epub)
case .pdf:
return readingOrder.allMatchingMediaType(.pdf)
default:
Expand Down
3 changes: 1 addition & 2 deletions Sources/Streamer/Parser/EPUB/EPUBManifestParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ final class EPUBManifestParser {

// Extracts metadata and links from the OPF.
let opfPackage = try await OPFParser(container: container, opfHREF: opfHREF, encryptions: encryptions).parsePublication()
let metadata = opfPackage.metadata
let links = opfPackage.readingOrder + opfPackage.resources

var manifest = await Manifest(
metadata: metadata,
metadata: opfPackage.metadata,
readingOrder: opfPackage.readingOrder,
resources: opfPackage.resources,
subcollections: parseCollections(in: container, package: opfPackage, links: links)
Expand Down
Loading