ReadViewSDK/Sources/RDReaderView/EPUBCore/RDEPUBRenderRequest.swift
shen 54798ba578 refactor: 添加中文注释 + 优化模块结构
- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级)
- 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行)
- 根目录翻页容器文件移入 ReaderView/ 目录
- Resources/ 移入 EPUBCore/Resources/(与使用者归属一致)
- RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖)
- RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层)
- 更新 podspec 资源路径
2026-05-25 10:19:14 +08:00

173 lines
5.7 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.

//
// RDEPUBRenderRequest.swift
// RDReaderView
//
// EPUBCore
// PresentationStyle/RenderRequest
// Fit Spread SpreadMode
// RDEPUBPreferences RDEPUBWebView
//
import UIKit
///
/// - auto:
/// - page:
/// - width:
public enum RDEPUBFixedLayoutFit: String, Codable {
case auto
case page
case width
}
/// Spread
/// - automatic:
/// - always:
/// - never:
public enum RDEPUBFixedLayoutSpreadMode: String, Codable {
case automatic
case always
case never
}
/// WebView Paginator
/// RDEPUBPreferences
public struct RDEPUBPresentationStyle: Equatable {
///
public var viewportSize: CGSize
///
public var contentInsets: UIEdgeInsets
/// pt
public var fontSize: CGFloat
/// 1.0
public var lineHeightMultiple: CGFloat
/// CSS "#FFFFFF"
public var themeBackgroundColor: String?
/// CSS "#000000"
public var themeTextColor: String?
public init(
viewportSize: CGSize,
contentInsets: UIEdgeInsets,
fontSize: CGFloat,
lineHeightMultiple: CGFloat,
themeBackgroundColor: String? = nil,
themeTextColor: String? = nil
) {
self.viewportSize = viewportSize
self.contentInsets = contentInsets
self.fontSize = fontSize
self.lineHeightMultiple = lineHeightMultiple
self.themeBackgroundColor = themeBackgroundColor
self.themeTextColor = themeTextColor
}
}
/// reflowable spine
public struct RDEPUBReflowableRenderRequest: Equatable {
/// spine
public var spineIndex: Int
///
public var href: String
///
public var pageIndex: Int
///
public var totalPagesInChapter: Int
///
public var presentation: RDEPUBPresentationStyle
///
public var targetLocation: RDEPUBLocation?
///
public var highlights: [RDEPUBHighlight]
///
public var searchPresentation: RDEPUBSearchPresentation?
public init(
spineIndex: Int,
href: String,
pageIndex: Int,
totalPagesInChapter: Int,
presentation: RDEPUBPresentationStyle,
targetLocation: RDEPUBLocation? = nil,
highlights: [RDEPUBHighlight] = [],
searchPresentation: RDEPUBSearchPresentation? = nil
) {
self.spineIndex = spineIndex
self.href = href
self.pageIndex = pageIndex
self.totalPagesInChapter = totalPagesInChapter
self.presentation = presentation
self.targetLocation = targetLocation
self.highlights = highlights
self.searchPresentation = searchPresentation
}
}
/// fixed spread
public struct RDEPUBFixedRenderRequest: Equatable {
/// spread 1-2
public var spread: EPUBFixedSpread
///
public var viewportSize: CGSize
///
public var contentInset: UIEdgeInsets
/// CSS
public var backgroundColorCSS: String?
/// auto/page/width
public var fit: RDEPUBFixedLayoutFit
///
public var searchPresentation: RDEPUBSearchPresentation?
public init(
spread: EPUBFixedSpread,
viewportSize: CGSize,
contentInset: UIEdgeInsets,
backgroundColorCSS: String? = nil,
fit: RDEPUBFixedLayoutFit = .page,
searchPresentation: RDEPUBSearchPresentation? = nil
) {
self.spread = spread
self.viewportSize = viewportSize
self.contentInset = contentInset
self.backgroundColorCSS = backgroundColorCSS
self.fit = fit
self.searchPresentation = searchPresentation
}
}
///
/// RDEPUBWebView
public enum RDEPUBRenderRequest: Equatable {
///
case reflowable(RDEPUBReflowableRenderRequest)
///
case fixed(RDEPUBFixedRenderRequest)
///
public var isFixedLayout: Bool {
if case .fixed = self {
return true
}
return false
}
/// spine
public var primarySpineIndex: Int {
switch self {
case .reflowable(let request):
return request.spineIndex
case .fixed(let request):
return request.spread.primaryResource.spineIndex
}
}
///
public var primaryHref: String {
switch self {
case .reflowable(let request):
return request.href
case .fixed(let request):
return request.spread.primaryResource.href
}
}
}