mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
fix(ui): Fill & Sign font size resizes the selected text (#1274)
The Font size control on the Fill & Sign bar only set the size of text typed afterwards; text already placed and picked up kept its size, so the only way to resize it was to type it again. With a placed Fill & Sign text or date selected, a size typed into the control (or the end of a drag) now applies to it through Edit::FontSizeAnnotation, one undo step per change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RUNQSPVXx3dDBabRZHAnjz
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
924c4da4ac
commit
0b77f4cb77
@@ -4582,12 +4582,29 @@ fn quick_bar(app: &mut PdfCraftApp, area: Rect, ui: &mut egui::Ui) {
|
||||
});
|
||||
if matches!(current_fill, Some(crate::fill_sign::FillTool::Text | crate::fill_sign::FillTool::Date)) {
|
||||
ui.label(tl!("Font size:"));
|
||||
ui.add(
|
||||
let size = ui.add(
|
||||
egui::DragValue::new(&mut app.fill_text_size)
|
||||
.range(crate::fill_sign::MIN_TEXT_SIZE..=crate::fill_sign::MAX_TEXT_SIZE)
|
||||
.speed(0.25)
|
||||
.suffix(" pt"),
|
||||
);
|
||||
// #1274: the size also applies to the Fill & Sign text that is selected,
|
||||
// once per change (a typed value, or the end of a drag), so a drag adds
|
||||
// one undo step and not one per frame.
|
||||
if ((size.changed() && !size.dragged()) || size.drag_stopped())
|
||||
&& let Some((index, id)) = app.active_ids()
|
||||
&& let Some((page, annotation)) = app.views.get(index).and_then(|view| view.comments.selected)
|
||||
&& app.session.get(id).is_some_and(|doc| {
|
||||
doc.allows_annotation()
|
||||
&& doc
|
||||
.info
|
||||
.annotations
|
||||
.iter()
|
||||
.any(|a| a.page == page && a.index == annotation && a.fill_sign && a.subtype == "FreeText" && !a.locked)
|
||||
})
|
||||
{
|
||||
app.apply_edit(Edit::FontSizeAnnotation { page, index: annotation, size: app.fill_text_size });
|
||||
}
|
||||
}
|
||||
if let QuickTool::Comment(tool) = app.quick_tool {
|
||||
let (r, _) = ui.allocate_exact_size(vec2(32.0, 9.0), Sense::hover());
|
||||
|
||||
@@ -168,6 +168,60 @@ fn fill_text_size_controls_new_text_and_survives_settings_restore() {
|
||||
assert_eq!(restored.fill_text_size, 24.0, "invalid settings do not change the size");
|
||||
}
|
||||
|
||||
/// #1274: with a placed Fill & Sign text selected, the Font size control resizes that text,
|
||||
/// not only text typed afterwards; with nothing selected it changes nothing on the page.
|
||||
#[test]
|
||||
fn fill_text_size_resizes_the_selected_text() {
|
||||
let mut h = harness();
|
||||
h.state_mut().execute("sign.fill.text");
|
||||
click(&mut h, 50.0, 250.0);
|
||||
h.event(egui::Event::Text("Resize me".into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
let height = |h: &Harness<'static, PdfCraftApp>| {
|
||||
let s = h.state();
|
||||
let a = s.session.get(s.views[0].id).unwrap().info.annotations.iter().find(|a| a.contents.as_deref() == Some("Resize me")).cloned().unwrap();
|
||||
a.rect[3] - a.rect[1]
|
||||
};
|
||||
let before = height(&h);
|
||||
let set_size = |h: &mut Harness<'static, PdfCraftApp>, value: &str| {
|
||||
h.query_all_by_role(egui::accesskit::Role::SpinButton)
|
||||
.find(|n| n.value().is_some_and(|v| v.ends_with(" pt")))
|
||||
.expect("the Font size control")
|
||||
.click();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Text(value.into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(4);
|
||||
};
|
||||
// Nothing selected: only the size for new text changes.
|
||||
h.state_mut().views[0].comments.selected = None;
|
||||
set_size(&mut h, "18");
|
||||
assert_eq!(h.state().fill_text_size, 18.0);
|
||||
assert_eq!(height(&h), before, "an unselected placed text keeps its size");
|
||||
// The placed text picked up with the Add text tool, then resized.
|
||||
let annotation = {
|
||||
let s = h.state();
|
||||
s.session
|
||||
.get(s.views[0].id)
|
||||
.unwrap()
|
||||
.info
|
||||
.annotations
|
||||
.iter()
|
||||
.find(|a| a.contents.as_deref() == Some("Resize me"))
|
||||
.map(|a| (a.page, a.index))
|
||||
.unwrap()
|
||||
};
|
||||
h.state_mut().views[0].comments.selected = Some(annotation);
|
||||
set_size(&mut h, "36");
|
||||
assert_eq!(h.state().fill_text_size, 36.0);
|
||||
let after = height(&h);
|
||||
assert!(after > before * 2.0, "36 pt text has a taller box than 10 pt text: {before} -> {after}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_type_box_grows_as_text_is_typed() {
|
||||
let mut h = harness();
|
||||
|
||||
Reference in New Issue
Block a user