mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Integration: fix the batch 27 CI failures (fmt, null Image Size percent)
- cargo fmt for the merged Tool list in paint_mouse.rs. - The #11516 fix refused an exported Image Size step with "percent": null, which main's review test treats as omitted. Native playback now omits a null percent like a null side or resolution, and export follows it, so both still agree. The null case moves from the invalid-percent test to a new native + round-trip test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a698d07214
commit
cf5347b545
5 files changed
+38
-4
No files matched your search
@@ -529,7 +529,7 @@ pub(super) fn image_size_to(_: &str, p: &Value) -> Option<Descriptor> {
|
||||
};
|
||||
// Native playback validates a supplied percentage even when explicit sides override it.
|
||||
// Dropping an invalid percentage would turn a refused action into a different, valid edit.
|
||||
if p.get("percent").is_some_and(|value| value.as_f64().is_none_or(|pc| !pc.is_finite() || pc <= 0.0)) {
|
||||
if p.get("percent").is_some_and(|value| !value.is_null() && value.as_f64().is_none_or(|pc| !pc.is_finite() || pc <= 0.0)) {
|
||||
return None;
|
||||
}
|
||||
// Resolution only with Resample on imports as keep-print-size; a command without it cannot be told apart.
|
||||
|
||||
@@ -3610,7 +3610,7 @@ fn image_size_explicit_sides_keep_precedence_over_percent() {
|
||||
|
||||
#[test]
|
||||
fn image_size_explicit_sides_do_not_hide_invalid_percent() {
|
||||
for percent in [json!(0), json!(-1), json!("50"), json!(false), json!(null)] {
|
||||
for percent in [json!(0), json!(-1), json!("50"), json!(false)] {
|
||||
let params = json!({"width": 20, "height": 18, "percent": percent, "resample": "nearest"});
|
||||
let mut native = Session::new();
|
||||
native.execute("file.new", json!({"width": 32, "height": 24})).unwrap();
|
||||
|
||||
@@ -257,7 +257,8 @@ fn image_size(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ph = scaled_dimension(p, "height", scale, "image.imageSize")?;
|
||||
}
|
||||
// `percent` scales both sides (what a Photoshop action records as "200%"); an explicit side wins.
|
||||
if let Some(pc) = p.get("percent") {
|
||||
// A null `percent` is omitted, like a null side or resolution.
|
||||
if let Some(pc) = p.get("percent").filter(|value| !value.is_null()) {
|
||||
let pc = pc.as_f64().filter(|v| v.is_finite() && *v > 0.0).ok_or_else(|| bad("image.imageSize", "`percent` must be a positive number"))?;
|
||||
pw = pw.or(Some(ow as f64 * pc / 100.0));
|
||||
ph = ph.or(Some(oh as f64 * pc / 100.0));
|
||||
|
||||
@@ -94,6 +94,31 @@ fn review_point_resize_exports_with_null_optional_values() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A null percentage is omitted at playback too, so an exported step and the native command agree.
|
||||
#[test]
|
||||
fn review_null_percent_is_omitted_by_the_native_resize() {
|
||||
for params in
|
||||
[json!({"width":72,"units":"pt","resample":"nearest","scaleStyles":false,"percent":null}), json!({"width":30,"resample":"nearest","percent":null})]
|
||||
{
|
||||
let mut without = params.clone();
|
||||
without.as_object_mut().unwrap().remove("percent");
|
||||
let mut expected = sized_document(20, 10, 144);
|
||||
expected.execute("image.imageSize", without).unwrap();
|
||||
let mut actual = sized_document(20, 10, 144);
|
||||
actual.execute("image.imageSize", params.clone()).expect("a null percent must not refuse the resize");
|
||||
assert_eq!(actual.active().unwrap().doc.size, expected.active().unwrap().doc.size);
|
||||
let action = Action::new("Recorded", vec![ActionStep::new("image.imageSize", params)]);
|
||||
let (bytes, skipped) = atn_cmds::export("Identifiers", &[&action], &[], false).unwrap();
|
||||
assert!(skipped.is_empty());
|
||||
let imported = atn_cmds::import(&bytes).unwrap();
|
||||
let mut replayed = sized_document(20, 10, 144);
|
||||
replayed.actions.list = ActionList::from_file(ActionsFile::new(imported.actions, Vec::new()));
|
||||
let result = replayed.execute("actions.play", json!({"action":"Recorded"})).unwrap();
|
||||
assert!(result.get("failed").is_none(), "{result}");
|
||||
assert_eq!(replayed.active().unwrap().doc.size, expected.active().unwrap().doc.size);
|
||||
}
|
||||
}
|
||||
|
||||
/// The native default resampler must be explicit in a physical-size recording.
|
||||
#[test]
|
||||
fn review_point_resize_exports_the_default_resampler() {
|
||||
|
||||
@@ -54,7 +54,15 @@ pub fn sync_tool_brush(app: &mut PhotocraftApp) {
|
||||
// start at 0° and off too, whatever the outgoing brush has (#12629).
|
||||
None if matches!(
|
||||
tool,
|
||||
Tool::BackgroundEraser | Tool::Healing | Tool::Burn | Tool::Dodge | Tool::Sponge | Tool::CloneStamp | Tool::Smudge | Tool::AdjustmentBrush | Tool::ArtHistoryBrush
|
||||
Tool::BackgroundEraser
|
||||
| Tool::Healing
|
||||
| Tool::Burn
|
||||
| Tool::Dodge
|
||||
| Tool::Sponge
|
||||
| Tool::CloneStamp
|
||||
| Tool::Smudge
|
||||
| Tool::AdjustmentBrush
|
||||
| Tool::ArtHistoryBrush
|
||||
) =>
|
||||
{
|
||||
fresh_brush(tool, ¤t)
|
||||
|
||||
Reference in new issue
Block a user