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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ All notable changes to this project will be documented in this file. Take a look
* This callback is called before executing any navigation action.
* Useful for hiding UI elements when the user navigates, or implementing analytics.
* Added swipe gesture support for navigating in PDF paginated spread mode.
* Added `fit` preference for PDF documents to control how pages are scaled within the viewport.
* Only effective in scroll mode. Paginated mode always uses page fit due to PDFKit limitations.
* Added `fit` preference for fixed-layout publications (PDF and FXL EPUB) to control how pages are scaled within the viewport.
* In the PDF navigator, it is only effective in scroll mode. Paginated mode always uses `page` fit due to PDFKit limitations.

### Deprecated

Expand All @@ -32,7 +32,7 @@ All notable changes to this project will be documented in this file. Take a look

* The `Fit` enum has been redesigned to fit the PDF implementation.
* **Breaking change:** Update any code using the old `Fit` enum values.
* The PDF navigator's content inset behavior has changed:
* The fixed-layout navigators (PDF and FXL EPUB)'s content inset behavior has changed:
* iPhone: Continues to apply window safe area insets (to account for notch/Dynamic Island).
* iPad/macOS: Now displays edge-to-edge with no automatic safe area insets.
* You can customize this behavior with `VisualNavigatorDelegate.navigatorContentInset(_:)`.
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.

