mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-16 23:34:01 +00:00
Merge pull request #2845 from gmrmad1/fix/2812-fitting-crop-units
Frame Fitting Options: crop amounts follow the document's ruler unit (#2812)
This commit is contained in:
4 files changed
+42
-6
No files matched your search
@@ -409,6 +409,12 @@ fn handle_request(app: &mut DesignApp, ctx: &egui::Context, req: &ControlRequest
|
||||
let d = match id {
|
||||
"frameSize" => crate::dialogs::frame_size_dialog(app, fields),
|
||||
"contactSheet" => crate::dialogs::contact_sheet_dialog(app, fields),
|
||||
"fittingOptions" => {
|
||||
let mut d = crate::dialogs::Dialog::new(id, fields);
|
||||
d.unit = app.session.active().map_or(designcraft_geom::Unit::Picas, |s| s.doc.settings.horizontal_units);
|
||||
d.vertical_unit = Some(d.unit);
|
||||
d
|
||||
}
|
||||
_ => crate::dialogs::Dialog::new(id, fields),
|
||||
};
|
||||
let v = serde_json::to_value(&d).unwrap_or_default();
|
||||
|
||||
@@ -4082,12 +4082,12 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {
|
||||
egui::Grid::new("ff_crop").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
|
||||
for (k, l) in [("cropTop", "Top:"), ("cropLeft", "Left:")] {
|
||||
crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
|
||||
text_field(ui, &mut d, k, 70.0);
|
||||
measure_field(ui, &mut d, k, 70.0);
|
||||
}
|
||||
ui.end_row();
|
||||
for (k, l) in [("cropBottom", "Bottom:"), ("cropRight", "Right:")] {
|
||||
crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
|
||||
text_field(ui, &mut d, k, 70.0);
|
||||
measure_field(ui, &mut d, k, 70.0);
|
||||
}
|
||||
ui.end_row();
|
||||
});
|
||||
@@ -5445,7 +5445,7 @@ fn confirm_part5(app: &mut DesignApp, d: Dialog) -> Result<Value, String> {
|
||||
json!({"path": d.s("path"), "removeStyles": d.b("removeStyles"), "styleConflicts": d.s("styleConflicts"), "styleMap": d.fields.get("map").cloned().unwrap_or(json!({}))}),
|
||||
),
|
||||
"fittingOptions" => {
|
||||
let m = |k: &str| d.fields.get(k).and_then(Value::as_str).and_then(|s| parse_measure(s, Unit::Points).ok()).unwrap_or(0.0);
|
||||
let m = |k: &str| d.m(k).unwrap_or(0.0);
|
||||
app.run(
|
||||
"object.fittingOptions",
|
||||
json!({"autoFit": d.b("autoFit"), "fitting": d.s("fitting"), "align": d.n("align").unwrap_or(4.0) as u64,
|
||||
|
||||
@@ -269,13 +269,17 @@ fn run_ui_part1(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value
|
||||
"app.fittingOptions" => {
|
||||
let g = app.session.active().and_then(|d| d.selection.items.first().and_then(|id| d.doc.item(*id)).and_then(|it| it.graphic().cloned()));
|
||||
let Some(g) = g else { return Some(Err("select a frame with a placed graphic".into())) };
|
||||
let unit = app.session.active().map(|d| d.doc.settings.horizontal_units).unwrap_or(designcraft_geom::Unit::Picas);
|
||||
let fitting = serde_json::to_value(g.auto_fit).unwrap_or(json!("none"));
|
||||
let c = |v: f64| json!(designcraft_geom::format_measure(v, designcraft_geom::Unit::Points));
|
||||
app.ui.dialog = Some(crate::dialogs::Dialog::new(
|
||||
let c = |v: f64| json!(designcraft_geom::format_measure(v, unit));
|
||||
let mut dialog = crate::dialogs::Dialog::new(
|
||||
"fittingOptions",
|
||||
json!({"autoFit": g.auto_fit != designcraft_doc::Fitting::None, "fitting": fitting, "align": g.fit_align,
|
||||
"cropTop": c(g.crop[0]), "cropLeft": c(g.crop[1]), "cropBottom": c(g.crop[2]), "cropRight": c(g.crop[3])}),
|
||||
));
|
||||
);
|
||||
dialog.unit = unit;
|
||||
dialog.vertical_unit = Some(unit);
|
||||
app.ui.dialog = Some(dialog);
|
||||
Ok(Value::Null)
|
||||
}
|
||||
"app.userDictionary" => {
|
||||
|
||||
@@ -986,6 +986,32 @@ fn fitting_has_indesigns_shortcuts() {
|
||||
assert!((width(&app) - 200.0).abs() < 1e-6, "fitted: {}", width(&app));
|
||||
}
|
||||
|
||||
/// Frame Fitting Options shows and reads its crop amounts in the document's ruler unit (#2812).
|
||||
#[test]
|
||||
fn fitting_options_follow_the_ruler_units() {
|
||||
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("document.preferences", json!({"horizontalUnits": "millimeters"})).unwrap();
|
||||
let png = designcraft_render::Rendered { width: 40, height: 20, pixels: vec![200; 40 * 20 * 4] }.to_png();
|
||||
let f = app.run("frame.create", json!({"rect": [100, 100, 300, 300]})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("file.place", json!({"base64": designcraft_engine::cmd::base64_encode(&png), "name": "a.png", "frame": f})).unwrap();
|
||||
app.run("selection.set", json!({"ids": [f]})).unwrap();
|
||||
run_ui(&mut app, "app.fittingOptions", &json!({})).unwrap().unwrap();
|
||||
let d = app.ui.dialog.as_ref().expect("Frame Fitting Options dialog");
|
||||
assert_eq!(d.id, "fittingOptions");
|
||||
assert_eq!(d.unit, designcraft_geom::Unit::Millimeters, "a bare number means the ruler unit");
|
||||
for k in ["cropTop", "cropLeft", "cropBottom", "cropRight"] {
|
||||
assert!(d.s(k).contains("mm"), "{k} is prefilled in millimetres, got {:?}", d.s(k));
|
||||
}
|
||||
// A bare number typed in a crop field is millimetres, not points.
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert("cropTop".into(), json!("2"));
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
let it = app.session.doc().unwrap().doc.item(designcraft_doc::ItemId(f)).unwrap().clone();
|
||||
let designcraft_doc::Content::Graphic(g) = &it.content else { panic!("placed graphic") };
|
||||
let want = 2.0 * designcraft_geom::units::PT_PER_MM;
|
||||
assert!((g.crop[0] - want).abs() < 1e-6, "cropTop 2 means 2 mm ({} pt), got {}", want, g.crop[0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_and_presentation_hide_floating_panels_too() {
|
||||
let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
|
||||
Reference in new issue
Block a user