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,87 @@
|
||||
import Foundation
|
||||
|
||||
public enum RDEPUBCFIGenerator {
|
||||
|
||||
public static func makeOffsetCFI(
|
||||
href: String,
|
||||
fileIndex: Int,
|
||||
chapterOffset: Int,
|
||||
fragmentID: String? = nil,
|
||||
sideBias: RDEPUBCFISideBias? = nil,
|
||||
textAssertion: RDEPUBCFITextAssertion? = nil,
|
||||
contentPath: RDEPUBCFIPath? = nil
|
||||
) -> RDEPUBCFI {
|
||||
let packagePath = RDEPUBCFIPath(steps: [
|
||||
RDEPUBCFIStep(index: 6),
|
||||
RDEPUBCFIStep(index: max((fileIndex + 1) * 2, 2), idAssertion: href)
|
||||
])
|
||||
let resolvedContentPath = contentPath ?? RDEPUBCFIPath(steps: [
|
||||
RDEPUBCFIStep(index: 4),
|
||||
RDEPUBCFIStep(index: 2, idAssertion: fragmentID)
|
||||
])
|
||||
return RDEPUBCFI(
|
||||
packagePath: packagePath,
|
||||
contentPath: resolvedContentPath,
|
||||
characterOffset: max(chapterOffset, 0),
|
||||
sideBias: sideBias,
|
||||
textAssertion: textAssertion
|
||||
)
|
||||
}
|
||||
|
||||
public static func makeCFI(
|
||||
href: String,
|
||||
fileIndex: Int,
|
||||
contentPath: RDEPUBCFIPath,
|
||||
characterOffset: Int,
|
||||
sideBias: RDEPUBCFISideBias? = nil,
|
||||
textAssertion: RDEPUBCFITextAssertion? = nil
|
||||
) -> RDEPUBCFI {
|
||||
let packagePath = RDEPUBCFIPath(steps: [
|
||||
RDEPUBCFIStep(index: 6),
|
||||
RDEPUBCFIStep(index: max((fileIndex + 1) * 2, 2), idAssertion: href)
|
||||
])
|
||||
return RDEPUBCFI(
|
||||
packagePath: packagePath,
|
||||
contentPath: contentPath,
|
||||
characterOffset: max(characterOffset, 0),
|
||||
sideBias: sideBias,
|
||||
textAssertion: textAssertion
|
||||
)
|
||||
}
|
||||
|
||||
public static func makeOffsetRangeCFI(
|
||||
href: String,
|
||||
fileIndex: Int,
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
fragmentID: String? = nil,
|
||||
startTextAssertion: RDEPUBCFITextAssertion? = nil,
|
||||
endTextAssertion: RDEPUBCFITextAssertion? = nil,
|
||||
contentPath: RDEPUBCFIPath? = nil
|
||||
) -> RDEPUBCFIRange {
|
||||
precondition(startOffset <= endOffset, "startOffset (\(startOffset)) must be <= endOffset (\(endOffset))")
|
||||
let start = makeOffsetCFI(
|
||||
href: href,
|
||||
fileIndex: fileIndex,
|
||||
chapterOffset: startOffset,
|
||||
fragmentID: fragmentID,
|
||||
sideBias: .before,
|
||||
textAssertion: startTextAssertion,
|
||||
contentPath: contentPath
|
||||
)
|
||||
let end = makeOffsetCFI(
|
||||
href: href,
|
||||
fileIndex: fileIndex,
|
||||
chapterOffset: endOffset,
|
||||
fragmentID: fragmentID,
|
||||
sideBias: .after,
|
||||
textAssertion: endTextAssertion,
|
||||
contentPath: contentPath
|
||||
)
|
||||
let parent = RDEPUBCFI(
|
||||
packagePath: start.packagePath.commonPrefix(with: end.packagePath),
|
||||
contentPath: start.contentPath.commonPrefix(with: end.contentPath)
|
||||
)
|
||||
return RDEPUBCFIRange(parent: parent, start: start, end: end)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user