mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge main into reset warning dialogs
This commit is contained in:
commit
7f64022241
126 files changed
+5348
-417
No files matched your search
@@ -20,6 +20,7 @@ next to them.
|
||||
| `assets/icons/gradient-tool.svg` | Gradient tool glyph with a horizontal opacity ramp | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/spirit-level.svg` | Straighten tool glyph: a spirit level with its vial and bubble under a dotted arc | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/type-vertical.svg` | Vertical Type tool glyph: Lucide `type`'s T, drawn narrower to make room for a downward arrow of our own at its left | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/type.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
| `assets/icons/quick-mask-{off,masked-areas,selected-areas}.svg` | Quick Mask toolbar glyphs showing the inactive mode and the two overlay meanings | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/path-op-{new-layer,combine,subtract,intersect,exclude,merge}.svg` | Path Operations glyphs (Pen options bar): a single square for New Layer, and two overlapping squares showing the area each operation keeps (union, back minus front, overlap, everything but the overlap, the merged outline), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/arrange-{tile-all-vertically,tile-all-horizontally,two-up-horizontal,two-up-vertical,three-up-horizontal,three-up-vertical,three-up-stacked,four-up,six-up,consolidate-all-to-tabs}.svg` | Window › Arrange layout glyphs: a window outline split into the panes each entry lays out (columns, rows, the n-up splits, and one window with a tab row for Consolidate All to Tabs), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
|
||||
| `assets/icons/history-brush.svg` | History Brush tool glyph: Lucide `brush` plus counter-clockwise history rewind arrow | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/brush.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
|
||||
|
||||
Generated
+96
-96
@@ -1376,7 +1376,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-automation",
|
||||
"craft-behavior",
|
||||
@@ -1417,7 +1417,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-affinity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -1438,7 +1438,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-appkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"objc2 0.6.5",
|
||||
@@ -1450,7 +1450,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
]
|
||||
@@ -1458,7 +1458,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-automation"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -1483,7 +1483,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-behavior"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bitflags 2.13.2",
|
||||
@@ -1501,7 +1501,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-browse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-docpath",
|
||||
@@ -1519,7 +1519,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cloud-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
@@ -1527,7 +1527,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
@@ -1536,12 +1536,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-color"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1549,7 +1549,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-transform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-cms",
|
||||
"craft-color",
|
||||
@@ -1559,7 +1559,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-color-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-cms",
|
||||
@@ -1580,7 +1580,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-ai-agents",
|
||||
"craft-atomic",
|
||||
@@ -1596,7 +1596,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control-protocol"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"serde_json",
|
||||
@@ -1606,7 +1606,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-metadata",
|
||||
"craft-xml",
|
||||
@@ -1616,7 +1616,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1624,7 +1624,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -1632,7 +1632,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-develop"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-color",
|
||||
"craft-color-transform",
|
||||
@@ -1647,7 +1647,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-develop-model"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-geom",
|
||||
"craft-metadata",
|
||||
@@ -1659,7 +1659,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dialogs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"craft-appkit",
|
||||
@@ -1685,7 +1685,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1693,7 +1693,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-draw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1712,7 +1712,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-drawingml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-xml",
|
||||
@@ -1724,12 +1724,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-file-formats"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"craft-idml",
|
||||
@@ -1747,7 +1747,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-flags"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"dirs",
|
||||
@@ -1757,7 +1757,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-catalog"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust 0.13.3",
|
||||
@@ -1772,7 +1772,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-manager"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -1792,7 +1792,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-os-windows"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"windows-registry",
|
||||
"windows-sys 0.61.2",
|
||||
@@ -1801,7 +1801,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"cap-primitives",
|
||||
"craft-atomic",
|
||||
@@ -1824,12 +1824,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-geom"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1837,7 +1837,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-heif"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"heic-rs",
|
||||
"rayon",
|
||||
@@ -1846,7 +1846,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-i18n",
|
||||
@@ -1859,7 +1859,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.2",
|
||||
@@ -1889,7 +1889,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-idml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -1899,7 +1899,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-heif",
|
||||
@@ -1927,7 +1927,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-imaging"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1945,12 +1945,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ipp"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1958,7 +1958,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-keymap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
@@ -1973,7 +1973,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-kra"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -1983,7 +1983,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-layers"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
@@ -1997,7 +1997,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-menu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2015,7 +2015,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
@@ -2027,7 +2027,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-nightly"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"uds_windows",
|
||||
"winsafe",
|
||||
@@ -2036,7 +2036,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ora"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip",
|
||||
@@ -2046,7 +2046,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pages"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2062,7 +2062,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-bundle"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-atomic",
|
||||
@@ -2075,7 +2075,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"serde",
|
||||
@@ -2086,7 +2086,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"flate2",
|
||||
@@ -2101,7 +2101,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdn"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2110,7 +2110,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-platform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-io",
|
||||
@@ -2143,7 +2143,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-plist"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -2151,7 +2151,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2175,7 +2175,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -2186,7 +2186,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -2199,7 +2199,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-raw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-crw",
|
||||
@@ -2217,7 +2217,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-review"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -2236,7 +2236,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-host",
|
||||
@@ -2253,7 +2253,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-xml",
|
||||
@@ -2274,7 +2274,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-table"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2286,7 +2286,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-testkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
"tempfile",
|
||||
@@ -2296,7 +2296,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-text"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-manager",
|
||||
@@ -2319,7 +2319,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-tracked",
|
||||
@@ -2334,7 +2334,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-editor"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-theme",
|
||||
@@ -2345,7 +2345,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2360,7 +2360,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2370,7 +2370,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-time"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2379,7 +2379,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-timeline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2394,7 +2394,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tracked"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -2402,7 +2402,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-cloud-ui",
|
||||
"craft-ui-canvas",
|
||||
@@ -2416,7 +2416,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-canvas"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -2433,7 +2433,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-contract"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"craft-behavior",
|
||||
@@ -2475,7 +2475,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2486,7 +2486,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-panels"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2504,7 +2504,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-patterns"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2525,7 +2525,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-shell"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2545,7 +2545,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-widgets"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2564,7 +2564,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
@@ -2596,7 +2596,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-win32"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
@@ -2604,7 +2604,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-window"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"craft-appkit",
|
||||
"craft-atomic",
|
||||
@@ -2636,7 +2636,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xcf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2645,7 +2645,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
@@ -2655,7 +2655,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
@@ -4179,7 +4179,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"hayro-interpret",
|
||||
@@ -4209,7 +4209,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-interpret"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"hayro-cmap",
|
||||
@@ -4227,7 +4227,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"fearless_simd",
|
||||
"hayro-ccitt",
|
||||
@@ -4251,7 +4251,7 @@ checksum = "bc2d80da85f31c3fdc0366431f44cfd645a9da1e242ed1f4a61f213d9765660f"
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
@@ -5344,7 +5344,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
|
||||
[[package]]
|
||||
name = "linesweeper"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"kurbo 0.13.1",
|
||||
@@ -9857,7 +9857,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "vello_common"
|
||||
version = "0.0.8"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"fearless_simd",
|
||||
@@ -9905,7 +9905,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "vello_cpu"
|
||||
version = "0.0.8"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glifo 0.1.1",
|
||||
@@ -11551,14 +11551,14 @@ source = "git+https://github.com/storytold/egui.git?rev=07c20531f89717e461c0f387
|
||||
[[patch.unused]]
|
||||
name = "hayro-cmap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "hayro-postscript"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=475f6feb712bd2db2f235d9999be61c68477ae39#475f6feb712bd2db2f235d9999be61c68477ae39"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fc3262f68babdb19a98a89c415c84c6b327073d3#fc3262f68babdb19a98a89c415c84c6b327073d3"
|
||||
+42
-42
@@ -12,21 +12,21 @@ rust-version = "1.95"
|
||||
[workspace.dependencies]
|
||||
# The craft framework through its facade (`craft::ui::…`). The egui `[patch]` below must match
|
||||
# `craft::egui_fork::REV` (checked by `cargo xtask ci`).
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39", default-features = false }
|
||||
craft-tracked = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-ui-macros = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", default-features = false }
|
||||
craft-tracked = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-ui-macros = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# internal
|
||||
photocraft-geom = { path = "crates/geom" }
|
||||
photocraft-color = { path = "crates/color" }
|
||||
photocraft-raster = { path = "crates/raster" }
|
||||
photocraft-doc = { path = "crates/doc" }
|
||||
photocraft-ops = { path = "crates/ops" }
|
||||
craft-plist = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
|
||||
craft-plist = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
|
||||
photocraft-raw = { path = "crates/raw" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-compose = { path = "crates/compose" }
|
||||
photocraft-gpu = { path = "crates/gpu" }
|
||||
photocraft-paint = { path = "crates/paint" }
|
||||
@@ -48,38 +48,38 @@ photocraft-ipp = { path = "crates/ipp" }
|
||||
|
||||
# external
|
||||
# ICC colour management: the shared crate (replaces crates/cms; craft-libs#779).
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784).
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["raster", "write-raster"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# Keep the shared embedded-image validation API until the framework revision includes it.
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# Camera-field EXIF reader/writer, shared prerequisite craft-libs#1563.
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-crs = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-develop = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
craft-develop-model = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n
|
||||
# catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at
|
||||
# the commit in `craft-i18n.rev`). Already in the tree through craft.
|
||||
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "475f6feb712bd2db2f235d9999be61c68477ae39", features = ["ui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3", features = ["ui"] }
|
||||
# Self-contained nightly profile isolation, launch protocol, and security fence.
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
thiserror = "2"
|
||||
serde = { version = "1", features = ["derive", "rc"] }
|
||||
serde_json = "1"
|
||||
@@ -352,16 +352,16 @@ opt-level = 3
|
||||
# Keep the complete egui family and native event bridge on reviewed fork commits.
|
||||
|
||||
[patch.crates-io]
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
vello_common = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
vello_cpu = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
vello_common = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
vello_cpu = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
|
||||
@@ -258,6 +258,8 @@ fn claim_single_instance(
|
||||
// launch that sets only `PHOTOCRAFT_PRESENT_MODE` (say) has per-process options too, so it
|
||||
// keeps its own process instead of handing its files over and being ignored.
|
||||
launch_options.extend_from_slice(&single_instance::env_launch_options());
|
||||
// The CPU-compatibility relaunch's `--safe-gpu` is not a person's: it takes part.
|
||||
let launch_options = single_instance::without_relaunch_safe_gpu(launch_options, std::env::var_os("PHOTOCRAFT_GPU_STARTUP_FAILURE").as_deref());
|
||||
let context = single_instance::LaunchContext {
|
||||
per_user_settings: launch_profile::current().is_nightly() || app_dirs::current().mode == app_dirs::Mode::Platform,
|
||||
new_instance_flag: new_instance && !nightly,
|
||||
|
||||
@@ -29,9 +29,7 @@ use std::io::{BufReader, Read, Write};
|
||||
use std::net::{Ipv4Addr, SocketAddr, TcpListener, TcpStream};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::path::Path;
|
||||
#[cfg(unix)]
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::{SyncSender, sync_channel};
|
||||
use std::sync::{Arc, Mutex, PoisonError};
|
||||
@@ -181,6 +179,22 @@ fn env_launch_options_from(get: impl Fn(&str) -> Option<std::ffi::OsString>) ->
|
||||
ENV_LAUNCH_OPTIONS.iter().filter(|(name, _, is_on)| get(name).is_some_and(|v| is_on(&v.to_string_lossy()))).map(|(_, option, _)| *option).collect()
|
||||
}
|
||||
|
||||
/// Whether `--safe-gpu` keeps a launch out of single-instance. It does when a person passes it, but
|
||||
/// not for the CPU-compatibility relaunch (which sets `PHOTOCRAFT_GPU_STARTUP_FAILURE`): that one
|
||||
/// takes the place of a launch that has already shut its instance down.
|
||||
pub fn safe_gpu_is_launch_option(gpu_startup_failure: Option<&std::ffi::OsStr>) -> bool {
|
||||
gpu_startup_failure.is_none()
|
||||
}
|
||||
|
||||
/// `options` without the `--safe-gpu` the CPU-compatibility relaunch adds; a person's stays
|
||||
/// ([`safe_gpu_is_launch_option`]). Every other option is kept.
|
||||
pub fn without_relaunch_safe_gpu(mut options: Vec<PerProcess>, gpu_startup_failure: Option<&std::ffi::OsStr>) -> Vec<PerProcess> {
|
||||
if !safe_gpu_is_launch_option(gpu_startup_failure) {
|
||||
options.retain(|option| *option != PerProcess::SafeGpu);
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
/// Why this launch runs as its own instance, or `None` to take part in single-instance.
|
||||
pub fn skip_reason(c: &LaunchContext) -> Option<String> {
|
||||
if !c.per_user_settings {
|
||||
@@ -210,6 +224,8 @@ pub struct Primary {
|
||||
/// then, so the second call (`Drop`) can't remove the socket the next primary has bound.
|
||||
#[cfg(unix)]
|
||||
socket: Mutex<Option<PathBuf>>,
|
||||
/// Where `instance.json` is, removed on [`Primary::shutdown`].
|
||||
dir: PathBuf,
|
||||
}
|
||||
|
||||
struct Shared {
|
||||
@@ -255,7 +271,13 @@ impl Primary {
|
||||
if let Some(path) = self.socket.lock().unwrap_or_else(PoisonError::into_inner).take() {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
drop(self.lock.lock().unwrap_or_else(PoisonError::into_inner).take());
|
||||
let mut lock = self.lock.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
if let Some(file) = lock.take() {
|
||||
// Before the lock goes, so the file can only be ours: a later launch never reads an
|
||||
// endpoint that has since been freed (or taken by another program).
|
||||
remove_info(&self.dir);
|
||||
drop(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,11 +346,11 @@ pub fn claim_with(dir: &Path, paths: &[String], timing: Timing) -> Launch {
|
||||
/// once a quitting or crashed primary is gone) and then the running primary, wherever
|
||||
/// `instance.json` says it listens.
|
||||
pub fn claim_in(dir: &Path, paths: &[String], timing: Timing, transport: &Transport) -> Launch {
|
||||
if let Err(e) = std::fs::create_dir_all(dir) {
|
||||
if let Err(e) = create_private_dir(dir) {
|
||||
return Launch::Standalone(format!("{}: {e}", dir.display()));
|
||||
}
|
||||
let lock_path = dir.join(LOCK_FILE);
|
||||
let lock = match OpenOptions::new().read(true).write(true).create(true).truncate(false).open(&lock_path) {
|
||||
let lock = match open_lock(&lock_path) {
|
||||
Ok(lock) => lock,
|
||||
Err(e) => return Launch::Standalone(format!("{}: {e}", lock_path.display())),
|
||||
};
|
||||
@@ -407,9 +429,39 @@ fn serve(dir: &Path, lock: File, timing: Timing, transport: &Transport) -> Resul
|
||||
shared,
|
||||
#[cfg(unix)]
|
||||
socket: Mutex::new(socket),
|
||||
dir: dir.to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
/// The settings folder, the user's alone (0700) on Unix when this is the first to create it.
|
||||
fn create_private_dir(dir: &Path) -> std::io::Result<()> {
|
||||
let mut builder = std::fs::DirBuilder::new();
|
||||
builder.recursive(true);
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::DirBuilderExt::mode(&mut builder, 0o700);
|
||||
builder.create(dir)
|
||||
}
|
||||
|
||||
/// `instance.lock`, the user's alone (0600) on Unix: another local user who could open it could
|
||||
/// hold the lock, and every launch would then wait out its hand-off time and start on its own.
|
||||
fn open_lock(path: &Path) -> std::io::Result<File> {
|
||||
let mut options = OpenOptions::new();
|
||||
options.read(true).write(true).create(true).truncate(false);
|
||||
#[cfg(unix)]
|
||||
std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600);
|
||||
let lock = options.open(path)?;
|
||||
// The mode applies only on create: narrow a lock file an earlier version left readable.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let wide = lock.metadata().is_ok_and(|m| m.permissions().mode() & 0o077 != 0);
|
||||
if wide && let Err(e) = lock.set_permissions(std::fs::Permissions::from_mode(0o600)) {
|
||||
log::warn!("{}: couldn't make it private: {e}", path.display());
|
||||
}
|
||||
}
|
||||
Ok(lock)
|
||||
}
|
||||
|
||||
/// The primary's listener on either transport.
|
||||
enum Listener {
|
||||
Tcp(TcpListener),
|
||||
@@ -574,6 +626,15 @@ fn write_info(dir: &Path, endpoint: &Endpoint, token: &str) -> Result<(), String
|
||||
})
|
||||
}
|
||||
|
||||
/// Remove `instance.json` if this process wrote it.
|
||||
fn remove_info(dir: &Path) {
|
||||
let path = dir.join(INFO_FILE);
|
||||
let pid = std::fs::read(&path).ok().and_then(|b| serde_json::from_slice::<Value>(&b).ok()).and_then(|v| v.get("pid")?.as_u64());
|
||||
if pid == Some(u64::from(std::process::id())) {
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_info(dir: &Path) -> Option<(Endpoint, String)> {
|
||||
let v: Value = serde_json::from_slice(&std::fs::read(dir.join(INFO_FILE)).ok()?).ok()?;
|
||||
let token = v.get("token")?.as_str()?.to_string();
|
||||
|
||||
@@ -133,9 +133,10 @@ fn a_launch_waiting_on_a_closing_instance_takes_over() {
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
primary.shutdown();
|
||||
assert!(matches!(waiting.join().unwrap(), Launch::Primary(_)), "the waiting launch becomes the primary");
|
||||
// After shutdown new connections are refused too.
|
||||
let Launch::Primary(next) = waiting.join().unwrap() else { panic!("the waiting launch becomes the primary") };
|
||||
// After shutdown new connections are refused too. (Read before the drop, which removes the file.)
|
||||
let (endpoint, token) = read_info(&dir).unwrap();
|
||||
drop(next);
|
||||
drop(primary);
|
||||
let short = Instant::now() + Duration::from_millis(300);
|
||||
assert!(send(&endpoint, &token, &["b.psd".into()], short).is_err());
|
||||
@@ -227,6 +228,82 @@ fn the_token_file_is_private_to_the_user() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 1: another local user can't open the lock, so can't hold it.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_lock_file_and_a_new_settings_folder_are_private_to_the_user() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mode = |p: &Path| std::fs::metadata(p).unwrap().permissions().mode() & 0o777;
|
||||
let dir = temp_dir("lock-mode").join("photocraft");
|
||||
let first = primary(&dir);
|
||||
assert_eq!((mode(&dir), mode(&dir.join(LOCK_FILE))), (0o700, 0o600));
|
||||
drop(first);
|
||||
// A lock file an earlier version created 0644 is narrowed on the next start.
|
||||
std::fs::set_permissions(dir.join(LOCK_FILE), std::fs::Permissions::from_mode(0o644)).unwrap();
|
||||
let second = primary(&dir);
|
||||
assert_eq!(mode(&dir.join(LOCK_FILE)), 0o600);
|
||||
drop(second);
|
||||
let _ = std::fs::remove_dir_all(dir.parent().unwrap());
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 3: a primary that shuts down takes its `instance.json` with it,
|
||||
/// and a second `shutdown` (the drop) leaves the next primary's alone.
|
||||
#[test]
|
||||
fn shutdown_removes_the_instance_file_but_not_the_next_ones() {
|
||||
let dir = temp_dir("info-cleanup");
|
||||
let first = primary(&dir);
|
||||
assert!(read_info(&dir).is_some());
|
||||
first.shutdown();
|
||||
assert!(read_info(&dir).is_none(), "no endpoint left behind for a later launch");
|
||||
let second = primary(&dir);
|
||||
let port = port_of(&dir);
|
||||
drop(first);
|
||||
assert_eq!(port_of(&dir), port, "the running primary's file stays");
|
||||
drop(second);
|
||||
assert!(read_info(&dir).is_none());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Follow-up to #3755, point 2: the CPU-compatibility relaunch takes part in single-instance;
|
||||
/// `--safe-gpu` given by a person still gets its own process.
|
||||
#[test]
|
||||
fn the_cpu_relaunch_takes_part_in_single_instance() {
|
||||
assert!(safe_gpu_is_launch_option(None));
|
||||
assert!(!safe_gpu_is_launch_option(Some(std::ffi::OsStr::new("wgpu: no adapter"))));
|
||||
// The relaunch sets the reason even when it is empty.
|
||||
assert!(!safe_gpu_is_launch_option(Some(std::ffi::OsStr::new(""))));
|
||||
}
|
||||
|
||||
/// The filtering `claim_single_instance` applies, through to `skip_reason`: the relaunch's own
|
||||
/// `--safe-gpu` takes part, a person's stays separate, and the relaunch keeps any other option.
|
||||
#[test]
|
||||
fn the_cpu_relaunch_filter_decides_who_takes_part() {
|
||||
let check = |options: &[PerProcess], failure: Option<&str>| {
|
||||
let launch_options = without_relaunch_safe_gpu(options.to_vec(), failure.map(std::ffi::OsStr::new));
|
||||
let context = LaunchContext {
|
||||
per_user_settings: true,
|
||||
new_instance_flag: false,
|
||||
new_instance_env: None,
|
||||
control: false,
|
||||
unreadable_paths: false,
|
||||
launch_options: &launch_options,
|
||||
};
|
||||
(launch_options.clone(), skip_reason(&context))
|
||||
};
|
||||
// The CPU relaunch with no other options takes part, whatever its reason says.
|
||||
for failure in ["wgpu: no adapter", ""] {
|
||||
assert_eq!(check(&[PerProcess::SafeGpu], Some(failure)), (vec![], None));
|
||||
}
|
||||
// A person's `--safe-gpu` keeps its own process.
|
||||
let (kept, reason) = check(&[PerProcess::SafeGpu], None);
|
||||
assert_eq!(kept, [PerProcess::SafeGpu]);
|
||||
assert!(reason.is_some());
|
||||
// The relaunch drops only its own `--safe-gpu`: another option still keeps it separate.
|
||||
let (kept, reason) = check(&[PerProcess::SafeGpu, PerProcess::GpuAdapterEnv], Some("wgpu: no adapter"));
|
||||
assert_eq!(kept, [PerProcess::GpuAdapterEnv]);
|
||||
assert!(reason.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unreachable_instance_falls_back_to_a_standalone_launch() {
|
||||
let dir = temp_dir("unreachable");
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M6 3h12a4 4 0 0 1 4 4v10a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V7a4 4 0 0 1 4-4Zm6 3-6 6 6 6 6-6-6-6Z" fill-rule="evenodd" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 239 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="3" y="4" width="18" height="16" rx="3" />
|
||||
<path d="m12 7 1.5 1.5m2 2 1.5 1.5-1.5 1.5m-2 2L12 17l-1.5-1.5m-2-2L7 12l1.5-1.5m2-2L12 7" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 338 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round">
|
||||
<rect x="3" y="4" width="18" height="16" rx="3" />
|
||||
<path d="m12 7 5 5-5 5-5-5Z" fill="currentColor" stroke="none" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 287 B |
@@ -306,6 +306,9 @@ sync_github_name = false
|
||||
real_name = "Jason DeBoever"
|
||||
sync_github_name = true
|
||||
|
||||
[people.yadser]
|
||||
real_name = "Sergey Yadryshnikov"
|
||||
|
||||
[people.dylanmtaylor]
|
||||
sync_github_name = true
|
||||
|
||||
@@ -361,3 +364,6 @@ sync_github_name = true
|
||||
|
||||
[people.MMexicann]
|
||||
display_name = "mexicann"
|
||||
|
||||
[people.webglobepl]
|
||||
real_name = "Maciej Malinowski"
|
||||
@@ -315,7 +315,12 @@ const PROTECT_DETAIL_LIMIT: f32 = 6.0 / 255.0;
|
||||
/// low halo a few pixels wide, and each difference is soft-limited to `L` = 6 levels:
|
||||
/// `v + amount·d·L/(L + |d|)`. Fine detail is sharpened about as much as without it, while a
|
||||
/// strong edge or a lone bright pixel moves by less than `L` per pass instead of overshooting.
|
||||
/// Uniform areas stay exactly as they are. Alpha is left unchanged.
|
||||
/// Uniform areas stay exactly as they are.
|
||||
///
|
||||
/// Without `protect_detail`, alpha is sharpened by the same rule as colour and clamped to 0..1
|
||||
/// (#12940): a semi-transparent edge gets crisper while the colour stays, since the colour is
|
||||
/// blurred premultiplied. An opaque pixel next to a transparent one stays as it is, because the
|
||||
/// clamp holds both at their limits. With `protect_detail`, alpha is left unchanged (not measured).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn local_sharpen(
|
||||
data: &[f32],
|
||||
@@ -346,7 +351,7 @@ pub fn local_sharpen(
|
||||
for c in 0..ch {
|
||||
let v = data[i + c];
|
||||
if Some(c) == alpha {
|
||||
dst[o + c] = v;
|
||||
dst[o + c] = if protect_detail { v } else { (v + amount * (v - blur_row[o + c])).clamp(0.0, 1.0) };
|
||||
continue;
|
||||
}
|
||||
let d = v - blur_row[o + c];
|
||||
|
||||
@@ -170,6 +170,36 @@ pub fn combine(old: Option<&Surface>, new: &[f32], area: Rect, mode: SelectionMo
|
||||
(s.tile_count() > 0).then_some(s)
|
||||
}
|
||||
|
||||
/// [`combine`] for a channel loaded as a selection, with Photoshop's channel arithmetic: where
|
||||
/// coverage is partial, Add screens (`a + b − a·b`), Subtract keeps what `new` leaves
|
||||
/// (`a·(1 − b)`) and Intersect multiplies (`a·b`). Intersecting a luminosity selection with the
|
||||
/// luminosity again so narrows it to brighter tones at every step (a 50% grey goes 50%, 25%,
|
||||
/// 12.5%, … while white stays selected), and Select All minus the lights minus the darks leaves
|
||||
/// the midtones; [`combine`]'s min and max would leave the first unchanged and the second empty.
|
||||
/// Fully selected and unselected pixels combine as in [`combine`]. Source: Greg Benz, "Photoshop
|
||||
/// channel math: add, subtract, intersect" (gregbenzphotography.com, luminosity-masking).
|
||||
pub fn combine_scaled(old: Option<&Surface>, new: &[f32], area: Rect, mode: SelectionMode) -> Option<Surface> {
|
||||
if area.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if mode == SelectionMode::Replace || (old.is_none() && mode == SelectionMode::Add) {
|
||||
return combine(old, new, area, mode);
|
||||
}
|
||||
let old = old?;
|
||||
if old.format() == PixelFormat::GRAY8 {
|
||||
return combine_mask::gray8_with(Some(old), new, area, mode, false, combine_mask::Arithmetic::Scaled);
|
||||
}
|
||||
// Quantized to the 8-bit grid first, as in `combine`, so the float path agrees with the GRAY8 one.
|
||||
let q = |v: f32| f32::from(coverage8(v)) / 255.0;
|
||||
let prev = mask_from_surface(Some(old), area);
|
||||
let s = match mode {
|
||||
SelectionMode::Add => surface_from_masks(area, new, Some(&prev), |p, v| p + q(v) - p * q(v)),
|
||||
SelectionMode::Subtract => surface_from_masks(area, new, Some(&prev), |p, v| p * (1.0 - q(v))),
|
||||
_ => surface_from_masks(area, new, Some(&prev), |p, v| p * q(v)),
|
||||
};
|
||||
(s.tile_count() > 0).then_some(s)
|
||||
}
|
||||
|
||||
fn close(a: [f32; 4], b: [f32; 4], tol: f32) -> bool {
|
||||
(a[3] == 0.0 && b[3] == 0.0) || (0..4).all(|c| (a[c] - b[c]).abs() * 255.0 <= tol + 1e-3)
|
||||
}
|
||||
|
||||
@@ -39,8 +39,45 @@ pub fn combine_band(old: Option<&Surface>, mask: &[f32], band: Rect, mode: Selec
|
||||
(out.tile_count() > 0).then_some(out)
|
||||
}
|
||||
|
||||
/// How two 8-bit coverages meet where both are partial. Fully selected and unselected pixels
|
||||
/// combine the same way under both.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum Arithmetic {
|
||||
/// The selection tools': Add keeps the larger coverage, Subtract takes the clipped
|
||||
/// difference and Intersect keeps the smaller.
|
||||
Extremes,
|
||||
/// A channel loaded as a selection (Photoshop's channel arithmetic): Add screens
|
||||
/// (`a + b − a·b`), Subtract keeps what the new coverage leaves (`a·(1 − b)`) and Intersect
|
||||
/// multiplies (`a·b`). Intersecting a partial selection with itself narrows it.
|
||||
Scaled,
|
||||
}
|
||||
|
||||
impl Arithmetic {
|
||||
pub(super) fn apply(self, mode: SelectionMode, prev: u8, new: u8) -> u8 {
|
||||
match (self, mode) {
|
||||
(_, SelectionMode::Replace) => new,
|
||||
(Arithmetic::Extremes, SelectionMode::Add) => prev.max(new),
|
||||
(Arithmetic::Extremes, SelectionMode::Subtract) => prev.saturating_sub(new),
|
||||
(Arithmetic::Extremes, SelectionMode::Intersect) => prev.min(new),
|
||||
(Arithmetic::Scaled, SelectionMode::Add) => u8::MAX - mul8(u8::MAX - prev, u8::MAX - new),
|
||||
(Arithmetic::Scaled, SelectionMode::Subtract) => mul8(prev, u8::MAX - new),
|
||||
(Arithmetic::Scaled, SelectionMode::Intersect) => mul8(prev, new),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `a·b / 255` rounded to the nearest byte, exactly, for every pair of bytes.
|
||||
pub(super) fn mul8(a: u8, b: u8) -> u8 {
|
||||
let t = u32::from(a) * u32::from(b) + 128;
|
||||
u8::try_from((t + (t >> 8)) >> 8).unwrap_or(u8::MAX)
|
||||
}
|
||||
|
||||
pub(super) fn gray8(old: Option<&Surface>, mask: &[f32], area: Rect, mode: SelectionMode, keep_outside: bool) -> Option<Surface> {
|
||||
build(old, area, mode, keep_outside, |i| coverage8(mask.get(i).copied().unwrap_or(0.0)))
|
||||
gray8_with(old, mask, area, mode, keep_outside, Arithmetic::Extremes)
|
||||
}
|
||||
|
||||
pub(super) fn gray8_with(old: Option<&Surface>, mask: &[f32], area: Rect, mode: SelectionMode, keep_outside: bool, arithmetic: Arithmetic) -> Option<Surface> {
|
||||
build(old, area, mode, keep_outside, arithmetic, |i| coverage8(mask.get(i).copied().unwrap_or(0.0)))
|
||||
}
|
||||
|
||||
pub(super) fn gray8_bytes(old: Option<&Surface>, mask: &[u8], area: Rect, mode: SelectionMode) -> Option<Surface> {
|
||||
@@ -48,10 +85,17 @@ pub(super) fn gray8_bytes(old: Option<&Surface>, mask: &[u8], area: Rect, mode:
|
||||
if area.is_empty() {
|
||||
return if keep { old.cloned().filter(|s| !s.content_bounds().is_empty()) } else { None };
|
||||
}
|
||||
build(old, area, mode, keep, |i| mask.get(i).copied().unwrap_or(0))
|
||||
build(old, area, mode, keep, Arithmetic::Extremes, |i| mask.get(i).copied().unwrap_or(0))
|
||||
}
|
||||
|
||||
fn build(old: Option<&Surface>, area: Rect, mode: SelectionMode, keep_outside: bool, sample: impl Fn(usize) -> u8 + Sync) -> Option<Surface> {
|
||||
fn build(
|
||||
old: Option<&Surface>,
|
||||
area: Rect,
|
||||
mode: SelectionMode,
|
||||
keep_outside: bool,
|
||||
arithmetic: Arithmetic,
|
||||
sample: impl Fn(usize) -> u8 + Sync,
|
||||
) -> Option<Surface> {
|
||||
let mut out = if keep_outside { old.cloned().unwrap_or_else(|| Surface::new(PixelFormat::GRAY8)) } else { Surface::new(PixelFormat::GRAY8) };
|
||||
let default = old.and_then(|s| s.default_bytes().first()).copied().unwrap_or(0);
|
||||
let out_default = out.default_bytes().first().copied().unwrap_or(0);
|
||||
@@ -77,12 +121,7 @@ fn build(old: Option<&Surface>, area: Rect, mode: SelectionMode, keep_outside: b
|
||||
for (i, d) in dst.iter_mut().enumerate() {
|
||||
let new = start.and_then(|j| j.checked_add(i)).map(&sample).unwrap_or(0);
|
||||
let prev = src.and_then(|s| s.get(i)).copied().unwrap_or(default);
|
||||
*d = match mode {
|
||||
SelectionMode::Replace => new,
|
||||
SelectionMode::Add => prev.max(new),
|
||||
SelectionMode::Subtract => prev.saturating_sub(new),
|
||||
SelectionMode::Intersect => prev.min(new),
|
||||
};
|
||||
*d = arithmetic.apply(mode, prev, new);
|
||||
}
|
||||
}
|
||||
let (lo, hi) = tile.bytes().iter().fold((u8::MAX, 0u8), |(lo, hi), b| (lo.min(*b), hi.max(*b)));
|
||||
|
||||
@@ -76,6 +76,37 @@ fn cropped_bands_match_dense_writeback_with_defaults_and_short_masks() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scaled_combining_narrows_partial_coverage_and_keeps_hard_edges() {
|
||||
use crate::selection::combine_scaled;
|
||||
let area = Rect::new(0, 0, 256, 256);
|
||||
let prev: Vec<f32> = (0..65536).map(|i| (i / 256) as f32 / 255.0).collect();
|
||||
let mask: Vec<f32> = (0..65536).map(|i| (i % 256) as f32 / 255.0).collect();
|
||||
let gray8 = crate::selection::mask_to_surface(&prev, area);
|
||||
// An unusual (float) selection surface takes the float path; it must agree with the byte path everywhere.
|
||||
let mut float = Surface::new(PixelFormat::new(ColorMode::Grayscale, SampleType::F32, false));
|
||||
float.write_region(area, &prev);
|
||||
for mode in MODES {
|
||||
let scaled = combine_scaled(Some(&gray8), &mask, area, mode);
|
||||
assert_eq!(scaled, combine_scaled(Some(&float), &mask, area, mode), "{mode:?}: float and byte paths");
|
||||
let scaled = mask_from_surface(scaled.as_ref(), area);
|
||||
let tools = mask_from_surface(combine(Some(&gray8), &mask, area, mode).as_ref(), area);
|
||||
for (i, ((&p, &m), (&s, &t))) in prev.iter().zip(&mask).zip(scaled.iter().zip(&tools)).enumerate() {
|
||||
if m == 0.0 || m == 1.0 {
|
||||
assert_eq!(s, t, "{mode:?} {i}: a fully selected or unselected pixel combines as the tools do");
|
||||
continue;
|
||||
}
|
||||
match mode {
|
||||
SelectionMode::Add => assert!(s >= t, "{mode:?} {i}: adding partial coverage keeps at least the larger one"),
|
||||
SelectionMode::Subtract => assert!(s >= t, "{mode:?} {i}: subtracting scales the selection, never below the difference"),
|
||||
SelectionMode::Intersect if p == m && p > 0.0 => assert!(s < p, "{mode:?} {i}: intersecting a partial selection with itself narrows it"),
|
||||
SelectionMode::Intersect => assert!(s <= t, "{mode:?} {i}: intersecting keeps no more than the smaller one"),
|
||||
SelectionMode::Replace => assert_eq!(s, t),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unusual_selection_formats_keep_their_float_behavior() {
|
||||
let area = Rect::new(-2, -1, 3, 2);
|
||||
|
||||
@@ -62,7 +62,7 @@ fn scalar_local_sharpen(
|
||||
for c in 0..ch {
|
||||
let v = data[i + c];
|
||||
if Some(c) == alpha {
|
||||
out[o + c] = v;
|
||||
out[o + c] = if protect_detail { v } else { (v + amount * (v - blur[o + c])).clamp(0.0, 1.0) };
|
||||
continue;
|
||||
}
|
||||
let d = v - blur[o + c];
|
||||
|
||||
@@ -334,10 +334,24 @@ impl Headless {
|
||||
_ => return Err(AutomationError::BadRequest("automation filesystem access is not granted: write authority is absent".into())),
|
||||
};
|
||||
let mut outputs = workspace.export_sequence(dir)?;
|
||||
let written = photocraft_engine::export_data_sets_with(&this.session, params, |name, bytes| {
|
||||
let report = photocraft_engine::export_data_sets_report_with(&this.session, params, |name, bytes| {
|
||||
outputs.write(name, bytes).map_err(|e| photocraft_engine::EngineError::Other(e.to_string()))
|
||||
});
|
||||
exported(dir, written, &mut outputs)
|
||||
// The sets a missing replacement image left out or stopped at, as the command says (#13767).
|
||||
let (written, report) = match report {
|
||||
Ok(report) => (Ok(report.files.clone()), Some(report)),
|
||||
Err(error) => (Err(error), None),
|
||||
};
|
||||
let mut result = exported(dir, written, &mut outputs)?;
|
||||
if let Some(report) = report {
|
||||
let full = report.json(Vec::new());
|
||||
for key in ["skipped", "stopped"] {
|
||||
if let Some(value) = full.get(key) {
|
||||
result[key] = value.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ photocraft-geom = { workspace = true }
|
||||
photocraft-color = { workspace = true }
|
||||
craft-cms = { workspace = true }
|
||||
# PCTIP codec from craft-libs#1564; kept at the same shared revision as the workspace.
|
||||
craft-pcraft-tip = { package = "craft-pcraft-format", git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-pcraft-tip = { package = "craft-pcraft-format", git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
photocraft-raster = { workspace = true }
|
||||
photocraft-doc = { workspace = true }
|
||||
photocraft-ops = { workspace = true }
|
||||
|
||||
@@ -7,6 +7,7 @@ use photocraft_raster::Surface;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{bad, num};
|
||||
use crate::color_cmds::ColorExt;
|
||||
use crate::{EngineError, Result, Session};
|
||||
|
||||
const CMD: &str = "image.adjustments.replaceColor";
|
||||
@@ -107,8 +108,12 @@ pub(super) fn apply(s: &mut Session, p: &Value) -> Result<Option<Value>> {
|
||||
if format.mode != st.doc.mode {
|
||||
return Err(bad(CMD, "pixel layout does not match the document profile"));
|
||||
}
|
||||
let transform = craft_cms::cached(&crate::color_cmds::document_profile(&st.doc), Builtin::LabD50.profile(), TransformOptions::default())
|
||||
.map_err(|e| bad(CMD, format!("Lab colour transform: {e}")))?;
|
||||
// The layer's samples live in the space the session shows the document in, so an untagged
|
||||
// document is read in its working space here too (#14224): Lab bounds that Replace Color works
|
||||
// in, and the Gamut Warning marks, agree.
|
||||
let source = s.color().document_profile(&st.doc);
|
||||
let transform =
|
||||
craft_cms::cached(&source, Builtin::LabD50.profile(), TransformOptions::default()).map_err(|e| bad(CMD, format!("Lab colour transform: {e}")))?;
|
||||
if transform.inputs() != format.mode.color_channels() || transform.outputs() != 3 || format.channels() != transform.inputs() + usize::from(format.alpha) {
|
||||
return Err(bad(CMD, "unsupported Lab colour-transform layout"));
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Load Selection…",
|
||||
["Select"],
|
||||
None,
|
||||
r##"{"channel":index|name|"composite"|"red|green|blue|…"|"transparency"|"mask"|"vectorMask"|"quickMask"|"selection"|"targeted" (the Channels panel's target),"layer":id|name|{"name":str}|{"background":true}?,"document":index?,"invert":bool=false,"operation":"new|add|subtract|intersect"="new"}"##,
|
||||
r##"{"channel":index|name|"composite"|"red|green|blue|…"|"transparency"|"mask"|"vectorMask"|"quickMask"|"selection"|"targeted" (the Channels panel's target),"layer":id|name|{"name":str}|{"background":true}?,"document":index?,"invert":bool=false,"operation":"new|add|subtract|intersect"="new"} (an RGB composite loads its luminosity converted into the working gray, edit.colorSettings workingGray; partial coverage combines as channels do: add screens, subtract keeps a·(1−b), intersect multiplies)"##,
|
||||
has_doc,
|
||||
load_selection
|
||||
),
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
use super::planes::{channel_format, next_alpha_name, plane_surface, read_plane};
|
||||
use super::refs::{ChanRef, bad, doc_index, parse_ref, source};
|
||||
use super::view::{ChannelTarget, QuickMaskOptions};
|
||||
use super::{AlphaChannel, ColorIndicates, Document, EngineError, PixelFormat, Rect, Result, SelectionMode, Session, Surface, Value, json, operation, sel};
|
||||
use super::{
|
||||
AlphaChannel, ColorIndicates, ColorMode, Document, EngineError, PixelFormat, Rect, Result, SelectionMode, Session, Surface, Value, json, operation, sel,
|
||||
};
|
||||
use crate::color_cmds::{ColorExt, cms_err, document_profile};
|
||||
use craft_cms::TransformOptions;
|
||||
|
||||
pub(super) fn save_selection(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "select.saveSelection";
|
||||
@@ -77,6 +81,43 @@ fn load_label(doc: &Document, p: &Value) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
/// The composite of an RGB document as a luminosity selection, as Photoshop builds one: the composite converted
|
||||
/// from the document's profile into the working gray (Edit › Color Settings › Gray) with the Color Settings
|
||||
/// conversion options. The working gray decides how much each tone is selected: with Gray Gamma 2.2 (Adobe RGB's
|
||||
/// tone curve) a middle grey loads about half selected, with a dot gain gray clearly less, and the 50 % ants move
|
||||
/// with it. `None` for any other channel or document mode, which loads its values as before. Source: Greg Benz,
|
||||
/// "How to optimize your gray working space for better luminosity masks" (gregbenzphotography.com).
|
||||
fn composite_luminosity(s: &Session, p: &Value, cmd: &str) -> Result<Option<Vec<f32>>> {
|
||||
// Pixels converted per call, so the interleaved RGB copy stays small.
|
||||
const BAND: usize = 1 << 16;
|
||||
let di = doc_index(s, p, "document")?;
|
||||
let Some(doc) = s.documents().get(di).map(|st| &st.doc) else { return Ok(None) };
|
||||
if doc.mode != ColorMode::Rgb || p.get("channel").and_then(|v| parse_ref(v, doc)) != Some(ChanRef::Composite) {
|
||||
return Ok(None);
|
||||
}
|
||||
// Invert applies to the gray, after the conversion, not to each colour plane.
|
||||
let mut plain = p.clone();
|
||||
if let Some(m) = plain.as_object_mut() {
|
||||
m.remove("invert");
|
||||
}
|
||||
let planes = source(s, &plain, cmd, false)?;
|
||||
let [red, green, blue] = planes.as_slice() else { return Ok(None) };
|
||||
let color = s.color();
|
||||
let options = TransformOptions { intent: color.settings.intent(), bpc: color.settings.bpc, ..TransformOptions::default() };
|
||||
let transform = craft_cms::cached(&document_profile(doc), &color.working(ColorMode::Grayscale), options).map_err(cms_err)?;
|
||||
let mut gray = vec![0.0f32; red.len()];
|
||||
let mut rgb = Vec::with_capacity(BAND * 3);
|
||||
for (((out, r), g), b) in gray.chunks_mut(BAND).zip(red.chunks(BAND)).zip(green.chunks(BAND)).zip(blue.chunks(BAND)) {
|
||||
rgb.clear();
|
||||
rgb.extend(r.iter().zip(g).zip(b).flat_map(|((&r, &g), &b)| [r, g, b]));
|
||||
transform.convert_f32(&rgb, 3, out, 1, false).map_err(cms_err)?;
|
||||
}
|
||||
if p.get("invert").and_then(Value::as_bool).unwrap_or(false) {
|
||||
gray.iter_mut().for_each(|v| *v = 1.0 - *v);
|
||||
}
|
||||
Ok(Some(gray))
|
||||
}
|
||||
|
||||
pub(super) fn load_selection(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "select.loadSelection";
|
||||
let mode = match operation(p, "operation") {
|
||||
@@ -103,12 +144,19 @@ pub(super) fn load_selection(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
}
|
||||
let p = &targeted;
|
||||
// Composite and colour channels load their luminosity / values, as ⌘-clicking them does.
|
||||
let plane = source(s, p, cmd, true)?.into_iter().next().ok_or_else(|| bad(cmd, "the channel has no pixels"))?;
|
||||
// An RGB composite loads its luminosity in the working gray; other channels (colour channels, alphas, masks)
|
||||
// load their values, as ⌘-clicking them does.
|
||||
let plane = match composite_luminosity(s, p, cmd)? {
|
||||
Some(plane) => plane,
|
||||
None => source(s, p, cmd, true)?.into_iter().next().ok_or_else(|| bad(cmd, "the channel has no pixels"))?,
|
||||
};
|
||||
let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;
|
||||
let label = load_label(doc, p);
|
||||
// A loaded channel meets the selection with channel arithmetic (multiply, screen), as Photoshop combines one:
|
||||
// ⌘⇧⌥-clicking the composite again narrows a luminosity selection to brighter tones each time (lights,
|
||||
// brighter lights, … up to the pure whites), where min / max would leave it unchanged.
|
||||
let selected = s.edit(label, |doc, _| {
|
||||
doc.selection = sel::combine(doc.selection.as_ref(), &plane, doc.bounds(), mode);
|
||||
doc.selection = sel::combine_scaled(doc.selection.as_ref(), &plane, doc.bounds(), mode);
|
||||
Ok(doc.selection.is_some())
|
||||
})?;
|
||||
Ok(json!({ "selected": selected }))
|
||||
|
||||
@@ -101,6 +101,72 @@ fn load_selection_operations_and_invert() {
|
||||
assert_eq!(sel_at(&s, 25, 5), 1.0);
|
||||
}
|
||||
|
||||
/// Paints the 40 × 20 background with neutral greys, `grey(x)` in column `x` (`edit.fill` is
|
||||
/// engine-paint's, not in this crate's session).
|
||||
fn paint_greys(s: &mut Session, grey: impl Fn(usize) -> f32) {
|
||||
let d = s.active_mut().unwrap();
|
||||
let id = d.active_layer.unwrap();
|
||||
let surf = std::sync::Arc::make_mut(d.doc_mut()).layer_mut(id).unwrap().surface_mut().unwrap();
|
||||
let n = surf.format().channels();
|
||||
let mut px = vec![1.0; 40 * 20 * n];
|
||||
for (i, p) in px.chunks_exact_mut(n).enumerate() {
|
||||
p[..3].fill(grey(i % 40));
|
||||
}
|
||||
surf.write_region(Rect::new(0, 0, 40, 20), &px);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersecting_the_composite_luminosity_with_itself_narrows_it_toward_the_whites() {
|
||||
// Luminosity masks: ⌘-click the composite, then ⌘⇧⌥-click it again and again. Each step multiplies the
|
||||
// selection by the luminosity, so it narrows to brighter tones while white stays fully selected; Select All
|
||||
// minus the lights minus the darks leaves the midtones. Min / max combining left the first unchanged and the
|
||||
// second empty.
|
||||
for depth in [8, 16] {
|
||||
let mut s = session_depth(depth);
|
||||
// Neutral greys from black (x 0) to white (x 39).
|
||||
paint_greys(&mut s, |x| x as f32 / 39.0);
|
||||
let load = |s: &mut Session, operation: &str, invert: bool| {
|
||||
s.execute("select.loadSelection", json!({"channel": "composite", "operation": operation, "invert": invert})).unwrap();
|
||||
(0..40).map(|x| sel_at(s, x, 5)).collect::<Vec<f32>>()
|
||||
};
|
||||
let lights = load(&mut s, "new", false);
|
||||
let lights2 = load(&mut s, "intersect", false);
|
||||
let lights3 = load(&mut s, "intersect", false);
|
||||
let step = 1.0 / 255.0 + 1e-6;
|
||||
for x in 1..39 {
|
||||
assert!(lights2[x] < lights[x] && lights3[x] <= lights2[x], "depth {depth}, x {x}: each step selects every grey less");
|
||||
assert!((lights2[x] - lights[x] * lights[x]).abs() <= step, "depth {depth}, x {x}: the step multiplies by the luminosity");
|
||||
}
|
||||
assert!(lights3[20] < lights2[20], "depth {depth}: a middle grey keeps narrowing");
|
||||
assert!([&lights, &lights2, &lights3].iter().all(|l| l[39] == 1.0 && l[0] == 0.0), "depth {depth}: white stays selected, black never is");
|
||||
s.execute("select.all", json!({})).unwrap();
|
||||
let darks = load(&mut s, "subtract", false);
|
||||
assert!(darks[0] == 1.0 && darks[39] == 0.0 && darks[20] > 0.4, "depth {depth}: Select All minus the lights is the darks");
|
||||
let mids = load(&mut s, "subtract", true);
|
||||
assert!(mids[0] == 0.0 && mids[39] == 0.0, "depth {depth}: the midtones hold neither black nor white");
|
||||
assert!(mids[20] > 0.2 && mids[20] > mids[5] && mids[20] > mids[34], "depth {depth}: they peak at the middle grey");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_composite_loads_its_luminosity_in_the_working_gray() {
|
||||
// ⌘-click on the composite converts it into Color Settings › Gray, as Photoshop does: a dot gain gray selects a
|
||||
// middle grey clearly less than Gray Gamma 2.2 (about half), so the 50 % ants move with the setting. Inverting
|
||||
// inverts that gray, not each colour plane before the conversion.
|
||||
let load = |gray: &str, invert: bool| {
|
||||
let mut s = session();
|
||||
s.execute("edit.colorSettings", json!({"workingGray": gray})).unwrap();
|
||||
paint_greys(&mut s, |_| 128.0 / 255.0);
|
||||
s.execute("select.loadSelection", json!({"channel": "composite", "invert": invert})).unwrap();
|
||||
sel_at(&s, 5, 5)
|
||||
};
|
||||
let (gamma, dot_gain) = (load("gray-gamma-2.2", false), load("dot-gain-20-compat", false));
|
||||
assert!((gamma - 0.5).abs() < 0.03, "Gray Gamma 2.2: a middle grey is about half selected ({gamma})");
|
||||
assert!(dot_gain < gamma - 0.05, "a dot gain gray selects it less ({dot_gain} vs {gamma})");
|
||||
let inverted = load("dot-gain-20-compat", true);
|
||||
assert!((inverted - (1.0 - dot_gain)).abs() <= 1.0 / 255.0 + 1e-6, "inverted: {inverted} vs 1 - {dot_gain}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channel_management_and_view_state() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
//! Colors / Gamut Warning) and the display transform the canvas applies.
|
||||
//!
|
||||
//! Document space: `Document::icc_profile` holds the document's ICC bytes (kept byte-exact
|
||||
//! from PSD resource 1039 / PNG iCCP / JPEG APP2 / TIFF). `None` means untagged: the working
|
||||
//! profile of the mode is assumed (sRGB, sGray, the built-in coated CMYK, Lab D50).
|
||||
//! from PSD resource 1039 / PNG iCCP / JPEG APP2 / TIFF). `None` means untagged: RGB and gray
|
||||
//! documents are then taken in the working space of Color Settings ([`ColorState::working`],
|
||||
//! sRGB and the default working gray unless the settings say otherwise, #14224), the other modes
|
||||
//! in the mode's built-in default (the built-in coated CMYK, Lab D50).
|
||||
//!
|
||||
//! Compositing stays in document space for RGB and gray documents. CMYK and Lab documents are
|
||||
//! composited in sRGB after a per-layer conversion with the built-in profiles (see
|
||||
@@ -111,7 +113,8 @@ impl Policy {
|
||||
|
||||
/// Edit › Color Settings: working spaces, colour management policies and conversion options.
|
||||
/// Honoured when files are opened ([`ColorExt::open_document`](crate::color_cmds::ColorExt::open_document)), by Image › Mode conversions
|
||||
/// and by "working" profile specs (Convert to Profile, Proof Setup).
|
||||
/// and by "working" profile specs (Convert to Profile, Proof Setup). An untagged RGB or Grayscale
|
||||
/// document is taken in the working space as well, on screen and in conversions (#14224).
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase", remote = "Self")]
|
||||
pub struct ColorSettings {
|
||||
@@ -468,6 +471,52 @@ impl ColorState {
|
||||
}
|
||||
}
|
||||
|
||||
/// The profile an untagged document is taken in: Color Settings' working space for the two
|
||||
/// modes #14224 measures, otherwise the mode's built-in default, as [`working_profile`] gives.
|
||||
pub fn untagged_profile(&self, doc: &Document) -> Arc<Profile> {
|
||||
match doc.mode {
|
||||
ColorMode::Rgb | ColorMode::Grayscale => self.working(doc.mode),
|
||||
_ => working_profile(doc.mode),
|
||||
}
|
||||
}
|
||||
|
||||
/// The document's profile as this session sees it: [`document_profile`], except that an
|
||||
/// untagged RGB or Grayscale document falls back to Color Settings' working space instead of
|
||||
/// the mode's built-in default (#14224). A tagged document, and every other mode, resolve
|
||||
/// exactly as the free function does.
|
||||
pub fn document_profile(&self, doc: &Document) -> Arc<Profile> {
|
||||
embedded_profile(doc).unwrap_or_else(|| self.untagged_profile(doc))
|
||||
}
|
||||
|
||||
/// [`composite_profile`] as this session sees it: an untagged document's composite is
|
||||
/// described by the working space it is shown in (#14224).
|
||||
pub fn composite_profile(&self, doc: &Document) -> Arc<Profile> {
|
||||
match mode_space(doc.mode) {
|
||||
ColorSpace::Rgb => self.document_profile(doc),
|
||||
ColorSpace::Gray => {
|
||||
let p = self.document_profile(doc);
|
||||
// sGray is a TRC profile, so its RGB view always exists; sRGB is the last resort.
|
||||
p.gray_as_rgb().or_else(|| Builtin::SGray.profile().gray_as_rgb()).map(Arc::new).unwrap_or_else(|| Arc::new(Builtin::Srgb.profile().clone()))
|
||||
}
|
||||
_ => Arc::new(Builtin::Srgb.profile().clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The working-space spec Color Settings holds for `mode`, with the intent that spec is
|
||||
/// validated against: the cheap stand-in for [`Self::working`] in the display cache key,
|
||||
/// which runs on every frame and would otherwise clone the profile's tables (or read its
|
||||
/// `.icc` file) each time (#14224).
|
||||
pub fn working_space_spec(&self, mode: ColorMode) -> Option<&str> {
|
||||
self.settings.working_spec(mode_space(mode))
|
||||
}
|
||||
|
||||
/// [`gamut_mask`] as this session sees `doc`: the composite is judged in the profile the canvas
|
||||
/// shows it in, so the Gamut Warning count and Color Range › Out of Gamut agree with the pixels
|
||||
/// the canvas marks (#14224).
|
||||
pub fn gamut_mask(&self, doc: &Document, setup: &ProofSetup, threshold: f32) -> Result<(Vec<u8>, usize)> {
|
||||
gamut_mask_against(doc, &self.composite_profile(doc), setup, threshold)
|
||||
}
|
||||
|
||||
/// Apply the colour management policy to a document being opened. Returns what happened
|
||||
/// (`action`: kept|converted|discarded|assigned|untagged) and whether to ask the user.
|
||||
///
|
||||
@@ -549,7 +598,7 @@ impl ColorState {
|
||||
}
|
||||
let working = self.working(doc.mode);
|
||||
let policy = self.settings.policy(doc.mode);
|
||||
let embedded = doc.icc_profile.as_ref().and_then(|b| profile_from_bytes(b).ok()).filter(|p| p.color_space == space);
|
||||
let embedded = embedded_profile(doc);
|
||||
match embedded {
|
||||
Some(emb) => {
|
||||
let linear_hdr =
|
||||
@@ -579,7 +628,13 @@ impl ColorState {
|
||||
pub fn resolve_open(&self, doc: &mut Document, action: &str) -> Result<()> {
|
||||
match action {
|
||||
"preserve" | "useEmbedded" => Ok(()),
|
||||
"convert" | "convertToWorking" => convert_document(doc, &self.working(doc.mode), self.settings.intent(), self.settings.bpc),
|
||||
// An untagged document already lives in the working space, so converting it to that
|
||||
// space keeps its samples and only tags it (#14224); a tagged one converts from its
|
||||
// embedded profile as before.
|
||||
"convert" | "convertToWorking" => {
|
||||
let untagged = self.untagged_profile(doc);
|
||||
convert_document_from(doc, &untagged, &self.working(doc.mode), self.settings.intent(), self.settings.bpc)
|
||||
}
|
||||
"discard" | "off" => {
|
||||
doc.icc_profile = None;
|
||||
Ok(())
|
||||
@@ -821,6 +876,11 @@ pub fn profile_from_bytes(bytes: &Arc<Vec<u8>>) -> std::result::Result<Arc<Profi
|
||||
Ok(p)
|
||||
}
|
||||
|
||||
/// The document's embedded profile, when it parses and fits its mode.
|
||||
pub(crate) fn embedded_profile(doc: &Document) -> Option<Arc<Profile>> {
|
||||
doc.icc_profile.as_ref().and_then(|b| profile_from_bytes(b).ok()).filter(|p| p.color_space == mode_space(doc.mode))
|
||||
}
|
||||
|
||||
/// The document's profile: its embedded profile when it parses and matches the mode,
|
||||
/// otherwise the mode's working profile.
|
||||
pub fn document_profile(doc: &Document) -> Arc<Profile> {
|
||||
@@ -1155,13 +1215,23 @@ fn paint_colors(p: &mut FxPaint, cc: &mut dyn FnMut(&mut Color)) {
|
||||
/// converted. A Duotone document going to a colour space starts from its ink colours
|
||||
/// ([`ink_duotone`]). The document is tagged with `dst`.
|
||||
pub fn convert_document(doc: &mut Document, dst: &Profile, intent: Intent, bpc: bool) -> Result<()> {
|
||||
let untagged = working_profile(doc.mode);
|
||||
convert_document_from(doc, &untagged, dst, intent, bpc)
|
||||
}
|
||||
|
||||
/// [`convert_document`] with the profile an untagged document is taken in given explicitly: for a
|
||||
/// session that is Color Settings' working space, which the free function cannot know (#14224).
|
||||
/// Only that fallback changes: a document with a usable embedded profile converts from it, read
|
||||
/// after [`ink_duotone`] has turned a Duotone one into sRGB, exactly as [`convert_document`] does.
|
||||
pub fn convert_document_from(doc: &mut Document, untagged: &Profile, dst: &Profile, intent: Intent, bpc: bool) -> Result<()> {
|
||||
let to_mode = space_mode(dst.color_space).ok_or_else(|| EngineError::Other(format!("cannot convert to a {:?} profile", dst.color_space)))?;
|
||||
if to_mode != ColorMode::Grayscale {
|
||||
ink_duotone(doc);
|
||||
}
|
||||
let src = document_profile(doc);
|
||||
let embedded = embedded_profile(doc);
|
||||
let src: &Profile = embedded.as_deref().unwrap_or(untagged);
|
||||
let from_mode = doc.pixel_format().mode;
|
||||
let t = Transform::new(&src, dst, intent, bpc).map_err(cms_err)?;
|
||||
let t = Transform::new(src, dst, intent, bpc).map_err(cms_err)?;
|
||||
let fmt = PixelFormat::new(to_mode, doc.depth, true);
|
||||
crate::image_cmds::for_each_surface(&mut doc.layers, false, &mut |surf, _| {
|
||||
let f = PixelFormat { alpha: surf.format().alpha, ..fmt };
|
||||
@@ -1274,7 +1344,10 @@ pub fn convert_mode(s: &mut Session, mode: ColorMode, p: &Value) -> Result<Value
|
||||
&& doc.icc_profile.as_ref().is_none_or(|bytes| profile_from_bytes(bytes).ok().is_some_and(|p| p.color_space == ColorSpace::Rgb));
|
||||
let dst = match p.get("profile").and_then(Value::as_str) {
|
||||
Some(spec) => s.color().resolve(spec, Some(doc), Some(mode))?,
|
||||
None if preserve_indexed_rgb => document_profile(doc),
|
||||
// Indexed → RGB keeps its samples and its ICC bytes, so the space of the document that
|
||||
// results is its embedded profile, or the working space of Color Settings when it carries
|
||||
// none - the same space the canvas shows it in (#14224).
|
||||
None if preserve_indexed_rgb => embedded_profile(doc).unwrap_or_else(|| s.color().working(ColorMode::Rgb)),
|
||||
None => s.color().working(mode),
|
||||
};
|
||||
if space_mode(dst.color_space)
|
||||
@@ -1288,6 +1361,9 @@ pub fn convert_mode(s: &mut Session, mode: ColorMode, p: &Value) -> Result<Value
|
||||
}
|
||||
let intent = intent_or(p, s.color().settings.intent())?;
|
||||
let bpc = bool_param(p, "bpc", s.color().settings.bpc);
|
||||
// An untagged document starts in Color Settings' working space, the space the canvas shows it
|
||||
// in, not in the mode's built-in default (#14224).
|
||||
let untagged = s.color().untagged_profile(doc);
|
||||
if preserve_indexed_rgb {
|
||||
s.edit("Mode Change", |doc, _| {
|
||||
doc.mode = ColorMode::Rgb;
|
||||
@@ -1296,7 +1372,7 @@ pub fn convert_mode(s: &mut Session, mode: ColorMode, p: &Value) -> Result<Value
|
||||
Ok(())
|
||||
})?;
|
||||
} else {
|
||||
s.edit("Mode Change", |doc, _| convert_document(doc, &dst, intent, bpc))?;
|
||||
s.edit("Mode Change", |doc, _| convert_document_from(doc, &untagged, &dst, intent, bpc))?;
|
||||
}
|
||||
Ok(json!({ "profile": dst.description, "intent": intent.id(), "bpc": bpc }))
|
||||
}
|
||||
@@ -1304,9 +1380,16 @@ pub fn convert_mode(s: &mut Session, mode: ColorMode, p: &Value) -> Result<Value
|
||||
// ------------------------------------------------------------------ gamut
|
||||
|
||||
/// Out-of-gamut mask of the document composite against `setup`'s profile: one byte per
|
||||
/// canvas pixel (255 = out of gamut, transparent pixels never are), plus the count.
|
||||
/// canvas pixel (255 = out of gamut, transparent pixels never are), plus the count. Judged in the
|
||||
/// composite profile of the mode, as the free [`composite_profile`] describes it; a session judges
|
||||
/// in [`ColorState::composite_profile`] instead, the space the canvas shows ([`ColorState::gamut_mask`],
|
||||
/// #14224).
|
||||
pub fn gamut_mask(doc: &Document, setup: &ProofSetup, threshold: f32) -> Result<(Vec<u8>, usize)> {
|
||||
let check = GamutCheck::new(&composite_profile(doc), &setup.profile, threshold).map_err(cms_err)?;
|
||||
gamut_mask_against(doc, &composite_profile(doc), setup, threshold)
|
||||
}
|
||||
|
||||
fn gamut_mask_against(doc: &Document, source: &Profile, setup: &ProofSetup, threshold: f32) -> Result<(Vec<u8>, usize)> {
|
||||
let check = GamutCheck::new(source, &setup.profile, threshold).map_err(cms_err)?;
|
||||
let buf = photocraft_compose::flatten(doc);
|
||||
let mut mask = vec![0u8; buf.px.len()];
|
||||
let count = check.mask_rgba(&buf.px, &mut mask).map_err(cms_err)?;
|
||||
@@ -1468,8 +1551,11 @@ fn convert_to_profile(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// or doesn't fit the mode is still replaced.
|
||||
let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;
|
||||
let measured = matches!(doc.mode, ColorMode::Rgb | ColorMode::Cmyk | ColorMode::Grayscale | ColorMode::Lab);
|
||||
let embedded = doc.icc_profile.as_ref().and_then(|b| profile_from_bytes(b).ok()).filter(|p| p.color_space == mode_space(doc.mode));
|
||||
let embedded = embedded_profile(doc);
|
||||
let same = measured && embedded.is_some_and(|p| p.same_colors(&dst));
|
||||
// The fallback for an untagged document is Color Settings' working space, the space it is
|
||||
// shown in (#14224); a tagged document keeps the embedded profile, as `document_profile` picks.
|
||||
let untagged = s.color().untagged_profile(doc);
|
||||
if same && !flatten && !rasterize {
|
||||
return Ok(json!({ "profile": dst.description, "mode": format!("{:?}", doc.mode), "intent": intent.id(), "bpc": bpc, "converted": false }));
|
||||
}
|
||||
@@ -1487,9 +1573,9 @@ fn convert_to_profile(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
doc.icc_profile = Some(dst.to_bytes());
|
||||
Ok(())
|
||||
} else if dither {
|
||||
profile_dither::convert(doc, &dst, intent, bpc)
|
||||
profile_dither::convert(doc, &untagged, &dst, intent, bpc)
|
||||
} else {
|
||||
convert_document(doc, &dst, intent, bpc)
|
||||
convert_document_from(doc, &untagged, &dst, intent, bpc)
|
||||
}
|
||||
})?;
|
||||
let d = &s.active().ok_or(EngineError::NoDocument)?.doc;
|
||||
@@ -1506,7 +1592,7 @@ fn profile_info(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Some(profile_json(&prof))
|
||||
}
|
||||
None => doc.as_deref().map(|d| {
|
||||
let mut j = profile_json(&document_profile(d));
|
||||
let mut j = profile_json(&s.color().document_profile(d));
|
||||
j["embedded"] = json!(d.icc_profile.is_some());
|
||||
j
|
||||
}),
|
||||
@@ -1555,7 +1641,7 @@ fn gamut_warning(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if let Some(spec) = p.get("profile").and_then(Value::as_str) {
|
||||
setup.profile = resolve_profile(spec, Some(&doc), Some(ColorMode::Cmyk))?;
|
||||
}
|
||||
let (_, count) = gamut_mask(&doc, &setup, threshold)?;
|
||||
let (_, count) = s.color().gamut_mask(&doc, &setup, threshold)?;
|
||||
let total = doc.size.width as usize * doc.size.height as usize;
|
||||
Ok(json!({ "on": on, "profile": setup.profile.description, "threshold": threshold, "outOfGamut": count, "fraction": count as f64 / total.max(1) as f64 }))
|
||||
}
|
||||
@@ -1699,7 +1785,10 @@ fn profile_mismatch(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"convert" | "convertToWorking" => {
|
||||
let dst = s.color().working(mode);
|
||||
let (intent, bpc) = (s.color().settings.intent(), s.color().settings.bpc);
|
||||
s.edit("Convert to Working RGB", |doc, _| convert_document(doc, &dst, intent, bpc))?;
|
||||
// An untagged document answers this dialog in its working space, not in the built-in
|
||||
// default (#14224); a tagged one keeps its embedded profile.
|
||||
let untagged = s.color().untagged_profile(&s.active().ok_or(EngineError::NoDocument)?.doc);
|
||||
s.edit("Convert to Working RGB", |doc, _| convert_document_from(doc, &untagged, &dst, intent, bpc))?;
|
||||
Ok(json!({"action": "converted", "profile": dst.description}))
|
||||
}
|
||||
"discard" | "off" => {
|
||||
@@ -2092,6 +2181,10 @@ mod assign_profile_enabled_modes_tests;
|
||||
#[path = "../color_settings_presets_tests.rs"]
|
||||
mod color_settings_presets_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../color_settings_untagged_display_tests.rs"]
|
||||
mod color_settings_untagged_display_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod settings_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -7,8 +7,8 @@ use photocraft_raster::Tile;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use super::{
|
||||
ColorMode, Document, EngineError, Intent, PixelFormat, Profile, Result, SampleType, Surface, Transform, cms_err, convert_color, convert_document,
|
||||
convert_layer_colors, convert_style_colors, convert_surface, document_profile, space_mode,
|
||||
ColorMode, Document, EngineError, Intent, PixelFormat, Profile, Result, SampleType, Surface, Transform, cms_err, convert_color, convert_document_from,
|
||||
convert_layer_colors, convert_style_colors, convert_surface, embedded_profile, space_mode,
|
||||
};
|
||||
|
||||
const TILE_PIXELS: u128 = (TILE_SIZE * TILE_SIZE) as u128;
|
||||
@@ -149,14 +149,17 @@ fn dither_tile(s: &Surface, out: &Surface, t: &Transform, bounds: Rect, c: TileC
|
||||
}
|
||||
|
||||
/// Preserve ordinary conversion outside opt-in U8, admitting the whole dither edit first.
|
||||
pub(super) fn convert(doc: &mut Document, dst: &Profile, intent: Intent, bpc: bool) -> Result<()> {
|
||||
let src = document_profile(doc);
|
||||
/// `untagged` is the profile an untagged document is taken in: Color Settings' working space,
|
||||
/// which only the session knows (#14224); a tagged document still converts from its embedded one.
|
||||
pub(super) fn convert(doc: &mut Document, untagged: &Profile, dst: &Profile, intent: Intent, bpc: bool) -> Result<()> {
|
||||
let embedded = embedded_profile(doc);
|
||||
let src: &Profile = embedded.as_deref().unwrap_or(untagged);
|
||||
if doc.depth != SampleType::U8 || src.to_bytes() == dst.to_bytes() || doc.mode == ColorMode::Duotone {
|
||||
return convert_document(doc, dst, intent, bpc);
|
||||
return convert_document_from(doc, untagged, dst, intent, bpc);
|
||||
}
|
||||
let to_mode = space_mode(dst.color_space).ok_or_else(|| EngineError::Other(format!("cannot convert to a {:?} profile", dst.color_space)))?;
|
||||
let from = doc.pixel_format().mode;
|
||||
let t = Transform::new(&src, dst, intent, bpc).map_err(cms_err)?;
|
||||
let t = Transform::new(src, dst, intent, bpc).map_err(cms_err)?;
|
||||
let format = PixelFormat::new(to_mode, doc.depth, true);
|
||||
let bounds = doc.bounds();
|
||||
if doc.size.width > i32::MAX as u32 || doc.size.height > i32::MAX as u32 {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//! RAW Defaults output sharpening (#17776).
|
||||
|
||||
use photocraft_algo::camera_raw::CameraRaw;
|
||||
use photocraft_raw::testgen::{DngSpec, mosaic};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::prefs::{RawColorSpace, RawSharpen, RawSharpenAmount, SavedPrefsExt};
|
||||
use crate::{Session, file_cmds};
|
||||
|
||||
#[test]
|
||||
fn saved_media_keep_their_existing_strength_without_an_amount() {
|
||||
for (medium, expected) in [("none", None), ("screen", Some((25.0, 1.0))), ("glossy", Some((40.0, 1.0))), ("matte", Some((35.0, 1.2)))] {
|
||||
let mut s = crate::session();
|
||||
let saved = json!({"rawDefaults": {"sharpenFor": medium}});
|
||||
assert!(s.load_prefs_json(&saved.to_string()).unwrap().is_empty());
|
||||
let defaults = &s.prefs().raw_defaults;
|
||||
assert_eq!(defaults.sharpen_amount, RawSharpenAmount::Standard);
|
||||
let mut settings = CameraRaw::default();
|
||||
assert_eq!(defaults.apply_output_sharpening(&mut settings), expected.is_some());
|
||||
if let Some(pair) = expected {
|
||||
assert_eq!((settings.sharpen_amount, settings.sharpen_radius), pair);
|
||||
} else {
|
||||
assert_eq!(settings, CameraRaw::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefs_set_rejects_unknown_sharpening_amounts_and_keeps_the_previous_choice() {
|
||||
let mut s = crate::session();
|
||||
let path = "rawDefaults.sharpenAmount";
|
||||
for valid in ["low", "standard", "high"] {
|
||||
s.execute("prefs.set", json!({"path":path, "value":valid})).unwrap();
|
||||
assert_eq!(s.execute("prefs.get", json!({"path":path})).unwrap(), json!(valid));
|
||||
}
|
||||
for invalid in [json!("medium"), json!(25)] {
|
||||
let err = s.execute("prefs.set", json!({"path":path, "value":invalid})).unwrap_err();
|
||||
assert!(err.to_string().contains(path), "{err}");
|
||||
assert_eq!(s.prefs().raw_defaults.sharpen_amount, RawSharpenAmount::High);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_detail_sharpening_takes_precedence_over_output_sharpening() {
|
||||
let mut s = crate::session();
|
||||
s.execute("prefs.set", json!({"values":{"rawDefaults.sharpenFor":"matte","rawDefaults.sharpenAmount":"high"}})).unwrap();
|
||||
let mut detail = CameraRaw::default();
|
||||
detail.sharpen_amount = 12.0;
|
||||
detail.sharpen_radius = 2.0;
|
||||
let mut settings = detail.clone();
|
||||
assert!(!s.prefs().raw_defaults.apply_output_sharpening(&mut settings));
|
||||
assert_eq!(settings, detail);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quiet_raw_sharpening_levels_order_the_pixel_change_from_unsharpened() {
|
||||
let (w, h) = (24, 16);
|
||||
// Keep the edge away from clipping so each change in strength can affect the pixels.
|
||||
let scene: Vec<_> = (0..w * h).map(|i| if i % w < w / 2 { [0.20; 3] } else { [0.32; 3] }).collect();
|
||||
let raw = DngSpec::cfa(w, h, mosaic(&scene, w, [0, 1, 1, 2], 0, 65535)).build();
|
||||
let open = |medium, amount| {
|
||||
let mut s = crate::session();
|
||||
s.execute("edit.colorSettings", json!({"askOnMismatch":false,"askOnMissing":false})).unwrap();
|
||||
let mut defaults = s.prefs().raw_defaults.clone();
|
||||
defaults.color_space = RawColorSpace::ProPhoto;
|
||||
defaults.sharpen_for = medium;
|
||||
defaults.sharpen_amount = amount;
|
||||
s.batch_raw_open = Some(defaults);
|
||||
file_cmds::open_bytes_as(&mut s, "IMG_0001.dng", &raw, None, None).unwrap();
|
||||
s
|
||||
};
|
||||
let pixels = |s: &Session| {
|
||||
let doc = &s.active().unwrap().doc;
|
||||
photocraft_compose::render(doc, doc.bounds())
|
||||
};
|
||||
let off = open(RawSharpen::None, RawSharpenAmount::High);
|
||||
let unsharpened = pixels(&off);
|
||||
let distance = |developed: &[[f32; 4]]| developed.iter().flatten().zip(unsharpened.px.iter().flatten()).map(|(a, b)| f64::from((a - b).abs())).sum::<f64>();
|
||||
let [low, standard, high] =
|
||||
[RawSharpenAmount::Low, RawSharpenAmount::Standard, RawSharpenAmount::High].map(|amount| pixels(&open(RawSharpen::Screen, amount)));
|
||||
let (low_distance, standard_distance, high_distance) = (distance(&low.px), distance(&standard.px), distance(&high.px));
|
||||
assert!(0.0 < low_distance && low_distance < standard_distance && standard_distance < high_distance);
|
||||
|
||||
let mut previous = off;
|
||||
previous.execute("filter.cameraRaw", json!({"sharpenAmount":25.0,"sharpenRadius":1.0})).unwrap();
|
||||
assert_eq!(standard.px.as_slice(), pixels(&previous).px.as_slice());
|
||||
}
|
||||
@@ -112,12 +112,7 @@ pub(super) fn prepare(s: &Session, name: &str, shown: &str, path: Option<&str>,
|
||||
settings.tint = 0.0;
|
||||
}
|
||||
}
|
||||
if let Some((amount, radius)) = defaults.sharpen_for.preset()
|
||||
&& settings.sharpen_amount == 0.0
|
||||
{
|
||||
settings.sharpen_amount = amount;
|
||||
settings.sharpen_radius = radius;
|
||||
}
|
||||
defaults.apply_output_sharpening(&mut settings);
|
||||
Ok(Some((imported, settings)))
|
||||
}
|
||||
|
||||
@@ -148,3 +143,7 @@ pub(super) fn finish(s: &mut Session, settings: CameraRaw) -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "raw_defaults_sharpen_tests.rs"]
|
||||
mod raw_defaults_sharpen_tests;
|
||||
@@ -112,8 +112,12 @@ pub(crate) fn adapt_copies(s: &Session, copies: &mut Document, dest: &Document)
|
||||
}
|
||||
}
|
||||
if (copies.mode, &copies.icc_profile) != (dest.mode, &dest.icc_profile) {
|
||||
let profile = crate::color_cmds::document_profile(dest);
|
||||
crate::color_cmds::convert_document(copies, &profile, s.color().settings.intent(), s.color().settings.bpc)?;
|
||||
// Both sides are read as the session reads them: an untagged document, source or
|
||||
// destination, is taken in its working space (#14224), so the copies keep their look on
|
||||
// the destination's canvas instead of landing as raw numbers.
|
||||
let untagged = s.color().untagged_profile(copies);
|
||||
let profile = s.color().document_profile(dest);
|
||||
crate::color_cmds::convert_document_from(copies, &untagged, &profile, s.color().settings.intent(), s.color().settings.bpc)?;
|
||||
}
|
||||
if copies.depth != dest.depth {
|
||||
crate::image_cmds::for_each_surface(&mut copies.layers, true, &mut |surf, _| {
|
||||
|
||||
@@ -967,6 +967,182 @@ fn merging_keeps_layer_effects_outside_the_pixels() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_down_keeps_the_lower_layers_style_live_on_the_union() {
|
||||
// Merge Down over a styled layer keeps its style live, as in Photoshop, where it
|
||||
// re-composes over the merged pixels: the glow that only surrounded the lower layer now
|
||||
// surrounds the union of both layers' content.
|
||||
let probe = |s: &Session| {
|
||||
let d = doc(s);
|
||||
photocraft_compose::render(d, d.bounds()).get(75, 26)
|
||||
};
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30));
|
||||
let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32));
|
||||
s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap();
|
||||
let before = probe(&s);
|
||||
assert!(before.iter().all(|v| *v > 0.9), "depth {depth}: the glow never reaches the probe before the merge: {before:?}");
|
||||
s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap();
|
||||
let merged = doc(&s).layer(lower).unwrap().clone();
|
||||
assert!(doc(&s).layer(upper).is_none());
|
||||
assert_eq!(merged.effects.items.len(), 1);
|
||||
assert!(merged.effects.items.iter().all(photocraft_doc::Effect::enabled), "the style stays live on the merged layer");
|
||||
let after = probe(&s);
|
||||
assert!(
|
||||
after.iter().take(3).zip(&before).all(|(a, b)| *a < *b - 0.03),
|
||||
"depth {depth}: the glow re-applies to the merged union: {before:?} -> {after:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_down_inherits_the_lower_layers_fill_opacity() {
|
||||
// Photoshop inherits the fill onto the merged layer (fixtures in PR #8750): merging onto a
|
||||
// Fill-0% lower layer keeps the union ink in the pixels but invisible, and only the live
|
||||
// style — re-rendered around the union — shows. The property is not reset to opaque.
|
||||
let ink = |s: &Session| {
|
||||
let d = doc(s);
|
||||
photocraft_compose::render(d, d.bounds()).get(66, 26)
|
||||
};
|
||||
let glow = |s: &Session| {
|
||||
let d = doc(s);
|
||||
photocraft_compose::render(d, d.bounds()).get(75, 26)
|
||||
};
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30));
|
||||
let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32));
|
||||
s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap();
|
||||
s.edit("zero fill", |doc, _| {
|
||||
doc.layer_mut(lower).unwrap().fill_opacity = 0.0;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let before_ink = ink(&s);
|
||||
let before_glow = glow(&s);
|
||||
s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap();
|
||||
let merged = doc(&s).layer(lower).unwrap().clone();
|
||||
assert_eq!(merged.fill_opacity, 0.0, "depth {depth}: the fill inherits onto the merged layer");
|
||||
assert_eq!(merged.effects.items.len(), 1, "depth {depth}: the style stays live");
|
||||
let after_ink = ink(&s);
|
||||
assert!(after_ink.iter().take(3).all(|v| *v > 0.9), "depth {depth}: the inherited zero fill hides the union ink: {before_ink:?} -> {after_ink:?}");
|
||||
let after_glow = glow(&s);
|
||||
assert!(
|
||||
after_glow.iter().take(3).zip(&before_glow).all(|(a, b)| *a < *b - 0.03),
|
||||
"depth {depth}: the glow re-renders around the invisible union: {before_glow:?} -> {after_glow:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_down_applies_the_inherited_fill_to_the_baked_ink() {
|
||||
// Observed in Photoshop (fixtures in PR #8750: each layer holds one opaque circle and one
|
||||
// painted at 50% brush opacity). Merge Down bakes the visible pixels — with the lower
|
||||
// layer's Fill already applied — onto the merged layer, and the merged layer inherits that
|
||||
// same Fill, so the lower content is attenuated twice: at Fill 50% the opaque circle lands
|
||||
// on a quarter (0.5 × 0.5) and the half-transparent one on an eighth, while the upper
|
||||
// circles stay at half and a quarter. At Fill 0% the lower ink is already empty when baked
|
||||
// and the rest leaves the composite through the inherited fill — as in the fixtures, where
|
||||
// the lower shape and its glow vanish; at Fill 100% the merge changes nothing visible.
|
||||
let alpha_at = |s: &Session, x: i32, y: i32| {
|
||||
let d = doc(s);
|
||||
photocraft_compose::render(d, d.bounds()).get(x, y)[3]
|
||||
};
|
||||
let alphas = |s: &Session| [alpha_at(s, 30, 30), alpha_at(s, 30, 80), alpha_at(s, 130, 30), alpha_at(s, 130, 80)];
|
||||
let close = |got: &[f32; 4], want: [f32; 4]| got.iter().zip(&want).all(|(g, w)| (g - w).abs() < 0.01);
|
||||
let (all, top_only) = (Rect::new(10, 10, 150, 100), Rect::new(110, 10, 150, 100));
|
||||
// (Fill, alpha of [lower opaque, lower half, upper opaque, upper half] after the merge,
|
||||
// the ink baked into the merged layer)
|
||||
let cases = [(1.0f32, [1.0, 0.5, 1.0, 0.5], all), (0.5, [0.25, 0.125, 0.5, 0.25], all), (0.0, [0.0; 4], top_only)];
|
||||
for (fill, after, baked) in cases {
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 160, "height": 120, "depth": depth, "background": "transparent"})).unwrap();
|
||||
let lower = rect_layer(&mut s, Rect::new(10, 10, 50, 50));
|
||||
let upper = rect_layer(&mut s, Rect::new(110, 10, 150, 50));
|
||||
let half = |s: &mut Session, id: LayerId, r: Rect| {
|
||||
s.edit("half", |doc, _| {
|
||||
doc.layer_mut(id).unwrap().surface_mut().unwrap().fill_rect(r, &[0.0, 0.0, 1.0, 0.5]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
half(&mut s, lower, Rect::new(10, 60, 50, 100));
|
||||
half(&mut s, upper, Rect::new(110, 60, 150, 100));
|
||||
s.edit("fill", |doc, _| {
|
||||
doc.layer_mut(lower).unwrap().fill_opacity = fill;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let before = alphas(&s);
|
||||
assert!(
|
||||
close(&before, [fill, fill * 0.5, 1.0, 0.5]),
|
||||
"depth {depth}, fill {fill}: the lower layer's own fill attenuates it once before the merge: {before:?}"
|
||||
);
|
||||
let layers_before = doc(&s).layer_count();
|
||||
s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap();
|
||||
let merged = doc(&s).layer(lower).unwrap().clone();
|
||||
assert!(doc(&s).layer(upper).is_none(), "depth {depth}, fill {fill}: the upper layer merged down");
|
||||
assert_eq!(doc(&s).layer_count(), layers_before - 1, "depth {depth}, fill {fill}: the merge took one layer");
|
||||
assert_eq!(merged.fill_opacity, fill, "depth {depth}, fill {fill}: the fill inherits onto the merged layer");
|
||||
assert_eq!(layer_bounds(&merged).unwrap(), baked, "depth {depth}, fill {fill}: the merge bakes the visible pixels of both layers");
|
||||
let got = alphas(&s);
|
||||
assert!(close(&got, after), "depth {depth}, fill {fill}: the inherited fill applies to the baked ink again: {got:?}, want {after:?}");
|
||||
s.undo();
|
||||
assert_eq!(doc(&s).layer_count(), layers_before, "depth {depth}, fill {fill}: undo brings both layers back");
|
||||
assert!(doc(&s).layer(upper).is_some(), "depth {depth}, fill {fill}: undo restores the upper layer");
|
||||
assert_eq!(doc(&s).layer(lower).unwrap().fill_opacity, fill, "depth {depth}, fill {fill}: undo restores the fill");
|
||||
assert!(close(&alphas(&s), before), "depth {depth}, fill {fill}: undo restores the composite");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_selected_layers_bakes_the_bottom_layers_style_to_pixels() {
|
||||
// Observed in Photoshop (fixtures in PR #8750): ⌘E over a selection merges the selected
|
||||
// layers preserving the visible composite — the bottommost layer's style is baked into
|
||||
// the merged pixels and no longer carried as a live effect, so it keeps drawing only
|
||||
// around its own shape and never wraps the upper layers' content.
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
let lower = rect_layer(&mut s, Rect::new(10, 10, 30, 30));
|
||||
let upper = rect_layer(&mut s, Rect::new(60, 20, 72, 32));
|
||||
s.execute("layer.layerStyle.outerGlow", json!({"layer": lower.0, "blend": "normal", "size": 6, "color": "#000000", "add": true})).unwrap();
|
||||
let before = photocraft_compose::render(doc(&s), doc(&s).bounds());
|
||||
select_all(&mut s, &[lower, upper]);
|
||||
let m = LayerId(s.execute("layer.mergeLayers", json!({})).unwrap()["layer"].as_u64().unwrap());
|
||||
assert!(doc(&s).layer(m).unwrap().effects.items.is_empty(), "depth {depth}: Merge Layers drops the style");
|
||||
let after = photocraft_compose::render(doc(&s), doc(&s).bounds());
|
||||
let worst = before.px.iter().zip(&after.px).map(|(a, b)| a.iter().zip(b).map(|(x, y)| (x - y).abs()).fold(0.0f32, f32::max)).fold(0.0f32, f32::max);
|
||||
assert!(worst <= 1.5 / 255.0, "depth {depth}: Merge Layers preserves the visible composite (off by {worst})");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_down_inside_the_shaped_layer_is_a_pixel_match() {
|
||||
// With the upper layer fully inside the lower one's shape, the union is the same shape, so
|
||||
// a correct merge is a pixel-for-pixel match: the style is neither lost, nor applied
|
||||
// twice, and Global Light follows the document instead of `Document::new` defaults.
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = session(depth);
|
||||
let lower = rect_layer(&mut s, Rect::new(10, 10, 60, 60));
|
||||
let upper = rect_layer(&mut s, Rect::new(25, 25, 45, 45));
|
||||
s.edit("light", |doc, _| {
|
||||
doc.global_light = photocraft_doc::GlobalLight { angle: 20.0, altitude: 40.0 };
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("layer.layerStyle.dropShadow", json!({"layer": lower.0, "blend": "normal", "useGlobalLight": true, "angle": 120, "distance": 5, "spread": 0, "size": 0, "opacity": 100, "color": "#000000"})).unwrap();
|
||||
let before = photocraft_compose::render(doc(&s), doc(&s).bounds());
|
||||
s.execute("layer.mergeDown", json!({"layer": upper.0})).unwrap();
|
||||
assert!(!doc(&s).layer(lower).unwrap().effects.items.is_empty());
|
||||
let after = photocraft_compose::render(doc(&s), doc(&s).bounds());
|
||||
let worst = before.px.iter().zip(&after.px).map(|(a, b)| a.iter().zip(b).map(|(x, y)| (x - y).abs()).fold(0.0f32, f32::max)).fold(0.0f32, f32::max);
|
||||
assert!(worst <= 1.5 / 255.0, "depth {depth}: merge down changed the composite (off by {worst})");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merging_a_group_down_preserves_the_composite() {
|
||||
for depth in [8, 16, 32] {
|
||||
|
||||
@@ -357,7 +357,9 @@ fn parse_dither(s: &str) -> Option<Dither> {
|
||||
/// grayscale output is a scalar sample replicated into the flattened RGB view.
|
||||
fn working_matte_color(s: &Session, doc: &Document, color: [f32; 4]) -> Result<[f32; 3]> {
|
||||
let destination = match crate::color_cmds::mode_space(doc.mode) {
|
||||
ColorSpace::Rgb | ColorSpace::Gray => crate::color_cmds::document_profile(doc),
|
||||
// An untagged RGB or Grayscale document is taken in Color Settings' working space (#14224),
|
||||
// which is where the tool colour above already lives.
|
||||
ColorSpace::Rgb | ColorSpace::Gray => s.color().document_profile(doc),
|
||||
// CMYK and Lab flatten through the compositor's sRGB view on the pinned main path.
|
||||
_ => crate::color_cmds::composite_profile(doc),
|
||||
};
|
||||
|
||||
@@ -298,10 +298,12 @@ fn parse_color(p: &Value) -> [f32; 3] {
|
||||
}
|
||||
}
|
||||
|
||||
/// Composite RGB (the compositor's output profile for the document) → CIE Lab D50.
|
||||
/// Composite RGB (the profile the session shows the document's composite in) → CIE Lab D50.
|
||||
fn lab_transform(s: &Session) -> Result<std::sync::Arc<craft_cms::Transform>> {
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let src = crate::color_cmds::composite_profile(&d.doc);
|
||||
// An untagged document's composite is the working space (#14224), so the hue rows and the
|
||||
// sampled colours select what the canvas actually shows.
|
||||
let src = s.color().composite_profile(&d.doc);
|
||||
craft_cms::cached(&src, craft_cms::Builtin::LabD50.profile(), craft_cms::TransformOptions::default())
|
||||
.map_err(|e| EngineError::Other(format!("colour management: {e}")))
|
||||
}
|
||||
@@ -553,10 +555,11 @@ fn color_range(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
"outOfGamut" => {
|
||||
// Pixels the current proof setup (View › Proof Setup) can't reproduce, as the gamut
|
||||
// warning shows them: judged on the composite.
|
||||
// warning shows them: judged on the composite, in the space the canvas shows it in
|
||||
// (#14224), so the selection marks the same pixels the warning marks.
|
||||
let d = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let pv = s.color().proof(d.doc.id);
|
||||
let (m, _) = crate::color_cmds::gamut_mask(&d.doc, &pv.setup, pv.gamut_threshold)?;
|
||||
let (m, _) = s.color().gamut_mask(&d.doc, &pv.setup, pv.gamut_threshold)?;
|
||||
(d.doc.bounds(), m.iter().map(|v| f32::from(*v) / 255.0).collect())
|
||||
}
|
||||
other => {
|
||||
|
||||
@@ -25,7 +25,10 @@ fn contents(s: &Session, doc: &Document, sm: &SmartObject, intent: Intent, bpc:
|
||||
let mut src = decode_source(&name, &bytes)?;
|
||||
let mode = doc.pixel_format().mode;
|
||||
if src.pixel_format().mode != mode || src.icc_profile != doc.icc_profile {
|
||||
crate::color_cmds::convert_document(&mut src, &crate::color_cmds::document_profile(doc), intent, bpc)?;
|
||||
// An untagged document is taken in its working space (#14224): the contents are re-encoded
|
||||
// into that space so they keep their look once they are layers on this canvas.
|
||||
let destination = s.color().document_profile(doc);
|
||||
crate::color_cmds::convert_document(&mut src, &destination, intent, bpc)?;
|
||||
if src.pixel_format().mode != mode {
|
||||
return Err(other(format!("can't convert the smart object's contents to the document's {:?} mode", doc.mode)));
|
||||
}
|
||||
|
||||
@@ -465,22 +465,69 @@ fn split_csv(line: &str, delim: u8) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// Apply each data set in turn and export the flattened document, restoring the original after.
|
||||
/// `{dir, format?("png"), dataSets?[names]}` → `{files:[…],count}`.
|
||||
/// `{dir, format?("png"), dataSets?[names], missingImage?, start?}` → `{files:[…],count,skipped?,stopped?}`.
|
||||
fn export_as_files(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let dir = p.get("dir").and_then(Value::as_str).ok_or_else(|| bad("file.export.dataSetsAsFiles", "need `dir`"))?.to_string();
|
||||
// The directory appears only once the batch has been planned, as it always did, so a batch
|
||||
// rejected for colliding names still leaves no directory behind.
|
||||
let mut made_dir = false;
|
||||
let names = export_data_sets_with(s, p, |name, bytes| {
|
||||
let report = export_data_sets_report_with(s, p, |name, bytes| {
|
||||
if !made_dir {
|
||||
std::fs::create_dir_all(&dir).map_err(|e| EngineError::Other(format!("mkdir `{dir}`: {e}")))?;
|
||||
made_dir = true;
|
||||
}
|
||||
crate::file_cmds::write_file(&format!("{dir}/{name}"), bytes)
|
||||
})?;
|
||||
let files: Vec<String> = names.iter().map(|name| format!("{dir}/{name}")).collect();
|
||||
let count = files.len();
|
||||
Ok(json!({"files": files, "count": count}))
|
||||
let files: Vec<String> = report.files.iter().map(|name| format!("{dir}/{name}")).collect();
|
||||
Ok(report.json(files))
|
||||
}
|
||||
|
||||
/// What a data-set export with a `missingImage` mode does when a set's Pixel Replacement image
|
||||
/// does not exist (#13767).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum MissingImage {
|
||||
/// The export ends with the missing-file error; the files written before it stay (the default).
|
||||
Error,
|
||||
/// The set is left out, listed in `skipped`, and the export goes on.
|
||||
Skip,
|
||||
/// The export ends without an error at that set; the result names it in `stopped`.
|
||||
Stop,
|
||||
}
|
||||
|
||||
/// The data set a `missingImage: "stop"` export stopped at: its name, its 0-based position in the
|
||||
/// batch (the `start` that resumes after it is `index + 1`), how many sets come after it and the
|
||||
/// missing-file error it would have ended with.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct StoppedDataSet {
|
||||
pub name: String,
|
||||
pub index: usize,
|
||||
pub remaining: usize,
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
/// What a data-set export did: the filenames written, in order, the sets left out for a missing
|
||||
/// replacement image (`missingImage: "skip"`) and the set a `"stop"` export stopped at.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct DataSetsExportReport {
|
||||
pub files: Vec<String>,
|
||||
pub skipped: Vec<String>,
|
||||
pub stopped: Option<StoppedDataSet>,
|
||||
}
|
||||
|
||||
impl DataSetsExportReport {
|
||||
/// The command's result, with `files` as the caller names them (joined to its folder).
|
||||
pub fn json(&self, files: Vec<String>) -> Value {
|
||||
let count = files.len();
|
||||
let mut out = json!({"files": files, "count": count});
|
||||
// Listed only when a set was left out, so an export without a missing image reads as before.
|
||||
if !self.skipped.is_empty() {
|
||||
out["skipped"] = json!(self.skipped);
|
||||
}
|
||||
if let Some(stop) = &self.stopped {
|
||||
out["stopped"] = json!({"name": stop.name, "index": stop.index, "remaining": stop.remaining, "error": stop.error});
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// The bodies of `file.export.dataSetsAsFiles`, streamed to `write` as a single-component
|
||||
@@ -488,8 +535,30 @@ fn export_as_files(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
/// so colliding names are rejected before any file is written, and automation writes exactly
|
||||
/// these bytes beneath its write root (#3216) — the two paths cannot drift. Returns the
|
||||
/// filenames written, in order.
|
||||
pub fn export_data_sets_with(s: &Session, p: &Value, mut write: impl FnMut(&str, &[u8]) -> Result<()>) -> Result<Vec<String>> {
|
||||
pub fn export_data_sets_with(s: &Session, p: &Value, write: impl FnMut(&str, &[u8]) -> Result<()>) -> Result<Vec<String>> {
|
||||
export_data_sets_report_with(s, p, write).map(|report| report.files)
|
||||
}
|
||||
|
||||
/// [`export_data_sets_with`] that also says which sets a missing replacement image left out or
|
||||
/// stopped at (`missingImage`, #13767). `start` resumes a batch at that 0-based position: the
|
||||
/// sets before it are not written, and `{index}` keeps counting from the first set.
|
||||
pub fn export_data_sets_report_with(s: &Session, p: &Value, mut write: impl FnMut(&str, &[u8]) -> Result<()>) -> Result<DataSetsExportReport> {
|
||||
let format = p.get("format").and_then(Value::as_str).unwrap_or("png");
|
||||
let missing = match p.get("missingImage") {
|
||||
None | Some(Value::Null) => MissingImage::Error,
|
||||
Some(v) => match v.as_str() {
|
||||
Some("error") => MissingImage::Error,
|
||||
Some("skip") => MissingImage::Skip,
|
||||
Some("stop") => MissingImage::Stop,
|
||||
_ => return Err(bad("file.export.dataSetsAsFiles", "`missingImage` must be \"error\", \"skip\" or \"stop\"")),
|
||||
},
|
||||
};
|
||||
let start = match p.get("start") {
|
||||
None | Some(Value::Null) => 0,
|
||||
Some(v) => {
|
||||
v.as_u64().and_then(|n| usize::try_from(n).ok()).ok_or_else(|| bad("file.export.dataSetsAsFiles", "`start` must be a whole number from 0"))?
|
||||
}
|
||||
};
|
||||
let st = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let original = st.doc.clone();
|
||||
let vars = original.variables.clone();
|
||||
@@ -498,6 +567,9 @@ pub fn export_data_sets_with(s: &Session, p: &Value, mut write: impl FnMut(&str,
|
||||
if sets.is_empty() {
|
||||
return Err(bad("file.export.dataSetsAsFiles", "no data sets to export"));
|
||||
}
|
||||
if start >= sets.len() {
|
||||
return Err(bad("file.export.dataSetsAsFiles", format!("`start` {start} is past the last of {} data sets", sets.len())));
|
||||
}
|
||||
// Judge every image path before anything is written, as Apply Data Set does.
|
||||
for set in &sets {
|
||||
authorize_pixel_paths(s, set)?;
|
||||
@@ -538,17 +610,30 @@ pub fn export_data_sets_with(s: &Session, p: &Value, mut write: impl FnMut(&str,
|
||||
}
|
||||
names.push(name);
|
||||
}
|
||||
let mut written = Vec::new();
|
||||
for (set, name) in sets.iter().zip(&names) {
|
||||
let mut report = DataSetsExportReport::default();
|
||||
for (n, (set, name)) in sets.iter().zip(&names).enumerate().skip(start) {
|
||||
let mut doc = (*original).clone();
|
||||
apply_to_doc(&mut doc, &vars, set)?;
|
||||
match apply_to_doc(&mut doc, &vars, set) {
|
||||
Ok(()) => {}
|
||||
// Only a replacement file that does not exist: one that can't be read or decoded is
|
||||
// still an error in every mode.
|
||||
Err(EngineError::Other(m)) if missing != MissingImage::Error && m.starts_with(DATA_SET_FILE_MISSING) => {
|
||||
if missing == MissingImage::Skip {
|
||||
report.skipped.push(set.name.clone());
|
||||
continue;
|
||||
}
|
||||
report.stopped = Some(StoppedDataSet { name: set.name.clone(), index: n, remaining: sets.len() - n - 1, error: m });
|
||||
break;
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
// An untrusted session's PSD export embeds no file a linked smart object names.
|
||||
let opts = photocraft_io::ExportOptions { read_linked_files: s.authorize.is_none(), ..Default::default() };
|
||||
let bytes = photocraft_io::export(&doc, format, &opts).map(|r| r.bytes).map_err(|e| EngineError::Other(format!("export `{}`: {e}", set.name)))?;
|
||||
write(name, &bytes)?;
|
||||
written.push(name.clone());
|
||||
report.files.push(name.clone());
|
||||
}
|
||||
Ok(written)
|
||||
Ok(report)
|
||||
}
|
||||
|
||||
fn list(s: &mut Session) -> Result<Value> {
|
||||
@@ -612,7 +697,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"file.export.dataSetsAsFiles",
|
||||
"Data Sets as Files…",
|
||||
&["File", "Export"],
|
||||
"{dir, format?:png, dataSets?[names], naming?:\"{name}|{index}|{document}\"} → {files,count}: apply each data set and export the flattened document; colliding filenames are rejected before writing (include {index} to disambiguate)",
|
||||
"{dir, format?:png, dataSets?[names], naming?:\"{name}|{index}|{document}\", missingImage?:error|skip|stop, start?:n} → {files,count,skipped?,stopped?:{name,index,remaining,error}}: apply each data set and export the flattened document; colliding filenames are rejected before writing (include {index} to disambiguate). A set whose Pixel Replacement image does not exist ends the export with an error (missingImage error, the default), is left out and listed in `skipped` (skip), or ends the export without an error, named in `stopped` (stop); `start` resumes at that 0-based set, keeping {index}",
|
||||
has_data_sets,
|
||||
|s, p| export_as_files(s, p)
|
||||
),
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
//! #14224: an untagged document is displayed in the working space of Edit > Color Settings, not
|
||||
//! always in the mode's built-in default, and a change of that space refreshes an open document.
|
||||
//!
|
||||
//! The checks are relative: what the canvas must show is the transform our own engine builds for
|
||||
//! the profile Color Settings names ([`ColorState::working`]) to the monitor the session resolves,
|
||||
//! evaluated in this file. The reference application's absolute numbers for ProPhoto working RGB
|
||||
//! are its profile's tables, so they are reported rather than asserted here.
|
||||
//!
|
||||
//! Untagged documents only: a tagged one keeps its embedded profile, and CMYK keeps today's
|
||||
//! display (the issue leaves it unmeasured).
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::Size;
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
use crate::display_color::{DISPLAY_BPC, DISPLAY_INTENT};
|
||||
|
||||
/// Tolerance of the CPU canvas path against the transform evaluated here (8-bit quantisation plus
|
||||
/// table evaluation), as in `display_color/tests.rs`.
|
||||
const TOL: f32 = 2.0;
|
||||
|
||||
/// An untagged RGB document: one 4x4 block per entry of `values`, in columns.
|
||||
fn untagged_rgb(values: &[[f32; 3]], depth: SampleType) -> Document {
|
||||
let fmt = PixelFormat::new(ColorMode::Rgb, depth, true);
|
||||
let mut d = Document::new("t", Size::new(values.len() as u32 * 4, 4), ColorMode::Rgb, depth);
|
||||
let mut surf = Surface::new(fmt);
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
let x = i as i32 * 4;
|
||||
surf.fill_rect(Rect::new(x, 0, x + 4, 4), &[v[0], v[1], v[2], 1.0]);
|
||||
}
|
||||
d.layers.push(Layer::new("pixels", LayerContent::Raster(surf)));
|
||||
d
|
||||
}
|
||||
|
||||
/// An RGB document tagged with `tag`.
|
||||
fn tagged_rgb(tag: &Profile, v: [f32; 3]) -> Document {
|
||||
let mut d = Document::with_background("t", Size::new(8, 8), ColorMode::Rgb, SampleType::U8, Color::rgb(v[0], v[1], v[2]));
|
||||
d.icc_profile = Some(tag.to_bytes());
|
||||
d
|
||||
}
|
||||
|
||||
/// An untagged Grayscale document.
|
||||
fn untagged_gray(v: f32) -> Document {
|
||||
Document::with_background("g", Size::new(8, 8), ColorMode::Grayscale, SampleType::U8, Color::gray(v))
|
||||
}
|
||||
|
||||
/// A two-layer untagged CMYK document, so the composite goes through the compositor.
|
||||
fn untagged_cmyk(ink: [f32; 4]) -> Document {
|
||||
let fmt = PixelFormat::new(ColorMode::Cmyk, SampleType::U8, true);
|
||||
let mut d = Document::new("c", Size::new(8, 8), ColorMode::Cmyk, SampleType::U8);
|
||||
let mut surf = Surface::new(fmt);
|
||||
surf.fill_rect(Rect::new(0, 0, 8, 8), &[ink[0], ink[1], ink[2], ink[3], 1.0]);
|
||||
d.layers.push(Layer::new("ink", LayerContent::Raster(surf)));
|
||||
d.layers.push(Layer::new("empty", LayerContent::Raster(Surface::new(fmt))));
|
||||
d
|
||||
}
|
||||
|
||||
/// What the CPU canvas shows in the middle of column `i` of `d`, in 8-bit codes.
|
||||
fn shown(s: &Session, d: &Document, i: usize) -> [f32; 3] {
|
||||
let buf = photocraft_compose::flatten(d);
|
||||
let img = s.color().canvas_display(d).unwrap().to_rgba8(&buf);
|
||||
let x = (i as u32 * 4 + 2).min(d.size.width - 1);
|
||||
let y = d.size.height / 2;
|
||||
let k = (y as usize * d.size.width as usize + x as usize) * 4;
|
||||
[0, 1, 2].map(|c| img.pixels[k + c] as f32)
|
||||
}
|
||||
|
||||
/// The transform our engine builds from `src` to the session's monitor, evaluated at `v`: what the
|
||||
/// canvas has to show. Returns 8-bit codes.
|
||||
fn shown_want(s: &Session, src: &Profile, v: &[f32]) -> [f32; 3] {
|
||||
let monitor = s.color().monitor();
|
||||
let t = Transform::new(src, &monitor, DISPLAY_INTENT, DISPLAY_BPC).unwrap();
|
||||
let mut out = [0.0f32; 16];
|
||||
t.eval(v, &mut out).unwrap();
|
||||
let n = t.outputs();
|
||||
[0, 1, 2].map(|c| out[if n == 1 { 0 } else { c }].clamp(0.0, 1.0) * 255.0)
|
||||
}
|
||||
|
||||
fn close(a: [f32; 3], b: [f32; 3], tol: f32) -> bool {
|
||||
(0..3).all(|i| (a[i] - b[i]).abs() <= tol)
|
||||
}
|
||||
|
||||
fn far(a: [f32; 3], b: [f32; 3], d: f32) -> bool {
|
||||
(0..3).any(|i| (a[i] - b[i]).abs() >= d)
|
||||
}
|
||||
|
||||
fn raw_codes(v: &[f32]) -> [f32; 3] {
|
||||
[0, 1, 2].map(|c| v[c] * 255.0)
|
||||
}
|
||||
|
||||
/// The document's description as `edit.profileInfo` reports it.
|
||||
fn reported(s: &mut Session) -> Value {
|
||||
s.execute("edit.profileInfo", json!({})).unwrap()["profile"].clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_untagged_rgb_document_is_displayed_in_the_working_space() {
|
||||
let mut s = crate::session();
|
||||
// The ticket's fixture: 200,30,30 and 30,60,200, profile removed.
|
||||
let values = [[200.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0], [30.0 / 255.0, 60.0 / 255.0, 200.0 / 255.0]];
|
||||
let d = untagged_rgb(&values, SampleType::U8);
|
||||
// Unchanged with the default settings: sRGB working RGB means the values go to the screen.
|
||||
let first = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(first.source.description, Builtin::Srgb.profile().description, "the default working space is sRGB");
|
||||
assert!(first.is_identity(), "sRGB on an sRGB monitor still costs nothing");
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let working = s.color().working(ColorMode::Rgb);
|
||||
assert_eq!(working.description, Builtin::ProPhotoCompat.profile().description, "the setting resolved");
|
||||
// The monitor side of the comparison: with no platform profile the canvas is shown on sRGB.
|
||||
assert_eq!(s.color().monitor().description, Builtin::Srgb.profile().description, "the test monitor");
|
||||
let cd = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(cd.source.description, working.description, "an untagged document is shown in Color Settings' working RGB");
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
let got = shown(&s, &d, i);
|
||||
let want = shown_want(&s, &working, v);
|
||||
assert!(close(got, want, TOL), "column {i}: canvas {got:?} vs the working space's transform {want:?}");
|
||||
assert!(far(got, raw_codes(v), 8.0), "column {i} is still shown as its raw values: {got:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changing_the_working_space_refreshes_an_open_untagged_document() {
|
||||
let mut s = crate::session();
|
||||
let v = [0.8, 0.12, 0.12];
|
||||
let d = untagged_rgb(&[v], SampleType::U8);
|
||||
let before = s.color().canvas_display(&d).unwrap();
|
||||
let signature = s.color().display_signature(&d);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "adobe-rgb-compat"})).unwrap();
|
||||
let after = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(after.source.description, s.color().working(ColorMode::Rgb).description);
|
||||
assert!(!Arc::ptr_eq(&before, &after), "the display cache handed back the entry made for the old working space");
|
||||
assert_ne!(before.key, after.key, "the cache entry and its signature have to move with the working space");
|
||||
assert_ne!(signature, s.color().display_signature(&d), "the canvas reloads the document without reopening it");
|
||||
assert_eq!(before.monitor.content_hash(), after.monitor.content_hash(), "only the working space moved");
|
||||
assert!(close(shown(&s, &d, 0), shown_want(&s, &after.source, &v), TOL), "{:?}", shown(&s, &d, 0));
|
||||
// Back to the default: the same entry as before, so the key follows the setting and not a counter.
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "srgb"})).unwrap();
|
||||
let back = s.color().canvas_display(&d).unwrap();
|
||||
assert!(back.is_identity());
|
||||
assert_eq!(back.key, before.key, "the same settings give the same display");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_untagged_document_stays_untagged_and_keeps_its_pixels() {
|
||||
let mut s = crate::session();
|
||||
let v = [200.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0];
|
||||
s.open_document(untagged_rgb(&[v], SampleType::U8), None);
|
||||
let before = reported(&mut s);
|
||||
assert_eq!(before["embedded"], json!(false));
|
||||
let sample = |s: &Session| s.active().unwrap().doc.layers[0].surface().unwrap().pixel(1, 1);
|
||||
let pixels = sample(&s);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let after = reported(&mut s);
|
||||
assert_eq!(after["embedded"], json!(false), "the working space is not written into the document");
|
||||
assert_eq!(after["description"], Builtin::ProPhotoCompat.profile().description, "the document is taken in the working space");
|
||||
assert_eq!(sample(&s), pixels, "only the interpretation changes, not the stored samples");
|
||||
let d = &s.active().unwrap().doc;
|
||||
assert!(close(shown(&s, d, 0), shown_want(&s, &s.color().working(ColorMode::Rgb), &v), TOL), "{:?}", shown(&s, d, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_tagged_document_keeps_its_embedded_profile() {
|
||||
let mut s = crate::session();
|
||||
let v = [0.4, 0.6, 0.2];
|
||||
for tag in [Builtin::Srgb, Builtin::AdobeRgbCompat, Builtin::DisplayP3] {
|
||||
let d = tagged_rgb(tag.profile(), v);
|
||||
let before = s.color().canvas_display(&d).unwrap();
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let cd = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(cd.source.content_hash(), tag.profile().content_hash(), "{} was replaced by the working space", tag.description());
|
||||
assert_eq!(cd.key, before.key, "a tagged document's display does not move with the setting");
|
||||
assert!(close(shown(&s, &d, 0), shown_want(&s, tag.profile(), &v), TOL), "{}: {:?}", tag.description(), shown(&s, &d, 0));
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "srgb"})).unwrap();
|
||||
}
|
||||
// The command read-back of a tagged document is its own profile.
|
||||
s.open_document(tagged_rgb(Builtin::AdobeRgbCompat.profile(), v), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let info = reported(&mut s);
|
||||
assert_eq!(info["embedded"], json!(true));
|
||||
assert_eq!(info["description"], Builtin::AdobeRgbCompat.profile().description);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_untagged_grayscale_document_follows_the_working_gray() {
|
||||
let mut s = crate::session();
|
||||
let d = untagged_gray(0.3);
|
||||
let first = s.color().canvas_display(&d).unwrap();
|
||||
// The default working Gray is the built-in default, so nothing moves without a setting.
|
||||
assert_eq!(first.source.content_hash(), working_profile(ColorMode::Grayscale).gray_as_rgb().unwrap().content_hash());
|
||||
s.execute("edit.colorSettings", json!({"workingGray": "gray-gamma-2.2"})).unwrap();
|
||||
let working = s.color().working(ColorMode::Grayscale);
|
||||
assert_eq!(working.description, Builtin::GrayGamma22.profile().description, "the setting resolved");
|
||||
let cd = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(cd.source.content_hash(), working.gray_as_rgb().unwrap().content_hash(), "an untagged gray document is shown in the working Gray");
|
||||
assert_ne!(cd.key, first.key, "and its display cache entry re-keys");
|
||||
assert!(close(shown(&s, &d, 0), shown_want(&s, &cd.source, &[0.3, 0.3, 0.3]), TOL), "{:?}", shown(&s, &d, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_untagged_cmyk_document_keeps_todays_display() {
|
||||
let mut s = crate::session();
|
||||
let ink = [0.1, 0.6, 0.7, 0.05];
|
||||
let d = untagged_cmyk(ink);
|
||||
let before = shown(&s, &d, 0);
|
||||
let entry = s.color().canvas_display(&d).unwrap();
|
||||
s.execute("edit.colorSettings", json!({"workingCmyk": "coated-fogra39"})).unwrap();
|
||||
let cd = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(cd.source.description, Builtin::Srgb.profile().description, "CMYK is not measured and keeps its sRGB composite");
|
||||
assert_eq!(cd.key, entry.key, "the working CMYK does not re-key an untagged CMYK document");
|
||||
assert!(close(shown(&s, &d, 0), before, 0.6), "its inks are still read through the built-in coated profile: {before:?} -> {:?}", shown(&s, &d, 0));
|
||||
// And the profile it is taken in stays the mode's built-in default even though the setting
|
||||
// now names another one: only RGB and Grayscale follow Color Settings here.
|
||||
assert_ne!(s.color().working(ColorMode::Cmyk).content_hash(), working_profile(ColorMode::Cmyk).content_hash(), "the setting really moved");
|
||||
assert_eq!(
|
||||
s.color().document_profile(&d).content_hash(),
|
||||
working_profile(ColorMode::Cmyk).content_hash(),
|
||||
"an untagged CMYK document keeps the mode default"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_same_rule_holds_at_every_depth() {
|
||||
let mut s = crate::session();
|
||||
let v = [0.8, 0.12, 0.12];
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let working = s.color().working(ColorMode::Rgb);
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
let d = untagged_rgb(&[v], depth);
|
||||
let cd = s.color().canvas_display(&d).unwrap();
|
||||
assert_eq!(cd.source.description, working.description, "{depth:?}");
|
||||
let got = shown(&s, &d, 0);
|
||||
let want = shown_want(&s, &working, &v);
|
||||
let tol = if depth == SampleType::U8 { TOL } else { 1.0 };
|
||||
assert!(close(got, want, tol), "{depth:?}: {got:?} vs {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_conversion_starts_from_the_working_space() {
|
||||
let mut s = crate::session();
|
||||
let v = [200.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0];
|
||||
let filled = [v[0], v[1], v[2], 1.0];
|
||||
s.open_document(untagged_rgb(&[v], SampleType::U8), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let working = s.color().working(ColorMode::Rgb);
|
||||
let srgb = Builtin::Srgb.profile().clone();
|
||||
// What Convert to Profile has to write: the working space's own transform of the stored
|
||||
// samples, clamped the way the sample write clamps them (this colour is outside sRGB).
|
||||
let clamp3 = |o: &[f32; 16]| [o[0].clamp(0.0, 1.0), o[1].clamp(0.0, 1.0), o[2].clamp(0.0, 1.0)];
|
||||
let mut out = [0.0f32; 16];
|
||||
Transform::new(&working, &srgb, Intent::RelativeColorimetric, false).unwrap().eval(&v, &mut out).unwrap();
|
||||
let want = clamp3(&out);
|
||||
let mut built_in = [0.0f32; 16];
|
||||
let default = working_profile(ColorMode::Rgb);
|
||||
Transform::new(&default, &srgb, Intent::RelativeColorimetric, false).unwrap().eval(&v, &mut built_in).unwrap();
|
||||
assert!(
|
||||
want.iter().zip(clamp3(&built_in).iter()).any(|(a, b)| (a - b).abs() > 8.0 / 255.0),
|
||||
"the fixture must tell the working space apart from the built-in default: {want:?} vs {built_in:?}"
|
||||
);
|
||||
for dither in [false, true] {
|
||||
let r = s.execute("edit.convertToProfile", json!({"profile": "srgb", "intent": "relative", "bpc": false, "dither": dither})).unwrap();
|
||||
assert_eq!(r["converted"], json!(true), "dither {dither}");
|
||||
let px = s.active().unwrap().doc.layers[0].surface().unwrap().pixel(1, 1);
|
||||
assert!((0..3).all(|c| (px[c] - want[c]).abs() <= 2.0 / 255.0), "dither {dither}: {px:?} vs the working space's own conversion {want:?}");
|
||||
assert_eq!(reported(&mut s)["description"], srgb.description, "tagged with the destination");
|
||||
// Back to the untagged start for the second round.
|
||||
s.execute("edit.assignProfile", json!({"profile": "none"})).unwrap();
|
||||
s.edit("reset", |doc, _| {
|
||||
doc.layers[0].surface_mut().unwrap().fill_rect(Rect::new(0, 0, 4, 4), &filled);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mode_change_starts_from_the_working_space() {
|
||||
let mut s = crate::session();
|
||||
let v = [0.8, 0.12, 0.12];
|
||||
s.open_document(untagged_rgb(&[v], SampleType::U8), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat", "workingGray": "gray-gamma-2.2"})).unwrap();
|
||||
let src = s.color().working(ColorMode::Rgb);
|
||||
let dst = s.color().working(ColorMode::Grayscale);
|
||||
let t = Transform::new(&src, &dst, Intent::RelativeColorimetric, false).unwrap();
|
||||
let from_built_in = {
|
||||
let built_in = working_profile(ColorMode::Rgb);
|
||||
Transform::new(&built_in, &dst, Intent::RelativeColorimetric, false).unwrap()
|
||||
};
|
||||
let mut out = [0.0f32; 16];
|
||||
let mut other = [0.0f32; 16];
|
||||
t.eval(&v, &mut out).unwrap();
|
||||
from_built_in.eval(&v, &mut other).unwrap();
|
||||
assert!((out[0] - other[0]).abs() > 1.0 / 255.0, "the fixture must tell the two sources apart: {out:?} vs {other:?}");
|
||||
s.execute("image.mode.grayscale", json!({"intent": "relative", "bpc": false})).unwrap();
|
||||
let px = s.active().unwrap().doc.layers[0].surface().unwrap().pixel(1, 1);
|
||||
assert!((px[0] - out[0]).abs() <= 2.0 / 255.0, "the mode change read the built-in default, not the working RGB: {px:?} vs {out:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layer_copied_into_an_untagged_document_lands_in_its_space() {
|
||||
let mut s = crate::session();
|
||||
// A: untagged, opened under the default settings so nothing is assigned to it on the way in.
|
||||
s.open_document(untagged_rgb(&[[0.5, 0.5, 0.5]], SampleType::U8), None);
|
||||
// B: the same shape tagged sRGB, with a saturated block.
|
||||
let v = [0.9f32, 0.2, 0.2];
|
||||
s.open_document(tagged_rgb(Builtin::Srgb.profile(), v), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let block = s.active().unwrap().active_layer.unwrap();
|
||||
let r = s.execute("layer.copyToDocument", json!({"document": 0, "source": 1, "layers": [block.0]})).unwrap();
|
||||
let id = photocraft_doc::LayerId(r["layers"][0].as_u64().unwrap());
|
||||
let a = &s.documents()[0].doc;
|
||||
assert!(a.icc_profile.is_none(), "the destination is still untagged");
|
||||
let px = a.layer(id).unwrap().surface().unwrap().pixel(1, 1);
|
||||
// It has to keep its look, so it is re-encoded into the space A is shown in.
|
||||
let mut out = [0.0f32; 16];
|
||||
let working = s.color().working(ColorMode::Rgb);
|
||||
Transform::new(Builtin::Srgb.profile(), &working, s.color().settings.intent(), s.color().settings.bpc).unwrap().eval(&v, &mut out).unwrap();
|
||||
let want = [out[0], out[1], out[2]];
|
||||
assert!((0..3).all(|c| (px[c] - want[c]).abs() <= 2.0 / 255.0), "the pasted block landed as {px:?}, not in the space A is shown in ({want:?})");
|
||||
assert!((0..3).any(|c| (px[c] - v[c]).abs() > 8.0 / 255.0), "the fixture must tell a raw copy apart from a re-encoded one: {px:?} vs {v:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gamut_count_is_judged_in_the_space_the_canvas_marks_in() {
|
||||
let mut s = crate::session();
|
||||
// Six colours that straddle the coated-CMYK gamut: read as sRGB some of them are inside it,
|
||||
// read as ProPhoto the same samples are far outside.
|
||||
let colours = [[0.95f32, 0.05, 0.05], [0.8, 0.3, 0.3], [0.6, 0.1, 0.1], [0.3, 0.85, 0.3], [0.1, 0.4, 0.9], [0.45, 0.45, 0.95]];
|
||||
s.open_document(untagged_rgb(&colours, SampleType::U8), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
s.execute("view.proofSetup", json!({"profile": "coated-cmyk", "intent": "perceptual"})).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let setup = s.color().proof(doc.id).setup.clone();
|
||||
let buf = photocraft_compose::flatten(&doc);
|
||||
let count_with = |src: &Profile| {
|
||||
let check = GamutCheck::new(src, &setup.profile, 4.0).unwrap();
|
||||
let mut mask = vec![0u8; buf.px.len()];
|
||||
let count = check.mask_rgba(&buf.px, &mut mask).unwrap();
|
||||
(mask, count)
|
||||
};
|
||||
// The canvas marks its out-of-gamut pixels through the display source; that is the count the
|
||||
// Gamut Warning command and Color Range > Out of Gamut have to agree with.
|
||||
let want = count_with(&s.color().composite_profile(&doc));
|
||||
let built_in = count_with(&composite_profile(&doc));
|
||||
assert_ne!(want.1, built_in.1, "the fixture must tell the two spaces apart: {want:?} vs {built_in:?}");
|
||||
let warning = s.execute("view.gamutWarning", json!({"on": true, "threshold": 4.0})).unwrap();
|
||||
assert_eq!(warning["outOfGamut"].as_u64().unwrap() as usize, want.1, "Gamut Warning judged another space than the canvas");
|
||||
// Color Range › Out of Gamut has to mark exactly those pixels.
|
||||
s.execute("select.colorRange", json!({"select": "outOfGamut"})).unwrap();
|
||||
let with = s.active().unwrap().doc.clone();
|
||||
let selection = with.selection.clone().expect("the selection was set");
|
||||
let width = with.size.width as usize;
|
||||
let marked = |surface: &photocraft_raster::Surface| -> Vec<usize> {
|
||||
(0..with.size.width as usize / 4).map(|i| (surface.pixel(i as i32 * 4 + 2, 2)[0] > 0.5) as usize).collect()
|
||||
};
|
||||
let marks = marked(&selection);
|
||||
let columns: Vec<usize> = (0..width / 4).map(|i| usize::from(want.0[2 * width + i * 4 + 2] == 255)).collect();
|
||||
assert_eq!(marks, columns, "Color Range > Out of Gamut marks other pixels than the warning counts");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converting_an_untagged_document_to_working_leaves_its_samples() {
|
||||
let mut s = crate::session();
|
||||
let v = [0.9f32, 0.2, 0.2];
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
// The answer to the "missing profile" prompt for a document that is not open yet.
|
||||
let mut d = untagged_rgb(&[v], SampleType::U8);
|
||||
s.color().resolve_open(&mut d, "convert").unwrap();
|
||||
let tagged = profile_from_bytes(d.icc_profile.as_ref().expect("tagged by the answer")).unwrap();
|
||||
assert_eq!(tagged.description, s.color().working(ColorMode::Rgb).description, "tagged with the working space");
|
||||
let px = d.layers[0].surface().unwrap().pixel(1, 1);
|
||||
assert!((0..3).all(|c| (px[c] - v[c]).abs() <= 2.0 / 255.0), "the answer read the document in the built-in default and moved its pixels: {px:?} vs {v:?}");
|
||||
// The command path agrees: an untagged document answers the same way once it is open.
|
||||
s.open_document(untagged_rgb(&[v], SampleType::U8), None);
|
||||
let r = s.execute("color.profileMismatch", json!({"action": "convertToWorking"})).unwrap();
|
||||
assert_eq!(r["action"], json!("converted"));
|
||||
let px = s.active().unwrap().doc.layers[0].surface().unwrap().pixel(1, 1);
|
||||
assert!((0..3).all(|c| (px[c] - v[c]).abs() <= 2.0 / 255.0), "the open document's answer moved its pixels: {px:?}");
|
||||
let info = reported(&mut s);
|
||||
assert_eq!(info["embedded"], json!(true));
|
||||
assert_eq!(info["description"], s.color().working(ColorMode::Rgb).description);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_untagged_indexed_document_follows_the_mode_default_until_it_becomes_rgb() {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 8, "height": 8, "background": "#ff0000"})).unwrap();
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
s.execute("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "colors": 8})).unwrap();
|
||||
// Indexed is not one of the two modes the item measures: it keeps the mode's built-in default.
|
||||
let indexed = working_profile(ColorMode::Indexed);
|
||||
assert_eq!(reported(&mut s)["description"], indexed.description, "an Indexed document is not switched");
|
||||
// Image > Mode > RGB without a profile keeps the stored samples; the document that results is
|
||||
// untagged RGB, so the reply and Profile Info have to name the same space.
|
||||
let r = s.execute("image.mode.rgb", json!({})).unwrap();
|
||||
assert_eq!(r["profile"], s.color().working(ColorMode::Rgb).description, "the reply names the space the result is taken in");
|
||||
assert_eq!(reported(&mut s)["description"], s.color().working(ColorMode::Rgb).description, "and Profile Info agrees");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colour_range_judges_sampled_colours_in_the_space_the_canvas_shows() {
|
||||
let mut s = crate::session();
|
||||
// A box spanned by two sampled colours and a ramp of columns across it. Membership is decided in
|
||||
// Lab, through the profile the composite is read in, so once the working space moves the box has
|
||||
// to move with the picture: with the ramp below one column drops out going from sRGB to
|
||||
// ProPhoto, and none of this changes at the default setting.
|
||||
let columns: Vec<[f32; 3]> = (0..8).map(|i| [0.55 + 0.03 * i as f32, 0.45 - 0.03 * i as f32, 0.45 - 0.02 * i as f32]).collect();
|
||||
s.open_document(untagged_rgb(&columns, SampleType::U8), None);
|
||||
let marked = |s: &mut Session| -> Vec<usize> {
|
||||
s.execute("select.colorRange", json!({"select": "sampledColors", "colors": ["#cc4d4d", "#996666"], "fuzziness": 40})).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let selection = doc.selection.clone().expect("a selection was set");
|
||||
(0..columns.len()).filter(|i| selection.pixel(*i as i32 * 4 + 2, 2)[0] > 0.5).collect()
|
||||
};
|
||||
let as_built_in = marked(&mut s);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let as_working = marked(&mut s);
|
||||
assert_ne!(as_built_in, as_working, "the sampled colour box marked the same columns whatever the working space: {as_built_in:?} vs {as_working:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_color_judges_its_lab_bounds_in_the_space_the_canvas_shows() {
|
||||
// A Lab cube drawn around one column of the gamut fixture through the profile this session reads
|
||||
// the layer in. The same device numbers sit far away when they are read in the mode's built-in
|
||||
// default, so the cube has to catch that column here and miss it in a session at the default.
|
||||
let columns = [[0.95f32, 0.05, 0.05], [0.8f32, 0.3, 0.3], [0.6f32, 0.1, 0.1], [0.3, 0.85, 0.3], [0.1, 0.4, 0.9], [0.45, 0.45, 0.95]];
|
||||
let column = 1usize;
|
||||
let lab_in = |profile: &Profile, v: [f32; 3]| -> [f32; 3] {
|
||||
let t = craft_cms::cached(profile, Builtin::LabD50.profile(), craft_cms::TransformOptions::default()).unwrap();
|
||||
let mut out = [0.0f32; 16];
|
||||
t.eval(&v, &mut out).unwrap();
|
||||
[out[0] * 100.0, out[1] * 255.0 - 128.0, out[2] * 255.0 - 128.0]
|
||||
};
|
||||
let mut s = crate::session();
|
||||
s.open_document(untagged_rgb(&columns, SampleType::U8), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let centre = lab_in(&s.color().document_profile(&doc), columns[column]);
|
||||
let elsewhere = lab_in(&document_profile(&doc), columns[column]);
|
||||
assert!((0..3).any(|c| (centre[c] - elsewhere[c]).abs() > 10.0), "the fixture must tell the two readings apart: {centre:?} vs {elsewhere:?}");
|
||||
let cube = json!({
|
||||
"labMinimum": [centre[0] - 4.0, centre[1] - 4.0, centre[2] - 4.0],
|
||||
"labMaximum": [centre[0] + 4.0, centre[1] + 4.0, centre[2] + 4.0],
|
||||
"fuzziness": 0,
|
||||
"saturation": -60,
|
||||
});
|
||||
let shifted = |s: &Session| -> bool {
|
||||
// The layer makes a Lab round trip whether it is inside the cube or not, which moves single
|
||||
// codes here and there; only the desaturation is a real change.
|
||||
let surf = s.active().unwrap().doc.layers[0].surface().unwrap();
|
||||
let got = raw_codes(&surf.pixel(column as i32 * 4 + 2, 2));
|
||||
let stored = raw_codes(&columns[column]);
|
||||
(0..3).any(|c| (got[c] - stored[c]).abs() > 8.0)
|
||||
};
|
||||
s.execute("image.adjustments.replaceColor", cube.clone()).unwrap();
|
||||
assert!(shifted(&s), "the cube drawn in this session's own space missed the column it was drawn around: {centre:?}");
|
||||
let mut plain = crate::session();
|
||||
plain.open_document(untagged_rgb(&columns, SampleType::U8), None);
|
||||
plain.execute("image.adjustments.replaceColor", cube).unwrap();
|
||||
assert!(!shifted(&plain), "the same cube also caught the column read in the built-in default: {centre:?} vs {elsewhere:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_profile_commands_answer_the_same_for_a_tagged_document() {
|
||||
let mut replies = Vec::new();
|
||||
for working in ["srgb", "prophoto-compat"] {
|
||||
let mut s = crate::session();
|
||||
s.open_document(tagged_rgb(Builtin::AdobeRgbCompat.profile(), [0.4, 0.6, 0.2]), None);
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": working})).unwrap();
|
||||
replies.push(json!({
|
||||
"info": reported(&mut s),
|
||||
"assign": s.execute("edit.assignProfile", json!({"profile": "display-p3"})).unwrap(),
|
||||
"info_after_assign": reported(&mut s),
|
||||
"convert": s.execute("edit.convertToProfile", json!({"profile": "srgb", "intent": "relative", "bpc": false})).unwrap(),
|
||||
"mode": s.execute("image.mode.grayscale", json!({"intent": "relative", "bpc": false})).unwrap(),
|
||||
"info_after_mode": reported(&mut s),
|
||||
}));
|
||||
}
|
||||
assert_eq!(replies[0], replies[1], "a tagged document's replies must not depend on the working space");
|
||||
}
|
||||
@@ -2,9 +2,10 @@
|
||||
//! monitor profile, on the GPU canvas (matrix/shaper or display 3D LUT) and the CPU canvas
|
||||
//! (an 8-bit transform of the composite).
|
||||
//!
|
||||
//! * The composite is in [`composite_profile`] (the document profile for RGB, its gray curve as
|
||||
//! * The composite is in `composite_profile` (the document profile for RGB, its gray curve as
|
||||
//! RGB for gray documents, sRGB for CMYK — read through the document's CMYK profile, see
|
||||
//! `photocraft_color::convert::CmykSpace` — and Lab).
|
||||
//! `photocraft_color::convert::CmykSpace` — and Lab). An untagged document has no profile of
|
||||
//! its own, and an untagged RGB or gray one is taken in Color Settings' working space (#14224).
|
||||
//! * Linear composites (EXR/HDR, linear profiles) are stored in the 8-bit canvas texture
|
||||
//! sRGB-encoded ([`CanvasDisplay::encode_srgb`]) so shadows keep their precision; the display
|
||||
//! source profile is then the same primaries with the sRGB curve.
|
||||
@@ -14,19 +15,21 @@
|
||||
//! * When the source and the monitor match (sRGB documents on an sRGB display, the common
|
||||
//! case) the transform is the identity and nothing is applied on either path.
|
||||
//!
|
||||
//! Results are cached per (document profile, mode, monitor profile); the rendering intent is
|
||||
//! relative colorimetric with black point compensation, as for Photoshop's monitor display.
|
||||
//! Results are cached per (document profile, mode, monitor profile) — plus the working space while
|
||||
//! the document is untagged, so a Color Settings change re-keys it (#14224); the rendering intent
|
||||
//! is relative colorimetric with black point compensation, as for Photoshop's monitor display.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
use craft_cms::{Builtin, ColorSpace, Curve, Intent, Profile, Transform};
|
||||
use photocraft_color::ColorMode;
|
||||
use photocraft_compose::Buffer;
|
||||
use photocraft_doc::Document;
|
||||
use photocraft_raster::Rgba8Image;
|
||||
|
||||
use crate::color_cmds::{ColorState, composite_profile, mode_space, profile_from_bytes, resolve_profile};
|
||||
use crate::color_cmds::{ColorState, mode_space, profile_from_bytes, resolve_profile};
|
||||
use crate::{EngineError, Result};
|
||||
|
||||
/// Display intent and black point compensation of the monitor transform.
|
||||
@@ -261,11 +264,15 @@ struct MonitorEntry {
|
||||
status: MonitorStatus,
|
||||
}
|
||||
|
||||
/// The canvas display cache key: colour space, document profile, monitor profile, and while the
|
||||
/// document is untagged the Color Settings working space it is shown in (#14224).
|
||||
type CanvasKey = (ColorSpace, u64, u64, Option<u64>);
|
||||
|
||||
/// Caches of [`ColorState`] for the display (monitor profiles per display, per-document displays).
|
||||
#[derive(Default)]
|
||||
pub struct DisplayCaches {
|
||||
monitor: Mutex<HashMap<Option<u32>, MonitorEntry>>,
|
||||
canvas: Mutex<HashMap<(ColorSpace, u64, u64), Arc<CanvasDisplay>>>,
|
||||
canvas: Mutex<HashMap<CanvasKey, Arc<CanvasDisplay>>>,
|
||||
}
|
||||
|
||||
impl ColorState {
|
||||
@@ -407,16 +414,30 @@ impl ColorState {
|
||||
}
|
||||
|
||||
/// How the canvas shows `doc` on `display` (cached per document profile, mode and monitor
|
||||
/// profile).
|
||||
/// profile; for an untagged document also per Color Settings' working space, which is the
|
||||
/// profile it is shown in).
|
||||
pub fn canvas_display_for(&self, doc: &Document, display: Option<u32>) -> Result<Arc<CanvasDisplay>> {
|
||||
let space = mode_space(doc.mode);
|
||||
let doc_hash = doc.icc_profile.as_ref().and_then(|b| profile_from_bytes(b).ok()).filter(|p| p.color_space == space).map_or(0, |p| p.content_hash());
|
||||
let embedded = crate::color_cmds::embedded_profile(doc);
|
||||
// An untagged RGB or Grayscale document is displayed in Color Settings' working space
|
||||
// (#14224), so the setting joins its key: the profile hash 0 that an untagged document
|
||||
// used before did not move when the working space did, and an open document kept the
|
||||
// display it was first shown with. The setting is hashed rather than the profile it
|
||||
// resolves to, because this runs on every frame and `working` would clone the profile's
|
||||
// tables (or read its `.icc` file) each time. Every other mode keeps the built-in default
|
||||
// and stays keyed 0.
|
||||
let working = if embedded.is_none() && matches!(doc.mode, ColorMode::Rgb | ColorMode::Grayscale) {
|
||||
Some(hash_of((self.working_space_spec(doc.mode), self.settings.intent().id())))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let doc_hash = embedded.map_or(0, |p| p.content_hash());
|
||||
let monitor = self.monitor_for(display);
|
||||
let key = (space, doc_hash, monitor.content_hash());
|
||||
let key: CanvasKey = (space, doc_hash, monitor.content_hash(), working);
|
||||
if let Some(d) = self.display.canvas.lock().unwrap_or_else(|e| e.into_inner()).get(&key) {
|
||||
return Ok(d.clone());
|
||||
}
|
||||
let composite = composite_profile(doc);
|
||||
let composite = self.composite_profile(doc);
|
||||
let encode_srgb = is_linear_rgb(&composite);
|
||||
let source = if encode_srgb { Arc::new(srgb_curve_twin(&composite)) } else { composite };
|
||||
let transform = if source.content_hash() == monitor.content_hash() {
|
||||
|
||||
@@ -14,6 +14,11 @@ pub const HIDDEN: &str = "Could not complete your request because the target lay
|
||||
/// The Art History Brush's own alert text (#12638).
|
||||
pub const ART_HISTORY_HIDDEN: &str = "Could not use the art history brush because the target layer is hidden.";
|
||||
|
||||
/// The gradient's alerts for a pixel layer's mask it can't draw into (#18637): the layer is hidden, or it has Lock All
|
||||
/// (its own or a group's). Measured with the Gradient tool in Gradient mode.
|
||||
pub const GRADIENT_MASK_HIDDEN: &str = "Could not use the gradient tool because the target layer mask is hidden.";
|
||||
pub const GRADIENT_MASK_LOCKED: &str = "Could not use the gradient tool because the layer is locked.";
|
||||
|
||||
/// The Color Replacement tool's alerts for a target it can't recolour (#17782): a pixel layer's
|
||||
/// mask, an adjustment layer (its mask or its content), a group's mask, an alpha channel or the
|
||||
/// Quick Mask.
|
||||
@@ -71,6 +76,11 @@ pub fn refusal(s: &Session, id: &str, params: &Value) -> Option<&'static str> {
|
||||
{
|
||||
return Some(why);
|
||||
}
|
||||
if id == "paint.gradient"
|
||||
&& let Some(why) = gradient_mask_refusal(s, ¶ms)
|
||||
{
|
||||
return Some(why);
|
||||
}
|
||||
if crate::channel_cmds::is_channel_target(¶ms) {
|
||||
return None;
|
||||
}
|
||||
@@ -85,6 +95,26 @@ pub fn refusal(s: &Session, id: &str, params: &Value) -> Option<&'static str> {
|
||||
(st.doc.layer(layer).is_some() && !shown(&st.doc, layer)).then_some(why)
|
||||
}
|
||||
|
||||
/// Why `paint.gradient` with `params` (its `target` filled in) can't draw into a pixel layer's mask (#18637): the layer is
|
||||
/// hidden, else it has Lock All. A hidden or locked adjustment, fill or group layer's mask was not measured and keeps the
|
||||
/// generic refusals. These texts are Gradient mode's: a Classic call (`"classic": true`) or one without the flag keeps the
|
||||
/// generic refusals too (#18902).
|
||||
fn gradient_mask_refusal(s: &Session, params: &Value) -> Option<&'static str> {
|
||||
if params.get("classic").and_then(Value::as_bool) != Some(false) || crate::channel_cmds::target_of(params) != crate::channel_cmds::Target::Mask {
|
||||
return None;
|
||||
}
|
||||
let st = s.active()?;
|
||||
let id = crate::commands::layer_param(s, params).ok()?;
|
||||
let layer = st.doc.layer(id).filter(|l| matches!(l.content, photocraft_doc::LayerContent::Raster(_)) && l.mask.is_some())?;
|
||||
if !shown(&st.doc, layer.id) {
|
||||
Some(GRADIENT_MASK_HIDDEN)
|
||||
} else if st.doc.effective_locks(layer.id).all {
|
||||
Some(GRADIENT_MASK_LOCKED)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Why `paint.colorReplacement` with `params` (its `target` filled in) can't recolour its target
|
||||
/// (#17782): the tool works on a pixel layer's full colour composite only, not on some of its
|
||||
/// colour channels (#17783). The target decides
|
||||
|
||||
@@ -55,7 +55,10 @@ pub mod shortcut_sets;
|
||||
mod slots;
|
||||
pub mod snap;
|
||||
mod state;
|
||||
pub use variables_cmds::{DATA_SET_FILE_MISSING, DATA_SET_LAYER_LOCKED, data_set_preview, export_data_sets_with, import_data_sets_text};
|
||||
pub use variables_cmds::{
|
||||
DATA_SET_FILE_MISSING, DATA_SET_LAYER_LOCKED, DataSetsExportReport, StoppedDataSet, data_set_preview, export_data_sets_report_with, export_data_sets_with,
|
||||
import_data_sets_text,
|
||||
};
|
||||
pub use video_cmds::render_video_with;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Layer › New › Layer: Photoshop's New Layer options (name, Use Previous Layer to Create Clipping
|
||||
//! Mask, color label, mode, opacity, and Fill with neutral color), applied in one history step.
|
||||
|
||||
use photocraft_doc::{BlendMode, LabelColor, Layer};
|
||||
use photocraft_color::{ColorMode, SampleType};
|
||||
use photocraft_doc::{BlendMode, Document, LabelColor, Layer};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::{EngineError, Result, Session};
|
||||
@@ -12,6 +13,31 @@ fn bad(msg: impl Into<String>) -> EngineError {
|
||||
EngineError::BadParams { cmd: CMD.into(), msg: msg.into() }
|
||||
}
|
||||
|
||||
/// The New Layer dialog only greys modes measured in RGB 32-bit and Lab 8-bit.
|
||||
pub fn greyed_modes(doc: &Document) -> &'static [BlendMode] {
|
||||
match (doc.mode, doc.depth) {
|
||||
(ColorMode::Rgb, SampleType::F32) | (ColorMode::Lab, SampleType::U8) => crate::pixel_fill::greyed_modes(doc.mode, doc.depth),
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
fn check_mode_available(s: &Session, mode: BlendMode) -> Result<()> {
|
||||
if let Some(st) = s.active()
|
||||
&& greyed_modes(&st.doc).contains(&mode)
|
||||
{
|
||||
crate::pixel_fill::check_mode_available(CMD, &st.doc, mode)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Refuse an unavailable mode before dispatch can settle a floating selection or the UI can commit a transform.
|
||||
pub(crate) fn precheck_mode(s: &Session, p: &Value) -> Result<()> {
|
||||
if let Some(mode) = p.get("mode").and_then(Value::as_str).and_then(crate::commands::parse_blend) {
|
||||
check_mode_available(s, mode)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The color that leaves everything below unchanged in `mode` (Photoshop's "Fill with
|
||||
/// Multiply-neutral color (white)"), as RGB, and its name. `None` for modes that have none.
|
||||
pub fn neutral_color(mode: BlendMode) -> Option<([f32; 3], &'static str)> {
|
||||
@@ -40,6 +66,7 @@ pub(crate) struct NewLayer {
|
||||
/// panel's ⌘/Ctrl-click), joining the clip group it lands in.
|
||||
pub fn run(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let NewLayer { clip, mode, opacity, label, neutral, below, name } = parse(p)?;
|
||||
check_mode_available(s, mode)?;
|
||||
let place = if below { crate::layer_place::Place::Below } else { crate::layer_place::Place::Auto };
|
||||
let id = s.edit("New Layer", |doc, active| {
|
||||
let name = name.clone().unwrap_or_else(|| doc.next_layer_suggestion());
|
||||
|
||||
@@ -557,17 +557,24 @@ pub fn remap_surface(s: &Surface, map: impl Fn(i32, i32) -> (i32, i32)) -> Surfa
|
||||
/// Merge `upper` onto `lower` producing a raster layer (Layer → Merge Down).
|
||||
pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer {
|
||||
let format = doc.pixel_format();
|
||||
let stack = vec![lower.clone(), upper.clone()];
|
||||
let mut tmp = Document::new("merge", doc.size, format.mode, format.sample);
|
||||
// The pair is read (and a CMYK one separated again) through the document's own profile.
|
||||
tmp.icc_profile = doc.icc_profile.clone();
|
||||
tmp.layers = stack.into();
|
||||
// Photoshop keeps the lower layer's layer style live on the merged layer, where it
|
||||
// re-applies to the merged pixels: bake the pair without it so it is not applied twice.
|
||||
let mut bare_lower = lower.clone();
|
||||
let style = std::mem::take(&mut bare_lower.effects);
|
||||
// The pair is rendered with the document's own Global Light, patterns and colour profile,
|
||||
// and read (and a CMYK one separated again) through that profile.
|
||||
let mut tmp = doc.clone();
|
||||
tmp.layers = vec![bare_lower, upper.clone()].into();
|
||||
// A Background stays canvas-sized; any other layer keeps the pixels outside the canvas (#5067).
|
||||
let s = if doc.is_background(lower.id) { composite_layers(&tmp, format, None) } else { composite_layers_uncropped(&tmp, format) };
|
||||
let mut merged = Layer::new(lower.name.clone(), LayerContent::Raster(s));
|
||||
merged.id = lower.id;
|
||||
merged.blend = lower.blend;
|
||||
merged.opacity = 1.0;
|
||||
// And the fill: Photoshop inherits the lower layer's fill opacity onto the merged layer,
|
||||
// so a zero-fill layer keeps its ink in the pixels but invisible, with only its style
|
||||
// visible — instead of resetting the property (observed in the PR fixtures).
|
||||
merged.fill_opacity = lower.fill_opacity;
|
||||
// Merge Down replaces the lower layer, so keep its editing restrictions.
|
||||
// In particular, a merged Background must remain opaque and position-locked.
|
||||
merged.locks = lower.locks;
|
||||
@@ -576,5 +583,8 @@ pub fn merge_down(doc: &Document, lower: &Layer, upper: &Layer) -> Layer {
|
||||
merged.clipped = lower.clipped && upper.clipped;
|
||||
merged.label = lower.label;
|
||||
merged.link_group = lower.link_group;
|
||||
// The fill opacity and the masks are in the pixels now; the layer style is kept, live, and
|
||||
// recomposes over the union of both layers' content.
|
||||
merged.effects = style;
|
||||
merged
|
||||
}
|
||||
@@ -117,6 +117,7 @@ choice!(FontPreview { Off = "off", Small = "small", Medium = "medium", Large = "
|
||||
choice!(RawColorSpace { Srgb = "srgb", AdobeRgb = "adobeRgb", ProPhoto = "proPhoto", DisplayP3 = "displayP3" } default DisplayP3);
|
||||
choice!(RawDepth { Eight = "8", Sixteen = "16" } default Sixteen);
|
||||
choice!(RawSharpen { None = "none", Screen = "screen", Glossy = "glossy", Matte = "matte" } default None);
|
||||
choice!(RawSharpenAmount { Low = "low", Standard = "standard", High = "high" } default Standard);
|
||||
choice!(
|
||||
/// How a raw file's colour filter array is filled in when it is developed: AHD
|
||||
/// (Hirakawa–Parks) keeps edges cleanest, Malvar–He–Cutler is sharp and fast, bilinear is the
|
||||
@@ -1177,6 +1178,7 @@ pub struct RawDefaults {
|
||||
#[serde(deserialize_with = "raw_resolution")]
|
||||
pub resolution: u32,
|
||||
pub sharpen_for: RawSharpen,
|
||||
pub sharpen_amount: RawSharpenAmount,
|
||||
pub open_as_smart_object: bool,
|
||||
pub apply_auto_tone: bool,
|
||||
/// Opening a raw file interactively shows the Camera Raw dialog first (Open / Cancel), as
|
||||
@@ -1194,6 +1196,23 @@ pub struct RawDefaults {
|
||||
impl RawDefaults {
|
||||
/// What Resolution takes, as the reference application's field does.
|
||||
pub const RESOLUTION: std::ops::RangeInclusive<u32> = 1..=999;
|
||||
|
||||
/// Apply output sharpening if a medium is selected and the raw has no Detail sharpening.
|
||||
pub fn apply_output_sharpening(&self, settings: &mut photocraft_algo::camera_raw::CameraRaw) -> bool {
|
||||
if settings.sharpen_amount != 0.0 {
|
||||
return false;
|
||||
}
|
||||
let Some((amount, radius)) = self.sharpen_for.preset() else { return false };
|
||||
// Vary the strength around the existing Standard preset while keeping the medium's radius.
|
||||
let amount = match self.sharpen_amount {
|
||||
RawSharpenAmount::Low => amount * 0.5,
|
||||
RawSharpenAmount::Standard => amount,
|
||||
RawSharpenAmount::High => amount * 1.5,
|
||||
};
|
||||
settings.sharpen_amount = amount;
|
||||
settings.sharpen_radius = radius;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// A saved Raw Defaults › Resolution as the field takes it: the nearest whole number within
|
||||
@@ -1251,6 +1270,7 @@ impl Default for RawDefaults {
|
||||
bit_depth: RawDepth::Sixteen,
|
||||
resolution: 300,
|
||||
sharpen_for: RawSharpen::None,
|
||||
sharpen_amount: RawSharpenAmount::Standard,
|
||||
open_as_smart_object: false,
|
||||
apply_auto_tone: false,
|
||||
open_in_camera_raw: true,
|
||||
|
||||
@@ -2,8 +2,8 @@ use super::shortcuts::normalize_shortcut;
|
||||
use super::{
|
||||
AppearanceMode, Ask, CanvasBorder, CanvasColor, CheckerColors, CheckerSize, ColorPicker, ExportLocation, ExportMetadata, FontPreview, GpuBackend,
|
||||
Interpolation, LineStyle, LinuxDisplayServer, LogDestination, LogDetail, OtherCursor, PaintingCursor, PlaybackPerformance, PointSize, PressureCurve,
|
||||
QuickExportFormat, RawColorSpace, RawDemosaic, RawDepth, RawSharpen, RenderingMode, RightClickPaint, TabletInput, TextEngine, TypeUnit, UiDensity,
|
||||
UiFontSize, UiScale, Unit, Value, WhenAppClosed,
|
||||
QuickExportFormat, RawColorSpace, RawDemosaic, RawDepth, RawSharpen, RawSharpenAmount, RenderingMode, RightClickPaint, TabletInput, TextEngine, TypeUnit,
|
||||
UiDensity, UiFontSize, UiScale, Unit, Value, WhenAppClosed,
|
||||
};
|
||||
|
||||
/// Preferences dialog sections in Photoshop's order: (id, title).
|
||||
@@ -96,6 +96,7 @@ pub fn choices(path: &str) -> Option<&'static [&'static str]> {
|
||||
"rawDefaults.colorSpace" => RawColorSpace::NAMES,
|
||||
"rawDefaults.bitDepth" => RawDepth::NAMES,
|
||||
"rawDefaults.sharpenFor" => RawSharpen::NAMES,
|
||||
"rawDefaults.sharpenAmount" => RawSharpenAmount::NAMES,
|
||||
"rawDefaults.demosaic" => RawDemosaic::NAMES,
|
||||
"performance.gpuBackend" => GpuBackend::NAMES,
|
||||
"performance.linuxDisplayServer" => LinuxDisplayServer::NAMES,
|
||||
|
||||
@@ -33,7 +33,11 @@ impl Session {
|
||||
/// `check_params` hooks.
|
||||
pub(crate) fn validate_params(&self, id: &str, spec: &crate::registry::CommandSpec, params: &Value) -> Result<()> {
|
||||
crate::param_check::check(spec, params)?;
|
||||
crate::registry::hooks().check_params.iter().try_for_each(|check| check(self, id, params))
|
||||
crate::registry::hooks().check_params.iter().try_for_each(|check| check(self, id, params))?;
|
||||
if id == "layer.new.layer" {
|
||||
crate::new_layer::precheck_mode(self, params)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check a call without running it: the command exists, its params have the shape
|
||||
|
||||
@@ -350,7 +350,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
label: "Gradient",
|
||||
menu: &[],
|
||||
shortcut: None,
|
||||
params: r##"{"from":[x,y],"to":[x,y],"style":"linear|radial|angle|reflected|diamond"="linear","colors":["#rrggbb",…]? (evenly spaced),"gradient":preset name?,"stops":[[t,"#rrggbb"|"foreground"|"background"],…]?,"transparency":[[t,0..100],…]? (default: the current gradient, see gradient.presets.select),"method":"classic|perceptual|linear|smooth"? (Photoshop's interpolation; omitted: straight stops),"smoothness":0..100=100,"reverse":bool=false,"dither":bool=true,"opacity":1..100=100,"mode":"normal|multiply|…|behind (paints only transparency)"="normal","layer":id? (default: the active layer; a layer name also works),"target":"pixels"|"mask"|"filterMask"|"quickMask"|{"channel":i}=Channels panel target}"##,
|
||||
params: r##"{"from":[x,y],"to":[x,y],"style":"linear|radial|angle|reflected|diamond"="linear","colors":["#rrggbb",…]? (evenly spaced),"gradient":preset name?,"stops":[[t,"#rrggbb"|"foreground"|"background"],…]?,"transparency":[[t,0..100],…]? (default: the current gradient, see gradient.presets.select),"method":"classic|perceptual|linear|smooth"? (Photoshop's interpolation; omitted: straight stops),"smoothness":0..100=100,"reverse":bool=false,"dither":bool=true,"opacity":1..100=100,"mode":"normal|multiply|…|behind (paints only transparency)"="normal","layer":id? (default: the active layer; a layer name also works),"target":"pixels"|"mask"|"filterMask"|"quickMask"|{"channel":i}=Channels panel target,"classic":bool? (the Gradient tool's mode: false = Gradient mode, whose refusals on a hidden or Lock All layer's mask use that mode's texts; true or omitted = the generic refusals)}"##,
|
||||
enabled: crate::cmd::has_paintable,
|
||||
run: gradient,
|
||||
journal: true,
|
||||
|
||||
@@ -458,6 +458,9 @@ mod tests;
|
||||
#[cfg(test)]
|
||||
mod clone_source_layer_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod untagged_working_space_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod patch_history_names_tests;
|
||||
|
||||
|
||||
@@ -238,9 +238,11 @@ fn resolve_source(s: &Session, p: &Value, cmd: &str, source: Option<crate::prese
|
||||
|
||||
/// Choose the sampled pixel/composite profile and cache its conversion to the destination profile.
|
||||
fn color_transform(s: &Session, doc: &Document, which: SampleLayers, cmd: &str) -> Result<Option<Arc<Transform>>> {
|
||||
let source = if which == SampleLayers::Current { crate::color_cmds::document_profile(doc) } else { crate::color_cmds::composite_profile(doc) };
|
||||
// Both documents are read as the session reads them: an untagged one is taken in its working
|
||||
// space (#14224), so a stamp cloned across documents keeps the look it has on its own canvas.
|
||||
let source = if which == SampleLayers::Current { s.color().document_profile(doc) } else { s.color().composite_profile(doc) };
|
||||
let target = s.active().ok_or(EngineError::NoDocument)?;
|
||||
let destination = crate::color_cmds::document_profile(&target.doc);
|
||||
let destination = s.color().document_profile(&target.doc);
|
||||
let inputs = if which == SampleLayers::Current { doc.mode.color_channels() } else { 3 };
|
||||
if source.channels() != inputs || destination.channels() != target.doc.mode.color_channels() {
|
||||
return Err(bad(cmd, "cross-document cloning does not support this color model"));
|
||||
|
||||
@@ -385,6 +385,9 @@ impl DabTool {
|
||||
}
|
||||
Self::Focus { sharpen, strength, protect, sigma } => {
|
||||
let a = alpha_index(&fmt);
|
||||
// Sharpen sharpens alpha too (#12940), measured at 8 bits only: 16- and 32-bit
|
||||
// layers keep their alpha as before.
|
||||
let keep_alpha = if sharpen && fmt.sample != SampleType::U8 { a } else { None };
|
||||
let mut shares = ProtectDetailShares::default();
|
||||
Box::new(move |work, fp| {
|
||||
let r = fp.rect.intersect(&work.rect);
|
||||
@@ -417,7 +420,9 @@ impl DabTool {
|
||||
let i = (x - wx0) as usize * n;
|
||||
let px = &mut line[i..i + n];
|
||||
for c in 0..n {
|
||||
px[c] += (out[o + c] - px[c]) * k;
|
||||
if Some(c) != keep_alpha {
|
||||
px[c] += (out[o + c] - px[c]) * k;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -917,6 +922,10 @@ mod smudge_refuses_indexed_tests;
|
||||
#[path = "smudge_mode_tests.rs"]
|
||||
mod smudge_mode_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sharpen_alpha_tests.rs"]
|
||||
mod sharpen_alpha_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "burn_grayscale_tests.rs"]
|
||||
mod burn_grayscale_tests;
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
//! #12940: with Protect Detail off, the Sharpen tool sharpens a layer's transparency by the same
|
||||
//! rule as its colour, and keeps the colour. The reference test layer is (200,40,40) at alpha 64
|
||||
//! for x 300..399 and alpha 191 for x 400..499, y 300..349, clicked once at 400,320 with a 40 px
|
||||
//! hard tip at Strength 100 %.
|
||||
//!
|
||||
//! The reference's exact alpha (40 at x 399, 215 at x 400, x 398 and 401 unchanged) comes from the
|
||||
//! 8-neighbour kernel of #12939; until that lands, alpha follows today's colour kernel.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
const RED: [f32; 3] = [200.0 / 255.0, 40.0 / 255.0, 40.0 / 255.0];
|
||||
|
||||
/// An 800 × 600 RGB document of `depth` whose active layer is `f(x, y)` (straight RGBA, 0..1).
|
||||
fn doc(depth: u64, transparent: bool, f: impl Fn(i32, i32) -> [f32; 4]) -> Session {
|
||||
let mut s = crate::session();
|
||||
let mut p = json!({"width": 800, "height": 600, "depth": depth, "mode": "rgb"});
|
||||
if transparent {
|
||||
p["background"] = json!("transparent");
|
||||
}
|
||||
s.execute("file.new", p).unwrap();
|
||||
s.edit("setup", |doc, active| {
|
||||
let b = doc.bounds();
|
||||
let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap();
|
||||
let fmt = surf.format();
|
||||
let mut data = Vec::new();
|
||||
for y in b.y0..b.y1 {
|
||||
for x in b.x0..b.x1 {
|
||||
data.extend(photocraft_raster::from_rgba(&fmt, f(x, y)));
|
||||
}
|
||||
}
|
||||
surf.write_region(b, &data);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// The reference layer: red at alpha 64 | 191, transparent elsewhere.
|
||||
fn steps(depth: u64) -> Session {
|
||||
doc(depth, true, |x, y| {
|
||||
let a = match (x, y) {
|
||||
(300..=399, 300..=349) => 64.0,
|
||||
(400..=499, 300..=349) => 191.0,
|
||||
_ => 0.0,
|
||||
};
|
||||
[RED[0], RED[1], RED[2], a / 255.0]
|
||||
})
|
||||
}
|
||||
|
||||
fn click(s: &mut Session, at: [i32; 2], extra: Value) {
|
||||
let mut p = json!({"points": [at], "size": 40, "hardness": 100, "strength": 100, "protectDetail": false});
|
||||
for (k, v) in extra.as_object().unwrap() {
|
||||
p[k] = v.clone();
|
||||
}
|
||||
s.execute("paint.sharpen", p).unwrap();
|
||||
}
|
||||
|
||||
/// The active layer's pixel as 8-bit RGBA.
|
||||
fn px(s: &Session, x: i32, y: i32) -> [i32; 4] {
|
||||
let d = s.active().unwrap();
|
||||
d.doc.layer(d.active_layer.unwrap()).unwrap().surface().unwrap().rgba(x, y).map(|v| (v * 255.0).round() as i32)
|
||||
}
|
||||
|
||||
fn row(s: &Session, xs: std::ops::Range<i32>, y: i32) -> Vec<[i32; 4]> {
|
||||
xs.map(|x| px(s, x, y)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_sharpens_the_alpha_boundary_and_keeps_the_colour() {
|
||||
let mut s = steps(8);
|
||||
click(&mut s, [400, 320], json!({}));
|
||||
let got = row(&s, 397..403, 320);
|
||||
for p in &got {
|
||||
assert!((p[0] - 200).abs() <= 1 && (p[1] - 40).abs() <= 1 && (p[2] - 40).abs() <= 1, "colour must stay 200,40,40: {got:?}");
|
||||
}
|
||||
let alpha: Vec<i32> = got.iter().map(|p| p[3]).collect();
|
||||
// The low side goes down and the high side up, as with colour (the reference: 64 · 64 · 40 ·
|
||||
// 215 · 191 · 191 with #12939's kernel). Pinned from today's sigma-1 kernel.
|
||||
assert!(alpha[2] < 64 && alpha[3] > 191, "alpha boundary not sharpened: {alpha:?}");
|
||||
assert_eq!(alpha, PINNED_ALPHA, "alpha x 397..402");
|
||||
}
|
||||
|
||||
/// Alpha at x 397..402 after the reference click, with today's kernel.
|
||||
const PINNED_ALPHA: [i32; 6] = [63, 57, 26, 229, 198, 192];
|
||||
|
||||
#[test]
|
||||
fn opaque_next_to_transparent_stays_as_it_is() {
|
||||
// A red square on an otherwise empty layer; a click on its left edge.
|
||||
let mut s = doc(8, true, |x, y| {
|
||||
let a = if (100..200).contains(&x) && (100..200).contains(&y) { 1.0 } else { 0.0 };
|
||||
[RED[0], RED[1], RED[2], a]
|
||||
});
|
||||
let before = row(&s, 80..120, 150);
|
||||
click(&mut s, [100, 150], json!({}));
|
||||
let after = row(&s, 80..120, 150);
|
||||
for (b, a) in before.iter().zip(&after) {
|
||||
assert_eq!(b[3], a[3], "alpha changed: {before:?} -> {after:?}");
|
||||
if b[3] == 255 {
|
||||
assert_eq!(b, a, "an opaque pixel changed: {before:?} -> {after:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_opaque_layer_keeps_todays_result() {
|
||||
// The epic's grey 96 | 160 step on the Background: pinned from main 038d035110.
|
||||
let mut s = doc(8, false, |x, _| {
|
||||
let g = if x < 400 { 96.0 } else { 160.0 } / 255.0;
|
||||
[g, g, g, 1.0]
|
||||
});
|
||||
click(&mut s, [400, 320], json!({}));
|
||||
let grey: Vec<i32> = row(&s, 396..404, 320).iter().map(|p| p[0]).collect();
|
||||
assert_eq!(grey, [96, 96, 92, 77, 179, 164, 160, 160]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_transparent_pixels_keeps_the_alpha() {
|
||||
let mut s = steps(8);
|
||||
s.execute("layer.setProps", json!({"locks": {"transparency": true}})).unwrap();
|
||||
let before = row(&s, 390..410, 320);
|
||||
click(&mut s, [400, 320], json!({}));
|
||||
let after = row(&s, 390..410, 320);
|
||||
assert_eq!(before.iter().map(|p| p[3]).collect::<Vec<_>>(), after.iter().map(|p| p[3]).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn protect_detail_keeps_the_alpha() {
|
||||
// Protect Detail on across a semi-transparent boundary was not measured: alpha stays.
|
||||
let mut s = steps(8);
|
||||
let before = row(&s, 390..410, 320);
|
||||
click(&mut s, [400, 320], json!({"protectDetail": true}));
|
||||
let after = row(&s, 390..410, 320);
|
||||
assert_eq!(before.iter().map(|p| p[3]).collect::<Vec<_>>(), after.iter().map(|p| p[3]).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sixteen_and_32_bit_keep_the_alpha() {
|
||||
// Alpha at 16 and 32 bit was not measured: it stays as it was.
|
||||
for depth in [16, 32] {
|
||||
let mut s = steps(depth);
|
||||
let before = row(&s, 390..410, 320);
|
||||
click(&mut s, [400, 320], json!({}));
|
||||
let after = row(&s, 390..410, 320);
|
||||
assert_eq!(before.iter().map(|p| p[3]).collect::<Vec<_>>(), after.iter().map(|p| p[3]).collect::<Vec<_>>(), "{depth}-bit");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blur_is_unchanged() {
|
||||
// Blur already blurred alpha; this change is Sharpen's alone.
|
||||
let mut s = steps(16);
|
||||
s.execute("paint.blur", json!({"points": [[400, 320]], "size": 40, "hardness": 100, "strength": 100})).unwrap();
|
||||
let alpha: Vec<i32> = row(&s, 397..403, 320).iter().map(|p| p[3]).collect();
|
||||
assert!(alpha[2] > 64 && alpha[3] < 191, "16-bit Blur still blurs alpha: {alpha:?}");
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//! #14224: cloning from another document into an untagged one lands in the space that document is
|
||||
//! shown in, not in the mode's built-in default.
|
||||
|
||||
use super::*;
|
||||
use crate::color_cmds::ColorExt;
|
||||
use craft_cms::{Builtin, Transform};
|
||||
use photocraft_color::ColorMode;
|
||||
|
||||
/// Cross-document Clone Stamp over a flat sRGB block, into an untagged RGB document whose working
|
||||
/// RGB is ProPhoto-compatible. The stamp keeps its look, so its samples are re-encoded into the
|
||||
/// space the destination is displayed in.
|
||||
#[test]
|
||||
fn a_cloned_block_lands_in_the_working_space_of_the_untagged_destination() {
|
||||
let mut s = crate::session();
|
||||
let filled = [0.9f32, 0.2, 0.2, 1.0];
|
||||
s.execute("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
s.execute("edit.assignProfile", json!({"profile": "srgb"})).unwrap();
|
||||
s.edit("block", |doc, active| {
|
||||
doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(0, 0, 64, 64), &filled);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("cloneSource.set", json!({"source": [16, 16]})).unwrap();
|
||||
// Opened under the default settings, so the document stays untagged.
|
||||
s.execute("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.execute("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let dst = s.active().unwrap().doc.clone();
|
||||
assert!(dst.icc_profile.is_none(), "the destination document is untagged");
|
||||
|
||||
s.execute("paint.cloneStamp", json!({"points": [[48, 48]], "size": 8, "hardness": 100})).unwrap();
|
||||
let st = s.active().unwrap();
|
||||
let got = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().read_region(Rect::new(48, 48, 49, 49));
|
||||
|
||||
let mut out = [0.0f32; 16];
|
||||
let working = s.color().working(ColorMode::Rgb);
|
||||
Transform::new(Builtin::Srgb.profile(), &working, s.color().settings.intent(), s.color().settings.bpc).unwrap().eval(&filled[..3], &mut out).unwrap();
|
||||
let want = [out[0], out[1], out[2]];
|
||||
assert!((0..3).any(|c| (got[c] - filled[c]).abs() > 8.0 / 255.0), "the fixture must tell the two spaces apart: the stamp kept the source samples {got:?}");
|
||||
for c in 0..3 {
|
||||
assert!((got[c] - want[c]).abs() < 0.01, "the stamp landed at {:?}, not in the destination's space {want:?}", &got[..3]);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
//! Tests that run paint commands, moved from the engine-core `new_layer` tests: 1 test(s).
|
||||
|
||||
use photocraft_doc::BlendMode;
|
||||
use photocraft_doc::{BlendMode, Layer};
|
||||
|
||||
use photocraft_geom::Rect;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use photocraft_engine::new_layer::neutral_color;
|
||||
use photocraft_engine::new_layer::{greyed_modes, neutral_color};
|
||||
|
||||
use photocraft_engine::Session;
|
||||
|
||||
@@ -41,9 +41,27 @@ fn neutral_fills_leave_the_image_unchanged() {
|
||||
let s0 = busy(mode, depth);
|
||||
let doc0 = s0.active().unwrap().doc.clone();
|
||||
let shown = photocraft_compose::render(&doc0, doc0.bounds());
|
||||
for m in BlendMode::LAYER_MODES.into_iter().filter(|m| neutral_color(*m).is_some()) {
|
||||
for (m, neutral) in BlendMode::LAYER_MODES.into_iter().filter_map(|m| neutral_color(m).map(|(rgb, _)| (m, rgb))) {
|
||||
let mut s = busy(mode, depth);
|
||||
s.execute("layer.new.layer", json!({"mode": m.label(), "fillNeutral": true})).unwrap();
|
||||
let result = s.execute("layer.new.layer", json!({"mode": m.label(), "fillNeutral": true}));
|
||||
if greyed_modes(&doc0).contains(&m) {
|
||||
let error = result.unwrap_err().to_string();
|
||||
assert!(error.contains(m.label()) && error.contains("not available"), "{error}");
|
||||
assert_eq!(s.active().unwrap().doc.layers.len(), doc0.layers.len());
|
||||
// A file can still contain a layer in a mode that New Layer cannot create at this depth.
|
||||
s.edit("Imported neutral layer", |doc, active| {
|
||||
let fmt = doc.pixel_format();
|
||||
let bounds = doc.bounds();
|
||||
let mut layer = Layer::raster("Imported neutral layer", fmt);
|
||||
layer.blend = m;
|
||||
layer.surface_mut().unwrap().fill_rect(bounds, &photocraft_raster::from_rgba(&fmt, [neutral[0], neutral[1], neutral[2], 1.0]));
|
||||
*active = Some(doc.insert_above(*active, layer));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
} else {
|
||||
result.unwrap();
|
||||
}
|
||||
let doc = &s.active().unwrap().doc;
|
||||
let top = doc.layers.last().unwrap();
|
||||
assert_eq!(top.blend, m);
|
||||
|
||||
@@ -1240,7 +1240,7 @@ fn export_stages_with_renderer(
|
||||
}
|
||||
if ext == "pdf" {
|
||||
let xmp = if opts.xmp == XmpEmbed::All { doc.metadata.xmp.as_deref() } else { None };
|
||||
let mut res = pdf::export_with(doc, opts.pdf_spot_plates, xmp, ctl)?;
|
||||
let mut res = pdf::export_with_icc(doc, opts.pdf_spot_plates, xmp, opts.encode.embed_icc, ctl)?;
|
||||
if let Some(r) = renderer {
|
||||
res.warnings.push("PDF export uses CPU compositor; GPU rendering applies to flat formats".into());
|
||||
res.warnings.extend(r.drain_diagnostics());
|
||||
|
||||
+13
-1
@@ -176,6 +176,18 @@ pub fn export(doc: &Document, spot_plates: bool, ctl: &photocraft_raster::Interr
|
||||
/// PDF writer;
|
||||
/// without plates it is written as it is, and nothing when there is none.
|
||||
pub fn export_with(doc: &Document, spot_plates: bool, doc_xmp: Option<&str>, ctl: &photocraft_raster::Interrupt) -> std::result::Result<ExportResult, IoError> {
|
||||
export_with_icc(doc, spot_plates, doc_xmp, true, ctl)
|
||||
}
|
||||
|
||||
/// [`export_with`] with control over embedding the document profile in the page images.
|
||||
/// The document's profile remains available to the compositor even when it is not embedded.
|
||||
pub(crate) fn export_with_icc(
|
||||
doc: &Document,
|
||||
spot_plates: bool,
|
||||
doc_xmp: Option<&str>,
|
||||
embed_icc: bool,
|
||||
ctl: &photocraft_raster::Interrupt,
|
||||
) -> std::result::Result<ExportResult, IoError> {
|
||||
ctl.check().map_err(|_| IoError::Cancelled)?;
|
||||
let (w, h) = (usize::try_from(doc.size.width).unwrap_or(0), usize::try_from(doc.size.height).unwrap_or(0));
|
||||
if w == 0 || h == 0 {
|
||||
@@ -203,7 +215,7 @@ pub fn export_with(doc: &Document, spot_plates: bool, doc_xmp: Option<&str>, ctl
|
||||
let dpi = f64::from(doc.resolution_dpi.max(1.0));
|
||||
let paper = if doc.mode == ColorMode::Cmyk { 0.0 } else { 1.0 };
|
||||
let to8 = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||
let icc = doc.icc_profile.as_ref().map(|p| p.to_vec());
|
||||
let icc = doc.icc_profile.as_ref().filter(|_| embed_icc).map(|p| p.to_vec());
|
||||
let plate_count = if spot_plates { plate_channels(doc).count() } else { 0 };
|
||||
// Straight alpha, composited here over paper: white in RGB/Gray (1 = full light), zero ink
|
||||
// in CMYK (0 = paper).
|
||||
|
||||
@@ -202,6 +202,67 @@ fn an_embedded_profile_travels_as_iccbased() {
|
||||
assert_eq!(stream_after(&out.bytes, "/N 3 /Alternate"), vec![1, 2, 3, 4, 5, 6, 7, 8], "the profile bytes survive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_export_profile_flag_changes_tagging_without_changing_samples_or_the_document() {
|
||||
use craft_cms::Builtin;
|
||||
|
||||
for (mode, profile, device) in [
|
||||
(ColorMode::Rgb, Builtin::DisplayP3, "DeviceRGB"),
|
||||
(ColorMode::Grayscale, Builtin::SGray, "DeviceGray"),
|
||||
(ColorMode::Cmyk, Builtin::CoatedCmyk, "DeviceCMYK"),
|
||||
] {
|
||||
let mut d = doc(mode);
|
||||
let profile = profile.profile().to_bytes();
|
||||
d.icc_profile = Some(profile.clone());
|
||||
let rect = Rect::new(0, 0, 4, 2);
|
||||
let before = photocraft_compose::composite_to_surface(&d, rect, d.pixel_format(), None).read_region(rect);
|
||||
let mut off = crate::ExportOptions::default();
|
||||
off.encode.embed_icc = false;
|
||||
let tagged = crate::export(&d, "out.pdf", &crate::ExportOptions::default()).unwrap();
|
||||
let untagged = crate::export(&d, "out.pdf", &off).unwrap();
|
||||
|
||||
assert!(has(&tagged.bytes, "[/ICCBased "), "{mode:?} image uses its profile");
|
||||
let marker = format!("/N {} /Alternate", d.pixel_format().channels() - 1);
|
||||
assert_eq!(stream_after(&tagged.bytes, &marker), *profile, "the document's exact profile");
|
||||
assert!(!has(&untagged.bytes, "/ICCBased"), "OFF writes no profile reference");
|
||||
assert!(!has(&untagged.bytes, "/Alternate"), "OFF writes no profile object");
|
||||
assert!(has(&untagged.bytes, &format!("/ColorSpace /{device}")), "OFF uses the matching device space");
|
||||
assert_eq!(stream_after(&tagged.bytes, "/Subtype /Image"), stream_after(&untagged.bytes, "/Subtype /Image"), "embedding must not convert the samples");
|
||||
assert_eq!(d.icc_profile.as_deref(), Some(profile.as_ref()), "the source profile remains");
|
||||
assert_eq!(photocraft_compose::composite_to_surface(&d, rect, d.pixel_format(), None).read_region(rect), before, "source samples remain");
|
||||
assert_eq!(d.layers.len(), 1);
|
||||
assert_eq!(d.layers[0].name, "Paper");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_export_profile_flag_applies_to_every_artboard_without_changing_plates() {
|
||||
let mut d = artboard_doc(&["Front", "Back"]);
|
||||
let profile = craft_cms::Builtin::DisplayP3.profile().to_bytes();
|
||||
d.icc_profile = Some(profile.clone());
|
||||
d.channels.push(spot("Varnish", photocraft_color::Color::WHITE, &[0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.5]));
|
||||
let mut off = crate::ExportOptions::default();
|
||||
off.encode.embed_icc = false;
|
||||
let tagged = crate::export(&d, "out.pdf", &crate::ExportOptions::default()).unwrap();
|
||||
let untagged = crate::export(&d, "out.pdf", &off).unwrap();
|
||||
let on_pdf = lopdf::Document::load_mem(&tagged.bytes).unwrap();
|
||||
let off_pdf = lopdf::Document::load_mem(&untagged.bytes).unwrap();
|
||||
assert_eq!(on_pdf.get_pages().len(), 2);
|
||||
assert_eq!(off_pdf.get_pages().len(), 2);
|
||||
assert_eq!(tagged.bytes.windows(11).filter(|w| *w == b"[/ICCBased ").count(), 2, "every composite is tagged");
|
||||
assert!(!has(&untagged.bytes, "/ICCBased"));
|
||||
assert!(!has(&untagged.bytes, "/Alternate"));
|
||||
assert_eq!(untagged.bytes.windows(22).filter(|w| *w == b"/ColorSpace /DeviceRGB").count(), 2, "every composite uses device RGB");
|
||||
for (on, off) in on_pdf.get_pages().values().zip(off_pdf.get_pages().values()) {
|
||||
assert_eq!(page_image(&on_pdf, *on), page_image(&off_pdf, *off), "the artboard samples remain");
|
||||
assert_eq!(page_xobject(&on_pdf, *on, b"Sp0"), page_xobject(&off_pdf, *off, b"Sp0"), "spot density remains");
|
||||
}
|
||||
assert_eq!(xmp_of(&tagged.bytes), xmp_of(&untagged.bytes), "spot descriptions remain");
|
||||
assert_eq!(d.icc_profile.as_deref(), Some(profile.as_ref()));
|
||||
assert_eq!(d.layers.len(), 2);
|
||||
assert_eq!(d.channels[0].surface.read_region(Rect::new(0, 0, 4, 2)), vec![0.0, 0.0, 1.0, 0.5, 0.0, 0.0, 1.0, 0.5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_modes_are_refused_with_an_actionable_error() {
|
||||
let d = doc(ColorMode::Lab);
|
||||
|
||||
@@ -7,7 +7,7 @@ license.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-ipp = { git = "https://github.com/storytold/craft-libs", rev = "475f6feb712bd2db2f235d9999be61c68477ae39" }
|
||||
craft-ipp = { git = "https://github.com/storytold/craft-libs", rev = "fc3262f68babdb19a98a89c415c84c6b327073d3" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -284,6 +284,43 @@ fn pencil_1px_freehand_line_never_breaks_where_it_turns() {
|
||||
assert_eq!(reached.len(), painted.len(), "the line breaks along {path:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pencil_1px_curve_has_no_holes() {
|
||||
// #9003: a curve drawn with the 1 px Pencil broke where it bent. Each segment steps from its
|
||||
// own column, so a pixel could be skipped between the end of one segment and the next.
|
||||
let b = BrushSettings { aliased: true, hardness: 1.0, size: 1.0, ..brush() };
|
||||
let curves: [Vec<StrokePoint>; 3] = [
|
||||
(0..70).map(|i| StrokePoint::new(6.0 + 0.75 * f64::from(i), 24.0 + 13.0 * (f64::from(i) / 7.0).sin(), 1.0)).collect(),
|
||||
(0..60).map(|i| StrokePoint::new(30.0 + 20.0 * (f64::from(i) / 9.5).cos(), 24.0 + 14.0 * (f64::from(i) / 9.5).sin(), 1.0)).collect(),
|
||||
vec![
|
||||
StrokePoint::new(4.3, 30.6, 1.0),
|
||||
StrokePoint::new(9.8, 8.2, 1.0),
|
||||
StrokePoint::new(15.1, 30.9, 1.0),
|
||||
StrokePoint::new(27.6, 12.4, 1.0),
|
||||
StrokePoint::new(33.2, 31.7, 1.0),
|
||||
],
|
||||
];
|
||||
for (k, pts) in curves.iter().enumerate() {
|
||||
let s = paint(&b, pts, 64, 48);
|
||||
let painted: std::collections::BTreeSet<(i32, i32)> =
|
||||
(0..48).flat_map(|y| (0..64).map(move |x| (x, y))).filter(|&(x, y)| s.rgba(x, y)[3] > 0.0).collect();
|
||||
let Some(&start) = painted.iter().next() else { panic!("curve {k}: nothing painted") };
|
||||
let mut seen = std::collections::BTreeSet::from([start]);
|
||||
let mut todo = vec![start];
|
||||
while let Some((x, y)) = todo.pop() {
|
||||
for (dx, dy) in [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)] {
|
||||
let q = (x + dx, y + dy);
|
||||
if painted.contains(&q) && seen.insert(q) {
|
||||
todo.push(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
let holes: Vec<_> = painted.difference(&seen).collect();
|
||||
assert!(holes.is_empty(), "curve {k}: the stroke breaks before {holes:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- spacing ----------
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -283,8 +283,9 @@ pub struct PathWalker {
|
||||
/// Pixel-grid stepping for small aliased tips: the dab-centre offset inside a pixel (see
|
||||
/// [`PathWalker::pixel_grid`]).
|
||||
grid: Option<f64>,
|
||||
/// The grid cell of the last pixel-grid step, so the next segment joins it (#8040).
|
||||
cell: Option<(f64, f64)>,
|
||||
/// The last pixel-grid step, on its grid cell, so the next segment joins it (#8040). Only pixel
|
||||
/// steps set it: speed spacing and airbrush build-up leave their gaps on purpose.
|
||||
cell: Option<StrokePoint>,
|
||||
}
|
||||
|
||||
impl PathWalker {
|
||||
@@ -329,6 +330,7 @@ impl PathWalker {
|
||||
let (dm, dn) = (pm - am, pn - an);
|
||||
let n = (m1 - m0).abs();
|
||||
if !(n.is_finite() && dn.is_finite()) || n > MAX_GRID_STEPS || dm == 0.0 {
|
||||
self.cell = None;
|
||||
return false;
|
||||
}
|
||||
let dir = (m1 - m0).signum();
|
||||
@@ -342,6 +344,7 @@ impl PathWalker {
|
||||
(q.x, q.y) = if steep { (cn, c) } else { (c, cn) };
|
||||
self.bridge(&q, out);
|
||||
self.emit(q, out);
|
||||
self.cell = Some(q);
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -350,11 +353,14 @@ impl PathWalker {
|
||||
/// samples its own line, so where a freehand stroke turns, the last pixel of one segment and
|
||||
/// the first of the next can sit two pixels apart, and the 1 px Pencil line breaks (#8040).
|
||||
fn bridge(&mut self, q: &StrokePoint, out: &mut impl FnMut(StepInput)) {
|
||||
let Some((mut x, mut y)) = self.cell else { return };
|
||||
let Some(last) = self.cell else { return };
|
||||
let (mut x, mut y) = (last.x, last.y);
|
||||
let n = (q.x - x).abs().max((q.y - y).abs()).round();
|
||||
// Only a turn's small gap: a step cut off by the walker's budget is not filled in.
|
||||
if (q.x - x).abs().max((q.y - y).abs()) > MAX_BRIDGE {
|
||||
if n > MAX_BRIDGE {
|
||||
return;
|
||||
}
|
||||
let mut i = 0.0;
|
||||
while (q.x - x).abs() > 1.5 || (q.y - y).abs() > 1.5 {
|
||||
if (q.x - x).abs() > 0.5 {
|
||||
x += (q.x - x).signum();
|
||||
@@ -362,7 +368,9 @@ impl PathWalker {
|
||||
if (q.y - y).abs() > 0.5 {
|
||||
y += (q.y - y).signum();
|
||||
}
|
||||
self.emit(StrokePoint { x, y, ..*q }, out);
|
||||
// Pressure, tilt and time run on across the filled-in cells too.
|
||||
i += 1.0;
|
||||
self.emit(StrokePoint { x, y, ..lerp_pt(&last, q, i / n) }, out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,9 +394,6 @@ impl PathWalker {
|
||||
if self.step >= MAX_STEPS_PER_STROKE {
|
||||
return;
|
||||
}
|
||||
if let Some(g) = self.grid {
|
||||
self.cell = Some((grid_cell(point.x, g), grid_cell(point.y, g)));
|
||||
}
|
||||
let s = StepInput { point, direction: self.dir, initial_direction: self.initial_dir.unwrap_or(self.dir), step: self.step };
|
||||
self.step += 1;
|
||||
out(s);
|
||||
@@ -415,6 +420,9 @@ impl PathWalker {
|
||||
}
|
||||
}
|
||||
if let Some(f) = self.pending_first.take() {
|
||||
if let Some(g) = self.grid {
|
||||
self.cell = Some(StrokePoint { x: grid_cell(f.x, g), y: grid_cell(f.y, g), ..f });
|
||||
}
|
||||
self.emit_first(f, out);
|
||||
}
|
||||
if len > 1e-9 {
|
||||
@@ -438,6 +446,8 @@ impl PathWalker {
|
||||
}
|
||||
}
|
||||
Some(iv) => {
|
||||
// The stroke moves on without pixel steps: a later pixel segment starts afresh.
|
||||
self.cell = None;
|
||||
self.speed_acc += dt;
|
||||
let max_n = (len / MIN_SPEED_STEP).ceil().max(1.0) as usize;
|
||||
let mut n = 0;
|
||||
@@ -1168,6 +1178,56 @@ mod streaming_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod grid_bridge_tests {
|
||||
use super::*;
|
||||
|
||||
fn walk(mut walker: PathWalker, pts: &[StrokePoint]) -> Vec<StrokePoint> {
|
||||
let mut steps = Vec::new();
|
||||
let mut out = |s: StepInput| steps.push(s.point);
|
||||
for p in pts {
|
||||
walker.push(*p, &|_: &StrokePoint| 1.0, &mut out);
|
||||
}
|
||||
walker.finish(&mut out);
|
||||
steps
|
||||
}
|
||||
|
||||
fn at(x: f64, y: f64, time: f64) -> StrokePoint {
|
||||
StrokePoint { time, ..StrokePoint::new(x, y, 1.0) }
|
||||
}
|
||||
|
||||
/// #9059 review: the bridge joins pixel steps only. Speed spacing leaves its gaps on purpose
|
||||
/// (Spacing off: faster movement spreads the dabs out), so a pixel segment after one starts
|
||||
/// afresh instead of filling the gap back in from the cell before it.
|
||||
#[test]
|
||||
fn a_pixel_segment_after_speed_spacing_leaves_its_gap() {
|
||||
// A fast 8 px move in 60 ms: speed steps about every 1.07 px, the last (at 7.97) half a pixel
|
||||
// short of the move's end. The segment after it has no timestamps, so it takes pixel steps.
|
||||
let pts = [at(0.5, 0.5, 0.0), at(8.5, 0.5, 60.0), at(12.5, 0.5, 60.0)];
|
||||
let steps = walk(PathWalker::new(None).speed_spacing(SPEED_SPACING_MS).pixel_grid(0.5), &pts);
|
||||
let xs: Vec<f64> = steps.iter().map(|p| p.x).collect();
|
||||
assert!(xs.iter().all(|x| !(8.0..9.4).contains(x)), "no cell filled in after the last speed step: {xs:?}");
|
||||
assert!(xs.windows(2).all(|w| w[1] > w[0]), "forward only: {xs:?}");
|
||||
assert!(steps.windows(2).all(|w| w[1].time >= w[0].time), "time runs on: {steps:?}");
|
||||
}
|
||||
|
||||
/// #9059 review: a cell filled in at a bend takes the pressure and time between its two
|
||||
/// neighbours, not the later one's, so pressure dynamics change across it.
|
||||
#[test]
|
||||
fn a_bridged_cell_blends_its_neighbours_dynamics() {
|
||||
// Shallow, then steep: the steep segment's first step lands two cells from the last one.
|
||||
let bend = [(0.3, 0.6), (10.6, 3.0), (13.0, 14.0)];
|
||||
let pts: Vec<_> = bend.iter().enumerate().map(|(i, &(x, y))| StrokePoint { pressure: 0.5 * i as f32, ..at(x, y, 100.0 * i as f64) }).collect();
|
||||
let steps = walk(PathWalker::new(None).pixel_grid(0.5), &pts);
|
||||
let cell = |p: &StrokePoint| (grid_cell(p.x, 0.5), grid_cell(p.y, 0.5));
|
||||
for w in steps.windows(2) {
|
||||
let ((ax, ay), (bx, by)) = (cell(&w[0]), cell(&w[1]));
|
||||
assert!((bx - ax).abs() <= 1.0 && (by - ay).abs() <= 1.0, "8-connected: {:?} then {:?}", w[0], w[1]);
|
||||
assert!(w[1].time > w[0].time && w[1].pressure > w[0].pressure, "dynamics run on: {:?} then {:?}", w[0], w[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "smoothing_lag_tests.rs"]
|
||||
mod smoothing_lag_tests;
|
||||
@@ -0,0 +1,58 @@
|
||||
//! Canvas surround for an artboard document with a converted Background (#17309).
|
||||
|
||||
use craft::behavior::CanvasView;
|
||||
use craft::behavior::kurbo::{Point, Rect as DocRect};
|
||||
use craft::ui::canvas::{PageFrame, Pasteboard};
|
||||
use egui::{Rect, pos2};
|
||||
use photocraft_doc::Document;
|
||||
use photocraft_engine::Session;
|
||||
use photocraft_geom::Rect as PixelRect;
|
||||
use serde_json::json;
|
||||
|
||||
use super::{doc_rect, uncovered};
|
||||
|
||||
fn in_pasteboard(doc: &Document, point: Point) -> bool {
|
||||
let screen = Rect::from_min_max(pos2(-40.0, -40.0), pos2(340.0, 240.0));
|
||||
let view = CanvasView::new(screen, Point::new(150.0, 100.0), 1.0);
|
||||
let pages: Vec<_> = doc.artboards().into_iter().map(|(_, _, board)| PageFrame::new(doc_rect(board.rect))).collect();
|
||||
let point = view.to_screen(point);
|
||||
Pasteboard::quads(&view, &pages, &uncovered(doc)).iter().any(|quad| Rect::from_points(quad).contains(point))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_converted_background_shows_around_the_board_but_stops_at_the_canvas() {
|
||||
let mut session = Session::new();
|
||||
session.execute("file.new", json!({"width": 300, "height": 200, "background": "transparent"})).unwrap();
|
||||
let layer = session.active().unwrap().active_layer.unwrap();
|
||||
session.execute("select.rect", json!({"x": 20, "y": 20, "width": 40, "height": 40})).unwrap();
|
||||
session.execute("edit.fill", json!({"color": "#c81e1e"})).unwrap();
|
||||
session.execute("select.deselect", json!({})).unwrap();
|
||||
let board = session.execute("layer.new.artboardFromLayers", json!({})).unwrap()["layer"].as_u64().unwrap();
|
||||
session.execute("layer.artboard.set", json!({"layer": board, "background": "white"})).unwrap();
|
||||
let around = Point::new(200.0, 150.0);
|
||||
let on_board = Point::new(30.0, 30.0);
|
||||
let outside = Point::new(320.0, 220.0);
|
||||
let doc = &session.active().unwrap().doc;
|
||||
assert!(doc.background().is_none());
|
||||
assert_eq!(doc.artboards()[0].2.rect, PixelRect::new(20, 20, 60, 60));
|
||||
assert!(in_pasteboard(doc, around));
|
||||
assert!(!in_pasteboard(doc, on_board));
|
||||
|
||||
session.tools.background = [0.0, 200.0 / 255.0, 0.0, 1.0];
|
||||
session.execute("layer.new.backgroundFromLayer", json!({"layer": layer.0})).unwrap();
|
||||
let doc = &session.active().unwrap().doc;
|
||||
assert_eq!(doc.bounds(), PixelRect::new(0, 0, 300, 200));
|
||||
assert!(doc.is_background(layer));
|
||||
assert_eq!(uncovered(doc), [DocRect::new(0.0, 0.0, 300.0, 200.0)]);
|
||||
assert!(!in_pasteboard(doc, around), "the actual pasteboard quads leave the Background open");
|
||||
assert!(!in_pasteboard(doc, on_board));
|
||||
assert!(in_pasteboard(doc, outside), "the real pasteboard beyond the canvas is still covered");
|
||||
|
||||
let green = photocraft_compose::render(doc, PixelRect::new(200, 150, 201, 151)).px[0];
|
||||
assert!(green[0] < 0.01 && green[1] > 0.5 && green[2] < 0.01 && green[3] > 0.99, "{green:?}");
|
||||
let white = photocraft_compose::render(doc, PixelRect::new(30, 30, 31, 31)).px[0];
|
||||
assert!(white.iter().all(|channel| *channel > 0.99), "the board remains white above it: {white:?}");
|
||||
|
||||
session.execute("layer.setProps", json!({"layer": layer.0, "visible": false})).unwrap();
|
||||
assert!(in_pasteboard(&session.active().unwrap().doc, around), "a hidden Background leaves the usual pasteboard");
|
||||
}
|
||||
@@ -33,21 +33,32 @@ pub(crate) fn pages(app: &PhotocraftApp, idx: usize) -> Arc<[PageFrame]> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Where visible layers outside the boards draw: Photoshop shows those over the pasteboard, so a
|
||||
/// board added next to earlier work must not paint over it (#5712). The Background and any layer
|
||||
/// that covers the whole canvas (or may draw anywhere, such as a fill layer) are backdrop, not
|
||||
/// loose work: they keep the pasteboard. The framework subtracts these rects and the pages from
|
||||
/// the pasteboard in every view.
|
||||
/// Where visible layers outside the boards draw. Loose work stays over the pasteboard (#5712),
|
||||
/// and a visible Background opens the whole canvas (#17309) unless an ordinary canvas-wide
|
||||
/// layer keeps the pasteboard. The framework subtracts these rects and the pages from it.
|
||||
pub(crate) fn uncovered(doc: &Document) -> Vec<DocRect> {
|
||||
let canvas = doc.bounds();
|
||||
let background = doc.background().map(|b| b.id);
|
||||
doc.layers
|
||||
let background = doc.background();
|
||||
let background_id = background.map(|layer| layer.id);
|
||||
let mut regions = Vec::new();
|
||||
let mut has_canvas_wide_layer = false;
|
||||
let layer_bounds = doc
|
||||
.layers
|
||||
.iter()
|
||||
.filter(|l| l.visible && !is_artboard(l) && Some(l.id) != background)
|
||||
.filter_map(|l| photocraft_compose::composite_bounds(l, canvas))
|
||||
.filter(|b| !b.is_empty() && !b.contains_rect(&canvas))
|
||||
.map(doc_rect)
|
||||
.collect()
|
||||
.filter(|l| l.visible && !is_artboard(l) && Some(l.id) != background_id)
|
||||
.map(|l| photocraft_compose::composite_bounds(l, canvas).unwrap_or(canvas))
|
||||
.filter(|b| !b.is_empty());
|
||||
for bounds in layer_bounds {
|
||||
if bounds.contains_rect(&canvas) {
|
||||
has_canvas_wide_layer = true;
|
||||
} else {
|
||||
regions.push(doc_rect(bounds));
|
||||
}
|
||||
}
|
||||
if background.is_some_and(|layer| layer.visible) && !canvas.is_empty() && !has_canvas_wide_layer {
|
||||
regions.push(doc_rect(canvas));
|
||||
}
|
||||
regions
|
||||
}
|
||||
|
||||
fn is_artboard(l: &Layer) -> bool {
|
||||
@@ -149,16 +160,42 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn full_canvas_layers_keep_the_pasteboard() {
|
||||
// The white Background (from `app()`) and a loose layer filling the whole canvas are
|
||||
// backdrop: the pasteboard still shows outside the board.
|
||||
// An ordinary layer filling the whole canvas keeps the pasteboard, with or without a Background.
|
||||
let (mut app, _) = app();
|
||||
app.run("layer.new.artboard", json!({"rect": [0, 0, 40, 50]})).unwrap();
|
||||
let mut doc = (*app.session.active().unwrap().doc).clone();
|
||||
assert!(doc.background().is_some());
|
||||
assert!(doc.background().unwrap().visible);
|
||||
let mut px = photocraft_doc::Layer::raster("Wash", doc.pixel_format());
|
||||
px.surface_mut().unwrap().fill_rect(doc.bounds(), &[0.0, 0.0, 1.0, 1.0]);
|
||||
doc.layers.push(px);
|
||||
assert!(uncovered(&doc).is_empty());
|
||||
assert!(uncovered(&doc).is_empty(), "a visible Background does not expose the full-canvas layer");
|
||||
doc.background_mut().unwrap().locks.position = false;
|
||||
assert!(doc.background().is_none());
|
||||
assert!(uncovered(&doc).is_empty(), "the same rule applies without a Background");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_with_an_opaque_default_keep_the_pasteboard() {
|
||||
let (mut app, _) = app();
|
||||
app.run("layer.new.artboard", json!({"rect": [0, 0, 40, 50]})).unwrap();
|
||||
let mut doc = (*app.session.active().unwrap().doc).clone();
|
||||
let canvas = doc.bounds();
|
||||
assert!(doc.background().unwrap().visible);
|
||||
|
||||
// An empty ordinary layer has bounded, empty content. It does not hide the Background.
|
||||
let fmt = doc.pixel_format();
|
||||
doc.layers.push(Layer::raster("Empty", fmt));
|
||||
assert_eq!(uncovered(&doc), vec![doc_rect(canvas)]);
|
||||
|
||||
// An opaque default can paint anywhere even without allocated raster tiles.
|
||||
let mut wash = Layer::raster("Opaque wash", fmt);
|
||||
*wash.surface_mut().unwrap() = photocraft_raster::Surface::with_default(fmt, &[0.0, 0.0, 1.0, 1.0]);
|
||||
for layer in [wash.clone(), Layer::group("Wash group", vec![wash])] {
|
||||
assert!(photocraft_compose::composite_bounds(&layer, canvas).is_none());
|
||||
let mut shown = doc.clone();
|
||||
shown.layers.push(layer);
|
||||
assert!(uncovered(&shown).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -186,3 +223,7 @@ mod tests {
|
||||
assert_eq!(crate::comps_ui::target(&app), Some(b));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../artboard_top_level_background_tests.rs"]
|
||||
mod top_level_background_tests;
|
||||
@@ -2065,7 +2065,8 @@ pub(crate) fn run(
|
||||
let doc = view.to_doc(at);
|
||||
open_at(app, tool, mods, at, [doc.x, doc.y], None);
|
||||
}
|
||||
if let Some(request) = host.context {
|
||||
// A right press that ended a Gradient drag made the gradient instead (#18703).
|
||||
if let Some(request) = host.context.filter(|_| !app.canvas_tools.gradient.ended_by_right_press()) {
|
||||
// A Space-held Hand opens the Hand's menu over the current tool. A momentary Zoom opens no menu of its own, but
|
||||
// with ⌘ held the right-click is still the one that lists the layers under the pointer (#307).
|
||||
let tool = match request.momentary {
|
||||
|
||||
@@ -320,7 +320,7 @@ fn arranged(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect, active: usiz
|
||||
}
|
||||
// A clean document can leave the session immediately, so close only after the pane indices were used.
|
||||
for id in closing {
|
||||
tabs::close_document(app, ui.ctx(), id);
|
||||
tabs::close_tab(app, ui.ctx(), id);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ fn canvas_controls(
|
||||
crate::slice_ui::canvas_controls(ui, app, rect);
|
||||
crate::symmetry_ui::canvas_controls(ui, app, rect);
|
||||
crate::perspective_crop_ui::body(app, ui, rect);
|
||||
crate::analysis::canvas::body(app, ui, rect);
|
||||
crate::analysis::canvas::body(app, ui, rect, host);
|
||||
// The frame is the active document's: another document on screen shows none (#18368).
|
||||
if primary && app.session.active_index() == Some(host.idx) {
|
||||
reported.crop = super::tools::crop::show_frame(app, ui, rect);
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(super) fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, out: DocumentT
|
||||
for event in out.events {
|
||||
match event {
|
||||
DocumentTabsEvent::Selected(tab) | DocumentTabsEvent::Picked(tab) | DocumentTabsEvent::Activated(tab) => show_tab(app, tab),
|
||||
DocumentTabsEvent::CloseRequested(DocTab::Doc(id)) => close_document(app, ctx, id),
|
||||
DocumentTabsEvent::CloseRequested(DocTab::Doc(id)) => close_tab(app, ctx, id),
|
||||
DocumentTabsEvent::CloseRequested(DocTab::Opening(job)) => {
|
||||
let _ = crate::jobs_ui::cancel(app, job);
|
||||
}
|
||||
@@ -120,7 +120,18 @@ pub(super) fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, out: DocumentT
|
||||
menu
|
||||
}
|
||||
|
||||
/// The guarded close shared by the tab strip and a tiled document's title.
|
||||
/// The close affordance shared by the tab strip and a tiled document's title.
|
||||
pub(super) fn close_tab(app: &mut PhotocraftApp, ctx: &egui::Context, id: DocId) {
|
||||
if app.ui.tool == crate::Tool::PerspectiveCrop
|
||||
&& app.session.active().is_some_and(|document| document.doc.id == id)
|
||||
&& crate::perspective_crop_ui::quad(app).is_some()
|
||||
{
|
||||
return;
|
||||
}
|
||||
close_document(app, ctx, id);
|
||||
}
|
||||
|
||||
/// Closes an open document, showing its unsaved-changes prompt when needed.
|
||||
pub(super) fn close_document(app: &mut PhotocraftApp, ctx: &egui::Context, id: DocId) {
|
||||
if let Some(index) = document_index(app, id) {
|
||||
let _ = crate::menus::invoke(app, ctx, "file.close", json!({"document": index}));
|
||||
@@ -307,6 +318,10 @@ mod file_info_copyright_title_tests;
|
||||
#[path = "tab_indexed_bitmap_label_tests.rs"]
|
||||
mod tab_indexed_bitmap_label_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tabs_perspective_crop_close_tests.rs"]
|
||||
mod tabs_perspective_crop_close_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../tab_title_channel_target_tests.rs"]
|
||||
mod tab_title_channel_target_tests;
|
||||
@@ -0,0 +1,122 @@
|
||||
use egui::accesskit::Role;
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::canvas::testing::to_screen;
|
||||
use crate::perspective_crop_ui;
|
||||
use crate::theme::AppTheme;
|
||||
use crate::{PhotocraftApp, Tool};
|
||||
|
||||
type App = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn two_documents(tiled: bool) -> Result<App, String> {
|
||||
let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(|cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, AppTheme::pro());
|
||||
PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default())
|
||||
});
|
||||
let app = h.state_mut();
|
||||
for name in ["Reference.psd", "Edited.psd"] {
|
||||
app.run("file.new", json!({"width": 400, "height": 300, "name": name}))?;
|
||||
}
|
||||
app.run("layer.new.layer", json!({"name": "Retouch"}))?;
|
||||
h.run_steps(4);
|
||||
let ctx = h.ctx.clone();
|
||||
if tiled {
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.arrange.tile", json!({}))?;
|
||||
}
|
||||
h.state_mut().ui.tool = Tool::PerspectiveCrop;
|
||||
h.state_mut().ui.extras.snap = false;
|
||||
h.run_steps(6);
|
||||
assert!(h.state().session.active().is_some_and(|doc| doc.doc.name == "Edited.psd" && doc.is_dirty()));
|
||||
Ok(h)
|
||||
}
|
||||
|
||||
fn point(h: &mut App, at: Pos2) {
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.run_steps(1);
|
||||
}
|
||||
|
||||
fn press(h: &mut App, pos: Pos2, pressed: bool) {
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
}
|
||||
|
||||
fn click(h: &mut App, at: Pos2) {
|
||||
point(h, at);
|
||||
press(h, at, true);
|
||||
press(h, at, false);
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn draw_quad(h: &mut App) {
|
||||
let from = to_screen(h.state(), [40.0, 30.0]);
|
||||
let to = to_screen(h.state(), [360.0, 270.0]);
|
||||
point(h, from);
|
||||
press(h, from, true);
|
||||
point(h, to);
|
||||
press(h, to, false);
|
||||
h.run_steps(2);
|
||||
assert!(perspective_crop_ui::quad(h.state()).is_some());
|
||||
}
|
||||
|
||||
fn click_close(h: &mut App, name: &str, tiled: bool) -> Result<(), String> {
|
||||
let label = format!("Close {name}");
|
||||
let canvas = h.state().last_canvas_rect;
|
||||
let at = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.filter(|node| node.accesskit_node().label().is_some_and(|text| text.starts_with(label.as_str())))
|
||||
.map(|node| node.rect().center())
|
||||
.find(|at| canvas.contains(*at) == tiled)
|
||||
.ok_or_else(|| format!("Missing {label} button for tiled={tiled}"))?;
|
||||
click(h, at);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The active tab and active tiled title must leave the same quad editing session in place.
|
||||
#[test]
|
||||
fn a_complete_quad_protects_its_dirty_document_from_tab_and_tile_close() -> Result<(), String> {
|
||||
for tiled in [false, true] {
|
||||
let mut h = two_documents(tiled)?;
|
||||
draw_quad(&mut h);
|
||||
let quad = perspective_crop_ui::quad(h.state());
|
||||
let active = h.state().session.active().map(|doc| doc.doc.id);
|
||||
click_close(&mut h, "Edited.psd", tiled)?;
|
||||
assert!(h.state().discard.is_none(), "close opened a save prompt for tiled={tiled}");
|
||||
assert_eq!(h.state().session.documents().len(), 2);
|
||||
assert_eq!(h.state().session.active().map(|doc| doc.doc.id), active);
|
||||
assert_eq!(perspective_crop_ui::quad(h.state()), quad);
|
||||
|
||||
// Reset through the tool before testing a partial session, independently of the tab's focus.
|
||||
perspective_crop_ui::cancel(h.state_mut());
|
||||
h.run_steps(3);
|
||||
assert!(perspective_crop_ui::quad(h.state()).is_none());
|
||||
let corner = to_screen(h.state(), [40.0, 30.0]);
|
||||
click(&mut h, corner);
|
||||
assert!(perspective_crop_ui::pending(h.state()), "one corner starts a partial session");
|
||||
assert!(perspective_crop_ui::quad(h.state()).is_none());
|
||||
click_close(&mut h, "Edited.psd", tiled)?;
|
||||
assert!(h.state().discard.is_some(), "without a quad the existing dirty-document prompt is available for tiled={tiled}");
|
||||
assert_eq!(h.state().session.documents().len(), 2);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_complete_quad_leaves_other_tabs_and_the_file_close_command_available() -> Result<(), String> {
|
||||
let mut h = two_documents(false)?;
|
||||
draw_quad(&mut h);
|
||||
let quad = perspective_crop_ui::quad(h.state());
|
||||
let active = h.state().session.active().map(|doc| doc.doc.id);
|
||||
click_close(&mut h, "Reference.psd", false)?;
|
||||
assert!(h.state().discard.is_none());
|
||||
assert_eq!(h.state().session.documents().len(), 1);
|
||||
assert_eq!(h.state().session.active().map(|doc| doc.doc.id), active);
|
||||
assert_eq!(perspective_crop_ui::quad(h.state()), quad);
|
||||
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "file.close", json!({}))?;
|
||||
assert!(h.state().discard.is_some(), "File Close still asks before closing the dirty document");
|
||||
Ok(())
|
||||
}
|
||||
@@ -514,6 +514,7 @@ fn with_rig<R>(
|
||||
) -> R {
|
||||
let tool = app.ui.tool;
|
||||
let fam = family(tool);
|
||||
let scale_ruler = crate::analysis::canvas::scale_ruler_on(app, host);
|
||||
let in_gesture = ToolHost::in_gesture(ctx, host.canvas_id());
|
||||
// Tools that own state the app lends nobody are built before the scope takes the app. The Crop tool edits the active
|
||||
// document's frame, so only that document's canvas runs it (#18368); a gesture keeps it to its cancel.
|
||||
@@ -528,7 +529,7 @@ fn with_rig<R>(
|
||||
// gesture another pick began leaves it in the app, where that tool edits it: the Frame tool's press on an image
|
||||
// handle opens the session and its drag moves the box.
|
||||
let transform_open = app.ui.transform.is_some();
|
||||
let lends_transform = stand_ins && (!in_gesture || tools.gesture_pick == GesturePick::Transform);
|
||||
let lends_transform = stand_ins && !scale_ruler && (!in_gesture || tools.gesture_pick == GesturePick::Transform);
|
||||
let free_transform = if lends_transform { app.ui.transform.take() } else { None };
|
||||
let BodyShown { crop: crop_shown, transform_snapped, .. } = shown;
|
||||
let mut transform = free_transform.as_ref().map(|session| crate::transform_tool::canvas_tool(session, transform_snapped));
|
||||
@@ -539,7 +540,7 @@ fn with_rig<R>(
|
||||
(Some(tool), Some(run)) => Some(crop::pass(tool, run, ctx, crop_shown)),
|
||||
_ => None,
|
||||
};
|
||||
let command_wanted = stand_ins && !transform_open && takes_command_stand_in(tool);
|
||||
let command_wanted = stand_ins && !scale_ruler && !transform_open && takes_command_stand_in(tool);
|
||||
let alt_wanted = stand_ins && !transform_open && super::cursor_policy::alt_eyedropper(tool);
|
||||
let source_wanted = stand_ins && matches!(tool, Tool::CloneStamp | Tool::Healing);
|
||||
|
||||
@@ -653,7 +654,7 @@ fn with_rig<R>(
|
||||
alt_t = Some(retouch::source_tool(&scope, state, host));
|
||||
}
|
||||
let alt_stand_in = alt_t.is_some();
|
||||
let mut pre = Preflight { scope: &scope, inner: selected, tool, dialog: dialog_picked, outline_open, alt_stand_in };
|
||||
let mut pre = Preflight { scope: &scope, inner: selected, tool, dialog: dialog_picked || scale_ruler, outline_open, alt_stand_in };
|
||||
let mut tool_host = ToolHost::new().momentary(momentary);
|
||||
if let Some(mover) = command_t.as_mut() {
|
||||
tool_host = tool_host.stand_in(StandInKey::Command, dynamic(mover));
|
||||
@@ -806,6 +807,15 @@ pub(crate) fn tool_changed(app: &mut PhotocraftApp, ctx: &egui::Context, host: C
|
||||
app.canvas_tools = tools;
|
||||
}
|
||||
|
||||
/// Cancels the gesture that belongs to `doc`, using its original canvas even if the document has closed.
|
||||
pub(crate) fn cancel_document_gesture(app: &mut PhotocraftApp, ctx: &egui::Context, doc: photocraft_doc::DocId) {
|
||||
let Some((_, host)) = app.canvas_tools.gesture_on.filter(|(owner, _)| *owner == doc.0) else { return };
|
||||
app.canvas_tools.gesture_on = None;
|
||||
if ToolHost::in_gesture(ctx, host.canvas_id()) {
|
||||
tool_changed(app, ctx, host);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the active document's own canvas has a gesture running, for the readers with no `Context` at hand.
|
||||
pub(crate) fn in_gesture(app: &PhotocraftApp) -> bool {
|
||||
let Some(idx) = app.session.active_index() else { return false };
|
||||
|
||||
@@ -132,7 +132,11 @@ pub(crate) mod params {
|
||||
check: Some(crate::canvas_tool_menu::pen_dialogs::check),
|
||||
..ParamFamily::new(crate::canvas_tool_menu::pen_dialogs::owns, crate::canvas_tool_menu::pen_dialogs::run)
|
||||
},
|
||||
ParamFamily::new(crate::analysis::dialogs::owns, crate::analysis::dialogs::run),
|
||||
ParamFamily {
|
||||
cancel: Some(crate::analysis::dialogs::cancel),
|
||||
document: Some(crate::analysis::dialogs::document),
|
||||
..ParamFamily::new(crate::analysis::dialogs::owns, crate::analysis::dialogs::run)
|
||||
},
|
||||
ParamFamily::new(crate::layers_panel_ui::owns, crate::layers_panel_ui::run),
|
||||
ParamFamily {
|
||||
check: Some(image_processor_ui::check),
|
||||
@@ -145,6 +149,10 @@ pub(crate) mod params {
|
||||
..ParamFamily::new(|key| key == "file.automate.batch", filter_dialog::run)
|
||||
},
|
||||
ParamFamily { document: Some(file_info_document), ..ParamFamily::new(|key| key == "file.fileInfo", run_file_info) },
|
||||
ParamFamily {
|
||||
cancel: Some(filter_dialog::cancel),
|
||||
..ParamFamily::new(|key| key == crate::view_cmds::dialogs::DATA_SETS, crate::view_cmds::dialogs::data_sets_run)
|
||||
},
|
||||
ParamFamily { cancel: Some(filter_dialog::cancel), ..ParamFamily::new(crate::view_cmds::dialogs::is_form, filter_dialog::run) },
|
||||
crate::prefs_ui::PRESETS_FAMILY,
|
||||
crate::swatches_ui::SWATCH_NAME_FAMILY,
|
||||
@@ -458,6 +466,7 @@ pub(crate) const PROMPTS: &[PromptRow] = &[
|
||||
preset_group_prompt::answer,
|
||||
open_prompt::answer_prompt,
|
||||
alerts::answer,
|
||||
crate::view_cmds::dialogs::data_sets_answer,
|
||||
contact_sheet_ui::answer,
|
||||
crate::jobs_ui::answer,
|
||||
crate::gpu_status::answer,
|
||||
|
||||
@@ -13,7 +13,7 @@ use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
/// The tag of an alert opened by [`alert_once`]: the dialog preference its "Don't show again" box sets.
|
||||
/// The tag of an alert opened by [`alert_once`] or [`info_once`]: the dialog preference its "Don't show again" box sets.
|
||||
pub(crate) struct AlertOnce {
|
||||
pref: &'static str,
|
||||
}
|
||||
@@ -102,6 +102,21 @@ pub(crate) fn feed_restored_warning(app: &mut PhotocraftApp, ctx: &egui::Context
|
||||
}
|
||||
}
|
||||
|
||||
/// [`alert_once`] with the catalog's info icon beside the message, as the reference shows for the
|
||||
/// Content-Aware Fill workspace's Custom sampling alert (#16693). The other alerts keep their look.
|
||||
pub fn info_once(app: &mut PhotocraftApp, message: impl Into<String>, pref: &'static str) -> Option<DialogId> {
|
||||
if dismissed(app, pref) {
|
||||
return None;
|
||||
}
|
||||
let prompt = StandardPrompt::custom(message.into())
|
||||
.title(TITLE)
|
||||
.icon(IconId::new("info"))
|
||||
.button(PromptChoice::Proceed, tl!("OK").to_owned())
|
||||
.dont_show_again()
|
||||
.tag(AlertOnce { pref });
|
||||
open_prompt(app, prompt).ok().or_else(|| prompt_tagged::<AlertOnce>(app))
|
||||
}
|
||||
|
||||
/// Keeps "Don't show again" for the question remembered as `pref`, with the other dialog preferences.
|
||||
pub fn remember_skip(app: &mut PhotocraftApp, pref: &str) {
|
||||
remember_skip_or(app, pref, tl!("The preference could not be saved: {error}"));
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
//! reference's info alert, "Use the Sampling Brush Tool to add to the sampling area in order to
|
||||
//! fill the selected region.", with "Don't show again" and OK, once per choice. OK closes it and the
|
||||
//! Sampling Brush adds. With "Don't show again" ticked it stays closed. Other choices show nothing.
|
||||
//! #16693: the alert shows an info icon beside its text.
|
||||
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -94,6 +96,25 @@ fn choosing_custom_shows_the_alert_once_and_ok_leaves_the_brush_adding() {
|
||||
assert_eq!((d["settings"]["sampling"].as_str(), d["brushMode"].as_str()), (Some("custom"), Some("add")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_alert_shows_an_icon_beside_its_text() {
|
||||
let mut app = app();
|
||||
open(&mut app).unwrap();
|
||||
choose(&mut app, "custom");
|
||||
let mut h = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1440.0, 900.0))
|
||||
.with_max_steps(16)
|
||||
.with_context(app.ctx().clone())
|
||||
.build_ui_state(|ui, app: &mut Box<PhotocraftApp>| crate::dialogs::run(app, ui), app);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
let title = h.get_by_role_and_label(Role::Heading, "PhotoCraft").rect();
|
||||
let message = h.get_by_label_contains(CUSTOM_SAMPLING_ALERT).rect();
|
||||
// The prompt draws the icon unnamed, so it shows in the layout: the title starts at the content's start, the
|
||||
// message after the icon on its row.
|
||||
assert!(message.left() > title.left() + 8.0, "the message starts after the icon: {message:?} vs title {title:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_choice_of_custom_shows_it() {
|
||||
let mut app = app();
|
||||
|
||||
@@ -316,7 +316,7 @@ pub(crate) fn take(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
if custom_chosen {
|
||||
let _ = crate::dialogs::alerts::alert_once(app, tl!(CUSTOM_SAMPLING_ALERT), CUSTOM_SAMPLING_PREF);
|
||||
let _ = crate::dialogs::alerts::info_once(app, tl!(CUSTOM_SAMPLING_ALERT), CUSTOM_SAMPLING_PREF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,14 +12,7 @@ use serde_json::json;
|
||||
/// Camera Raw Defaults › Sharpen For: output sharpening, folded into the Camera Raw step `rest`
|
||||
/// as the workflow's Sharpen For is. Returns what it applied.
|
||||
pub(super) fn output_sharpening(d: &photocraft_engine::prefs::RawDefaults, rest: &mut CameraRaw) -> Vec<&'static str> {
|
||||
match d.sharpen_for.preset() {
|
||||
Some((amount, radius)) if rest.sharpen_amount == 0.0 => {
|
||||
rest.sharpen_amount = amount;
|
||||
rest.sharpen_radius = radius;
|
||||
vec!["sharpenFor"]
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
if d.apply_output_sharpening(rest) { vec!["sharpenFor"] } else { Vec::new() }
|
||||
}
|
||||
|
||||
/// The Camera Raw Defaults [`apply_raw_conversions`] applies. Resolution is not among them: the
|
||||
|
||||
@@ -212,6 +212,14 @@ fn query_key(app: &PhotocraftApp, params: &Value) -> u64 {
|
||||
(setup.profile.content_hash(), setup.intent, setup.bpc, setup.simulate_paper, setup.kind).hash(&mut key);
|
||||
(proof.enabled, proof.gamut_warning, proof.gamut_threshold.to_bits()).hash(&mut key);
|
||||
}
|
||||
// Both fast paths judge colour in the space the session shows the document in (#14224): the
|
||||
// sampled-colour box runs through the document's profile, and so does the gamut mask, which for
|
||||
// an untagged RGB or Grayscale document is Color Settings' working space. Hash the setting
|
||||
// rather than the resolved profile, for the same reason as the proof setup above.
|
||||
let color = app.session.color();
|
||||
for mode in [photocraft_doc::ColorMode::Rgb, photocraft_doc::ColorMode::Grayscale] {
|
||||
color.working_space_spec(mode).hash(&mut key);
|
||||
}
|
||||
key.finish().max(1)
|
||||
}
|
||||
|
||||
@@ -264,7 +272,7 @@ fn proxy_mask(app: &PhotocraftApp, proxy: &Document, k: u32, params: &Value) ->
|
||||
}
|
||||
if params.get("select").and_then(Value::as_str) == Some("outOfGamut") {
|
||||
let pv = app.session.color().proof(proxy.id);
|
||||
let (m, _) = photocraft_engine::color_cmds::gamut_mask(proxy, &pv.setup, pv.gamut_threshold).map_err(|e| e.to_string())?;
|
||||
let (m, _) = app.session.color().gamut_mask(proxy, &pv.setup, pv.gamut_threshold).map_err(|e| e.to_string())?;
|
||||
let invert = params.get("invert").and_then(Value::as_bool).unwrap_or(false);
|
||||
let mut mask: Vec<f32> = m.iter().map(|v| f32::from(*v) / 255.0).map(|v| if invert { 1.0 - v } else { v }).collect();
|
||||
scope_preview(proxy, params, &mut mask);
|
||||
|
||||
@@ -130,6 +130,39 @@ fn preview_cache_refreshes_after_foreground_and_proof_changes() {
|
||||
assert_ne!(query_key(&app, &p), query_key(&app, &json!({"select": "outOfGamut", "invert": true})));
|
||||
}
|
||||
|
||||
/// An untagged RGB strip whose colours straddle coated CMYK: read as sRGB some of them are inside
|
||||
/// it, read as ProPhoto the same numbers are far outside.
|
||||
fn untagged_strip_session() -> photocraft_engine::Session {
|
||||
let colours = [[0.95f32, 0.05, 0.05], [0.8, 0.3, 0.3], [0.6, 0.1, 0.1], [0.3, 0.85, 0.3], [0.1, 0.4, 0.9], [0.45, 0.45, 0.95]];
|
||||
let mut doc = Document::with_background("strip", Size::new(24, 4), ColorMode::Rgb, SampleType::U8, Color::WHITE);
|
||||
{
|
||||
let bg = doc.layers[0].surface_mut().unwrap();
|
||||
for (i, c) in colours.iter().enumerate() {
|
||||
bg.fill_rect(GRect::new(i as i32 * 4, 0, i as i32 * 4 + 4, 4), &[c[0], c[1], c[2], 1.0]);
|
||||
}
|
||||
}
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.add_document(doc, None);
|
||||
s
|
||||
}
|
||||
|
||||
/// #14224: both fast preview paths judge colour in the space the session shows the document in, so
|
||||
/// Color Settings' working space belongs in the key the cached picture is kept under - otherwise the
|
||||
/// dialog keeps showing the old Out of Gamut mask after the setting moves.
|
||||
#[test]
|
||||
fn preview_cache_refreshes_after_a_working_space_change() {
|
||||
let mut app = PhotocraftApp::new(untagged_strip_session(), crate::Services::default());
|
||||
app.run("view.proofSetup", json!({"profile": "coated-cmyk", "intent": "perceptual"})).unwrap();
|
||||
let p = json!({"select": "outOfGamut"});
|
||||
let doc = app.session.active().unwrap().doc.clone();
|
||||
let before = proxy_mask(&app, &doc, 1, &p).unwrap();
|
||||
let key_before = query_key(&app, &p);
|
||||
app.run("edit.colorSettings", json!({"workingRgb": "prophoto-compat"})).unwrap();
|
||||
let after = proxy_mask(&app, &doc, 1, &p).unwrap();
|
||||
assert_ne!(before, after, "the preview marks the same pixels whatever the working space of an untagged document");
|
||||
assert_ne!(key_before, query_key(&app, &p), "and the cache key holds onto the picture the setting has made stale");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eyedropper_hover_reuses_preview_textures_without_sampling() {
|
||||
let mut app = app_with_doc();
|
||||
|
||||
@@ -271,3 +271,10 @@ fn monitor_color_follows_a_monitor_profile_change() {
|
||||
let c = &app.session.color().settings;
|
||||
assert_eq!((c.preset.as_str(), c.working_rgb.as_str(), c.monitor_profile.as_str()), ("Monitor Color", "display-p3", "display-p3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_setup_has_a_spelled_out_label_that_reads_its_name_in_english() {
|
||||
for name in COLOR_SETTINGS_PRESETS {
|
||||
assert_eq!(preset_label(name), Some(name), "a setup missing from `preset_label`, or a misspelled key, shows untranslated");
|
||||
}
|
||||
}
|
||||
@@ -1099,3 +1099,29 @@ fn profile_and_metadata_follow_the_existing_exporter() {
|
||||
assert!(kept.windows(b"secret".len()).any(|w| w == b"secret"));
|
||||
assert_eq!(doc, before);
|
||||
}
|
||||
|
||||
/// A panorama's preview is the exported picture alone: the texture Export As shows has the export's
|
||||
/// proportions, and an opaque image previews opaque. A preview padded to a square would read as
|
||||
/// transparent bands above and below a wide image, as if the exported file had them.
|
||||
#[test]
|
||||
fn a_panorama_previews_at_its_own_proportions_with_no_transparent_bands() {
|
||||
let mut h = harness(export_app(2172, 724));
|
||||
super::open(h.state_mut()).unwrap();
|
||||
settle_preview(&mut h);
|
||||
let [w, h_px] = h.state().export_open.as_ref().expect("Export As is open").texture.as_ref().expect("the preview is shown").size();
|
||||
assert!(w > h_px, "the preview is wider than tall: {w} × {h_px}");
|
||||
let ratio = w as f64 / h_px as f64;
|
||||
assert!((ratio - 3.0).abs() < 0.02, "the preview keeps 2172 × 724's proportions: {w} × {h_px}");
|
||||
|
||||
let doc = Document::with_background(
|
||||
"panorama",
|
||||
photocraft_doc::Size::new(2172, 724),
|
||||
photocraft_doc::ColorMode::Rgb,
|
||||
photocraft_doc::SampleType::U8,
|
||||
photocraft_doc::Color::WHITE,
|
||||
);
|
||||
let f = Map::from_iter([("format".into(), json!("jpg")), ("scale".into(), json!(100))]);
|
||||
let pixels = super::preview_pixels(&default_preview_proxy(&doc, &f).unwrap(), None);
|
||||
assert_eq!(pixels.rgba.len(), pixels.width * pixels.height * 4);
|
||||
assert!(pixels.rgba.as_chunks::<4>().0.iter().all(|px| px[3] == 255), "every preview pixel of an opaque image is opaque");
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
use craft::behavior::EditEvent;
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, Outcome as _, Props as _, Show as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, StackDialog as _};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, NumberUnit, Param, ParamKind};
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use craft::ui::runtime::env::{Label, UnitKind};
|
||||
use craft::ui::runtime::requests::PathKind;
|
||||
use craft_print::ui::{Destination, Duplex, HostedPrint, PrintAnswer, PrintFinish, PrintMarks, PrintSection, PrintSheet, Printer, Settings, State};
|
||||
use serde_json::{Map, Value, json};
|
||||
@@ -146,7 +148,17 @@ pub fn open_print(app: &mut PhotocraftApp) -> DialogId {
|
||||
}
|
||||
}
|
||||
write_settings(&mut fields, &state.settings);
|
||||
let sections = sections(&fields);
|
||||
let document_profile = app.session.active().map(|state| {
|
||||
let doc = &state.doc;
|
||||
if doc.icc_profile.is_some() {
|
||||
Label::from(crate::panels::chrome_ui::profile_name(doc))
|
||||
} else if doc.mode == photocraft_doc::ColorMode::Lab {
|
||||
Label::from(tl!("Lab Color"))
|
||||
} else {
|
||||
Label::from(tl!(crate::canvas::mode_label(doc)))
|
||||
}
|
||||
});
|
||||
let sections = sections(&fields, document_profile);
|
||||
app.framework.dialogs.open(HostedPrint::new(state, fields, sections).json_form(|fields, listing| {
|
||||
if fields.text("paper") == Some("custom") {
|
||||
listing.insert("paper".into(), print_params(fields)["paper"].clone());
|
||||
@@ -157,7 +169,7 @@ pub fn open_print(app: &mut PhotocraftApp) -> DialogId {
|
||||
/// The dialog's sections under the printer panel, as rows over today's `file.print` keys.
|
||||
/// Lengths are shown in the unit `file.print` keeps them in: positions in inches, the custom paper
|
||||
/// in points.
|
||||
pub(super) fn sections(fields: &DialogFields) -> Vec<PrintSection> {
|
||||
fn sections(fields: &DialogFields, document_profile: Option<Label>) -> Vec<PrintSection> {
|
||||
let choice = |options: &[(&str, &'static str)], default: &str| {
|
||||
ParamKind::choice(options.iter().map(|(k, l)| ((*k).to_string(), (*l).into())).collect(), Some(default.to_string()))
|
||||
};
|
||||
@@ -210,43 +222,68 @@ pub(super) fn sections(fields: &DialogFields) -> Vec<PrintSection> {
|
||||
let position = |key: &str, label: &'static str| {
|
||||
Param::number_in_units(key, label, 0.0, 0.1, 2, "units", lengths(1.0)).bounds(Some(-limit), Some(limit)).enabled_when("center", FieldValue::Bool(false))
|
||||
};
|
||||
let on = |key: &str| (key.to_string(), FieldValue::Text("photocraftManages".into()));
|
||||
let (on_key, on_value) = on("colorHandling");
|
||||
let printer_manages = "printerManages";
|
||||
let photocraft_manages = "photocraftManages";
|
||||
let managed = |row: Param| row.visible_when_in("colorHandling", [printer_manages, photocraft_manages]);
|
||||
let warning = |key, text: Label, handling| Param::read_only_text(key, text.clone(), text).full_width().visible_when("colorHandling", handling);
|
||||
let has_document = document_profile.is_some();
|
||||
let mark = |key: &str, label: &'static str| Param::new(key, label, ParamKind::bool(false));
|
||||
|
||||
vec![
|
||||
PrintSection::new(
|
||||
tl!("Color Management"),
|
||||
vec![
|
||||
warning(
|
||||
"enablePrinterColorManagement",
|
||||
tl!("Remember to enable the printer's color management in the print settings dialog box.").into(),
|
||||
printer_manages,
|
||||
),
|
||||
warning(
|
||||
"disablePrinterColorManagement",
|
||||
tl!("Remember to disable the printer's color management in the print settings dialog box.").into(),
|
||||
photocraft_manages,
|
||||
),
|
||||
managed(Param::read_only_text("documentProfile", tl!("Document Profile"), document_profile.unwrap_or_default()).shown(has_document)),
|
||||
Param::new(
|
||||
"colorHandling",
|
||||
tl!("Color Management"),
|
||||
tl!("Color Handling"),
|
||||
choice(
|
||||
&[
|
||||
("printerManages", tl!("Printer Manages Colors")),
|
||||
("photocraftManages", tl!("PhotoCraft Manages Colors")),
|
||||
(printer_manages, tl!("Printer Manages Colors")),
|
||||
(photocraft_manages, tl!("PhotoCraft Manages Colors")),
|
||||
("noColorManagement", tl!("No Color Management")),
|
||||
],
|
||||
"printerManages",
|
||||
printer_manages,
|
||||
),
|
||||
),
|
||||
Param::new("printerProfile", tl!("Profile"), ParamKind::choice(profiles, Some("coated-cmyk".into())))
|
||||
.visible_when(on_key.clone(), on_value.clone()),
|
||||
Param::new(
|
||||
"intent",
|
||||
tl!("Mode"),
|
||||
choice(
|
||||
&[
|
||||
("perceptual", tl!("Perceptual")),
|
||||
("relative", tl!("Relative Colorimetric")),
|
||||
("saturation", tl!("Saturation")),
|
||||
("absolute", tl!("Absolute Colorimetric")),
|
||||
],
|
||||
"relative",
|
||||
),
|
||||
)
|
||||
.visible_when(on_key.clone(), on_value.clone()),
|
||||
Param::new("bpc", tl!("Black Point Compensation"), ParamKind::bool(true)).visible_when(on_key, on_value),
|
||||
managed(
|
||||
Param::new("printerProfile", tl!("Printer Profile"), ParamKind::choice(profiles, Some("coated-cmyk".into())))
|
||||
.enabled_when("colorHandling", photocraft_manages),
|
||||
),
|
||||
managed(
|
||||
Param::new(
|
||||
"intent",
|
||||
tl!("Rendering Intent"),
|
||||
choice(
|
||||
&[
|
||||
("perceptual", tl!("Perceptual")),
|
||||
("relative", tl!("Relative Colorimetric")),
|
||||
("saturation", tl!("Saturation")),
|
||||
("absolute", tl!("Absolute Colorimetric")),
|
||||
],
|
||||
"relative",
|
||||
),
|
||||
)
|
||||
.enabled_when("colorHandling", photocraft_manages),
|
||||
),
|
||||
// Printer-managed color always displays an unchecked box without touching the stored setting.
|
||||
Param::custom("printerManagedBpc", Label::Empty, |ui, _, _| {
|
||||
Checkbox::new(Bind::given(false)).label(tl!("Black Point Compensation")).enabled(false).show(ui).response().clone()
|
||||
})
|
||||
.full_width()
|
||||
.disabled()
|
||||
.visible_when("colorHandling", printer_manages),
|
||||
Param::new("bpc", tl!("Black Point Compensation"), ParamKind::bool(true)).visible_when("colorHandling", photocraft_manages),
|
||||
],
|
||||
),
|
||||
PrintSection::new(
|
||||
@@ -270,7 +307,7 @@ pub(super) fn sections(fields: &DialogFields) -> Vec<PrintSection> {
|
||||
position("top", tl!("Top")),
|
||||
position("left", tl!("Left")),
|
||||
Param::new("scaleToFit", tl!("Scale to Fit Media"), ParamKind::bool(false)),
|
||||
Param::new("scale", tl!("Scale (%)"), ParamKind::number(Some(1.0), Some(1000.0), 100.0, 1.0, 2))
|
||||
Param::new("scale", tl!("Scale (%)"), ParamKind::number(Some(0.01), Some(1500.0), 100.0, 1.0, 2))
|
||||
.enabled_when("scaleToFit", FieldValue::Bool(false)),
|
||||
],
|
||||
),
|
||||
@@ -292,6 +329,10 @@ pub(super) fn sections(fields: &DialogFields) -> Vec<PrintSection> {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../../../tests/it/print_color_section_layout.rs"]
|
||||
mod print_color_section_layout;
|
||||
|
||||
/// The system's printers, as the engine lists them without waiting: the driver list where the
|
||||
/// driver API answers (Windows), else the spooler's.
|
||||
fn take_printer_lists(app: &mut PhotocraftApp) -> Vec<Printer> {
|
||||
|
||||
@@ -49,7 +49,8 @@ pub(super) fn row(label: Label) -> Param {
|
||||
let name = label.clone();
|
||||
Param::custom(KEY, label, move |ui, fields, _| {
|
||||
let mut entries = Vec::new();
|
||||
let named = COLOR_SETTINGS_PRESETS.iter().map(|n| (*n, *n));
|
||||
// The labels are translated; the values stay the English names scripts and saved settings use.
|
||||
let named = COLOR_SETTINGS_PRESETS.iter().map(|n| (*n, preset_label(n).unwrap_or(n)));
|
||||
for (value, label) in [(CUSTOM_SETTINGS, tl!("Custom")), (OTHER, tl!("Other"))].into_iter().chain(named) {
|
||||
if GROUP_STARTS.contains(&value) {
|
||||
entries.push(Entry::separator());
|
||||
@@ -64,6 +65,27 @@ pub(super) fn row(label: Label) -> Param {
|
||||
})
|
||||
}
|
||||
|
||||
/// A named setup's translated label, spelled out so `cargo xtask i18n-coverage` lists each one;
|
||||
/// `None` for a name the menu doesn't have.
|
||||
fn preset_label(name: &str) -> Option<&'static str> {
|
||||
Some(match name {
|
||||
"Europe General Purpose 3" => tl!("Europe General Purpose 3"),
|
||||
"Europe Prepress 3" => tl!("Europe Prepress 3"),
|
||||
"Europe Web/Internet 2" => tl!("Europe Web/Internet 2"),
|
||||
"Monitor Color" => tl!("Monitor Color"),
|
||||
"Japan Color for Newspaper" => tl!("Japan Color for Newspaper"),
|
||||
"Japan General Purpose 2" => tl!("Japan General Purpose 2"),
|
||||
"Japan Magazine Advertisement Color" => tl!("Japan Magazine Advertisement Color"),
|
||||
"Japan Prepress 2" => tl!("Japan Prepress 2"),
|
||||
"Japan Web/Internet" => tl!("Japan Web/Internet"),
|
||||
"North America General Purpose 2" => tl!("North America General Purpose 2"),
|
||||
"North America Newspaper" => tl!("North America Newspaper"),
|
||||
"North America Prepress 2" => tl!("North America Prepress 2"),
|
||||
"North America Web/Internet" => tl!("North America Web/Internet"),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Blend Text Colors Using Gamma, in place of the spec's two rows: the checkbox, with the field
|
||||
/// beside it. The field shows two decimals, 1.00 to 3.00, and stays editable while the box is off;
|
||||
/// a value typed or stepped into it checks the box. A value typed out of range is held to the
|
||||
|
||||
@@ -139,12 +139,14 @@ pub(crate) struct PcGallerySource {
|
||||
background: [f32; 4],
|
||||
/// The middle of the layer, about 4× the thumbnail size, sampled down to the thumbnail size.
|
||||
thumb_src: Surface,
|
||||
/// Keeps the shared thumbnail cache from reusing pictures from an earlier Gallery.
|
||||
thumb_revision: Revision,
|
||||
catalog: PcCatalog,
|
||||
preview: SharedPicture,
|
||||
}
|
||||
|
||||
impl PcGallerySource {
|
||||
fn new(src: Surface, canvas: Rect, target: Value, colours: [[f32; 4]; 2]) -> Self {
|
||||
fn new(src: Surface, canvas: Rect, target: Value, colours: [[f32; 4]; 2], thumb_revision: Revision) -> Self {
|
||||
let cb = src.content_bounds().intersect(&canvas);
|
||||
let cb = if cb.is_empty() { canvas } else { cb };
|
||||
let k = ((cb.width() as usize / (THUMB[0] * 4)).min(cb.height() as usize / (THUMB[1] * 4))).max(1) as u32;
|
||||
@@ -152,7 +154,17 @@ impl PcGallerySource {
|
||||
let (cx, cy) = ((cb.x0 + cb.x1) / 2, (cb.y0 + cb.y1) / 2);
|
||||
let thumb_src = sample(&src, Rect::new(cx - tw / 2, cy - th / 2, cx - tw / 2 + tw, cy - th / 2 + th), k);
|
||||
let preview = SharedPicture::new(PixelSize::new(canvas.width().max(1), canvas.height().max(1)));
|
||||
PcGallerySource { src: Arc::new(src), canvas, target, foreground: colours[0], background: colours[1], thumb_src, catalog: PcCatalog, preview }
|
||||
PcGallerySource {
|
||||
src: Arc::new(src),
|
||||
canvas,
|
||||
target,
|
||||
foreground: colours[0],
|
||||
background: colours[1],
|
||||
thumb_src,
|
||||
thumb_revision,
|
||||
catalog: PcCatalog,
|
||||
preview,
|
||||
}
|
||||
}
|
||||
|
||||
/// The command params for `effects`: what OK runs and what the preview renders.
|
||||
@@ -213,9 +225,9 @@ impl FilterGallerySource for PcGallerySource {
|
||||
}
|
||||
|
||||
impl ThumbSource<GalleryThumb> for PcGallerySource {
|
||||
/// The crop and colours are fixed while the gallery is open, so a filter's thumbnail never changes.
|
||||
fn revision(&self, key: &GalleryThumb, _request: &ThumbRequest) -> Revision {
|
||||
Revision::of(&key.filter)
|
||||
/// All filters use the same immutable source, and each filter has its own cache key.
|
||||
fn revision(&self, _key: &GalleryThumb, _request: &ThumbRequest) -> Revision {
|
||||
self.thumb_revision
|
||||
}
|
||||
|
||||
fn render(&self, key: &GalleryThumb, _request: &ThumbRequest) -> ThumbRender {
|
||||
@@ -501,7 +513,8 @@ fn open_on(
|
||||
session.effects = effects;
|
||||
}
|
||||
let size = PixelSize::new(canvas.width().max(1), canvas.height().max(1));
|
||||
let source = Arc::new(PcGallerySource::new(src, canvas, target, colours));
|
||||
let thumb_revision = Revision::new(app.texture_serials.mint());
|
||||
let source = Arc::new(PcGallerySource::new(src, canvas, target, colours, thumb_revision));
|
||||
let workspace = FilterGalleryWorkspace::new(FilterGalleryOpen::new(size, layer_name, session));
|
||||
|
||||
let shared: Arc<dyn FilterGallerySource> = source.clone();
|
||||
|
||||
@@ -408,3 +408,67 @@ fn glow_color_keeps_exact_floats_until_a_new_pick_and_stores_linear() {
|
||||
};
|
||||
assert!(near(&recorded(h.state())[..3], &[0.21586, 0.05127, 1.0], 1e-3), "{:?}", recorded(h.state()));
|
||||
}
|
||||
|
||||
type GalleryHarness = egui_kittest::Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn open_gallery(mut app: Box<PhotocraftApp>) -> GalleryHarness {
|
||||
let ctx = app.ctx().clone();
|
||||
crate::menus::invoke(&mut app, &ctx, KEY, json!({})).unwrap();
|
||||
let mut gallery = egui_kittest::Harness::builder().with_context(ctx).with_size(egui::vec2(1500.0, 950.0)).with_pixels_per_point(1.25).build_ui_state(
|
||||
|ui, app: &mut Box<PhotocraftApp>| {
|
||||
app.framework.dialogs.run(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
gallery.run_steps(4);
|
||||
gallery
|
||||
}
|
||||
|
||||
fn painted_thumbnails(gallery: &GalleryHarness) -> Vec<[usize; 2]> {
|
||||
let output = gallery.output();
|
||||
let painted = gallery.ctx.tessellate(output.shapes.clone(), output.pixels_per_point);
|
||||
let drawn: std::collections::HashSet<_> = painted
|
||||
.iter()
|
||||
.filter_map(|item| match &item.primitive {
|
||||
egui::epaint::Primitive::Mesh(mesh) => Some(mesh.texture_id),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
gallery
|
||||
.ctx
|
||||
.tex_manager()
|
||||
.read()
|
||||
.allocated()
|
||||
.filter(|(id, meta)| drawn.contains(id) && meta.name.contains("filterGallery.thumbs"))
|
||||
.map(|(_, meta)| meta.size)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gallery_browser_paints_filter_thumbnails() {
|
||||
let mut app = app();
|
||||
app.run("edit.fill", json!({"color": "#3366cc"})).unwrap();
|
||||
let gallery = open_gallery(app);
|
||||
let artistic = GalleryFilter::ALL.iter().filter(|f| f.category() == GalleryFilter::ColoredPencil.category()).count();
|
||||
let thumbs = painted_thumbnails(&gallery);
|
||||
assert_eq!(thumbs.len(), artistic, "every filter in the open Artistic category is painted");
|
||||
assert!(thumbs.iter().all(|size| size[0] > 1 && size[1] > 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gallery_replaces_blank_thumbnails_when_reopened_on_paint() {
|
||||
let mut app = app();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
let mut gallery = open_gallery(app);
|
||||
let blank = painted_thumbnails(&gallery);
|
||||
assert!(!blank.is_empty() && blank.iter().all(|size| *size == [1, 1]), "the first layer has no pixels");
|
||||
let ctx = gallery.ctx.clone();
|
||||
ui(gallery.state_mut(), json!({"cancel": true})).unwrap();
|
||||
take(gallery.state_mut(), &ctx);
|
||||
gallery.state_mut().run("edit.fill", json!({"color": "#3366cc"})).unwrap();
|
||||
crate::menus::invoke(gallery.state_mut(), &ctx, KEY, json!({})).unwrap();
|
||||
gallery.run_steps(4);
|
||||
let painted = painted_thumbnails(&gallery);
|
||||
assert_eq!(painted.len(), blank.len(), "every Artistic tile has a picture");
|
||||
assert!(painted.iter().all(|size| size[0] > 1 && size[1] > 1), "reopening still paints blank previews: {painted:?}");
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
//! #17369: New Layer keeps every mode listed and refuses the unavailable modes in measured document types.
|
||||
|
||||
use craft::ui::patterns::form_dialogs::ParamKind;
|
||||
use egui::accesskit::Role;
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use photocraft_doc::BlendMode;
|
||||
use photocraft_engine::{Session, float_cmds};
|
||||
use serde_json::json;
|
||||
|
||||
use super::{COMMAND, layer_mode_param};
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
type H = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
const RGB_32: &[&str] = &[
|
||||
"Color Burn",
|
||||
"Linear Burn",
|
||||
"Screen",
|
||||
"Color Dodge",
|
||||
"Overlay",
|
||||
"Soft Light",
|
||||
"Hard Light",
|
||||
"Vivid Light",
|
||||
"Linear Light",
|
||||
"Pin Light",
|
||||
"Hard Mix",
|
||||
"Exclusion",
|
||||
];
|
||||
const LAB_8: &[&str] = &["Darken", "Color Burn", "Lighten", "Color Dodge", "Difference", "Exclusion", "Subtract", "Divide"];
|
||||
|
||||
fn document(mode: &str, depth: u32) -> Session {
|
||||
let mut session = Session::new();
|
||||
session.execute("file.new", json!({"width": 16, "height": 16, "mode": mode, "depth": depth})).unwrap();
|
||||
session
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_mode_row_greys_only_the_measured_unavailable_modes() {
|
||||
for (mode, depth, unavailable) in [
|
||||
("rgb", 32, RGB_32),
|
||||
("lab", 8, LAB_8),
|
||||
("grayscale", 8, &[][..]),
|
||||
("lab", 16, &[][..]),
|
||||
("rgb", 8, &[][..]),
|
||||
("rgb", 16, &[][..]),
|
||||
("cmyk", 8, &[][..]),
|
||||
("bitmap", 1, &[][..]),
|
||||
] {
|
||||
let session = document(mode, depth);
|
||||
let row = layer_mode_param(&session.active().unwrap().doc);
|
||||
let ParamKind::Blend { modes, .. } = &row.kind else { panic!("Mode is a blend row") };
|
||||
assert_eq!(modes.len(), BlendMode::LAYER_MODES.len(), "{mode} {depth}: every mode is listed");
|
||||
for blend in BlendMode::LAYER_MODES {
|
||||
assert_eq!(row.option_enabled(blend.key()), !unavailable.contains(&blend.label()), "{mode} {depth}: {}", blend.label());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lab_dialog() -> H {
|
||||
let mut app = PhotocraftApp::new(document("lab", 8), crate::Services::default());
|
||||
let ctx = app.ctx().clone();
|
||||
crate::menus::invoke(&mut app, &ctx, COMMAND, json!({})).unwrap();
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1280.0, 800.0))
|
||||
.with_max_steps(64)
|
||||
.with_context(ctx)
|
||||
.build_ui_state(|ui, app: &mut Box<PhotocraftApp>| crate::dialogs::run(app, ui), app);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn pointer_click(h: &mut H, pos: Pos2) {
|
||||
h.event(Event::PointerMoved(pos));
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_mode_list(h: &mut H) {
|
||||
let pos = h.get_by_role_and_label(Role::ComboBox, "Mode").rect().center();
|
||||
pointer_click(h, pos);
|
||||
}
|
||||
|
||||
fn assert_mode(h: &H, mode: &str) {
|
||||
assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Mode").accesskit_node().value().as_deref(), Some(mode));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_picker_skips_an_unavailable_mode_for_pointer_arrows_and_type_ahead() {
|
||||
let mut h = lab_dialog();
|
||||
open_mode_list(&mut h);
|
||||
let darken = h.get_by_role_and_label(Role::ListBoxOption, "Darken");
|
||||
assert!(darken.accesskit_node().is_disabled());
|
||||
let pos = darken.rect().center();
|
||||
pointer_click(&mut h, pos);
|
||||
assert_mode(&h, "Normal");
|
||||
|
||||
let pos = h.get_by_role_and_label(Role::ListBoxOption, "Dissolve").rect().center();
|
||||
pointer_click(&mut h, pos);
|
||||
assert_mode(&h, "Dissolve");
|
||||
open_mode_list(&mut h);
|
||||
h.key_press(Key::ArrowDown);
|
||||
h.run_steps(3);
|
||||
assert_mode(&h, "Multiply");
|
||||
|
||||
h.event(Event::Text("Darken".into()));
|
||||
h.run_steps(3);
|
||||
assert_mode(&h, "Multiply");
|
||||
// Start a second search after the picker's one-second type-ahead buffer expires.
|
||||
let next_search = h.ctx.input(|input| input.time) + 1.25;
|
||||
h.input_mut().time = Some(next_search);
|
||||
h.event(Event::Text("Hue".into()));
|
||||
h.run_steps(3);
|
||||
assert_mode(&h, "Hue");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_new_layer_command_refuses_greyed_modes_and_keeps_other_modes_available() {
|
||||
for (mode, depth, unavailable, allowed) in [
|
||||
("rgb", 32, RGB_32, BlendMode::LinearDodge),
|
||||
("lab", 8, LAB_8, BlendMode::Multiply),
|
||||
("lab", 16, &[][..], BlendMode::Darken),
|
||||
("grayscale", 8, &[][..], BlendMode::Hue),
|
||||
("rgb", 8, &[][..], BlendMode::Overlay),
|
||||
("rgb", 16, &[][..], BlendMode::Overlay),
|
||||
("cmyk", 8, &[][..], BlendMode::ColorBurn),
|
||||
] {
|
||||
let mut session = document(mode, depth);
|
||||
let snapshot = |session: &Session| {
|
||||
let state = session.active().unwrap();
|
||||
(state.doc.layers.len(), state.active_layer, state.history.past_len(), state.doc.next_layer_suggestion())
|
||||
};
|
||||
let before = snapshot(&session);
|
||||
for &blend in unavailable {
|
||||
let params = json!({"mode": blend});
|
||||
let error = session.execute(COMMAND, params.clone()).unwrap_err().to_string();
|
||||
assert!(error.contains(blend) && error.contains("not available"), "{mode} {depth}: {error}");
|
||||
assert_eq!(session.precheck(COMMAND, ¶ms).unwrap_err().to_string(), error, "Free Transform precheck agrees");
|
||||
assert_eq!(snapshot(&session), before, "{mode} {depth}: refusing {blend} leaves the document unchanged");
|
||||
}
|
||||
session.execute(COMMAND, json!({"mode": allowed.key()})).unwrap();
|
||||
let state = session.active().unwrap();
|
||||
assert_eq!(state.doc.layer(state.active_layer.unwrap()).unwrap().blend, allowed, "{mode} {depth}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_mode_leaves_a_pending_selection_floating() {
|
||||
let mut session = document("rgb", 32);
|
||||
session.execute(COMMAND, json!({})).unwrap();
|
||||
session.execute("edit.fill", json!({"color": "#ff0000"})).unwrap();
|
||||
session.execute("select.rect", json!({"x": 2, "y": 2, "width": 4, "height": 4})).unwrap();
|
||||
session.execute("select.float", json!({"dx": 4})).unwrap();
|
||||
let state = session.active().unwrap();
|
||||
let history = state.history.past_len();
|
||||
let offset = float_cmds::floating(state).unwrap().offset;
|
||||
|
||||
let error = session.execute(COMMAND, json!({"mode": "Overlay", "fillNeutral": true})).unwrap_err().to_string();
|
||||
assert!(error.contains("Overlay") && error.contains("not available"), "{error}");
|
||||
let state = session.active().unwrap();
|
||||
assert_eq!(state.history.past_len(), history);
|
||||
assert_eq!(float_cmds::floating(state).unwrap().offset, offset);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use craft::ui::dialog::DialogId;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use craft::ui::runtime::env::{Label, UnitKind};
|
||||
use craft::ui::value_drag::SliderScale;
|
||||
use photocraft_doc::{BlendMode, LabelColor};
|
||||
use photocraft_doc::{BlendMode, Document, LabelColor};
|
||||
use photocraft_engine::new_layer::neutral_color;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -40,9 +40,17 @@ fn layer_opacity_param() -> Param {
|
||||
Param::new("opacity", tl!("Opacity:"), ParamKind::range(0.0, 100.0, 100.0, SliderScale::Linear)).decimals(0).unit(UnitKind::Percent).popup_slider()
|
||||
}
|
||||
|
||||
fn layer_mode_param(doc: &Document) -> Param {
|
||||
super::blend_options::blend_param("mode", tl!("Mode:"), false, BlendMode::Normal)
|
||||
.disabled_options(photocraft_engine::new_layer::greyed_modes(doc).iter().map(|mode| mode.key()))
|
||||
.beside_next()
|
||||
}
|
||||
|
||||
/// Open the dialog for the active document, with the name the layer would get.
|
||||
pub fn open(app: &mut PhotocraftApp) -> Result<DialogId, String> {
|
||||
let name = app.session.active().ok_or("no document open")?.doc.next_layer_suggestion();
|
||||
let doc = &app.session.active().ok_or("no document open")?.doc;
|
||||
let name = doc.next_layer_suggestion();
|
||||
let mode_row = layer_mode_param(doc);
|
||||
Ok(params::open_param(app, COMMAND, DialogFields::new(), Value::Null, move |fields: &mut DialogFields| {
|
||||
let neutral_modes: Vec<String> =
|
||||
BlendMode::LAYER_MODES.into_iter().filter(|m| neutral_color(*m).is_some()).map(|mode| mode.key().to_string()).collect();
|
||||
@@ -51,7 +59,7 @@ pub fn open(app: &mut PhotocraftApp) -> Result<DialogId, String> {
|
||||
Param::new("clipToPrevious", tl!("Use Previous Layer to Create Clipping Mask"), ParamKind::bool(false)),
|
||||
color_param(),
|
||||
// Opacity shares the Mode row, as in the reference application.
|
||||
crate::dialogs::blend_options::blend_param("mode", tl!("Mode:"), false, BlendMode::Normal).beside_next(),
|
||||
mode_row.clone(),
|
||||
layer_opacity_param(),
|
||||
Param::new("fillNeutral", neutral_label(mode(fields)), ParamKind::bool(false)).enabled_when_in("mode", neutral_modes),
|
||||
];
|
||||
@@ -134,6 +142,10 @@ pub(crate) mod testing {
|
||||
#[path = "new_layer_name_trim_tests.rs"]
|
||||
mod new_layer_name_trim_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "new_layer_greyed_modes_tests.rs"]
|
||||
mod new_layer_greyed_modes_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
//! #13767: File › Export › Data Sets as Files with a data set whose Pixel Replacement image is
|
||||
//! missing. The form asks, naming the set, whether to export the remaining sets: Yes leaves that
|
||||
//! set out and goes on (asking again at the next missing image), No stops with the files written
|
||||
//! so far. A missing image in the last set keeps today's error (not measured). Agents get the same
|
||||
//! choice without a prompt through the command's `missingImage` and `start` parameters, and the
|
||||
//! result lists the sets left out (`skipped`) or stopped at (`stopped`).
|
||||
use crate::PhotocraftApp;
|
||||
use craft::ui::dialog::{DialogId, StandardPrompt};
|
||||
use serde_json::{Value, json};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const EXPORT: &str = "file.export.dataSetsAsFiles";
|
||||
|
||||
/// A fresh scratch folder for one test, holding `ok.png` (a real image) and an `out` folder to come.
|
||||
fn scratch(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("pc-13767-{}-{name}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.execute("file.new", json!({"width": 4, "height": 4})).unwrap();
|
||||
let png = photocraft_io::export(&s.active().unwrap().doc, "png", &Default::default()).unwrap().bytes;
|
||||
std::fs::write(dir.join("ok.png"), png).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
/// A document whose raster layer `photo` is bound to a Pixel Replacement variable, with one data
|
||||
/// set per entry of `images` ("Data Set 1", …): `true` names `ok.png`, `false` a file that is not there.
|
||||
fn app(dir: &Path, images: &[bool]) -> (Box<PhotocraftApp>, egui::Context) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 16, "height": 16})).unwrap();
|
||||
app.run("layer.new.layer", json!({"name": "photo"})).unwrap();
|
||||
let layer = app.session.active().unwrap().active_layer.unwrap().0;
|
||||
app.run("image.variables.define", json!({"defs": [{"name": "photo", "layer": layer, "type": "pixelReplacement"}]})).unwrap();
|
||||
let sets: Vec<Value> = images
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, ok)| {
|
||||
let file = if *ok { dir.join("ok.png") } else { dir.join(format!("missing-{}.png", i + 1)) };
|
||||
json!({"name": format!("Data Set {}", i + 1), "values": [{"variable": "photo", "kind": "pixels", "value": file}]})
|
||||
})
|
||||
.collect();
|
||||
app.run("image.variables.dataSets", json!({"dataSets": sets})).unwrap();
|
||||
app.sync_views();
|
||||
let ctx = app.ctx().clone();
|
||||
(app, ctx)
|
||||
}
|
||||
|
||||
/// The files in `dir`, by name, sorted.
|
||||
fn files(dir: &Path) -> Vec<String> {
|
||||
let mut names: Vec<String> = std::fs::read_dir(dir).map(|r| r.map(|e| e.unwrap().file_name().to_string_lossy().into_owned()).collect()).unwrap_or_default();
|
||||
names.sort();
|
||||
names
|
||||
}
|
||||
|
||||
/// Opens the form through the menu and confirms it with `out` as the destination.
|
||||
fn export_from_form(app: &mut PhotocraftApp, ctx: &egui::Context, out: &Path) {
|
||||
let reply = crate::menus::invoke(app, ctx, EXPORT, json!({})).unwrap();
|
||||
let want = reply["dialog"].as_str().unwrap().to_owned();
|
||||
let dialog = app.framework.dialogs.open_dialogs().into_iter().map(|d| d.id).find(|d| d.value().to_string() == want).unwrap();
|
||||
app.framework.dialogs.set_json_field(ctx, dialog, "dir", json!(out)).unwrap();
|
||||
crate::dialogs::confirm(app, ctx, dialog).unwrap();
|
||||
}
|
||||
|
||||
/// The open missing-image question and its message.
|
||||
fn question(app: &PhotocraftApp) -> Option<(DialogId, String)> {
|
||||
let id = crate::dialogs::alerts::prompt_tagged::<crate::view_cmds::dialogs::DataSetsMissingImage>(app)?;
|
||||
let prompt = app.framework.dialogs.get::<StandardPrompt>()?;
|
||||
let host = app.framework.host();
|
||||
let buttons: Vec<String> = prompt.shown_buttons(host).into_iter().map(|(_, label)| label).collect();
|
||||
Some((id, format!("{} | {} | {}", prompt.shown_title(host), prompt.shown_message(host), buttons.join(" / "))))
|
||||
}
|
||||
|
||||
fn answer(app: &mut PhotocraftApp, ctx: &egui::Context, id: DialogId, yes: bool) {
|
||||
if !yes {
|
||||
app.framework.dialogs.set_json_field(ctx, id, "choice", json!("cancel")).unwrap();
|
||||
}
|
||||
crate::dialogs::confirm(app, ctx, id).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_form_asks_yes_no_naming_the_set_and_yes_exports_the_others() {
|
||||
let dir = scratch("yes");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
|
||||
let (id, message) = question(&app).expect("a missing image asks");
|
||||
assert!(message.contains("Data Set 2"), "{message}");
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "the sets before it are written before the question");
|
||||
assert!(message.ends_with("| Yes / No"), "Yes and No: {message}");
|
||||
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png", "Data_Set_3.png"], "Yes leaves set 2 out and writes set 3");
|
||||
assert!(app.ui.status.contains("Data Set 2") && !app.ui.status_error, "the status lists the skipped set: {}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_stops_with_the_files_written_so_far() {
|
||||
let dir = scratch("no");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, false);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "No writes nothing more");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_missing_images_in_a_row_ask_once_each_in_every_combination() {
|
||||
for (answers, want) in
|
||||
[(vec![true, true], vec!["Data_Set_1.png", "Data_Set_4.png"]), (vec![true, false], vec!["Data_Set_1.png"]), (vec![false], vec!["Data_Set_1.png"])]
|
||||
{
|
||||
let dir = scratch(&format!("row-{answers:?}").replace([' ', ',', '[', ']'], ""));
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let mut asked = Vec::new();
|
||||
for yes in &answers {
|
||||
let (id, message) = question(&app).expect("asked");
|
||||
asked.push(message);
|
||||
answer(&mut app, &ctx, id, *yes);
|
||||
}
|
||||
assert!(question(&app).is_none(), "{answers:?}: no further question");
|
||||
assert_eq!(files(&out), want, "{answers:?}");
|
||||
assert!(asked[0].contains("Data Set 2"), "{asked:?}");
|
||||
if let Some(second) = asked.get(1) {
|
||||
assert!(second.contains("Data Set 3"), "{asked:?}");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_image_in_the_last_set_keeps_todays_error() {
|
||||
let dir = scratch("last");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
assert!(question(&app).is_none(), "not measured: no question for the last set");
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"]);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_command_reports_skipped_and_stopped_sets_without_a_prompt() {
|
||||
let dir = scratch("cmd");
|
||||
let (mut app, _) = app(&dir, &[true, false, true]);
|
||||
let out = |n: &str| dir.join(n).to_string_lossy().into_owned();
|
||||
|
||||
// Default: today's error, after Data Set 1.
|
||||
let e = app.run(EXPORT, json!({"dir": out("error")})).unwrap_err();
|
||||
assert!(e.starts_with(photocraft_engine::DATA_SET_FILE_MISSING), "{e}");
|
||||
assert_eq!(files(&dir.join("error")), ["Data_Set_1.png"]);
|
||||
|
||||
let r = app.run(EXPORT, json!({"dir": out("skip"), "missingImage": "skip"})).unwrap();
|
||||
assert_eq!(r["skipped"], json!(["Data Set 2"]));
|
||||
assert_eq!(r["count"], json!(2));
|
||||
assert!(r.get("stopped").is_none());
|
||||
assert_eq!(files(&dir.join("skip")), ["Data_Set_1.png", "Data_Set_3.png"]);
|
||||
|
||||
let r = app.run(EXPORT, json!({"dir": out("stop"), "missingImage": "stop", "naming": "{index}"})).unwrap();
|
||||
assert_eq!(r["stopped"]["name"], json!("Data Set 2"));
|
||||
assert_eq!(r["stopped"]["index"], json!(1));
|
||||
assert_eq!(r["stopped"]["remaining"], json!(1));
|
||||
assert!(r["stopped"]["error"].as_str().unwrap().starts_with(photocraft_engine::DATA_SET_FILE_MISSING));
|
||||
assert!(r.get("skipped").is_none(), "nothing was skipped: {r}");
|
||||
assert_eq!(files(&dir.join("stop")), ["001.png"]);
|
||||
|
||||
// `start` resumes after the stop and keeps the numbering of the whole batch.
|
||||
let r = app.run(EXPORT, json!({"dir": out("stop"), "missingImage": "stop", "naming": "{index}", "start": 2})).unwrap();
|
||||
assert_eq!(r["count"], json!(1));
|
||||
assert_eq!(files(&dir.join("stop")), ["001.png", "003.png"]);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_missing_image_and_start_params_are_errors_not_panics() {
|
||||
let dir = scratch("bad");
|
||||
let (mut app, _) = app(&dir, &[true, false]);
|
||||
let out = dir.join("out").to_string_lossy().into_owned();
|
||||
for params in [
|
||||
json!({"dir": out, "missingImage": "maybe"}),
|
||||
json!({"dir": out, "missingImage": 3}),
|
||||
json!({"dir": out, "start": 2}),
|
||||
json!({"dir": out, "start": -1}),
|
||||
json!({"dir": out, "start": 1.5}),
|
||||
json!({"dir": out, "start": "1"}),
|
||||
json!({"dir": out, "start": u64::MAX}),
|
||||
] {
|
||||
assert!(app.run(EXPORT, params.clone()).is_err(), "{params}");
|
||||
}
|
||||
assert!(files(&dir.join("out")).is_empty(), "a refused batch writes nothing");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_sets_changed_while_asking_end_the_export_instead_of_resuming_at_another_set() {
|
||||
let dir = scratch("changed");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
// Reorder the sets while the question is open: position 2 is now another set.
|
||||
let sets = app.run("variables.list", json!({})).unwrap()["dataSets"].as_array().unwrap().clone();
|
||||
let reordered: Vec<Value> = [2, 0, 1].iter().map(|i| sets[*i].clone()).collect();
|
||||
app.run("image.variables.dataSets", json!({"dataSets": reordered})).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "nothing more is written");
|
||||
assert!(app.ui.status_error && app.ui.status.contains("changed"), "{}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_after_an_earlier_yes_lists_every_set_left_out() {
|
||||
let dir = scratch("yes-no-status");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
let (id, _) = question(&app).expect("set 3 asks too");
|
||||
answer(&mut app, &ctx, id, false);
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "No writes nothing more");
|
||||
let status = &app.ui.status;
|
||||
assert!(status.contains("Data Set 2") && status.contains("Data Set 3") && !app.ui.status_error, "both sets left out are listed: {status}");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_document_made_active_while_asking_does_not_stop_the_next_yes() {
|
||||
let dir = scratch("other-doc");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
// A second document, with no data sets, becomes the active one while the question is open.
|
||||
app.run("file.new", json!({"width": 8, "height": 8})).unwrap();
|
||||
app.sync_views();
|
||||
let other = app.session.active().unwrap().doc.id;
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert_eq!(app.session.active().unwrap().doc.id, other, "the other document stays active");
|
||||
let (id, message) = question(&app).expect("set 3 asks");
|
||||
assert!(message.contains("Data Set 3"), "{message}");
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png", "Data_Set_4.png"], "the export goes on with the document it ran on");
|
||||
assert!(!app.ui.status_error, "{}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_variable_bound_anew_while_asking_ends_the_export() {
|
||||
let dir = scratch("rebound");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
// Bind the variable to another layer while the question is open: the rest would come from it.
|
||||
app.run("layer.new.layer", json!({"name": "other"})).unwrap();
|
||||
let layer = app.session.active().unwrap().active_layer.unwrap().0;
|
||||
app.run("image.variables.define", json!({"defs": [{"name": "photo", "layer": layer, "type": "pixelReplacement"}]})).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "nothing more is written");
|
||||
assert!(app.ui.status_error && app.ui.status.contains("changed"), "{}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_document_edited_while_asking_ends_the_export() {
|
||||
let dir = scratch("edited");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, true]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
// Resize the canvas while the question is open: the rest would no longer match the files written.
|
||||
app.run("image.canvasSize", json!({"width": 24, "height": 24})).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"], "nothing more is written");
|
||||
assert!(app.ui.status_error && app.ui.status.contains("changed"), "{}", app.ui.status);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_last_set_after_a_yes_still_lists_the_set_left_out() {
|
||||
let dir = scratch("yes-then-last");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false]);
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert!(question(&app).is_none(), "the last set keeps today's error, no question");
|
||||
assert_eq!(files(&out), ["Data_Set_1.png"]);
|
||||
let status = &app.ui.status;
|
||||
assert!(app.ui.status_error && status.starts_with(photocraft_engine::DATA_SET_FILE_MISSING), "{status}");
|
||||
assert!(status.contains("Data Set 2"), "the set an earlier Yes left out stays listed: {status}");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_recorded_step_keeps_the_forms_question_parameters_out() {
|
||||
let dir = scratch("journal");
|
||||
let out = dir.join("out");
|
||||
let (mut app, ctx) = app(&dir, &[true, false, false, true]);
|
||||
let from = app.session.journal.len();
|
||||
export_from_form(&mut app, &ctx, &out);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
let (id, _) = question(&app).unwrap();
|
||||
answer(&mut app, &ctx, id, true);
|
||||
assert_eq!(files(&out), ["Data_Set_1.png", "Data_Set_4.png"]);
|
||||
|
||||
let steps: Vec<&Value> = app.session.journal[from..].iter().filter(|(id, _)| id == EXPORT).map(|(_, p)| p).collect();
|
||||
assert_eq!(steps.len(), 1, "the resumed runs are not recorded as steps: {steps:?}");
|
||||
for key in ["missingImage", "start"] {
|
||||
assert!(steps[0].get(key).is_none(), "{key} stays out of the recorded step: {:?}", steps[0]);
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//! #18642: the Classic gradient's Opacity field drops every typed character but the digits, `-` and the locale's decimal
|
||||
//! separator before it reads the value: "a7" is 7, "1e2" is 12, "+20" is 20, and the other separator is dropped, so with
|
||||
//! a decimal comma "33.6" reads 336 and is kept as 100. Text without a digit is ignored.
|
||||
|
||||
use egui::accesskit::Role;
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use super::opacity_typed;
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The options bar of the Classic gradient at Opacity 50.
|
||||
fn bar() -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 80, "height": 80})).unwrap();
|
||||
app.ui.tool = Tool::Gradient;
|
||||
app.ui.tool_options.gradient_classic = true;
|
||||
app.ui.tool_options.fill_opacity = 50.0;
|
||||
crate::theme::install_fonts(app.ctx());
|
||||
crate::theme::apply(app.ctx(), &crate::theme::AppTheme::pro());
|
||||
let mut h = Harness::builder()
|
||||
.with_context(app.ctx().clone())
|
||||
.with_size(vec2(1800.0, 300.0))
|
||||
.with_step_dt(1.0 / 60.0)
|
||||
.build_ui_state(move |ui, app: &mut Box<PhotocraftApp>| crate::panels::options_bar(app, ui), app);
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// Types `text` into the Opacity field and commits it with Enter.
|
||||
fn type_opacity(h: &mut Harness<'static, Box<PhotocraftApp>>, text: &str) {
|
||||
h.query_all_by_role(Role::SpinButton)
|
||||
.find(|n| n.accesskit_node().label().as_deref().is_some_and(|l| l.trim_end_matches(':') == "Opacity"))
|
||||
.expect("the Opacity field")
|
||||
.click();
|
||||
h.run_steps(1);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Text(text.into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// The test locale reads `.` as the decimal separator, so the comma is the one dropped.
|
||||
#[test]
|
||||
fn typed_text_keeps_only_digits_minus_and_the_decimal_separator() {
|
||||
let rows: [(&str, f32); 10] =
|
||||
[("a7", 7.0), ("5%", 5.0), ("50abc", 50.0), ("1e2", 12.0), ("+20", 20.0), (" 7", 7.0), ("1,5", 15.0), ("12,34", 100.0), ("200%", 100.0), ("abc", 50.0)];
|
||||
for (typed, kept) in rows {
|
||||
let mut h = bar();
|
||||
type_opacity(&mut h, typed);
|
||||
assert_eq!(h.state().ui.tool_options.fill_opacity, kept, "{typed:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With a decimal comma the period is dropped: "33.6" reads 336, past the field's 100.
|
||||
#[test]
|
||||
fn a_decimal_comma_drops_the_period() {
|
||||
for (typed, read) in [("a7", 7.0), ("5%", 5.0), ("50abc", 50.0), ("1e2", 12.0), ("+20", 20.0), ("0.4", 4.0), (" 7", 7.0), ("50,5", 50.5)] {
|
||||
assert_eq!(opacity_typed(typed, ','), Some(read), "{typed:?}");
|
||||
}
|
||||
for (typed, read) in [("33.6", 336.0), ("99.5", 995.0), ("100.6", 1006.0), ("200%", 200.0)] {
|
||||
assert_eq!(opacity_typed(typed, ','), Some(read), "{typed:?}");
|
||||
assert!(read > 100.0, "{typed:?} is past the range, which keeps 100");
|
||||
}
|
||||
assert_eq!(opacity_typed("abc", ','), None, "no digit: ignored");
|
||||
}
|
||||
@@ -37,6 +37,9 @@ pub static ICONS: &[(&str, &[u8])] = &[
|
||||
("path-op-new-layer", include_bytes!("../../../assets/icons/path-op-new-layer.svg")),
|
||||
("path-op-subtract", include_bytes!("../../../assets/icons/path-op-subtract.svg")),
|
||||
("pipette", include_bytes!("../../../assets/icons/pipette.svg")),
|
||||
("quick-mask-masked-areas", include_bytes!("../../../assets/icons/quick-mask-masked-areas.svg")),
|
||||
("quick-mask-off", include_bytes!("../../../assets/icons/quick-mask-off.svg")),
|
||||
("quick-mask-selected-areas", include_bytes!("../../../assets/icons/quick-mask-selected-areas.svg")),
|
||||
("rectangle-horizontal", include_bytes!("../../../assets/icons/rectangle-horizontal.svg")),
|
||||
("rectangle-vertical", include_bytes!("../../../assets/icons/rectangle-vertical.svg")),
|
||||
("redo-2", include_bytes!("../../../assets/icons/redo-2.svg")),
|
||||
|
||||
@@ -342,7 +342,7 @@ pub(crate) fn command_rows(app: &PhotocraftApp) -> Vec<CommandDef> {
|
||||
def.has_alt_variant = true;
|
||||
}
|
||||
}
|
||||
// Edit in Quick Mask Mode is a button in the tool rail's footer, which shows its command's icon.
|
||||
// Edit in Quick Mask Mode has a generic command icon. The tool rail shows the active document's mask state.
|
||||
if let Some(&at) = index.get(crate::panels::QUICK_MASK) {
|
||||
rows[at].icon = Some("square-dashed".into());
|
||||
}
|
||||
|
||||
@@ -1119,6 +1119,8 @@ mod artboards_to_pdf_reverse_tests;
|
||||
#[cfg(test)]
|
||||
mod browse_field_tests;
|
||||
#[cfg(test)]
|
||||
mod export_data_sets_missing_image_tests;
|
||||
#[cfg(test)]
|
||||
mod export_quality_tests;
|
||||
#[cfg(test)]
|
||||
mod select_and_mask_button_tests;
|
||||
|
||||
@@ -9,6 +9,10 @@ use super::{DOCUMENT_ITEM, PhotocraftApp, Value};
|
||||
#[path = "type_paste_lorem_greyed_tests.rs"]
|
||||
mod type_paste_lorem_greyed_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../stack_mode_check_mark_tests.rs"]
|
||||
mod stack_mode_check_mark_tests;
|
||||
|
||||
/// Whether View › Zoom Out has stopped at a document-specific minimum.
|
||||
pub(crate) fn zoom_out_at_minimum(app: &PhotocraftApp) -> bool {
|
||||
let Some(document) = app.session.active() else { return false };
|
||||
@@ -171,7 +175,7 @@ fn panel_of(id: &str) -> Option<&str> {
|
||||
|
||||
/// Is a UI-level toggle currently on (for checkmarks)?
|
||||
pub(super) fn checked(app: &PhotocraftApp, id: &str) -> Option<bool> {
|
||||
use photocraft_doc::{ColorMode, SampleType};
|
||||
use photocraft_doc::{ColorMode, LayerContent, SampleType, StackMode};
|
||||
if let Some(c) = crate::view_cmds::checked(app, id) {
|
||||
return Some(c);
|
||||
}
|
||||
@@ -192,6 +196,10 @@ pub(super) fn checked(app: &PhotocraftApp, id: &str) -> Option<bool> {
|
||||
if id == "edit.transform.warp" {
|
||||
return Some(crate::transform_tool::warps_active_layer(app));
|
||||
}
|
||||
if let Some(mode) = id.strip_prefix("layer.smartObjects.stackMode.").and_then(StackMode::from_id) {
|
||||
let active_layer = app.session.active().and_then(|d| d.doc.layer(d.active_layer?));
|
||||
return Some(matches!(active_layer.map(|layer| &layer.content), Some(LayerContent::Smart(smart)) if smart.stack_mode == Some(mode)));
|
||||
}
|
||||
if id == "view.proofColors" || id == "view.gamutWarning" {
|
||||
let Some(d) = app.session.active() else { return Some(false) };
|
||||
let pv = app.session.color().proof(d.doc.id);
|
||||
|
||||
@@ -1033,6 +1033,169 @@ pub(crate) fn batch_check(app: &mut PhotocraftApp, result: &ParamResult) -> Resu
|
||||
Err(Label::from(message))
|
||||
}
|
||||
|
||||
/// File › Export › Data Sets as Files (#13767).
|
||||
pub(crate) const DATA_SETS: &str = "file.export.dataSetsAsFiles";
|
||||
|
||||
/// The Data Sets as Files form's OK: runs the export with `missingImage: "stop"`, so a data set
|
||||
/// whose replacement image is missing asks whether to export the remaining sets.
|
||||
pub(crate) fn data_sets_run(app: &mut PhotocraftApp, ctx: &egui::Context, mut result: ParamResult) {
|
||||
result.fields.set("missingImage", FieldValue::Text("stop".into()));
|
||||
let doc = app.session.active().map(|st| st.doc.id);
|
||||
let params = crate::dialogs::filter_dialog::command_params(DATA_SETS, &result.fields);
|
||||
let journal = app.session.journal.len();
|
||||
let outcome = crate::dialogs::filter_dialog::run_command(app, ctx, DATA_SETS, result);
|
||||
keep_prompt_params_out_of_the_journal(app, journal, false);
|
||||
match outcome {
|
||||
Ok(reply) => data_sets_went_on(app, doc, params, Vec::new(), &reply),
|
||||
Err(error) => crate::notices::error(app, error),
|
||||
}
|
||||
}
|
||||
|
||||
/// `missingImage` and `start` belong to the question this form asks, not to the export: a recorded step
|
||||
/// that kept them would, on playback, stop at a missing image without an error and skip the sets after it,
|
||||
/// or write from a position chosen for another document. The step the form ran loses `missingImage`
|
||||
/// (a playback is the plain export, and a missing image is an error again); the resumed run after Yes
|
||||
/// (`resumed`) is part of the same export, so its step is not recorded at all.
|
||||
fn keep_prompt_params_out_of_the_journal(app: &mut PhotocraftApp, from: usize, resumed: bool) {
|
||||
let journal = &mut app.session.journal;
|
||||
if journal.len() <= from {
|
||||
return;
|
||||
}
|
||||
if resumed {
|
||||
let mut index = 0;
|
||||
journal.retain(|(id, _)| {
|
||||
let keep = index < from || id != DATA_SETS;
|
||||
index += 1;
|
||||
keep
|
||||
});
|
||||
return;
|
||||
}
|
||||
for (id, params) in journal.iter_mut().skip(from) {
|
||||
if id == DATA_SETS
|
||||
&& let Some(map) = params.as_object_mut()
|
||||
{
|
||||
map.remove("missingImage");
|
||||
map.remove("start");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The question a missing replacement image asks: the document, its edit revision and its variables
|
||||
/// and data sets as the export read them, the export's parameters, the set it stopped at and where
|
||||
/// the batch resumes, and the sets skipped so far.
|
||||
pub(crate) struct DataSetsMissingImage {
|
||||
pub(crate) doc: Option<photocraft_doc::DocId>,
|
||||
pub(crate) revision: u64,
|
||||
pub(crate) defs: Vec<photocraft_doc::VariableDef>,
|
||||
pub(crate) sets: Vec<photocraft_doc::DataSet>,
|
||||
pub(crate) params: Value,
|
||||
pub(crate) name: String,
|
||||
pub(crate) resume: usize,
|
||||
pub(crate) skipped: Vec<String>,
|
||||
}
|
||||
|
||||
/// After one run of the export: a set it stopped at asks Yes / No, unless it was the last set
|
||||
/// (not measured: today's error stands). A finished export lists the sets skipped in the status bar.
|
||||
fn data_sets_went_on(app: &mut PhotocraftApp, doc: Option<photocraft_doc::DocId>, params: Value, skipped: Vec<String>, reply: &Value) {
|
||||
let Some(stopped) = reply.get("stopped").filter(|s| s.is_object()) else {
|
||||
if !skipped.is_empty() {
|
||||
app.ui.status = crate::i18n::fmt(tl!("Data sets not exported (replacement file not found): {names}"), &[("names", &skipped.join(", "))]);
|
||||
app.ui.status_error = false;
|
||||
}
|
||||
return;
|
||||
};
|
||||
let name = stopped.get("name").and_then(Value::as_str).unwrap_or_default().to_owned();
|
||||
let index = stopped.get("index").and_then(Value::as_u64).and_then(|n| usize::try_from(n).ok());
|
||||
let remaining = stopped.get("remaining").and_then(Value::as_u64).unwrap_or(0);
|
||||
let (Some(index), true) = (index, remaining > 0) else {
|
||||
let mut error = stopped.get("error").and_then(Value::as_str).unwrap_or(photocraft_engine::DATA_SET_FILE_MISSING).to_owned();
|
||||
// Sets an earlier Yes left out stay listed next to the last set's error.
|
||||
if !skipped.is_empty() {
|
||||
error.push(' ');
|
||||
error.push_str(&crate::i18n::fmt(tl!("Data sets not exported (replacement file not found): {names}"), &[("names", &skipped.join(", "))]));
|
||||
}
|
||||
crate::notices::error(app, error);
|
||||
return;
|
||||
};
|
||||
let message = crate::i18n::fmt(tl!("“{name}” was not exported: its replacement file was not found. Export the remaining data sets?"), &[("name", &name)]);
|
||||
// The sets of the document the export ran on, as Yes compares them: a resumed run restores the document that was
|
||||
// active, which may be another one by now.
|
||||
let (revision, defs, sets) = app
|
||||
.session
|
||||
.documents()
|
||||
.iter()
|
||||
.find(|st| Some(st.doc.id) == doc)
|
||||
.map(|st| (edit_revision(st), st.doc.variables.defs.clone(), st.doc.variables.data_sets.clone()))
|
||||
.unwrap_or_default();
|
||||
let tag = DataSetsMissingImage { doc, revision, defs, sets, params, name, resume: index.saturating_add(1), skipped };
|
||||
let prompt = craft::ui::dialog::StandardPrompt::custom(message)
|
||||
.title(tl!("Data Sets as Files"))
|
||||
.icon(craft::behavior::IconId::new("info"))
|
||||
.button(craft::ui::dialog::PromptChoice::Proceed, tl!("Yes"))
|
||||
.button(craft::ui::dialog::PromptChoice::Cancel, tl!("No"))
|
||||
.tag(tag);
|
||||
if crate::dialogs::alerts::open_prompt(app, prompt).is_err() {
|
||||
crate::dialogs::alerts::report_error(app, tl!("Data Sets as Files stopped: another question is open"));
|
||||
}
|
||||
}
|
||||
|
||||
/// A document's revision without its view-only changes (channel eyes, Layers panel isolation),
|
||||
/// which leave the exported files as they are.
|
||||
fn edit_revision(st: &photocraft_engine::DocState) -> u64 {
|
||||
st.revision.wrapping_sub(st.view_revision)
|
||||
}
|
||||
|
||||
/// The `PROMPTS` entry of the missing-image question: Yes skips that set and exports the rest
|
||||
/// (asking again at the next missing image), No stops with the files written so far.
|
||||
pub(crate) fn data_sets_answer(app: &mut PhotocraftApp, _ctx: &egui::Context, answer: &mut craft::ui::dialog::PromptAnswer) -> bool {
|
||||
let Some(mut pending) = answer.take_tag::<DataSetsMissingImage>() else { return false };
|
||||
pending.skipped.push(pending.name.clone());
|
||||
if answer.choice != craft::ui::dialog::PromptChoice::Proceed {
|
||||
// Sets skipped by an earlier Yes stay listed next to the one it stopped at.
|
||||
app.ui.status = if pending.skipped.len() > 1 {
|
||||
crate::i18n::fmt(
|
||||
tl!("Data Sets as Files stopped at “{name}”. Data sets not exported (replacement file not found): {names}"),
|
||||
&[("name", &pending.name), ("names", &pending.skipped.join(", "))],
|
||||
)
|
||||
} else {
|
||||
crate::i18n::fmt(tl!("Data Sets as Files stopped at “{name}”"), &[("name", &pending.name)])
|
||||
};
|
||||
app.ui.status_error = false;
|
||||
return true;
|
||||
}
|
||||
// The batch resumes by position from the document as it is now: data sets edited while the
|
||||
// question was open would resume at another set, variables bound anew would write the rest from
|
||||
// other layers, and an edited or resized document would make the rest differ from the files
|
||||
// already written, so the export ends there instead.
|
||||
let unchanged = app
|
||||
.session
|
||||
.documents()
|
||||
.iter()
|
||||
.find(|st| Some(st.doc.id) == pending.doc)
|
||||
.is_some_and(|st| edit_revision(st) == pending.revision && st.doc.variables.defs == pending.defs && st.doc.variables.data_sets == pending.sets);
|
||||
if pending.doc.is_some() && !unchanged {
|
||||
crate::dialogs::alerts::report_error(app, tl!("Data Sets as Files stopped: the document changed while the question was open"));
|
||||
return true;
|
||||
}
|
||||
let mut params = pending.params.clone();
|
||||
if let Some(map) = params.as_object_mut() {
|
||||
map.insert("start".into(), json!(pending.resume));
|
||||
map.insert("missingImage".into(), json!("stop"));
|
||||
}
|
||||
let run = |app: &mut PhotocraftApp| app.run(DATA_SETS, params.clone());
|
||||
let journal = app.session.journal.len();
|
||||
let outcome = match pending.doc {
|
||||
Some(doc) => app.with_document(doc, run),
|
||||
None => run(app),
|
||||
};
|
||||
keep_prompt_params_out_of_the_journal(app, journal, true);
|
||||
match outcome {
|
||||
Ok(reply) => data_sets_went_on(app, pending.doc, pending.params, pending.skipped, &reply),
|
||||
Err(error) => crate::notices::error(app, error),
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "batch_ok_validation_tests.rs"]
|
||||
mod batch_ok_validation_tests;
|
||||
|
||||
@@ -171,6 +171,9 @@ fn channels<const N: usize>(v: &Value) -> Option<[u8; N]> {
|
||||
/// unit and the same RGB/CMYK readout as the pointer (one composite pixel each). A point with no colour
|
||||
/// to read is left out.
|
||||
pub(crate) fn sampler_rows(app: &mut PhotocraftApp) -> Vec<(SamplerReadout, [Label; 2])> {
|
||||
if app.ui.analysis.hide_color_samplers {
|
||||
return Vec::new();
|
||||
}
|
||||
let readouts = sampler_readouts(app);
|
||||
let Some(st) = app.session.active() else { return Vec::new() };
|
||||
let (size, dpi) = (st.doc.size, f64::from(st.doc.resolution_dpi));
|
||||
@@ -309,3 +312,7 @@ mod info_ruler_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "info_unit_format_tests.rs"]
|
||||
mod info_unit_format_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "info_color_samplers_toggle_tests.rs"]
|
||||
mod info_color_samplers_toggle_tests;
|
||||
@@ -0,0 +1,163 @@
|
||||
use craft::ui::menu::PanelRow;
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandState};
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Shape};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use super::sampler_rows;
|
||||
use crate::canvas::testing::to_screen;
|
||||
use crate::input::shortcut_dispatch::tests::app_harness;
|
||||
use crate::panels::{panel_docking, region_versions, registry};
|
||||
use crate::{PhotocraftApp, Services};
|
||||
|
||||
const MENU_LABEL: &str = "Color Samplers";
|
||||
const POINT: [f64; 2] = [25.5, 18.5];
|
||||
type AppHarness = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn app() -> Box<PhotocraftApp> {
|
||||
PhotocraftApp::new(photocraft_engine::Session::new(), Services::default())
|
||||
}
|
||||
|
||||
fn add_document(app: &mut PhotocraftApp) {
|
||||
app.run("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap();
|
||||
}
|
||||
|
||||
fn add_sampler(app: &mut PhotocraftApp) {
|
||||
app.run("view.colorSamplers.add", json!({"x": POINT[0], "y": POINT[1]})).unwrap();
|
||||
}
|
||||
|
||||
fn command(app: &PhotocraftApp) -> CommandRef {
|
||||
let info = registry::entry("info").unwrap();
|
||||
let rows = (info.rows)(app);
|
||||
let [PanelRow::Command(command)] = rows.as_slice() else { panic!("one Info command") };
|
||||
command.clone()
|
||||
}
|
||||
|
||||
fn menu_state(app: &PhotocraftApp) -> CommandState {
|
||||
let info = registry::entry("info").unwrap();
|
||||
let command = command(app);
|
||||
(info.states)(app, info.id).iter().find(|(cmd, _)| cmd == &command).unwrap().1.clone()
|
||||
}
|
||||
|
||||
fn fire(app: &mut PhotocraftApp) {
|
||||
let ctx = app.ctx().clone();
|
||||
let command = command(app);
|
||||
assert!(registry::run_fired(app, &ctx, &command));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn color_samplers_toggle_is_session_wide_and_requires_points_in_the_active_document() {
|
||||
let mut app = app();
|
||||
let state = |enabled, checked| CommandState::new().enabled(enabled).checked(checked);
|
||||
assert_eq!(menu_state(&app), state(false, true));
|
||||
fire(&mut app);
|
||||
add_document(&mut app);
|
||||
assert_eq!(menu_state(&app), state(false, true));
|
||||
|
||||
add_sampler(&mut app);
|
||||
assert_eq!(menu_state(&app), state(true, true));
|
||||
assert_eq!(sampler_rows(&mut app).len(), 1);
|
||||
let info_version = region_versions::panel(&app, "info");
|
||||
let canvas_version = region_versions::canvas(&app);
|
||||
let active = app.session.active().unwrap();
|
||||
let (revision, history) = (active.revision, active.history.past_len());
|
||||
fire(&mut app);
|
||||
assert_ne!(region_versions::panel(&app, "info"), info_version, "the Info body is invalidated");
|
||||
assert_ne!(region_versions::canvas(&app), canvas_version, "the canvas body is invalidated");
|
||||
let active = app.session.active().unwrap();
|
||||
assert_eq!((active.revision, active.history.past_len()), (revision, history));
|
||||
assert_eq!(menu_state(&app), state(true, false));
|
||||
assert!(sampler_rows(&mut app).is_empty());
|
||||
assert_eq!(crate::analysis::sampler_at(&app, POINT), Some(0), "the sampler tools can still find the stored point");
|
||||
|
||||
add_document(&mut app);
|
||||
assert_eq!(menu_state(&app), state(false, true), "empty documents show the disabled item checked");
|
||||
fire(&mut app);
|
||||
add_sampler(&mut app);
|
||||
assert_eq!(menu_state(&app), state(true, false));
|
||||
assert!(sampler_rows(&mut app).is_empty());
|
||||
fire(&mut app);
|
||||
assert_eq!(sampler_rows(&mut app).len(), 1);
|
||||
assert!(app.session.set_active(0));
|
||||
assert_eq!(menu_state(&app), state(true, true));
|
||||
assert_eq!(sampler_rows(&mut app).len(), 1);
|
||||
}
|
||||
|
||||
fn click(h: &mut AppHarness, at: Pos2) {
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.run_steps(1);
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
fn open_menu(h: &mut AppHarness) {
|
||||
let info = h.get_by_role_and_label(Role::TabPanel, "Info");
|
||||
let at = info.get_by_role_and_label(Role::Button, "Panel Menu").rect().center();
|
||||
click(h, at);
|
||||
}
|
||||
|
||||
fn sampler_mark(shape: &Shape, at: Pos2) -> bool {
|
||||
match shape {
|
||||
Shape::Circle(circle) => circle.center.distance(at) < 0.5 && circle.stroke.width > 0.0,
|
||||
Shape::Vec(shapes) => shapes.iter().any(|shape| sampler_mark(shape, at)),
|
||||
Shape::PaintChunk(shapes) => shapes.iter().any(|shape| sampler_mark(&shape.shape, at)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn shows_marker(h: &AppHarness) -> bool {
|
||||
// The engine stores the pixel centre, but the shared ColorSamplers collection uses the pixel index to paint.
|
||||
let at = to_screen(h.state(), POINT.map(f64::floor));
|
||||
h.output().shapes.iter().any(|clipped| clipped.clip_rect.contains(at) && sampler_mark(&clipped.shape, at))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_info_flyout_hides_and_restores_the_readout_and_canvas_marker_without_history() {
|
||||
let _language = crate::i18n::language_scope(crate::i18n::Lang::EN);
|
||||
let mut app = app();
|
||||
add_document(&mut app);
|
||||
add_sampler(&mut app);
|
||||
for panel in ["navigator", "histogram", "info"] {
|
||||
panel_docking::show_panel(&mut app, panel, Some(true)).unwrap();
|
||||
}
|
||||
app.run("window.panel.iconic", json!({"panel": "info", "iconic": false})).unwrap();
|
||||
panel_docking::show_panel(&mut app, "info", Some(true)).unwrap();
|
||||
let mut h = app_harness(app);
|
||||
|
||||
assert!(shows_marker(&h));
|
||||
assert_eq!(sampler_rows(h.state_mut()).len(), 1);
|
||||
let stored = h.state_mut().run("view.colorSamplers.list", json!({})).unwrap();
|
||||
let active = h.state().session.active().unwrap();
|
||||
let (revision, history) = (active.revision, active.history.past_len());
|
||||
|
||||
open_menu(&mut h);
|
||||
let row = h.get_by_role_and_label(Role::MenuItemCheckBox, MENU_LABEL);
|
||||
assert_eq!(row.accesskit_node().toggled(), Some(Toggled::True));
|
||||
assert!(!row.accesskit_node().is_disabled());
|
||||
let at = row.rect().center();
|
||||
click(&mut h, at);
|
||||
|
||||
assert!(!shows_marker(&h));
|
||||
assert!(sampler_rows(h.state_mut()).is_empty());
|
||||
assert_eq!(h.state_mut().run("view.colorSamplers.list", json!({})).unwrap(), stored);
|
||||
let active = h.state().session.active().unwrap();
|
||||
assert_eq!((active.revision, active.history.past_len()), (revision, history));
|
||||
|
||||
open_menu(&mut h);
|
||||
let row = h.get_by_role_and_label(Role::MenuItemCheckBox, MENU_LABEL);
|
||||
assert_eq!(row.accesskit_node().toggled(), Some(Toggled::False));
|
||||
let at = row.rect().center();
|
||||
click(&mut h, at);
|
||||
assert!(shows_marker(&h));
|
||||
assert_eq!(sampler_rows(h.state_mut()).len(), 1);
|
||||
|
||||
h.state_mut().ui.view.extras = false;
|
||||
h.run_steps(4);
|
||||
assert!(!shows_marker(&h));
|
||||
assert_eq!(sampler_rows(h.state_mut()).len(), 1, "View > Extras only hides the canvas marker");
|
||||
}
|
||||
@@ -31,7 +31,7 @@ use serde_json::{Value, json};
|
||||
use std::hash::{DefaultHasher, Hash as _, Hasher as _};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::preset_panels::{PresetUi, run, tool_presets};
|
||||
use super::preset_panels::{PresetUi, current_tool_only, remember_current_tool_only, run, tool_presets};
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
@@ -798,7 +798,7 @@ pub fn finish_custom_shape(app: &mut PhotocraftApp, rect: [f64; 4], keep: bool,
|
||||
/// Window › Tool Presets: a click applies the preset's tool and options. Current Tool Only lists the current tool's
|
||||
/// presets.
|
||||
pub fn tool_presets_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let only = app.ui.presets_ui.current_tool_only;
|
||||
let only = current_tool_only(app);
|
||||
let current = app.ui.tool;
|
||||
let presets: Vec<(String, String)> = app
|
||||
.session
|
||||
@@ -820,12 +820,12 @@ pub fn tool_presets_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let look = Look {
|
||||
list: true,
|
||||
flat: true,
|
||||
empty: Some(if only { tl!("No presets for the current tool.") } else { tl!("No tool presets.") }),
|
||||
empty: Some(if only { tl!("No tool presets are defined for the current tool.") } else { tl!("No tool presets.") }),
|
||||
leading: Some(Box::new(leading)),
|
||||
..Look::default()
|
||||
};
|
||||
let (events, keys) = show(&mut app.ui.presets_ui, zone, ui, TOOL_PRESETS, &source, look);
|
||||
app.ui.presets_ui.current_tool_only = flag.get();
|
||||
remember_current_tool_only(app, flag.get());
|
||||
apply(app, ui.ctx(), TOOL_PRESETS, &[], &keys, events);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ pub struct PresetUi {
|
||||
pub clone_cursor: Option<(photocraft_doc::DocId, [f64; 2])>,
|
||||
/// Selected preset per panel (by name / pattern id).
|
||||
pub selected: BTreeMap<String, String>,
|
||||
/// Tool Presets: Current Tool Only.
|
||||
pub current_tool_only: bool,
|
||||
/// Custom Shape tool: the shape it draws.
|
||||
pub custom_shape: String,
|
||||
/// Custom Shape tool: the layer its last drag placed, in that document; with that tool active the
|
||||
@@ -117,6 +115,22 @@ impl PresetUi {
|
||||
}
|
||||
}
|
||||
|
||||
const TOOL_PRESETS_SECTION: &str = "photocraft.tool-presets";
|
||||
|
||||
/// Tool Presets starts filtered unless the user has explicitly changed it.
|
||||
pub(super) fn current_tool_only(app: &PhotocraftApp) -> bool {
|
||||
app.session.prefs().sections.get(TOOL_PRESETS_SECTION).and_then(|section| section.get("currentToolOnly")).and_then(Value::as_bool).unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Save a changed filter and invalidate the dock body that reads it.
|
||||
pub(super) fn remember_current_tool_only(app: &mut PhotocraftApp, on: bool) {
|
||||
if current_tool_only(app) != on {
|
||||
app.session.prefs.edit(|prefs| {
|
||||
prefs.sections.insert(TOOL_PRESETS_SECTION.into(), serde_json::json!({"currentToolOnly": on}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs the engine command `id`; a failure goes to the status line.
|
||||
pub(crate) fn run(app: &mut PhotocraftApp, id: &str, p: Value) -> Option<Value> {
|
||||
match app.run(id, p) {
|
||||
@@ -129,6 +143,10 @@ pub(crate) fn run(app: &mut PhotocraftApp, id: &str, p: Value) -> Option<Value>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
#[path = "tool_presets_current_tool_only_tests.rs"]
|
||||
mod tool_presets_current_tool_only_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -71,11 +71,10 @@ pub(crate) fn status_bar(app: &PhotocraftApp) -> u64 {
|
||||
version(app, (item, zoom, message, super::chrome_ui::render_path_label(app), progress))
|
||||
}
|
||||
|
||||
/// The version of the toolbar's footer: the colour chips' two colours, whether the active document is in Quick Mask and
|
||||
/// the screen mode the Screen Mode button shows. A shortcut changed in the keymap reaches the buttons' tooltips through
|
||||
/// the framework, which tracks the keymap a view reads.
|
||||
/// The version of the toolbar's footer: the colour chips, the active document's Quick Mask state and the screen mode.
|
||||
/// A shortcut changed in the keymap reaches the buttons' tooltips through the framework, which tracks the keymap a view reads.
|
||||
pub(crate) fn toolbar_footer(app: &PhotocraftApp) -> u64 {
|
||||
let quick_mask = app.session.active().is_some_and(|st| st.doc.quick_mask.is_some());
|
||||
let quick_mask = super::toolbar::QuickMaskState::of(app);
|
||||
version(app, (colours(app), quick_mask, app.ui.view.screen_mode))
|
||||
}
|
||||
|
||||
@@ -125,7 +124,9 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 {
|
||||
}
|
||||
"info" => {
|
||||
let crop = crate::crop_ui::info_size(app).map(|size| size.map(f64::to_bits));
|
||||
version(app, (app.hover_doc.map(|at| at.map(f64::to_bits)), app.current_zoom().to_bits(), app.ui.tool_options.eyedropper.size.pixels(), crop))
|
||||
let pointer = app.hover_doc.map(|at| at.map(f64::to_bits));
|
||||
let sample = (app.current_zoom().to_bits(), app.ui.tool_options.eyedropper.size.pixels());
|
||||
version(app, (pointer, sample, crop, app.ui.analysis.hide_color_samplers))
|
||||
}
|
||||
"cloneSource" => version(app, app.ui.presets_ui.clone_cursor.map(|(document, at)| (document, at.map(f64::to_bits)))),
|
||||
"modifierKeys" => version(app, app.ui.shell.latched),
|
||||
@@ -296,7 +297,7 @@ pub(crate) fn canvas(app: &PhotocraftApp) -> u64 {
|
||||
&ui.selected_guide,
|
||||
&ui.direct_selection,
|
||||
&ui.hidden_work_path,
|
||||
(&ui.analysis, &ui.slices, &ui.frame_tool, &ui.artboard_tool),
|
||||
(&ui.analysis, ui.analysis.hide_color_samplers, &ui.slices, &ui.frame_tool, &ui.artboard_tool),
|
||||
));
|
||||
let sessions =
|
||||
(crate::transform_tool::bar_key(app), crate::puppet_ui::bar_key(app), crate::perspective_ui::bar_key(app), crate::crop_ui::bar::bar_key(app));
|
||||
|
||||
@@ -12,7 +12,7 @@ use craft::ui::contract::{Scroll, ShowContainer as _};
|
||||
use craft::ui::docking::DockHeights;
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::menu::PanelRow;
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandSet as _};
|
||||
use craft::ui::runtime::commands::{CommandRef, CommandSet as _, CommandState};
|
||||
use egui::{Rect, pos2, vec2};
|
||||
|
||||
use std::sync::Arc;
|
||||
@@ -145,7 +145,12 @@ pub(crate) static PANELS: &[PanelEntry] = &[
|
||||
run: super::histogram_panel::run_fired,
|
||||
..panel("histogram", || tl!("Histogram").to_string(), "chart_line", LEAST, |app, ui| scrolled(app, ui, super::histogram_panel::show))
|
||||
},
|
||||
panel("info", || tl!("Info").to_string(), "info", LEAST, |app, ui| scrolled(app, ui, super::info::info_panel)),
|
||||
PanelEntry {
|
||||
rows: |_| vec![PanelRow::Command(CommandRef::from(InfoCommand::ColorSamplers))],
|
||||
states: info_source_states,
|
||||
run: info_run,
|
||||
..panel("info", || tl!("Info").to_string(), "info", LEAST, |app, ui| scrolled(app, ui, super::info::info_panel))
|
||||
},
|
||||
PanelEntry {
|
||||
heights: Some(HISTORY_HEIGHTS),
|
||||
rows: super::history_menu_ui::panel_rows,
|
||||
@@ -226,6 +231,41 @@ pub(crate) static PANELS: &[PanelEntry] = &[
|
||||
floating("notes", || tl!("Notes").to_string(), "square_plus", [260.0, 300.0], |app, ui| scrolled(app, ui, crate::tools::analysis::notes_panel::body)),
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft::ui::contract::CommandSet)]
|
||||
#[command(prefix = "info")]
|
||||
enum InfoCommand {
|
||||
#[command(label = "Color Samplers")]
|
||||
ColorSamplers,
|
||||
}
|
||||
|
||||
fn has_color_samplers(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|doc| !doc.color_samplers.is_empty())
|
||||
}
|
||||
|
||||
#[derive(craft::ui::contract::MemoProps)]
|
||||
struct InfoMenuFacts {
|
||||
available: bool,
|
||||
visible: bool,
|
||||
}
|
||||
|
||||
fn info_source_states(app: &PhotocraftApp, name: &'static str) -> Arc<SourceStates> {
|
||||
let facts = InfoMenuFacts { available: has_color_samplers(app), visible: !app.ui.analysis.hide_color_samplers };
|
||||
derived_states(app, name, &facts, || {
|
||||
vec![(CommandRef::from(InfoCommand::ColorSamplers), CommandState::new().enabled(facts.available).checked(!facts.available || facts.visible))]
|
||||
})
|
||||
}
|
||||
|
||||
fn info_run(app: &mut PhotocraftApp, ctx: &egui::Context, command: &CommandRef) -> bool {
|
||||
if InfoCommand::from_ref(command) != Some(InfoCommand::ColorSamplers) {
|
||||
return false;
|
||||
}
|
||||
if has_color_samplers(app) {
|
||||
app.ui.analysis.hide_color_samplers = !app.ui.analysis.hide_color_samplers;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// The Color panel menu's states, from the panel's own state.
|
||||
fn color_states(app: &PhotocraftApp) -> SourceStates {
|
||||
let state = &app.ui.color_panel.panel;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//! The Tool Presets panel filters a fresh profile and keeps a user's choice across restarts.
|
||||
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use photocraft_engine::presets::{PresetsExt, tools::ToolPreset};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::input::shortcut_dispatch::tests::app_harness;
|
||||
use crate::{PhotocraftApp, Services, Tool};
|
||||
|
||||
const FILTER: &str = "Current Tool Only";
|
||||
const BRUSH: &str = "Filter fixture brush";
|
||||
const CROP: &str = "Filter fixture crop";
|
||||
const EMPTY: &str = "No tool presets are defined for the current tool.";
|
||||
|
||||
type H = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn open_panel(services: Services) -> Result<H, String> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services);
|
||||
app.run("file.new", json!({"width": 64, "height": 48}))?;
|
||||
app.ui.tool = Tool::Brush;
|
||||
app.session.presets_mut().tool_presets =
|
||||
[(BRUSH, "brush"), (CROP, "crop")].map(|(name, tool)| ToolPreset { name: name.into(), tool: tool.into(), options: json!({}) }).into();
|
||||
let mut h = app_harness(app);
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.panel.toolPresets", json!({"show": true}))?;
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.panel.window", json!({"panel": "toolPresets", "native": false}))?;
|
||||
h.run_steps(6);
|
||||
Ok(h)
|
||||
}
|
||||
|
||||
fn filter_state(h: &H) -> Option<Toggled> {
|
||||
h.get_by_role_and_label(Role::CheckBox, FILTER).accesskit_node().toggled()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_presets_filter_a_fresh_profile_and_explain_an_empty_current_tool() -> Result<(), String> {
|
||||
let mut h = open_panel(Services::default())?;
|
||||
assert_eq!(filter_state(&h), Some(Toggled::True));
|
||||
assert!(h.query_by_label_contains(BRUSH).is_some());
|
||||
assert!(h.query_by_label_contains(CROP).is_none());
|
||||
assert!(h.query_by_label(EMPTY).is_none());
|
||||
|
||||
h.state_mut().ui.tool = Tool::RectMarquee;
|
||||
h.run_steps(4);
|
||||
assert_eq!(filter_state(&h), Some(Toggled::True));
|
||||
assert!(h.query_by_label_contains(BRUSH).is_none());
|
||||
assert!(h.query_by_label_contains(CROP).is_none());
|
||||
assert!(h.query_by_label(EMPTY).is_some());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_presets_keep_the_unchecked_filter_after_a_restart() -> Result<(), String> {
|
||||
use std::sync::Arc;
|
||||
|
||||
let files = Arc::new(craft::settings::testing::MemoryFiles::new());
|
||||
let dir = std::env::temp_dir().join("photocraft-tool-presets-current-tool-only");
|
||||
let launch = || {
|
||||
let options = photocraft_engine::prefs::store_options(Some(&dir)).files(files.clone());
|
||||
open_panel(Services { settings: Some(craft::settings::SettingsStore::open_with(options)), ..Default::default() })
|
||||
};
|
||||
let mut h = launch()?;
|
||||
h.get_by_role_and_label(Role::CheckBox, FILTER).click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(filter_state(&h), Some(Toggled::False));
|
||||
assert!(h.query_by_label_contains(BRUSH).is_some());
|
||||
assert!(h.query_by_label_contains(CROP).is_some());
|
||||
|
||||
crate::prefs_ui::save_preferences(h.state_mut())?;
|
||||
drop(h);
|
||||
|
||||
let restarted = launch()?;
|
||||
assert_eq!(filter_state(&restarted), Some(Toggled::False));
|
||||
assert!(restarted.query_by_label_contains(BRUSH).is_some());
|
||||
assert!(restarted.query_by_label_contains(CROP).is_some());
|
||||
Ok(())
|
||||
}
|
||||
@@ -30,6 +30,8 @@ fn tool_preset_rows_paint_distinct_tool_glyphs_and_a_fallback() {
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.panel.toolPresets", json!({})).unwrap();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "window.panel.window", json!({"panel": "toolPresets", "native": false})).unwrap();
|
||||
h.run_steps(6);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::CheckBox, "Current Tool Only").click();
|
||||
h.run_steps(4);
|
||||
|
||||
let textures = names.map(|name| {
|
||||
let row = h.query_by_label_contains(name).expect("the preset is exposed as a row in the panel");
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
use super::{PhotocraftApp, Tool, json};
|
||||
use craft::behavior::IconId;
|
||||
use craft::behavior::overlay::Side;
|
||||
use craft::color_ui::ui::{PairWell, SwatchPair, Well};
|
||||
use craft::ui::contract::{Bind, Gap, MemoProps, MemoView, Props as _, Show as _, ShowContainer as _, Tracked, clicked};
|
||||
use craft::ui::layout::RowAlign;
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::primitives::IconSpec;
|
||||
use craft::ui::rails::{
|
||||
DrawerGroup, FlyoutButton, LastUsed, RailFooter, RailTool, ToolRail, ToolSlot, ToolbarDrawer, ToolbarEdit, apply_toolbar_edit, visible_slots,
|
||||
};
|
||||
use craft::ui::runtime::commands::CommandRef;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::shell::ScreenModeButton;
|
||||
use photocraft_doc::ColorIndicates;
|
||||
use photocraft_engine::prefs::ToolbarCustomization;
|
||||
|
||||
use super::tool_commands;
|
||||
@@ -21,6 +24,9 @@ mod toolbar_docking_tests;
|
||||
#[path = "toolbar_flyout_mark_tests.rs"]
|
||||
mod toolbar_flyout_mark_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "toolbar_quick_mask_icon_tests.rs"]
|
||||
mod toolbar_quick_mask_icon_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "toolbar_rotate_view_reset_tests.rs"]
|
||||
mod toolbar_rotate_view_reset_tests;
|
||||
#[cfg(test)]
|
||||
@@ -174,12 +180,37 @@ pub(crate) fn run_quick_mask(app: &mut PhotocraftApp, params: serde_json::Value)
|
||||
Ok(reply)
|
||||
}
|
||||
|
||||
/// Quick Mask as a rail button, the size of the tool buttons: a click runs Edit in Quick Mask Mode, and the button shows
|
||||
/// on while the active document is in Quick Mask.
|
||||
/// The Quick Mask glyph and selected state shown for the active document.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(super) enum QuickMaskState {
|
||||
Off,
|
||||
MaskedAreas,
|
||||
SelectedAreas,
|
||||
}
|
||||
|
||||
impl QuickMaskState {
|
||||
pub(super) fn of(app: &PhotocraftApp) -> Self {
|
||||
match app.session.active().and_then(|st| st.doc.quick_mask.as_ref()).map(|mask| mask.indicates) {
|
||||
None => Self::Off,
|
||||
Some(ColorIndicates::MaskedAreas) => Self::MaskedAreas,
|
||||
Some(ColorIndicates::SelectedAreas) => Self::SelectedAreas,
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(self) -> IconSpec<'static> {
|
||||
IconSpec::svg(match self {
|
||||
Self::Off => IconId::new("quick-mask-off"),
|
||||
Self::MaskedAreas => IconId::new("quick-mask-masked-areas"),
|
||||
Self::SelectedAreas => IconId::new("quick-mask-selected-areas"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A rail button that runs Edit in Quick Mask Mode and shows which areas the active mask marks.
|
||||
fn quick_mask_button(app: &PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let on = app.session.active().is_some_and(|s| s.doc.quick_mask.is_some());
|
||||
let tools = [RailTool::new(0_u8, CommandRef::new(QUICK_MASK))];
|
||||
let _ = FlyoutButton::new(&tools, &0).id_salt("quick-mask").selected(on).show(ui);
|
||||
let state = QuickMaskState::of(app);
|
||||
let tools = [RailTool::new(0_u8, CommandRef::new(QUICK_MASK)).icon(state.icon())];
|
||||
let _ = FlyoutButton::new(&tools, &0).id_salt("quick-mask").selected(state != QuickMaskState::Off).show(ui);
|
||||
}
|
||||
|
||||
/// The side of the toolbar its tool flyouts, "…" flyout and Edit Toolbar drawer open on: the end (the right in a
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//! #17795: the Quick Mask button paints three distinct glyphs and follows the current document.
|
||||
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
use egui::{Rect, Shape, TextureId};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use super::{PhotocraftApp, QUICK_MASK};
|
||||
use crate::input::shortcut_dispatch::tests::app_harness;
|
||||
|
||||
const LABEL: &str = "Edit in Quick Mask Mode";
|
||||
|
||||
fn icon_texture(shape: &Shape, button: Rect) -> Option<TextureId> {
|
||||
match shape {
|
||||
Shape::Vec(shapes) => shapes.iter().find_map(|shape| icon_texture(shape, button)),
|
||||
Shape::PaintChunk(shapes) => shapes.iter().find_map(|shape| icon_texture(&shape.shape, button)),
|
||||
Shape::Mesh(mesh) if mesh.texture_id != TextureId::default() && button.contains(mesh.calc_bounds().center()) => Some(mesh.texture_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the glyph that was actually painted inside the accessible button's bounds.
|
||||
fn glyph(h: &Harness<'_, Box<PhotocraftApp>>, pressed: Toggled) -> TextureId {
|
||||
let button = h.get_by_role_and_label(Role::Button, LABEL);
|
||||
assert_eq!(button.accesskit_node().toggled(), Some(pressed));
|
||||
h.output().shapes.iter().find_map(|shape| icon_texture(&shape.shape, button.rect())).expect("Quick Mask button paints a glyph")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_quick_mask_glyph_tracks_color_indicates_and_the_active_document() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
for name in ["First", "Second"] {
|
||||
app.run("file.new", json!({"width": 64, "height": 64, "name": name})).unwrap();
|
||||
}
|
||||
assert!(app.session.set_active(0));
|
||||
let mut h = app_harness(app);
|
||||
|
||||
let off = glyph(&h, Toggled::False);
|
||||
h.state_mut().run(QUICK_MASK, json!({"on": true})).unwrap();
|
||||
h.run_steps(3);
|
||||
let masked = glyph(&h, Toggled::True);
|
||||
assert_ne!(masked, off);
|
||||
|
||||
// The options command changes the indicator without toggling the mask or touching the toolbar.
|
||||
h.state_mut().run("channel.options", json!({"channel": "quickMask", "indicates": "selected"})).unwrap();
|
||||
h.run_steps(3);
|
||||
let selected = glyph(&h, Toggled::True);
|
||||
assert_ne!(selected, off);
|
||||
assert_ne!(selected, masked);
|
||||
|
||||
// The session now defaults to Selected Areas. The second document is still off until it enters Quick Mask.
|
||||
assert!(h.state_mut().session.set_active(1));
|
||||
h.run_steps(3);
|
||||
assert_eq!(glyph(&h, Toggled::False), off);
|
||||
h.state_mut().run(QUICK_MASK, json!({"on": true})).unwrap();
|
||||
h.state_mut().run("channel.options", json!({"channel": "quickMask", "indicates": "masked"})).unwrap();
|
||||
h.run_steps(3);
|
||||
assert_eq!(glyph(&h, Toggled::True), masked);
|
||||
|
||||
// The session default changed again, but the first document still marks Selected Areas.
|
||||
assert!(h.state_mut().session.set_active(0));
|
||||
h.run_steps(3);
|
||||
assert_eq!(glyph(&h, Toggled::True), selected);
|
||||
|
||||
h.get_by_role_and_label(Role::Button, LABEL).click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(glyph(&h, Toggled::False), off);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use craft::text::ui::character::{
|
||||
StyleOptionValues, StyleOptionsChange, TextAlign, TextStyleOptions,
|
||||
};
|
||||
use craft::theme::Rgba;
|
||||
use photocraft_doc::text::{CharStyle, ParagraphStyle};
|
||||
use photocraft_doc::text::{CharStyle, Digits, ParagraphStyle};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{color_picker, run};
|
||||
@@ -157,9 +157,28 @@ pub(crate) fn character_values(style: &CharStyle) -> CharacterValues {
|
||||
values.strikethrough = Some(style.strikethrough);
|
||||
values.opentype = opentype;
|
||||
values.language = style.language.clone();
|
||||
values.digits = Some(digit_name(style.digits).to_string());
|
||||
values
|
||||
}
|
||||
|
||||
/// The engine's `digits` name of a digit style.
|
||||
pub(crate) fn digit_name(d: Digits) -> &'static str {
|
||||
match d {
|
||||
Digits::AsTyped => "asTyped",
|
||||
Digits::Western => "western",
|
||||
Digits::Contextual => "contextual",
|
||||
Digits::Devanagari => "devanagari",
|
||||
Digits::Bengali => "bengali",
|
||||
Digits::Gurmukhi => "gurmukhi",
|
||||
Digits::Gujarati => "gujarati",
|
||||
Digits::Odia => "odia",
|
||||
Digits::Tamil => "tamil",
|
||||
Digits::Telugu => "telugu",
|
||||
Digits::Kannada => "kannada",
|
||||
Digits::Malayalam => "malayalam",
|
||||
}
|
||||
}
|
||||
|
||||
/// The values the Paragraph controls show for `style`.
|
||||
pub(crate) fn paragraph_values(style: &ParagraphStyle) -> ParagraphValues {
|
||||
use photocraft_doc::text::TextDirection as D;
|
||||
|
||||
@@ -25,6 +25,7 @@ use serde_json::{Value, json};
|
||||
use super::fields::{PrefPages, RESET_WARNING_DIALOGS_ROW, choice_label};
|
||||
use super::{PhotocraftApp, prefs};
|
||||
use craft::ui::patterns::preferences::{CustomSettings, SettingsDraft};
|
||||
use photocraft_engine::prefs::{RawSharpen, RawSharpenAmount};
|
||||
|
||||
const MEMORY_PERCENT: &str = "performance.memoryUsagePercent";
|
||||
const MEMORY_MB: &str = "performance.memoryUsageMb";
|
||||
@@ -39,6 +40,8 @@ const DARK_THEME: &str = "interface.darkTheme";
|
||||
const FAVORITE_THEMES: &str = "interface.favoriteThemes";
|
||||
const DENSITY: &str = "interface.density";
|
||||
const RAW_RESOLUTION: &str = "rawDefaults.resolution";
|
||||
const RAW_SHARPEN_FOR: &str = "rawDefaults.sharpenFor";
|
||||
const RAW_SHARPEN_AMOUNT: &str = "rawDefaults.sharpenAmount";
|
||||
/// The page agents' settings live on, drawn whole by [`craft::automation::ui::agents::AgentsPage`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(super) const AGENTS_PAGE: &str = "integrations";
|
||||
@@ -103,6 +106,8 @@ impl CustomSettings<PrefPages> for PrefsCustom {
|
||||
"tools.tabletInput" => tablet_input_row(ui, draft),
|
||||
APPEARANCE_MODE => self.appearance_row(ui, draft),
|
||||
RAW_RESOLUTION => raw_resolution_row(ui, draft),
|
||||
RAW_SHARPEN_FOR => raw_sharpen_for_row(ui, draft),
|
||||
RAW_SHARPEN_AMOUNT => raw_sharpen_amount_row(ui, draft),
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
@@ -195,6 +200,45 @@ fn raw_resolution_row(ui: &mut egui::Ui, draft: &mut SettingsDraft) {
|
||||
}
|
||||
}
|
||||
|
||||
/// None is the saved off state. Show Screen as the disabled choice and start there when turned on.
|
||||
fn raw_sharpen_for_row(ui: &mut egui::Ui, draft: &mut SettingsDraft) {
|
||||
let stored: RawSharpen = draft.get(RAW_SHARPEN_FOR).unwrap_or_default();
|
||||
let was_on = stored != RawSharpen::None;
|
||||
let mut on = was_on;
|
||||
let mut medium = if was_on { stored } else { RawSharpen::Screen };
|
||||
let options = [
|
||||
Entry::new(RawSharpen::Screen, tl!("Screen").to_string()),
|
||||
Entry::new(RawSharpen::Glossy, tl!("Glossy Paper").to_string()),
|
||||
Entry::new(RawSharpen::Matte, tl!("Matte Paper").to_string()),
|
||||
];
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::bound(&mut on)).label(tl!("Sharpen For")).show(ui);
|
||||
Select::new(tl!("Output Medium").to_string(), Bind::bound(&mut medium), &options).enabled(on).show(ui);
|
||||
});
|
||||
let next = if on { medium } else { RawSharpen::None };
|
||||
if next != stored {
|
||||
draft.set(RAW_SHARPEN_FOR, &next);
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_sharpen_amount_row(ui: &mut egui::Ui, draft: &mut SettingsDraft) {
|
||||
let on = draft.get::<RawSharpen>(RAW_SHARPEN_FOR).unwrap_or_default() != RawSharpen::None;
|
||||
let stored: RawSharpenAmount = draft.get(RAW_SHARPEN_AMOUNT).unwrap_or_default();
|
||||
let mut amount = stored;
|
||||
let options = [
|
||||
Entry::new(RawSharpenAmount::Low, tl!("Low").to_string()),
|
||||
Entry::new(RawSharpenAmount::Standard, tl!("Standard").to_string()),
|
||||
Entry::new(RawSharpenAmount::High, tl!("High").to_string()),
|
||||
];
|
||||
let label = tl!("Amount");
|
||||
Field::new(label.to_string()).show(ui, |ui, _| {
|
||||
Select::new(label.to_string(), Bind::bound(&mut amount), &options).enabled(on).show(ui);
|
||||
});
|
||||
if amount != stored {
|
||||
draft.set(RAW_SHARPEN_AMOUNT, &amount);
|
||||
}
|
||||
}
|
||||
|
||||
/// A checkbox enabling a 1–95 % field; off stores no value.
|
||||
fn memory_percent_row(ui: &mut egui::Ui, draft: &mut SettingsDraft) {
|
||||
let stored: Option<u32> = draft.get(MEMORY_PERCENT);
|
||||
|
||||
@@ -191,6 +191,9 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec<SettingRule> {
|
||||
// RAW Defaults › Resolution drops a typed comma and alerts when it clamps (#18027), which the window's own
|
||||
// whole-number row does not.
|
||||
tweak(&mut rules, "rawDefaults.resolution", |r| r.custom());
|
||||
// The sharpening checkbox uses the saved medium's None value as off. Its two selects stay visible when off.
|
||||
tweak(&mut rules, "rawDefaults.sharpenFor", |r| r.custom_rows());
|
||||
tweak(&mut rules, "rawDefaults.sharpenAmount", |r| r.label("Amount").custom_rows());
|
||||
// Rows that draw their own label or heading, so the window adds none: the Appearance page (Appearance Mode, the
|
||||
// themes), Rendering Mode's select, the Memory Usage block and its labelled percent checkbox.
|
||||
for path in ["interface.appearanceMode", "performance.renderingMode", "performance.memoryUsageMb", "performance.memoryUsagePercent"] {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
//! The Stack Mode flyout reports the active Smart Object's stored mode in automation and AccessKit.
|
||||
|
||||
use craft::window::policy::{CaptionFamily, Captions, Decision, Desktop, DesktopKind, Frame};
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
use egui::{Event, Modifiers, PointerButton};
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use photocraft_doc::StackMode;
|
||||
use photocraft_engine::Session;
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
use crate::shortcut_dispatch::tests::app_harness;
|
||||
use crate::{PhotocraftApp, Services};
|
||||
|
||||
const PREFIX: &str = "layer.smartObjects.stackMode.";
|
||||
const NONE: &str = "layer.smartObjects.stackMode.none";
|
||||
|
||||
fn smart_object() -> Session {
|
||||
let mut session = Session::new();
|
||||
session.execute("file.new", json!({"width": 16, "height": 12})).unwrap();
|
||||
session.execute("layer.new.layer", json!({})).unwrap();
|
||||
session
|
||||
.edit("paint", |doc, active| {
|
||||
doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(2, 2, 10, 8), &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
|
||||
session
|
||||
}
|
||||
|
||||
fn assert_listed_mode(app: &mut PhotocraftApp, current: Option<StackMode>, enabled: bool) {
|
||||
let (request, _reply) = ControlRequest::new("ui.menu.list", json!({}));
|
||||
let ctx = app.ctx().clone();
|
||||
let Reply::Done(reply) = crate::control::handle(app, &ctx, &request) else { panic!("expected an immediate menu response") };
|
||||
let rows = reply["result"].as_array().expect("ui.menu.list returns rows");
|
||||
let find = |id: &str| rows.iter().find(|row| row["id"] == id).unwrap_or_else(|| panic!("missing row {id}"));
|
||||
for mode in StackMode::ALL {
|
||||
let row = find(&format!("{PREFIX}{}", mode.id()));
|
||||
assert_eq!(row["checked"], Some(mode) == current, "{row}");
|
||||
assert_eq!(row["enabled"], enabled, "{row}");
|
||||
}
|
||||
assert_eq!(find(NONE)["checked"], Value::Null, "None remains a plain command");
|
||||
assert_eq!(find(NONE)["enabled"], enabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn menu_list_checks_only_the_active_smart_objects_current_mode() {
|
||||
let mut app = PhotocraftApp::new(smart_object(), Services::default());
|
||||
let smart = app.session.active().unwrap().active_layer.unwrap();
|
||||
assert_listed_mode(&mut app, None, true);
|
||||
|
||||
app.session.execute("layer.smartObjects.stackMode.median", json!({})).unwrap();
|
||||
assert_listed_mode(&mut app, Some(StackMode::Median), true);
|
||||
|
||||
app.session.execute("layer.smartObjects.stackMode.standardDeviation", json!({})).unwrap();
|
||||
assert_listed_mode(&mut app, Some(StackMode::StandardDeviation), true);
|
||||
|
||||
app.session.execute("layer.new.layer", json!({})).unwrap();
|
||||
assert_listed_mode(&mut app, None, false);
|
||||
app.session.select_layer(smart).unwrap();
|
||||
assert_listed_mode(&mut app, Some(StackMode::StandardDeviation), true);
|
||||
|
||||
app.session.execute(NONE, json!({})).unwrap();
|
||||
assert_listed_mode(&mut app, None, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_stack_mode_flyout_exposes_its_check_in_the_accessibility_tree() {
|
||||
let mut session = smart_object();
|
||||
session.execute("layer.smartObjects.stackMode.median", json!({})).unwrap();
|
||||
|
||||
// Use the in-window bar even on hosts that ordinarily use a native menu bar.
|
||||
let ctx = egui::Context::default();
|
||||
let frame = Frame::Integrated(Captions { family: CaptionFamily::Windows, layout: craft::window::Layout::default() });
|
||||
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
|
||||
PhotocraftApp::setup_window(&ctx, Default::default(), Decision { frame, overridden: None, desktop }, None);
|
||||
let mut h = app_harness(PhotocraftApp::with_context(ctx, session, Services::default()));
|
||||
|
||||
let at = h.get_by_role_and_label(Role::MenuItem, "Layer").rect().center();
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.step();
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(6);
|
||||
for submenu in ["Smart Objects", "Stack Mode"] {
|
||||
let at = h.get_by_role_and_label(Role::MenuItem, submenu).rect().center();
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.run_steps(6);
|
||||
}
|
||||
|
||||
let median = h.get_by_role_and_label(Role::MenuItemCheckBox, "Median");
|
||||
assert_eq!(median.accesskit_node().toggled(), Some(Toggled::True));
|
||||
let mean = h.get_by_role_and_label(Role::MenuItemCheckBox, "Mean");
|
||||
assert_eq!(mean.accesskit_node().toggled(), Some(Toggled::False));
|
||||
let none = h.get_by_role_and_label(Role::MenuItem, "None");
|
||||
assert_eq!(none.accesskit_node().toggled(), None);
|
||||
}
|
||||
@@ -26,6 +26,7 @@ use crate::state::Tool;
|
||||
/// The family's state between passes, kept in `CanvasTools::analysis`.
|
||||
pub(crate) struct AnalysisTools {
|
||||
ruler: RulerTool,
|
||||
scale: ScaleRuler,
|
||||
sampler: ColorSamplerTool,
|
||||
/// The document's points as the framework's collection, which the sampler pass borrows. It is rebuilt from the
|
||||
/// document at every pass (`tool`); it is storage for that borrow, not state.
|
||||
@@ -38,6 +39,7 @@ impl Default for AnalysisTools {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ruler: RulerTool::new(),
|
||||
scale: ScaleRuler::default(),
|
||||
sampler: ColorSamplerTool::new(),
|
||||
samplers: ColorSamplers::new(),
|
||||
count: CountTool::default(),
|
||||
@@ -46,6 +48,72 @@ impl Default for AnalysisTools {
|
||||
}
|
||||
}
|
||||
|
||||
/// The scale form's temporary line and the draft value as they stood before a drag. Neither touches the document.
|
||||
#[derive(Default)]
|
||||
struct ScaleRuler {
|
||||
tool: RulerTool,
|
||||
line: Option<RulerLine>,
|
||||
before: Option<(Option<RulerLine>, f64)>,
|
||||
}
|
||||
|
||||
impl ScaleRuler {
|
||||
fn restore_drag(&mut self, app: &mut PhotocraftApp) {
|
||||
if let Some((line, length)) = self.before.take() {
|
||||
self.line = line;
|
||||
super::dialogs::set_pixel_length(app, length);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_line(&mut self, app: &mut PhotocraftApp, line: Option<RulerLine>) {
|
||||
self.line = line;
|
||||
if let Some(line) = line {
|
||||
let length = line.start.distance(line.end);
|
||||
if length.is_finite() && length > 0.0 {
|
||||
super::dialogs::set_pixel_length(app, length.round().clamp(1.0, super::dialogs::MAX_PIXEL_LENGTH));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn drain(&mut self, app: &mut PhotocraftApp) {
|
||||
if !super::dialogs::measuring(app) {
|
||||
if self.before.is_some() {
|
||||
self.restore_drag(app);
|
||||
self.tool = RulerTool::new();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for event in self.tool.take_events() {
|
||||
match event {
|
||||
EditEvent::Begin { .. } => {
|
||||
self.before = super::dialogs::pixel_length(app).map(|length| (self.line, length));
|
||||
}
|
||||
EditEvent::Update { value, .. } => self.set_line(app, value),
|
||||
EditEvent::Commit { after, .. } => {
|
||||
if self.before.is_some_and(|(line, _)| after == line && self.line != after) {
|
||||
// A click or short release kept the preceding line. Keep the draft length too.
|
||||
self.restore_drag(app);
|
||||
} else {
|
||||
self.set_line(app, after);
|
||||
self.before = None;
|
||||
}
|
||||
}
|
||||
EditEvent::Set { after, .. } => self.set_line(app, after),
|
||||
EditEvent::Cancel { .. } => self.restore_drag(app),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this exact canvas may run the temporary scale ruler and paint its line.
|
||||
pub(crate) fn scale_ruler_on(app: &PhotocraftApp, host: CanvasHost) -> bool {
|
||||
app.session.active_index() == Some(host.idx) && host.is_primary(app) && super::dialogs::measuring(app)
|
||||
}
|
||||
|
||||
pub(super) fn clear_scale_ruler(app: &mut PhotocraftApp) {
|
||||
app.canvas_tools.analysis.scale = ScaleRuler::default();
|
||||
}
|
||||
|
||||
/// The document's Color Sampler points as the framework's collection, with the document's size in pixels. The one
|
||||
/// place the document's list becomes `ColorSamplers`.
|
||||
pub(super) fn samplers_of(app: &PhotocraftApp) -> Option<(ColorSamplers, [u32; 2])> {
|
||||
@@ -68,10 +136,11 @@ fn ruler_line(app: &PhotocraftApp) -> Option<RulerLine> {
|
||||
}
|
||||
|
||||
/// The tool of `Tool::{Ruler, ColorSampler, Count, Note}` for one pass.
|
||||
pub(crate) fn tool<'a>(scope: &'a ToolScope<'a>, state: &'a mut AnalysisTools, _host: CanvasHost) -> FamilyTool<'a> {
|
||||
pub(crate) fn tool<'a>(scope: &'a ToolScope<'a>, state: &'a mut AnalysisTools, host: CanvasHost) -> FamilyTool<'a> {
|
||||
let tool = scope.with_app(|app| app.ui.tool);
|
||||
let AnalysisTools { ruler, sampler, samplers, count, note } = state;
|
||||
let AnalysisTools { ruler, scale, sampler, samplers, count, note } = state;
|
||||
match tool {
|
||||
Tool::Ruler if scope.with_app(|app| scale_ruler_on(app, host)) => Box::new(scale.tool.pass(scale.line)),
|
||||
Tool::Ruler => {
|
||||
let line = scope.with_app(|app| ruler_line(app));
|
||||
Box::new(ruler.pass(line))
|
||||
@@ -97,6 +166,7 @@ pub(crate) fn tool<'a>(scope: &'a ToolScope<'a>, state: &'a mut AnalysisTools, _
|
||||
|
||||
/// Turns the events the tools reported into engine commands, in order.
|
||||
pub(crate) fn drain(app: &mut PhotocraftApp, state: &mut AnalysisTools, _response: &ToolHostResponse) {
|
||||
state.scale.drain(app);
|
||||
for event in state.ruler.take_events() {
|
||||
match event {
|
||||
// A drag's updates are not applied: the pass shows the running line from the tool's own proposal, and the
|
||||
@@ -220,11 +290,12 @@ fn pixel_centre(at: [f64; 2]) -> [f64; 2] {
|
||||
/// The ruler line, the sampler marks, the count markers and the note cards over the document, in the canvas body over
|
||||
/// `rect`. The marks show with every tool; the line with its handles only with the Ruler. View › Extras off hides the
|
||||
/// line (View › Show has no Ruler entry, #11987) and the sampler marks, whose points and Info readouts stay (#11741).
|
||||
pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect, host: CanvasHost) {
|
||||
let scale = scale_ruler_on(app, host);
|
||||
let view = &app.ui.view;
|
||||
let (show_count, show_notes, extras) = (view.shows(view.show.count), view.shows(view.show.notes), view.extras);
|
||||
let line = ruler_line(app).filter(|_| extras);
|
||||
let samplers = samplers_of(app).map(|(s, _)| s).filter(|_| extras);
|
||||
let samplers = if extras && !app.ui.analysis.hide_color_samplers { samplers_of(app).map(|(samplers, _)| samplers) } else { None };
|
||||
let groups: Vec<CountGroupMarks> = if show_count {
|
||||
app.session.active().map_or_else(Vec::new, |d| {
|
||||
d.doc
|
||||
@@ -250,7 +321,10 @@ pub(crate) fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
};
|
||||
let selected = app.ui.analysis.note_selected;
|
||||
let tools = &mut app.canvas_tools.analysis;
|
||||
if app.ui.tool == Tool::Ruler {
|
||||
if scale {
|
||||
let scale = &mut tools.scale;
|
||||
scale.tool.pass(scale.line.filter(|_| extras)).show_line(ui, rect);
|
||||
} else if app.ui.tool == Tool::Ruler {
|
||||
tools.ruler.pass(line).show_line(ui, rect);
|
||||
} else if let Some(line) = line {
|
||||
// The line and its arm stay drawn under every tool (#11987); only the Ruler tool has handles on them.
|
||||
@@ -645,3 +719,7 @@ impl Component for NoteCards {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "scale_ruler_while_open_tests.rs"]
|
||||
mod scale_ruler_while_open_tests;
|
||||
@@ -1,19 +1,23 @@
|
||||
//! The Set Measurement Scale, Select Data Points and Place Scale Marker dialogs: parameter forms hosted on the dialog
|
||||
//! host, answered through the `ParamFamily` row of `dialogs.rs`.
|
||||
|
||||
use craft::behavior::IconId;
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, Props as _, Scroll, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::display::{Divider, Elide, Text};
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use craft::ui::contract::{Bind, CanvasGesture, Props as _, Sampler as _, Scroll, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, dialog_id};
|
||||
use craft::ui::display::{Divider, Elide, Icon, Text};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use craft::ui::primitives::IconSpec;
|
||||
use craft::ui::runtime::env::{Env, Label, UnitKind};
|
||||
use photocraft_doc::Document;
|
||||
use photocraft_doc::{DocId, Document};
|
||||
use photocraft_engine::analysis_cmds;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::document_display::CanvasHost;
|
||||
use crate::dialogs::params;
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The three analysis dialogs.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -58,9 +62,21 @@ fn suggested_length(d: &Document) -> f64 {
|
||||
pub(crate) fn open(app: &mut PhotocraftApp, kind: Kind) -> Result<DialogId, String> {
|
||||
let no_document = || tl!("No document is open.").to_owned();
|
||||
let mut fields = DialogFields::new();
|
||||
let mut captured = Value::Null;
|
||||
match kind {
|
||||
Kind::Scale => {
|
||||
let id = scale_id();
|
||||
if app.framework.dialogs.get_by_id::<HostedParamDialog>(id).is_some() {
|
||||
return Ok(id);
|
||||
}
|
||||
let doc = app.session.active().ok_or_else(no_document)?.doc.clone();
|
||||
let previous = crate::tool_memory::selected(app);
|
||||
captured = json!({"document": doc.id.0, "previousTool": previous});
|
||||
let ctx = app.ctx().clone();
|
||||
crate::canvas::tools::cancel_document_gesture(app, &ctx, doc.id);
|
||||
app.ui.spring = None;
|
||||
app.stylus.tool_before_eraser = None;
|
||||
app.ui.tool = Tool::Ruler;
|
||||
let sc = &doc.measurement.scale;
|
||||
fields.set("preset", "custom");
|
||||
fields.set("pixelLength", sc.pixel_length);
|
||||
@@ -82,7 +98,54 @@ pub(crate) fn open(app: &mut PhotocraftApp, kind: Kind) -> Result<DialogId, Stri
|
||||
fields.set("color", "black");
|
||||
}
|
||||
}
|
||||
Ok(params::open_param(app, kind.command(), fields, Value::Null, move |f: &mut DialogFields| form(kind, f)))
|
||||
let scale_canvas = app.session.active_index().filter(|_| kind == Kind::Scale).map(|index| CanvasHost::primary(app, index).canvas_id());
|
||||
Ok(params::open_param(app, kind.command(), fields, captured, move |f: &mut DialogFields| form(kind, f, scale_canvas)))
|
||||
}
|
||||
|
||||
fn scale_id() -> DialogId {
|
||||
dialog_id(Kind::Scale.command())
|
||||
}
|
||||
|
||||
/// The document bound to the scale form, for the host's document-close and canvas-routing checks.
|
||||
pub(crate) fn document(captured: &Value) -> Option<DocId> {
|
||||
captured.get("document").and_then(Value::as_u64).map(DocId)
|
||||
}
|
||||
|
||||
/// The top scale dialog can measure only the active document it opened on.
|
||||
pub(super) fn measuring(app: &PhotocraftApp) -> bool {
|
||||
app.framework.dialogs.stack().top() == Some(scale_id())
|
||||
&& app.ui.tool == Tool::Ruler
|
||||
&& app.framework.captured.get(Kind::Scale.command()).and_then(document).is_some_and(|id| app.session.active().is_some_and(|st| st.doc.id == id))
|
||||
}
|
||||
|
||||
pub(super) fn pixel_length(app: &PhotocraftApp) -> Option<f64> {
|
||||
app.framework.dialogs.get_by_id::<HostedParamDialog>(scale_id())?.fields().number("pixelLength")
|
||||
}
|
||||
|
||||
pub(super) fn set_pixel_length(app: &mut PhotocraftApp, length: f64) {
|
||||
if let Some(form) = app.framework.dialogs.get_mut_by_id::<HostedParamDialog>(scale_id())
|
||||
&& form.fields().number("pixelLength") != Some(length)
|
||||
{
|
||||
form.set_field("pixelLength", FieldValue::Number(length));
|
||||
}
|
||||
}
|
||||
|
||||
/// OK and every cancellation path give the canvas and previous tool back together.
|
||||
fn finish_scale(app: &mut PhotocraftApp, ctx: &egui::Context, captured: &Value) {
|
||||
if let Some(doc) = document(captured) {
|
||||
crate::canvas::tools::cancel_document_gesture(app, ctx, doc);
|
||||
}
|
||||
super::canvas::clear_scale_ruler(app);
|
||||
if let Some(previous) = captured.get("previousTool").and_then(|tool| serde_json::from_value(tool.clone()).ok()) {
|
||||
app.ui.tool = previous;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn cancel(app: &mut PhotocraftApp, ctx: &egui::Context, id: DialogId) {
|
||||
if id == scale_id() {
|
||||
let captured = params::captured(app, Kind::Scale.command());
|
||||
finish_scale(app, ctx, &captured);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `key` is the key of one of these dialogs.
|
||||
@@ -109,10 +172,20 @@ pub(crate) fn command(kind: Kind, f: &DialogFields) -> Option<(&'static str, Val
|
||||
}
|
||||
|
||||
/// OK: runs the dialog's command; an engine refusal goes to the status line.
|
||||
pub(crate) fn run(app: &mut PhotocraftApp, _ctx: &egui::Context, result: ParamResult) {
|
||||
pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamResult) {
|
||||
let Some(kind) = Kind::of(&result.key) else { return };
|
||||
let Some((id, params)) = command(kind, &result.fields) else { return };
|
||||
if let Err(error) = app.run(id, params)
|
||||
let Some((id, values)) = command(kind, &result.fields) else { return };
|
||||
let outcome = if kind == Kind::Scale {
|
||||
let captured = params::captured(app, id);
|
||||
finish_scale(app, ctx, &captured);
|
||||
match document(&captured) {
|
||||
Some(doc) => app.with_document(doc, |app| app.run(id, values)),
|
||||
None => Err(tl!("No document is open.").to_owned()),
|
||||
}
|
||||
} else {
|
||||
app.run(id, values)
|
||||
};
|
||||
if let Err(error) = outcome
|
||||
&& error != "cancelled"
|
||||
{
|
||||
app.ui.status = error;
|
||||
@@ -123,6 +196,8 @@ pub(crate) fn run(app: &mut PhotocraftApp, _ctx: &egui::Context, result: ParamRe
|
||||
/// The most characters of the scale readout that set its width: about the width of the dialog's fields.
|
||||
const READOUT_CHARS: usize = 46;
|
||||
|
||||
pub(super) const MAX_PIXEL_LENGTH: f64 = 1e7;
|
||||
|
||||
/// The Measurement Scale readout: `<px> pixel(s) = <length, 4 decimals> <units>`, with `decimal` as the decimal mark,
|
||||
/// as the reference shows it while the values are typed (#17414). The Default preset reads 1 pixel(s) = 1 pixels.
|
||||
pub(crate) fn scale_readout(f: &DialogFields, decimal: char) -> String {
|
||||
@@ -135,23 +210,36 @@ pub(crate) fn scale_readout(f: &DialogFields, decimal: char) -> String {
|
||||
format!("{} pixel(s) = {} {units}", mark(pixels.to_string()), mark(format!("{length:.4}")))
|
||||
}
|
||||
|
||||
fn scale_ruler_note(ui: &mut egui::Ui, canvas: Option<egui::Id>) {
|
||||
Row::new().show(ui, |ui, cx| {
|
||||
// The dialog runs every pass, even when the canvas replays its cached draw.
|
||||
if let Some(canvas) = canvas {
|
||||
cx.pass_canvas_gesture(canvas, CanvasGesture::PRIMARY);
|
||||
}
|
||||
Icon::new(IconSpec::svg(IconId::new("info"))).show(ui);
|
||||
let note = tl!("The Ruler tool has been activated while this dialog is open. You may use it to measure the pixel length for use in your scale.");
|
||||
let sample: String = note.chars().take(READOUT_CHARS).collect();
|
||||
Text::new(note).sample(Label::from(sample)).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
fn options(pairs: &[(&str, &str)]) -> Vec<(String, Label)> {
|
||||
pairs.iter().map(|(key, name)| ((*key).to_owned(), Label::from((*name).to_owned()))).collect()
|
||||
}
|
||||
|
||||
/// The dialog of `kind` over `fields`.
|
||||
fn form(kind: Kind, fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
fn form(kind: Kind, fields: &mut DialogFields, scale_canvas: Option<egui::Id>) -> ParamDialog<'_> {
|
||||
let key = kind.command();
|
||||
let dialog = match kind {
|
||||
Kind::Scale => {
|
||||
let rows = vec![
|
||||
Param::new("preset", tl!("Presets:"), ParamKind::choice(options(&[("custom", tl!("Custom"))]), Some("custom".into()))).not_remembered(),
|
||||
// The dialog opens on its first text-entry field and selects its value.
|
||||
Param::new("pixelLength", tl!("Pixel Length:"), ParamKind::number(Some(0.001), Some(1e7), 1.0, 1.0, 4)).not_remembered(),
|
||||
Param::new("pixelLength", tl!("Pixel Length:"), ParamKind::number(Some(0.001), Some(MAX_PIXEL_LENGTH), 1.0, 1.0, 4)).not_remembered(),
|
||||
Param::new("logicalLength", tl!("Logical Length:"), ParamKind::number(Some(0.0001), Some(1e7), 1.0, 1.0, 4)).not_remembered(),
|
||||
Param::new("units", tl!("Logical Units:"), ParamKind::text("pixels")).not_remembered(),
|
||||
];
|
||||
ParamDialog::command(key, tl!("Measurement Scale"), rows).below(|ui, f| {
|
||||
ParamDialog::command(key, tl!("Measurement Scale"), rows).below(move |ui, f| {
|
||||
// One line: units too long for it are cut with "…", so the dialog keeps its width (#17414). The decimal
|
||||
// mark is the one the fields above write: the system's (any mark, not only `.` or `,`) or the host's.
|
||||
let text = scale_readout(f, Env::of(ui).format().separators().0);
|
||||
@@ -159,6 +247,7 @@ fn form(kind: Kind, fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
// and long units are cut with "…" instead of widening the dialog.
|
||||
let sample: String = text.chars().take(READOUT_CHARS).collect();
|
||||
Text::new(Label::from(text)).elide(Elide::End).sample(Label::from(sample)).show(ui);
|
||||
scale_ruler_note(ui, scale_canvas);
|
||||
})
|
||||
}
|
||||
Kind::DataPoints => {
|
||||
|
||||
@@ -96,6 +96,9 @@ pub struct AnalysisUi {
|
||||
pub note_color: [f32; 3],
|
||||
/// Ruler options bar: show values in the measurement scale's units.
|
||||
pub use_measurement_scale: bool,
|
||||
/// The Info panel and canvas hide sampler readouts and marks for this app session.
|
||||
#[serde(skip)]
|
||||
pub(crate) hide_color_samplers: bool,
|
||||
}
|
||||
|
||||
impl Default for AnalysisUi {
|
||||
@@ -107,6 +110,7 @@ impl Default for AnalysisUi {
|
||||
note_author: String::new(),
|
||||
note_color: photocraft_engine::notes_cmds::DEFAULT_NOTE_COLOR,
|
||||
use_measurement_scale: false,
|
||||
hide_color_samplers: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user