chore: checkpoint current milestone work
This commit is contained in:
@@ -24,25 +24,40 @@ public final class RDPlainTextBookBuilder {
|
||||
let rendered = try renderer.renderChapter(html: html, baseURL: nil, style: style)
|
||||
|
||||
let content = NSMutableAttributedString(attributedString: rendered.attributedString)
|
||||
let pageRanges = content.length > 0 ? content.ss_pageRanges(size: pageSize) : []
|
||||
let effectivePageRanges = pageRanges.isEmpty && content.length > 0
|
||||
? [NSRange(location: 0, length: content.length)]
|
||||
: pageRanges
|
||||
let layoutFrames = content.length > 0 ? content.rd_paginatedFrames(size: pageSize) : []
|
||||
let effectiveFrames = layoutFrames.isEmpty && content.length > 0
|
||||
? [
|
||||
RDEPUBTextLayoutFrame(
|
||||
contentRange: NSRange(location: 0, length: content.length),
|
||||
breakReason: .chapterEnd,
|
||||
blockRange: nil,
|
||||
attachmentRanges: [],
|
||||
attachmentKinds: [],
|
||||
trailingFragmentID: nil,
|
||||
diagnostics: [
|
||||
"page break: chapterEnd",
|
||||
"page range: \(NSStringFromRange(NSRange(location: 0, length: content.length)))"
|
||||
]
|
||||
)
|
||||
]
|
||||
: layoutFrames
|
||||
|
||||
let href = "chapter_\(index).xhtml"
|
||||
let pages = effectivePageRanges.enumerated().map { localPageIndex, range in
|
||||
RDEPUBTextPage(
|
||||
let pages = effectiveFrames.enumerated().map { localPageIndex, frame in
|
||||
let range = frame.contentRange
|
||||
return RDEPUBTextPage(
|
||||
absolutePageIndex: flatPages.count + localPageIndex,
|
||||
chapterIndex: index,
|
||||
spineIndex: index,
|
||||
href: href,
|
||||
chapterTitle: spec.title ?? "第 \(index + 1) 章",
|
||||
pageIndexInChapter: localPageIndex,
|
||||
totalPagesInChapter: effectivePageRanges.count,
|
||||
totalPagesInChapter: effectiveFrames.count,
|
||||
content: content.attributedSubstring(from: range),
|
||||
contentRange: range,
|
||||
pageStartOffset: range.location,
|
||||
pageEndOffset: range.location + max(range.length - 1, 0)
|
||||
pageEndOffset: range.location + max(range.length - 1, 0),
|
||||
metadata: frame.metadata
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,6 +69,7 @@ public final class RDPlainTextBookBuilder {
|
||||
title: spec.title ?? "第 \(index + 1) 章",
|
||||
attributedContent: content.copy() as! NSAttributedString,
|
||||
fragmentOffsets: [:],
|
||||
pageBreakReasons: pages.map(\.metadata.breakReason),
|
||||
pages: pages
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user