feat: EPUB阅读器搜索、注释、CFI模块及大书远距跳转优化
- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
This commit is contained in:
@@ -1,25 +1,15 @@
|
||||
// RDEPUBFixedLayoutTemplate.swift
|
||||
// 固定版式(Fixed Layout)HTML 模板生成器
|
||||
// 根据渲染请求和 Publication 信息,将 iframe 拼装到 HTML 模板中,
|
||||
// 生成适配视口尺寸和内边距的固定版式页面 HTML。
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 固定版式模板生成器,负责将 spine 资源渲染为 iframe 嵌套的 HTML 页面
|
||||
enum RDEPUBFixedLayoutTemplate {
|
||||
/// 根据渲染请求和 Publication 生成固定版式页面的完整 HTML
|
||||
/// - Parameters:
|
||||
/// - request: 固定版式渲染请求(含 spread、视口尺寸、内边距、适配模式等)
|
||||
/// - publication: EPUB 出版物,用于解析资源 URL
|
||||
/// - Returns: 完整的 HTML 字符串
|
||||
|
||||
static func html(for request: RDEPUBFixedRenderRequest, publication: RDEPUBPublication) -> String {
|
||||
// 遍历 spread 中的每个资源,生成对应的 iframe pane HTML
|
||||
|
||||
let panes = request.spread.resources.enumerated().compactMap { index, resource -> String? in
|
||||
guard let url = publication.resourceResolver.resourceURL(forRelativePath: resource.href)?.absoluteString else {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据 spread 中的资源数量判断页面类型:单页/左页/右页/居中
|
||||
let pageType: String
|
||||
if request.spread.resources.count == 1 {
|
||||
pageType = "single"
|
||||
@@ -36,7 +26,6 @@ enum RDEPUBFixedLayoutTemplate {
|
||||
"""
|
||||
}.joined()
|
||||
|
||||
// 计算视口区域(去除内边距后的可用区域)
|
||||
let background = request.backgroundColorCSS ?? "#FFFFFF"
|
||||
let viewportWidth = max(1, Int((request.viewportSize.width - request.contentInset.left - request.contentInset.right).rounded(.down)))
|
||||
let viewportHeight = max(1, Int((request.viewportSize.height - request.contentInset.top - request.contentInset.bottom).rounded(.down)))
|
||||
@@ -44,7 +33,7 @@ enum RDEPUBFixedLayoutTemplate {
|
||||
let insetRight = Int(request.contentInset.right.rounded(.down))
|
||||
let insetBottom = Int(request.contentInset.bottom.rounded(.down))
|
||||
let insetLeft = Int(request.contentInset.left.rounded(.down))
|
||||
// 从资源仓库加载 HTML 模板并替换占位符
|
||||
|
||||
return RDEPUBAssetRepository.string(
|
||||
for: .fixedLayoutTemplate,
|
||||
replacements: [
|
||||
|
||||
Reference in New Issue
Block a user