Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Fix main UI regressions in paging, fonts and test expectations (#2502)

FredApps609a724235a5
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 5941f6a4a..989b731b7 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2397,7 +2397,8 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
// Paging owns the vertical axis in single-page view; leave it to the pager.
// The rest of a gesture that turned the page is swallowed too, or it would pan the new page
// away from the edge it was shown at.
- if single_paging || (!view.continuous && view.wheel.gesture_turned()) {
+ let paging_owns_vertical = single_paging || (!view.continuous && view.wheel.gesture_turned());
+ if paging_owns_vertical {
precise_scroll.y = 0.0;
}
if now < view.precise_scroll_until {
@@ -2410,7 +2411,7 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
// dialog has the input, or animations are off; any click, key, zoom or other scrolling ends it.
// Asked of the preference, not of egui's animation time, which test harnesses zero.
let animates = app.animation_effects.animates(app.motion.reduced);
- let may_glide = !single_paging && !middle_gesture && navigation_enabled && unobstructed && animates;
+ let may_glide = !paging_owns_vertical && !middle_gesture && navigation_enabled && unobstructed && animates;
let over_page = ui.rect_contains_pointer(avail);
ui.input(|i| view.fling.read(&i.events, now, may_glide && over_page));
let interrupted = ui.input(|i| i.pointer.any_pressed() || i.events.iter().any(|e| matches!(e, egui::Event::Key { pressed: true, .. })));
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index d28a7b658..3f43a03dc 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -367,6 +367,9 @@ fn font_definitions_for_platform(prefer_hans: bool, platform: FontPolicyPlatform
add(&mut fonts, "JetBrainsMono", include_bytes!("../../../assets/fonts/JetBrainsMono-Regular.ttf"));
fonts.families.entry(FontFamily::Proportional).or_default().insert(0, "Inter".to_owned());
fonts.families.entry(FontFamily::Monospace).or_default().insert(0, "JetBrainsMono".to_owned());
+ // Keep missing Latin/Cyrillic letters in the app's own faces (for example Bulgarian ѝ,
+ // absent from JetBrains Mono), before egui's defaults or optional system/CJK fallbacks.
+ fonts.families.entry(FontFamily::Monospace).or_default().insert(1, "Inter".to_owned());
// The same static bytes pdfcraft-fonts uses for Japanese/Chinese text in PDFs: one copy, not two.
for face in pdfcraft_fonts::ui_cjk_fonts(prefer_hans) {
let name = face.name();
diff --git a/crates/ui-egui/tests/control.rs b/crates/ui-egui/tests/control.rs
index 847ffcc75..88ed1c0a9 100644
--- a/crates/ui-egui/tests/control.rs
+++ b/crates/ui-egui/tests/control.rs
@@ -1603,7 +1603,15 @@ fn page_size_shows_while_the_pointer_is_in_the_bottom_left_quadrant() {
#[test]
fn navigation_history_commands_and_rail_are_per_tab_and_non_editing() {
+ for os in [egui::os::OperatingSystem::Nix, egui::os::OperatingSystem::Mac, egui::os::OperatingSystem::Windows] {
+ navigation_history_for_os(os);
+ }
+}
+
+fn navigation_history_for_os(os: egui::os::OperatingSystem) {
let (mut h, c) = harness();
+ h.ctx.set_os(os);
+ h.run_steps(2);
let enabled =
|list: Value, id: &str| list["commands"].as_array().unwrap().iter().find(|cmd| cmd["id"] == id).unwrap()["enabled"].as_bool().unwrap();
assert!(!enabled(ok(&mut h, &c, "ui.commands", json!({})), "view.previous_view"));
@@ -1617,7 +1625,8 @@ fn navigation_history_commands_and_rail_are_per_tab_and_non_editing() {
ok(&mut h, &c, "ui.set", json!({"key": "page", "value": "4"}));
assert!(enabled(ok(&mut h, &c, "ui.commands", json!({})), "view.previous_view"));
// The real rail button is accessible and invokes the same history, not the adjacent page.
- ok(&mut h, &c, "ui.click", json!({"label": &format!("Previous view ({})", if cfg!(target_os = "macos") { "⌘[" } else { "Ctrl+[" })}));
+ let shortcut = if h.ctx.os() == egui::os::OperatingSystem::Mac { "⌘[" } else { "Ctrl+[" };
+ ok(&mut h, &c, "ui.click", json!({"label": &format!("Previous view ({shortcut})")}));
assert_eq!(h.state().views[0].current, 0);
assert!(enabled(ok(&mut h, &c, "ui.commands", json!({})), "view.next_view"));
ok(&mut h, &c, "ui.command", json!({"id": "view.next_view"}));
diff --git a/crates/ui-egui/tests/editing.rs b/crates/ui-egui/tests/editing.rs
index 65b90dad5..f8db52575 100644
--- a/crates/ui-egui/tests/editing.rs
+++ b/crates/ui-egui/tests/editing.rs
@@ -1777,9 +1777,12 @@ fn files_dropped_beside_the_pages_panel_still_open_as_documents() {
h.hover_at(egui::pos2(thumb.left() - 300.0, thumb.center().y));
h.run_steps(2);
drop_files(&mut h, vec![Dropped("other.pdf", fixture(1))]);
- h.run_steps(3);
+ // Native opening prepares the document on a worker; three UI frames need not give it
+ // any CPU time. Wait for the result, as the other dropped-document regression does.
+ support::wait_until(&mut h, "document dropped beside the Pages panel", |app| app.views.len() == 2 && app.password_prompt.is_none());
assert_eq!(h.state().views.len(), 2);
assert_eq!(texts_of(h.state(), 0), ["Page 1", "Page 2"]);
+ assert_eq!(texts_of(h.state(), 1), ["Page 1"], "the dropped PDF opens as its own document");
}
fn grid_zoom(h: &Harness<'static, PdfCraftApp>) -> f32 {
diff --git a/crates/ui-egui/tests/fonts.rs b/crates/ui-egui/tests/fonts.rs
index 258abe89c..9cfa36c8a 100644
--- a/crates/ui-egui/tests/fonts.rs
+++ b/crates/ui-egui/tests/fonts.rs
@@ -291,12 +291,16 @@ fn ui_fonts_work_without_craft_fonts() {
}
/// Latin- and Cyrillic-script catalogs (Czech, Brazilian Portuguese, German, Spanish, French, Russian, Bulgarian, Hungarian, Ukrainian, Italian, Slovene) are drawn entirely by the app's own faces
-/// (Inter, JetBrains Mono): no letter falls through to egui's defaults or a CJK fallback. (egui's
+/// (Inter, JetBrains Mono with Inter fallback): no letter falls through to egui's defaults or a CJK fallback. (egui's
/// `has_glyphs` can't answer this: with only the primary face it is also the replacement face.)
#[test]
fn primary_ui_fonts_cover_latin_and_cyrillic_catalogs() {
use skrifa::MetadataProvider as _;
let defs = theme::font_definitions();
+ assert_eq!(&defs.families[&FontFamily::Monospace][..2], ["JetBrainsMono", "Inter"]);
+ let fallback = &defs.font_data["Inter"];
+ let fallback_font = skrifa::FontRef::from_index(&fallback.font, fallback.index).unwrap();
+ let fallback_charmap = fallback_font.charmap();
for (code, catalog) in [
("cs", include_str!("../src/i18n/cs.tsv")),
("el", include_str!("../src/i18n/el.tsv")),
@@ -325,7 +329,8 @@ fn primary_ui_fonts_cover_latin_and_cyrillic_catalogs() {
let data = &defs.font_data[name];
let font = skrifa::FontRef::from_index(&data.font, data.index).unwrap();
let charmap = font.charmap();
- let mut missing: Vec<char> = text.chars().filter(|c| charmap.map(*c).is_none()).collect();
+ let mut missing: Vec<char> =
+ text.chars().filter(|c| charmap.map(*c).is_none() && (name != "JetBrainsMono" || fallback_charmap.map(*c).is_none())).collect();
missing.sort_unstable();
missing.dedup();
assert!(missing.is_empty(), "{code}: {name} lacks {missing:?}");
diff --git a/crates/ui-egui/tests/print.rs b/crates/ui-egui/tests/print.rs
index 48f12feab..f3d10238c 100644
--- a/crates/ui-egui/tests/print.rs
+++ b/crates/ui-egui/tests/print.rs
@@ -244,14 +244,16 @@ fn print_dialog_shows_the_printer_driver_options() {
h.get_by_label("Printer properties");
h.get_by_label("Media");
h.get_by_label("Paper tray");
- assert_eq!(h.state().print_draft.job("form.pdf").options, [("InputSlot".to_string(), "Tray2".to_string())]);
+ // The selected sheet's media is always sent, independently of changed driver properties.
+ let media = vec![("media".to_string(), "Letter".to_string())];
+ assert_eq!(h.state().print_draft.job("form.pdf").options, [("InputSlot".to_string(), "Tray2".to_string()), media[0].clone()]);
h.get_by_label("Reset to printer defaults").click();
h.run_steps(2);
- assert!(h.state().print_draft.job("form.pdf").options.is_empty(), "defaults are not sent");
+ assert_eq!(h.state().print_draft.job("form.pdf").options, media, "driver defaults are not sent; selected paper is retained");
// Options read for another printer never go with this one's job.
h.state_mut().print_draft.driver_choices.insert("InputSlot".into(), "Tray2".into());
h.state_mut().print_draft.printer = Some("Other_Queue".into());
- assert!(h.state().print_draft.job("form.pdf").options.is_empty());
+ assert_eq!(h.state().print_draft.job("form.pdf").options, media, "another queue must not inherit driver options");
}
/// The desktop app lists printers in the background (PowerShell on Windows takes a second or
diff --git a/crates/ui-egui/tests/view.rs b/crates/ui-egui/tests/view.rs
index 65f4b3132..3fdeff637 100644
--- a/crates/ui-egui/tests/view.rs
+++ b/crates/ui-egui/tests/view.rs
@@ -347,6 +347,7 @@ fn precise_touchpad_wheel_scrolls_one_to_one() {
/// Steps `frames` frames and returns how far the document scrolled down over them, from the
/// pages on screen in each pair of consecutive frames (a page can leave the screen on the way).
+#[cfg(not(target_os = "macos"))]
fn scroll_over(h: &mut Harness<'static, PdfCraftApp>, frames: usize) -> f32 {
let tops = |h: &Harness<'static, PdfCraftApp>| (0..3).map(|p| rect(h, p).map(|r| r.min.y)).collect::<Vec<_>>();
let mut moved = 0.0;
@@ -363,6 +364,7 @@ fn scroll_over(h: &mut Harness<'static, PdfCraftApp>, frames: usize) -> f32 {
/// A two-finger swipe down the page, 25 points a frame for six frames, lifted the frame after
/// (the axis stop Wayland sends), at 300 % so the document is long enough to glide in: how far
/// it scrolled by the frame after the lift (the page is drawn a frame behind its scroll).
+#[cfg(not(target_os = "macos"))]
fn swipe_and_lift(h: &mut Harness<'static, PdfCraftApp>) -> f32 {
let at = h.state().views[0].viewport_rect().center();
h.hover_at(at);