4 changes: 3 additions & 1 deletion Sources/Navigator/EPUB/EPUBFixedSpreadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ final class EPUBFixedSpreadView: EPUBSpreadView {
insets.right = horizontalInsets

let viewportSize = bounds.inset(by: insets).size
let fitString = viewModel.settings.fit.rawValue

webView.evaluateJavaScript("""
spread.setViewport(
{'width': \(Int(viewportSize.width)), 'height': \(Int(viewportSize.height))},
{'top': \(Int(insets.top)), 'left': \(Int(insets.left)), 'bottom': \(Int(insets.bottom)), 'right': \(Int(insets.right))}
{'top': \(Int(insets.top)), 'left': \(Int(insets.left)), 'bottom': \(Int(insets.bottom)), 'right': \(Int(insets.right))},
'\(fitString)'
);
""")
}
Expand Down
15 changes: 14 additions & 1 deletion Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1043,10 +1043,23 @@ extension EPUBNavigatorViewController: EPUBSpreadViewDelegate {
// the application's bars.
var insets = view.window?.safeAreaInsets ?? .zero

if publication.metadata.layout != .fixed {
switch publication.metadata.layout ?? .reflowable {
case .fixed:
// With iPadOS and macOS, we aim to display content edge-to-edge
// since there are no physical notches or Dynamic Island like on the
// iPhone.
if UIDevice.current.userInterfaceIdiom != .phone {
insets = .zero
}

case .reflowable:
let configInset = config.contentInset(for: view.traitCollection.verticalSizeClass)
insets.top = max(insets.top, configInset.top)
insets.bottom = max(insets.bottom, configInset.bottom)

case .scrolled:
// Not supported with EPUB.
break
}

return insets
Expand Down
1 change: 1 addition & 0 deletions Sources/Navigator/EPUB/EPUBNavigatorViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ final class EPUBNavigatorViewModel: Loggable {
|| oldSettings.verticalText != newSettings.verticalText
|| oldSettings.scroll != newSettings.scroll
|| oldSettings.spread != newSettings.spread
|| oldSettings.fit != newSettings.fit

// We don't commit the CSS changes if we invalidate the pagination, as
// the resources will be reloaded anyway.
Expand Down
10 changes: 10 additions & 0 deletions Sources/Navigator/EPUB/Preferences/EPUBPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public struct EPUBPreferences: ConfigurablePreferences {
/// spread).
public var columnCount: ColumnCount?

/// Method for fitting the content of a fixed-layout publication within the
/// viewport.
///
/// - `auto` or `page`: Fit entire page within viewport (default).
/// - `width`: Fit page width, allow vertical scrolling if needed.
public var fit: Fit?

/// Default typeface for the text.
public var fontFamily: FontFamily?

Expand Down Expand Up @@ -97,6 +104,7 @@ public struct EPUBPreferences: ConfigurablePreferences {
public init(
backgroundColor: Color? = nil,
columnCount: ColumnCount? = nil,
fit: Fit? = nil,
fontFamily: FontFamily? = nil,
fontSize: Double? = nil,
fontWeight: Double? = nil,
Expand All @@ -123,6 +131,7 @@ public struct EPUBPreferences: ConfigurablePreferences {
) {
self.backgroundColor = backgroundColor
self.columnCount = columnCount
self.fit = fit
self.fontFamily = fontFamily
self.fontSize = fontSize.map { max($0, 0) }
self.fontWeight = fontWeight?.clamped(to: 0.0 ... 2.5)
Expand Down Expand Up @@ -152,6 +161,7 @@ public struct EPUBPreferences: ConfigurablePreferences {
EPUBPreferences(
backgroundColor: other.backgroundColor ?? backgroundColor,
columnCount: other.columnCount ?? columnCount,
fit: other.fit ?? fit,
fontFamily: other.fontFamily ?? fontFamily,
fontSize: other.fontSize ?? fontSize,
fontWeight: other.fontWeight ?? fontWeight,
Expand Down
12 changes: 12 additions & 0 deletions Sources/Navigator/EPUB/Preferences/EPUBPreferencesEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public final class EPUBPreferencesEditor: StatefulPreferencesEditor<EPUBPreferen
supportedValues: [.auto, .one, .two]
)

/// Method for fitting the content within the viewport.
///
/// Only effective with fixed-layout publications.
public lazy var fit: AnyEnumPreference<Fit> =
enumPreference(
preference: \.fit,
setting: \.fit,
defaultEffectiveValue: defaults.fit ?? .auto,
isEffective: { [layout] _ in layout == .fixed },
supportedValues: [.auto, .page, .width]
)

/// Default typeface for the text.
///
/// Only effective with reflowable publications.
Expand Down
9 changes: 9 additions & 0 deletions Sources/Navigator/EPUB/Preferences/EPUBSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ReadiumShared
public struct EPUBSettings: ConfigurableSettings {
public var backgroundColor: Color?
public var columnCount: ColumnCount
public var fit: Fit
public var fontFamily: FontFamily?
public var fontSize: Double
public var fontWeight: Double?
Expand Down Expand Up @@ -46,6 +47,7 @@ public struct EPUBSettings: ConfigurableSettings {
public init(
backgroundColor: Color?,
columnCount: ColumnCount,
fit: Fit,
fontFamily: FontFamily?,
fontSize: Double,
fontWeight: Double?,
Expand All @@ -72,6 +74,7 @@ public struct EPUBSettings: ConfigurableSettings {
) {
self.backgroundColor = backgroundColor
self.columnCount = columnCount
self.fit = fit
self.fontFamily = fontFamily
self.fontSize = fontSize
self.fontWeight = fontWeight
Expand Down Expand Up @@ -139,6 +142,9 @@ public struct EPUBSettings: ConfigurableSettings {
columnCount: preferences.columnCount
?? defaults.columnCount
?? .auto,
fit: preferences.fit
?? defaults.fit
?? .auto,
fontFamily: preferences.fontFamily,
fontSize: preferences.fontSize
?? defaults.fontSize
Expand Down Expand Up @@ -196,6 +202,7 @@ public struct EPUBSettings: ConfigurableSettings {
/// See `EPUBPreferences`.
public struct EPUBDefaults {
public var columnCount: ColumnCount?
public var fit: Fit?
public var fontSize: Double?
public var fontWeight: Double?
public var hyphens: Bool?
Expand All @@ -218,6 +225,7 @@ public struct EPUBDefaults {

public init(
columnCount: ColumnCount? = nil,
fit: Fit? = nil,
fontSize: Double? = nil,
fontWeight: Double? = nil,
hyphens: Bool? = nil,
Expand All @@ -239,6 +247,7 @@ public struct EPUBDefaults {
wordSpacing: Double? = nil
) {
self.columnCount = columnCount
self.fit = fit
self.fontSize = fontSize
self.fontWeight = fontWeight
self.hyphens = hyphens
Expand Down
Loading