Merge pull request #253 from theironchef/fix/area-type-frame-offset

Type tools: a dragged area-type frame is the dragged rectangle
This commit is contained in:
BFlat 2026-10-07 10:55:41 +07:00 committed by GitHub
commit 24f7d5fba5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -328,6 +328,23 @@ fn select_all_and_cut_like_ui() {
assert_eq!(obj(&s, id).plain_text(), "abc defabc def");
}
#[test]
fn a_frame_dragged_with_the_type_tools_is_the_dragged_rectangle() {
for tool in ["type", "verticalType"] {
let mut s = session();
let v = ViewInfo::default();
s.select_tool(tool, v).unwrap();
for (k, x, y) in [(PointerKind::Down, 100.0, 100.0), (PointerKind::Drag, 300.0, 180.0), (PointerKind::Up, 300.0, 180.0)] {
s.pointer(&PointerEvent::new(k, x, y), v).unwrap();
}
let t = obj(&s, s.doc().unwrap().selection.objects[0]);
let TextKind::Area { frame } = &t.kind else { panic!("{tool}: not area type") };
let b = frame.bounds().unwrap();
let (a, z) = (t.xf * Point::new(b.x0, b.y0), t.xf * Point::new(b.x1, b.y1));
assert!((a - Point::new(100.0, 100.0)).hypot() < 1e-9 && (z - Point::new(300.0, 180.0)).hypot() < 1e-9, "{tool}: {a:?} {z:?}");
}
}
#[test]
fn area_type_from_a_circle_keeps_glyphs_inside() {
let mut s = session();

View File

@ -271,7 +271,7 @@ impl TypeTool {
}
let area = drag.map(|d| Rect::from_points(start, d)).filter(|r| r.width() > cx.tol(6.0) && r.height() > cx.tol(6.0));
let mut params = match area {
Some(r) => json!({"x": r.x0, "y": r.y0 + 12.0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
Some(r) => json!({"x": r.x0, "y": r.y0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
None => json!({"x": start.x, "y": start.y, "text": ""}),
};
params["vertical"] = json!(self.vertical);