ReadViewSDK/Sources/RDEpubReaderView/EPUBUI/Settings/RDEPUBReaderSettings.swift
shenlei d7fcda345d refactor: rename RDReaderView -> RDEpubReaderView, update pod config and docs
- Rename source module from RDReaderView to RDEpubReaderView
- Move all source files from Sources/RDReaderView/ to Sources/RDEpubReaderView/
- Update podspec: RDReaderView.podspec -> RDEpubReaderView.podspec
- Update Podfile, demo project, and CocoaPods config for new pod name
- Delete old RDReaderView pod support files from ReadViewDemo/Pods
- Add new RDEpubReaderView pod support files
- Update documentation (API ref, architecture, UML, conventions, etc.)
- Add FixedLayoutRotationTests
- Update .gitignore: exclude .DS_Store, manual unpack backups, _ssoft-output
2026-07-10 19:44:53 +09:00

161 lines
4.1 KiB
Swift

import UIKit
public enum RDEPUBReaderDisplayMode: String, Codable, Equatable {
case pageCurl
case horizontalScroll
case verticalScroll
case horizontalCoverScroll
init(displayType: RDEpubReaderView.DisplayType) {
switch displayType {
case .pageCurl:
self = .pageCurl
case .horizontalScroll:
self = .horizontalScroll
case .verticalScroll:
self = .verticalScroll
}
}
var displayType: RDEpubReaderView.DisplayType {
switch self {
case .pageCurl:
return .pageCurl
case .horizontalScroll, .horizontalCoverScroll:
return .horizontalScroll
case .verticalScroll:
return .verticalScroll
}
}
}
public enum RDEPUBReaderThemePreset: String, Codable, CaseIterable, Equatable {
case light
case yellow
case green
case pink
case blue
case dark
public var theme: RDEPUBReaderTheme {
switch self {
case .light:
return .light
case .yellow:
return .yellow
case .green:
return .green
case .pink:
return .pink
case .blue:
return .blue
case .dark:
return .dark
}
}
public init?(theme: RDEPUBReaderTheme) {
switch theme {
case .light:
self = .light
case .yellow:
self = .yellow
case .green:
self = .green
case .pink:
self = .pink
case .blue:
self = .blue
case .dark:
self = .dark
default:
return nil
}
}
}
public struct RDEPUBReaderSettings: Codable, Equatable {
public var brightness: CGFloat?
public var fontSize: CGFloat?
public var fontChoice: RDEPUBReaderFontChoice?
public var lineHeightMultiple: CGFloat?
public var numberOfColumns: Int?
public var displayMode: RDEPUBReaderDisplayMode?
public var themePreset: RDEPUBReaderThemePreset?
public init(
brightness: CGFloat? = nil,
fontSize: CGFloat? = nil,
fontChoice: RDEPUBReaderFontChoice? = nil,
lineHeightMultiple: CGFloat? = nil,
numberOfColumns: Int? = nil,
displayMode: RDEPUBReaderDisplayMode? = nil,
themePreset: RDEPUBReaderThemePreset? = nil
) {
self.brightness = brightness
self.fontSize = fontSize
self.fontChoice = fontChoice
self.lineHeightMultiple = lineHeightMultiple
self.numberOfColumns = numberOfColumns
self.displayMode = displayMode
self.themePreset = themePreset
}
public func applying(to configuration: RDEPUBReaderConfiguration) -> RDEPUBReaderConfiguration {
var resolvedConfiguration = configuration
if let fontSize {
resolvedConfiguration.fontSize = fontSize
}
if let fontChoice {
resolvedConfiguration.fontChoice = fontChoice
}
if let lineHeightMultiple {
resolvedConfiguration.lineHeightMultiple = lineHeightMultiple
}
if let numberOfColumns {
resolvedConfiguration.numberOfColumns = max(1, numberOfColumns)
}
if let displayMode {
resolvedConfiguration.displayType = displayMode.displayType
}
if let themePreset {
resolvedConfiguration.theme = themePreset.theme
}
return resolvedConfiguration
}
public static func capture(
configuration: RDEPUBReaderConfiguration,
brightness: CGFloat
) -> RDEPUBReaderSettings {
RDEPUBReaderSettings(
brightness: max(0, min(1, brightness)),
fontSize: configuration.fontSize,
fontChoice: configuration.fontChoice,
lineHeightMultiple: configuration.lineHeightMultiple,
numberOfColumns: configuration.numberOfColumns,
displayMode: RDEPUBReaderDisplayMode(displayType: configuration.displayType),
themePreset: RDEPUBReaderThemePreset(theme: configuration.theme)
)
}
}