feat(layout): detect reflowable vs fixed-layout EPUB, fix pagination overflow
This commit is contained in:
@@ -5,14 +5,15 @@ use crate::theme::{self, BgType, Theme};
|
||||
|
||||
pub fn recalculate_pages(book: &mut Book, font_size: f32, line_height: f32, panel_width: f32, panel_height: f32, style: &StyleProfile) {
|
||||
let char_width = font_size * 1.0;
|
||||
let safety = 0.95;
|
||||
let safety_w = 0.95;
|
||||
let safety_h = 0.96;
|
||||
let chars_per_line = if char_width > 0.0 {
|
||||
((panel_width / char_width) * safety).max(1.0) as usize
|
||||
((panel_width / char_width) * safety_w).max(1.0) as usize
|
||||
} else {
|
||||
1
|
||||
};
|
||||
let lines_per_page = if line_height > 0.0 {
|
||||
((panel_height / line_height) * safety).max(1.0) as usize
|
||||
((panel_height / line_height) * safety_h).max(1.0) as usize
|
||||
} else {
|
||||
1
|
||||
};
|
||||
@@ -101,7 +102,8 @@ pub fn reading_view(
|
||||
action.go_back = true;
|
||||
}
|
||||
ui.separator();
|
||||
ui.label(&book.title);
|
||||
ui.label(format!("《{}》", &book.title));
|
||||
ui.label(format!("[{}]", book.layout.label()));
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let (theme_icon, theme_hint) = match theme {
|
||||
Theme::Dark => ("🌞", "切换到浅色主题"),
|
||||
@@ -412,9 +414,9 @@ pub fn calculate_pages(text: &str, chars_per_page: usize) -> Vec<usize> {
|
||||
break;
|
||||
}
|
||||
|
||||
// Search backward from next for paragraph (\n\n) or line (\n) breaks
|
||||
// 在页面后半段查找段落边界(\n\n)或行边界(\n),不回超理想页长
|
||||
let search_start = pos + chars_per_page / 2;
|
||||
let search_end = (next + chars_per_page / 2).min(total_chars);
|
||||
let search_end = next.min(total_chars);
|
||||
let mut split = next;
|
||||
|
||||
// Prefer double newline (paragraph), then single newline
|
||||
|
||||
Reference in New Issue
Block a user