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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ All notable changes to this project will be documented in this file. Take a look

**Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution.

<!--## [Unreleased]-->
## [Unreleased]

### Added

#### Navigator

* New `EPUBNavigatorFragment.Configuration.useReadiumCssFontSize` option to revert to the 2.2.0 strategy for setting the font size of reflowable EPUB publications.
* The native font size strategy introduced in 2.3.0 uses the Android web view's [`WebSettings.textZoom`](https://developer.android.com/reference/android/webkit/WebSettings#setTextZoom(int)) property to adjust the font size. 2.2.0 was using Readium CSS's [`--USER__fontSize` variable](https://readium.org/readium-css/docs/CSS12-user_prefs.html#font-size).
* `WebSettings.textZoom` will work with more publications than `--USER__fontSize`, even the ones poorly authored. However the page width is not adjusted when changing the font size to keep the optimal line length.

## [2.3.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typealias JavascriptInterfaceFactory = (resource: Link) -> Any?
*
* To use this [Fragment], create a factory with `EpubNavigatorFragment.createFactory()`.
*/
@OptIn(ExperimentalDecorator::class, ExperimentalReadiumApi::class)
@OptIn(ExperimentalDecorator::class, ExperimentalReadiumApi::class, DelicateReadiumApi::class)
class EpubNavigatorFragment internal constructor(
override val publication: Publication,
private val baseUrl: String?,
Expand Down Expand Up @@ -132,6 +132,22 @@ class EpubNavigatorFragment internal constructor(
@ExperimentalReadiumApi
var readiumCssRsProperties: RsProperties,

/**
* When disabled, the Android web view's `WebSettings.textZoom` will be used to adjust the
* font size, instead of using the Readium CSS's `--USER__fontSize` variable.
*
* `WebSettings.textZoom` will work with more publications than `--USER__fontSize`, even the
* ones poorly authored. However, the page width is not adjusted when changing the font
* size to keep the optimal line length.
*
* See:
* - https://github.com/readium/mobile/issues/5
* - https://github.com/readium/mobile/issues/1#issuecomment-652431984
*/
@ExperimentalReadiumApi
@DelicateReadiumApi
var useReadiumCssFontSize: Boolean = true,

/**
* Supported HTML decoration templates.
*/
Expand Down Expand Up @@ -503,18 +519,20 @@ class EpubNavigatorFragment internal constructor(
}

private fun R2PagerAdapter.setFontSize(fontSize: Double) {
r2PagerAdapter?.mFragments?.forEach { _, fragment ->
if (config.useReadiumCssFontSize) return

mFragments.forEach { _, fragment ->
(fragment as? R2EpubPageFragment)?.setFontSize(fontSize)
}
}

private inner class PagerAdapterListener : R2PagerAdapter.Listener {
override fun onCreatePageFragment(fragment: Fragment) {
if (viewModel.layout == EpubLayout.FIXED) {
return
if (viewModel.layout == EpubLayout.REFLOWABLE) {
if (!config.useReadiumCssFontSize) {
(fragment as? R2EpubPageFragment)?.setFontSize(settings.value.fontSize)
}
}

(fragment as? R2EpubPageFragment)?.setFontSize(settings.value.fontSize)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.readium.r2.navigator.html.HtmlDecorationTemplates
import org.readium.r2.navigator.preferences.*
import org.readium.r2.navigator.util.createViewModelFactory
import org.readium.r2.shared.COLUMN_COUNT_REF
import org.readium.r2.shared.DelicateReadiumApi
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.SCROLL_REF
import org.readium.r2.shared.extensions.addPrefix
Expand All @@ -44,7 +45,7 @@ internal enum class DualPage {
AUTO, OFF, ON
}

@OptIn(ExperimentalReadiumApi::class, ExperimentalDecorator::class)
@OptIn(ExperimentalReadiumApi::class, ExperimentalDecorator::class, DelicateReadiumApi::class)
internal class EpubNavigatorViewModel(
application: Application,
val publication: Publication,
Expand Down Expand Up @@ -118,7 +119,7 @@ internal class EpubNavigatorViewModel(
fontFamilyDeclarations = config.fontFamilyDeclarations,
googleFonts = googleFonts,
assetsBaseHref = WebViewServer.assetsBaseHref
).update(settings.value)
).update(settings.value, useReadiumCssFontSize = config.useReadiumCssFontSize)
)

init {
Expand Down Expand Up @@ -230,7 +231,7 @@ internal class EpubNavigatorViewModel(

val newSettings = settingsPolicy.settings(preferences)
_settings.value = newSettings
css.update { it.update(newSettings) }
css.update { it.update(newSettings, useReadiumCssFontSize = config.useReadiumCssFontSize) }

val needsInvalidation: Boolean = (
oldSettings.readingProgression != newSettings.readingProgression ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data class EpubSettings(
) : Configurable.Settings

@OptIn(ExperimentalReadiumApi::class)
internal fun ReadiumCss.update(settings: EpubSettings): ReadiumCss {
internal fun ReadiumCss.update(settings: EpubSettings, useReadiumCssFontSize: Boolean): ReadiumCss {

fun resolveFontStack(fontFamily: String): List<String> = buildList {
add(fontFamily)
Expand Down Expand Up @@ -109,9 +109,8 @@ internal fun ReadiumCss.update(settings: EpubSettings): ReadiumCss {
backgroundColor = backgroundColor?.toCss(),
fontOverride = (fontFamily != null || textNormalization),
fontFamily = fontFamily?.toCss(),
// Font size is handled natively with WebSettings.textZoom.
// See https://github.com/readium/mobile/issues/1#issuecomment-652431984
// fontSize = fontSize?.let { Length.Percent(it) },
fontSize = if (useReadiumCssFontSize) Length.Percent(fontSize)
else null,
advancedSettings = !publisherStyles,
typeScale = typeScale,
textAlign = when (textAlign) {
Expand Down