2.4 KiB
2.4 KiB
Phase 6: 页面几何与交互命中层 - Patterns
Reusable Patterns
Offset continuity is already the compatibility contract
Sources/RDReaderView/EPUBTextRendering/RDEPUBTextBookBuilder.swiftandSources/RDReaderView/LegacyRDReaderController/RDEPUBTextPaging.swiftboth preservepageStartOffset,pageEndOffset, andfragmentOffsets.Sources/RDReaderView/EPUBCore/RDEPUBReadingModels.swiftkeepsRDEPUBTextOffsetRangeInfoas the absolute-offset payload used by selection and highlight consumers.- Phase 6 should keep that contract intact even after a geometry overlay is introduced.
The layouter already knows more than the view layer
Sources/RDReaderView/EPUBTextRendering/RDEPUBTextLayouter.swiftalready determinesblockRange,attachmentRanges,attachmentKinds,breakReason, andtrailingFragmentID.- That makes the layouter the right place to enrich
RDEPUBTextLayoutFramewith queryable page geometry instead of re-deriving page rules insideRDEPUBTextContentView.
Reader coordination already belongs to the controller
Sources/RDReaderView/EPUBUI/RDEPUBReaderController.swiftalready owns selection persistence, current-location updates, highlight creation, search state, and repagination.- Any new geometry-backed selection flow should plug into the controller rather than creating a second reader state owner.
Content view should become a thin host
Sources/RDReaderView/EPUBUI/RDEPUBTextContentView.swiftcurrently mixes display, selection, highlight painting, and offset conversion.- For this phase, the safest direction is to let the view host text plus an overlay and keep the selection model conversion in one place.
Closest Existing Analogs
RDEPUBTextLayoutFrameis the natural home for page geometry metadata.RDEPUBTextBookBuilderis the natural place to lift geometry results into page-level book state.RDEPUBReaderControlleris the natural adapter layer for user interactions and persistence.RDEPUBTextContentViewis the natural host for an overlay layer because it already owns the page view composition.
Design Guardrails
- Do not move fixed/interactive EPUB off
WKWebView. - Do not change
RDReaderView. - Do not break the existing offset-based consumers while introducing geometry queries.
- Do not let search/highlight/tap-locate become separate geometry implementations; they should reuse the same page geometry API later.