feat(07): close native text pagination semantics loop

This commit is contained in:
shen
2026-05-22 20:39:26 +08:00
parent 21c8bbb23a
commit d7339aa255
15 changed files with 722 additions and 22 deletions
+37 -1
View File
@@ -51,12 +51,31 @@ final class ViewController: UIViewController {
lines.append("样本验证:\(passedCount)/\(checkedCount) 通过,失败样本:\(titles)")
}
lines.append(contentsOf: matrixLines.prefix(3))
lines.append(contentsOf: diagnosticLines.prefix(2))
lines.append(contentsOf: prioritizedDiagnosticLines())
if !rerunHint.isEmpty {
lines.append(rerunHint)
}
return lines.joined(separator: "\n")
}
private func prioritizedDiagnosticLines() -> [String] {
var selected: [String] = []
if let semanticLine = diagnosticLines.first(where: { $0.contains("属性闭环诊断") }) {
selected.append(semanticLine)
}
if let paginationLine = diagnosticLines.first(where: { $0.contains("分页诊断") && !selected.contains($0) }) {
selected.append(paginationLine)
}
if selected.count < 2 {
for line in diagnosticLines where !selected.contains(line) {
selected.append(line)
if selected.count == 2 {
break
}
}
}
return selected
}
}
private let statusLabel: UILabel = {
@@ -346,6 +365,9 @@ final class ViewController: UIViewController {
if let paginationSummary = makePaginationSummary(diagnostics, title: book.title) {
summaryLines.append("分页诊断:\(paginationSummary)")
}
if let semanticSummary = builder.phase7SemanticSummary(title: book.title) {
summaryLines.append("属性闭环诊断:\(semanticSummary)")
}
if let restoreSummary = makeRestoreSummary(
parser: parser,
publication: publication,
@@ -438,6 +460,9 @@ final class ViewController: UIViewController {
guard !diagnostics.isEmpty else { return nil }
let attachmentPages = diagnostics.reduce(0) { $0 + $1.attachmentPageCount }
let semanticBreakPages = diagnostics.reduce(0) { $0 + $1.blockAdjustedPageCount }
let blockKinds = uniqueValues(diagnostics.flatMap(\.blockKinds))
let semanticHints = uniqueValues(diagnostics.flatMap(\.semanticHints))
let attachmentPlacements = uniqueValues(diagnostics.flatMap(\.attachmentPlacements))
let breakReasonCounts = diagnostics
.flatMap(\.breakReasons)
.reduce(into: [RDEPUBTextPageBreakReason: Int]()) { counts, reason in
@@ -460,6 +485,9 @@ final class ViewController: UIViewController {
"章节 \(diagnostics.count)",
"attachment 页 \(attachmentPages)",
"semantic break 页 \(semanticBreakPages)",
blockKinds.isEmpty ? nil : "block kinds [\(blockKinds.map(\.rawValue).joined(separator: ","))]",
semanticHints.isEmpty ? nil : "hints [\(semanticHints.map(\.rawValue).joined(separator: ","))]",
attachmentPlacements.isEmpty ? nil : "placements [\(attachmentPlacements.map(\.rawValue).joined(separator: ","))]",
orderedReasons.isEmpty ? nil : "reasons [\(orderedReasons)]"
].compactMap { $0 }
if let note {
@@ -547,6 +575,14 @@ final class ViewController: UIViewController {
].joined(separator: " · ")
}
nonisolated private static func uniqueValues<T: Equatable>(_ values: [T]) -> [T] {
values.reduce(into: [T]()) { result, value in
if !result.contains(value) {
result.append(value)
}
}
}
private func openBook(_ book: DemoBook) {
let controller = RDURLReaderController(bookURL: book.fileURL)
controller.title = book.title