Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/app-expo/assets/reader/reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
let currentFontTheme = 'default';
let currentCustomFontFaceCSS = '';
let currentCustomFontFamily = '';
let currentUseBookFonts = true;
let tapNavigationInFlight = false;
let tapNavigationResetTimer = null;
let readerElement = null;
Expand Down Expand Up @@ -1785,6 +1786,9 @@
if (settings.customFontFamily !== undefined) {
currentCustomFontFamily = settings.customFontFamily || '';
}
if (settings.useBookFonts !== undefined) {
currentUseBookFonts = settings.useBookFonts !== false;
}

if (settings.fontSize !== undefined) {
currentFontSize = settings.fontSize;
Expand All @@ -1804,7 +1808,7 @@
}

if (settings.fontSize !== undefined || settings.lineHeight !== undefined || settings.fontTheme !== undefined || settings.paragraphSpacing !== undefined
|| settings.customFontFamily !== undefined || settings.customFontFaceCSS !== undefined) {
|| settings.customFontFamily !== undefined || settings.customFontFaceCSS !== undefined || settings.useBookFonts !== undefined) {
const fontThemes = {
default: { cjk: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif', serif: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif' },
system: { cjk: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif', serif: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif' },
Expand Down Expand Up @@ -1836,6 +1840,15 @@
const layoutScale = currentFontSize / BASELINE_FONT_SIZE;
const ps = Math.round(currentParagraphSpacing * layoutScale);

// When useBookFonts is enabled (default), do not force the reader
// font family onto every element so the book's own fonts (e.g.
// embedded @font-face families) render where the book specifies them.
const bodyStarFontOverride = currentUseBookFonts
? ''
: `:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}`;

const baseStyles = `
:root {
--readany-font-family: ${fontFamily};
Expand All @@ -1847,9 +1860,7 @@
-webkit-text-size-adjust: none;
text-size-adjust: none;
}
:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}
${bodyStarFontOverride}
:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *):not(rt):not(rp) {
font-size: ${fSize}px !important;
}
Expand Down
19 changes: 15 additions & 4 deletions packages/app-expo/assets/reader/reader.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
let currentFontTheme = 'default';
let currentCustomFontFaceCSS = '';
let currentCustomFontFamily = '';
let currentUseBookFonts = true;
let tapNavigationInFlight = false;
let tapNavigationResetTimer = null;
let readerElement = null;
Expand Down Expand Up @@ -1785,6 +1786,9 @@
if (settings.customFontFamily !== undefined) {
currentCustomFontFamily = settings.customFontFamily || '';
}
if (settings.useBookFonts !== undefined) {
currentUseBookFonts = settings.useBookFonts !== false;
}

if (settings.fontSize !== undefined) {
currentFontSize = settings.fontSize;
Expand All @@ -1804,7 +1808,7 @@
}

if (settings.fontSize !== undefined || settings.lineHeight !== undefined || settings.fontTheme !== undefined || settings.paragraphSpacing !== undefined
|| settings.customFontFamily !== undefined || settings.customFontFaceCSS !== undefined) {
|| settings.customFontFamily !== undefined || settings.customFontFaceCSS !== undefined || settings.useBookFonts !== undefined) {
const fontThemes = {
default: { cjk: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif', serif: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif' },
system: { cjk: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif', serif: '-apple-system, BlinkMacSystemFont, system-ui, sans-serif' },
Expand Down Expand Up @@ -1836,6 +1840,15 @@
const layoutScale = currentFontSize / BASELINE_FONT_SIZE;
const ps = Math.round(currentParagraphSpacing * layoutScale);

// When useBookFonts is enabled (default), do not force the reader
// font family onto every element so the book's own fonts (e.g.
// embedded @font-face families) render where the book specifies them.
const bodyStarFontOverride = currentUseBookFonts
? ''
: `:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}`;

const baseStyles = `
:root {
--readany-font-family: ${fontFamily};
Expand All @@ -1847,9 +1860,7 @@
-webkit-text-size-adjust: none;
text-size-adjust: none;
}
:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}
${bodyStarFontOverride}
:root:not(.vrtl):not(.vltr) body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *):not(rt):not(rp) {
font-size: ${fSize}px !important;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/app-expo/src/hooks/use-reader-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface ReaderInitialSettings {
paragraphSpacing?: number;
pageMargin?: number;
fontTheme?: string;
useBookFonts?: boolean;
viewMode?: "paginated" | "scroll";
paginatedLayout?: "single" | "double";
}
Expand Down Expand Up @@ -266,6 +267,7 @@ export function useReaderBridge(callbacks: ReaderBridgeCallbacks) {
paragraphSpacing?: number;
pageMargin?: number;
fontTheme?: string;
useBookFonts?: boolean;
viewMode?: string;
paginatedLayout?: "single" | "double";
customFontFaceCSS?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/app-expo/src/screens/ReaderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export function ReaderScreen({ route, navigation }: Props) {
paragraphSpacing: settings.paragraphSpacing,
pageMargin: settings.pageMargin,
fontTheme: settings.fontTheme,
useBookFonts: settings.useBookFonts,
viewMode: settings.viewMode,
paginatedLayout: settings.paginatedLayout,
customFontFaceCSS: fontCSS,
Expand Down Expand Up @@ -1140,6 +1141,7 @@ export function ReaderScreen({ route, navigation }: Props) {
paragraphSpacing: readSettings.paragraphSpacing,
pageMargin: readSettings.pageMargin,
fontTheme: readSettings.fontTheme,
useBookFonts: readSettings.useBookFonts,
viewMode: readSettings.viewMode,
paginatedLayout: readSettings.paginatedLayout,
},
Expand Down
15 changes: 15 additions & 0 deletions packages/app-expo/src/screens/reader/ReaderSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ export function ReaderSettingsPanel({ visible, readSettings, bookId, onClose, on
</View>
</ScrollView>
</View>
{/* Use book fonts */}
<View style={s.settingRow}>
<View style={s.settingLabelBlock}>
<Text style={s.settingLabel}>{t("reader.useBookFonts")}</Text>
<Text style={s.settingHint}>{t("reader.useBookFontsDesc")}</Text>
</View>
<TouchableOpacity
style={[s.settingToggleBtn, readSettings.useBookFonts !== false && s.settingToggleBtnActive]}
onPress={() => onUpdateSetting("useBookFonts", readSettings.useBookFonts === false)}
>
<Text style={[s.settingToggleText, readSettings.useBookFonts !== false && s.settingToggleTextActive]}>
{readSettings.useBookFonts !== false ? t("settings.enabled") : t("settings.disabled")}
</Text>
</TouchableOpacity>
</View>
{/* View Mode */}
<View style={s.settingRow}>
<Text style={s.settingLabel}>{t("reader.viewMode", "阅读模式")}</Text>
Expand Down
29 changes: 21 additions & 8 deletions packages/app-expo/src/stores/settings-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const defaultReadSettings: ReadSettings = {
fontSize: 16,
lineHeight: 1.6,
fontTheme: "classic",
useBookFonts: true,
viewMode: "paginated",
paginatedLayout: "double",
pageMargin: 40,
Expand Down Expand Up @@ -83,14 +84,26 @@ const defaultAIConfig: AIConfig = {
};

function migrateSettingsState(state: SettingsState): SettingsState {
if (state.aiConfig.maxTokens !== 4096) return state;
return {
...state,
aiConfig: {
...state.aiConfig,
maxTokens: defaultAIConfig.maxTokens,
},
};
let next = state;
if (next.aiConfig.maxTokens === 4096) {
next = {
...next,
aiConfig: {
...next.aiConfig,
maxTokens: defaultAIConfig.maxTokens,
},
};
}
if (next.readSettings?.useBookFonts === undefined) {
next = {
...next,
readSettings: {
...next.readSettings,
useBookFonts: true,
},
};
}
return next;
}

async function fetchModelsFromEndpoint(endpoint: AIEndpoint): Promise<string[]> {
Expand Down
17 changes: 13 additions & 4 deletions packages/app/src/components/reader/FoliateViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,7 @@ export const FoliateViewer = forwardRef<FoliateViewerHandle, FoliateViewerProps>
viewSettings.customFontFamily,
viewSettings.customFontFaceCSS,
viewSettings.customFontCssUrls,
viewSettings.useBookFonts,
viewSettings.paragraphSpacing,
isFixedLayout,
appTheme,
Expand Down Expand Up @@ -3174,6 +3175,17 @@ function getRendererStyles(settings: ViewSettings, theme: AppTheme): string {
const layoutScale = settings.fontSize / BASELINE_FONT_SIZE;
const scaledParagraphSpacing = Math.round(settings.paragraphSpacing * layoutScale);

// When useBookFonts is enabled (default), do not force the reader font
// family onto every element so the book's own fonts (e.g. embedded
// @font-face families) render where the book specifies them.
const bodyStarFontOverride =
settings.useBookFonts === false
? `body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}
`
: "";

return `${settings.customFontFaceCSS ? `/* Custom font faces */\n${settings.customFontFaceCSS}\n\n` : ""}/* Font styles */
html {
--theme-bg-color: ${bgColor};
Expand All @@ -3192,10 +3204,7 @@ html, body {
text-size-adjust: none;
}

body *:not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *) {
font-family: var(--readany-font-family) !important;
}

${bodyStarFontOverride}
body :not(#__readany_font_size_override):not(svg):not(svg *):not(math):not(math *):not(pre):not(pre *):not(code):not(code *):not(kbd):not(kbd *):not(samp):not(samp *):not(rt):not(rp) {
font-size: ${settings.fontSize}px !important;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/app/src/components/settings/ReadSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Slider } from "@/components/ui/slider";
import { Switch } from "@/components/ui/switch";
import { useAppStore } from "@/stores/app-store";
import { useSettingsStore } from "@/stores/settings-store";
import { useFontStore } from "@readany/core/stores";
Expand Down Expand Up @@ -94,6 +95,20 @@ export function ReadSettingsPanel() {
</Select>
</div>

{/* Use book fonts */}
<div className="flex items-center justify-between pt-1">
<div>
<span className="text-sm text-foreground">{t("settings.useBookFonts")}</span>
<p className="mt-0.5 text-xs text-muted-foreground">
{t("settings.useBookFontsDesc")}
</p>
</div>
<Switch
checked={readSettings.useBookFonts !== false}
onCheckedChange={(checked) => updateReadSettings({ useBookFonts: checked })}
/>
</div>

{/* Font Size */}
<div>
<div className="mb-3 flex items-center justify-between">
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/en/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "Font Size",
"lineHeight": "Line Height",
"fontTheme": "Font Theme",
"useBookFonts": "Use book fonts",
"useBookFontsDesc": "Honor the book's own fonts (e.g. embedded fonts) where specified.",
"viewMode": "View Mode",
"paginated": "Paginated",
"scrollMode": "Scroll",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "Font Size: {{size}}px",
"lineHeight": "Line Height: {{height}}",
"fontTheme": "Font Theme",
"useBookFonts": "Use book fonts",
"useBookFontsDesc": "Honor the book's own fonts (e.g. embedded fonts) where specified.",
"paragraphSpacing": "Paragraph Spacing",
"showTopTitleProgress": "Top Title & Progress",
"showBottomTimeBattery": "Bottom Time & Battery",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/es/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "Tamaño de fuente",
"lineHeight": "Altura de línea",
"fontTheme": "Tema de fuente",
"useBookFonts": "Usar fuentes del libro",
"useBookFontsDesc": "Mostrar prioritariamente las fuentes del libro (fuentes incrustadas).",
"viewMode": "Modo de vista",
"paginated": "Paginado",
"scrollMode": "Desplazamiento",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/es/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "Tamaño de fuente: {{size}}px",
"lineHeight": "Altura de línea: {{height}}",
"fontTheme": "Tema de fuente",
"useBookFonts": "Usar fuentes del libro",
"useBookFontsDesc": "Mostrar prioritariamente las fuentes del libro (fuentes incrustadas).",
"paragraphSpacing": "Espaciado entre párrafos",
"showTopTitleProgress": "Título y progreso superior",
"showBottomTimeBattery": "Hora y batería inferior",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/fr/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "Taille de police",
"lineHeight": "Interligne",
"fontTheme": "Thème de police",
"useBookFonts": "Utiliser les polices du livre",
"useBookFontsDesc": "Afficher en priorité les polices du livre (polices intégrées).",
"viewMode": "Mode d'affichage",
"paginated": "Paginé",
"scrollMode": "Défilement",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/fr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "Taille de police : {{size}}px",
"lineHeight": "Interligne : {{height}}",
"fontTheme": "Thème de police",
"useBookFonts": "Utiliser les polices du livre",
"useBookFontsDesc": "Afficher en priorité les polices du livre (polices intégrées).",
"paragraphSpacing": "Espacement des paragraphes",
"showTopTitleProgress": "Titre et progression en haut",
"showBottomTimeBattery": "Heure et batterie en bas",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ja/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "文字サイズ",
"lineHeight": "行間",
"fontTheme": "フォントテーマ",
"useBookFonts": "書籍のフォントを使用",
"useBookFontsDesc": "書籍内で指定されたフォント(埋め込みフォントなど)を優先表示します。",
"viewMode": "表示モード",
"paginated": "ページ送り",
"scrollMode": "スクロール",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ja/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "文字サイズ: {{size}}px",
"lineHeight": "行間: {{height}}",
"fontTheme": "フォントテーマ",
"useBookFonts": "書籍のフォントを使用",
"useBookFontsDesc": "書籍内で指定されたフォント(埋め込みフォントなど)を優先表示します。",
"paragraphSpacing": "段落間隔",
"showTopTitleProgress": "上部タイトル&進捗表示",
"showBottomTimeBattery": "下部時刻&バッテリー表示",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ko/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "글꼴 크기",
"lineHeight": "줄 간격",
"fontTheme": "글꼴 테마",
"useBookFonts": "책의 글꼴 사용",
"useBookFontsDesc": "책에 지정된 글꼴(내장 글꼴 등)을 우선 표시합니다.",
"viewMode": "보기 모드",
"paginated": "페이지 넘기기",
"scrollMode": "스크롤",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/ko/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "글꼴 크기: {{size}}px",
"lineHeight": "줄 간격: {{height}}",
"fontTheme": "글꼴 테마",
"useBookFonts": "책의 글꼴 사용",
"useBookFontsDesc": "책에 지정된 글꼴(내장 글꼴 등)을 우선 표시합니다.",
"paragraphSpacing": "문단 간격",
"showTopTitleProgress": "상단 제목 및 진행률",
"showBottomTimeBattery": "하단 시간 및 배터리",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh-TW/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "字型大小",
"lineHeight": "行高",
"fontTheme": "字型主題",
"useBookFonts": "使用書籍字型",
"useBookFontsDesc": "優先顯示書籍自帶的字型(如內嵌字型)。",
"viewMode": "閱讀模式",
"paginated": "翻頁",
"scrollMode": "捲動",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "字型大小:{{size}}px",
"lineHeight": "行高:{{height}}",
"fontTheme": "字型主題",
"useBookFonts": "使用書籍字型",
"useBookFontsDesc": "優先顯示書籍自帶的字型(如內嵌字型)。",
"paragraphSpacing": "段落間距",
"showTopTitleProgress": "頂部標題與進度",
"showBottomTimeBattery": "底部時間與電量",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh/reader.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"fontSize": "字号",
"lineHeight": "行高",
"fontTheme": "字体主题",
"useBookFonts": "使用书籍字体",
"useBookFontsDesc": "优先显示书籍自带的字体(如内嵌字体)。",
"viewMode": "阅读模式",
"paginated": "翻页",
"scrollMode": "滚动",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/i18n/locales/zh/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"fontSize": "字体大小:{{size}}px",
"lineHeight": "行高:{{height}}",
"fontTheme": "字体主题",
"useBookFonts": "使用书籍字体",
"useBookFontsDesc": "优先显示书籍自带的字体(如内嵌字体)。",
"paragraphSpacing": "段落间距",
"showTopTitleProgress": "顶部标题与进度",
"showBottomTimeBattery": "底部时间与电量",
Expand Down
Loading