mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
pdf-shell-w19: net change of 3 commits
- pdf-shell-w19: written from its sheet - pdf-shell-w19: repair 1 - pdf-shell-w19: review fixes (review-1)
This commit is contained in:
@@ -1,117 +1,5 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn text_without_rtl_is_borrowed_unchanged() {
|
||||
for s in ["", "report.pdf", "日本語の文字.pdf", "a (b) [c]", "caf\u{00E9} \u{200E}x"] {
|
||||
assert!(matches!(visual(s), Cow::Borrowed(v) if v == s), "{s:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arabic_words_swap_and_the_extension_stays_last() {
|
||||
// The reported name: "one two.pdf" in Arabic.
|
||||
assert_eq!(visual("واحد اثنين.pdf"), "اثنين واحد.pdf");
|
||||
assert_eq!(visual("ملف.pdf"), "ملف.pdf");
|
||||
assert_eq!(visual("تقرير نهائي جدا.pdf"), "جدا نهائي تقرير.pdf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latin_and_numbers_keep_their_own_order() {
|
||||
assert_eq!(visual("report واحد اثنين final.pdf"), "report اثنين واحد final.pdf");
|
||||
// A number inside right-to-left text reads left to right, to the left of what precedes it.
|
||||
assert_eq!(visual("ملف 2024.pdf"), "2024 ملف.pdf");
|
||||
assert_eq!(visual(r"C:\Users\me\واحد اثنين\a.pdf"), r"C:\Users\me\اثنين واحد\a.pdf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hebrew_and_brackets() {
|
||||
assert_eq!(visual("שלום עולם.pdf"), "עולם שלום.pdf");
|
||||
// Brackets between right-to-left words flip with the direction.
|
||||
assert_eq!(visual("واحد (اثنين) ثلاثة.pdf"), "ثلاثة (اثنين) واحد.pdf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direction_controls_are_not_drawn() {
|
||||
assert_eq!(visual("\u{202B}واحد اثنين\u{202C}.pdf"), "اثنين واحد.pdf");
|
||||
assert_eq!(visual("\u{200F}واحد\u{061C}"), "واحد");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_labels_read_right_to_left() {
|
||||
// No right-to-left characters: unchanged.
|
||||
for s in ["", "Save as…", "{n} pages", "日本語"] {
|
||||
assert_eq!(display_rtl(s), s);
|
||||
}
|
||||
assert_eq!(display_rtl("حفظ"), "حفظ");
|
||||
// "Save as…": the second word and the ellipsis end up on the left.
|
||||
assert_eq!(display_rtl("حفظ باسم…"), "…باسم حفظ");
|
||||
// Latin words and numbers keep their own order inside the line.
|
||||
assert_eq!(display_rtl("إنشاء PDF من ملف"), "ملف من PDF إنشاء");
|
||||
assert_eq!(display_rtl("تصدير إلى Microsoft Word الآن"), "الآن Microsoft Word إلى تصدير");
|
||||
assert_eq!(display_rtl("صالح لمدة 5 سنوات"), "سنوات 5 لمدة صالح");
|
||||
// Keyboard shortcuts are not reversed.
|
||||
assert_eq!(display_rtl("طباعة (⌘P)"), "(⌘P) طباعة");
|
||||
assert_eq!(display_rtl("تدوير العرض (⇧⌘+)"), "(⇧⌘+) العرض تدوير");
|
||||
assert_eq!(display_rtl("التمرير مع ⌘ أيضًا"), "أيضًا ⌘ مع التمرير");
|
||||
assert_eq!(display_rtl("نص (عادي)"), "(عادي) نص");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_labels_keep_placeholders_whole() {
|
||||
// Two placeholders around a colon stay together, left to right: a file name and its error.
|
||||
assert_eq!(display_rtl("تعذّر فتح {name}: {e}"), "{name}: {e} فتح تعذّر");
|
||||
assert_eq!(display_rtl("فشل {label}، السبب {e}"), "{e} السبب ،{label} فشل");
|
||||
assert_eq!(display_rtl("{n} صفحات"), "صفحات {n}");
|
||||
assert_eq!(display_rtl("الصفحة {p} من {n}"), "{n} من {p} الصفحة");
|
||||
// Adjacent placeholders keep their order, as numbers around a slash would.
|
||||
assert_eq!(display_rtl("جارٍ البحث… {s}/{p}"), "{s}/{p} …البحث جارٍ");
|
||||
// Braces that are not a placeholder are ordinary punctuation.
|
||||
assert_eq!(display_rtl("حرف } واحد"), "واحد { حرف");
|
||||
let many = format!("ا {}", "{a} ".repeat(200));
|
||||
assert_eq!(display_rtl(&many).matches("{a}").count(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_labels_keep_their_edges() {
|
||||
// Edge spaces and separator dots stay where the code concatenates.
|
||||
assert_eq!(display_rtl(" (صفحة {p})"), " ({p} صفحة)");
|
||||
assert_eq!(display_rtl(" · محمي بكلمة مرور"), " · مرور بكلمة محمي");
|
||||
assert_eq!(display_rtl("سلسلة المفاتيح · "), "المفاتيح سلسلة · ");
|
||||
// A caption's colon stays next to its widget; a sentence's colon ends the sentence.
|
||||
assert_eq!(display_rtl("الاسم:"), "الاسم:");
|
||||
assert_eq!(display_rtl("صادرة عن: "), "عن صادرة: ");
|
||||
assert_eq!(display_rtl("اختر المعرّف الرقمي الذي تريد استخدامه:"), ":استخدامه تريد الذي الرقمي المعرّف اختر");
|
||||
// Each line is its own paragraph.
|
||||
assert_eq!(display_rtl("تعذّر عرض الصفحة.\n{e}"), ".الصفحة عرض تعذّر\n{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rtl_labels_never_panic_on_odd_input() {
|
||||
let long = "ا {n} ".repeat(20_000);
|
||||
for s in [
|
||||
"ا{",
|
||||
"ا}",
|
||||
"ا{}",
|
||||
"ا{{{",
|
||||
"}ا{",
|
||||
"ا\u{E000}{n}",
|
||||
"⌘",
|
||||
"ا ⌘",
|
||||
"⌘ا⌘{",
|
||||
"ا (⇧⌘",
|
||||
"\u{064B}:",
|
||||
":",
|
||||
"ا:",
|
||||
" : ا : ",
|
||||
"ا\n\n\nب",
|
||||
"\u{202E}ا{n}",
|
||||
long.as_str(),
|
||||
] {
|
||||
let v = display_rtl(s);
|
||||
assert!(v.chars().count() <= s.chars().count(), "{:?}", s.chars().take(12).collect::<String>());
|
||||
}
|
||||
}
|
||||
|
||||
/// `wrap` with a width of `n` characters.
|
||||
fn wrap_at(text: &str, n: usize) -> Vec<Line> {
|
||||
wrap(text, |s| s.chars().count() <= n)
|
||||
@@ -252,89 +140,3 @@ fn egui_draws_lines_in_reading_order() {
|
||||
assert_eq!(on_screen("See واحد اثنين here"), [format!("See {} {} here", rev("اثنين"), rev("واحد"))]);
|
||||
assert_eq!(on_screen("واحد (اثنين)."), [format!(".({}) {}", rev("اثنين"), rev("واحد"))]);
|
||||
}
|
||||
|
||||
/// A file name keeps its extension at the visual end even when the first strong word is
|
||||
/// Arabic: with an explicit `LeftToRight` base, `.pdf` is right of every Arabic glyph.
|
||||
#[test]
|
||||
fn file_names_are_laid_out_left_to_right() {
|
||||
if pdfcraft_fonts::ui_arabic_fonts().is_empty() {
|
||||
return;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
ctx.set_fonts(crate::theme::font_definitions());
|
||||
let mut positions: Vec<(char, f32)> = Vec::new();
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
let galley = layout_ltr(ui, "واحد اثنين.pdf", egui::FontId::proportional(13.0), egui::Color32::WHITE);
|
||||
positions = galley.rows.iter().flat_map(|row| row.glyphs.iter().map(|g| (g.chr, g.pos.x))).collect();
|
||||
})
|
||||
.drop_without_applying_deltas();
|
||||
let rightmost_arabic = positions.iter().filter(|(c, _)| is_rtl_script(*c)).map(|(_, x)| *x).fold(f32::MIN, f32::max);
|
||||
let leftmost_extension = positions.iter().filter(|(c, _)| matches!(*c, '.' | 'p' | 'd' | 'f')).map(|(_, x)| *x).fold(f32::MAX, f32::min);
|
||||
assert!(rightmost_arabic < leftmost_extension, "the extension must stay to the right: {positions:?}");
|
||||
let last = positions.iter().filter(|(c, _)| !c.is_whitespace()).max_by(|a, b| a.1.total_cmp(&b.1));
|
||||
assert_eq!(last.map(|(c, _)| *c), Some('f'), "the painted line ends in the extension");
|
||||
}
|
||||
|
||||
/// Arabic/Kurdish labels get an explicit right-to-left paragraph, even when their first
|
||||
/// strong character is Latin. With English the same text stays left to right.
|
||||
#[test]
|
||||
fn arabic_ui_labels_use_an_explicit_paragraph_direction() {
|
||||
if pdfcraft_fonts::ui_arabic_fonts().is_empty() {
|
||||
return;
|
||||
}
|
||||
let previous = crate::i18n::current();
|
||||
let ctx = egui::Context::default();
|
||||
ctx.set_fonts(crate::theme::font_definitions());
|
||||
let read = |lang: &str| {
|
||||
crate::i18n::set_current(crate::i18n::Lang::from_code(lang).expect("registered language"));
|
||||
let mut got = None;
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
let galley = layout_ui(ui, "PDF واحد", egui::FontId::proportional(13.0), egui::Color32::WHITE);
|
||||
let positions: Vec<_> = galley.rows.iter().flat_map(|row| row.glyphs.iter().map(|g| (g.chr, g.pos.x))).collect();
|
||||
got = Some((galley.job.direction, positions));
|
||||
})
|
||||
.drop_without_applying_deltas();
|
||||
got.expect("one layout")
|
||||
};
|
||||
let (direction, positions) = read("ar");
|
||||
crate::i18n::set_current(previous);
|
||||
assert_eq!(direction, egui::epaint::text::TextDirection::RightToLeft);
|
||||
let p = positions.iter().find(|(c, _)| *c == 'P').map(|(_, x)| *x).expect("a Latin P");
|
||||
let rightmost_arabic = positions.iter().filter(|(c, _)| is_rtl_script(*c)).map(|(_, x)| *x).fold(f32::MIN, f32::max);
|
||||
assert!(p > rightmost_arabic, "in an RTL paragraph the first Latin run is at the right: {positions:?}");
|
||||
|
||||
let (direction, positions) = read("en");
|
||||
crate::i18n::set_current(previous);
|
||||
assert_eq!(direction, egui::epaint::text::TextDirection::Auto);
|
||||
let p = positions.iter().find(|(c, _)| *c == 'P').map(|(_, x)| *x).expect("a Latin P");
|
||||
let leftmost_arabic = positions.iter().filter(|(c, _)| is_rtl_script(*c)).map(|(_, x)| *x).fold(f32::MAX, f32::min);
|
||||
assert!(p < leftmost_arabic, "with English the Latin run stays at the left: {positions:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_line_with_its_own_direction() {
|
||||
assert!(matches!(visual_auto("Ada Lovelace"), Cow::Borrowed("Ada Lovelace")));
|
||||
assert_eq!(visual_auto("علی رضایی"), "رضایی علی");
|
||||
assert_eq!(visual_auto("علی 2"), "2 علی");
|
||||
assert_eq!(visual_auto("Team علی رضایی"), "Team رضایی علی");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn odd_input_never_panics() {
|
||||
let long = "ا ب ".repeat(20_000);
|
||||
let odd = [
|
||||
"\u{064B}",
|
||||
"\u{064B}\u{064C} \u{0301}",
|
||||
"\u{202E}\u{202E}\u{202E}ا",
|
||||
"\u{2067}ا\u{2066}b",
|
||||
"ا\nب\r\nج\u{2029}د",
|
||||
"\u{FEFF}ا\u{0000}ب",
|
||||
"ا\u{10FFFF}\u{E000}ب",
|
||||
"((((ا]]]]",
|
||||
long.as_str(),
|
||||
];
|
||||
for s in odd {
|
||||
let v = visual(s);
|
||||
assert!(v.chars().count() <= s.chars().count(), "{:?}", s.chars().take(12).collect::<String>());
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
|
||||
use egui::{Key, Modifiers};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_render::DestView;
|
||||
use pdfcraft_ui_egui::canvas::Fit;
|
||||
use pdfcraft_ui_egui::{OpenOutcome, PdfCraftApp, RightPanel};
|
||||
@@ -87,8 +88,8 @@ fn near(got: f32, want: f32, what: &str) {
|
||||
#[test]
|
||||
fn an_xyz_open_action_puts_its_point_at_the_window_top_left() {
|
||||
let mut h = harness("/OpenAction [5 0 R /XYZ 100 500 2]");
|
||||
assert_eq!(h.state().views[0].current, 2);
|
||||
assert_eq!((h.state().views[0].fit, h.state().views[0].zoom), (Fit::None, 2.0));
|
||||
assert_eq!(h.state().views[0].current(), 2);
|
||||
assert_eq!((h.state().views[0].fit(), h.state().views[0].zoom()), (Fit::None, 2.0));
|
||||
// `left`: the page sits 100 user points further left than one opened at left 0.
|
||||
let (left, scale) = page_left(&h, 2);
|
||||
let (left0, _) = page_left(&harness("/OpenAction [5 0 R /XYZ 0 500 2]"), 2);
|
||||
@@ -101,8 +102,8 @@ fn an_xyz_open_action_puts_its_point_at_the_window_top_left() {
|
||||
#[test]
|
||||
fn a_fith_open_action_puts_its_top_at_the_window_top() {
|
||||
let mut h = harness("/OpenAction [4 0 R /FitH 400]");
|
||||
assert_eq!(h.state().views[0].current, 1);
|
||||
assert_eq!(h.state().views[0].fit, Fit::Width);
|
||||
assert_eq!(h.state().views[0].current(), 1);
|
||||
assert_eq!(h.state().views[0].fit(), Fit::Width);
|
||||
let (page, top) = window_top(&mut h);
|
||||
assert_eq!(page, 1);
|
||||
near(top, 400.0, "y 400 is at the window's top edge");
|
||||
@@ -119,16 +120,16 @@ fn a_named_open_destination_opens_its_page() {
|
||||
"/OpenAction /there /Dests << /there [7 0 R /XYZ 0 792 0] >>",
|
||||
] {
|
||||
let mut h = harness(catalog);
|
||||
assert_eq!(h.state().views[0].current, 4, "{catalog}");
|
||||
assert_eq!(h.state().views[0].current(), 4, "{catalog}");
|
||||
// A zoom of 0 keeps the default zoom.
|
||||
assert_eq!(h.state().views[0].fit, Fit::Width, "{catalog}");
|
||||
assert_eq!(h.state().views[0].fit(), Fit::Width, "{catalog}");
|
||||
let (page, top) = window_top(&mut h);
|
||||
assert_eq!(page, 4, "{catalog}");
|
||||
near(top, 792.0, "the page's top is at the window's top edge");
|
||||
}
|
||||
// A name nothing defines opens on the first page.
|
||||
let h = harness("/OpenAction << /S /GoTo /D /missing >> /Dests << /there [7 0 R /Fit] >>");
|
||||
assert_eq!(h.state().views[0].current, 0);
|
||||
assert_eq!(h.state().views[0].current(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -144,8 +145,8 @@ fn always_my_default_view_keeps_the_zoom_and_goes_to_the_page_top() {
|
||||
});
|
||||
h.run_steps(4);
|
||||
settle(&mut h);
|
||||
assert_eq!(h.state().views[0].current, 2);
|
||||
assert_eq!(h.state().views[0].fit, Fit::Width);
|
||||
assert_eq!(h.state().views[0].current(), 2);
|
||||
assert_eq!(h.state().views[0].fit(), Fit::Width);
|
||||
let (page, top) = window_top(&mut h);
|
||||
assert_eq!(page, 2);
|
||||
near(top, 792.0, "the page's top");
|
||||
@@ -155,13 +156,13 @@ fn always_my_default_view_keeps_the_zoom_and_goes_to_the_page_top() {
|
||||
fn a_full_screen_document_shows_its_non_full_screen_panel_outside_full_screen() {
|
||||
for (mode, want) in [("UseThumbs", Some(RightPanel::Pages)), ("UseOC", Some(RightPanel::Layers)), ("UseNone", None)] {
|
||||
let mut h = harness(&format!("/PageMode /FullScreen /ViewerPreferences << /NonFullScreenPageMode /{mode} >>"));
|
||||
assert!(h.state().pending_full_screen.is_some(), "{mode}: full screen is asked for");
|
||||
// The prompt (`ask_full_screen`) is on the dialog host, found by its question.
|
||||
h.get_by_label("Open in Full Screen mode?");
|
||||
assert_eq!(h.state().right, want, "{mode}: the panel behind the prompt");
|
||||
// Declining it leaves that panel.
|
||||
let ctx = h.ctx.clone();
|
||||
h.state_mut().resolve_full_screen_prompt(&ctx, false);
|
||||
h.get_by_label("Not now").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!((h.state().full_screen, h.state().right), (false, want), "{mode}: declined");
|
||||
assert_eq!((h.state().full_screen(), h.state().right), (false, want), "{mode}: declined");
|
||||
// Entering and leaving full screen comes back to it.
|
||||
h.state_mut().apply_full_screen(true);
|
||||
h.run_steps(2);
|
||||
@@ -204,32 +205,45 @@ fn manual(test: &str) -> String {
|
||||
path.to_string_lossy().into_owned()
|
||||
}
|
||||
|
||||
/// A window with no document, in English.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn bare_window() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_file_named_with_open_parameters_opens_at_their_destination() {
|
||||
// #3425: a help system starts PdfCraft with `manual.pdf#nameddest=…`. Files named at launch
|
||||
// open before the first frame.
|
||||
// #3425: a help system starts PdfCraft with `manual.pdf#nameddest=…`.
|
||||
let path = manual("launch");
|
||||
for (parameters, page) in [("#nameddest=Load Flow", 3), ("#nameddest=intro", 1), ("#intro", 1), ("#page=5", 4), ("#zoom=200", 2)] {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
assert_eq!(app.open_path(&format!("{path}{parameters}")), OpenOutcome::Opened, "{parameters}");
|
||||
assert_eq!(app.views.len(), 1, "{parameters}");
|
||||
assert_eq!(app.views[0].current, page, "{parameters}");
|
||||
let mut h = bare_window();
|
||||
assert!(matches!(h.state_mut().open_path(&format!("{path}{parameters}")), OpenOutcome::Opened | OpenOutcome::Pending), "{parameters}");
|
||||
crate::support::wait_until(&mut h, "the manual", |app| app.views.len() == 1);
|
||||
assert_eq!(h.state().views.len(), 1, "{parameters}");
|
||||
assert_eq!(h.state().views[0].current(), page, "{parameters}");
|
||||
let app = h.state();
|
||||
assert_eq!(app.session.get(app.views[0].id).and_then(|d| d.path.clone()).as_deref(), Some(path.as_str()), "{parameters}: the file itself");
|
||||
assert_eq!(app.toast, None, "{parameters}");
|
||||
assert!(h.state().notices.posted().is_empty(), "{parameters}");
|
||||
}
|
||||
// A name the file doesn't define: it opens where it would have, and says so.
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
assert_eq!(app.open_path(&format!("{path}#nameddest=Nowhere")), OpenOutcome::Opened);
|
||||
assert_eq!(app.views[0].current, 2);
|
||||
assert!(app.toast.as_ref().is_some_and(|(text, _)| text.contains("named destination was not applied")), "{:?}", app.toast);
|
||||
let mut h = bare_window();
|
||||
assert!(matches!(h.state_mut().open_path(&format!("{path}#nameddest=Nowhere")), OpenOutcome::Opened | OpenOutcome::Pending));
|
||||
crate::support::wait_until(&mut h, "the manual", |app| app.views.len() == 1);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().views[0].current(), 2);
|
||||
assert!(!h.state().notices.posted().is_empty(), "the unapplied name is told");
|
||||
// A path that names no file, before a `#` or as a whole, still fails as before.
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
assert_eq!(app.open_path(&format!("{path}.missing#page=2")), OpenOutcome::Failed);
|
||||
assert!(app.views.is_empty());
|
||||
let mut h = bare_window();
|
||||
assert!(!matches!(h.state_mut().open_path(&format!("{path}.missing#page=2")), OpenOutcome::Opened | OpenOutcome::Focused));
|
||||
h.run_steps(4);
|
||||
assert!(h.state().views.is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -246,14 +260,14 @@ fn open_parameters_handed_to_the_running_app_show_their_destination() {
|
||||
// Asked twice before it has opened, it opens at the place asked for last.
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#page=5")), OpenOutcome::Pending);
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#nameddest=Load Flow")), OpenOutcome::Pending);
|
||||
crate::support::wait_until(&mut h, "the manual at Load Flow", |app| app.views.len() == 1 && app.views[0].current == 3);
|
||||
crate::support::wait_until(&mut h, "the manual at Load Flow", |app| app.views.len() == 1 && app.views[0].current() == 3);
|
||||
// Asked again for a place in the open file, its tab goes there instead of opening it again.
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#page=2")), OpenOutcome::Focused);
|
||||
assert_eq!((h.state().views.len(), h.state().views[0].current), (1, 1));
|
||||
assert_eq!((h.state().views.len(), h.state().views[0].current()), (1, 1));
|
||||
// A name is looked up off the UI thread: the tab moves once the lookup is in.
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#nameddest=Load Flow")), OpenOutcome::Focused);
|
||||
assert_eq!(h.state().views[0].current, 1, "not yet");
|
||||
crate::support::wait_until(&mut h, "Load Flow", |app| app.views[0].current == 3);
|
||||
assert_eq!(h.state().views[0].current(), 1, "not yet");
|
||||
crate::support::wait_until(&mut h, "Load Flow", |app| app.views[0].current() == 3);
|
||||
// A page asked for while a name is still being looked up wins: the lookup's answer is dropped.
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#nameddest=intro")), OpenOutcome::Focused);
|
||||
assert_eq!(h.state_mut().open_path(&format!("{path}#page=5")), OpenOutcome::Focused);
|
||||
@@ -261,17 +275,16 @@ fn open_parameters_handed_to_the_running_app_show_their_destination() {
|
||||
h.run_steps(1);
|
||||
std::thread::sleep(std::time::Duration::from_millis(20));
|
||||
}
|
||||
assert_eq!(h.state().views[0].current, 4);
|
||||
assert_eq!(h.state().views[0].current(), 4);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn open_parameters_wait_with_their_file_behind_a_password_prompt_and_a_full_queue() {
|
||||
// Launched with a protected file first and more files than the open worker queues at once:
|
||||
// the files past its bound wait their turn, and the later ones wait behind the password
|
||||
// prompt. A file named with open parameters keeps them while it waits, and named again, it
|
||||
// opens at the place asked for last; the protected file named again with them while its
|
||||
// password is asked for opens there once unlocked. They opened where they would have.
|
||||
// Launched with a protected file first and many files after it: the later ones wait behind
|
||||
// the password prompt. A file named with open parameters keeps them while it waits, and named
|
||||
// again, it opens at the place asked for last; the protected file named again with them while
|
||||
// its password is asked for opens there once unlocked. They opened where they would have.
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-open-parameters-queue-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
@@ -297,11 +310,17 @@ fn open_parameters_wait_with_their_file_behind_a_password_prompt_and_a_full_queu
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
assert!(h.state().password_prompt.is_some(), "the protected file is asked for");
|
||||
h.state_mut().submit_password(Some("reader".into()));
|
||||
h.get_by_label("Password required");
|
||||
// The password goes into the dialog's field and OK is pressed.
|
||||
// PLAN: the password field is found by its role; the OK button is the dialog's own (the last "Open" button)
|
||||
let field = h.get_by(|n| n.role() == egui::accesskit::Role::PasswordInput);
|
||||
field.focus();
|
||||
field.type_text("reader");
|
||||
h.run_steps(1);
|
||||
h.get_all_by_role_and_label(egui::accesskit::Role::Button, "Open").last().unwrap().click();
|
||||
crate::support::wait_until(&mut h, "every file", |app| app.views.len() == others.len() + 2);
|
||||
let app = h.state();
|
||||
let page_of = |path: &str| app.views.iter().find(|v| app.session.get(v.id).and_then(|d| d.path.as_deref()) == Some(path)).map(|v| v.current);
|
||||
let page_of = |path: &str| app.views.iter().find(|v| app.session.get(v.id).and_then(|d| d.path.as_deref()) == Some(path)).map(|v| v.current());
|
||||
// `fixture(NAMED)` opens at page 3 by its /OpenAction.
|
||||
assert_eq!(page_of(&manual), Some(4), "the file past the queue's bound, at the last page asked for");
|
||||
assert_eq!(page_of(&locked), Some(3), "the protected file, at the page asked for during its prompt");
|
||||
|
||||
@@ -36,13 +36,15 @@ fn pending_pages_use_document_reading_background() {
|
||||
app.views[0].go_to_page(page);
|
||||
// Draw the real canvas without finishing the render frame, so no texture can
|
||||
// race the assertion or hide the pending-page background.
|
||||
let mut textures = usize::MAX;
|
||||
let mut output =
|
||||
ctx.run_ui(RawInput { screen_rect: Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(900.0, 600.0))), ..Default::default() }, |ui| {
|
||||
pdfcraft_ui_egui::canvas::document_area(&mut app, 0, ui);
|
||||
let rect = ui.max_rect();
|
||||
textures = pdfcraft_ui_egui::canvas::document_area_at(&mut app, 0, rect, ui).textures.entries;
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
let view = &app.views[0];
|
||||
assert_eq!(view.raster_memory().page_count, 0, "the page must still be waiting for its raster");
|
||||
assert_eq!(textures, 0, "the page must still be waiting for its picture");
|
||||
let rect = view.page_screen_rect(page).expect("target page visible");
|
||||
let fill = output.shapes.iter().find_map(|s| match &s.shape {
|
||||
Shape::Rect(r) if r.rect == rect && r.stroke.width == 0.0 => Some(r.fill),
|
||||
@@ -84,16 +86,17 @@ fn reading_colours_preference_round_trips() {
|
||||
|
||||
// The choice survives a restart through the same path the settings file uses.
|
||||
let mut restored = PdfCraftApp::new();
|
||||
restored.restore(&h.state().persist());
|
||||
restored.apply_settings(&h.state().settings_snapshot());
|
||||
assert_eq!(restored.reading_colors, ReadingColors::WHITE_ON_BLACK);
|
||||
// A settings file without the field keeps Off.
|
||||
let restore = |app: &mut PdfCraftApp, json: &str| app.apply_settings(&pdfcraft_ui_egui::settings::import_json(json).0);
|
||||
let mut fresh = PdfCraftApp::new();
|
||||
fresh.restore(r#"{"theme": "dark"}"#);
|
||||
restore(&mut fresh, r#"{"theme": "dark"}"#);
|
||||
assert_eq!(fresh.reading_colors, ReadingColors::default());
|
||||
// A corrupt value fails to deserialize and falls back to Off instead of panicking.
|
||||
fresh.restore(r#"{"reading_colors": {"params": {"text": "zzz", "background": [0, 0, 0], "only_black": false, "line_art": true}}}"#);
|
||||
// A corrupt value falls back to Off instead of panicking.
|
||||
restore(&mut fresh, r#"{"reading_colors": {"params": {"text": "zzz", "background": [0, 0, 0], "only_black": false, "line_art": true}}}"#);
|
||||
assert_eq!(fresh.reading_colors, ReadingColors::default());
|
||||
fresh.restore(r#"{"reading_colors": 7}"#);
|
||||
restore(&mut fresh, r#"{"reading_colors": 7}"#);
|
||||
assert_eq!(fresh.reading_colors, ReadingColors::default());
|
||||
}
|
||||
|
||||
@@ -170,7 +173,7 @@ fn reading_colours_seed_on_open() {
|
||||
assert_eq!(h.state().session.reading_colors(signed), Some(ReadingColors::YELLOW_ON_BLACK));
|
||||
|
||||
// Created documents open through their own session calls too — a comment summary via
|
||||
// `open_created`, an image import via `open_created_bytes` — and seed the same way.
|
||||
// `open_created`, an image import via `open_new_document` — and seed the same way.
|
||||
h.state_mut().summarize_comments();
|
||||
let summary = h.state().views.last().unwrap().id;
|
||||
assert_ne!(summary, signed);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//! A document reloads when its file changes on disk (#431): a LaTeX or Typst build rewriting the
|
||||
//! open PDF. Here the watcher looks once per frame on the test's thread (`run_inline`); in the
|
||||
//! app a worker thread looks every quarter second.
|
||||
//! open PDF. Here the watcher is built inline and looks once per frame on the test's thread; in
|
||||
//! the app a worker thread looks every quarter second.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use egui_kittest::Harness;
|
||||
@@ -73,23 +74,45 @@ impl Drop for TempPdf {
|
||||
}
|
||||
}
|
||||
|
||||
fn harness(path: &str) -> Harness<'static, PdfCraftApp> {
|
||||
/// An app on a host whose jobs wait for the test (`ManualJobs`) and whose watcher looks inline
|
||||
/// on each pass.
|
||||
fn app_with(jobs: Arc<craft::host::ManualJobs>) -> PdfCraftApp {
|
||||
use craft::host::{AppInfo, Host, Wake};
|
||||
use craft::platform::clipboard::{Clipboard, SystemClipboard};
|
||||
use craft::platform::open::FileIntake;
|
||||
use craft::platform::watch::FileWatch;
|
||||
use pdfcraft_ui_egui::AppServices;
|
||||
let info = AppInfo { id: "pdfcraft", name: "PdfCraft", version: "0" };
|
||||
let host = Host::builder(info).jobs(jobs).files(Arc::new(craft::host::ScriptedFiles::new())).build();
|
||||
let (intake, _sender) = FileIntake::new(Wake::none());
|
||||
let watch = FileWatch::new(Wake::none()).inline();
|
||||
let services = AppServices::new(Wake::none(), Clipboard::new(SystemClipboard::new()), None, None, intake, watch);
|
||||
let mut app = PdfCraftApp::with_host(Arc::new(host), services);
|
||||
// The labels looked for are English, whatever the machine's language.
|
||||
app.set_option("language", "en").unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
/// A window over `app_with` whose open job has run.
|
||||
fn harness_with(path: &str, setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
|
||||
let path = path.to_owned();
|
||||
let jobs = Arc::new(craft::host::ManualJobs::new());
|
||||
let queue = jobs.clone();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
// The labels looked for are English, whatever the machine's language.
|
||||
app.set_option("language", "en").unwrap();
|
||||
// The labels below are English whatever the developer's system language is.
|
||||
app.set_option("language", "en").unwrap();
|
||||
app.run_inline = true;
|
||||
let mut app = app_with(jobs);
|
||||
setup(&mut app);
|
||||
app.open_path(&path);
|
||||
app
|
||||
});
|
||||
queue.run_all();
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn harness(path: &str) -> Harness<'static, PdfCraftApp> {
|
||||
harness_with(path, |_| {})
|
||||
}
|
||||
|
||||
fn pages(h: &Harness<'static, PdfCraftApp>) -> usize {
|
||||
let app = h.state();
|
||||
app.session.get(app.views[0].id).unwrap().info.pages.len()
|
||||
@@ -110,8 +133,8 @@ fn a_rebuilt_file_reloads_in_place_keeping_the_page_and_zoom() {
|
||||
let file = TempPdf::new("rebuild", &fixture(3));
|
||||
let mut h = harness(&file.path);
|
||||
let id = h.state().views[0].id;
|
||||
h.state_mut().views[0].fit = pdfcraft_ui_egui::canvas::Fit::None;
|
||||
h.state_mut().views[0].zoom = 1.5;
|
||||
h.state_mut().views[0].view.fit = craft::pages::Fit::None;
|
||||
h.state_mut().views[0].view.zoom = 1.5;
|
||||
h.state_mut().views[0].go_to_page(2);
|
||||
h.run_steps(4);
|
||||
file.rebuild(&fixture(4));
|
||||
@@ -120,14 +143,13 @@ fn a_rebuilt_file_reloads_in_place_keeping_the_page_and_zoom() {
|
||||
let app = h.state();
|
||||
assert_eq!(pages(&h), 4, "the new version shows");
|
||||
assert_eq!((app.views.len(), app.views[0].id), (1, id), "in the same tab");
|
||||
assert_eq!((app.views[0].current, app.views[0].zoom), (2, 1.5), "at the same page and zoom");
|
||||
assert_eq!((app.views[0].current(), app.views[0].zoom()), (2, 1.5), "at the same page and zoom");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
use pdfcraft_engine::{Edit, LabelStyle, Session};
|
||||
use pdfcraft_ui_egui::canvas::display_token;
|
||||
use std::sync::Arc;
|
||||
use craft::pages::display_token;
|
||||
|
||||
let labelled = |ranges: &[(usize, usize, LabelStyle)]| {
|
||||
let mut source = Session::new().with_clock(|| 1_700_000_000);
|
||||
@@ -148,7 +170,7 @@ fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
h.state_mut().set_option("page", "4").unwrap();
|
||||
h.run_steps(3);
|
||||
let view = &h.state().views[0];
|
||||
assert_eq!((view.current, display_token(view.layout, view.continuous())), (3, display));
|
||||
assert_eq!((view.current(), display_token(view.view.display, view.view.continuous)), (3, display));
|
||||
let doc = h.state().session.get(id).unwrap();
|
||||
assert_eq!(doc.bytes, original);
|
||||
assert!(!doc.dirty);
|
||||
@@ -179,8 +201,12 @@ fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
assert_eq!(doc.bytes, replacement, "the watcher loaded the replacement before checking navigation");
|
||||
assert_eq!((doc.info.pages.len(), doc.info.pages[3].label.as_str()), (5, "iv"));
|
||||
// First causal negative: a single-page reader must not become a continuous reader.
|
||||
assert_eq!((view.current, display_token(view.layout, view.continuous())), (3, display), "reload retains the physical page and display mode");
|
||||
assert_eq!(view.zoom, 1.0);
|
||||
assert_eq!(
|
||||
(view.current(), display_token(view.view.display, view.view.continuous)),
|
||||
(3, display),
|
||||
"reload retains the physical page and display mode"
|
||||
);
|
||||
assert_eq!(view.zoom(), 1.0);
|
||||
assert_eq!(view.page_input, "iv");
|
||||
assert_eq!(h.ctx.memory(|m| m.focused()), Some(editor));
|
||||
h.get(By::new().role(egui::accesskit::Role::TextInput).value("iv"));
|
||||
@@ -188,7 +214,7 @@ fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
// Keep the replacement editor's selection and then its caret, without re-focusing it.
|
||||
h.event(egui::Event::Text("2".into()));
|
||||
h.run_steps(2);
|
||||
assert_eq!((h.state().views[0].current, h.state().views[0].page_input.as_str()), (3, "2"));
|
||||
assert_eq!((h.state().views[0].current(), h.state().views[0].page_input.as_str()), (3, "2"));
|
||||
h.event(egui::Event::Text("x".into()));
|
||||
h.run_steps(1);
|
||||
assert_eq!(h.state().views[0].page_input, "2x");
|
||||
@@ -198,7 +224,7 @@ fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
let app = h.state();
|
||||
assert_eq!((app.views[0].id, app.views[0].current, app.views[0].page_input.as_str()), (id, 1, "ii"));
|
||||
assert_eq!((app.views[0].id, app.views[0].current(), app.views[0].page_input.as_str()), (id, 1, "ii"));
|
||||
let doc = app.session.get(id).unwrap();
|
||||
assert_eq!(doc.path.as_deref(), Some(file.path.as_str()));
|
||||
assert!(!doc.dirty);
|
||||
@@ -276,7 +302,7 @@ fn nothing_reloads_with_the_preference_off() {
|
||||
h.run_steps(4);
|
||||
assert_eq!(pages(&h), 2);
|
||||
let mut restarted = PdfCraftApp::new();
|
||||
restarted.restore(&h.state().persist());
|
||||
restarted.apply_settings(&h.state().settings_snapshot());
|
||||
assert!(!restarted.reload_changed_files, "the choice is kept");
|
||||
}
|
||||
|
||||
@@ -286,14 +312,17 @@ fn a_shorter_new_version_drops_what_pointed_into_the_old_one() {
|
||||
let mut h = harness(&file.path);
|
||||
h.state_mut().views[0].go_to_page(4);
|
||||
h.state_mut().views[0].select_pages(&[3, 4]);
|
||||
h.state_mut().views[0].comments.selected = Some((4, 0));
|
||||
h.run_steps(2);
|
||||
// Pick the last page's comment as a user does: its row in the Comments panel.
|
||||
h.get_all_by_label_contains("note").last().expect("a comment row").click();
|
||||
h.run_steps(2);
|
||||
file.rebuild(&fixture(1));
|
||||
h.run_steps(4);
|
||||
let view = &h.state().views[0];
|
||||
assert_eq!(pages(&h), 1);
|
||||
assert_eq!(view.current, 0, "the page is clamped");
|
||||
assert!(view.selected.is_empty() && view.comments.selected.is_none(), "no selection points past the new version");
|
||||
assert_eq!(view.current(), 0, "the page is clamped");
|
||||
// PLAN: assumed `comments.primary()` reads the selected comment (pdf-comments)
|
||||
assert!(view.selected.is_empty() && view.comments.primary().is_none(), "no selection points past the new version");
|
||||
}
|
||||
|
||||
/// Save asks before writing over a version of the file the document did not come from (#2166):
|
||||
@@ -330,16 +359,7 @@ fn saving_over_a_file_changed_by_something_else_asks_first() {
|
||||
#[test]
|
||||
fn saving_checks_the_file_with_the_watcher_off_too() {
|
||||
let file = TempPdf::new("overwrite-unwatched", &fixture(2));
|
||||
let path = file.path.clone();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.set_option("language", "en").unwrap();
|
||||
app.run_inline = true;
|
||||
app.reload_changed_files = false;
|
||||
app.open_path(&path);
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
let mut h = harness_with(&file.path, |app| app.reload_changed_files = false);
|
||||
rotate_first_page(&mut h);
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(3);
|
||||
@@ -373,7 +393,7 @@ fn a_file_rebuilt_under_an_open_dialog_reloads_when_the_dialog_closes() {
|
||||
// open would apply the dialog (Rotate, Protect, Comment Properties…) to the new version.
|
||||
let file = TempPdf::new("under-dialog", &fixture(2));
|
||||
let mut h = harness(&file.path);
|
||||
h.state_mut().dialog = Some(pdfcraft_ui_egui::Dialog::RotatePages);
|
||||
h.state_mut().set_option("dialog", "page.rotate_dialog").unwrap();
|
||||
h.run_steps(2);
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(4);
|
||||
@@ -381,7 +401,7 @@ fn a_file_rebuilt_under_an_open_dialog_reloads_when_the_dialog_closes() {
|
||||
file.rebuild(&fixture(5));
|
||||
h.run_steps(4);
|
||||
assert_eq!(pages(&h), 2, "still not replaced under the dialog");
|
||||
h.state_mut().dialog = None;
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!((pages(&h), dirty(&h)), (5, false), "the newest version is applied once the dialog closes");
|
||||
}
|
||||
@@ -392,12 +412,12 @@ fn a_version_held_under_preferences_is_dropped_when_reloading_is_turned_off_ther
|
||||
// change on disk" must not still apply the version found while it was open.
|
||||
let file = TempPdf::new("held-pref-off", &fixture(2));
|
||||
let mut h = harness(&file.path);
|
||||
h.state_mut().dialog = Some(pdfcraft_ui_egui::Dialog::RotatePages);
|
||||
h.state_mut().set_option("dialog", "preferences").unwrap();
|
||||
h.run_steps(2);
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(4);
|
||||
h.state_mut().reload_changed_files = false;
|
||||
h.state_mut().dialog = None;
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(pages(&h), 2, "reloading was turned off before the dialog closed");
|
||||
}
|
||||
@@ -409,7 +429,7 @@ fn a_newer_version_found_as_the_dialog_closes_replaces_the_held_one() {
|
||||
// edit generation: one is expected.
|
||||
let file = TempPdf::new("held-coalesced", &fixture(2));
|
||||
let mut h = harness(&file.path);
|
||||
h.state_mut().dialog = Some(pdfcraft_ui_egui::Dialog::RotatePages);
|
||||
h.state_mut().set_option("dialog", "page.rotate_dialog").unwrap();
|
||||
h.run_steps(2);
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(4);
|
||||
@@ -419,7 +439,7 @@ fn a_newer_version_found_as_the_dialog_closes_replaces_the_held_one() {
|
||||
h.step();
|
||||
let generation = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(h.state().views[0].id).unwrap().edit_generation();
|
||||
let before = generation(&h);
|
||||
h.state_mut().dialog = None;
|
||||
h.get_by_label("Cancel").click();
|
||||
h.step();
|
||||
assert_eq!((pages(&h), generation(&h) - before), (5, 1), "the held version is not loaded on the way");
|
||||
}
|
||||
@@ -430,12 +450,13 @@ fn a_file_rebuilt_under_the_full_screen_prompt_reloads_once_it_is_answered() {
|
||||
let file = TempPdf::new("under-full-screen", &fixture(2));
|
||||
let mut h = harness(&file.path);
|
||||
let id = h.state().views[0].id;
|
||||
h.state_mut().pending_full_screen = Some(id);
|
||||
// PLAN: assumed `ask_full_screen(id)` takes the document id (pdf-dialogs-w4)
|
||||
h.state_mut().ask_full_screen(id);
|
||||
h.run_steps(2);
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(4);
|
||||
assert_eq!(pages(&h), 2, "not replaced under the prompt");
|
||||
h.state_mut().pending_full_screen = None;
|
||||
h.get_by_label("Not now").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(pages(&h), 4, "applied once the prompt is gone");
|
||||
}
|
||||
|
||||
+225
-442
File diff suppressed because it is too large
Load Diff
@@ -185,7 +185,8 @@ fn f8_hides_the_interface_of_any_document_and_shows_it_again() {
|
||||
#[test]
|
||||
fn hiding_the_interface_is_never_saved() {
|
||||
let h = harness(|_| {}, &[HIDE_ALL]);
|
||||
let settings = h.state().persist();
|
||||
// PLAN: assumed the settings snapshot is `Serialize` (pdf-shell-w9)
|
||||
let settings = serde_json::to_string(&h.state().settings_snapshot()).unwrap();
|
||||
assert!(!settings.contains("interface"), "{settings}");
|
||||
}
|
||||
|
||||
@@ -194,7 +195,7 @@ fn opening_fit(catalog: &str, own_view: bool) -> Fit {
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.always_default_view = own_view;
|
||||
app.open_bytes("x.pdf", None, fixture(catalog)).unwrap();
|
||||
app.views[0].fit
|
||||
app.views[0].fit()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -214,7 +215,7 @@ fn one_page_at_a_time_opens_at_fit_page() {
|
||||
assert_eq!(opening_fit("/PageLayout /SinglePage /OpenAction [3 0 R /FitH 300]", false), Fit::Width);
|
||||
let mut app = PdfCraftApp::new();
|
||||
app.open_bytes("x.pdf", None, fixture("/PageLayout /SinglePage /OpenAction [3 0 R /XYZ 0 300 2]")).unwrap();
|
||||
assert_eq!((app.views[0].fit, app.views[0].zoom), (Fit::None, 2.0));
|
||||
assert_eq!((app.views[0].fit(), app.views[0].zoom()), (Fit::None, 2.0));
|
||||
}
|
||||
|
||||
/// Review on #4378: where the reader left off wins over the fit page a one-page-at-a-time
|
||||
@@ -224,11 +225,11 @@ fn a_remembered_zoom_wins_over_the_layouts_fit_page() {
|
||||
let path = std::env::temp_dir().join(format!("pdfcraft-viewer-prefs-last-view-{}.pdf", std::process::id())).to_string_lossy().into_owned();
|
||||
let mut app = PdfCraftApp::new();
|
||||
let json_path = serde_json::to_string(&path).unwrap();
|
||||
app.restore(&format!(r#"{{"last_views": [{{"path": {json_path}, "page": 1, "zoom": "62.5%", "display": "single"}}]}}"#));
|
||||
app.apply_settings(&pdfcraft_ui_egui::settings::import_json(&format!(r#"{{"last_views": [{{"path": {json_path}, "page": 1, "zoom": "62.5%", "display": "single"}}]}}"#)).0);
|
||||
assert!(app.restore_last_view);
|
||||
app.open_bytes("x.pdf", Some(path), fixture("/PageLayout /SinglePage")).unwrap();
|
||||
let v = &app.views[0];
|
||||
assert_eq!((v.fit, v.zoom, v.current), (Fit::None, 0.625, 1));
|
||||
assert_eq!((v.fit(), v.zoom(), v.current()), (Fit::None, 0.625, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -236,14 +237,17 @@ fn always_default_view_wins_over_a_remembered_view() {
|
||||
let path = std::env::temp_dir().join(format!("pdfcraft-viewer-prefs-always-default-{}.pdf", std::process::id())).to_string_lossy().into_owned();
|
||||
let mut app = PdfCraftApp::new();
|
||||
let json_path = serde_json::to_string(&path).unwrap();
|
||||
app.restore(&format!(
|
||||
r#"{{"last_views": [{{"path": {json_path}, "page": 1, "zoom": "62.5%", "display": "single"}}], "always_default_view": true}}"#
|
||||
));
|
||||
app.apply_settings(
|
||||
&pdfcraft_ui_egui::settings::import_json(&format!(
|
||||
r#"{{"last_views": [{{"path": {json_path}, "page": 1, "zoom": "62.5%", "display": "single"}}], "always_default_view": true}}"#
|
||||
))
|
||||
.0,
|
||||
);
|
||||
assert!(app.always_default_view);
|
||||
assert!(app.restore_last_view);
|
||||
app.open_bytes("x.pdf", Some(path), fixture("/PageLayout /SinglePage")).unwrap();
|
||||
let v = &app.views[0];
|
||||
assert_eq!((v.fit, v.layout, v.continuous(), v.current), (Fit::Width, pdfcraft_ui_egui::canvas::PageLayout::Single, true, 1));
|
||||
assert_eq!((v.fit(), v.view.display, v.view.continuous, v.current()), (Fit::Width, craft::pages::PageDisplay::Single, true, 1));
|
||||
}
|
||||
|
||||
/// The last `InnerSize` and `OuterPosition` asked for over `frames` frames.
|
||||
|
||||
Reference in New Issue
Block a user