mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
pdf-edit-w7: net change of 3 commits
- pdf-edit-w7: written by an agent - pdf-edit-w7: finished by an agent - pdf-edit-w7: review fixes (review-1)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -266,18 +266,15 @@ fn typing_moving_styling_and_deleting_added_content() {
|
||||
/// browser) places it on the current page, as Add Image does.
|
||||
#[test]
|
||||
fn a_picture_on_the_clipboard_is_pasted_onto_the_page() {
|
||||
use pdfcraft_ui_egui::Clip;
|
||||
// Three frames between modifier releases represent a short real key gesture.
|
||||
let mut h = harness_with_step_dt(1.0 / 60.0);
|
||||
let v = |pressed, modifiers| egui::Event::Key { key: egui::Key::V, physical_key: None, pressed, repeat: false, modifiers };
|
||||
let images = |h: &Harness<'static, PdfCraftApp>| added(h).iter().filter(|a| matches!(a.content, pdfcraft_engine::AddedContent::Image(_))).count();
|
||||
// Text on the clipboard: egui gets a Paste event instead of the press; nothing lands on the page.
|
||||
h.state_mut().clipboard_override = Some(Clip::Text("hello".into()));
|
||||
h.event(egui::Event::Paste("hello".into()));
|
||||
h.event(v(false, egui::Modifiers::COMMAND));
|
||||
h.run_steps(3);
|
||||
assert_eq!(images(&h), 0);
|
||||
h.state_mut().clipboard_override = Some(Clip::Image { width: 30, height: 20, rgba: [90u8, 90, 90, 255].repeat(30 * 20) });
|
||||
// A plain V comes through pressed and released: it picks the Select tool, it doesn't paste.
|
||||
h.event(v(true, egui::Modifiers::NONE));
|
||||
h.run_steps(1);
|
||||
@@ -682,115 +679,13 @@ fn released_text_does_not_jump_back_before_the_page_is_redrawn() {
|
||||
assert!(new > 20 && old == 0, "the redrawn page has the text in its new place ({old} old, {new} new)");
|
||||
}
|
||||
|
||||
/// Format text is laid out as Acrobat's: alignment from its flyout, style buttons by name, and
|
||||
/// the controls PdfCraft can't apply yet present but disabled.
|
||||
/// Format text lines its rows up (#3037): the size list is centred beside the colour swatch and
|
||||
/// the alignment button and is as tall as the font list, each spacing row's controls share one
|
||||
/// line, and nothing reaches past the font list, which spans the panel.
|
||||
/// Format text sets the armed Add text style through its labelled controls: an alignment chosen
|
||||
/// from the flyout and a style button each land in `text_style`.
|
||||
#[test]
|
||||
fn format_text_rows_line_up_and_fit_the_panel() {
|
||||
use egui::accesskit::Role;
|
||||
fn format_text_panel_sets_alignment_and_bold_for_the_armed_style() {
|
||||
let mut h = harness();
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("FORMAT TEXT");
|
||||
let combo = |h: &Harness<'static, PdfCraftApp>, value: &str| {
|
||||
h.query_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some(value)).map(|n| n.rect()).expect(value)
|
||||
};
|
||||
let (font, size) = (combo(&h, "Helvetica"), h.get_by_label("Font size:").rect());
|
||||
let middle = |r: egui::Rect| r.center().y;
|
||||
for label in ["Colour", "Alignment"] {
|
||||
let other = h.get_by_label(label).rect();
|
||||
assert!((middle(size) - middle(other)).abs() < 0.5, "the size list ({size:?}) is centred with {label} ({other:?})");
|
||||
}
|
||||
assert_eq!(size.height(), font.height(), "the font and size lists are the same height");
|
||||
// Line and paragraph spacing; scale and character spacing with their lists.
|
||||
let line = [combo(&h, "Auto"), combo(&h, "0")];
|
||||
assert!((middle(line[0]) - middle(line[1])).abs() < 0.5, "{line:?}");
|
||||
// Each: its number field and the arrow that lists common values.
|
||||
let scale_row: Vec<egui::Rect> =
|
||||
["Horizontal scale", "Character spacing"].iter().flat_map(|l| h.query_all_by_label(l).map(|n| n.rect())).collect();
|
||||
assert_eq!(scale_row.len(), 4, "two fields and their two arrows: {scale_row:?}");
|
||||
for r in &scale_row {
|
||||
assert!((middle(*r) - middle(scale_row[0])).abs() < 0.5, "{scale_row:?}");
|
||||
}
|
||||
for r in h.query_all_by_role(Role::ComboBox).map(|n| n.rect()).chain(scale_row).chain([size, h.get_by_label("Font size").rect()]) {
|
||||
assert!(r.right() <= font.right() + 0.5, "{r:?} reaches past the panel ({font:?})");
|
||||
}
|
||||
}
|
||||
|
||||
/// The Tools pane can't be dragged narrower than Format text needs: at its smallest width no
|
||||
/// control reaches past the font list, which spans the panel.
|
||||
#[test]
|
||||
fn format_text_fits_the_tools_pane_at_its_narrowest() {
|
||||
use egui::accesskit::Role;
|
||||
let mut h = harness();
|
||||
// At the largest interface size too: it scales points to pixels, and the layout is in points.
|
||||
h.state_mut().set_option("ui-scale", "300").unwrap();
|
||||
h.state_mut().side_panels.tools_width = 0.0;
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(3);
|
||||
let font = h.query_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some("Helvetica")).map(|n| n.rect()).expect("the font list");
|
||||
let rects = ["Alignment", "Colour", "Font size", "Character spacing", "Horizontal scale", "Line spacing", "Paragraph spacing"]
|
||||
.into_iter()
|
||||
.flat_map(|l| h.query_all_by_label(l).map(move |n| (l, n.rect())))
|
||||
.chain(h.query_all_by_role(Role::ComboBox).map(|n| ("list", n.rect())))
|
||||
.collect::<Vec<_>>();
|
||||
for (label, r) in rects {
|
||||
assert!(r.right() <= font.right() + 0.5, "{label} {r:?} reaches past the font list ({font:?})");
|
||||
}
|
||||
// The font list ends where the pane's own content does: the header's Close button is its right edge.
|
||||
let close = h.get_by_label("Close panel").rect();
|
||||
assert!((font.right() - close.right()).abs() < 1.5, "the font list {font:?} is not at the pane's content edge ({close:?})");
|
||||
// The rows below scroll, and the scrollbar floats over their right edge: they stop short of it.
|
||||
let image = h.get_by_label("Image").rect();
|
||||
assert!(image.right() <= font.right() - 17.0, "the Image row {image:?} runs under the scrollbar ({font:?})");
|
||||
// The right-hand column ends where the font list does, as the left one starts where it does.
|
||||
for label in ["Paragraph spacing", "Character spacing"] {
|
||||
let right = h.query_all_by_label(label).map(|n| n.rect().right()).fold(f32::MIN, f32::max);
|
||||
assert!((right - font.right()).abs() < 1.5, "{label} ends at {right}, the font list at {}", font.right());
|
||||
}
|
||||
}
|
||||
|
||||
/// The lists and the size row in Format text fit the narrowest Tools pane in every interface
|
||||
/// language: "Auto" in the line spacing list and "Mixed" in the size field are translated, and in
|
||||
/// Czech or French they are much longer. The font list spans the pane, so nothing may end past it.
|
||||
#[test]
|
||||
fn format_text_lists_fit_the_narrowest_tools_pane_in_every_language() {
|
||||
use egui::accesskit::Role;
|
||||
for lang in pdfcraft_ui_egui::i18n::Lang::all() {
|
||||
let mut h = harness();
|
||||
// A script with no face on this machine (Lao without system fonts) can't be drawn at all.
|
||||
if !h.ctx.fonts_mut(|f| f.has_glyphs(&egui::FontId::proportional(13.0), lang.name())) {
|
||||
continue;
|
||||
}
|
||||
h.state_mut().set_option("language", lang.code()).unwrap();
|
||||
h.state_mut().side_panels.tools_width = 0.0;
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(3);
|
||||
let lists: Vec<egui::Rect> = h.query_all_by_role(Role::ComboBox).map(|n| n.rect()).collect();
|
||||
// Found by its value (a font name, never translated), not as the widest list: an overrun
|
||||
// could make another list the widest.
|
||||
let font = h.query_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some("Helvetica")).map(|n| n.rect()).expect("the font list");
|
||||
for r in &lists {
|
||||
assert!(r.right() <= font.right() + 0.5, "{}: {r:?} reaches past the font list ({font:?})", lang.code());
|
||||
}
|
||||
// The size row too: its field reserves room for a translated "Mixed".
|
||||
let align = h.get_by_label(pdfcraft_ui_egui::i18n::t("Alignment")).rect();
|
||||
assert!(align.right() <= font.right() + 0.5, "{}: Alignment {align:?} reaches past the font list ({font:?})", lang.code());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_text_panel_sets_alignment_and_lists_planned_controls_disabled() {
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let mut h = harness();
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("FORMAT TEXT");
|
||||
for planned in ["Bulleted list", "Numbered list", "Superscript", "Subscript"] {
|
||||
assert!(h.get_by_label(planned).accesskit_node().is_disabled(), "{planned} is shown but disabled");
|
||||
}
|
||||
h.get_by_label("Alignment").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Centre").click();
|
||||
@@ -850,19 +745,13 @@ fn the_text_editor_aligns_a_narrow_box_to_its_own_edge() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Added text takes character spacing from Format text (#4245), typed like a paragraph's; its
|
||||
/// line spacing and horizontal scale stay disabled until added text has them.
|
||||
/// Added text takes character spacing from Format text (#4245), typed into its field in points.
|
||||
#[test]
|
||||
fn format_text_sets_character_spacing_for_added_text() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let mut h = harness();
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(3);
|
||||
let disabled = |h: &Harness<'static, PdfCraftApp>, label: &str| h.get_by_role_and_label(Role::SpinButton, label).accesskit_node().is_disabled();
|
||||
assert!(disabled(&h, "Horizontal scale"), "added text has no scale yet");
|
||||
assert!(!disabled(&h, "Character spacing"), "added text takes character spacing");
|
||||
h.get_by_role_and_label(Role::SpinButton, "Character spacing").click();
|
||||
h.get_by_label("Character spacing").click();
|
||||
h.run_steps(2);
|
||||
h.event(egui::Event::Text("2.5".into()));
|
||||
h.run_steps(1);
|
||||
@@ -1679,26 +1568,6 @@ fn image_context_menu_requires_visible_body_even_when_the_frame_crosses_the_page
|
||||
}
|
||||
}
|
||||
|
||||
/// The rail's page and zoom fields are the same size, and each sits wholly inside the rail, so
|
||||
/// neither box is cut off at the edge (the page box lost its right side once the rail's contents
|
||||
/// changed width).
|
||||
#[test]
|
||||
fn rail_page_and_zoom_fields_match_and_fit_the_rail() {
|
||||
let mut h = harness();
|
||||
h.run_steps(3);
|
||||
// The rail is 49 pt wide at the window's right edge (1400 pt wide), inside a 1 pt border.
|
||||
let (rail_left, rail_right) = (1400.0 - 49.0 + 1.0, 1400.0 - 1.0);
|
||||
let rail = h.get_by_label("Bookmarks").rect();
|
||||
let (page, zoom) = (h.get_by_label("Current page").rect(), h.get_by_label("Zoom").rect());
|
||||
assert_eq!((page.width(), page.height()), (zoom.width(), zoom.height()), "{page:?} vs {zoom:?}");
|
||||
// The size `RAIL_FIELD_SIZE` sets: wide enough for "6400%", the largest zoom.
|
||||
assert_eq!((page.width(), page.height()), (42.0, 22.0), "{page:?}");
|
||||
for r in [page, zoom] {
|
||||
assert!(r.left() >= rail_left && r.right() <= rail_right, "{r:?} is cut off by the rail ({rail_left}..{rail_right})");
|
||||
assert!((r.center().x - rail.center().x).abs() < 1.0, "{r:?} is off the rail's centre ({rail:?})");
|
||||
}
|
||||
}
|
||||
|
||||
/// Added text, typed and selected with Done.
|
||||
fn selected_added_text() -> Harness<'static, PdfCraftApp> {
|
||||
let mut h = harness();
|
||||
@@ -1720,8 +1589,7 @@ fn selected_added_text() -> Harness<'static, PdfCraftApp> {
|
||||
fn delete_and_escape_under_a_dialog_leave_the_selected_added_text() {
|
||||
for key in [egui::Key::Delete, egui::Key::Escape] {
|
||||
let mut h = selected_added_text();
|
||||
h.state_mut().dialog = Some(pdfcraft_ui_egui::Dialog::Shortcuts);
|
||||
h.run_steps(3);
|
||||
crate::support::open_shortcuts_from_the_help_menu(&mut h);
|
||||
h.key_press(key);
|
||||
h.run_steps(3);
|
||||
assert_eq!(added(&h).len(), 1, "{key:?} under a dialog deletes nothing");
|
||||
@@ -1730,6 +1598,30 @@ fn delete_and_escape_under_a_dialog_leave_the_selected_added_text() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Escape on a new box adds nothing, and a press on the page's background keeps the typed text as
|
||||
/// one item: the editor is told `esc_commits(false)`.
|
||||
#[test]
|
||||
fn an_escape_on_a_new_box_adds_nothing_and_a_background_press_commits_one_text() {
|
||||
let mut h = harness();
|
||||
assert!(h.state_mut().execute("edit.text"));
|
||||
h.run_steps(2);
|
||||
let p = at(&h, 40.0, 300.0);
|
||||
click(&mut h, p);
|
||||
h.event(egui::Event::Text("Dropped".into()));
|
||||
h.run_steps(2);
|
||||
assert!(h.state().views[0].content.draft.is_some(), "the box is open");
|
||||
h.key_press(egui::Key::Escape);
|
||||
h.run_steps(3);
|
||||
assert!(h.state().views[0].content.draft.is_none(), "Escape closes the box");
|
||||
assert!(added(&h).is_empty(), "Escape saves nothing");
|
||||
click(&mut h, p);
|
||||
h.event(egui::Event::Text("Kept".into()));
|
||||
h.run_steps(2);
|
||||
let elsewhere = at(&h, 40.0, 100.0);
|
||||
click(&mut h, elsewhere);
|
||||
assert_eq!(texts(&h), vec!["Kept".to_string()], "the background press commits the typed text once");
|
||||
}
|
||||
|
||||
/// The Escape that closes a dialog opened from a menu while added text is being typed is the
|
||||
/// dialog's: the typing stays, in the editor or added to the page. It was thrown away.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user