收紧脚注图的 alt 兜底判定

原判定 alt 非空即视为脚注图,导致带 alt 的正常插图(如凡人修仙传的
logo)被缩到一个字号大小。改为 alt 长度达到脚注正文量级(≥8 字符)
且原图为小图标(≤50pt)双条件同时成立才走脚注缩放,与 HTML 归一化
层只认 qqreader-footnote class 的口径对齐。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
shenlei 2026-07-06 12:16:53 +09:00
parent 5ae7823ef8
commit ca408c20ab

View File

@ -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
}
}