Merge PR #18265: Warp over type: the bar hides Split and lists Custom greyed, no None (#18262)

This commit is contained in:
David Mann committed 2026-11-30 23:55:06 +01:00
commit 717cecf674
3 files changed
+36 -7

No files matched your search

+3 -1
View File
@@ -442,8 +442,10 @@ fn target(s: &Session, cmd: &str, p: &Value) -> Result<(LayerId, Rect)> {
fn type_warp(cmd: &str, w: &Warp) -> Result<Option<photocraft_doc::text::TextWarp>> {
let clamp = |v: f64| if v.is_finite() { v.clamp(-100.0, 100.0) as f32 } else { 0.0 };
match w.style {
// A style with no bend or distortion is no Warp Text (#12499): over type the bar offers no
// None, so Bend, H and V at 0 is how a stored Warp Text is taken off.
WarpStyle::None => Ok(None),
WarpStyle::Custom if w.is_identity() => Ok(None),
_ if w.is_identity() => Ok(None),
WarpStyle::Custom => Err(bad(cmd, "type can only take a warp style (arc, flag, …); a custom mesh needs rasterized type")),
WarpStyle::Cylinder => Err(bad(cmd, "type can only take a warp style (arc, flag, …); a cylinder needs rasterized type")),
s => Ok(Some(photocraft_doc::text::TextWarp {
@@ -71,6 +71,28 @@ fn warp_style_on_type_is_warp_text() {
assert!(s.execute("edit.transform.warp", json!({"warp": Warp::custom(mesh, [0.0, 0.0, 10.0, 10.0])})).is_err());
}
/// A style at Bend, H and V 0 takes a stored Warp Text off (#12499): over type the bar offers no
/// None, so this is how the warp is removed. On unwarped type it changes nothing.
#[test]
fn an_unbent_style_on_type_removes_its_warp_text() {
let mut s = crate::session();
s.execute("file.new", json!({"width": 200, "height": 100})).unwrap();
s.execute("type.create", json!({"x": 10, "y": 60, "text": "Hi"})).unwrap();
let warp = |s: &crate::Session| {
let st = s.active().unwrap();
let LayerContent::Text(t) = &st.doc.layer(st.active_layer.unwrap()).unwrap().content else { panic!("type") };
t.warp.clone()
};
let r = s.execute("edit.transform.warp", json!({"style": "arc", "bend": 0})).unwrap();
assert_eq!(r["changed"], false, "unwarped type stays as it is");
s.execute("edit.transform.warp", json!({"style": "flag", "bend": 30})).unwrap();
assert!(warp(&s).is_some());
let n = s.active().unwrap().history.past_len();
s.execute("edit.transform.warp", json!({"style": "flag", "bend": 0})).unwrap();
assert!(warp(&s).is_none(), "the Warp Text is off");
assert_eq!(s.active().unwrap().history.past_len(), n + 1, "in one step");
}
/// The seven values of a cylinder over the session's painted box (x 10..60, y 10..40).
const CYL: [f64; 7] = [10.0, 40.0, 60.0, 10.0, 0.3, 0.3, 0.5];
@@ -133,12 +133,17 @@ fn ruler_texts(app: &PhotocraftApp) -> (RulerText, RulerText) {
}
/// The Warp menu's styles in Photoshop's order: None, Custom and the presets, then Cylinder
/// (#4112). Custom and Cylinder are not offered over type (#3004: Warp Text has neither), and a
/// cylinder has no splits or grid (its handles are its own).
/// (#4112). Over type, None and Cylinder are not offered and Custom is listed greyed (#3004: Warp
/// Text has neither Custom nor Cylinder; #12499: the reference lists Custom greyed and no None),
/// and a cylinder has no splits or grid (its handles are its own).
pub(super) fn style_entries() -> Vec<WarpStyleEntry> {
let entry = |s: WarpStyle| WarpStyleEntry::new(s.id(), s.label()).preset(s.is_preset());
WarpStyle::all()
.map(|s| if s == WarpStyle::Custom { entry(s).over_type(false) } else { entry(s) })
.map(|s| match s {
WarpStyle::None => entry(s).over_type(false),
WarpStyle::Custom => entry(s).greyed_over_type(true),
_ => entry(s),
})
.chain(std::iter::once(entry(WarpStyle::Cylinder).over_type(false).splits(false)))
.collect()
}
@@ -208,11 +213,11 @@ fn warp_edit(app: &mut PhotocraftApp, edit: WarpFieldsEdit) {
set_warp(app, next);
}
/// Back to the untouched box: the default one-patch grid over the box, no bend (over type, the
/// None style). One undo step through the session, and no Split tool armed.
/// Back to the untouched box: the default one-patch grid over the box, no bend (over type, Arc at
/// Bend 0, as Warp opens there, #12499). One undo step through the session, and no Split tool armed.
pub fn reset_warp(app: &mut PhotocraftApp) {
let Some((b, on_type)) = app.ui.transform.as_ref().and_then(|t| t.session.warp()).map(|w| (w.warp.bounds, w.on_type)) else { return };
set_warp(app, if on_type { Warp::none(b) } else { Warp::custom(BezierMesh::identity(b, 1, 1), b) });
set_warp(app, if on_type { Warp { style: WarpStyle::Arc, ..Warp::none(b) } } else { Warp::custom(BezierMesh::identity(b, 1, 1), b) });
if let Some(pv) = app.transform_preview.as_mut() {
pv.split = None;
}