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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. Take a look
* `blendImages`, `darkenImages`, `invertGaiji` and `invertImages` filter the images, [see the user guide](docs/Guides/Navigator/Preferences.md#image-filters).
* `fontWidth` changes the width of the glyphs, with the fonts supporting it.
* `noRuby` hides the ruby (furigana) annotations in CJK publications.
* New `settings(for:)` API on the navigators (`Configurable`) to get the settings they would apply with given preferences, without submitting them. Check which settings apply to the current publication with `isApplicable(_:)`, e.g. to disable the controls of a settings screen, [see the user guide](docs/Guides/Navigator/Preferences.md#build-a-user-settings-interface).
* Japanese publications following the EBPAJ EPUB 3 production guide are now rendered with the iOS fonts, such as Hiragino Mincho and Hiragino Sans, instead of the Windows fonts they reference.

### Changed
Expand All @@ -33,18 +34,20 @@ All notable changes to this project will be documented in this file. Take a look
* `columnCount` is now an `Int?`, where `nil` means an automatic number of columns.
* `pageMargins` is now a factor applied to the minimal margins on each side of the lines.
* The EPUB navigator now adapts the number of columns and the length of the lines to the screen and font sizes:
* The lines are limited to a maximal length by default. Set `EPUBDefaults.maximalLineLength` to `nil` to let them take all the available width.
* The lines are limited to a maximal length by default. Set `maximalLineLength` to `.infinity` to let them take all the available width.
* In automatic mode (`columnCount = nil`), as many columns as the screen can hold are displayed, instead of at most two.
* The line lengths follow the font size, so a larger font displays fewer columns with about the same number of characters per line.
* On foldable devices, one column is displayed on each side of the hinge.
* Removed the OpenDyslexic, AccessibleDfA and iA Writer Duospace fonts bundled with the toolkit, [see the migration guide](docs/Migration%20Guide.md#bundled-fonts).
* SVG documents in the reading order of an EPUB are now rendered as fixed-layout pages, even in a reflowable publication.
* The `letterSpacing` EPUB preference is no longer halved: `1.0` is now `1rem` instead of `0.5rem`, like in the other Readium toolkits, [see the migration guide](docs/Migration%20Guide.md#other-preference-changes).

### Removed

#### Navigator

* The `Preferences` types and their values are no longer `Codable`. Persist your own settings model and derive the preferences from it instead, [see the migration guide](docs/Migration%20Guide.md#preferences-are-no-longer-codable).
* The preferences editors (e.g. `EPUBPreferencesEditor`) are removed. Edit the preferences in your own settings model, and check which settings apply with `navigator.settings(for:)` and `isApplicable(_:)`, [see the migration guide](docs/Migration%20Guide.md#the-preferences-editors-are-removed).

### Fixed

Expand Down
16 changes: 9 additions & 7 deletions Sources/Navigator/Audiobook/AudioNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1095,10 +1095,7 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
public private(set) var settings: AudioSettings

public func submitPreferences(_ preferences: AudioPreferences) {
settings = AudioSettings(
preferences: preferences,
defaults: config.defaults
)
settings = settings(for: preferences)

player.volume = Float(settings.volume)

Expand All @@ -1109,12 +1106,17 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
}
}

public func editor(of preferences: AudioPreferences) -> AudioPreferencesEditor {
AudioPreferencesEditor(
initialPreferences: preferences,
public func settings(for preferences: AudioPreferences) -> AudioSettings {
AudioSettings(
preferences: preferences,
defaults: config.defaults
)
}

@available(*, unavailable, message: "Get the settings with settings(for:) and check AudioSettings.isApplicable(_:), see the migration guide")
public func editor(of preferences: AudioPreferences) -> AudioPreferencesEditor {
fatalError()
}
}

private extension MediaPlaybackState {
Expand Down
11 changes: 8 additions & 3 deletions Sources/Navigator/Audiobook/Preferences/AudioPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import ReadiumShared
public struct AudioPreferences: ConfigurablePreferences, Sendable {
public static let empty: AudioPreferences = .init()

/// Volume of playback, from 0.0 to 1.0.
/// Volume of playback, from `0.0` to `1.0`.
///
/// Accepted range: `0.0...1.0`, other values are a programming error.
/// Suggested step: `0.1`.
public var volume: Double? {
willSet { precondition(newValue == nil || 0 ... 1 ~= newValue!) }
}

/// Speed of playback.
/// Normal is 1.0.
/// Speed of playback, greater than or equal to `0.0`. Normal is `1.0`.
///
/// Accepted range: `0.0...`, negative values are a programming error.
/// Suggested range: `0.1...6.0`, with a step of `0.1`.
public var speed: Double? {
willSet { precondition(newValue == nil || newValue! >= 0) }
}
Expand Down

This file was deleted.

16 changes: 15 additions & 1 deletion Sources/Navigator/Audiobook/Preferences/AudioSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public struct AudioSettings: ConfigurableSettings, Sendable {
public let volume: Double
public let speed: Double

init(preferences: AudioPreferences, defaults: AudioDefaults) {
/// Resolves the settings applied by the audio navigator with the given
/// `preferences`.
///
/// A preference takes precedence over the `defaults`.
///
/// - Parameters:
/// - defaults: Default values of the navigator, given in its
/// `AudioNavigator.Configuration`.
init(preferences: AudioPreferences, defaults: AudioDefaults = AudioDefaults()) {
volume = preferences.volume
?? defaults.volume
?? 1.0
Expand All @@ -23,6 +31,12 @@ public struct AudioSettings: ConfigurableSettings, Sendable {
?? defaults.speed
?? 1.0
}

/// Every audio setting always applies, see
/// `ConfigurableSettings.isApplicable(_:)`.
public func isApplicable(_ setting: PartialKeyPath<AudioSettings>) -> Bool {
true
}
}

/// Default setting values for the audio navigator.
Expand Down
22 changes: 12 additions & 10 deletions Sources/Navigator/EPUB/CSS/LayoutResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class LayoutResolver {
columnCount: Int?,
optimalLineLength: Double,
minimalLineLength: Double?,
maximalLineLength: Double?,
maximalLineLength: Double,
pageMargins: Double,
fontScale: Double,
viewportSize: CGSize,
Expand All @@ -107,7 +107,7 @@ final class LayoutResolver {
// The parameters are factors, these lengths are in points.
let optimalLength = baseOptimalLineLength * optimalLineLength * fontScale
let minLength = minimalLineLength.map { baseMinLineLength * $0 * fontScale }
let maxLength = maximalLineLength.map { baseMaxLineLength * $0 * fontScale }
let maxLength = baseMaxLineLength * maximalLineLength * fontScale
let insetsMargins = verticalText
? max(insets.top, insets.bottom)
: max(insets.left, insets.right)
Expand Down Expand Up @@ -145,15 +145,17 @@ final class LayoutResolver {
columnLength - min(margins, columnLength / 2) * 2
}

/// Returns the `available` length, limited to `maxLength` if any.
private func capped(_ available: Double, at maxLength: Double?) -> Double {
min(available, maxLength ?? available)
/// Returns the `available` length, limited to `maxLength`.
///
/// An infinite `maxLength` (no limit) gives the `available` length.
private func capped(_ available: Double, at maxLength: Double) -> Double {
maxLength < available ? maxLength : available
}

private func scrolledLayout(
viewportLength: Double,
margins: Double,
maxLength: Double?
maxLength: Double
) -> Layout {
let available = availableLength(in: viewportLength, margins: margins)
let lineLength = capped(available, at: maxLength)
Expand All @@ -169,7 +171,7 @@ final class LayoutResolver {
requestedColCount: Int?,
margins: Double,
optimalLength: Double,
maxLength: Double?,
maxLength: Double,
minLength: Double?,
hingeWidth: Double?
) -> Layout {
Expand Down Expand Up @@ -207,7 +209,7 @@ final class LayoutResolver {
margins: Double,
optimalLength: Double,
viewportWidth: Double,
maxLength: Double?
maxLength: Double
) -> Layout {
let optimalLength = min(optimalLength, viewportWidth)
guard optimalLength > 0 else {
Expand Down Expand Up @@ -243,7 +245,7 @@ final class LayoutResolver {
hingeWidth: Double,
margins: Double,
viewportWidth: Double,
maxLength: Double?
maxLength: Double
) -> Layout? {
let halfHinge = max(hingeWidth, 0) / 2
let sideWidth = viewportWidth / 2
Expand Down Expand Up @@ -274,7 +276,7 @@ final class LayoutResolver {
margins: Double,
viewportWidth: Double,
minLength: Double?,
maxLength: Double?
maxLength: Double
) -> Layout {
let available = availableLength(in: viewportWidth / Double(colCount), margins: margins)

Expand Down
10 changes: 4 additions & 6 deletions Sources/Navigator/EPUB/CSS/ReadiumCSS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ struct ReadiumCSS {
}

extension ReadiumCSS {
// Default colors of the Readium CSS stylesheets, used when the matching
// user colors are unset and the publication doesn't have its own.
static let defaultTextColor = Color(rawValue: 0x121212)
/// Default background color of the Readium CSS stylesheets, used when the
/// user background color is unset and the publication doesn't have its
/// own.
static let defaultBackgroundColor = Color(rawValue: 0xFFFFFF)
static let defaultLinkColor = Color(rawValue: 0x0000EE)
static let defaultVisitedColor = Color(rawValue: 0x551A8B)
}

extension ReadiumCSS {
Expand Down Expand Up @@ -112,7 +110,7 @@ extension ReadiumCSS {
paraSpacing: settings.paragraphSpacing.map { CSSRemLength($0) },
paraIndent: settings.paragraphIndent.map { CSSRemLength($0) },
wordSpacing: settings.wordSpacing.map { CSSRemLength($0) },
letterSpacing: settings.letterSpacing.map { CSSRemLength($0 / 2) },
letterSpacing: settings.letterSpacing.map { CSSRemLength($0) },
bodyHyphens: settings.hyphens.map { $0 ? .auto : .none },
ligatures: settings.ligatures.map { $0 ? .common : .none },
a11yNormalize: settings.textNormalization,
Expand Down
17 changes: 10 additions & 7 deletions Sources/Navigator/EPUB/EPUBLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import ReadiumShared
/// The set of EPUB layouts used by the resources of a reading order.
///
/// A publication can mix reflowable and fixed-layout resources, so knowing
/// which layouts are actually rendered is what determines whether a preference
/// is effective.
struct EPUBLayouts {
/// Layout used by the resources which don't override it.
let `default`: EPUBLayout
/// which layouts are actually rendered is what determines whether a setting
/// applies.
struct EPUBLayouts: Hashable, Sendable {
/// Layouts of a reading order containing only reflowable resources.
static let reflowable = EPUBLayouts(layouts: [.reflowable])

private let layouts: Set<EPUBLayout>

init(readingOrder: [Link], metadata: Metadata) {
`default` = metadata.epubLayout
layouts = Set(readingOrder.map { metadata.epubLayout(of: $0) })
self.init(layouts: Set(readingOrder.map { metadata.epubLayout(of: $0) }))
}

private init(layouts: Set<EPUBLayout>) {
self.layouts = layouts
}

/// Indicates whether the reading order contains at least one resource
Expand Down
7 changes: 6 additions & 1 deletion Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,13 @@ open class EPUBNavigatorViewController: InputObservableViewController,
delegate?.navigator(self, presentationDidChange: presentation)
}

public func settings(for preferences: EPUBPreferences) -> EPUBSettings {
viewModel.settings(for: preferences)
}

@available(*, unavailable, message: "Get the settings with settings(for:) and check EPUBSettings.isApplicable(_:), see the migration guide")
public func editor(of preferences: EPUBPreferences) -> EPUBPreferencesEditor {
viewModel.editor(of: preferences)
fatalError()
}

/// Applies user settings that require native configuration instead of
Expand Down
Loading
Loading