diff --git a/AGENTS.md b/AGENTS.md
index e44dbe32a8..6adc5923db 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -131,7 +131,6 @@ Then append a terse entry to `log/devlog.md` (what landed, numbers, what's still
- `../craftrules/release/playbook.md`: how every storytold app builds signed release binaries (the canonical recipe; `docs/release-playbook.md` just points there); `docs/releasing.md` is PhotoCraft's specifics.
- `plan/` (local, gitignored): research, parity plan, execution plan, estimates.
- `log/` (local, gitignored): the dev log.
--
## 8. Keeping the native format complete
diff --git a/Cargo.lock b/Cargo.lock
index 6820d6dee5..e7bfc1112c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -550,12 +550,48 @@ dependencies = [
"arrayvec",
]
+[[package]]
+name = "aws-lc-rs"
+version = "1.18.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "faac5829c2b74c28f830747e7818ccfb684261b5f48a1118b1e2a13d36dfab13"
+dependencies = [
+ "aws-lc-sys",
+ "untrusted 0.7.1",
+ "zeroize",
+]
+
+[[package]]
+name = "aws-lc-sys"
+version = "0.46.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1622d8446a2d4b2ce0c7eefc73dd43a99779028d5ee5c2dd8073a658ba8a2bc"
+dependencies = [
+ "cc",
+ "cmake",
+ "dunce",
+ "fs_extra",
+ "pkg-config",
+]
+
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+[[package]]
+name = "base64"
+version = "0.23.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
+
+[[package]]
+name = "base64ct"
+version = "1.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
+
[[package]]
name = "bindgen"
version = "0.72.1"
@@ -645,7 +681,7 @@ dependencies = [
"cc",
"cfg-if",
"constant_time_eq",
- "cpufeatures",
+ "cpufeatures 0.3.1",
]
[[package]]
@@ -654,6 +690,15 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
+[[package]]
+name = "block-buffer"
+version = "0.10.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "block2"
version = "0.5.1"
@@ -804,7 +849,7 @@ dependencies = [
"maybe-owned",
"rustix 1.1.5",
"rustix-linux-procfs",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
"winx",
]
@@ -885,7 +930,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
dependencies = [
"cfg-if",
- "cpufeatures",
+ "cpufeatures 0.3.1",
"rand_core 0.10.1",
]
@@ -896,8 +941,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
dependencies = [
"iana-time-zone",
+ "js-sys",
"num-traits",
"serde",
+ "wasm-bindgen",
"windows-link",
]
@@ -973,6 +1020,39 @@ dependencies = [
"error-code",
]
+[[package]]
+name = "cmake"
+version = "0.1.58"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
+dependencies = [
+ "cc",
+]
+
+[[package]]
+name = "cmpv2"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "961b955a666e25ee5a1091d219128d6e6401e3dab84efb1a2bf6b4035d797b39"
+dependencies = [
+ "crmf",
+ "der",
+ "spki",
+ "x509-cert",
+]
+
+[[package]]
+name = "cms"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730"
+dependencies = [
+ "const-oid",
+ "der",
+ "spki",
+ "x509-cert",
+]
+
[[package]]
name = "codespan-reporting"
version = "0.13.1"
@@ -1028,6 +1108,12 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "const-oid"
+version = "0.9.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
+
[[package]]
name = "constant_time_eq"
version = "0.4.2"
@@ -1103,6 +1189,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "core_detect"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
+
[[package]]
name = "core_maths"
version = "0.1.1"
@@ -1112,6 +1204,15 @@ dependencies = [
"libm",
]
+[[package]]
+name = "cpufeatures"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "cpufeatures"
version = "0.3.1"
@@ -1124,9 +1225,14 @@ dependencies = [
[[package]]
name = "craft-print"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=d991bf6792f8ade99c51358bf3c1d902c8cd96b5#d991bf6792f8ade99c51358bf3c1d902c8cd96b5"
+source = "git+https://github.com/storytold/craft-libs?rev=3d37da389a3618ab9b76109da11416e9ca4ea719#3d37da389a3618ab9b76109da11416e9ca4ea719"
dependencies = [
+ "craft-winprint-gdi",
+ "miniz_oxide 0.8.9",
+ "roxmltree",
"tempfile",
+ "winprint",
+ "winsafe",
]
[[package]]
@@ -1138,6 +1244,14 @@ dependencies = [
"serde",
]
+[[package]]
+name = "craft-winprint-gdi"
+version = "0.1.0"
+source = "git+https://github.com/storytold/winprint.rs?rev=417ac3c4d14d3da5485a99c7d5ce8f05664ec312#417ac3c4d14d3da5485a99c7d5ce8f05664ec312"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "crc32fast"
version = "1.5.2"
@@ -1181,6 +1295,18 @@ dependencies = [
"itertools 0.10.5",
]
+[[package]]
+name = "crmf"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36fe21b96d5b87f5de4b5b7202ec41c00110ac817ce6728fe75fb2fe5962ed92"
+dependencies = [
+ "cms",
+ "der",
+ "spki",
+ "x509-cert",
+]
+
[[package]]
name = "crossbeam-channel"
version = "0.5.17"
@@ -1221,6 +1347,16 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
+[[package]]
+name = "crypto-common"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
+dependencies = [
+ "generic-array",
+ "typenum",
+]
+
[[package]]
name = "cursor-icon"
version = "1.2.0"
@@ -1267,6 +1403,30 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
+[[package]]
+name = "der"
+version = "0.7.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
+dependencies = [
+ "const-oid",
+ "der_derive",
+ "flagset",
+ "pem-rfc7468",
+ "zeroize",
+]
+
+[[package]]
+name = "der_derive"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "dify"
version = "0.8.0"
@@ -1280,6 +1440,16 @@ dependencies = [
"rayon",
]
+[[package]]
+name = "digest"
+version = "0.10.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
+dependencies = [
+ "block-buffer",
+ "crypto-common",
+]
+
[[package]]
name = "dispatch"
version = "0.2.0"
@@ -1394,6 +1564,12 @@ dependencies = [
"linux-raw-sys 0.9.4",
]
+[[package]]
+name = "dunce"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
+
[[package]]
name = "dyn-clone"
version = "1.0.20"
@@ -1578,6 +1754,20 @@ dependencies = [
"serde",
]
+[[package]]
+name = "encoding_rs"
+version = "0.8.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"
+dependencies = [
+ "cfg-if",
+ "core_detect",
+ "multiversion_no_op",
+ "rustversion",
+ "scopeguard",
+ "simdutf8",
+]
+
[[package]]
name = "endi"
version = "1.1.1"
@@ -1701,7 +1891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -1797,6 +1987,16 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693"
+[[package]]
+name = "filetime"
+version = "0.2.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759"
+dependencies = [
+ "cfg-if",
+ "libc",
+]
+
[[package]]
name = "find-msvc-tools"
version = "0.1.14"
@@ -1809,6 +2009,12 @@ version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99"
+[[package]]
+name = "flagset"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe"
+
[[package]]
name = "flate2"
version = "1.1.10"
@@ -1826,6 +2032,28 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
+[[package]]
+name = "fmt-derive"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1cb4a4b45c26455885f8b462db12978e51f60cc914337bccb9a36faf93410169"
+dependencies = [
+ "fmt-derive-proc",
+]
+
+[[package]]
+name = "fmt-derive-proc"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7704da0760734344ce8753f15b21e97c6be85dc5a8f2c3a963fbd042b3380d23"
+dependencies = [
+ "proc-macro-crate",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "fmv-macos-events"
version = "0.1.0"
@@ -1948,6 +2176,12 @@ dependencies = [
"windows-sys 0.59.0",
]
+[[package]]
+name = "fs_extra"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
+
[[package]]
name = "futures"
version = "0.3.34"
@@ -2073,6 +2307,16 @@ dependencies = [
"libc",
]
+[[package]]
+name = "generic-array"
+version = "0.14.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
+dependencies = [
+ "typenum",
+ "version_check",
+]
+
[[package]]
name = "gethostname"
version = "1.1.0"
@@ -2092,6 +2336,19 @@ dependencies = [
"unicode-width",
]
+[[package]]
+name = "getrandom"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
+dependencies = [
+ "cfg-if",
+ "js-sys",
+ "libc",
+ "wasi",
+ "wasm-bindgen",
+]
+
[[package]]
name = "getrandom"
version = "0.3.4"
@@ -2111,9 +2368,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"r-efi 6.0.0",
"rand_core 0.10.1",
+ "wasm-bindgen",
]
[[package]]
@@ -2279,6 +2538,25 @@ dependencies = [
"euclid",
]
+[[package]]
+name = "h2"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118"
+dependencies = [
+ "atomic-waker",
+ "bytes",
+ "fnv",
+ "futures-core",
+ "futures-sink",
+ "http",
+ "indexmap",
+ "slab",
+ "tokio",
+ "tokio-util",
+ "tracing",
+]
+
[[package]]
name = "half"
version = "2.7.1"
@@ -2359,6 +2637,107 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+[[package]]
+name = "http"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
+dependencies = [
+ "bytes",
+ "itoa",
+]
+
+[[package]]
+name = "http-body"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
+dependencies = [
+ "bytes",
+ "http",
+]
+
+[[package]]
+name = "http-body-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "http",
+ "http-body",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "httparse"
+version = "1.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
+
+[[package]]
+name = "hyper"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
+dependencies = [
+ "atomic-waker",
+ "bytes",
+ "futures-channel",
+ "futures-core",
+ "h2",
+ "http",
+ "http-body",
+ "httparse",
+ "itoa",
+ "pin-project-lite",
+ "smallvec",
+ "tokio",
+ "want",
+]
+
+[[package]]
+name = "hyper-rustls"
+version = "0.27.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53"
+dependencies = [
+ "http",
+ "hyper",
+ "hyper-util",
+ "rustls",
+ "tokio",
+ "tokio-rustls",
+ "tower-service",
+]
+
+[[package]]
+name = "hyper-util"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
+dependencies = [
+ "base64 0.23.1",
+ "bytes",
+ "futures-channel",
+ "futures-util",
+ "http",
+ "http-body",
+ "httparse",
+ "hyper",
+ "ipnet",
+ "libc",
+ "percent-encoding",
+ "pin-project-lite",
+ "socket2",
+ "system-configuration",
+ "tokio",
+ "tower-service",
+ "tracing",
+ "windows-registry",
+]
+
[[package]]
name = "iana-time-zone"
version = "0.1.65"
@@ -2649,7 +3028,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
dependencies = [
"hermit-abi",
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -3188,6 +3567,12 @@ dependencies = [
"imgref",
]
+[[package]]
+name = "lru-slab"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f"
+
[[package]]
name = "maybe-owned"
version = "0.3.4"
@@ -3237,6 +3622,12 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "mime"
+version = "0.3.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
+
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@@ -3299,9 +3690,15 @@ dependencies = [
"objc2-foundation 0.3.2",
"png 0.18.1",
"thiserror 2.0.21",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
+[[package]]
+name = "multiversion_no_op"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"
+
[[package]]
name = "naga"
version = "30.0.1"
@@ -3997,6 +4394,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "openssl-probe"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
+
[[package]]
name = "orbclient"
version = "0.3.55"
@@ -4033,7 +4436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -4116,6 +4519,25 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
+[[package]]
+name = "pem"
+version = "3.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be"
+dependencies = [
+ "base64 0.22.1",
+ "serde_core",
+]
+
+[[package]]
+name = "pem-rfc7468"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412"
+dependencies = [
+ "base64ct",
+]
+
[[package]]
name = "peniko"
version = "0.6.1"
@@ -4260,7 +4682,7 @@ dependencies = [
name = "photocraft-automation"
version = "0.8.2"
dependencies = [
- "base64",
+ "base64 0.22.1",
"cap-std",
"getrandom 0.3.4",
"photocraft-codecs",
@@ -4581,7 +5003,8 @@ dependencies = [
name = "photocraft-ui-egui"
version = "0.8.2"
dependencies = [
- "base64",
+ "base64 0.22.1",
+ "craft-print",
"craft-ui",
"eframe",
"egui",
@@ -4850,6 +5273,30 @@ dependencies = [
"toml_edit",
]
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
[[package]]
name = "proc-macro2"
version = "1.0.107"
@@ -4956,6 +5403,63 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "quinn"
+version = "0.11.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11"
+dependencies = [
+ "bytes",
+ "cfg_aliases",
+ "pin-project-lite",
+ "quinn-proto",
+ "quinn-udp",
+ "rustc-hash 2.1.3",
+ "rustls",
+ "socket2",
+ "thiserror 2.0.21",
+ "tokio",
+ "tracing",
+ "web-time",
+]
+
+[[package]]
+name = "quinn-proto"
+version = "0.11.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe"
+dependencies = [
+ "aws-lc-rs",
+ "bytes",
+ "getrandom 0.4.3",
+ "lru-slab",
+ "rand 0.10.3",
+ "rand_pcg",
+ "ring",
+ "rustc-hash 2.1.3",
+ "rustls",
+ "rustls-pki-types",
+ "slab",
+ "thiserror 2.0.21",
+ "tinyvec",
+ "tracing",
+ "web-time",
+]
+
+[[package]]
+name = "quinn-udp"
+version = "0.5.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016"
+dependencies = [
+ "cfg_aliases",
+ "libc",
+ "once_cell",
+ "socket2",
+ "tracing",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "quote"
version = "1.0.47"
@@ -5008,6 +5512,12 @@ dependencies = [
"rand_core 0.9.5",
]
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+
[[package]]
name = "rand_core"
version = "0.9.5"
@@ -5023,6 +5533,15 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+[[package]]
+name = "rand_pcg"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
+dependencies = [
+ "rand_core 0.10.1",
+]
+
[[package]]
name = "rand_xorshift"
version = "0.4.0"
@@ -5233,6 +5752,49 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
+[[package]]
+name = "reqwest"
+version = "0.13.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "16a1cfa75cc186dd73d5818e510e042e40927bccc9c236b061cea97e1eb08029"
+dependencies = [
+ "base64 0.23.1",
+ "bytes",
+ "encoding_rs",
+ "futures-channel",
+ "futures-core",
+ "futures-util",
+ "h2",
+ "http",
+ "http-body",
+ "http-body-util",
+ "hyper",
+ "hyper-rustls",
+ "hyper-util",
+ "js-sys",
+ "log",
+ "mime",
+ "percent-encoding",
+ "pin-project-lite",
+ "quinn",
+ "rustls",
+ "rustls-pki-types",
+ "rustls-platform-verifier",
+ "serde",
+ "serde_json",
+ "serde_urlencoded",
+ "sync_wrapper",
+ "tokio",
+ "tokio-rustls",
+ "tower",
+ "tower-http",
+ "tower-service",
+ "url",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "web-sys",
+]
+
[[package]]
name = "resvg"
version = "0.45.1"
@@ -5286,6 +5848,20 @@ dependencies = [
"bytemuck",
]
+[[package]]
+name = "ring"
+version = "0.17.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
+dependencies = [
+ "cc",
+ "cfg-if",
+ "getrandom 0.2.17",
+ "libc",
+ "untrusted 0.9.0",
+ "windows-sys 0.52.0",
+]
+
[[package]]
name = "rmcp"
version = "3.5.0"
@@ -5400,7 +5976,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -5413,6 +5989,81 @@ dependencies = [
"rustix 1.1.5",
]
+[[package]]
+name = "rustls"
+version = "0.23.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634"
+dependencies = [
+ "aws-lc-rs",
+ "once_cell",
+ "rustls-pki-types",
+ "rustls-webpki",
+ "subtle",
+ "zeroize",
+]
+
+[[package]]
+name = "rustls-native-certs"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d"
+dependencies = [
+ "openssl-probe",
+ "rustls-pki-types",
+ "schannel",
+ "security-framework",
+]
+
+[[package]]
+name = "rustls-pki-types"
+version = "1.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
+dependencies = [
+ "web-time",
+ "zeroize",
+]
+
+[[package]]
+name = "rustls-platform-verifier"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98"
+dependencies = [
+ "core-foundation 0.10.1",
+ "core-foundation-sys",
+ "jni",
+ "log",
+ "once_cell",
+ "rustls",
+ "rustls-native-certs",
+ "rustls-platform-verifier-android",
+ "rustls-webpki",
+ "security-framework",
+ "security-framework-sys",
+ "webpki-root-certs",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "rustls-platform-verifier-android"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f"
+
+[[package]]
+name = "rustls-webpki"
+version = "0.103.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
+dependencies = [
+ "aws-lc-rs",
+ "ring",
+ "rustls-pki-types",
+ "untrusted 0.9.0",
+]
+
[[package]]
name = "rustversion"
version = "1.0.23"
@@ -5458,6 +6109,18 @@ dependencies = [
"twox-hash",
]
+[[package]]
+name = "ryu"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
+
+[[package]]
+name = "ryu-js"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04d056b875a9d2e6cb9a61d127afee9ac5999b9f87bcb32079d1318e505be714"
+
[[package]]
name = "same-file"
version = "1.0.6"
@@ -5467,6 +6130,15 @@ dependencies = [
"winapi-util",
]
+[[package]]
+name = "schannel"
+version = "0.1.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "schemars"
version = "1.2.2"
@@ -5505,6 +6177,29 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+[[package]]
+name = "security-framework"
+version = "3.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
+dependencies = [
+ "bitflags 2.13.2",
+ "core-foundation 0.10.1",
+ "core-foundation-sys",
+ "libc",
+ "security-framework-sys",
+]
+
+[[package]]
+name = "security-framework-sys"
+version = "2.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
[[package]]
name = "self_cell"
version = "1.3.0"
@@ -5571,6 +6266,17 @@ dependencies = [
"zmij",
]
+[[package]]
+name = "serde_json_canonicalizer"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe52319a927259afbfa5180c5157cd8167edfd3e8c254f9558c7fef44c5649f2"
+dependencies = [
+ "ryu-js",
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "serde_repr"
version = "0.1.21"
@@ -5591,6 +6297,40 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "serde_urlencoded"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
+dependencies = [
+ "form_urlencoded",
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "sha1"
+version = "0.10.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.2.17",
+ "digest",
+]
+
+[[package]]
+name = "sha2"
+version = "0.10.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.2.17",
+ "digest",
+]
+
[[package]]
name = "shlex"
version = "1.3.0"
@@ -5613,6 +6353,175 @@ dependencies = [
"libc",
]
+[[package]]
+name = "signature"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
+dependencies = [
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "sigstore-bundle"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e7dc53c8a941858d01479622dbb7650aaa2ee0ca1fb58fb6cdddbfc3064abbb"
+dependencies = [
+ "base64 0.22.1",
+ "hex",
+ "serde",
+ "serde_json",
+ "sigstore-crypto",
+ "sigstore-merkle",
+ "sigstore-rekor",
+ "sigstore-tsa",
+ "sigstore-types",
+ "thiserror 2.0.21",
+]
+
+[[package]]
+name = "sigstore-crypto"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da90c3d9af638898a5fdc347479b18f950bb0dde11ecf2244f94cd28135da53b"
+dependencies = [
+ "aws-lc-rs",
+ "base64 0.22.1",
+ "const-oid",
+ "der",
+ "digest",
+ "pem",
+ "rand_core 0.10.1",
+ "sha2",
+ "signature",
+ "sigstore-types",
+ "spki",
+ "thiserror 2.0.21",
+ "tracing",
+ "x509-cert",
+]
+
+[[package]]
+name = "sigstore-merkle"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7c0d53558825c77716855c13794306fff766854c1bf92948e77d7890da3f2455"
+dependencies = [
+ "base64 0.22.1",
+ "hex",
+ "sigstore-crypto",
+ "sigstore-types",
+ "thiserror 2.0.21",
+]
+
+[[package]]
+name = "sigstore-rekor"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "641fdaaa40d0cd6e249cf1671c2240beff1a3ece578062cf43e750779e8db2b3"
+dependencies = [
+ "base64 0.22.1",
+ "hex",
+ "reqwest",
+ "serde",
+ "serde_json",
+ "sigstore-crypto",
+ "sigstore-merkle",
+ "sigstore-types",
+ "thiserror 2.0.21",
+ "url",
+]
+
+[[package]]
+name = "sigstore-trust-root"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6b0d2550f05c096400066e858db13d91f9de3b750a7541fb1291c1dc80ca290"
+dependencies = [
+ "base64 0.22.1",
+ "chrono",
+ "hex",
+ "rustls-pki-types",
+ "serde",
+ "serde_json",
+ "sigstore-crypto",
+ "sigstore-types",
+ "thiserror 2.0.21",
+ "x509-cert",
+]
+
+[[package]]
+name = "sigstore-tsa"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bc86c8abc1ece6832236e7e34e9baebb5d4d40490c0332b814a0d8624ca7255"
+dependencies = [
+ "aws-lc-rs",
+ "base64 0.22.1",
+ "chrono",
+ "cmpv2",
+ "cms",
+ "const-oid",
+ "der",
+ "hex",
+ "rand 0.10.3",
+ "reqwest",
+ "rustls-pki-types",
+ "rustls-webpki",
+ "sigstore-crypto",
+ "sigstore-types",
+ "thiserror 2.0.21",
+ "tracing",
+ "x509-cert",
+ "x509-tsp",
+]
+
+[[package]]
+name = "sigstore-types"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8d870c9bcfdf83396ac2bd2d6a23c5d09ec02cc9fda50fa1cbb3dd71a9bee53"
+dependencies = [
+ "base64 0.22.1",
+ "chrono",
+ "hex",
+ "pem",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.21",
+]
+
+[[package]]
+name = "sigstore-verify"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d30aff69036e4579b416956e9ba68cec45b793116f78f10842d04c7f8b924bab"
+dependencies = [
+ "base64 0.22.1",
+ "chrono",
+ "cms",
+ "const-oid",
+ "hex",
+ "pem",
+ "rustls-pki-types",
+ "rustls-webpki",
+ "serde",
+ "serde_json",
+ "serde_json_canonicalizer",
+ "sigstore-bundle",
+ "sigstore-crypto",
+ "sigstore-merkle",
+ "sigstore-rekor",
+ "sigstore-trust-root",
+ "sigstore-tsa",
+ "sigstore-types",
+ "thiserror 2.0.21",
+ "tls_codec",
+ "tracing",
+ "x509-cert",
+]
+
[[package]]
name = "simd-adler32"
version = "0.3.10"
@@ -5772,7 +6681,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5790,6 +6699,16 @@ dependencies = [
"bitflags 2.13.2",
]
+[[package]]
+name = "spki"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
+dependencies = [
+ "base64ct",
+ "der",
+]
+
[[package]]
name = "stable_deref_trait"
version = "1.2.1"
@@ -5833,6 +6752,33 @@ version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+[[package]]
+name = "strum"
+version = "0.28.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd"
+dependencies = [
+ "strum_macros",
+]
+
+[[package]]
+name = "strum_macros"
+version = "0.28.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "subtle"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
+
[[package]]
name = "svgtypes"
version = "0.15.3"
@@ -5843,6 +6789,16 @@ dependencies = [
"siphasher",
]
+[[package]]
+name = "syn"
+version = "1.0.109"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+dependencies = [
+ "proc-macro2",
+ "unicode-ident",
+]
+
[[package]]
name = "syn"
version = "2.0.119"
@@ -5865,6 +6821,15 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "sync_wrapper"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
+dependencies = [
+ "futures-core",
+]
+
[[package]]
name = "synstructure"
version = "0.14.0"
@@ -5885,6 +6850,27 @@ dependencies = [
"libc",
]
+[[package]]
+name = "system-configuration"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
+dependencies = [
+ "bitflags 2.13.2",
+ "core-foundation 0.9.4",
+ "system-configuration-sys",
+]
+
+[[package]]
+name = "system-configuration-sys"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
[[package]]
name = "system-deps"
version = "7.0.8"
@@ -5898,6 +6884,17 @@ dependencies = [
"version-compare",
]
+[[package]]
+name = "tar"
+version = "0.4.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840"
+dependencies = [
+ "filetime",
+ "libc",
+ "xattr",
+]
+
[[package]]
name = "target-lexicon"
version = "0.13.5"
@@ -5911,10 +6908,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
- "getrandom 0.4.3",
+ "getrandom 0.3.4",
"once_cell",
"rustix 1.1.5",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -6033,6 +7030,27 @@ version = "1.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
+[[package]]
+name = "tls_codec"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0de2e01245e2bb89d6f05801c564fa27624dbd7b1846859876c7dad82e90bf6b"
+dependencies = [
+ "tls_codec_derive",
+ "zeroize",
+]
+
+[[package]]
+name = "tls_codec_derive"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "tokio"
version = "1.53.1"
@@ -6059,6 +7077,16 @@ dependencies = [
"syn 3.0.6",
]
+[[package]]
+name = "tokio-rustls"
+version = "0.26.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
+dependencies = [
+ "rustls",
+ "tokio",
+]
+
[[package]]
name = "tokio-stream"
version = "0.1.19"
@@ -6135,6 +7163,51 @@ version = "1.1.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
+[[package]]
+name = "tower"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
+dependencies = [
+ "futures-core",
+ "futures-util",
+ "pin-project-lite",
+ "sync_wrapper",
+ "tokio",
+ "tower-layer",
+ "tower-service",
+]
+
+[[package]]
+name = "tower-http"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
+dependencies = [
+ "bitflags 2.13.2",
+ "bytes",
+ "futures-util",
+ "http",
+ "http-body",
+ "pin-project-lite",
+ "tower",
+ "tower-layer",
+ "tower-service",
+ "url",
+]
+
+[[package]]
+name = "tower-layer"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
+
+[[package]]
+name = "tower-service"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
+
[[package]]
name = "tracing"
version = "0.1.44"
@@ -6188,6 +7261,12 @@ dependencies = [
"petgraph",
]
+[[package]]
+name = "try-lock"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
+
[[package]]
name = "ttf-parser"
version = "0.25.1"
@@ -6218,6 +7297,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
+[[package]]
+name = "typenum"
+version = "1.20.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
+
[[package]]
name = "uds_windows"
version = "1.2.1"
@@ -6226,7 +7311,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
dependencies = [
"memoffset",
"tempfile",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6295,6 +7380,18 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
+[[package]]
+name = "untrusted"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
+
+[[package]]
+name = "untrusted"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
+
[[package]]
name = "url"
version = "2.5.8"
@@ -6313,7 +7410,7 @@ version = "0.45.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80be9b06fbae3b8b303400ab20778c80bbaf338f563afe567cf3c9eea17b47ef"
dependencies = [
- "base64",
+ "base64 0.22.1",
"data-url",
"flate2",
"fontdb",
@@ -6421,6 +7518,15 @@ dependencies = [
"winapi-util",
]
+[[package]]
+name = "want"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b"
+dependencies = [
+ "try-lock",
+]
+
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
@@ -6755,6 +7861,15 @@ dependencies = [
"wasm-bindgen",
]
+[[package]]
+name = "webpki-root-certs"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b"
+dependencies = [
+ "rustls-pki-types",
+]
+
[[package]]
name = "weezl"
version = "0.1.12"
@@ -6956,7 +8071,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -7042,6 +8157,17 @@ dependencies = [
"windows-link",
]
+[[package]]
+name = "windows-registry"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
+dependencies = [
+ "windows-link",
+ "windows-result",
+ "windows-strings",
+]
+
[[package]]
name = "windows-result"
version = "0.4.1"
@@ -7294,6 +8420,27 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "winprint"
+version = "0.2.1"
+source = "git+https://github.com/storytold/winprint.rs?rev=5f80b9baf6b58937c401656634e42d33f00ddf49#5f80b9baf6b58937c401656634e42d33f00ddf49"
+dependencies = [
+ "flate2",
+ "fmt-derive",
+ "reqwest",
+ "scopeguard",
+ "sigstore-trust-root",
+ "sigstore-types",
+ "sigstore-verify",
+ "strum",
+ "tar",
+ "thiserror 2.0.21",
+ "windows",
+ "windows-core",
+ "windows-implement",
+ "xml",
+]
+
[[package]]
name = "winresource"
version = "0.1.31"
@@ -7382,6 +8529,41 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
+[[package]]
+name = "x509-cert"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94"
+dependencies = [
+ "const-oid",
+ "der",
+ "sha1",
+ "signature",
+ "spki",
+ "tls_codec",
+]
+
+[[package]]
+name = "x509-tsp"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f5ceece934a21607055b7ac5c25adb56a2ff559804b10705dc674d1d838c15e1"
+dependencies = [
+ "cmpv2",
+ "cms",
+ "der",
+]
+
+[[package]]
+name = "xattr"
+version = "1.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"
+dependencies = [
+ "libc",
+ "rustix 1.1.5",
+]
+
[[package]]
name = "xcap"
version = "0.9.8"
@@ -7449,6 +8631,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
+[[package]]
+name = "xml"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f45bb2c13fec6a6cb4c0f76a7e94839e110a14ec803ec2940777a94c347bc52"
+
[[package]]
name = "xml-rs"
version = "0.8.29"
@@ -7646,6 +8834,26 @@ dependencies = [
"synstructure",
]
+[[package]]
+name = "zeroize"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
+dependencies = [
+ "zeroize_derive",
+]
+
+[[package]]
+name = "zeroize_derive"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "zerotrie"
version = "0.2.5"
diff --git a/Cargo.toml b/Cargo.toml
index f96b5cb468..2c329d980d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,7 +38,7 @@ photocraft-testkit = { path = "crates/testkit" }
photocraft-tablet = { path = "crates/tablet" }
# external
-craft-print = { git = "https://github.com/storytold/craft-libs", rev = "d991bf6792f8ade99c51358bf3c1d902c8cd96b5" }
+craft-print = { git = "https://github.com/storytold/craft-libs", rev = "3d37da389a3618ab9b76109da11416e9ca4ea719" }
thiserror = "2"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
diff --git a/README.md b/README.md
index 5fd2650415..b272705e40 100644
--- a/README.md
+++ b/README.md
@@ -187,7 +187,7 @@ Every screenshot here is the real app at work on public-domain art, rendered off
🗃️ Layers, done properly
- Groups, clipping masks, pixel and vector masks, fill layers (solid, gradient and pattern), adjustment layers, live smart objects with smart filters and lossless transforms and warps, multi-layer selection with align, distribute and link, alpha channels and Quick Mask, 27 Photoshop blend modes plus six Paint.NET variants, opacity and fill, locks, colour labels, layer filters, merge, flatten, rasterize, Layer via Copy/Cut, Paste Into.
+ Groups, clipping masks, pixel and vector masks, fill layers (solid, gradient and pattern), adjustment layers, live smart objects with smart filters and lossless transforms and warps, multi-layer selection with align, distribute and link, alpha channels and Quick Mask, 27 Photoshop blend modes plus six Paint.NET variants, opacity and fill, locks, colour labels, a layer kind filter, merge, flatten, rasterize, Layer via Copy/Cut, Paste Into.
diff --git a/ROADMAP.md b/ROADMAP.md
index 98e8c1184c..f41b71bfc9 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -2,7 +2,7 @@
**Stage: alpha** · next: beta, ~30 points (ready for real work ~45% → ~75%, with reliable PSD) and ~1,100–1,800 h away
-> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-11 · **Change:** minor (toolbox count 56 of 68, 12 missing) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-13 · **Change:** minor (oracle floor 145 of 258 and 953 open issues, as in gaps.md and on GitHub; toolbox count 56 of 68, 12 missing) · **Target:** Adobe Photoshop 2026
PhotoCraft's one-page summary of how close it is to Adobe Photoshop 2026 (27.11.0, measured from
the installed app on 2026-10-10) at version 0.6.0. Detail: [target-app parity](docs/target-app-parity.md)
@@ -40,7 +40,7 @@ the one above. About 80% parallelizes (independent crates and command modules);
architecture and the PSD writer are the serial parts.
**Why alpha.** Core workflows (open, layer, select, paint, adjust, filter, type, save) work end to
-end, and breadth is high, but users of 0.5/0.6 have 579 open issues, 22 of 25 performance budgets
+end, and breadth is high, but 953 issues are open (2026-10-13), 22 of 25 performance budgets
are missed, and PSDs we write are not yet reliably accepted by Photoshop (#1281, #2469). Beta
needs ~75% ready and no blocking PSD gap. The [alpha gate](docs/roadmap.md#alpha-gate) passes: all six core workflows
(retouch, composite, cut-out, design, paint, PSD exchange) complete end to end and save and reopen;
@@ -110,7 +110,7 @@ Also shipped: Traditional Chinese, Russian, Ukrainian, Czech, Polish, Greek, Dut
| Rank | Milestone | Estimate |
|---|---|---:|
-| 1 | PSD that Photoshop trusts: Save As corruption, Photoshop re-open check, Photoshop-oracle floor 133 → 200+ of 256 | 150–250 h |
+| 1 | PSD that Photoshop trusts: Save As corruption, Photoshop re-open check, Photoshop-oracle floor 145 → 200+ of 258 | 150–250 h |
| 2 | Performance budgets: the 22 over-budget scenarios and the 150-layer GPU crash | 200–350 h |
| 3 | User bug backlog to under 100 open | 250–400 h |
| 4 | Brush and transform feel (brush-parity, ui-parity rows) | 160–290 h |
@@ -135,6 +135,7 @@ Detail and the next releases: [docs/roadmap.md](docs/roadmap.md).
| Date | Change | Summary |
|---|---|---|
+| 2026-10-13 | minor | Focus item 1 quoted the oracle floor as 133 of 256; it is 145 of 258 (`crates/io/tests/corpus.rs`, gaps.md G1). Open issues 579 → 953 (2026-10-13) |
| 2026-10-11 | minor | Toolbox count 56 of 68 (12 missing) with the Convert Point tool (#3204) |
| 2026-10-10 | minor | Readiness by audience with hours per tier |
| 2026-10-10 | minor | Mainstream-practitioner and essentials-user numbers added |
diff --git a/crates/algo/src/lib.rs b/crates/algo/src/lib.rs
index 78dae7b06f..49ab15871c 100644
--- a/crates/algo/src/lib.rs
+++ b/crates/algo/src/lib.rs
@@ -600,6 +600,13 @@ impl FilterParams {
self.halo() == Halo::Bounds
}
+ /// Whether the filter renders new pixels without reading the layer's own (Fibers): it fills
+ /// the reference bounds even where the layer is transparent, as Photoshop's does on an
+ /// empty layer, while still reading no neighbourhood.
+ pub fn renders_from_nothing(&self) -> bool {
+ matches!(self, FilterParams::Fibers { .. })
+ }
+
/// Human-readable name.
pub fn label(&self) -> &'static str {
match self {
@@ -905,12 +912,13 @@ pub fn kernel(params: &FilterParams, src: &Image, out: Rect, ctx: &Ctx) -> Vec) -> Rect {
let mut area = match params.halo_for(bounds) {
Halo::Bounds => bounds,
+ Halo::Radius(_) if params.renders_from_nothing() => bounds,
Halo::Radius(r) => {
if content.is_empty() {
Rect::EMPTY
diff --git a/crates/algo/src/selection.rs b/crates/algo/src/selection.rs
index ad858df2a2..94f744d0be 100644
--- a/crates/algo/src/selection.rs
+++ b/crates/algo/src/selection.rs
@@ -682,18 +682,23 @@ fn hue_chroma([r, g, b]: [f32; 3]) -> (f32, f32) {
/// Color Range › Select: Reds, Yellows, Greens, Cyans, Blues or Magentas (`center` = 0, 60,
/// 120, 180, 240, 300°). A pixel belongs to a family by how close its hue is (full at the
-/// family's hue, none 60° away, so an orange is half red, half yellow) times its chroma, so
-/// neutrals are never selected and muted colours only partly.
+/// family's hue, none 60° away, so an orange is half red, half yellow) times its chroma
+/// (max − min), so neutrals are never selected and muted colours only partly. Darker colours
+/// weigh more, by `2 − max`: measured against Photoshop 2025's presets on 126 colours each for
+/// Reds, Yellows and Blues (hue ±40°, saturation 5..100 %, brightness 33..100 %), this matches
+/// its selection to within one level, where chroma alone fell up to 61 levels short (#5243).
pub fn hue_range(px: &[[f32; 4]], center: f32) -> Vec {
px.iter()
.map(|&[r, g, b, a]| {
if a <= 0.0 {
return 0.0;
}
- let (h, chroma) = hue_chroma([r, g, b].map(|v| v.clamp(0.0, 1.0)));
+ let rgb = [r, g, b].map(|v| v.clamp(0.0, 1.0));
+ let (h, chroma) = hue_chroma(rgb);
+ let max = rgb[0].max(rgb[1]).max(rgb[2]);
let dh = (h - center).rem_euclid(360.0);
let dh = dh.min(360.0 - dh);
- ((1.0 - dh / 60.0).clamp(0.0, 1.0) * chroma).clamp(0.0, 1.0)
+ ((1.0 - dh / 60.0).clamp(0.0, 1.0) * chroma * (2.0 - max)).clamp(0.0, 1.0)
})
.collect()
}
@@ -1180,6 +1185,17 @@ mod tests {
assert!((hue_range(&[[1.0, 0.0, 0.5, 1.0]], 300.0)[0] - 0.5).abs() < 1e-5);
}
+ #[test]
+ fn hue_families_weigh_dark_colours_like_photoshop() {
+ // Photoshop 2025's Blues on an 8-bit sRGB document (selection levels 0..255, #5243): the
+ // muted navy #3d3f54, a dark blue (0, 0, 84) and a mid blue (61, 61, 153).
+ let c = |r: u8, g: u8, b: u8| [f32::from(r) / 255.0, f32::from(g) / 255.0, f32::from(b) / 255.0, 1.0];
+ let blues = hue_range(&[c(0x3d, 0x3f, 0x54), c(0, 0, 84), c(61, 61, 153)], 240.0);
+ for (got, want) in blues.iter().zip([35.0, 140.0, 129.0]) {
+ assert!((got * 255.0 - want).abs() <= 1.0, "{} vs Photoshop {want}", got * 255.0);
+ }
+ }
+
#[test]
fn tonal_ranges() {
let g = |v: f32| [v / 255.0, v / 255.0, v / 255.0, 1.0];
diff --git a/crates/algo/src/tests.rs b/crates/algo/src/tests.rs
index 9a90012df9..31def5f99d 100644
--- a/crates/algo/src/tests.rs
+++ b/crates/algo/src/tests.rs
@@ -446,6 +446,10 @@ fn halos_and_output_area() {
assert_eq!(output_area(&FilterParams::Twirl { angle: 1.0 }, content, R, None), R);
assert_eq!(output_area(&FilterParams::BoxBlur { radius: 1.0 }, content, R, Some(Rect::new(0, 0, 12, 12))), Rect::new(8, 8, 12, 12));
assert!(output_area(&FilterParams::Invert, Rect::EMPTY, R, None).is_empty());
+ // Fibers renders without reading the layer: an empty layer still fills the bounds (#5241).
+ let fibers = FilterParams::Fibers { variance: 16.0, strength: 4.0, seed: 0, foreground: [0.0; 4], background: [1.0; 4] };
+ assert_eq!(output_area(&fibers, Rect::EMPTY, R, None), R);
+ assert_eq!(output_area(&fibers, content, R, Some(Rect::new(0, 0, 12, 12))), Rect::new(0, 0, 12, 12));
}
#[test]
diff --git a/crates/automation/tests/agent_tasks.rs b/crates/automation/tests/agent_tasks.rs
index 271993d2bb..e1585e2040 100644
--- a/crates/automation/tests/agent_tasks.rs
+++ b/crates/automation/tests/agent_tasks.rs
@@ -166,7 +166,7 @@ async fn agent_completes_ten_scripted_tasks() {
let outside = pixel(&c, 1, 1).await;
assert!(inside[0] > 0.99 && inside[1] < 0.01, "task 5: centre is red {inside:?}");
assert!(outside[0] < 0.1, "task 5: corner shows the photo {outside:?}");
- run(&c, "select.deselect", json!({})).await;
+ assert_eq!(inspect(&c).await["hasSelection"], false, "task 5: the selection became the mask");
// 6. Save a selection to a channel and load it back.
run(&c, "select.rect", json!({"x": 4, "y": 6, "width": 20, "height": 10})).await;
@@ -413,7 +413,7 @@ async fn agent_completes_ten_more_scripted_tasks() {
assert_eq!(top_layer(&doc)["hasMask"], true, "task 17");
let boundary = pixel(&c, 20, 40).await;
assert!(boundary[3] > 0.05 && boundary[3] < 0.95, "task 17: the feathered edge keeps partial alpha {boundary:?}");
- run(&c, "select.deselect", json!({})).await;
+ assert_eq!(doc["hasSelection"], false, "task 17: the selection became the mask");
// 18. Expand a selection and read its bounds back.
run(&c, "select.rect", json!({"x": 20, "y": 20, "width": 20, "height": 20})).await;
diff --git a/crates/compose/src/effects.rs b/crates/compose/src/effects.rs
index 6966254547..5acdd79314 100644
--- a/crates/compose/src/effects.rs
+++ b/crates/compose/src/effects.rs
@@ -13,7 +13,8 @@
//! Interior effects are painted relative to the layer's shape and then take the shape's alpha
//! (an overlay recolours a half-transparent edge without adding coverage). The outside parts
//! of strokes blend onto the backdrop with their own modes, an upper stroke covering the
-//! lower ones. Drop shadows are knocked out only through see-through fill.
+//! lower ones. Drop shadows are knocked out through see-through fill, and beneath the whole shape
+//! when the layer's mode lets what's under it show through (see [`shadow_see_through`]).
//!
//! Shapes come from the layer's alpha (after its mask). A stroke's outer edge, and precise glows /
//! chiselled bevels, use an exact Euclidean transform: a 5 × 5 chamfer's level sets are polygons,
@@ -1850,6 +1851,16 @@ fn knock_out_exterior(map: &mut Map, shape: &Map, fill_opacity: f32) {
}
}
+/// How far the layer lets a knocked-out drop shadow show beneath its own shape (Layer Knocks Out
+/// Drop Shadow), 0 = covered, 1 = knocked out wholly. In a normal mode an opaque layer covers the
+/// shadow anyway, so only see-through fill knocks it out (and anti-aliased edges are not
+/// attenuated twice). In any other mode the layer blends with what's beneath it, shadow and all:
+/// an Exclusion or Difference layer would invert it, Multiply darken by it, Screen show it as
+/// grey. Photoshop keeps it out from under the shape, so here it's knocked out wholly.
+pub fn shadow_see_through(layer: &Layer) -> f32 {
+ if matches!(layer.blend, BlendMode::Normal | BlendMode::Dissolve | BlendMode::PassThrough) { 1.0 - layer.fill_opacity.clamp(0.0, 1.0) } else { 1.0 }
+}
+
/// Blend Interior Effects as Group off (Photoshop's default): the layer's mode applies to its
/// own pixels only, and the interior effects paint over the blended result. The layer is merged
/// into the backdrop before they paint, so an Overlay colour overlay on a black Color-mode layer
@@ -1916,10 +1927,10 @@ pub(crate) fn composite_with_effects_prepared(
if let Effect::DropShadow(s) = e {
let mut m = fx(i, 0);
if s.knocks_out {
- // The layer hides the shadow beneath it only where its fill is see-through: at
- // 100 % fill the layer covers it anyway (and anti-aliased edges are not
- // attenuated twice), at 0 % the shape shows the bare backdrop.
- knock_out_exterior(&mut m, &shape, layer.fill_opacity);
+ // The layer hides the shadow beneath it where its fill is see-through (at 100 %
+ // fill in a normal mode it covers it anyway; at 0 % the shape shows the bare
+ // backdrop), and wholly in a mode that blends with it ([`shadow_see_through`]).
+ knock_out_exterior(&mut m, &shape, 1.0 - shadow_see_through(layer));
}
paint_color(&mut work, &m, rgb(&s.color), s.common.blend, s.common.opacity);
}
diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs
index f9e49ac04e..778d9cf29a 100644
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@ -1473,6 +1473,36 @@ fn shadow_knockout_needs_see_through_fill() {
assert!(close4(on, px(&base, 10, 20)), "{on:?}");
}
+#[test]
+fn shadow_knockout_beneath_a_layer_in_a_blending_mode() {
+ // Layer Knocks Out Drop Shadow keeps the shadow out from under the layer's shape. In Normal
+ // mode an opaque layer covers it anyway; in a mode that blends with what's beneath, the shadow
+ // would show through: under a white Exclusion square on white, it read as white (white over
+ // the black shadow) instead of black (white over white), so a logo's Exclusion bar with a
+ // drop shadow came out blank. A red Multiply square came out black instead of red.
+ for (blend, colour, inside, depth) in [
+ (photocraft_color::BlendMode::Exclusion, [1.0, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 1.0]),
+ (photocraft_color::BlendMode::Multiply, [1.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0]),
+ ]
+ .into_iter()
+ .flat_map(|c| SampleType::ALL.map(|depth| (c, depth)))
+ .map(|((b, c, i), depth)| (b, c, i, depth))
+ {
+ let mut d = Document::new("t", Size::new(40, 40), ColorMode::Rgb, depth);
+ d.layers.push(solid_layer("bg", Rect::new(0, 0, 40, 40), [1.0; 4]));
+ let mut l = solid_layer("sq", Rect::new(10, 10, 30, 30), colour);
+ l.blend = blend;
+ l.effects.items = vec![Effect::DropShadow(shadow(0.0, 90.0))];
+ d.layers.push(l);
+ assert!(close4(px(&d, 20, 20), inside), "{blend:?} {depth:?}: {:?}", px(&d, 20, 20));
+ // Not knocked out, the shadow shows through the blend, as in Photoshop with the box unticked.
+ if let Effect::DropShadow(s) = &mut d.layers[1].effects.items[0] {
+ s.knocks_out = false;
+ }
+ assert!(!close4(px(&d, 20, 20), inside), "{blend:?} {depth:?} without knockout: {:?}", px(&d, 20, 20));
+ }
+}
+
#[test]
fn linked_pattern_overlay_anchors_at_the_effects_reference_point() {
use photocraft_doc::pattern::Pattern;
diff --git a/crates/engine/src/adjust_cmds/tests.rs b/crates/engine/src/adjust_cmds/tests.rs
index 8fa053e86e..9f614732de 100644
--- a/crates/engine/src/adjust_cmds/tests.rs
+++ b/crates/engine/src/adjust_cmds/tests.rs
@@ -353,7 +353,6 @@ fn invert_with_the_mask_targeted_inverts_the_mask() {
let mut s = session(depth, "rgb");
s.execute("select.rect", json!({"x": 24, "y": 0, "width": 24, "height": 32})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
let (pixels, off_canvas) = (rgba(&s, 3, 3), mask_at(&s, -500, 3));
let steps = s.active().unwrap().history.past_len();
s.execute("image.adjustments.invert", json!({"target": "mask"})).unwrap();
@@ -372,6 +371,31 @@ fn invert_with_the_mask_targeted_inverts_the_mask() {
}
}
+/// Photoshop: a mask made from the selection (Reveal Selection, the Layers panel's mask button)
+/// takes the selection with it, as Hide Selection does. So ⌘I on the new mask right away inverts
+/// all of it; with the selection kept it inverted only the inside, leaving the mask all black.
+/// Undo brings the selection back with the mask gone, in one step.
+#[test]
+fn reveal_selection_drops_the_selection_so_invert_flips_the_whole_mask() {
+ for depth in DEPTHS {
+ let mut s = session(depth, "rgb");
+ s.execute("select.rect", json!({"x": 24, "y": 0, "width": 24, "height": 32})).unwrap();
+ let selection = s.active().unwrap().doc.selection.clone();
+ let steps = s.active().unwrap().history.past_len();
+ s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
+ assert!(s.active().unwrap().doc.selection.is_none(), "depth {depth}: the selection became the mask");
+ assert_eq!(s.active().unwrap().history.past_len(), steps + 1, "one step");
+ assert_eq!((mask_at(&s, 3, 3), mask_at(&s, 30, 3)), (0.0, 1.0));
+ s.execute("image.adjustments.invert", json!({"target": "mask"})).unwrap();
+ assert_eq!((mask_at(&s, 3, 3), mask_at(&s, 30, 3)), (1.0, 0.0), "depth {depth}: inside and outside both flip");
+ s.undo();
+ s.undo();
+ let st = s.active().unwrap();
+ assert_eq!(st.doc.selection, selection, "undo restores the selection");
+ assert!(st.doc.layer(st.active_layer.unwrap()).unwrap().mask.is_none(), "and removes the mask");
+ }
+}
+
// ---------- Image › Adjustments as smart filters (FILE-215-4) ----------
/// A painted pixel layer converted to a smart object, over the painted Background.
@@ -492,7 +516,6 @@ fn a_targeted_mask_enables_editing_it_on_any_layer() {
s.execute("layer.delete", json!({})).unwrap();
s.execute("select.rect", json!({"x": 24, "y": 0, "width": 24, "height": 32})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
let pixels = rgba(&s, 23, 3);
s.execute("filter.blur.gaussianBlur", json!({"radius": 3, "target": "mask"})).unwrap();
assert!(mask_at(&s, 23, 3) > 0.0 && mask_at(&s, 23, 3) < 1.0, "the mask's edge is blurred");
diff --git a/crates/engine/src/align_cmds.rs b/crates/engine/src/align_cmds.rs
index b54f4b7a73..c7df82902f 100644
--- a/crates/engine/src/align_cmds.rs
+++ b/crates/engine/src/align_cmds.rs
@@ -381,7 +381,7 @@ mod tests {
let m = r["aligned"][0]["matrix"].as_array().unwrap().iter().map(|v| v.as_f64().unwrap()).collect::>();
assert!((m[2] + 6.0).abs() < 1.0 && (m[5] + 5.0).abs() < 1.0, "{r}");
assert!(s.execute("edit.autoAlignLayers", json!({"projection": "sideways"})).is_err());
- assert!(s.execute("edit.autoAlignLayers", json!({"reference": 9999})).is_err());
+ assert!(s.execute("edit.autoAlignLayers", json!({"reference": u64::MAX})).is_err());
}
#[test]
diff --git a/crates/engine/src/automate_cmds/tests.rs b/crates/engine/src/automate_cmds/tests.rs
index b60dc2940e..67852534c3 100644
--- a/crates/engine/src/automate_cmds/tests.rs
+++ b/crates/engine/src/automate_cmds/tests.rs
@@ -50,7 +50,7 @@ fn browse_runs_a_script_file() {
assert_eq!((d.size.width, d.size.height), (20, 30));
assert!(s.execute("file.scripts.browse", json!({"script": "no.such.command"})).is_err());
// A failing step stops the script and is reported.
- let r = s.execute("file.scripts.browse", json!({"steps": [["layer.delete", {"layer": 999_999}], ["image.imageRotation.90cw", {}]]})).unwrap();
+ let r = s.execute("file.scripts.browse", json!({"steps": [["layer.delete", {"layer": u64::MAX}], ["image.imageRotation.90cw", {}]]})).unwrap();
assert_eq!(r["results"].as_array().unwrap().len(), 1);
}
@@ -348,7 +348,7 @@ fn a_failed_step_inside_a_called_action_fails_scripts_and_batch() {
});
s.actions.list.push(Action {
name: "Bad".into(),
- steps: vec![("layer.delete".into(), json!({"layer": 999_999}))],
+ steps: vec![("layer.delete".into(), json!({"layer": u64::MAX}))],
disabled: Default::default(),
..Default::default()
});
diff --git a/crates/engine/src/background_cmds.rs b/crates/engine/src/background_cmds.rs
index 81c47501d3..0c067b3842 100644
--- a/crates/engine/src/background_cmds.rs
+++ b/crates/engine/src/background_cmds.rs
@@ -144,6 +144,32 @@ mod tests {
(s, [bg, a, b])
}
+ #[test]
+ fn opacity_fill_or_a_blend_mode_turn_the_background_into_a_layer() {
+ // Like Photoshop: the Background takes none of them, so it becomes "Layer 0" first.
+ for (key, value) in [("opacity", json!(0.5)), ("fill", json!(0.5)), ("blend", json!("Multiply"))] {
+ let (mut s, [bg, ..]) = with_background();
+ s.execute("layer.setProps", json!({"layer": bg.0, key: value})).unwrap();
+ let l = doc(&s).layer(bg).unwrap();
+ assert!(!doc(&s).is_background(bg) && l.name == "Layer 0", "{key}");
+ assert!(l.opacity < 1.0 || l.fill_opacity < 1.0 || l.blend == photocraft_color::BlendMode::Multiply, "{key}: applied");
+ }
+ // Values that leave its look alone keep it the Background.
+ let (mut s, [bg, ..]) = with_background();
+ s.execute("layer.setProps", json!({"layer": bg.0, "opacity": 1.0, "fill": 1.0, "blend": "Normal", "visible": false})).unwrap();
+ assert!(doc(&s).is_background(bg));
+ }
+
+ #[test]
+ fn select_and_mask_output_to_a_layer_mask_turns_the_background_into_a_layer() {
+ let (mut s, [bg, ..]) = with_background();
+ s.execute("layer.select", json!({"layer": bg.0})).unwrap();
+ s.execute("select.rect", json!({"x": 2, "y": 2, "width": 6, "height": 6})).unwrap();
+ s.execute("select.refineEdge", json!({"output": "layerMask"})).unwrap();
+ let l = doc(&s).layer(bg).unwrap();
+ assert!(l.mask.is_some() && !doc(&s).is_background(bg) && l.name == "Layer 0");
+ }
+
#[test]
fn makes_the_layer_the_background_at_the_bottom() {
for depth in [8, 16, 32] {
@@ -207,7 +233,7 @@ mod tests {
assert!(s.execute(CMD, json!({"layer": bg.0})).is_err());
// Bad params.
let (mut s, [_, a, _]) = session(8);
- for p in [json!({"layer": "A"}), json!({"layer": -1}), json!({"layer": 1.5}), json!({"layer": 99999}), json!({"layer": [a.0]})] {
+ for p in [json!({"layer": "A"}), json!({"layer": -1}), json!({"layer": 1.5}), json!({"layer": u64::MAX}), json!({"layer": [a.0]})] {
assert!(s.execute(CMD, p.clone()).is_err(), "{p}");
}
assert!(doc(&s).background().is_none());
diff --git a/crates/engine/src/channel_clip.rs b/crates/engine/src/channel_clip.rs
index fc52cf0a43..fea1048235 100644
--- a/crates/engine/src/channel_clip.rs
+++ b/crates/engine/src/channel_clip.rs
@@ -59,15 +59,16 @@ pub(crate) fn copy(s: &mut Session) -> Result> {
return Err(EngineError::Other("Could not copy: the selected area is empty".into()));
}
let fmt = PixelFormat::new(ColorMode::Grayscale, doc.pixel_format().sample, true);
- let values = src.read_region(area);
- let cover = sel.map(|m| (m.read_region(area), m.format().channels().max(1)));
- let mut px = Vec::with_capacity(values.len() / n * 2);
+ let values = crate::allocation::read_region(src, area, "copying a channel")?;
+ let cover = sel.map(|m| crate::allocation::read_region(m, area, "copying a channel selection").map(|v| (v, m.format().channels().max(1)))).transpose()?;
+ let len = (values.len() / n).checked_mul(2).ok_or_else(|| EngineError::Other("the channel is too large to copy".into()))?;
+ let mut px = crate::allocation::capacity(len, "copying a channel")?;
for (i, p) in values.chunks_exact(n).enumerate() {
px.push(p.get(k).copied().unwrap_or(0.0));
px.push(cover.as_ref().map_or(1.0, |(m, mk)| m.get(i * mk).copied().unwrap_or(0.0)));
}
let mut surface = Surface::new(fmt);
- surface.write_region(area, &px);
+ surface.try_write_region(area, &px)?;
surface.prune();
let bounds = surface.content_bounds();
if bounds.is_empty() {
diff --git a/crates/engine/src/channel_clip/tests.rs b/crates/engine/src/channel_clip/tests.rs
index 39cb029b3d..be7e51dfd7 100644
--- a/crates/engine/src/channel_clip/tests.rs
+++ b/crates/engine/src/channel_clip/tests.rs
@@ -163,3 +163,22 @@ fn clearing_a_channel_reports_allocation_failure_without_editing() {
assert_eq!(s.active().unwrap().history.entries(), history);
}
}
+
+#[test]
+fn channel_copy_allocation_failure_keeps_clipboard_and_document() {
+ for depth in [8, 16, 32] {
+ let mut s = session(depth);
+ s.execute("edit.copy", json!({})).unwrap();
+ s.execute("channel.target", json!({"channel": "red"})).unwrap();
+ let before = s.active().unwrap().doc.clone();
+ let clip = s.clipboard.as_ref().unwrap().surface.clone();
+ let history = s.active().unwrap().history.entries();
+ crate::allocation::fail_next_for_test();
+ let result = copy(&mut s);
+ let _ = crate::allocation::capacity::(0, "reset failpoint");
+ assert!(result.is_err());
+ assert_eq!(*s.active().unwrap().doc, *before);
+ assert_eq!(s.active().unwrap().history.entries(), history);
+ assert_eq!(s.clipboard.as_ref().unwrap().surface, clip);
+ }
+}
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index a32c5feb8d..a954eca7e2 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -681,6 +681,16 @@ fn build() -> Vec {
has_layer,
|s, p| {
let id = layer_param(s, p)?;
+ // Opacity and Fill are fractions here, while the Layer Style commands take
+ // percentages: a value outside 0..1 is refused, never clamped to 100 % (#5242).
+ let unit = |key: &str| -> Result> {
+ let Some(v) = p.get(key) else { return Ok(None) };
+ match v.as_f64() {
+ Some(x) if (0.0..=1.0).contains(&x) => Ok(Some(x as f32)),
+ _ => Err(bad("layer.setProps", format!("{key} must be a number in 0..1 (1 = 100 %), got {v}"))),
+ }
+ };
+ let (opacity, fill) = (unit("opacity")?, unit("fill")?);
let only_visibility =
p.as_object().is_some_and(|o| o.contains_key("visible") && o.keys().all(|k| matches!(k.as_str(), "layer" | "visible" | "coalesce")));
let label = if only_visibility { "Layer Visibility" } else { "Layer Properties" };
@@ -688,6 +698,13 @@ fn build() -> Vec {
// Clipping and channel changes reach the layers around it: recomposite everything.
let local = p.get("clipped").is_none() && p.get("channels").is_none();
s.edit(label, |doc, _| {
+ // The Background has no opacity, fill or blend mode: like Photoshop, setting
+ // one that changes its look turns it into a normal layer ("Layer 0") first.
+ let num = |k: &str| p.get(k).and_then(Value::as_f64).is_some_and(|v| v < 1.0);
+ let blends = p.get("blend").and_then(Value::as_str).and_then(blend_from_str).is_some_and(|b| b != photocraft_color::BlendMode::Normal);
+ if num("opacity") || num("fill") || blends {
+ crate::extra_cmds::background_to_layer(doc, id);
+ }
let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?;
if let Some(v) = p.get("name").and_then(Value::as_str) {
l.name = v.to_string();
@@ -695,11 +712,11 @@ fn build() -> Vec {
if let Some(v) = p.get("visible").and_then(Value::as_bool) {
l.visible = v;
}
- if let Some(v) = p.get("opacity").and_then(Value::as_f64) {
- l.opacity = (v as f32).clamp(0.0, 1.0);
+ if let Some(v) = opacity {
+ l.opacity = v;
}
- if let Some(v) = p.get("fill").and_then(Value::as_f64) {
- l.fill_opacity = (v as f32).clamp(0.0, 1.0);
+ if let Some(v) = fill {
+ l.fill_opacity = v;
}
if let Some(v) = p.get("blend").and_then(Value::as_str) {
l.blend = blend_from_str(v).ok_or_else(|| bad("layer.setProps", format!("unknown blend mode `{v}`")))?;
@@ -788,7 +805,10 @@ fn build() -> Vec {
|s, p| {
let sel = s.active().and_then(|d| d.doc.selection.clone()).ok_or(EngineError::Other("no selection".into()))?;
let mask = LayerMask { surface: sel, ..LayerMask::reveal_all() };
- set_mask(s, p, "Add Layer Mask", Some(mask))
+ // The selection becomes the mask, so Photoshop drops it (as Hide Selection does): a
+ // following Invert (⌘I) on the targeted mask then inverts all of it, not just the
+ // part inside the old selection. Same undo step as the mask.
+ set_mask_and_deselect(s, p, "Add Layer Mask", mask)
}
),
cmd!("layer.layerMask.delete", "Delete", ["Layer", "Layer Mask"], None, r##"{"layer":id?}"##, has_layer, |s, p| set_mask(
@@ -1427,6 +1447,15 @@ fn arrange(s: &mut Session, p: &Value, delta: i32) -> Result {
/// Add (`Some`) or remove (`None`) a layer mask. Adding acts on every selected layer that can take
/// one ([`crate::layer_multi_cmds::mask_targets`]), in one history step.
fn set_mask(s: &mut Session, p: &Value, label: &str, mask: Option) -> Result {
+ set_mask_with(s, p, label, mask, false)
+}
+
+/// [`set_mask`] that also drops the selection the mask was made from, in the same history step.
+fn set_mask_and_deselect(s: &mut Session, p: &Value, label: &str, mask: LayerMask) -> Result {
+ set_mask_with(s, p, label, Some(mask), true)
+}
+
+fn set_mask_with(s: &mut Session, p: &Value, label: &str, mask: Option, deselect: bool) -> Result {
let ids = if mask.is_some() { crate::layer_multi_cmds::mask_targets(s, p)? } else { vec![layer_param(s, p)?] };
s.edit(label, |doc, _| {
let mask = mask.clone().map(|mask| mask_at_depth(mask, doc.depth)).transpose()?;
@@ -1436,6 +1465,9 @@ fn set_mask(s: &mut Session, p: &Value, label: &str, mask: Option) ->
}
doc.layer_mut(*id).ok_or(EngineError::NoLayer(*id))?.mask = mask.clone();
}
+ if deselect {
+ doc.selection = None;
+ }
Ok(())
})?;
Ok(Value::Null)
@@ -1547,3 +1579,30 @@ mod registry_tests {
assert_eq!(registry.specs.len(), 2);
}
}
+
+#[cfg(test)]
+mod set_props_tests {
+ use super::*;
+
+ #[test]
+ fn opacity_and_fill_outside_zero_to_one_are_refused_not_clamped() {
+ // #5242: `55` (a percentage, as the Layer Style commands take) used to become 100 %.
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("layer.setProps", json!({"opacity": 0.55, "fill": 0.4})).unwrap();
+ let layer = |s: &Session| {
+ let d = s.active().unwrap();
+ let l = d.doc.layer(d.active_layer.unwrap()).unwrap();
+ (l.opacity, l.fill_opacity)
+ };
+ assert_eq!(layer(&s), (0.55, 0.4));
+ for bad in [json!({"opacity": 55}), json!({"opacity": -0.1}), json!({"fill": 1.5}), json!({"opacity": "50%"}), json!({"opacity": 0.5, "fill": 40})] {
+ let e = s.execute("layer.setProps", bad.clone()).unwrap_err().to_string();
+ assert!(e.contains("0..1"), "{bad}: {e}");
+ assert_eq!(layer(&s), (0.55, 0.4), "{bad} left the layer alone");
+ }
+ s.execute("layer.setProps", json!({"opacity": 0, "fill": 1})).unwrap();
+ assert_eq!(layer(&s), (0.0, 1.0));
+ }
+}
diff --git a/crates/engine/src/cutout_cmds.rs b/crates/engine/src/cutout_cmds.rs
index d5cc734668..2f6e2b70b5 100644
--- a/crates/engine/src/cutout_cmds.rs
+++ b/crates/engine/src/cutout_cmds.rs
@@ -254,7 +254,7 @@ mod tests {
let (mut s, _) = disc(8);
let before = s.active().unwrap().revision;
- assert!(s.execute(CMD, json!({"layer": 999_999})).is_err());
+ assert!(s.execute(CMD, json!({"layer": u64::MAX})).is_err());
// A `layer` string names a layer; one that isn't there is an error, not the active layer.
assert!(s.execute(CMD, json!({"layer": "x"})).is_err());
assert_eq!(s.active().unwrap().revision, before);
diff --git a/crates/engine/src/edit_cmds.rs b/crates/engine/src/edit_cmds.rs
index f0541136ad..20ef23a41b 100644
--- a/crates/engine/src/edit_cmds.rs
+++ b/crates/engine/src/edit_cmds.rs
@@ -495,9 +495,12 @@ fn new_from_clipboard(s: &mut Session) -> Result {
if w == 0 || h == 0 {
return Err(EngineError::Other("the clipboard image has no size".into()));
}
+ let (Some(dx), Some(dy)) = (b.x0.checked_neg(), b.y0.checked_neg()) else {
+ return Err(EngineError::Other("the clipboard origin is outside the coordinate range for a new document".into()));
+ };
let fmt = clip.surface.format();
let target = PixelFormat::new(fmt.mode, fmt.sample, true);
- let moved = if b.x0 == 0 && b.y0 == 0 { clip.surface } else { photocraft_algo::resample::translate_surface(&clip.surface, -b.x0, -b.y0) };
+ let moved = if dx == 0 && dy == 0 { clip.surface } else { photocraft_algo::resample::translate_surface(&clip.surface, dx, dy) };
let mut doc = Document::new("Untitled", photocraft_geom::Size::new(w, h), fmt.mode, fmt.sample);
if let Some(r) = clip.resolution.filter(|r| r.is_finite() && *r > 0.0) {
doc.resolution_dpi = r;
@@ -1044,6 +1047,19 @@ mod tests {
s
}
+ #[test]
+ fn new_clipboard_document_rejects_an_unrepresentable_origin() {
+ let mut s = Session::new();
+ let mut surface = Surface::new(PixelFormat::RGBA8);
+ surface.write_pixel(i32::MIN, 0, &[1.0, 0.0, 0.0, 1.0]);
+ s.clipboard = Some(Clip { surface, bounds: Rect::from_xywh(i32::MIN, 0, 1, 1), layers: None, resolution: None });
+ let result = new_from_clipboard(&mut s);
+ assert!(result.unwrap_err().to_string().contains("clipboard origin"));
+ assert!(s.execute("file.newFromClipboard", json!({})).is_err());
+ assert!(s.documents().is_empty());
+ assert_eq!(s.clipboard.as_ref().unwrap().surface.rgba(i32::MIN, 0), [1.0, 0.0, 0.0, 1.0]);
+ }
+
#[test]
fn injected_clear_buffer_failure_leaves_the_document_unchanged() {
let mut s = session();
diff --git a/crates/engine/src/extra_cmds.rs b/crates/engine/src/extra_cmds.rs
index 1f3748d7b9..3a27c99be3 100644
--- a/crates/engine/src/extra_cmds.rs
+++ b/crates/engine/src/extra_cmds.rs
@@ -1549,7 +1549,7 @@ mod tests {
// Layer 1 is already the only visible layer: ⌥-clicking it shows everything.
assert_eq!(s.execute("layer.showOnly", json!({})).unwrap()["shownAlone"], false);
assert!(doc(&s).layers.iter().all(|l| l.visible));
- assert!(s.execute("layer.showOnly", json!({"layer": 9999})).is_err());
+ assert!(s.execute("layer.showOnly", json!({"layer": u64::MAX})).is_err());
assert!(Session::new().execute("layer.showOnly", json!({})).is_err());
}
@@ -1624,7 +1624,7 @@ mod tests {
let bg_locks = doc(&s).layer(bg).unwrap().locks;
assert!(s.execute("layer.toggleLockTransparency", json!({"layer": bg.0})).is_err());
assert_eq!(doc(&s).layer(bg).unwrap().locks, bg_locks, "the Background is left alone");
- assert!(s.execute("layer.toggleLockTransparency", json!({"layer": 999_999})).is_err());
+ assert!(s.execute("layer.toggleLockTransparency", json!({"layer": u64::MAX})).is_err());
}
#[test]
diff --git a/crates/engine/src/file_cmds/tests.rs b/crates/engine/src/file_cmds/tests.rs
index 99ddce15de..9b6567c2a8 100644
--- a/crates/engine/src/file_cmds/tests.rs
+++ b/crates/engine/src/file_cmds/tests.rs
@@ -586,7 +586,6 @@ fn flatten_all_layer_effects_and_masks() {
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 40})).unwrap();
s.execute("select.inverse", json!({})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
assert!(composite(&s, 15, 15)[1] > 0.99 && composite(&s, 15, 15)[0] > 0.99, "white shows through the mask");
let r = s.execute("file.scripts.flattenAllMasks", json!({})).unwrap();
assert_eq!(r["flattened"], 1);
@@ -633,7 +632,6 @@ fn flatten_all_layer_effects_keeps_masks() {
.unwrap();
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 40})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
// Layer 2: a red square at the bottom-right with the same overlay and a *disabled* mask.
s.execute("layer.new.layer", json!({})).unwrap();
s.execute("select.rect", json!({"x": 30, "y": 30, "width": 8, "height": 8})).unwrap();
@@ -652,7 +650,6 @@ fn flatten_all_layer_effects_keeps_masks() {
.unwrap();
s.execute("select.rect", json!({"x": 34, "y": 34, "width": 2, "height": 2})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
s.edit("disable", |doc, _| {
if let Some(m) = doc.layer_mut(id2).and_then(|l| l.mask.as_mut()) {
m.enabled = false;
diff --git a/crates/engine/src/fill_key_cmds.rs b/crates/engine/src/fill_key_cmds.rs
index 6b94e6cd47..ce3b478a70 100644
--- a/crates/engine/src/fill_key_cmds.rs
+++ b/crates/engine/src/fill_key_cmds.rs
@@ -264,7 +264,7 @@ mod tests {
for id in IDS {
assert!(s.execute(id, json!([1, 2])).is_err(), "{id}");
assert!(s.execute(id, json!("x")).is_err(), "{id}");
- assert!(s.execute(id, json!({"layer": 99_999})).is_err(), "{id}");
+ assert!(s.execute(id, json!({"layer": u64::MAX})).is_err(), "{id}");
assert!(s.execute(id, json!({"target": {"channel": 42}})).is_err(), "{id}");
}
}
diff --git a/crates/engine/src/filters.rs b/crates/engine/src/filters.rs
index a9b6564309..9cd6ff4600 100644
--- a/crates/engine/src/filters.rs
+++ b/crates/engine/src/filters.rs
@@ -460,7 +460,6 @@ mod tests {
if reveal_selection {
s.execute("select.all", json!({})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
} else {
s.execute("layer.layerMask.revealAll", json!({})).unwrap();
}
diff --git a/crates/engine/src/filters_ext/tests.rs b/crates/engine/src/filters_ext/tests.rs
index b616101f7c..0f32c5367d 100644
--- a/crates/engine/src/filters_ext/tests.rs
+++ b/crates/engine/src/filters_ext/tests.rs
@@ -164,6 +164,27 @@ fn colour_filters_use_and_record_tool_colours() {
}
}
+#[test]
+fn fibers_fill_an_empty_layer() {
+ // #5241: Fibers renders from the colours, not the layer's pixels, so an empty layer fills
+ // like in Photoshop (and can be transformed afterwards).
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 48, "height": 32})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("filter.render.fibers", json!({"seed": 3})).unwrap();
+ let px = pixels(&s);
+ assert!(px.as_chunks::<4>().0.iter().all(|p| p[3] == 1.0), "every pixel is rendered opaque");
+ s.execute("edit.transform.flipHorizontal", json!({})).unwrap();
+
+ // With a selection only the selection fills.
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 6})).unwrap();
+ s.execute("filter.render.fibers", json!({"seed": 3})).unwrap();
+ let d = s.active().unwrap();
+ let surf = d.doc.layer(d.active_layer.unwrap()).unwrap().surface().unwrap();
+ assert_eq!(surf.content_bounds(), Rect::new(4, 4, 14, 10));
+}
+
#[test]
fn displace_reads_another_document() {
let mut s = session();
diff --git a/crates/engine/src/fx_view_cmds.rs b/crates/engine/src/fx_view_cmds.rs
index 03241d8405..3598ea56b0 100644
--- a/crates/engine/src/fx_view_cmds.rs
+++ b/crates/engine/src/fx_view_cmds.rs
@@ -118,7 +118,7 @@ mod tests {
let bg = s.active().unwrap().doc.layers[0].id.0;
for p in [
json!({"layer": bg}),
- json!({"layer": 9999}),
+ json!({"layer": u64::MAX}),
json!({"layer": "x"}),
json!({"layer": -1}),
json!({"expanded": "yes", "all": true}),
diff --git a/crates/engine/src/fx_visibility_cmds.rs b/crates/engine/src/fx_visibility_cmds.rs
index bc24d84b18..7911bcd3cc 100644
--- a/crates/engine/src/fx_visibility_cmds.rs
+++ b/crates/engine/src/fx_visibility_cmds.rs
@@ -161,7 +161,7 @@ mod tests {
let before = state(&s, a);
for p in [
json!({"layer": bg}),
- json!({"layer": 9999}),
+ json!({"layer": u64::MAX}),
json!({"layer": "x"}),
json!({"layer": -1}),
json!({"layer": a, "index": 2}),
diff --git a/crates/engine/src/gradient_fill_cmds/tests.rs b/crates/engine/src/gradient_fill_cmds/tests.rs
index bb357df050..efcdb494d9 100644
--- a/crates/engine/src/gradient_fill_cmds/tests.rs
+++ b/crates/engine/src/gradient_fill_cmds/tests.rs
@@ -273,7 +273,7 @@ fn commands_fail_gracefully() {
// A zero-length drag still makes a valid gradient.
s.execute(CREATE, json!({"from": [3, 3], "to": [3, 3]})).unwrap();
for p in [
- json!({"layer": 999_999}),
+ json!({"layer": u64::MAX}),
json!({"from": [0]}),
json!({"to": [1e30, 0]}),
json!({"angle": "x"}),
diff --git a/crates/engine/src/group_view_cmds.rs b/crates/engine/src/group_view_cmds.rs
index 32a22f5e39..b95acff6a7 100644
--- a/crates/engine/src/group_view_cmds.rs
+++ b/crates/engine/src/group_view_cmds.rs
@@ -142,7 +142,7 @@ mod tests {
let bg = s.active().unwrap().doc.layers[0].id.0;
for p in [
json!({"layer": bg}),
- json!({"layer": 9999}),
+ json!({"layer": u64::MAX}),
json!({"layer": "x"}),
json!({"layer": -1}),
json!({"expanded": "yes", "all": true}),
diff --git a/crates/engine/src/layer_copy_cmds/tests.rs b/crates/engine/src/layer_copy_cmds/tests.rs
index a81ebbdc47..93bd7b94ef 100644
--- a/crates/engine/src/layer_copy_cmds/tests.rs
+++ b/crates/engine/src/layer_copy_cmds/tests.rs
@@ -130,7 +130,7 @@ fn bad_params_and_states_fail_without_changing_anything() {
json!({"document": -1}),
json!({"document": "1"}),
json!({"document": 1, "source": 9}),
- json!({"document": 1, "layers": [999_999]}),
+ json!({"document": 1, "layers": [u64::MAX]}),
json!({"document": 1, "layers": "all"}),
json!({"document": 1, "layers": []}),
json!({"document": 1, "at": [1.0]}),
@@ -314,7 +314,7 @@ fn duplicate_destinations_that_are_not_new_fail_cleanly() {
json!({"document": []}),
json!({"document": {}}),
json!({"document": "other"}),
- json!({"document": "new", "layer": 999_999}),
+ json!({"document": "new", "layer": u64::MAX}),
] {
let before = (doc(&s, 0).clone(), s.documents().len(), s.active_index());
let err = s.execute("layer.duplicate", p.clone()).unwrap_err().to_string();
diff --git a/crates/engine/src/layer_menu_cmds/tests.rs b/crates/engine/src/layer_menu_cmds/tests.rs
index 708bee5fce..46688500b1 100644
--- a/crates/engine/src/layer_menu_cmds/tests.rs
+++ b/crates/engine/src/layer_menu_cmds/tests.rs
@@ -588,7 +588,7 @@ fn transfer_effects_moves_or_copies_between_layers() {
for bad in [
json!({"from": a.0, "to": a.0}),
json!({"from": a.0}),
- json!({"from": a.0, "to": 9999}),
+ json!({"from": a.0, "to": u64::MAX}),
json!({"from": a.0, "to": b.0, "effect": 7}),
json!({"from": a.0, "to": b.0, "effect": -1}),
json!({"from": b.0, "to": a.0}),
diff --git a/crates/engine/src/layer_multi_cmds.rs b/crates/engine/src/layer_multi_cmds.rs
index 21e9e2caac..80da3bdd81 100644
--- a/crates/engine/src/layer_multi_cmds.rs
+++ b/crates/engine/src/layer_multi_cmds.rs
@@ -1625,8 +1625,8 @@ mod tests {
let all = doc(&s).bounds();
assert!(damage(&s).is_none_or(|r| r.contains_rect(&all)), "{:?}", damage(&s));
// Bad params still fail cleanly.
- assert!(s.execute("layer.setProps", json!({"layer": 999_999, "visible": true})).is_err());
- assert!(s.execute("layer.translate", json!({"layer": 999_999, "dx": 1})).is_err());
+ assert!(s.execute("layer.setProps", json!({"layer": u64::MAX, "visible": true})).is_err());
+ assert!(s.execute("layer.translate", json!({"layer": u64::MAX, "dx": 1})).is_err());
}
/// #1771: a new empty layer or group changes no pixels, so it (and undoing or redoing it)
@@ -1805,7 +1805,7 @@ mod tests {
let mut locked = (*before).clone();
locked.layer_mut(a).unwrap().locks.position = true;
assert!(moved(&locked, &ids, 1, 1).is_err());
- assert!(moved(&before, &[LayerId(999_999)], 1, 1).is_err());
+ assert!(moved(&before, &[LayerId(u64::MAX)], 1, 1).is_err());
}
#[test]
@@ -1894,7 +1894,7 @@ mod tests {
assert_eq!(s.active().unwrap().doc.layer(a).unwrap().name, "x");
s.execute("layer.showLayers", json!({"layer": a.0})).unwrap();
assert!(s.active().unwrap().doc.layer(a).unwrap().visible);
- assert!(s.execute("layer.hideLayers", json!({"layer": 999_999})).is_err());
+ assert!(s.execute("layer.hideLayers", json!({"layer": u64::MAX})).is_err());
assert!(s.execute("layer.hideLayers", json!({})).is_err());
assert!(!s.is_enabled("layer.align.topEdges"));
}
diff --git a/crates/engine/src/layer_style.rs b/crates/engine/src/layer_style.rs
index fbbc949e20..5f7b8f0eee 100644
--- a/crates/engine/src/layer_style.rs
+++ b/crates/engine/src/layer_style.rs
@@ -1206,7 +1206,7 @@ mod tests {
let layer = s.active().unwrap().active_layer.unwrap().0;
s.execute("layer.layerStyle.clear", json!({"layer": layer, "effect": 0})).unwrap();
assert!(matches!(effects(&s)[..], [Effect::ColorOverlay { .. }]));
- for bad in [json!({"effect": 5}), json!({"effect": -1}), json!({"effect": "x"}), json!({"effect": 0, "layer": 999_999})] {
+ for bad in [json!({"effect": 5}), json!({"effect": -1}), json!({"effect": "x"}), json!({"effect": 0, "layer": u64::MAX})] {
assert!(s.execute("layer.layerStyle.clear", bad).is_err());
}
assert_eq!(effects(&s).len(), 1, "bad params change nothing");
diff --git a/crates/engine/src/mask_view_cmds/tests.rs b/crates/engine/src/mask_view_cmds/tests.rs
index 33e36b1421..ce9bffa744 100644
--- a/crates/engine/src/mask_view_cmds/tests.rs
+++ b/crates/engine/src/mask_view_cmds/tests.rs
@@ -10,7 +10,6 @@ fn session() -> (Session, u64, u64) {
s.execute("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap();
s.execute("select.rect", json!({"x": 20, "y": 0, "width": 20, "height": 20})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
let st = s.active_mut().unwrap();
st.saved_revision = st.revision;
(s, masked, bg)
@@ -96,7 +95,7 @@ fn bad_params_and_no_mask_fail_gracefully() {
for p in [
json!({"layer": bg, "mode": "gray"}),
json!({"layer": bg}),
- json!({"layer": 999_999, "mode": "gray"}),
+ json!({"layer": u64::MAX, "mode": "gray"}),
json!({"layer": "x"}),
json!({"layer": -1}),
json!({"mode": 3}),
diff --git a/crates/engine/src/pattern_fill_cmds.rs b/crates/engine/src/pattern_fill_cmds.rs
index daa7e9660f..b9d75e6cb5 100644
--- a/crates/engine/src/pattern_fill_cmds.rs
+++ b/crates/engine/src/pattern_fill_cmds.rs
@@ -225,7 +225,7 @@ mod tests {
json!([1, 2]),
json!({"layer": -1}),
json!({"layer": "x"}),
- json!({"layer": 999_999}),
+ json!({"layer": u64::MAX}),
json!({"document": 999_999}),
json!({"pattern": "nope"}),
json!({"pattern": ""}),
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index 5e728cb546..b163d40d88 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -1553,7 +1553,8 @@ impl Session {
}
};
interface.insert("appearanceMode".into(), json!(mode));
- interface.insert(slot.into(), json!(theme.name()));
+ // A partially migrated file may already contain a newer theme selection (#5139).
+ interface.entry(slot).or_insert_with(|| json!(theme.name()));
}
let color = v.as_object_mut().and_then(|m| m.remove("colorSettings"));
let presets = v.as_object_mut().and_then(|m| m.remove("presets"));
diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rs
index 36a5b69abc..6b56cbc7ba 100644
--- a/crates/engine/src/prefs/tests.rs
+++ b/crates/engine/src/prefs/tests.rs
@@ -67,6 +67,17 @@ fn appearance_defaults_and_legacy_theme_migrate() {
}
}
+#[test]
+fn legacy_theme_migration_preserves_saved_theme_slots() {
+ for (legacy, slot, saved) in [("proMedium", "darkTheme", "solarizedDark"), ("studioLight", "lightTheme", "adwaita")] {
+ let mut interface = json!({"theme": legacy});
+ interface[slot] = json!(saved);
+ let mut session = Session::new();
+ session.load_prefs_json(&json!({"interface": interface}).to_string()).unwrap();
+ assert_eq!(session.prefs_value()["interface"][slot], saved, "explicit {slot} survives migration");
+ }
+}
+
#[test]
fn appearance_choices_validate_and_legacy_theme_still_selects() {
let mut s = Session::new();
diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rs
index 73324711d9..9a0af4a054 100644
--- a/crates/engine/src/print_cmds.rs
+++ b/crates/engine/src/print_cmds.rs
@@ -14,6 +14,8 @@
use std::io::Write as _;
+mod windows_marks;
+
use photocraft_color::ColorMode;
use photocraft_doc::{Document, LayerContent, SmartSource};
use serde_json::{Value, json};
@@ -388,6 +390,21 @@ fn render_and_spool(doc: &Document, p: &Value, cmd: &str) -> Result {
let send = p.get("send").and_then(Value::as_bool).unwrap_or(output.is_none());
let copies = crate::commands::int(p, "copies").unwrap_or(1).clamp(1, 999) as u32;
let dry = p.get("dryRun").and_then(Value::as_bool).unwrap_or(false);
+ // Shared RGB transport handles compatible Windows pages; PDF-only content retains its route.
+ // Sending follows the shared command contract; fuzz tests explicitly request dryRun.
+ // The worker returns its result before repeat settings and hooks are applied once.
+ let handling = p.get("colorHandling").and_then(Value::as_str).unwrap_or("printerManages");
+ if cfg!(windows) && send && !dry && output.is_none() && native_rgb_compatible(&page, handling) {
+ require_printing_enabled()?;
+ let printed = print_windows(&page, p, &doc.name, copies)?;
+ return Ok(json!({
+ "pdf": Value::Null, "paper": [pw, ph], "imageRect": [x, y, w, h], "emulsionDown": emulsion_down, "scale": scale * 100.0,
+ "copies": copies, "command": Value::Null, "sent": true, "spooler": printed, "color": color,
+ }));
+ }
+ if cfg!(windows) && send && !dry && output.is_none() && printer_settings(p)?.is_some() {
+ return Err(other("the selected color profile or page text requires PDF printing. Save as PDF, or clear Print Settings to use PDF printing."));
+ }
let pdf = print_pdf(&page);
let job = craft_print::Job {
printer: p.get("printer").and_then(Value::as_str).filter(|v| !v.is_empty()).map(str::to_string),
@@ -409,13 +426,7 @@ fn render_and_spool(doc: &Document, p: &Value, cmd: &str) -> Result {
let mut sent = false;
let mut spool = Value::Null;
if send && !dry {
- // The last line of defence: a test or fuzz run must never print a page (`dryRun` still
- // renders and reports the command).
- if printing_disabled() {
- return Err(other(
- "printing is disabled in this process (photocraft_engine::print_cmds::disable_printing or PHOTOCRAFT_NO_PRINT); use dryRun: true",
- ));
- }
+ require_printing_enabled()?;
spool = json!(craft_print::submit(&pdf, &job).map_err(other)?);
sent = true;
}
@@ -424,6 +435,15 @@ fn render_and_spool(doc: &Document, p: &Value, cmd: &str) -> Result {
)
}
+/// Keep CMYK output profiles and page text on the existing PDF composition path. GDI currently
+/// draws RGB/gray and vector marks only; it must never silently omit requested page content.
+fn native_rgb_compatible(page: &PrintPage, handling: &str) -> bool {
+ matches!(page.image.channels, 1 | 3)
+ && (page.image.icc.is_none() || matches!(handling, "photocraftManages" | "photoshopManages" | "noColorManagement"))
+ && page.description.as_deref().is_none_or(str::is_empty)
+ && page.label.as_deref().is_none_or(str::is_empty)
+}
+
/// Print One Copy repeats these.
fn remember_print(s: &mut Session, p: &Value) {
let mut remembered = p.clone();
@@ -436,6 +456,101 @@ fn remember_print(s: &mut Session, p: &Value) {
s.file_menu.last_print = Some(remembered);
}
+/// The `printer` parameter, or the system's default printer.
+fn printer_name(p: &Value) -> Result {
+ if let Some(name) = p.get("printer").and_then(Value::as_str).filter(|v| !v.trim().is_empty()) {
+ return Ok(name.to_string());
+ }
+ craft_print::rgb::default_printer().map_err(other)?.ok_or_else(|| other("no printer chosen and no default printer is set"))
+}
+
+/// The driver settings chosen with Print Settings… (`printerSettings`, hex), when any.
+fn printer_settings(p: &Value) -> Result> {
+ match p.get("printerSettings").and_then(Value::as_str).filter(|v| !v.is_empty()) {
+ Some(hex) => craft_print::rgb::DevMode::from_hex(hex).map(Some).map_err(|e| bad("file.print", e.to_string())),
+ None => Ok(None),
+ }
+}
+
+/// The page's image as 8-bit RGB rows (gray expanded), mirrored for Emulsion Down.
+pub fn page_rgb(page: &PrintPage) -> Result> {
+ let img = &page.image;
+ let (w, h) = (img.width as usize, img.height as usize);
+ let mut rgb = match img.channels {
+ 3 => img.data.clone(),
+ 1 => img.data.iter().flat_map(|g| [*g, *g, *g]).collect(),
+ _ => return Err(other("this printer profile is CMYK; Windows printers take RGB, so choose the printer's own (RGB) profile")),
+ };
+ let row = w.checked_mul(3).ok_or_else(|| other("print image is too large"))?;
+ if row == 0 || row.checked_mul(h) != Some(rgb.len()) {
+ return Err(other("nothing to print"));
+ }
+ if page.emulsion_down {
+ for row in rgb.chunks_exact_mut(row) {
+ row.as_chunks_mut::<3>().0.reverse();
+ }
+ }
+ Ok(rgb)
+}
+
+/// The image box with its origin at the sheet's top-left (GDI's), mirrored for Emulsion Down.
+pub fn page_rect_top_left(page: &PrintPage) -> (f64, f64, f64, f64) {
+ let (pw, ph) = page.paper;
+ let (x, y, w, h) = page.rect;
+ let x = if page.emulsion_down { pw - x - w } else { x };
+ (x, ph - y - h, w, h)
+}
+
+/// Prints `page` on a Windows printer. Corner/centre crop and registration marks are drawn with
+/// GDI vector calls, matching the PDF path's geometry; description and label text are still
+/// PDF-only (no font/text layout in the GDI path yet).
+fn print_windows(page: &PrintPage, p: &Value, title: &str, copies: u32) -> Result {
+ let printer = printer_name(p)?;
+ let settings = printer_settings(p)?;
+ let device_page = craft_print::rgb::page(&printer, settings.as_ref()).map_err(other)?;
+ if (device_page.paper.0 - page.paper.0).abs() > 2.0 || (device_page.paper.1 - page.paper.1).abs() > 2.0 {
+ return Err(other("the driver paper or orientation differs from the print layout; choose the matching paper in Print Settings before printing"));
+ }
+ let rgb = page_rgb(page)?;
+ let image = craft_print::rgb::RgbImage { width: page.image.width, height: page.image.height, data: &rgb };
+ let rect = page_rect_top_left(page);
+ let primitives = windows_marks::primitives(page.marks, rect);
+ let color_policy = match p.get("colorHandling").and_then(Value::as_str) {
+ Some("photocraftManages" | "photoshopManages") => craft_print::rgb::ColorPolicy::ApplicationManaged,
+ Some("noColorManagement") => craft_print::rgb::ColorPolicy::Unmanaged,
+ _ => craft_print::rgb::ColorPolicy::DriverManaged,
+ };
+ let job = craft_print::rgb::Job {
+ printer: &printer,
+ settings: settings.as_ref(),
+ title,
+ output_file: None,
+ copies: copies.clamp(1, 999),
+ color_policy,
+ primitives: &primitives,
+ };
+ let done = craft_print::rgb::print(&job, &image, rect).map_err(other)?;
+ Ok(
+ json!({"printer": printer, "dpi": [done.dpi.0, done.dpi.1], "deviceRect": [done.device_rect.0, done.device_rect.1, done.device_rect.2, done.device_rect.3]}),
+ )
+}
+
+fn printers(_: &mut Session, _: &Value) -> Result {
+ match craft_print::rgb::printers() {
+ Ok(list) => Ok(json!({"supported": true, "printers": list.iter().map(|p| json!({"name": p.name, "default": p.default})).collect::>()})),
+ Err(craft_print::rgb::PrintError::Unsupported) => Ok(json!({"supported": false, "printers": []})),
+ Err(e) => Err(other(e)),
+ }
+}
+
+fn printer_page(_: &mut Session, p: &Value) -> Result {
+ let printer = printer_name(p)?;
+ let pg = craft_print::rgb::page(&printer, printer_settings(p)?.as_ref()).map_err(other)?;
+ Ok(
+ json!({"printer": printer, "paper": [pg.paper.0, pg.paper.1], "printable": [pg.printable.0, pg.printable.1, pg.printable.2, pg.printable.3], "dpi": [pg.dpi.0, pg.dpi.1]}),
+ )
+}
+
/// Set once by test harnesses (the panic hunt) so no command in the process can reach a printer.
static PRINTING_DISABLED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
@@ -450,9 +565,17 @@ pub fn printing_disabled() -> bool {
PRINTING_DISABLED.load(std::sync::atomic::Ordering::Relaxed) || std::env::var_os("PHOTOCRAFT_NO_PRINT").is_some_and(|v| !v.is_empty() && v != "0")
}
+fn require_printing_enabled() -> Result<()> {
+ if printing_disabled() {
+ Err(other("printing is disabled in this process (photocraft_engine::print_cmds::disable_printing or PHOTOCRAFT_NO_PRINT); use dryRun: true"))
+ } else {
+ Ok(())
+ }
+}
+
/// The printers the system spooler knows (Print's Printer menu): CUPS queues and driverless
/// destinations on macOS and Linux, `Win32_Printer` on Windows, none in the browser.
-fn printers(_: &mut Session, _: &Value) -> Result {
+fn system_printers(_: &mut Session, _: &Value) -> Result {
let list = craft_print::printers();
let default = list.iter().find(|p| p.default).map(|p| p.name.clone());
let printers: Vec = list.into_iter().map(|p| json!({"name": p.name, "default": p.default})).collect();
@@ -627,9 +750,30 @@ pub fn specs() -> Vec {
CommandSpec { id: $id, label: $label, menu: $menu, shortcut: $sc, params: $params, enabled: $enabled, journal: true, run: $run }
};
}
- const PRINT_PARAMS: &str = r##"{"printer":name? (default printer),"copies":1..999=1,"paper":"letter|legal|tabloid|a3|a4|a5|4x6|5x7"|[w,h] pt="letter","orientation":"portrait|landscape"="portrait","center":bool=true,"top":in?,"left":in?,"scale":%=100,"scaleToFit":bool=false,"colorHandling":"printerManages|photocraftManages|noColorManagement"="printerManages","printerProfile":profile? (photocraftManages),"intent":"perceptual|relative|saturation|absolute"="relative","bpc":bool=true,"cornerCropMarks":bool,"centerCropMarks":bool,"registrationMarks":bool,"description":bool,"labels":bool,"emulsionDown":bool=false (mirror the page left to right, for sublimation and other transfer printing),"output":pdf path? (print to PDF; then "send" defaults to false),"send":bool?,"dryRun":bool=false (render the PDF, report the backend command, don't spool; write a PDF only at an explicit output path)} → {pdf:path|null (null without explicit output), imageRect, command:diagnostic array|null, sent}"##;
+ const PRINT_PARAMS: &str = r##"{"printerSettings":hex? (Windows driver settings),"printer":name? (default printer),"copies":1..999=1,"paper":"letter|legal|tabloid|a3|a4|a5|4x6|5x7"|[w,h] pt="letter","orientation":"portrait|landscape"="portrait","center":bool=true,"top":in?,"left":in?,"scale":%=100,"scaleToFit":bool=false,"colorHandling":"printerManages|photocraftManages|noColorManagement"="printerManages","printerProfile":profile? (photocraftManages),"intent":"perceptual|relative|saturation|absolute"="relative","bpc":bool=true,"cornerCropMarks":bool,"centerCropMarks":bool,"registrationMarks":bool,"description":bool,"labels":bool,"emulsionDown":bool=false (mirror the page left to right, for sublimation and other transfer printing),"output":pdf path? (print to PDF; then "send" defaults to false),"send":bool?,"dryRun":bool=false (render the PDF, report the backend command, don't spool; write a PDF only at an explicit output path)} → {pdf:path|null (null without explicit output), imageRect, command:diagnostic array|null, sent}"##;
+
vec![
spec!("file.print", "Print…", &["File"], Some("Cmd+P"), PRINT_PARAMS, native_doc, print),
+ CommandSpec {
+ id: "file.print.printers",
+ label: "Printers",
+ menu: &[],
+ shortcut: None,
+ params: r##"{} → {supported, printers: [{name, default}]} (supported: Windows; elsewhere Print spools with lp)"##,
+ enabled: |_| Ok(()),
+ journal: false,
+ run: printers,
+ },
+ CommandSpec {
+ id: "file.print.page",
+ label: "Printer Page",
+ menu: &[],
+ shortcut: None,
+ params: r##"{"printer":name? (default printer),"printerSettings":hex?} → {printer, paper: [w,h] pt, printable: [x,y,w,h] pt from the top-left, dpi: [x,y]} (Windows)"##,
+ enabled: |_| Ok(()),
+ journal: false,
+ run: printer_page,
+ },
CommandSpec {
id: "file.printers",
label: "Printers",
@@ -638,7 +782,7 @@ pub fn specs() -> Vec {
params: r##"{} → {printers:[{name, default}], default:name|null} (the system spooler's printers; a name is Print's "printer")"##,
enabled: crate::commands::always,
journal: false,
- run: printers,
+ run: system_printers,
},
spec!(
"file.printOneCopy",
diff --git a/crates/engine/src/print_cmds/tests.rs b/crates/engine/src/print_cmds/tests.rs
index bf5f1e3857..d012f6de41 100644
--- a/crates/engine/src/print_cmds/tests.rs
+++ b/crates/engine/src/print_cmds/tests.rs
@@ -52,7 +52,7 @@ fn print_dry_run_renders_a_pdf_and_reports_the_platform_backend() {
assert!(!cmd.contains(&out), "PDF bytes are streamed instead of passing a path");
}
#[cfg(windows)]
- assert!(cmd.last().unwrap().contains("craft-print PDF spooler"));
+ assert_eq!(cmd.first().map(String::as_str), Some("xps-print"));
assert_eq!(r["sent"], false);
assert_eq!(r["pdf"], out);
let pdf = std::fs::read(&out).unwrap();
@@ -151,6 +151,60 @@ fn emulsion_down_mirrors_the_whole_page() {
let _ = std::fs::remove_dir_all(&dir);
}
+fn page_of(channels: usize, data: Vec, emulsion_down: bool) -> PrintPage {
+ PrintPage {
+ paper: (600.0, 800.0),
+ image: PrintImage { width: 2, height: 1, channels, data, icc: None },
+ rect: (100.0, 200.0, 144.0, 72.0),
+ marks: Marks::default(),
+ description: None,
+ label: None,
+ emulsion_down,
+ }
+}
+
+#[test]
+fn windows_print_image_is_rgb_mirrored_for_emulsion_down() {
+ assert_eq!(page_rgb(&page_of(3, vec![1, 2, 3, 4, 5, 6], false)).unwrap(), [1, 2, 3, 4, 5, 6]);
+ assert_eq!(page_rgb(&page_of(3, vec![1, 2, 3, 4, 5, 6], true)).unwrap(), [4, 5, 6, 1, 2, 3]);
+ assert_eq!(page_rgb(&page_of(1, vec![7, 9], true)).unwrap(), [9, 9, 9, 7, 7, 7]);
+ assert!(page_rgb(&page_of(4, vec![0; 8], false)).is_err(), "CMYK can't go to a GDI printer");
+ assert!(page_rgb(&page_of(3, vec![0; 5], false)).is_err(), "short data");
+ // GDI's origin is the sheet's top-left; Emulsion Down moves the box to the mirrored side.
+ assert_eq!(page_rect_top_left(&page_of(3, vec![0; 6], false)), (100.0, 528.0, 144.0, 72.0));
+ assert_eq!(page_rect_top_left(&page_of(3, vec![0; 6], true)), (356.0, 528.0, 144.0, 72.0));
+}
+
+#[test]
+fn native_rgb_route_preserves_pdf_only_color_and_page_content() {
+ let mut page = page_of(3, vec![0; 6], false);
+ assert!(native_rgb_compatible(&page, "printerManages"));
+ page.label = Some("Print Me".into());
+ assert!(!native_rgb_compatible(&page, "printerManages"));
+ page.label = None;
+ page.description = Some("Proof description".into());
+ assert!(!native_rgb_compatible(&page, "printerManages"));
+ page.description = Some(String::new());
+ assert!(native_rgb_compatible(&page, "printerManages"));
+ page.image.icc = Some(vec![1, 2, 3]);
+ assert!(!native_rgb_compatible(&page, "printerManages"), "preserve embedded source ICC in the PDF route");
+ assert!(native_rgb_compatible(&page, "photocraftManages"));
+ assert!(native_rgb_compatible(&page, "photoshopManages"));
+ assert!(!native_rgb_compatible(&page_of(4, vec![0; 8], false), "photocraftManages"));
+ assert!(native_rgb_compatible(&page_of(1, vec![0; 2], false), "noColorManagement"));
+}
+
+#[test]
+fn printer_commands_answer_without_a_document_and_reject_bad_settings() {
+ let mut s = Session::new();
+ let r = s.execute("file.print.printers", json!({})).unwrap();
+ assert_eq!(r["supported"], cfg!(windows));
+ assert!(r["printers"].is_array());
+ assert!(s.execute("file.print.page", json!({"printer": "Anything", "printerSettings": "zz"})).is_err());
+ let mut s = session("rgb", 8);
+ assert!(s.execute("file.print", json!({"printer": "Anything", "printerSettings": "0102", "send": true})).is_err());
+}
+
#[test]
fn printer_profile_can_be_an_installed_icc_file() {
let dir = tmp("icc");
@@ -183,7 +237,7 @@ fn print_one_copy_repeats_the_last_settings() {
#[cfg(unix)]
assert_eq!(&cmd[..3], &["lp", "-n", "1"]);
#[cfg(windows)]
- assert!(cmd.last().unwrap().contains("craft-print PDF spooler"));
+ assert_eq!(cmd.first().map(String::as_str), Some("xps-print"));
assert!(r["pdf"].is_null());
}
diff --git a/crates/engine/src/print_cmds/windows_marks.rs b/crates/engine/src/print_cmds/windows_marks.rs
new file mode 100644
index 0000000000..857e6335a9
--- /dev/null
+++ b/crates/engine/src/print_cmds/windows_marks.rs
@@ -0,0 +1,47 @@
+//! App-owned print-mark composition in points from the sheet's top-left.
+use super::Marks;
+use craft_print::rgb::{Primitive, Shape};
+
+pub(super) fn primitives(marks: Marks, (x, y, w, h): (f64, f64, f64, f64)) -> Vec {
+ let mut out = Vec::with_capacity(24);
+ let line = |out: &mut Vec, x0, y0, x1, y1| {
+ out.push(Primitive { shape: Shape::Line { from: (x0, y0), to: (x1, y1) }, width: 0.3, color: [0; 3] });
+ };
+ let (gap, len) = (6.0, 18.0);
+ if marks.corner_crop {
+ for (cx, cy, dx, dy) in [(x, y, -1.0, -1.0), (x + w, y, 1.0, -1.0), (x, y + h, -1.0, 1.0), (x + w, y + h, 1.0, 1.0)] {
+ line(&mut out, cx + dx * gap, cy, cx + dx * (gap + len), cy);
+ line(&mut out, cx, cy + dy * gap, cx, cy + dy * (gap + len));
+ }
+ }
+ if marks.center_crop {
+ let (mx, my) = (x + w / 2.0, y + h / 2.0);
+ line(&mut out, mx, y - gap, mx, y - gap - len);
+ line(&mut out, mx, y + h + gap, mx, y + h + gap + len);
+ line(&mut out, x - gap, my, x - gap - len, my);
+ line(&mut out, x + w + gap, my, x + w + gap + len, my);
+ }
+ if marks.registration {
+ let (r, off) = (5.0, gap + len / 2.0);
+ for (cx, cy) in [(x + w / 2.0, y - off), (x + w / 2.0, y + h + off), (x - off, y + h / 2.0), (x + w + off, y + h / 2.0)] {
+ out.push(Primitive { shape: Shape::Ellipse { bounds: (cx - r, cy - r, 2.0 * r, 2.0 * r) }, width: 0.3, color: [0; 3] });
+ line(&mut out, cx - r * 1.6, cy, cx + r * 1.6, cy);
+ line(&mut out, cx, cy - r * 1.6, cx, cy + r * 1.6);
+ }
+ }
+ out
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ #[test]
+ fn marks_surround_the_final_image_box_in_physical_points() {
+ let out = primitives(Marks { corner_crop: true, center_crop: true, registration: true }, (100.0, 200.0, 144.0, 72.0));
+ assert_eq!(out.len(), 24);
+ assert_eq!(out[0].shape, Shape::Line { from: (94.0, 200.0), to: (76.0, 200.0) });
+ assert_eq!(out[12].shape, Shape::Ellipse { bounds: (167.0, 180.0, 10.0, 10.0) });
+ assert!(out.iter().all(|p| p.width == 0.3 && p.color == [0; 3]));
+ assert!(primitives(Marks::default(), (0.0, 0.0, 10.0, 10.0)).is_empty());
+ }
+}
diff --git a/crates/engine/src/rasterize_style_cmds/tests.rs b/crates/engine/src/rasterize_style_cmds/tests.rs
index 9b5ef7d359..b4391cb6f2 100644
--- a/crates/engine/src/rasterize_style_cmds/tests.rs
+++ b/crates/engine/src/rasterize_style_cmds/tests.rs
@@ -78,7 +78,6 @@ fn fill_opacity_masks_and_layer_opacity_survive_the_bake() {
s.execute("layer.setProps", json!({"layer": id, "fill": 0.4, "opacity": 0.7})).unwrap();
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 34, "height": 48})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
let square = json!({"subpaths": [{"closed": true, "knots": [[4, 4], [60, 4], [60, 26], [4, 26]]}]});
s.execute("layer.vectorMask.add", json!({"layer": id, "path": square})).unwrap();
bake_and_check(&mut s, id, depth);
@@ -153,7 +152,7 @@ fn disabled_and_bad_params_fail_gracefully() {
let (mut s, id) = scene(8);
let bg = doc(&s).layers[0].id.0;
assert!(s.execute(ID, json!({"layer": bg})).is_err(), "the Background has no effects");
- assert!(s.execute(ID, json!({"layer": 9999})).is_err(), "no such layer");
+ assert!(s.execute(ID, json!({"layer": u64::MAX})).is_err(), "no such layer");
assert!(s.execute(ID, json!({"layer": u64::MAX})).is_err(), "no such layer");
assert_eq!(layer(&s, id).effects.items.len(), 5, "a bad call changes nothing");
s.execute("layer.layerStyle.hideAllEffects", json!({})).unwrap();
diff --git a/crates/engine/src/retouch_cmds/tests.rs b/crates/engine/src/retouch_cmds/tests.rs
index 9a0ae22f08..e20706857a 100644
--- a/crates/engine/src/retouch_cmds/tests.rs
+++ b/crates/engine/src/retouch_cmds/tests.rs
@@ -993,7 +993,7 @@ fn patch_fails_gracefully() {
json!({"offset": [0, -30]}),
json!({"offset": [10, 0], "target": "mask"}),
json!({"offset": [10, 0], "target": {"channel": 7}}),
- json!({"offset": [10, 0], "layer": 999}),
+ json!({"offset": [10, 0], "layer": u64::MAX}),
] {
assert!(s.execute("paint.patch", p.clone()).is_err(), "{p}");
}
@@ -1269,7 +1269,7 @@ fn content_aware_move_fails_gracefully() {
json!({"offset": [0, -30]}),
json!({"offset": [10, 0], "target": "mask"}),
json!({"offset": [10, 0], "target": {"channel": 7}}),
- json!({"offset": [10, 0], "layer": 999}),
+ json!({"offset": [10, 0], "layer": u64::MAX}),
json!({"offset": [10, 0], "scaleX": 0}),
json!({"offset": [10, 0], "scaleY": 0.5}),
json!({"offset": [10, 0], "scaleX": 1e9}),
@@ -1727,7 +1727,7 @@ fn remove_bad_params_are_errors() {
json!({"points": []}),
json!({"points": "x"}),
json!({"points": [[1, 1]], "size": "big", "closeLoops": "yes", "sampleAllLayers": 3}),
- json!({"points": [[1, 1]], "layer": 999_999}),
+ json!({"points": [[1, 1]], "layer": u64::MAX}),
] {
let _ = s.execute("paint.remove", p);
}
diff --git a/crates/engine/src/selection_cmds.rs b/crates/engine/src/selection_cmds.rs
index 8efb8d7b94..ecc812a51c 100644
--- a/crates/engine/src/selection_cmds.rs
+++ b/crates/engine/src/selection_cmds.rs
@@ -461,7 +461,12 @@ fn modify(s: &mut Session, p: &Value, op: &str) -> Result {
// continue past the canvas. Border has no such option: its band always follows the canvas edge,
// or a Select All would border to nothing.
let at_bounds = op == "border" || b(p, "applyAtCanvasBounds", false);
- let (area, m) = current_mask(&s.active().ok_or(EngineError::NoDocument)?.doc);
+ let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;
+ let area = doc.bounds();
+ if area.size().area() > MAX_MODIFY_PIXELS as u64 {
+ return Err(EngineError::BadParams { cmd: format!("select.modify.{op}"), msg: "the selection is too large to modify".into() });
+ }
+ let (_, m) = current_mask(doc);
let (w, h) = (area.width() as usize, area.height() as usize);
// Feather reaches 3σ = 3 r (σ = r, as in Photoshop); the others reach r. A margin past that
// keeps the canvas edge out of reach. A selection clear of the canvas edge needs none: both
@@ -765,6 +770,28 @@ mod tests {
assert!(err.to_string().contains("detectFaces"), "{err}");
}
+ #[test]
+ fn modify_rejects_oversized_canvases_before_reading_the_mask() {
+ let mut s = Session::new();
+ let mut doc = photocraft_doc::Document::new(
+ "large",
+ photocraft_geom::Size::new(300_000, 300_000),
+ photocraft_color::ColorMode::Rgb,
+ photocraft_color::SampleType::U8,
+ );
+ let mut selection = photocraft_raster::Surface::new(photocraft_color::PixelFormat::GRAY8);
+ selection.write_pixel(0, 0, &[1.0]);
+ doc.selection = Some(selection);
+ s.add_document(doc, None);
+ let before = s.active().unwrap().doc.clone();
+ for op in ["expand", "contract", "border", "smooth", "feather"] {
+ let error = s.execute(&format!("select.modify.{op}"), json!({"radius": 1})).unwrap_err();
+ assert!(error.to_string().contains("too large to modify"));
+ assert_eq!(*s.active().unwrap().doc, *before);
+ assert!(!s.active().unwrap().history.can_undo());
+ }
+ }
+
#[test]
fn color_range_replace_is_bounded_by_existing_selection() {
for params in [json!({"color": "#ff0000", "fuzziness": 0}), json!({"select": "reds"})] {
@@ -850,7 +877,6 @@ mod tests {
let mut s = session();
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
s.execute("view.layerMask", json!({"mode": "gray"})).unwrap();
s.execute("select.magicWand", json!({"x": 7, "y": 7, "tolerance": 0, "antiAlias": false})).unwrap();
assert_eq!(coverage(&s, 2, 2), 1.0, "gray mask view selects the mask");
@@ -977,6 +1003,45 @@ mod tests {
assert!(lighter > redder + 0.15 && redder > 0.0, "lighter {lighter}, redder {redder}");
}
+ #[test]
+ fn color_range_fuzziness_zero_selects_exact_match_only() {
+ // Sampled Colors at Fuzziness 0 selects only the exact match (TOOL-214-3, #214).
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 50, "height": 10})).unwrap();
+ s.edit("paint", |doc, _| {
+ let bg = doc.layers[0].surface_mut().unwrap();
+ let v = |c: u8| f32::from(c) / 255.0;
+ // Exact target color [200, 140, 120]
+ bg.fill_rect(Rect::new(0, 0, 10, 10), &[v(200), v(140), v(120), 1.0]);
+ // Off by 1 level in red [201, 140, 120]
+ bg.fill_rect(Rect::new(10, 0, 20, 10), &[v(201), v(140), v(120), 1.0]);
+ // Off by 1 level in green [200, 141, 120]
+ bg.fill_rect(Rect::new(20, 0, 30, 10), &[v(200), v(141), v(120), 1.0]);
+ // Off by 2 levels in blue [200, 140, 122] (crosses 8-bit Lab grid threshold)
+ bg.fill_rect(Rect::new(30, 0, 40, 10), &[v(200), v(140), v(122), 1.0]);
+ // Exact target color again at a different position
+ bg.fill_rect(Rect::new(40, 0, 50, 10), &[v(200), v(140), v(120), 1.0]);
+ Ok(())
+ })
+ .unwrap();
+
+ // Sampled via eyedropper point at [5, 5] with Fuzziness 0
+ s.execute("select.colorRange", json!({"points": [[5, 5]], "fuzziness": 0})).unwrap();
+ assert_eq!(coverage(&s, 5, 5), 1.0, "sampled pixel itself is fully selected");
+ assert_eq!(coverage(&s, 45, 5), 1.0, "identical color elsewhere on canvas is fully selected");
+ assert_eq!(coverage(&s, 15, 5), 0.0, "1 level off in red is unselected at fuzziness 0");
+ assert_eq!(coverage(&s, 25, 5), 0.0, "1 level off in green is unselected at fuzziness 0");
+ assert_eq!(coverage(&s, 35, 5), 0.0, "1 level off in blue is unselected at fuzziness 0");
+
+ // Sampled via hex color with Fuzziness 0
+ s.execute("select.colorRange", json!({"color": "#c88c78", "fuzziness": 0})).unwrap();
+ assert_eq!(coverage(&s, 5, 5), 1.0, "exact color match from hex is fully selected");
+ assert_eq!(coverage(&s, 45, 5), 1.0, "identical color elsewhere on canvas is fully selected");
+ assert_eq!(coverage(&s, 15, 5), 0.0, "1 level off in red is unselected for hex at fuzziness 0");
+ assert_eq!(coverage(&s, 25, 5), 0.0, "1 level off in green is unselected for hex at fuzziness 0");
+ assert_eq!(coverage(&s, 35, 5), 0.0, "1 level off in blue is unselected for hex at fuzziness 0");
+ }
+
/// Red squares (from `session`), a blue square, a black and a mid-grey strip on white.
fn session_colours() -> Session {
let mut s = session();
diff --git a/crates/engine/src/smart_cmds/tests.rs b/crates/engine/src/smart_cmds/tests.rs
index a764712c9f..1caaff6ce2 100644
--- a/crates/engine/src/smart_cmds/tests.rs
+++ b/crates/engine/src/smart_cmds/tests.rs
@@ -243,7 +243,7 @@ fn smart_filter_commands_check_an_explicit_layer_target() {
assert_eq!(active(&s), curves, "the active layer stays");
// A target that isn't a smart object with filters is still refused, and the active layer stays.
assert!(matches!(s.execute("layer.smartFilter.setParams", json!({"layer": curves, "params": {}})), Err(EngineError::Disabled(..))));
- assert!(s.execute("layer.smartFilter.setParams", json!({"layer": 999_999, "params": {}})).is_err());
+ assert!(s.execute("layer.smartFilter.setParams", json!({"layer": u64::MAX, "params": {}})).is_err());
assert_eq!(active(&s), curves);
}
diff --git a/crates/engine/src/smartselect_cmds.rs b/crates/engine/src/smartselect_cmds.rs
index 651db7cdc0..380b6a7200 100644
--- a/crates/engine/src/smartselect_cmds.rs
+++ b/crates/engine/src/smartselect_cmds.rs
@@ -217,10 +217,23 @@ impl ObjectFinderCache {
}
}
+/// Object Selection samples only the active layer by default: when that layer has no pixels in
+/// `area`, say so instead of quietly finding nothing (#5246; scripts often add an empty layer
+/// above the photo first).
+fn check_sampled_pixels(doc: &Document, layer: Option, all_layers: bool, area: Rect) -> Result<()> {
+ let Some(surf) = sampled_target(doc, layer, all_layers).and_then(|id| doc.layer(id)).and_then(Layer::surface) else { return Ok(()) };
+ if surf.content_bounds().intersect(&area).is_empty() {
+ let msg = if surf.content_bounds().is_empty() { "the active layer is empty" } else { "the active layer has no pixels in that area" };
+ return Err(bad("select.object", &format!("{msg}; set \"sampleAllLayers\": true or select a layer with pixels")));
+ }
+ Ok(())
+}
+
/// `select.object` with `"point"`: the Object Finder's object under the point (cached).
fn object_at_point(s: &mut Session, p: &Value, (x, y): (f32, f32)) -> Result {
let all_layers = b(p, "sampleAllLayers", false);
let d = s.active().ok_or(EngineError::NoDocument)?;
+ check_sampled_pixels(&d.doc, d.active_layer, all_layers, Rect::from_xywh(x.floor() as i32, y.floor() as i32, 1, 1))?;
let target = sampled_target(&d.doc, d.active_layer, all_layers);
let region = match s.object_finder.lookup(&d.doc, target, x, y) {
Some(r) => Some(r),
@@ -248,7 +261,10 @@ fn object_selection(s: &mut Session, p: &Value) -> Result {
return object_at_point(s, p, pt);
}
let rect = rect_param(p).ok_or_else(|| bad("select.object", "needs \"rect\": [x, y, w, h] or \"point\": [x, y]"))?;
- let region = with_sampler(s, b(p, "sampleAllLayers", false), |smp, doc| grabcut::object_select(smp, doc.bounds(), rect, 160_000))?;
+ let all_layers = b(p, "sampleAllLayers", false);
+ let d = s.active().ok_or(EngineError::NoDocument)?;
+ check_sampled_pixels(&d.doc, d.active_layer, all_layers, rect)?;
+ let region = with_sampler(s, all_layers, |smp, doc| grabcut::object_select(smp, doc.bounds(), rect, 160_000))?;
apply(s, "Object Selection", region.as_ref(), mode(p, "replace"))
}
@@ -417,6 +433,7 @@ fn refine_edge(s: &mut Session, p: &Value) -> Result {
s.edit("Select and Mask", |doc, _| {
let surface =
region.as_ref().map(matting::region_surface).unwrap_or_else(|| photocraft_raster::Surface::new(photocraft_color::PixelFormat::GRAY8));
+ crate::extra_cmds::background_to_layer_for_mask(doc, id);
let existing = doc.layer(id).and_then(|l| l.mask.as_ref()).cloned().unwrap_or_else(LayerMask::reveal_all);
doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?.mask = Some(LayerMask { surface, ..existing });
doc.selection = None;
@@ -703,7 +720,7 @@ mod tests {
// Any point on the object hits; the background and another target miss.
assert!(std::sync::Arc::ptr_eq(&s.object_finder.lookup(&doc, target, 120.0, 90.0).unwrap(), &r));
assert!(s.object_finder.lookup(&doc, target, 3.0, 3.0).is_none());
- assert!(s.object_finder.lookup(&doc, Some(LayerId(9999)), 100.0, 80.0).is_none());
+ assert!(s.object_finder.lookup(&doc, Some(LayerId(u64::MAX)), 100.0, 80.0).is_none());
// The click reuses it, and a selection-only edit keeps it.
s.execute("select.object", json!({"point": [110, 70]})).unwrap();
assert_eq!(s.object_finder.len(), 1);
@@ -730,6 +747,26 @@ mod tests {
assert!(cov(&s, 100, 80) >= 0.5);
}
+ #[test]
+ fn object_selection_on_an_empty_active_layer_says_so() {
+ // #5246: an empty layer above the photo used to find nothing without a word.
+ let (mut s, inside) = disc(8);
+ s.execute("layer.new.layer", json!({})).unwrap();
+ for p in [json!({"rect": [40, 20, 120, 120]}), json!({"point": [100, 80]})] {
+ let e = s.execute("select.object", p.clone()).unwrap_err().to_string();
+ assert!(e.contains("active layer is empty") && e.contains("sampleAllLayers"), "{p}: {e}");
+ assert!(s.active().unwrap().doc.selection.is_none());
+ }
+ // Sampling all layers finds the disc below.
+ s.execute("select.object", json!({"rect": [40, 20, 120, 120], "sampleAllLayers": true})).unwrap();
+ assert!(sel_iou(&s, 200, 160, &inside) > 0.95);
+ // A layer with pixels elsewhere: the rectangle holds none of them.
+ s.execute("select.deselect", json!({})).unwrap();
+ s.execute("paint.pencil", json!({"points": [[5, 5], [10, 5]], "size": 2, "color": "#000000"})).unwrap();
+ let e = s.execute("select.object", json!({"rect": [60, 60, 100, 80]})).unwrap_err().to_string();
+ assert!(e.contains("no pixels in that area"), "{e}");
+ }
+
#[test]
fn select_subject_centred_object() {
let (mut s, inside) = disc(8);
@@ -970,7 +1007,6 @@ mod tests {
fn refine_edge_works_on_layer_mask_without_selection() {
let mut s = blurred_edge_selected();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
assert!(s.active().unwrap().doc.selection.is_none());
assert!(s.active().unwrap().doc.layers[0].mask.is_some());
assert!(s.is_enabled("select.refineEdge"));
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 08e17bd39c..83458f05a6 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -553,7 +553,7 @@ fn clipping_masks_apply_to_every_selected_layer() {
// A `layer` param still acts on that layer alone.
s.execute("layer.releaseClippingMask", json!({"layer": ids[2]})).unwrap();
assert_eq!(clipped(&s), [false, true, false]);
- assert!(s.execute("layer.createClippingMask", json!({"layer": 999_999})).is_err());
+ assert!(s.execute("layer.createClippingMask", json!({"layer": u64::MAX})).is_err());
}
#[test]
@@ -992,8 +992,8 @@ fn move_to_copy_rejects_bad_params() {
for p in [
json!({"layer": a, "copy": true}),
json!({"layer": a, "target": "x", "copy": true}),
- json!({"layer": a, "target": 9_999_999, "copy": true}),
- json!({"layer": 9_999_999, "target": a, "copy": true}),
+ json!({"layer": a, "target": u64::MAX, "copy": true}),
+ json!({"layer": u64::MAX, "target": a, "copy": true}),
json!({"layer": a, "target": a, "position": "into", "copy": true}),
] {
assert!(s.execute("layer.moveTo", p.clone()).is_err(), "{p}");
diff --git a/crates/engine/src/type_caret_cmds.rs b/crates/engine/src/type_caret_cmds.rs
index fbc9322c62..419d305ee6 100644
--- a/crates/engine/src/type_caret_cmds.rs
+++ b/crates/engine/src/type_caret_cmds.rs
@@ -482,7 +482,7 @@ mod tests {
bad(&mut s, "type.navigate", json!({"layer": id, "index": 9, "move": "end"}));
bad(&mut s, "type.navigate", json!({"layer": id, "index": 0, "move": "lineNext", "x": "no"}));
bad(&mut s, "type.navigate", json!({"layer": pixel, "index": 0, "move": "start"}));
- assert!(matches!(s.execute("type.caret", json!({"layer": 9_999_999, "index": 0})), Err(EngineError::NoLayer(_))));
+ assert!(matches!(s.execute("type.caret", json!({"layer": u64::MAX, "index": 0})), Err(EngineError::NoLayer(_))));
// A point on the named layer but outside its text still returns a caret, marked outside.
let far = s.execute("type.hitTest", json!({"layer": id, "x": 390, "y": 290})).unwrap();
assert_eq!(far["inside"], false);
diff --git a/crates/engine/src/type_cmds.rs b/crates/engine/src/type_cmds.rs
index 4bf193b679..d6b92e840c 100644
--- a/crates/engine/src/type_cmds.rs
+++ b/crates/engine/src/type_cmds.rs
@@ -1184,7 +1184,7 @@ mod tests {
st.saved_revision = st.revision;
}
let rev = s.active().unwrap().revision;
- let unknown = [(doc_id, LayerId(9999)), (photocraft_doc::DocId(u64::MAX), id)];
+ let unknown = [(doc_id, LayerId(u64::MAX)), (photocraft_doc::DocId(u64::MAX), id)];
assert!(s.refresh_type_layers(&[&[(doc_id, id)][..], &unknown].concat()).is_empty());
assert!(text_layer(&s, id.0).cache.is_some());
let st = s.active().unwrap();
diff --git a/crates/engine/src/type_extra_cmds/tests.rs b/crates/engine/src/type_extra_cmds/tests.rs
index 9f604eed1b..7386927bb7 100644
--- a/crates/engine/src/type_extra_cmds/tests.rs
+++ b/crates/engine/src/type_extra_cmds/tests.rs
@@ -108,8 +108,9 @@ fn vertical_orientation_renders_columns_inside_the_canvas() {
assert!(l.vertical && l.lines.len() == 2);
let [x0, y0, x1, y1] = l.bounds().unwrap();
assert!(x1 > 0.0 && x0 < -40.0 && y0 >= -1e-3 && y1 > 60.0, "{:?}", l.bounds());
- // Bad layer ids fail cleanly.
- assert!(s.execute("type.orientation.vertical", json!({"layer": 9999})).is_err());
+ // Bad layer ids fail cleanly. Not a small number like 9999: ids come from one process-wide
+ // counter, so in a full test run a layer made above can get it (#3343).
+ assert!(s.execute("type.orientation.vertical", json!({"layer": u64::MAX})).is_err());
}
#[test]
@@ -299,7 +300,7 @@ fn type_attaches_to_a_path_and_releases_it() {
.unwrap();
assert!(s.execute("type.attachToPath", json!({"subpath": 5})).is_err());
assert!(s.execute("type.attachToPath", json!({"start": "far"})).is_err());
- assert!(s.execute("type.attachToPath", json!({"shape": 9999})).is_err());
+ assert!(s.execute("type.attachToPath", json!({"shape": u64::MAX})).is_err());
s.execute("type.attachToPath", json!({"start": 4})).unwrap();
assert!(matches!(text(&s, id).shape, TextShape::Path { start, .. } if start == 4.0));
let on_path = ink(&s, id);
diff --git a/crates/engine/src/variables_cmds/tests.rs b/crates/engine/src/variables_cmds/tests.rs
index 28fc14a36f..c2a30cab68 100644
--- a/crates/engine/src/variables_cmds/tests.rs
+++ b/crates/engine/src/variables_cmds/tests.rs
@@ -105,7 +105,7 @@ fn listed_pixel_methods_can_be_used_to_redefine_variables() {
#[test]
fn bad_params_are_errors() {
let (mut s, _p, badge, _t) = session();
- assert!(s.execute("image.variables.define", json!({"defs": [{"name": "x", "layer": 999999, "type": "visibility"}]})).is_err());
+ assert!(s.execute("image.variables.define", json!({"defs": [{"name": "x", "layer": u64::MAX, "type": "visibility"}]})).is_err());
assert!(s.execute("image.variables.define", json!({"defs": [{"name": "x", "layer": badge.0, "type": "nope"}]})).is_err());
assert!(s.execute("image.applyDataSet", json!({"name": "missing"})).is_err());
}
diff --git a/crates/engine/src/vector_cmds/tests.rs b/crates/engine/src/vector_cmds/tests.rs
index 4c2a9a9071..7e1c871dff 100644
--- a/crates/engine/src/vector_cmds/tests.rs
+++ b/crates/engine/src/vector_cmds/tests.rs
@@ -646,7 +646,6 @@ fn rasterizing_a_vector_mask_keeps_what_the_masks_show() {
if let Some((feather, density)) = pm {
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 40, "height": 64})).unwrap();
s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
- s.execute("select.deselect", json!({})).unwrap();
s.edit("mask settings", |doc, _| {
let m = doc.layer_mut(id).unwrap().mask.as_mut().unwrap();
(m.feather, m.density) = (feather, density);
@@ -925,7 +924,7 @@ fn combine_shapes_fails_gracefully() {
let (mut s, a, _) = two_selected_rects(8);
let before = doc(&s).clone();
let history = s.active().unwrap().history.past_len();
- let bad_params = [json!({"layer": 999_999}), json!({"layer": a, "subpath": 99}), json!({"subpath": 99}), json!({"tolerance": "x", "layer": 999_999})];
+ let bad_params = [json!({"layer": u64::MAX}), json!({"layer": a, "subpath": 99}), json!({"subpath": 99}), json!({"tolerance": "x", "layer": u64::MAX})];
for cmd in [
"layer.combineShapes.unite",
"layer.combineShapes.subtractFrontShape",
diff --git a/crates/engine/tests/eraser_locked.rs b/crates/engine/tests/eraser_locked.rs
index ae160ca277..d7405a7311 100644
--- a/crates/engine/tests/eraser_locked.rs
+++ b/crates/engine/tests/eraser_locked.rs
@@ -122,7 +122,7 @@ fn eraser_bad_params_fail_gracefully() {
assert!(s.execute("paint.stroke", json!({"erase": true})).is_err());
assert!(s.execute("paint.stroke", json!({"erase": true, "points": []})).is_err());
assert!(s.execute("paint.stroke", json!({"erase": true, "points": "x"})).is_err());
- assert!(erase(&mut s, json!({"layer": 99999})).is_err());
+ assert!(erase(&mut s, json!({"layer": u64::MAX})).is_err());
assert!(erase(&mut s, json!({"target": "mask"})).is_err(), "no mask");
// Absurd coordinates are refused up front (a stroke that long would run billions of dabs).
assert!(erase(&mut s, json!({"points": [[0, 0], [f64::MAX, 0.0]]})).is_err());
diff --git a/crates/engine/tests/explicit_layer_target.rs b/crates/engine/tests/explicit_layer_target.rs
index 6479b9c6d7..6d968c410a 100644
--- a/crates/engine/tests/explicit_layer_target.rs
+++ b/crates/engine/tests/explicit_layer_target.rs
@@ -67,7 +67,7 @@ fn a_named_layer_of_the_wrong_kind_or_that_does_not_exist_is_refused() {
let r = s.execute("layer.smartObjects.rasterize", json!({"layer": pixels}));
assert!(matches!(r, Err(EngineError::Disabled(..))), "{r:?}");
// A layer that doesn't exist falls back to the active layer's check, and still fails.
- assert!(s.execute("layer.smartObjects.rasterize", json!({"layer": 999_999})).is_err());
+ assert!(s.execute("layer.smartObjects.rasterize", json!({"layer": u64::MAX})).is_err());
assert!(s.execute("layer.smartObjects.rasterize", json!({"layer": "nope"})).is_err());
assert_eq!(s.active().unwrap().doc, before);
assert_eq!(active(&s), pixels);
diff --git a/crates/engine/tests/layer_mask_depth.rs b/crates/engine/tests/layer_mask_depth.rs
index 082761286c..7093164a5f 100644
--- a/crates/engine/tests/layer_mask_depth.rs
+++ b/crates/engine/tests/layer_mask_depth.rs
@@ -45,7 +45,12 @@ fn newly_created_layer_masks_follow_document_depth() {
assert_eq!(m.value(20, 20), white);
if selected {
assert_eq!(m.value(0, 0), 0.0);
- assert_eq!(d.doc.selection, before.selection, "the selection is unchanged");
+ if command == "layer.layerMask.revealSelection" {
+ // The selection became the mask: Photoshop drops it, as Hide Selection does.
+ assert!(d.doc.selection.is_none(), "{command}: the selection is dropped");
+ } else {
+ assert_eq!(d.doc.selection, before.selection, "the selection is unchanged");
+ }
} else {
assert_eq!(m.surface.tile_count(), 0, "uniform masks stay sparse");
assert_eq!(m.value(-300_000, 300_000), white);
@@ -133,7 +138,8 @@ fn mask_creation_preserves_selection_coverage_and_existing_masks() {
before.selection.as_ref().unwrap().read_region(before.bounds()),
"{depth}-bit coverage is unchanged"
);
- assert_eq!(after.selection, before.selection);
+ let kept = if command == "layer.layerMask.revealSelection" { None } else { before.selection.clone() };
+ assert_eq!(after.selection, kept, "{command}");
assert_eq!(after.layers[0].mask, before.layers[0].mask, "creating a mask does not requantize an existing mask");
}
}
diff --git a/crates/engine/tests/panic_hunt.rs b/crates/engine/tests/panic_hunt.rs
index c73980a2f2..893ba5c23d 100644
--- a/crates/engine/tests/panic_hunt.rs
+++ b/crates/engine/tests/panic_hunt.rs
@@ -5,7 +5,8 @@
use photocraft_engine::{Session, command_specs};
use serde_json::{Value, json};
use std::panic::{AssertUnwindSafe, catch_unwind};
-use std::sync::mpsc;
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::{Mutex, Once, PoisonError, mpsc};
use std::time::Duration;
fn fresh() -> Session {
@@ -22,19 +23,41 @@ fn fresh() -> Session {
/// 0.3 s even on a heavily loaded machine, so this only catches real hangs.
const DEADLINE: Duration = Duration::from_secs(4);
-/// Run `id` with `p` on a fresh session, on a worker thread. `None` if it timed out, else whether
-/// it finished without panicking (returning Ok or a graceful Err both count).
-fn run_once(id: &str, p: &Value) -> Option {
- let (tx, rx) = mpsc::channel();
- let (id, p) = (id.to_string(), p.clone());
- std::thread::spawn(move || {
- let r = catch_unwind(AssertUnwindSafe(|| {
- let mut s = fresh();
- let _ = s.execute(&id, p);
+/// Panics anywhere in the process, counted by a hook. `Session::execute` contains a command's
+/// panic and returns an ordinary `Err`, so the unwind never reaches `catch_unwind` here; the hook
+/// still sees it, on whichever thread (rayon workers included) it happened (#4982).
+static PANICS: AtomicUsize = AtomicUsize::new(0);
+/// One run at a time, so a panic is charged to the run that caused it.
+static RUN: Mutex<()> = Mutex::new(());
+
+/// Run `f` on a worker thread. `None` if it timed out, else whether it finished without
+/// panicking, contained or not (returning Ok or a graceful Err both count).
+fn run_watched(f: impl FnOnce() + Send + 'static) -> Option {
+ static HOOK: Once = Once::new();
+ HOOK.call_once(|| {
+ let default = std::panic::take_hook();
+ std::panic::set_hook(Box::new(move |info| {
+ PANICS.fetch_add(1, Ordering::SeqCst);
+ default(info);
}));
+ });
+ let _one = RUN.lock().unwrap_or_else(PoisonError::into_inner);
+ let before = PANICS.load(Ordering::SeqCst);
+ let (tx, rx) = mpsc::channel();
+ std::thread::spawn(move || {
+ let r = catch_unwind(AssertUnwindSafe(f));
let _ = tx.send(r.is_ok());
});
- rx.recv_timeout(DEADLINE).ok()
+ rx.recv_timeout(DEADLINE).ok().map(|ok| ok && PANICS.load(Ordering::SeqCst) == before)
+}
+
+/// Run `id` with `p` on a fresh session; see [`run_watched`].
+fn run_once(id: &str, p: &Value) -> Option {
+ let (id, p) = (id.to_string(), p.clone());
+ run_watched(move || {
+ let mut s = fresh();
+ let _ = s.execute(&id, p);
+ })
}
/// `Err` with a reason on panic or hang, `Ok` otherwise.
@@ -60,13 +83,18 @@ fn no_command_panics_or_hangs_on_adversarial_params() {
json!({"x": 1e5, "y": -1e5, "radius": 300, "amount": 300, "angle": 1e5, "opacity": -100, "scale": -5, "gamma": -1}),
json!({"points": [], "from": [0, 0], "to": [0, 0], "stops": [], "matrix": [0, 0, 0, 0, 0, 0], "colors": [], "name": "", "mode": "", "style": ""}),
];
- // Commands whose success reaches outside the process: `file.print` and `file.printOneCopy`
- // spool to CUPS, so a fuzz run with `{}` printed a blank page on the default printer. Their
- // params are validated like everyone else's; the spooling itself is not fuzzed.
- const EXTERNAL: &[&str] = &["file.print", "file.printOneCopy"];
let mut bad: Vec = Vec::new();
- for spec in command_specs().iter().filter(|spec| !EXTERNAL.contains(&spec.id)) {
+ for spec in command_specs() {
for p in ¶ms {
+ // Print and Print One Copy reach real printers (lp, or the Windows driver): fuzz them
+ // as dry runs so the hunt never prints a page.
+ let mut p = p.clone();
+ if spec.id.starts_with("file.print")
+ && let Some(o) = p.as_object_mut()
+ {
+ o.insert("dryRun".into(), json!(true));
+ }
+ let p = &p;
if let Err(why) = run_guarded(spec.id, p) {
bad.push(format!("{} [{why}] <- {p}", spec.id));
break;
@@ -75,3 +103,17 @@ fn no_command_panics_or_hangs_on_adversarial_params() {
}
assert!(bad.is_empty(), "{} commands panicked or hung:\n{}", bad.len(), bad.join("\n"));
}
+
+/// #4982: a panic the code under test contains still fails the run; a graceful `Err` does not.
+#[test]
+fn contained_panics_count_and_graceful_errors_do_not() {
+ let contained = run_watched(|| {
+ let _ = catch_unwind(|| panic!("contained, as Session::execute does"));
+ });
+ assert_eq!(contained, Some(false));
+ let graceful = run_watched(|| {
+ let mut s = fresh();
+ assert!(s.execute("layer.delete", json!({"layer": 999999})).is_err());
+ });
+ assert_eq!(graceful, Some(true));
+}
diff --git a/crates/engine/tests/rasterize_selected_layers.rs b/crates/engine/tests/rasterize_selected_layers.rs
index 40b962aca8..a738b51681 100644
--- a/crates/engine/tests/rasterize_selected_layers.rs
+++ b/crates/engine/tests/rasterize_selected_layers.rs
@@ -140,6 +140,6 @@ fn bad_targets_fail_gracefully() {
}
let mut sc = scene();
for id in ["layer.rasterize.layer", "layer.rasterize.shape", "layer.rasterize.smartObject"] {
- assert!(sc.s.execute(id, json!({"layer": 9_999_999})).is_err(), "{id}: no such layer");
+ assert!(sc.s.execute(id, json!({"layer": u64::MAX})).is_err(), "{id}: no such layer");
}
}
diff --git a/crates/engine/tests/selection_layer_commands.rs b/crates/engine/tests/selection_layer_commands.rs
index 8d144d44de..44f63cf5d2 100644
--- a/crates/engine/tests/selection_layer_commands.rs
+++ b/crates/engine/tests/selection_layer_commands.rs
@@ -148,6 +148,6 @@ fn bad_targets_fail_gracefully() {
}
let mut sc = scene();
for id in ["layer.layerMask.revealAll", "layer.layerStyle.pasteLayerStyle", "layer.layerStyle.clear"] {
- assert!(sc.s.execute(id, json!({"layer": 9_999_999})).is_err(), "{id}: no such layer");
+ assert!(sc.s.execute(id, json!({"layer": u64::MAX})).is_err(), "{id}: no such layer");
}
}
diff --git a/crates/format/src/autosave.rs b/crates/format/src/autosave.rs
index 4767413617..06150e60ed 100644
--- a/crates/format/src/autosave.rs
+++ b/crates/format/src/autosave.rs
@@ -199,12 +199,33 @@ pub fn list_recovery(recovery_dir: &Path) -> Vec {
if bundle.join(crate::store::MANIFEST).is_file() {
out.push(RecoveryEntry { info, bundle });
}
+ } else if e.file_type().is_ok_and(|ft| ft.is_dir())
+ && let Some(entry) = sidecarless_entry(recovery_dir, &p)
+ {
+ out.push(entry);
}
}
out.sort_by(|a, b| b.info.saved_at.cmp(&a.info.saved_at).then(a.info.key.cmp(&b.info.key)));
out
}
+/// A committed `.pcraft` bundle (its manifest is written last) whose sidecar was never
+/// published, e.g. a crash during a document's first autosave. The metadata is rebuilt from the
+/// manifest (read like a load reads it) and its modification time. Incomplete bundles (no
+/// readable manifest) and bundles with anything at the sidecar's path are not entries.
+fn sidecarless_entry(recovery_dir: &Path, bundle: &Path) -> Option {
+ let key = bundle.file_name()?.to_str()?.strip_suffix(".pcraft")?;
+ if key.is_empty() || sanitize(key) != key || std::fs::symlink_metadata(recovery_dir.join(format!("{key}.json"))).is_ok() {
+ return None;
+ }
+ let meta = std::fs::symlink_metadata(bundle.join(crate::store::MANIFEST)).ok().filter(|m| m.is_file())?;
+ let source = crate::store::DirSource { root: bundle.to_path_buf() };
+ let manifest = crate::store::read_manifest(&source, &crate::LoadOptions::default()).ok()?;
+ let saved_at = meta.modified().ok().and_then(|t| t.duration_since(UNIX_EPOCH).ok()).map_or(0, |d| d.as_secs());
+ let info = RecoveryInfo { key: key.to_string(), document_name: manifest.document.name, original_path: None, saved_at, revision: 0 };
+ Some(RecoveryEntry { info, bundle: bundle.to_path_buf() })
+}
+
/// Load a recovered document.
pub fn recover(entry: &RecoveryEntry) -> Result {
crate::load_path(&entry.bundle)
@@ -292,8 +313,9 @@ impl RecoveryStore {
const ORPHAN_AGE: std::time::Duration = std::time::Duration::from_secs(24 * 60 * 60);
/// Best-effort removal of recovery data nothing can ever load or clean up:
-/// - `.pcraft` bundle folders with no `.json` sidecar (a crash during a document's
-/// first autosave: the sidecar is written after the bundle, and `list_recovery` skips them);
+/// - `.pcraft` bundle folders with no `.json` sidecar and no readable manifest (a
+/// crash in the middle of a document's first autosave). A sidecar-less bundle whose manifest
+/// was committed is complete and listed by `list_recovery`, so it is kept;
/// - `*.pcsave.tmp` files left by an interrupted atomic write (see [`crate::atomic::temp_name`])
/// that another process created.
///
@@ -321,7 +343,8 @@ fn sweep_orphans(recovery_dir: &Path, min_age: std::time::Duration) {
// Anything at the sidecar's path (even a broken one) keeps the bundle.
let has_sidecar = std::fs::symlink_metadata(recovery_dir.join(format!("{key}.json"))).is_ok();
let parts = [path.clone(), path.join("tiles"), path.join("blobs")];
- if !has_sidecar && parts.iter().all(|p| untouched_for(p, min_age, true)) {
+ // A committed bundle is recoverable work: keep exactly what `list_recovery` lists.
+ if !has_sidecar && sidecarless_entry(recovery_dir, &path).is_none() && parts.iter().all(|p| untouched_for(p, min_age, true)) {
let _ = std::fs::remove_dir_all(&path);
} else {
bundles.extend(parts);
@@ -437,4 +460,41 @@ mod tests {
assert_eq!(recover(&entries[0]).unwrap(), *doc);
let _ = std::fs::remove_dir_all(&dir);
}
+
+ #[cfg(not(target_arch = "wasm32"))]
+ #[test]
+ fn a_committed_bundle_without_a_sidecar_is_listed_and_survives_the_sweep() {
+ let dir = std::env::temp_dir().join(format!(
+ "pcraft-nosidecar-{}-{}",
+ std::process::id(),
+ SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_nanos()).unwrap_or(0)
+ ));
+ let doc =
+ Arc::new(Document::new("Lost", photocraft_doc::Size { width: 4, height: 4 }, photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U8));
+ let saver = Autosaver::new(&dir, "first");
+ saver.request(doc.clone(), 1, None, SaveOptions::default());
+ assert!(saver.flush().is_some_and(|r| r.is_ok()));
+ // The crash: the bundle was committed, the sidecar never published.
+ std::fs::remove_file(dir.join("first.json")).unwrap();
+
+ let entries = list_recovery(&dir);
+ assert_eq!(entries.len(), 1, "the committed bundle is discoverable");
+ assert_eq!((entries[0].info.key.as_str(), entries[0].info.document_name.as_str()), ("first", "Lost"));
+ assert_eq!(recover(&entries[0]).unwrap(), *doc);
+
+ sweep_orphans(&dir, std::time::Duration::ZERO);
+ assert!(dir.join("first.pcraft").is_dir(), "aged cleanup keeps a committed bundle");
+
+ // Incomplete bundles (no manifest, or one that does not read) are neither listed nor kept.
+ let partial = dir.join("partial.pcraft");
+ std::fs::create_dir_all(partial.join("tiles")).unwrap();
+ let broken = dir.join("broken.pcraft");
+ std::fs::create_dir_all(&broken).unwrap();
+ std::fs::write(broken.join("manifest.json"), b"{").unwrap();
+ assert_eq!(list_recovery(&dir).len(), 1);
+ sweep_orphans(&dir, std::time::Duration::ZERO);
+ assert!(!partial.exists() && !broken.exists());
+ assert!(dir.join("first.pcraft").is_dir());
+ let _ = std::fs::remove_dir_all(&dir);
+ }
}
diff --git a/crates/gpu/src/plan.rs b/crates/gpu/src/plan.rs
index b8c083c7af..48abbc0930 100644
--- a/crates/gpu/src/plan.rs
+++ b/crates/gpu/src/plan.rs
@@ -1097,9 +1097,10 @@ impl<'a> Planner<'a> {
};
for &(i, e) in &rev {
if let Effect::DropShadow(s) = e {
- // The layer hides the shadow beneath it where its fill is see-through.
+ // The layer hides the shadow beneath it where its fill is see-through, and wholly
+ // in a mode that blends with it (as the CPU renderer: `shadow_see_through`).
let flags = if s.knocks_out { F_KNOCKOUT } else { 0 };
- let see_through = 1.0 - layer.fill_opacity.clamp(0.0, 1.0);
+ let see_through = photocraft_compose::effects::shadow_see_through(layer);
w = self.paint_k(
w,
content,
diff --git a/crates/io/src/abr_map.rs b/crates/io/src/abr_map.rs
index c21800f13d..53cfd205ff 100644
--- a/crates/io/src/abr_map.rs
+++ b/crates/io/src/abr_map.rs
@@ -527,10 +527,17 @@ fn fit(w: u32, h: u32, v: Vec, max: u32) -> (u32, u32, Vec) {
let k = (w.max(h) as f32 / max as f32).max(1.0);
let (nw, nh) = (((w as f32 / k).round() as u32).clamp(1, max), ((h as f32 / k).round() as u32).clamp(1, max));
let mut out = vec![0.0f32; nw as usize * nh as usize];
+ // Source rows/columns `[i * n / m, (i + 1) * n / m)` (at least one) for output index `i` of
+ // `m`; in u64, as `(i + 1) * n` passes u32 for a plane over 2^32 / `max` long. The parsers'
+ // edge caps keep today's inputs below that, but this function should not depend on them.
+ let span = |i: u32, n: u32, m: u32| {
+ let at = |k: u32| usize::try_from(u64::from(k) * u64::from(n) / u64::from(m)).unwrap_or(usize::MAX);
+ (at(i), at(i + 1).max(at(i).saturating_add(1)).min(n as usize))
+ };
for y in 0..nh {
- let (y0, y1) = ((y * h / nh) as usize, (((y + 1) * h / nh) as usize).max((y * h / nh) as usize + 1).min(h as usize));
+ let (y0, y1) = span(y, h, nh);
for x in 0..nw {
- let (x0, x1) = ((x * w / nw) as usize, (((x + 1) * w / nw) as usize).max((x * w / nw) as usize + 1).min(w as usize));
+ let (x0, x1) = span(x, w, nw);
let (mut sum, mut n) = (0.0, 0usize);
for yy in y0..y1 {
for xx in x0..x1 {
@@ -593,3 +600,18 @@ fn pattern_tile(p: &PsdPattern) -> Option {
#[cfg(test)]
mod tests;
+
+#[cfg(test)]
+mod fit_tests {
+ use super::fit;
+
+ /// A tall, narrow plane: `(y + 1) * h` passes `u32::MAX` once `h` is over 2^32 / `max` rows.
+ /// The ABR and pattern parsers cap edges well below that, but `fit` must not rely on it.
+ #[test]
+ fn fit_tall_planes_without_overflow() {
+ let h = 5_000_000u32;
+ let (w, nh, out) = fit(1, h, vec![1.0; h as usize], 1024);
+ assert_eq!((w, nh), (1, 1024));
+ assert!(out.iter().all(|v| (*v - 1.0).abs() < 1e-6), "every output row averages real input rows");
+ }
+}
diff --git a/crates/io/src/gradient_bake.rs b/crates/io/src/gradient_bake.rs
index e452ae9e1f..0d34816a79 100644
--- a/crates/io/src/gradient_bake.rs
+++ b/crates/io/src/gradient_bake.rs
@@ -106,12 +106,15 @@ fn smooth_ease(u: f32) -> f32 {
/// Colour at `t` for sorted stops (positions in 0..1) in `m`'s space.
fn eval(stops: &[(f32, [f32; 3])], mids: &[f32], smooth: f32, t: f32, m: Method) -> [f32; 3] {
let n = stops.len();
- if t <= stops[0].0 {
- return stops[0].1;
+ let (Some(first), Some(last)) = (stops.first(), stops.last()) else { return [0.0; 3] };
+ // A lone stop (even at a NaN position, which neither test below catches) is the colour.
+ if t <= first.0 || n < 2 {
+ return first.1;
}
- if t >= stops[n - 1].0 {
- return stops[n - 1].1;
+ if t >= last.0 {
+ return last.1;
}
+ // From here `stops[i + 1]` and the tangents' `n - 2` are in range: `i < n - 1` and `n >= 2`.
let i = stops.windows(2).position(|w| t >= w[0].0 && t <= w[1].0).unwrap_or(0);
let (t0, t1) = (stops[i].0, stops[i + 1].0);
let h = (t1 - t0).max(1e-6);
@@ -281,4 +284,14 @@ mod tests {
let s = bake(vec![(0.0, Color::BLACK), (1.0, Color::WHITE)], &[0.25], 0.0, Method::Classic);
assert!((at(&s, 0.25)[0] - 0.5).abs() < 0.01);
}
+
+ /// `eval` guards its own stops instead of relying on `bake`'s two-stop check.
+ #[test]
+ fn eval_with_fewer_than_two_stops_does_not_index_out_of_range() {
+ assert_eq!(eval(&[], &[], 1.0, 0.5, Method::Smooth), [0.0; 3]);
+ let lone = [(f32::NAN, [0.25, 0.5, 0.75])];
+ for m in [Method::Classic, Method::Smooth] {
+ assert_eq!(eval(&lone, &[], 1.0, 0.5, m), [0.25, 0.5, 0.75]);
+ }
+ }
}
diff --git a/crates/io/src/psd_export.rs b/crates/io/src/psd_export.rs
index 9db3d4799f..47861dbcc3 100644
--- a/crates/io/src/psd_export.rs
+++ b/crates/io/src/psd_export.rs
@@ -1636,6 +1636,7 @@ fn document_to_psd_nested(doc: &Document, opts: &PsdExportOptions, depth: u32, c
// Resources.
let mut resources = vec![
+ // hRes/vRes are always pixels per inch. The display unit written here is inches.
ImageResource::new(ids::RESOLUTION_INFO, ResolutionInfo::from_dpi(f64::from(doc.resolution_dpi)).to_bytes()),
ImageResource::new(ids::GLOBAL_ANGLE, (doc.global_light.angle.round() as i32).to_be_bytes().to_vec()),
ImageResource::new(ids::GLOBAL_ALTITUDE, (doc.global_light.altitude.round() as i32).to_be_bytes().to_vec()),
diff --git a/crates/io/src/psd_import.rs b/crates/io/src/psd_import.rs
index 444c2d6e5b..211bba4da9 100644
--- a/crates/io/src/psd_import.rs
+++ b/crates/io/src/psd_import.rs
@@ -673,8 +673,9 @@ pub fn psd_to_document_with(file: &PsdFile, ctl: &photocraft_raster::Interrupt)
match r.id {
ids::RESOLUTION_INFO => {
if let Ok(ri) = photocraft_psd::ResolutionInfo::from_bytes(&r.data) {
- let ppi = |res: f64, unit: u16| if unit == 2 { res * 2.54 } else { res };
- let (x, y) = (ppi(ri.h_res(), ri.h_res_unit), ppi(ri.v_res(), ri.v_res_unit));
+ // Fixed 16.16 hRes/vRes are pixels per inch. The unit shorts only
+ // say how to show that number (1 = px/in, 2 = px/cm).
+ let (x, y) = (ri.h_res(), ri.v_res());
doc.resolution_dpi = x as f32;
warnings.extend(crate::unequal_resolution_warning(x, y));
}
diff --git a/crates/io/tests/psd32_export.rs b/crates/io/tests/psd32_export.rs
index cbb4a31524..9ff2b4113b 100644
--- a/crates/io/tests/psd32_export.rs
+++ b/crates/io/tests/psd32_export.rs
@@ -203,3 +203,36 @@ fn merged_oracle_does_not_treat_extra_channels_as_transparency() {
assert_eq!(merged_composite(&file).unwrap(), vec![[2.0, 2.0, 2.0, 1.0]], "{mode:?}");
}
}
+
+// Photoshop saves a transparent 32-bit document with a positive layer count and an `Mt32`
+// ("Saving Merged Transparency") global block: the merged image's first extra channel, named
+// "Transparency", is its transparency (psd-tools transparentbg.psd). The oracle reads it as the
+// composite's alpha, and opening the file doesn't turn it into an alpha channel.
+#[test]
+fn mt32_marks_the_merged_transparency() {
+ let mut doc = Document::new("transparent", Size::new(2, 1), ColorMode::Rgb, SampleType::F32);
+ let fmt = doc.pixel_format();
+ let mut layer = photocraft_doc::Layer::raster("shape", fmt);
+ if let Some(s) = layer.surface_mut() {
+ s.fill_rect(photocraft_geom::Rect::new(0, 0, 1, 1), &[0.0, 0.0, 0.0, 1.0]);
+ }
+ doc.layers.push(layer);
+ let mut file = PsdFile::from_bytes(&export_psd(&doc)).unwrap();
+ file.header.channels = 4;
+ if let Some(li) = file.layer_info.as_mut() {
+ li.merged_alpha = false;
+ }
+ file.image_data.compression = Compression::Raw;
+ let plane = |v: [f32; 2]| v.into_iter().flat_map(f32::to_be_bytes).collect::>();
+ file.image_data.data = [plane([0.0, 1.0]), plane([0.0, 1.0]), plane([0.0, 1.0]), plane([1.0, 0.0])].concat();
+ let name: Vec = [0u8, 0, 0, 13].into_iter().chain("Transparency\0".encode_utf16().flat_map(u16::to_be_bytes)).collect();
+ file.resources.retain(|r| r.id != 1045);
+ file.resources.push(photocraft_psd::ImageResource::new(1045, name));
+ assert!(!file.merged_has_alpha(), "a positive layer count alone");
+ file.global_blocks.push(photocraft_psd::TaggedBlock::new(*b"Mt32", Vec::new()));
+ assert!(file.merged_has_alpha());
+ let merged = merged_composite(&file).unwrap();
+ assert_eq!(merged.iter().map(|p| p[3]).collect::>(), vec![1.0, 0.0]);
+ let opened = import("transparent.psd", &file.to_bytes().unwrap()).unwrap();
+ assert!(opened.document.channels.is_empty(), "{:?}", opened.document.channels.iter().map(|c| &c.name).collect::>());
+}
diff --git a/crates/io/tests/psd_structure.rs b/crates/io/tests/psd_structure.rs
index e893adaf94..5627dca3f4 100644
--- a/crates/io/tests/psd_structure.rs
+++ b/crates/io/tests/psd_structure.rs
@@ -460,13 +460,18 @@ fn guides_and_alpha_names_roundtrip() {
}
#[test]
-fn resolution_in_cm_converted() {
+fn resolution_info_cm_display_unit_stays_pixels_per_inch() {
let mut f = testgen::small(Version::Psd, Compression::Raw);
- let mut ri = photocraft_psd::ResolutionInfo::from_dpi(100.0);
+ let mut ri = photocraft_psd::ResolutionInfo::from_dpi(300.0);
ri.h_res_unit = 2;
+ ri.v_res_unit = 2;
f.resources[0] = photocraft_psd::ImageResource::new(1005, ri.to_bytes());
let (d, _) = psd_to_document(&f);
- assert!((d.resolution_dpi - 254.0).abs() < 1e-3);
+ assert!((d.resolution_dpi - 300.0).abs() < 1e-3, "{}", d.resolution_dpi);
+ let out = document_to_psd(&d);
+ let written = out.resolution().unwrap();
+ assert!((written.h_res() - 300.0).abs() < 1e-3, "{}", written.h_res());
+ assert!((written.v_res() - 300.0).abs() < 1e-3, "{}", written.v_res());
}
#[test]
diff --git a/crates/io/tests/resolution_axes.rs b/crates/io/tests/resolution_axes.rs
index 58b67d93c4..f7f8cbf006 100644
--- a/crates/io/tests/resolution_axes.rs
+++ b/crates/io/tests/resolution_axes.rs
@@ -59,13 +59,27 @@ fn psd_with_equal_axes_opens_silently() {
let r = import("x.psd", &psd(ResolutionInfo::from_dpi(300.0))).unwrap();
assert!((r.document.resolution_dpi - 300.0).abs() < 1e-3, "{}", r.document.resolution_dpi);
assert!(resolution_notes(&r).is_empty(), "{:?}", r.warnings);
- // Each axis is read in its own unit: 100 pixels per centimetre on both is 254 ppi on both.
- let mut cm = ResolutionInfo::from_dpi(100.0);
+}
+
+/// Resource 1005 stores 300 ppi even when the display unit is centimetres. Scaling
+/// that fixed-point value by 2.54 opened the file at 762 ppi (#5201).
+#[test]
+fn resolution_info_cm_display_unit_is_pixels_per_inch() {
+ let mut cm = ResolutionInfo::from_dpi(300.0);
cm.h_res_unit = 2;
cm.v_res_unit = 2;
+ cm.width_unit = 2;
+ cm.height_unit = 2;
let r = import("x.psd", &psd(cm)).unwrap();
- assert!((r.document.resolution_dpi - 254.0).abs() < 1e-3, "{}", r.document.resolution_dpi);
+ assert!((r.document.resolution_dpi - 300.0).abs() < 1e-3, "{}", r.document.resolution_dpi);
assert!(resolution_notes(&r).is_empty(), "{:?}", r.warnings);
+
+ let out = export(&r.document, "out.psd", &ExportOptions::default()).unwrap();
+ let file = photocraft_psd::PsdFile::from_bytes(&out.bytes).unwrap();
+ let written = file.resolution().unwrap();
+ assert!((written.h_res() - 300.0).abs() < 1e-3, "{}", written.h_res());
+ assert!((written.v_res() - 300.0).abs() < 1e-3, "{}", written.v_res());
+ assert_eq!((written.h_res_unit, written.v_res_unit), (1, 1));
}
/// A layered TIFF opens through the PSD importer with the TIFF's own resolution tags.
diff --git a/crates/psd/src/file.rs b/crates/psd/src/file.rs
index 1e86665ad8..effaa1fa11 100644
--- a/crates/psd/src/file.rs
+++ b/crates/psd/src/file.rs
@@ -272,7 +272,10 @@ impl PsdFile {
self.image_data.decode(&self.header)
}
- /// `true` if the merged image carries a transparency channel.
+ /// `true` if the merged image carries a transparency channel: its first extra channel, when
+ /// the layer count was stored negative or a "Saving Merged Transparency" global block (`Mtrn`,
+ /// `Mt16`, `Mt32`) is present. Photoshop marks 32-bit documents with `Mt32` and a positive
+ /// layer count (psd-tools transparentbg.psd).
pub fn merged_has_alpha(&self) -> bool {
let Some(color) = self.header.color_mode.color_channels() else {
return false;
@@ -280,8 +283,9 @@ impl PsdFile {
if self.header.channels <= color {
return false;
}
+ let marked = self.global_blocks.iter().any(|b| matches!(&b.key, b"Mtrn" | b"Mt16" | b"Mt32"));
match &self.layer_info {
- Some(li) => li.merged_alpha,
+ Some(li) => li.merged_alpha || marked,
None => true,
}
}
diff --git a/crates/psd/src/resources.rs b/crates/psd/src/resources.rs
index c20efbfc9e..4d78a062be 100644
--- a/crates/psd/src/resources.rs
+++ b/crates/psd/src/resources.rs
@@ -45,20 +45,24 @@ pub struct ImageResource {
}
/// Fixed-point resolution info (resource 1005).
+///
+/// `h_res_fixed` and `v_res_fixed` are always pixels per inch (16.16 fixed).
+/// `h_res_unit` and `v_res_unit` only say how to display that number
+/// (1 = pixels/inch, 2 = pixels/cm) and do not rescale the stored value.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ResolutionInfo {
- /// Horizontal resolution, 16.16 fixed point (pixels per inch/cm).
+ /// Horizontal resolution, 16.16 fixed point, always pixels per inch.
pub h_res_fixed: u32,
- /// 1 = pixels per inch, 2 = pixels per cm.
+ /// Display unit for the horizontal resolution (1 = px/in, 2 = px/cm).
pub h_res_unit: u16,
- /// Display unit for width (1 in, 2 cm, 3 pt, 4 pica, 5 column).
+ /// Ruler unit for width (1 in, 2 cm, 3 pt, 4 pica, 5 column).
pub width_unit: u16,
- /// Vertical resolution, 16.16 fixed.
+ /// Vertical resolution, 16.16 fixed point, always pixels per inch.
pub v_res_fixed: u32,
- /// Vertical resolution unit.
+ /// Display unit for the vertical resolution (1 = px/in, 2 = px/cm).
pub v_res_unit: u16,
- /// Display unit for height.
+ /// Ruler unit for height (1 in, 2 cm, 3 pt, 4 pica, 5 column).
pub height_unit: u16,
}
@@ -68,11 +72,11 @@ impl ResolutionInfo {
let f = (dpi * 65536.0).round().clamp(0.0, u32::MAX as f64) as u32;
ResolutionInfo { h_res_fixed: f, h_res_unit: 1, width_unit: 1, v_res_fixed: f, v_res_unit: 1, height_unit: 1 }
}
- /// Horizontal resolution as float.
+ /// Horizontal resolution in pixels per inch.
pub fn h_res(&self) -> f64 {
f64::from(self.h_res_fixed) / 65536.0
}
- /// Vertical resolution as float.
+ /// Vertical resolution in pixels per inch.
pub fn v_res(&self) -> f64 {
f64::from(self.v_res_fixed) / 65536.0
}
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index d6a49c0038..aeefacaf2f 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -8,6 +8,7 @@ license.workspace = true
workspace = true
[dependencies]
+craft-print = { workspace = true }
craft-ui = { workspace = true }
photocraft-geom = { workspace = true }
photocraft-color = { workspace = true }
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index db0efe31fa..676d068070 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -697,10 +697,12 @@ fn feed_live_stroke(app: &mut PhotocraftApp) {
return;
}
l.fed = d.points.len();
+ let started = crate::gpu_canvas::now_ms();
match l.stroke.push(&pts) {
Ok(r) => l.damage.push(r),
Err(_) => app.live_stroke = None,
}
+ app.stroke_trace.stroke(crate::gpu_canvas::now_ms() - started);
}
/// The points the live retouching stroke has rendered.
@@ -5460,7 +5462,9 @@ fn commit_brush_stroke(app: &mut PhotocraftApp, d: &Drag) {
{
app.session.clear_live_stroke();
}
+ let started = crate::gpu_canvas::now_ms();
let result = app.run(stroke_command(app, d.tool), p);
+ app.stroke_trace.stroke(crate::gpu_canvas::now_ms() - started);
app.session.clear_live_stroke();
let Ok(r) = result else { return };
let revision = app.session.documents().iter().find(|st| st.doc.id == doc).map(|st| st.revision);
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index db908d0943..209691b875 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -1315,7 +1315,7 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value {
"frame": app.frame,
"session": photocraft_engine::inspect::session(&app.session),
"document": app.session.active().map(photocraft_engine::inspect::document),
- "perf": {"fps": app.fps, "timings": app.perf},
+ "perf": {"fps": app.fps, "timings": app.perf, "strokeTrace": app.stroke_trace.last},
"brush": {"size": app.session.tools.brush.size, "hardness": app.session.tools.brush.hardness, "opacity": app.session.tools.brush.opacity},
"distort": app.distort.describe(),
"jobs": crate::jobs_ui::inspect(app),
diff --git a/crates/ui-egui/src/file_ui.rs b/crates/ui-egui/src/file_ui.rs
index 4b708fa1c0..c3b8abc4d7 100644
--- a/crates/ui-egui/src/file_ui.rs
+++ b/crates/ui-egui/src/file_ui.rs
@@ -726,7 +726,7 @@ pub fn open_print(app: &mut PhotocraftApp) -> u64 {
f.insert("__label".into(), json!("PhotoCraft Print Settings"));
// Asked once per opening: the Printer menu lists what the spooler knows now.
let printers = app.session.execute("file.printers", json!({})).unwrap_or_default();
- f.insert("__printers".into(), printers["printers"].clone());
+ f.insert("__systemPrinters".into(), printers["printers"].clone());
if let Some(Value::Object(m)) = app.session.file_menu.last_print.clone() {
f.extend(m);
}
@@ -755,9 +755,35 @@ pub fn open_print(app: &mut PhotocraftApp) -> u64 {
] {
f.entry(k.to_string()).or_insert(v);
}
+ // Windows: the system's printers, and the paper from the chosen printer's driver settings.
+ if let Ok(list) = craft_print::rgb::printers() {
+ f.insert("__printers".into(), json!(list.iter().map(|p| p.name.clone()).collect::>()));
+ let known = |n: &str| list.iter().any(|p| p.name == n);
+ if !known(&s(&f, "printer", "")) {
+ let fallback = list.iter().find(|p| p.default).or(list.first()).map(|p| p.name.clone()).unwrap_or_default();
+ f.insert("printer".into(), json!(fallback));
+ f.remove("printerSettings");
+ }
+ }
app.ui.open_dialog(DialogKind::Command, f)
}
+/// Takes the paper from the printer's driver settings (Windows), as Photoshop does.
+fn driver_page(f: &mut Map) {
+ let printer = s(f, "printer", "");
+ let settings = f.get("printerSettings").and_then(Value::as_str).and_then(|h| craft_print::rgb::DevMode::from_hex(h).ok());
+ match craft_print::rgb::page(&printer, settings.as_ref()) {
+ Ok(pg) => {
+ f.insert("paper".into(), json!([pg.paper.0, pg.paper.1]));
+ f.insert("orientation".into(), json!("portrait"));
+ f.remove("__pageError");
+ }
+ Err(e) => {
+ f.insert("__pageError".into(), json!(e.to_string()));
+ }
+ }
+}
+
/// Points per unit for the Position and Size fields.
fn unit_pt(units: &str) -> f64 {
match units {
@@ -839,6 +865,22 @@ fn print_paper_controls(ui: &mut egui::Ui, f: &mut Map) {
fn print_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map) {
let t = Tokens::get(ui.ctx());
let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return };
+ // PDF exports and previews retain editable paper on Windows too. Only a real native
+ // submission takes its media from the printer; entering that mode refreshes the driver
+ // geometry after any export-only paper edits.
+ let printers: Option> = if !b(f, "dryRun", false) && s(f, "output", "").is_empty() {
+ f.get("__printers").and_then(Value::as_array).map(|a| a.iter().filter_map(|v| v.as_str().map(str::to_string)).collect())
+ } else {
+ None
+ };
+ if printers.is_some() {
+ if !b(f, "__driverPageInitialized", false) {
+ driver_page(f);
+ f.insert("__driverPageInitialized".into(), json!(true));
+ }
+ } else {
+ f.remove("__driverPageInitialized");
+ }
let p = params(f);
ui.horizontal_top(|ui| {
// Page preview.
@@ -915,17 +957,57 @@ fn print_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map = opts.iter().map(|(k, l)| (k.clone(), l.as_str())).collect();
- if crate::widgets::dropdown(ui, "print-printer", &mut pr, &o, 240.0) {
- f.insert("printer".into(), json!(pr));
+ if let Some(printers) = &printers {
+ // Windows: Photoshop's Printer menu and Print Settings… (the driver's own dialog).
+ ui.horizontal(|ui| {
+ ui.label(egui::RichText::new(tl!("Printer")).color(t.text_dim));
+ let before = s(f, "printer", "");
+ let opts: Vec<(&str, &str)> = printers.iter().map(|n| (n.as_str(), n.as_str())).collect();
+ dropdown_str(ui, "print-printer", f, "printer", &opts, 220.0);
+ if s(f, "printer", "") != before {
+ f.remove("printerSettings");
+ driver_page(f);
+ }
+ });
+ ui.horizontal(|ui| {
+ number(ui, f, "copies", tl!("Copies"), 1.0..=999.0, "", 1.0);
+ if ui.button(tl!("Print Settings…")).clicked() {
+ let printer = s(f, "printer", "");
+ let current = f.get("printerSettings").and_then(Value::as_str).and_then(|h| craft_print::rgb::DevMode::from_hex(h).ok());
+ match craft_print::rgb::settings_dialog(&printer, current.as_ref(), None) {
+ Ok(Some(dm)) => {
+ f.insert("printerSettings".into(), json!(dm.to_hex()));
+ driver_page(f);
+ }
+ Ok(None) => {}
+ Err(e) => {
+ f.insert("__pageError".into(), json!(e.to_string()));
+ }
+ }
+ }
+ });
+ let paper = p.get("paper").and_then(Value::as_array).map(|a| (a.first().and_then(Value::as_f64), a.get(1).and_then(Value::as_f64)));
+ let text = match paper {
+ Some((Some(w), Some(h))) => format!("{:.0} × {:.0} mm · {}", w / 72.0 * 25.4, h / 72.0 * 25.4, tl!("set in Print Settings…")),
+ _ => String::new(),
+ };
+ ui.label(egui::RichText::new(text).color(t.text_dim).size(11.0));
+ if let Some(e) = f.get("__pageError").and_then(Value::as_str) {
+ ui.label(egui::RichText::new(e).color(t.warning).size(11.0));
}
- });
- number(ui, f, "copies", tl!("Copies"), 1.0..=999.0, "", 1.0);
- print_paper_controls(ui, f);
+ } else {
+ ui.horizontal(|ui| {
+ ui.label(egui::RichText::new(tl!("Printer")).color(t.text_dim));
+ let mut pr = s(f, "printer", "");
+ let opts = printer_options(f.get("__systemPrinters"), &pr);
+ let o: Vec<(String, &str)> = opts.iter().map(|(k, l)| (k.clone(), l.as_str())).collect();
+ if crate::widgets::dropdown(ui, "print-printer", &mut pr, &o, 240.0) {
+ f.insert("printer".into(), json!(pr));
+ }
+ });
+ number(ui, f, "copies", tl!("Copies"), 1.0..=999.0, "", 1.0);
+ print_paper_controls(ui, f);
+ }
head(ui, tl!("Color Management"));
dropdown_str(
ui,
@@ -977,6 +1059,11 @@ fn print_body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map) -> Result