fix(fonts): fix Adobe font deobfuscation and CSS var fallbacks, closes #3662 (#3696)

Two issues caused embedded EPUB fonts to fail:

1. Adobe font deobfuscation (http://ns.adobe.com/pdf/enc#RC) derived the
   XOR key from the wrong UUID. getUUID() picked the first UUID across all
   dc:identifier elements (e.g. Calibre's internal UUID) instead of the
   book's unique-identifier. Also fixed getElementById not working on
   DOMParser-parsed XML (no DTD), and made UUID regex case-insensitive.

2. transformStylesheet replaced generic font families (sans-serif, serif,
   monospace) with CSS var() references without fallback values. In
   fixed-layout iframes where setStyles doesn't inject the variables,
   the undefined var() invalidated the entire font-family declaration
   per CSS spec, causing all fonts to fall back to system defaults.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Huang Xin
2026-03-31 01:06:22 +08:00
committed by GitHub
parent 956c71cd7b
commit e9c5ebb696
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -794,9 +794,9 @@ export const transformStylesheet = (css: string, vw: number, vh: number, vertica
.replace(/([\s;])-o-user-select\s*:\s*none/gi, '$1-o-user-select: unset')
.replace(/([\s;])user-select\s*:\s*none/gi, '$1user-select: unset')
.replace(/(font-family\s*:[^;]*?)\bsans-serif\b/gi, '$1READEST_SS_PLACEHOLDER')
.replace(/(font-family\s*:[^;]*?)\bserif\b(?!-)/gi, '$1var(--serif)')
.replace(/READEST_SS_PLACEHOLDER/g, 'var(--sans-serif)')
.replace(/(font-family\s*:[^;]*?)\bmonospace\b/gi, '$1var(--monospace)')
.replace(/(font-family\s*:[^;]*?)\bserif\b(?!-)/gi, '$1var(--serif, serif)')
.replace(/READEST_SS_PLACEHOLDER/g, 'var(--sans-serif, sans-serif)')
.replace(/(font-family\s*:[^;]*?)\bmonospace\b/gi, '$1var(--monospace, monospace)')
.replace(/([\s;])font-weight\s*:\s*normal/gi, '$1font-weight: var(--font-weight)')
.replace(/([\s;])color\s*:\s*black/gi, '$1color: var(--theme-fg-color)')
.replace(/([\s;])color\s*:\s*#000000/gi, '$1color: var(--theme-fg-color)')