Skip to content

Commit a7cd0e0

Browse files
authored
Fix RWP conforming to EPUB (#642)
1 parent 9e6b0a8 commit a7cd0e0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ All notable changes to this project will be documented in this file. Take a look
3030

3131
* [go-toolkit#92](https://github.com/readium/go-toolkit/issues/92) The accessibility feature `printPageNumbers` is deprecated in favor of `pageNavigation`.
3232

33+
### Fixed
34+
35+
* Fixed support of Readium Web Publication packages conforming to the EPUB profile (contributed by [@ddfreiling](https://github.com/readium/kotlin-toolkit/pull/642)).
36+
3337

3438
## [3.0.3]
3539

readium/navigator/src/main/java/org/readium/r2/navigator/epub/HtmlInjector.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ internal fun Resource.injectHtml(
4242
var content = bytes.toString(mediaType.charset ?: Charsets.UTF_8).trim()
4343
val injectables = mutableListOf<String>()
4444

45-
if (publication.metadata.presentation.layout == EpubLayout.REFLOWABLE) {
45+
if (publication.metadata.presentation.layout == EpubLayout.FIXED) {
46+
injectables.add(
47+
script(baseHref.resolve(Url("readium/scripts/readium-fixed.js")!!))
48+
)
49+
} else {
4650
content = try {
4751
css.injectHtml(content)
4852
} catch (e: Exception) {
@@ -54,10 +58,6 @@ internal fun Resource.injectHtml(
5458
baseHref.resolve(Url("readium/scripts/readium-reflowable.js")!!)
5559
)
5660
)
57-
} else {
58-
injectables.add(
59-
script(baseHref.resolve(Url("readium/scripts/readium-fixed.js")!!))
60-
)
6161
}
6262

6363
// Disable the text selection if the publication is protected.

readium/streamer/src/main/java/org/readium/r2/streamer/parser/readium/ReadiumWebPubParser.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ import org.readium.r2.shared.util.resource.Resource
4242
import org.readium.r2.shared.util.resource.SingleResourceContainer
4343
import org.readium.r2.streamer.parser.PublicationParser
4444
import org.readium.r2.streamer.parser.audio.AudioLocatorService
45+
import org.readium.r2.streamer.parser.epub.EpubPositionsService
4546
import timber.log.Timber
4647

4748
/**
4849
* Parses any Readium Web Publication package or manifest, e.g. WebPub, Audiobook, DiViNa, LCPDF...
50+
*
51+
* @param epubReflowablePositionsStrategy Strategy used to calculate the number
52+
* of positions in a reflowable resource of a web publication conforming to the
53+
* EPUB profile.
4954
*/
5055
public class ReadiumWebPubParser(
5156
private val context: Context? = null,
5257
private val httpClient: HttpClient,
5358
private val pdfFactory: PdfDocumentFactory<*>?,
59+
private val epubReflowablePositionsStrategy: EpubPositionsService.ReflowableStrategy = EpubPositionsService.ReflowableStrategy.recommended,
5460
) : PublicationParser {
5561

5662
override suspend fun parse(
@@ -97,6 +103,8 @@ public class ReadiumWebPubParser(
97103
pdfFactory?.let { LcpdfPositionsService.create(it) }
98104
manifest.conformsTo(Publication.Profile.DIVINA) ->
99105
PerResourcePositionsService.createFactory(MediaType("image/*")!!)
106+
manifest.conformsTo(Publication.Profile.EPUB) ->
107+
EpubPositionsService.createFactory(epubReflowablePositionsStrategy)
100108
else ->
101109
WebPositionsService.createFactory(httpClient)
102110
}

0 commit comments

Comments
 (0)