Skip to content

Commit 6a489f7

Browse files
authoredJul 17, 2023
Abstract the toolkit over publication source (#353)
1 parent 2d80205 commit 6a489f7

File tree

196 files changed

+5723
-4655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+5723
-4655
lines changed
 

‎readium/adapters/pdfium/pdfium-document/src/main/java/org/readium/adapters/pdfium/document/PdfiumDocument.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import kotlin.reflect.KClass
1616
import kotlinx.coroutines.Dispatchers
1717
import kotlinx.coroutines.withContext
1818
import org.readium.r2.shared.PdfSupport
19+
import org.readium.r2.shared.error.getOrThrow
1920
import org.readium.r2.shared.extensions.md5
2021
import org.readium.r2.shared.extensions.tryOrNull
21-
import org.readium.r2.shared.fetcher.Resource
22+
import org.readium.r2.shared.fetcher.Fetcher
2223
import org.readium.r2.shared.util.pdf.PdfDocument
2324
import org.readium.r2.shared.util.pdf.PdfDocumentFactory
2425
import org.readium.r2.shared.util.use
@@ -89,19 +90,19 @@ class PdfiumDocumentFactory(context: Context) : PdfDocumentFactory<PdfiumDocumen
8990
override suspend fun open(file: File, password: String?): PdfiumDocument =
9091
core.fromFile(file, password)
9192

92-
override suspend fun open(resource: Resource, password: String?): PdfiumDocument {
93+
override suspend fun open(resource: Fetcher.Resource, password: String?): PdfiumDocument {
9394
// First try to open the resource as a file on the FS for performance improvement, as
9495
// PDFium requires the whole PDF document to be loaded in memory when using raw bytes.
9596
return resource.openAsFile(password)
9697
?: resource.openBytes(password)
9798
}
9899

99-
private suspend fun Resource.openAsFile(password: String?): PdfiumDocument? =
100+
private suspend fun Fetcher.Resource.openAsFile(password: String?): PdfiumDocument? =
100101
file?.let {
101102
tryOrNull { open(it, password) }
102103
}
103104

104-
private suspend fun Resource.openBytes(password: String?): PdfiumDocument =
105+
private suspend fun Fetcher.Resource.openBytes(password: String?): PdfiumDocument =
105106
use {
106107
core.fromBytes(read().getOrThrow(), password)
107108
}

‎readium/adapters/pdfium/pdfium-navigator/src/main/java/org/readium/adapters/pdfium/navigator/PdfiumDocumentFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import org.readium.r2.navigator.preferences.Axis
2121
import org.readium.r2.navigator.preferences.Fit
2222
import org.readium.r2.navigator.preferences.ReadingProgression
2323
import org.readium.r2.shared.ExperimentalReadiumApi
24-
import org.readium.r2.shared.fetcher.Resource
2524
import org.readium.r2.shared.publication.Link
2625
import org.readium.r2.shared.publication.Publication
26+
import org.readium.r2.shared.resource.Resource
2727
import timber.log.Timber
2828

2929
@ExperimentalReadiumApi

0 commit comments

Comments
 (0)