ReadViewSDK/Sources/RDReaderView/EPUBUI/Settings/RDEPUBReaderSettings.swift
shen 1efb9d172f feat(reader): 增强阅读器功能与 UI 测试支持
- 新增字体选择(系统/宋体/圆体/等宽)与暗色图片柔化配置
- 文本选择改为自定义手势+操作栏(拷贝/高亮/批注)
- 添加 accessibilityIdentifier 支持自动化 UI 测试
- 新增 UITests 覆盖阅读器打开/关闭、工具栏、设置面板、批注等
- 添加 Demo 测试用 EPUB 书源(宝山辽墓材料与释读)
- 新增文档:UI 自动化测试、功能开发计划、阅读器规划
2026-05-31 23:56:54 +08:00

193 lines
6.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
// MARK: -
///
/// RDReaderView.DisplayType
public enum RDEPUBReaderDisplayMode: String, Codable, Equatable {
/// 仿
case pageCurl
///
case horizontalScroll
///
case verticalScroll
///
case horizontalCoverScroll
/// DisplayType UI DisplayMode
init(displayType: RDReaderView.DisplayType) {
switch displayType {
case .pageCurl:
self = .pageCurl
case .horizontalScroll:
self = .horizontalScroll
case .verticalScroll:
self = .verticalScroll
}
}
/// RDReaderView DisplayType
/// horizontalCoverScroll horizontalScroll
var displayType: RDReaderView.DisplayType {
switch self {
case .pageCurl:
return .pageCurl
case .horizontalScroll, .horizontalCoverScroll:
return .horizontalScroll
case .verticalScroll:
return .verticalScroll
}
}
}
// MARK: -
///
/// RDEPUBReaderTheme
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
}
}
///
/// nil
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
}
}
}
// MARK: -
///
///
///
public struct RDEPUBReaderSettings: Codable, Equatable {
// MARK:
/// 0.0 ~ 1.0nil 使
public var brightness: CGFloat?
/// ptnil 使
public var fontSize: CGFloat?
/// nil 使
public var fontChoice: RDEPUBReaderFontChoice?
/// nil 使
public var lineHeightMultiple: CGFloat?
/// nil 使
public var numberOfColumns: Int?
/// nil 使
public var displayMode: RDEPUBReaderDisplayMode?
/// nil 使
public var themePreset: RDEPUBReaderThemePreset?
/// nil
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
}
///
/// nil
/// - Parameter configuration: RDEPUBReaderConfiguration.default
/// - Returns:
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
}
///
/// 0.0 ~ 1.0
/// - Parameters:
/// - configuration:
/// - brightness:
/// - Returns:
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)
)
}
}