Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d1333a4
Refactor `Fetcher.Resource` into `Publication.Resource`
mickael-menu Jul 26, 2023
690c21b
Minor fixes
mickael-menu Jul 26, 2023
5a5e66a
Use `MediaType` type in `Resource.mediaType()`
mickael-menu Jul 26, 2023
20dc24b
Fix
mickael-menu Jul 26, 2023
dbebf88
Remove `Publication.Resource`
mickael-menu Jul 27, 2023
9331f09
Add support for file:// Href
mickael-menu Jul 27, 2023
347d213
Expose `href` and `baseHref` of `Href`
mickael-menu Jul 27, 2023
4537177
Replace `Resource.key` with `Resource.href`
mickael-menu Jul 27, 2023
d2815ca
Replace `Resource.href` with `Resource.url`
mickael-menu Jul 27, 2023
0ed2756
Introduce dedicated `Resource.Properties` map
mickael-menu Jul 27, 2023
55bf9c7
Rename `Resource.url` to `Resource.source`
mickael-menu Jul 27, 2023
3608fed
Refactor `Resource.suggestedFilename`
mickael-menu Jul 27, 2023
b7a3f48
Make Publication.localizedTitle optional
mickael-menu Jul 28, 2023
b1b847a
Change the default HREF for standalone files to `.`
mickael-menu Jul 28, 2023
b6cd714
Remove `Container.name`, `Resource.name`, `Asset.name`
mickael-menu Jul 28, 2023
ecf1a91
Refactor `LcpDecryptor` to source the `Encryption` metadata
mickael-menu Jul 28, 2023
2368417
Remove the `Fetcher`
mickael-menu Aug 1, 2023
277ea03
Make `Container.get()` non suspending
mickael-menu Aug 1, 2023
ac7432d
Remove `PublicationResource`
mickael-menu Aug 2, 2023
b3b6016
Fix shared tests
mickael-menu Aug 2, 2023
37f50ab
Fix `EpubDeobfuscator` and Streamer tests
mickael-menu Aug 2, 2023
2ce68cd
Fix media type in Publication.get
mickael-menu Aug 2, 2023
92058ac
Merge branch 'v3' into remove-fetcher
mickael-menu Aug 2, 2023
b5e9a4e
Small changes
qnga Aug 7, 2023
6e6e0dd
Refactor Href
qnga Aug 8, 2023
f6edd58
Make title required when parsing a RWPM
mickael-menu Aug 16, 2023
e4b2d6d
Prevent exceptions when creating `FileResource`
mickael-menu Aug 16, 2023
9e20a74
Fix Zip properties
qnga Aug 16, 2023
355a924
Make `Container.entries` an optional `Set`
mickael-menu Aug 16, 2023
2f835eb
Merge branch 'remove-fetcher' of github.com:readium/kotlin-toolkit in…
mickael-menu Aug 16, 2023
8a1a9f2
Restore original `Href` APIs
mickael-menu Aug 16, 2023
8caf71e
Take into account `Manifest.links`,`Link.children` and `Link.alternat…
mickael-menu Aug 16, 2023
06111d2
Merge branch 'remove-fetcher-fixes' into remove-fetcher
mickael-menu Aug 16, 2023
68c874c
Remove Link helpers in BytesResource
mickael-menu Aug 16, 2023
3932b37
Lint
mickael-menu Aug 16, 2023
7ad2208
Fix tests
mickael-menu Aug 17, 2023
b95102c
Refactor media type sniffing (#377)
mickael-menu Aug 22, 2023
7e8be08
Update changelog
mickael-menu Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ lint/reports/
docs/readium
docs/index.md
docs/package-list
site/
site/
androidTestResultsUserPreferences.xml
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ All notable changes to this project will be documented in this file. Take a look

* Readium resources are now prefixed with `readium_`. Take care of updating any overridden resource by following [the migration guide](docs/migration-guide.md#300).

#### Shared

* `Publication.localizedTitle` is nullable, as we cannot guarantee that all publication sources offer a title.
* The `MediaType` sniffing helpers are deprecated in favor of `MediaTypeRetriever` (for media type and file extension hints and raw content) and `AssetRetriever` (for URLs).

#### Navigator

* `EpubNavigatorFragment.firstVisibleElementLocator()` now returns the first *block* element that is visible on the screen, even if it starts on previous pages.
Expand All @@ -39,6 +44,10 @@ All notable changes to this project will be documented in this file. Take a look

* All the navigator `Activity` are deprecated in favor of the `Fragment` variants.

#### Streamer

* The `Fetcher` interface was deprecated in favor of the `Container` one in `readium-shared`.

### Fixed

#### Navigator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import org.readium.r2.shared.InternalReadiumApi
import org.readium.r2.shared.error.getOrThrow
import org.readium.r2.shared.extensions.md5
import org.readium.r2.shared.extensions.tryOrNull
import org.readium.r2.shared.fetcher.Fetcher
import org.readium.r2.shared.resource.Resource
import org.readium.r2.shared.util.pdf.PdfDocument
import org.readium.r2.shared.util.pdf.PdfDocumentFactory
import org.readium.r2.shared.util.toFile
import org.readium.r2.shared.util.use
import timber.log.Timber

Expand Down Expand Up @@ -87,26 +88,29 @@ public class PdfiumDocumentFactory(context: Context) : PdfDocumentFactory<Pdfium
override suspend fun open(file: File, password: String?): PdfiumDocument =
core.fromFile(file, password)

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

private suspend fun Fetcher.Resource.openAsFile(password: String?): PdfiumDocument? =
file?.let {
tryOrNull { open(it, password) }
private suspend fun Resource.openAsFile(password: String?): PdfiumDocument? =
tryOrNull {
source?.toFile()?.let { open(it, password) }
}

private suspend fun Fetcher.Resource.openBytes(password: String?): PdfiumDocument =
private suspend fun Resource.openBytes(password: String?): PdfiumDocument =
use {
core.fromBytes(read().getOrThrow(), password)
}

private fun PdfiumCore.fromFile(file: File, password: String?): PdfiumDocument =
fromDocument(
newDocument(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY), password),
newDocument(
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY),
password
),
identifier = file.md5()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ import org.readium.r2.shared.ExperimentalReadiumApi
@ExperimentalReadiumApi
public data class PdfiumDefaults(
val pageSpacing: Double? = null,
val readingProgression: ReadingProgression? = null,
val readingProgression: ReadingProgression? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class PdfiumDocumentFragment internal constructor(
val context = context?.applicationContext ?: return

viewLifecycleOwner.lifecycleScope.launch {

try {
val document = PdfiumDocumentFactory(context)
// PDFium crashes when reusing the same PdfDocument, so we must not cache it.
Expand Down Expand Up @@ -141,8 +140,11 @@ public class PdfiumDocumentFragment internal constructor(
override val pageIndex: Int get() = viewPageIndex ?: initialPageIndex

private val viewPageIndex: Int? get() =
if (pdfView.isRecycled) null
else convertPageIndexFromView(pdfView.currentPage)
if (pdfView.isRecycled) {
null
} else {
convertPageIndexFromView(pdfView.currentPage)
}

override fun goToPageIndex(index: Int, animated: Boolean): Boolean {
if (!isValidPageIndex(index)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public data class PdfiumPreferences(
val fit: Fit? = null,
val pageSpacing: Double? = null,
val readingProgression: ReadingProgression? = null,
val scrollAxis: Axis? = null,
val scrollAxis: Axis? = null
) : Configurable.Preferences<PdfiumPreferences> {

init {
Expand All @@ -40,6 +40,6 @@ public data class PdfiumPreferences(
fit = other.fit ?: fit,
pageSpacing = other.pageSpacing ?: pageSpacing,
readingProgression = other.readingProgression ?: readingProgression,
scrollAxis = other.scrollAxis ?: scrollAxis,
scrollAxis = other.scrollAxis ?: scrollAxis
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.readium.r2.shared.publication.Metadata
public class PdfiumPreferencesEditor internal constructor(
initialPreferences: PdfiumPreferences,
publicationMetadata: Metadata,
defaults: PdfiumDefaults,
defaults: PdfiumDefaults
) : PreferencesEditor<PdfiumPreferences> {

private data class State(
Expand Down Expand Up @@ -55,7 +55,7 @@ public class PdfiumPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.fit },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(fit = value) } },
supportedValues = listOf(Fit.CONTAIN, Fit.WIDTH),
supportedValues = listOf(Fit.CONTAIN, Fit.WIDTH)
)

/**
Expand All @@ -69,7 +69,7 @@ public class PdfiumPreferencesEditor internal constructor(
updateValue = { value -> updateValues { it.copy(pageSpacing = value) } },
supportedRange = 0.0..50.0,
progressionStrategy = DoubleIncrement(5.0),
valueFormatter = { "${it.format(1)} dp" },
valueFormatter = { "${it.format(1)} dp" }
)

/**
Expand All @@ -81,7 +81,7 @@ public class PdfiumPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.readingProgression },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(readingProgression = value) } },
supportedValues = listOf(ReadingProgression.LTR, ReadingProgression.RTL),
supportedValues = listOf(ReadingProgression.LTR, ReadingProgression.RTL)
)

/**
Expand All @@ -93,7 +93,7 @@ public class PdfiumPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.scrollAxis },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(scrollAxis = value) } },
supportedValues = listOf(Axis.VERTICAL, Axis.HORIZONTAL),
supportedValues = listOf(Axis.VERTICAL, Axis.HORIZONTAL)
)

private fun updateValues(updater: (PdfiumPreferences) -> PdfiumPreferences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public object PdfiumSharedPreferencesFilter : PreferencesFilter<PdfiumPreference

override fun filter(preferences: PdfiumPreferences): PdfiumPreferences =
preferences.copy(
readingProgression = null,
readingProgression = null
)
}

Expand All @@ -29,6 +29,6 @@ public object PdfiumPublicationPreferencesFilter : PreferencesFilter<PdfiumPrefe

override fun filter(preferences: PdfiumPreferences): PdfiumPreferences =
PdfiumPreferences(
readingProgression = preferences.readingProgression,
readingProgression = preferences.readingProgression
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public data class PdfiumSettings(
val fit: Fit,
val pageSpacing: Double,
val readingProgression: ReadingProgression,
val scrollAxis: Axis,
val scrollAxis: Axis
) : Configurable.Settings
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class PdfiumSettingsResolver(
fit = fit,
pageSpacing = pageSpacing,
readingProgression = readingProgression,
scrollAxis = scrollAxis,
scrollAxis = scrollAxis
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import java.io.File
import kotlin.reflect.KClass
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.readium.r2.shared.fetcher.Fetcher
import org.readium.r2.shared.publication.ReadingProgression
import org.readium.r2.shared.resource.Resource
import org.readium.r2.shared.util.pdf.PdfDocument
import org.readium.r2.shared.util.pdf.PdfDocumentFactory
import timber.log.Timber
Expand All @@ -33,7 +33,7 @@ public class PsPdfKitDocumentFactory(context: Context) : PdfDocumentFactory<PsPd
override suspend fun open(file: File, password: String?): PsPdfKitDocument =
open(context, DocumentSource(file.toUri(), password))

override suspend fun open(resource: Fetcher.Resource, password: String?): PsPdfKitDocument =
override suspend fun open(resource: Resource, password: String?): PsPdfKitDocument =
open(context, DocumentSource(ResourceDataProvider(resource), password))

private suspend fun open(context: Context, documentSource: DocumentSource): PsPdfKitDocument =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import com.pspdfkit.document.providers.DataProvider
import java.util.*
import kotlinx.coroutines.runBlocking
import org.readium.r2.shared.error.getOrElse
import org.readium.r2.shared.fetcher.Fetcher
import org.readium.r2.shared.fetcher.synchronized
import org.readium.r2.shared.resource.Resource
import org.readium.r2.shared.resource.synchronized
import org.readium.r2.shared.util.isLazyInitialized
import timber.log.Timber

internal class ResourceDataProvider(
resource: Fetcher.Resource,
resource: Resource,
private val onResourceError: (Resource.Exception) -> Unit = { Timber.e(it) }
) : DataProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public data class PsPdfKitDefaults(
val pageSpacing: Double? = null,
val readingProgression: ReadingProgression? = null,
val scroll: Boolean? = null,
val spread: Spread? = null,
val spread: Spread? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ internal class PsPdfKitDocumentFragment(
.pagePadding(settings.pageSpacing.roundToInt())
.restoreLastViewedPage(false)
.scrollDirection(
if (!settings.scroll) PageScrollDirection.HORIZONTAL
else settings.scrollAxis.scrollDirection
if (!settings.scroll) {
PageScrollDirection.HORIZONTAL
} else {
settings.scrollAxis.scrollDirection
}
)
.scrollMode(settings.scroll.scrollMode)
.scrollOnEdgeTapEnabled(false)
Expand Down Expand Up @@ -185,7 +188,9 @@ internal class PsPdfKitDocumentFragment(
if (
pagePosition == null || clickedAnnotation is LinkAnnotation ||
clickedAnnotation is SoundAnnotation
) return false
) {
return false
}

pdfFragment.viewProjection.toViewPoint(pagePosition, pageIndex)
return listener?.onTap(pagePosition) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class PsPdfKitEngineProvider(
override suspend fun createDocumentFragment(
input: PdfDocumentFragmentInput<PsPdfKitSettings>
): PdfDocumentFragment<PsPdfKitSettings> {

val publication = input.publication
val document = PsPdfKitDocumentFactory(context)
.cachedIn(publication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public data class PsPdfKitPreferences(
val readingProgression: ReadingProgression? = null,
val scroll: Boolean? = null,
val scrollAxis: Axis? = null,
val spread: Spread? = null,
val spread: Spread? = null
) : Configurable.Preferences<PsPdfKitPreferences> {

init {
Expand All @@ -46,6 +46,6 @@ public data class PsPdfKitPreferences(
readingProgression = other.readingProgression ?: readingProgression,
scroll = other.scroll ?: scroll,
scrollAxis = other.scrollAxis ?: scrollAxis,
spread = other.spread ?: spread,
spread = other.spread ?: spread
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.readium.r2.shared.publication.Metadata
public class PsPdfKitPreferencesEditor internal constructor(
initialPreferences: PsPdfKitPreferences,
publicationMetadata: Metadata,
defaults: PsPdfKitDefaults,
defaults: PsPdfKitDefaults
) : PreferencesEditor<PsPdfKitPreferences> {

private data class State(
Expand Down Expand Up @@ -66,7 +66,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.fit },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(fit = value) } },
supportedValues = listOf(Fit.CONTAIN, Fit.WIDTH),
supportedValues = listOf(Fit.CONTAIN, Fit.WIDTH)
)

/**
Expand All @@ -81,7 +81,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getValue = { preferences.offsetFirstPage },
getEffectiveValue = { state.settings.offsetFirstPage },
getIsEffective = { !state.settings.scroll && state.settings.spread != Spread.NEVER },
updateValue = { value -> updateValues { it.copy(offsetFirstPage = value) } },
updateValue = { value -> updateValues { it.copy(offsetFirstPage = value) } }
)

/**
Expand All @@ -95,7 +95,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
updateValue = { value -> updateValues { it.copy(pageSpacing = value) } },
supportedRange = 0.0..50.0,
progressionStrategy = DoubleIncrement(5.0),
valueFormatter = { "${it.format(1)} dp" },
valueFormatter = { "${it.format(1)} dp" }
)

/**
Expand All @@ -107,7 +107,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.readingProgression },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(readingProgression = value) } },
supportedValues = listOf(ReadingProgression.LTR, ReadingProgression.RTL),
supportedValues = listOf(ReadingProgression.LTR, ReadingProgression.RTL)
)

/**
Expand All @@ -118,7 +118,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getValue = { preferences.scroll },
getEffectiveValue = { state.settings.scroll },
getIsEffective = { true },
updateValue = { value -> updateValues { it.copy(scroll = value) } },
updateValue = { value -> updateValues { it.copy(scroll = value) } }
)

/**
Expand All @@ -132,7 +132,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.scrollAxis },
getIsEffective = { state.settings.scroll },
updateValue = { value -> updateValues { it.copy(scrollAxis = value) } },
supportedValues = listOf(Axis.VERTICAL, Axis.HORIZONTAL),
supportedValues = listOf(Axis.VERTICAL, Axis.HORIZONTAL)
)

/**
Expand All @@ -146,7 +146,7 @@ public class PsPdfKitPreferencesEditor internal constructor(
getEffectiveValue = { state.settings.spread },
getIsEffective = { !state.settings.scroll },
updateValue = { value -> updateValues { it.copy(spread = value) } },
supportedValues = listOf(Spread.AUTO, Spread.NEVER, Spread.ALWAYS),
supportedValues = listOf(Spread.AUTO, Spread.NEVER, Spread.ALWAYS)
)

private fun updateValues(updater: (PsPdfKitPreferences) -> PsPdfKitPreferences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public object PsPdfKitSharedPreferencesFilter : PreferencesFilter<PsPdfKitPrefer
preferences.copy(
readingProgression = null,
offsetFirstPage = null,
spread = null,
spread = null
)
}

Expand All @@ -33,6 +33,6 @@ public object PsPdfKitPublicationPreferencesFilter : PreferencesFilter<PsPdfKitP
PsPdfKitPreferences(
readingProgression = preferences.readingProgression,
offsetFirstPage = preferences.offsetFirstPage,
spread = preferences.spread,
spread = preferences.spread
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public data class PsPdfKitSettings(
val readingProgression: ReadingProgression,
val scroll: Boolean,
val scrollAxis: Axis,
val spread: Spread,
val spread: Spread
) : Configurable.Settings
Loading