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
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
extension RDEPUBReaderController {
|
||||
|
||||
func currentLayoutContext() -> RDEPUBNavigatorLayoutContext {
|
||||
readerContext.currentLayoutContext()
|
||||
}
|
||||
|
||||
func currentPreferences() -> RDEPUBPreferences {
|
||||
readerContext.currentPreferences()
|
||||
}
|
||||
|
||||
func currentTextPageSize() -> CGSize {
|
||||
readerContext.currentTextPageSize()
|
||||
}
|
||||
|
||||
func currentTextRenderStyle() -> RDEPUBTextRenderStyle {
|
||||
readerContext.currentTextRenderStyle()
|
||||
}
|
||||
|
||||
func currentTextLayoutConfig(pageSize: CGSize) -> RDEPUBTextLayoutConfig {
|
||||
readerContext.currentTextLayoutConfig(pageSize: pageSize)
|
||||
}
|
||||
|
||||
func resolvedTextRenderer() -> RDEPUBTextRenderer {
|
||||
readerContext.resolvedTextRenderer()
|
||||
}
|
||||
|
||||
func ensurePaginationHostView() -> UIView {
|
||||
let viewportSize = currentLayoutContext().viewportSize
|
||||
let hostFrame = CGRect(x: -viewportSize.width - 32, y: 0, width: viewportSize.width, height: viewportSize.height)
|
||||
if paginationHostView.superview == nil {
|
||||
view.addSubview(paginationHostView)
|
||||
view.sendSubviewToBack(paginationHostView)
|
||||
}
|
||||
paginationHostView.frame = hostFrame
|
||||
return paginationHostView
|
||||
}
|
||||
|
||||
func request(for pageIndex: Int) -> RDEPUBRenderRequest? {
|
||||
guard let publication, activePages.indices.contains(pageIndex) else {
|
||||
return nil
|
||||
}
|
||||
let page = activePages[pageIndex]
|
||||
let pendingLocation = readingSession?.pendingLocation(forPageNumber: pageIndex + 1, spineIndex: page.spineIndex)
|
||||
let pendingHighlightRangeInfo = readingSession?.pendingHighlightRangeInfo(
|
||||
forPageNumber: pageIndex + 1,
|
||||
spineIndex: page.spineIndex
|
||||
)
|
||||
var preferences = currentPreferences()
|
||||
if publication.layout == .fixed, readerView.pagesPerScreen == 2 {
|
||||
// 横屏双页:左右页各让出 5pt,拼出 10pt 的书脊间距
|
||||
preferences.fixedContentInset.left += 5
|
||||
preferences.fixedContentInset.right += 5
|
||||
}
|
||||
return preferences.renderRequest(
|
||||
for: page,
|
||||
publication: publication,
|
||||
viewportSize: currentLayoutContext().viewportSize,
|
||||
targetLocation: pendingLocation,
|
||||
targetHighlightRangeInfo: pendingHighlightRangeInfo,
|
||||
highlights: highlights(for: page),
|
||||
searchPresentation: searchPresentation(for: page)
|
||||
)
|
||||
}
|
||||
|
||||
func fallbackLocation(for pageIndex: Int) -> RDEPUBLocation? {
|
||||
guard activePages.indices.contains(pageIndex) else { return nil }
|
||||
return readingSession?.fallbackLocation(for: activePages[pageIndex], bookIdentifier: currentBookIdentifier)
|
||||
}
|
||||
|
||||
private func highlights(for page: EPUBPage) -> [RDEPUBHighlight] {
|
||||
guard let publication else { return [] }
|
||||
if let spread = page.fixedSpread {
|
||||
let hrefs = Set(spread.resources.compactMap { publication.resourceResolver.normalizedHref($0.href) })
|
||||
return activeHighlights.filter { highlight in
|
||||
guard let normalizedHref = publication.resourceResolver.normalizedHref(highlight.location.href) else {
|
||||
return false
|
||||
}
|
||||
return hrefs.contains(normalizedHref)
|
||||
}
|
||||
}
|
||||
|
||||
guard publication.spine.indices.contains(page.spineIndex) else { return [] }
|
||||
let href = publication.spine[page.spineIndex].href
|
||||
let normalizedHref = publication.resourceResolver.normalizedHref(href)
|
||||
return activeHighlights.filter { highlight in
|
||||
publication.resourceResolver.normalizedHref(highlight.location.href) == normalizedHref
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user