feat(reader): 支持 EPUB 嵌入字体显示(桌面端 + 移动端) - #636
Open
k6G52m4Dz75W wants to merge 1 commit into
Open
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
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 会内嵌字体(通过
@font-face引用书内的 ttf/otf/woff/woff2,甚至带 IDPF 混淆),例如内嵌中文书法体、艺术字标题、或西文衬线体。此前 ReadAny 为了保证字体主题统一,在渲染时对所有元素强制注入body * { font-family: var(--readany-font-family) !important },导致书籍嵌入字体永远无法显示——即使引擎层(foliate-js)已经把@font-face字体正确加载成 blob URL(含 IDPF 去混淆)。改动
新增全局阅读设置
useBookFonts(使用书籍字体),默认开启,桌面端与移动端一致:body *的全元素字体覆盖,仅保留html/body上的主题字体作为基础。书内显式指定了font-family的元素(如嵌入字体段落)正常显示嵌入字体,未指定字体的正文仍使用用户选择的字体主题。具体变更:
core/src/types/book.tsViewSettings增加可选useBookFontscore/src/stores/settings-store.tsapp/.../FoliateViewer.tsxapp/.../settings/ReadSettings.tsxapp-expo/.../ReaderScreen.tsx、use-reader-bridge.tsuseBookFontsapp-expo/assets/reader/reader.template.html+reader.htmlapp-expo/.../ReaderSettingsPanel.tsxsettings.json/reader.json影响面
验证
reader.html在浏览器中加载含嵌入字体的测试 epub 实测:body *覆盖规则TestEmbedded, serif(Brush Script 手写体)测试建议(Reviewer)