From ca408c20ab6ab9a1b8d797e6992dd82fe0cdd302 Mon Sep 17 00:00:00 2001 From: shenlei Date: Mon, 6 Jul 2026 12:16:53 +0900 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E7=B4=A7=E8=84=9A=E6=B3=A8=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=20alt=20=E5=85=9C=E5=BA=95=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原判定 alt 非空即视为脚注图,导致带 alt 的正常插图(如凡人修仙传的 logo)被缩到一个字号大小。改为 alt 长度达到脚注正文量级(≥8 字符) 且原图为小图标(≤50pt)双条件同时成立才走脚注缩放,与 HTML 归一化 层只认 qqreader-footnote class 的口径对齐。 Co-Authored-By: Claude Fable 5 --- .../RDEPUBAttachmentNormalizer.swift | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Sources/RDReaderView/EPUBTextRendering/Typesetter/RDEPUBAttachmentNormalizer.swift b/Sources/RDReaderView/EPUBTextRendering/Typesetter/RDEPUBAttachmentNormalizer.swift index 8486512..ffae4bf 100644 --- a/Sources/RDReaderView/EPUBTextRendering/Typesetter/RDEPUBAttachmentNormalizer.swift +++ b/Sources/RDReaderView/EPUBTextRendering/Typesetter/RDEPUBAttachmentNormalizer.swift @@ -136,8 +136,11 @@ struct RDEPUBAttachmentNormalizer { private static func isFootnoteAttachment(_ attachment: DTTextAttachment) -> Bool { let lowercasedClasses = ((attachment.attributes["class"] as? String) ?? "").lowercased() + if lowercasedClasses.contains("qqreader-footnote") { + return true + } let altText = attachment.attributes["alt"] as? String - return lowercasedClasses.contains("qqreader-footnote") || hasFootnoteAltText(altText) + return hasFootnoteAltText(altText) && isFootnoteSizedImage(attachment.originalSize) } private static func isCoverAttachment(_ attachment: DTTextAttachment) -> Bool { @@ -224,10 +227,31 @@ struct RDEPUBAttachmentNormalizer { } let label = fileAttachment.accessibilityLabel let lowercasedLabel = (label ?? "").lowercased() - return lowercasedLabel.contains("qqreader-footnote") || hasFootnoteAltText(label) + if lowercasedLabel.contains("qqreader-footnote") { + return true + } + let imageSize = fileAttachment.image?.size ?? fileAttachment.bounds.size + return hasFootnoteAltText(label) && isFootnoteSizedImage(imageSize) } + // Footnote images without the qqreader-footnote class are recognized by their + // alt text carrying the note body. Short alts ("logo", "图1") are ordinary + // accessibility descriptions, and note markers are small inline icons, so both + // conditions must hold before an image is shrunk to footnote size. + private static let minimumFootnoteAltTextLength = 8 + + private static let maximumFootnoteImageDimension: CGFloat = 50 + private static func hasFootnoteAltText(_ text: String?) -> Bool { - text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false + guard let trimmed = text?.trimmingCharacters(in: .whitespacesAndNewlines) else { + return false + } + return trimmed.count >= minimumFootnoteAltTextLength + } + + private static func isFootnoteSizedImage(_ size: CGSize) -> Bool { + guard size.width > 0, size.height > 0 else { return false } + return size.width <= maximumFootnoteImageDimension + && size.height <= maximumFootnoteImageDimension } }