fix(epub): 修复部分 EPUB 丢失样式的问题(HTML 未链接任何 CSS 时兜底注入 manifest 样式) - #639
Open
k6G52m4Dz75W wants to merge 2 commits into
Open
fix(epub): 修复部分 EPUB 丢失样式的问题(HTML 未链接任何 CSS 时兜底注入 manifest 样式)#639k6G52m4Dz75W wants to merge 2 commits into
k6G52m4Dz75W wants to merge 2 commits into
Conversation
Add a global read setting 'useBookFonts' (default on) that lets the reader's own fonts - including fonts embedded in EPUBs - render where the book specifies them, instead of forcing the app font theme onto every element. - ViewSettings: add optional useBookFonts - Desktop (FoliateViewer): only inject the body* font-family override when useBookFonts is off; re-apply styles live on toggle - Mobile (reader.template.html + build reader.html): same conditional override, wired through ReaderScreen/use-reader-bridge - Settings UI + toggle in desktop ReadSettingsPanel and mobile ReaderSettingsPanel - Store defaults + migration backfill for existing users (old persisted settings default to on) - i18n: settings.json and reader.json across all 7 locales
Some malformed EPUBs ship content documents that never link any stylesheet, so the book's CSS (declared in the package manifest) is never loaded and the book renders completely unstyled. Fallback: when an XHTML section has no <link rel=stylesheet> at all, inject every CSS file declared in the package manifest (in manifest order) as <link> elements during section loading. CSS goes through the regular loader path, so url() references (images/fonts) and ref-counting/unload are handled correctly. Single code path in foliate-js applies to both desktop (direct import) and mobile (bundled reader.html, rebuilt). Verified in a real browser against the built mobile reader.html: a broken book without CSS links now renders identically to a normal book; a normal book is unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
部分制作有问题的 EPUB(常见于"自由转换"产物),其内容文档(XHTML)里完全没有
<link rel="stylesheet">,导致书籍自带样式从未被加载,打开后所有样式丢失。引擎层(foliate-js)此前只改写 HTML 中"已存在"的样式表引用,对这种文件无能为力。改动
在章节加载(foliate-js
loadReplaced)中新增兜底:当某章节文档完全没有样式表链接时,将 OPF manifest 中声明的所有 CSS 文件(media-type="text/css",按 manifest 顺序)动态注入为该章节的<link rel="stylesheet">。loadItem),CSS 内的url()(图片/字体)、@import、字体去混淆、引用计数/卸载回收全部正确处理;验证
用真实构建产物
reader.html在浏览器中实测:<link>坏书在修复后与好书渲染表现一致;颜色被强制为主题色是阅读器既有行为,两本书一致。
测试建议(Reviewer)
<link rel="stylesheet">,但content.opf的<manifest>声明了 CSS。