Files
ReadViewSDK/Sources/RDReaderView/EPUBTextRendering/Pagination/RDEPUBTextLayouter.swift
T

27 lines
1.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import CoreText
import UIKit
#if canImport(DTCoreText)
import DTCoreText
#endif
/// CoreText 分页引擎 Facade:将富文本按页面尺寸拆分为多帧(每帧对应一页)。
///
/// 内部委托给三个组件:
/// - RDEPUBCoreTextPageFrameFactory — 帧创建、属性查询、诊断
/// - RDEPUBPageBreakPolicy — 分页规则(语义保护、keepWithNext
/// - RDEPUBChapterPageCounter — 顶层分页循环编排
struct RDEPUBTextLayouter {
private let counter: RDEPUBChapterPageCounter
init(attributedString: NSAttributedString, pageSize: CGSize, config: RDEPUBTextLayoutConfig = .default) {
let factory = RDEPUBCoreTextPageFrameFactory(attributedString: attributedString, pageSize: pageSize, config: config)
self.counter = RDEPUBChapterPageCounter(factory: factory)
}
/// 执行分页,返回布局帧列表(每帧对应一页)。
func layoutFrames(fragmentOffsets: [String: Int] = [:]) -> [RDEPUBTextLayoutFrame] {
counter.layoutFrames(fragmentOffsets: fragmentOffsets)
}
}