feat: font selection with three bundled fonts
- Add FontDef registry (思源黑体 bundled, 霞鹜文楷 + 思源宋体 runtime) - Runtime font loading from fonts/ dir with fallback to bundled default - ComboBox in toolbar to switch fonts - Persist font_name in settings - Download LXGW WenKai Lite (13MB) and Source Han Serif SC (23MB)
This commit is contained in:
42
src/app.rs
42
src/app.rs
@@ -57,6 +57,7 @@ impl App {
|
||||
let settings_dir = persistence::settings_dir();
|
||||
let settings = persistence::load_settings(&settings_dir).unwrap_or_default();
|
||||
cc.egui_ctx.set_style(theme::create_style(&settings.theme));
|
||||
crate::font::setup_fonts(&cc.egui_ctx, &settings.font_name);
|
||||
Self {
|
||||
state: AppState {
|
||||
book: None,
|
||||
@@ -297,21 +298,23 @@ BgType::Custom(ref path) if !path.is_empty() => {
|
||||
let bookmarks = self.settings.bookmarks.get(&file_path).cloned().unwrap_or_default();
|
||||
let mut jump_to_bookmark: Option<usize> = None;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
let book = self.state.book.as_mut().unwrap();
|
||||
let (action, jump) = crate::reader::reading_view(
|
||||
ui,
|
||||
book,
|
||||
&mut self.state.current_section,
|
||||
&mut self.state.current_page,
|
||||
&mut self.state.sidebar_open,
|
||||
&mut style,
|
||||
&theme_copy,
|
||||
bg_type.clone(),
|
||||
&file_path,
|
||||
&profile_names,
|
||||
&bookmarks,
|
||||
);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
let book = self.state.book.as_mut().unwrap();
|
||||
let current_font = self.settings.font_name.clone();
|
||||
let (action, jump) = crate::reader::reading_view(
|
||||
ui,
|
||||
book,
|
||||
&mut self.state.current_section,
|
||||
&mut self.state.current_page,
|
||||
&mut self.state.sidebar_open,
|
||||
&mut style,
|
||||
&theme_copy,
|
||||
bg_type.clone(),
|
||||
&file_path,
|
||||
&profile_names,
|
||||
&bookmarks,
|
||||
¤t_font,
|
||||
);
|
||||
jump_to_bookmark = jump;
|
||||
|
||||
if action.go_back {
|
||||
@@ -336,7 +339,14 @@ BgType::Custom(ref path) if !path.is_empty() => {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(new_bg) = action.switch_bg {
|
||||
if let Some(ref new_font) = action.switch_font {
|
||||
if new_font != &self.settings.font_name {
|
||||
let actual = crate::font::setup_fonts(ui.ctx(), new_font);
|
||||
self.settings.font_name = actual;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(new_bg) = action.switch_bg {
|
||||
self.settings.bg_type = new_bg;
|
||||
// 切换背景时,如果选自定义图片则弹出文件选择器
|
||||
if let BgType::Custom(_) = &self.settings.bg_type {
|
||||
|
||||
Reference in New Issue
Block a user