diff --git a/ASSETS.md b/ASSETS.md
index 029a978153..ffa455079d 100644
--- a/ASSETS.md
+++ b/ASSETS.md
@@ -115,6 +115,7 @@ Generated-in-code art is original and has no file to list. This covers the defau
| `assets/icons/dc-anchor-smooth.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-appearance.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-arc.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
+| `assets/icons/dc-arc-three-point.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | The Three-Point Arc tool: an arc through its two ends and a third point |
| `assets/icons/dc-arrow-down.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-arrow-extend.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-arrow-fill.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | The Selection and Direct Selection arrows' fill, painted black or white under their outline |
diff --git a/Cargo.lock b/Cargo.lock
index fa3b9166e7..65cc426291 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1001,7 +1001,7 @@ dependencies = [
[[package]]
name = "craft-affinity"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"crc32fast",
"flate2",
@@ -1012,12 +1012,12 @@ dependencies = [
[[package]]
name = "craft-codepage"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
[[package]]
name = "craft-dds"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"rayon",
]
@@ -1025,12 +1025,12 @@ dependencies = [
[[package]]
name = "craft-docpath"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
[[package]]
name = "craft-dxf"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"craft-codepage",
"encoding_rs",
@@ -1042,12 +1042,12 @@ dependencies = [
[[package]]
name = "craft-eps"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
[[package]]
name = "craft-font-catalog"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3#23acc704933a9a5619a5cd1cddc9bb1fb5a9b2d3"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"harfrust 0.13.3",
"kurbo 0.13.1",
@@ -1061,12 +1061,12 @@ dependencies = [
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
[[package]]
name = "craft-gif"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"gif",
]
@@ -1074,7 +1074,7 @@ dependencies = [
[[package]]
name = "craft-gzip"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"flate2",
]
@@ -1082,7 +1082,7 @@ dependencies = [
[[package]]
name = "craft-i18n"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"fixed_decimal",
"icu_decimal",
@@ -1105,7 +1105,7 @@ dependencies = [
[[package]]
name = "craft-image-codecs"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"craft-dds",
"craft-jpeg",
@@ -1132,7 +1132,7 @@ dependencies = [
[[package]]
name = "craft-jpeg"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"thiserror 2.0.21",
]
@@ -1140,8 +1140,9 @@ dependencies = [
[[package]]
name = "craft-jxl"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
+ "brotli-decompressor 5.0.3",
"jixel",
"jxl-oxide",
"thiserror 2.0.21",
@@ -1150,7 +1151,7 @@ dependencies = [
[[package]]
name = "craft-keymap"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"egui",
"serde",
@@ -1160,7 +1161,7 @@ dependencies = [
[[package]]
name = "craft-metadata"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"brotli-decompressor 6.3.2",
"chrono",
@@ -1172,7 +1173,7 @@ dependencies = [
[[package]]
name = "craft-metafile"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"encoding_rs",
"image",
@@ -1183,7 +1184,7 @@ dependencies = [
[[package]]
name = "craft-mime"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"chrono",
"craft-codepage",
@@ -1193,7 +1194,7 @@ dependencies = [
[[package]]
name = "craft-pdf"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"hayro-interpret",
"hayro-syntax",
@@ -1204,15 +1205,16 @@ dependencies = [
[[package]]
name = "craft-plotter"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=a7fb55eaf9a15c21e8ce0b13cf605dc54fd15f57#a7fb55eaf9a15c21e8ce0b13cf605dc54fd15f57"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
+ "kurbo 0.13.1",
"thiserror 2.0.21",
]
[[package]]
name = "craft-print"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"craft-winprint-gdi",
"log",
@@ -1226,7 +1228,7 @@ dependencies = [
[[package]]
name = "craft-proof"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"log",
"miniz_oxide 0.9.1",
@@ -1237,7 +1239,7 @@ dependencies = [
[[package]]
name = "craft-ps"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"flate2",
"kurbo 0.13.1",
@@ -1246,7 +1248,7 @@ dependencies = [
[[package]]
name = "craft-psd"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"encoding_rs",
"flate2",
@@ -1257,7 +1259,7 @@ dependencies = [
[[package]]
name = "craft-stream-codecs"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"fax",
"hayro-ccitt",
@@ -1268,12 +1270,14 @@ dependencies = [
[[package]]
name = "craft-svg"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"craft-image-codecs",
"craft-xml",
"data-url",
"flate2",
+ "gif",
+ "image-webp",
"kurbo 0.13.1",
"quick-xml 0.41.0",
"resvg 0.48.1",
@@ -1287,7 +1291,7 @@ dependencies = [
[[package]]
name = "craft-tiff"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"serde",
"thiserror 2.0.21",
@@ -1296,7 +1300,7 @@ dependencies = [
[[package]]
name = "craft-ui"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"craft-fonts-build",
"craft-i18n",
@@ -1317,7 +1321,7 @@ dependencies = [
[[package]]
name = "craft-update"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"chrono",
"dunce",
@@ -1344,7 +1348,7 @@ dependencies = [
[[package]]
name = "craft-vectorcraft-format"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"flate2",
"serde",
@@ -1355,7 +1359,7 @@ dependencies = [
[[package]]
name = "craft-web-api"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"js-sys",
"serde_json",
@@ -1366,7 +1370,7 @@ dependencies = [
[[package]]
name = "craft-window"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"egui",
"objc2 0.6.5",
@@ -1385,7 +1389,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"quick-xml 0.41.0",
"serde",
@@ -2492,7 +2496,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
[[package]]
name = "hayro-cmap"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"brotli",
"hayro-postscript",
@@ -2501,7 +2505,7 @@ dependencies = [
[[package]]
name = "hayro-interpret"
version = "0.7.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"bitflags 2.13.2",
"hayro-cmap",
@@ -2519,7 +2523,7 @@ dependencies = [
[[package]]
name = "hayro-jbig2"
version = "0.3.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"fearless_simd",
"hayro-ccitt",
@@ -2537,12 +2541,12 @@ dependencies = [
[[package]]
name = "hayro-postscript"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
[[package]]
name = "hayro-syntax"
version = "0.7.2"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"flate2",
"hayro-ccitt",
@@ -3342,7 +3346,7 @@ dependencies = [
[[package]]
name = "krilla"
version = "0.8.2"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"base64 0.22.1",
"bumpalo",
@@ -3451,7 +3455,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
[[package]]
name = "linesweeper"
version = "0.5.0"
-source = "git+https://github.com/storytold/craft-libs?rev=64b181977a0488e4d1e167bc5cc8cfededc2ed4b#64b181977a0488e4d1e167bc5cc8cfededc2ed4b"
+source = "git+https://github.com/storytold/craft-libs?rev=50b0ee7bf811e363b5f238382b5c77318cf33e46#50b0ee7bf811e363b5f238382b5c77318cf33e46"
dependencies = [
"arrayvec",
"kurbo 0.13.1",
diff --git a/Cargo.toml b/Cargo.toml
index e334f3e9e3..fea9cdda55 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,40 +11,40 @@ rust-version = "1.95"
repository = "https://github.com/storytold/vectorcraft"
[workspace.dependencies]
-craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", default-features = false, features = ["interpret", "write"] }
-craft-print = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", features = ["serde"] }
-craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", default-features = false, features = ["interpret", "write"] }
+craft-print = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", features = ["serde"] }
+craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# Decides who draws the window frame (desktop vs. app) so the suite shares one native titlebar per
# desktop. The `egui` feature adds `craft_window::decorate`. (craft-libs#217.)
-craft-window = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", features = ["egui"] }
+craft-window = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", features = ["egui"] }
# The `.vectorcraft` envelope: its members, version, embedded images and the data after the JSON.
-craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
# Native Affinity documents (craft-libs#914).
-craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# SVG parsing, limits, SVGZ and writer (craft-libs#778).
-craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", features = ["tree"] }
-craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", features = ["tree"] }
+craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# EPS container, previews, ASCII85 and DSC comments (craft-libs#778).
-craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# DXF tags, reader and writer (craft-libs#778, #926, #927).
-craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "a7fb55eaf9a15c21e8ce0b13cf605dc54fd15f57" }
-craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
# WMF, EMF and EMF+ reader (craft-libs#778).
-craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", default-features = false, features = ["write"] }
-craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", features = ["egui"] }
+craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", default-features = false, features = ["write"] }
+craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", features = ["egui"] }
# internal
vectorcraft-geom = { path = "crates/geom" }
vectorcraft-color = { path = "crates/color" }
@@ -185,13 +185,13 @@ lto = "thin"
codegen-units = 1
[patch.crates-io]
-hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-krilla = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
-linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b" }
+hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+krilla = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
+linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46" }
ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
diff --git a/ROADMAP.md b/ROADMAP.md
index c4a6edc8fb..ef05d5dc9a 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -128,6 +128,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap
- 2026-11-14: Built-in symbol library Weather Icons: adds a sixth procedural symbol library (Window › Symbol Libraries, the Symbols panel's Symbol Libraries Menu) containing six original vector symbols (Sun, Moon, Cloud, Rain, Thunder, Snow) generated in code without default 9-slice guides (part of Gap 5). Headline numbers unchanged.
- 2026-11-14: Built-in Tech Circuit brush library: Circuit Trace (chamfered art with 45-degree elbows and terminal pads), Bus Lines (parallel conductor pattern) and Terminal Nodes (repeating solder pads, test points and leads), all original geometry generated in code. Ten built-in brush libraries; G5 remaining estimate 3–13 h (estimated), headline numbers unchanged.
+- 2026-11-18: Built-in Paint brush library: Flat Sweep, Dry Drag, Loaded Stroke and Fan Sweep, original art brushes generated in code that take the stroke color as tints. Thirteen built-in brush libraries; headline numbers unchanged.
- 2026-11-05: Window › Toolbars › Keep Tools Beside the Canvas, off by default, docks the Tools panel between left-side panels and the canvas instead of at the window's left edge, and the canvas's left edge then also docks a floating Tools panel (`window.toolsBesideCanvas`, #5395). Workspaces keep the setting; workspaces saved without it keep Tools at the window's edge. An optional VectorCraft layout choice; headline numbers unchanged.
- 2026-11-17: The canvas's left edge docks a floating Tools panel whichever way Keep Tools Beside the Canvas is set: a drop there, right of panels docked on the left, turns the setting on, and a drop on the window's left edge turns it off (#7837). Headline numbers unchanged.
@@ -162,6 +163,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap
- 2026-11-17: Tangent Circle Tool joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools, and the All Tools drawer): click a path segment, then another, to draw the circle tangent to the first where it was clicked that touches the second; Shift uses the tool's radius and a drag from the second segment sets the radius (Shift in round steps, Cmd/Ctrl slowly), the circle then touching the first segment anywhere along it. The circle shows with its center and radii before the click, one undo step (`tangentCircle`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-18: Common Tangents also takes a point (a path of one anchor) and a convex closed path: the lines from the point that touch the path, and the line from the point to the path's center if asked; a point on the outline gets the one tangent there, and a point inside gets none, with a message (#7846). A VectorCraft addition: headline numbers unchanged.
- 2026-11-15: With Smart Guides and Snap to Tangent on, a Line Segment drag pressed on one convex curved path and dragged near another lands on a common tangent of the two: both ends move to where the line touches the paths, each labeled "tangent" (#7845). A VectorCraft addition: headline numbers unchanged.
+- 2026-11-17: Three-Point Arc tool, in the Line Segment tool's group after the Arc tool: two ends placed by a drag or two clicks, then a third point the open circular arc passes through, or with Third Point Sets Direction (Tool Options, or `]` while drawing) the direction the arc leaves an end in; it previews the arc, its center and, with Measurement Labels on, its radius, and draws it in one undo step (`shape.threePointArc`). Points with no arc are refused with a message. A VectorCraft addition: headline numbers unchanged.
- 2026-11-15: Smooth Bridge joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): two selected circles become one closed outline joined by two concave arcs that touch both circles, so every anchor is smooth; the arcs' radius is a percentage of the smaller circle's radius (1 to 1000%, 100% by default), and Keep Originals adds the outline above the circles instead of replacing them. A dialog with Preview, one undo step (`addon.pathtools.bridge`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-18: Smooth Bridge also joins three or more circles: every two whose outlines are within Reach (10 pt by default) are joined, the bridges that connect become one shape each, and a circle bridged to no other stays as it is (at most 2000 circles); with Constant Gap the arcs' radius is the smaller circle's radius plus a gap (#8030). A VectorCraft addition: headline numbers unchanged.
- 2026-11-03: Text Tweaker, the first tool of the Type Tools add-on (Object › Plug-ins › Type Tools): one character attribute (size, baseline shift, rotation, horizontal or vertical scale, tracking, leading or stroke weight) goes letter by letter from a start value to an end value along a straight ramp, an ease, a bow, a spike or at random with a seed, set as the Character panel sets it, while the text stays live; a dialog with Preview, one undo step (`addon.type.textTweaker`, #4924). A VectorCraft addition: headline numbers unchanged.
diff --git a/apps/vectorcraft-cli/src/main.rs b/apps/vectorcraft-cli/src/main.rs
index d1ead11969..533074b9b5 100644
--- a/apps/vectorcraft-cli/src/main.rs
+++ b/apps/vectorcraft-cli/src/main.rs
@@ -246,6 +246,7 @@ fn with_stores(mut h: Headless) -> Headless {
prefs_dir::attach_script_data(&mut h.session);
prefs_dir::attach_metadata_templates_dir(&mut h.session);
prefs_dir::attach_new_doc_profiles(&mut h.session);
+ prefs_dir::attach_proof_setups(&mut h.session);
prefs_dir::attach_profile_store(&mut h.session);
prefs_dir::attach_color_settings(&mut h.session);
prefs_dir::attach_plugin_store(&mut h.session);
diff --git a/apps/vectorcraft-web/Cargo.toml b/apps/vectorcraft-web/Cargo.toml
index f86996f075..9569d2b3f3 100644
--- a/apps/vectorcraft-web/Cargo.toml
+++ b/apps/vectorcraft-web/Cargo.toml
@@ -17,7 +17,7 @@ path = "src/main.rs"
vectorcraft-engine = { workspace = true, features = ["bundled-fonts", "heif"] }
vectorcraft-ui-egui = { workspace = true }
# The page command API (storytold/craft-libs#413): the request plumbing behind window.vectorcraft.
-craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "64b181977a0488e4d1e167bc5cc8cfededc2ed4b", version = "0.1.0" }
+craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "50b0ee7bf811e363b5f238382b5c77318cf33e46", version = "0.1.0" }
vectorcraft-format = { workspace = true }
vectorcraft-text = { workspace = true }
egui = { workspace = true }
diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs
index 927b2899ae..29cb56bdfa 100644
--- a/apps/vectorcraft/src/main.rs
+++ b/apps/vectorcraft/src/main.rs
@@ -554,6 +554,7 @@ fn main() -> std::process::ExitCode {
// File Info's metadata templates live in their own folder next to the preferences.
prefs_dir::attach_metadata_templates_dir(&mut session);
prefs_dir::attach_new_doc_profiles(&mut session);
+ prefs_dir::attach_proof_setups(&mut session);
prefs_dir::attach_script_data(&mut session);
let mut app = VectorcraftApp::new(session, services(cc.winit_window().cloned(), cc.egui_ctx.clone()));
app.set_startup_update_check(true);
diff --git a/apps/vectorcraft/src/prefs_dir.rs b/apps/vectorcraft/src/prefs_dir.rs
index 5820240362..492e2ea7bf 100644
--- a/apps/vectorcraft/src/prefs_dir.rs
+++ b/apps/vectorcraft/src/prefs_dir.rs
@@ -81,6 +81,14 @@ pub fn attach_new_doc_profiles(session: &mut vectorcraft_engine::Session) {
}
}
+/// Have View › Proof Setup list the proof setups saved in the `Proof Setups` folder, which
+/// `view.proofSetup.save` makes when it saves a setup by name.
+pub fn attach_proof_setups(session: &mut vectorcraft_engine::Session) {
+ if let Some(dir) = store_dir("Proof Setups") {
+ session.attach_proof_setups(dir);
+ }
+}
+
/// Keep each script's `Folder.userData` in the `Script Data` folder, and the file access people
/// allow scripts with Always in `Script Grants.json` beside it. Both are made when a script first
/// needs them.
diff --git a/assets/icons/dc-arc-three-point.svg b/assets/icons/dc-arc-three-point.svg
new file mode 100644
index 0000000000..479a9a5930
--- /dev/null
+++ b/assets/icons/dc-arc-three-point.svg
@@ -0,0 +1 @@
+
diff --git a/crates/cad/src/hpgl/write.rs b/crates/cad/src/hpgl/write.rs
index 06ddc09b93..4e08fb3f5e 100644
--- a/crates/cad/src/hpgl/write.rs
+++ b/crates/cad/src/hpgl/write.rs
@@ -534,47 +534,13 @@ fn plain(by_pen: &[Vec>]) -> Vec {
/// HP-GL/2: `IN;`, the palette, each pen's paths as one `PE`, `PU;SP0;`.
fn encoded(by_pen: &[Vec>], pens: &[[u8; 3]]) -> Vec {
- let mut out = b"IN;".to_vec();
- if !pens.is_empty() {
- // Pens 1 to n on a plotter, and on a raster device (whose pens are 0 to NP − 1) too.
- let np = (pens.len() + 1).next_power_of_two().max(2);
- out.extend(format!("NP{np};").bytes());
- for (i, [r, g, b]) in pens.iter().enumerate() {
- out.extend(format!("PC{},{r},{g},{b};", i + 1).bytes());
- }
- }
- let mut at: Option<(i64, i64)> = None;
- for (i, paths) in by_pen.iter().enumerate().filter(|(_, p)| !p.is_empty()) {
- out.extend(format!("PU;SP{};PE", i + 1).bytes());
- for path in paths {
- for (k, &p) in path.iter().enumerate() {
- if k == 0 {
- out.push(b'<');
- }
- // The first move of the plot is absolute, and so is one longer than the range a
- // device takes for each number; every other is relative.
- match at.map(|a| (p.0 - a.0, p.1 - a.1)).filter(|d| d.0.abs() <= MAX_COORD && d.1.abs() <= MAX_COORD) {
- None => {
- out.push(b'=');
- pe_number(&mut out, p.0);
- pe_number(&mut out, p.1);
- }
- Some((dx, dy)) => {
- pe_number(&mut out, dx);
- pe_number(&mut out, dy);
- }
- }
- at = Some(p);
- }
- }
- out.push(b';');
- }
- out.extend(b"PU;SP0;");
- out
+ let pens: Vec<_> = pens.iter().enumerate().map(|(index, &rgb)| craft_plotter::hpgl::write::Pen { number: index + 1, rgb }).collect();
+ craft_plotter::hpgl::write::write_hpgl2(&pens, by_pen)
}
/// `v` as a base-64 PE number: the sign in the low bit, the low digits from 63 up and the last
/// digit from 191 up.
+#[cfg(test)]
fn pe_number(out: &mut Vec, v: i64) {
let mut n = (v.unsigned_abs() << 1) | u64::from(v < 0);
while n >= 64 {
@@ -973,10 +939,8 @@ impl<'a> Walk<'a> {
end(&mut cur, &mut out, false);
cur.push(p);
}
- PathEl::LineTo(p) => {
- if cur.last() != Some(&p) {
- cur.push(p);
- }
+ PathEl::LineTo(p) if cur.last() != Some(&p) => {
+ cur.push(p);
}
PathEl::ClosePath => {
let s = cur.first().copied();
diff --git a/crates/cad/src/hpgl/write/tests.rs b/crates/cad/src/hpgl/write/tests.rs
index 493e53906c..f04b331696 100644
--- a/crates/cad/src/hpgl/write/tests.rs
+++ b/crates/cad/src/hpgl/write/tests.rs
@@ -1179,6 +1179,25 @@ fn encoded_numbers_follow_the_reference_guide() {
assert_eq!(out, [194, 191]);
}
+/// The app adapter must preserve raw bytes and position across the one-based pen table.
+#[test]
+fn hpgl2_shared_writer_preserves_raw_bytes_and_pen_indices() {
+ let paths = vec![vec![vec![(32, -32)]], vec![], vec![vec![(33, -31)], vec![(34, -30)]]];
+ let pens = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
+ assert_eq!(encoded(&paths, &pens), b"IN;NP4;PC1,1,2,3;PC2,4,5,6;PC3,7,8,9;PU;SP1;PE<=?\xc0@\xc0;PU;SP3;PE<\xc1\xc1<\xc1\xc1;PU;SP0;");
+}
+
+#[test]
+fn hpgl2_shared_writer_preserves_empty_and_last_admitted_pen() {
+ assert_eq!(encoded(&[], &[]), b"IN;PU;SP0;");
+ let pens = vec![[0, 0, 0]; MAX_PENS];
+ let mut paths = vec![vec![]; MAX_PENS];
+ paths[MAX_PENS - 1] = vec![vec![(0, 0)]];
+ let bytes = encoded(&paths, &pens);
+ assert!(bytes.starts_with(b"IN;NP256;PC1,0,0,0;"));
+ assert!(bytes.ends_with(b"PC255,0,0,0;PU;SP255;PE<=\xbf\xbf;PU;SP0;"));
+}
+
#[test]
fn hpgl2_writes_the_palette_and_encoded_polylines() {
let out = plot(&three(), &HpglOptions { version: Version::Hpgl2, ..opts(&three()) });
diff --git a/crates/cad/src/scene.rs b/crates/cad/src/scene.rs
index 3fc68180d0..700632313e 100644
--- a/crates/cad/src/scene.rs
+++ b/crates/cad/src/scene.rs
@@ -34,6 +34,7 @@ const WIDE_LINES: &str =
"lines wider than 2.11 mm (the widest lineweight) are written at 2.11 mm: Alter Paths for Appearance writes their true width";
const STROKE_EXTRAS: &str = "stroke alignment, width profiles, arrowheads and brushes are left out (Maximize Editability writes strokes as lines)";
const CLIPPING: &str = "clipping masks are not applied: the art they clip is written whole";
+const DISTORTED_IMAGES: &str = "images changed by Perspective Distort or Free Distort are written as the nearest parallelogram";
const TYPE_ITEMS: &str = "fills and strokes added to whole type objects are left out of text entities (outline the text to keep them)";
/// The warning for an image left out because it can't be decoded: the note raster exports give
/// (`vectorcraft-engine`'s `rasterfx::undecoded_warning`).
@@ -671,7 +672,18 @@ impl<'a> Scene<'a> {
self.shape(n, &bp, *rule);
}
NodeKind::Text(t) => self.text(n, t),
- NodeKind::Image(im) => self.image(&self.doc.shown_image(n, im)),
+ NodeKind::Image(im) => match vectorcraft_doc::image_quad::nearest_affine(n) {
+ // DXF clips nothing, so a distorted image is written at the affine placement nearest
+ // its corners, with the warning once it is written.
+ Some(xf) => {
+ if self.image(&ImageObject { xf, ..self.doc.shown_image(n, im).into_owned() }) {
+ self.warn(DISTORTED_IMAGES);
+ }
+ }
+ None => {
+ self.image(&self.doc.shown_image(n, im));
+ }
+ },
NodeKind::SymbolInstance { symbol, xf } => {
let doc = self.doc;
if self.symbol_nodes >= vectorcraft_doc::MAX_SYMBOL_NODES {
@@ -1325,18 +1337,19 @@ impl<'a> Scene<'a> {
name
}
- /// A placed image, linked to its file (written once per image).
- fn image(&mut self, im: &ImageObject) {
+ /// A placed image, linked to its file (written once per image). False when no `IMAGE` entity is
+ /// written.
+ fn image(&mut self, im: &ImageObject) -> bool {
if !self.o.version.handles() {
self.warn(NO_IMAGES);
- return;
+ return false;
}
if !self.o.include_images {
self.note_setting(IMAGES_OFF);
- return;
+ return false;
}
- let Some(i) = self.image_def(im) else { return };
- let Some((dw, dh)) = self.images.get(i).map(|d| (f64::from(d.size.0), f64::from(d.size.1))) else { return };
+ let Some(i) = self.image_def(im) else { return false };
+ let Some((dw, dh)) = self.images.get(i).map(|d| (f64::from(d.size.0), f64::from(d.size.1))) else { return false };
let (w, h) = (f64::from(im.width.max(1)), f64::from(im.height.max(1)));
let map = self.to_dxf * im.xf;
let lin = |v: kurbo::Vec2| (map * v.to_point()) - (map * Point::ZERO);
@@ -1349,7 +1362,7 @@ impl<'a> Scene<'a> {
let at = map * Point::new(0.0, h);
let handle = self.handle();
let reactor = self.handle();
- let Some(def) = self.images.get_mut(i) else { return };
+ let Some(def) = self.images.get_mut(i) else { return false };
def.reactors.push((reactor, handle));
let def = def.handle;
let layer = self.layer.clone();
@@ -1375,6 +1388,7 @@ impl<'a> Scene<'a> {
if self.o.version >= crate::DxfVersion::R2010 {
self.e.int(290, 0);
}
+ true
}
/// The image file for image `im`, encoded once in the chosen format (`None`: left out).
diff --git a/crates/cad/src/tests.rs b/crates/cad/src/tests.rs
index 797223b688..35a1e8c45d 100644
--- a/crates/cad/src/tests.rs
+++ b/crates/cad/src/tests.rs
@@ -984,6 +984,37 @@ fn images_can_be_left_out_with_their_files() {
assert!(r12.warnings.iter().any(|w| w.contains("no images")) && r12.setting_notes.is_empty());
}
+/// DXF does not clip, so an image changed by Perspective Distort is written as one image at the
+/// placement nearest its corners, with a warning; an undistorted image gets no warning.
+#[test]
+fn a_distorted_image_is_written_as_its_nearest_parallelogram_with_a_warning() {
+ let mut d = image_and_fill_doc(Paint::None);
+ let warned = |o: &DxfOutput| o.warnings.iter().any(|w| w.contains("Perspective Distort or Free Distort"));
+ assert!(!warned(&export(&d, &opts(&d)).unwrap()));
+ let id = d.layers[0].children().unwrap()[1].id;
+ let q = [(12.0, 20.0), (28.0, 20.0), (30.0, 30.0), (10.0, 30.0)].map(|(x, y)| Point::new(x, y));
+ d.node_mut(id).unwrap().set_image_corners(q).unwrap();
+ let out = export(&d, &opts(&d)).unwrap();
+ assert!(warned(&out), "{:?}", out.warnings);
+ assert_eq!(kinds(&out).iter().filter(|k| *k == "IMAGE").count(), 1, "{:?}", kinds(&out));
+ // Placed as an undistorted image with the nearest affine placement as its transform would be.
+ let near = vectorcraft_doc::image_quad::nearest_affine(d.node(id).unwrap()).unwrap();
+ let mut plain = d.clone();
+ let n = plain.node_mut(id).unwrap();
+ n.extras_mut().image_quad = None;
+ if let NodeKind::Image(im) = &mut n.kind {
+ im.xf = near;
+ }
+ let placement = |o: &DxfOutput| {
+ let e = entities(o).into_iter().find(|e| kind(e) == "IMAGE").expect("an IMAGE");
+ [10, 20, 11, 21, 12, 22].map(|c| all(&e, c))
+ };
+ assert_eq!(placement(&out), placement(&export(&plain, &opts(&plain)).unwrap()));
+ // With images left out, no IMAGE is written and the distortion warning does not appear.
+ let left_out = export(&d, &DxfOptions { include_images: false, ..opts(&d) }).unwrap();
+ assert!(!warned(&left_out), "{:?}", left_out.warnings);
+}
+
#[test]
fn images_and_hatches_are_left_out_independently_and_the_cnc_preset_leaves_out_both() {
let d = image_and_fill_doc(Paint::solid(Color::rgb(1.0, 0.0, 0.0)));
diff --git a/crates/color/src/cms.rs b/crates/color/src/cms.rs
index a3c35db8ce..a01d174ce7 100644
--- a/crates/color/src/cms.rs
+++ b/crates/color/src/cms.rs
@@ -458,6 +458,15 @@ impl Cms {
CmykSpace::Generic(g) => g.to_srgb(cmyk, absolute, bpc),
CmykSpace::Device => naive_cmyk_to_rgb(cmyk),
CmykSpace::Icc(p) => {
+ // With black-point compensation the profile's black maps onto sRGB black, as
+ // `cmyk_to_srgb` shows the working space.
+ if bpc
+ && !absolute
+ && let Some(srgb) = builtin_rgb_cache(SRGB)
+ && let Some(v) = p.to_rgb_of(&srgb, &cmyk, Intent::RelativeColorimetric, true)
+ {
+ return v;
+ }
let i = if absolute { Intent::AbsoluteColorimetric } else { Intent::RelativeColorimetric };
p.to_srgb(&cmyk, i).unwrap_or_else(|| naive_cmyk_to_rgb(cmyk))
}
@@ -676,32 +685,108 @@ impl Cms {
ProofTarget::Tritanopia => TRITANOPIA.simulate(srgb),
ProofTarget::WorkingCmyk => {
let working = self.working_cms();
- let cmyk = working.srgb_to_cmyk(srgb, proof.intent);
- working.cmyk_to_srgb(cmyk, proof.simulate_paper)
+ let cmyk = if proof.preserve_numbers { self.preserved_cmyk(srgb) } else { working.srgb_to_cmyk(srgb, proof.intent) };
+ self.proof_cmyk_to_srgb(cmyk, proof)
}
ProofTarget::Cmyk(name) => match cmyk_space(name) {
Ok(sp) => {
- let cmyk = Self::srgb_to_cmyk_in(&sp, srgb, proof.intent, self.settings.bpc);
- Self::cmyk_to_srgb_in(&sp, cmyk, proof.simulate_paper, self.settings.bpc)
+ let cmyk = if proof.preserve_numbers {
+ self.preserved_cmyk(srgb)
+ } else {
+ Self::srgb_to_cmyk_in(&sp, srgb, proof.intent, self.settings.bpc)
+ };
+ self.proof_cmyk_to_srgb(cmyk, proof)
+ }
+ Err(_) => srgb,
+ },
+ ProofTarget::Rgb(name) => match rgb_space(canonical_name(name)) {
+ Ok(RgbSpace::Srgb) if !proof.preserve_numbers => srgb,
+ Ok(RgbSpace::Srgb) => self.srgb_to_rgb(srgb).map(|v| v.clamp(0.0, 1.0)),
+ Ok(RgbSpace::Icc(p)) => {
+ // The device's own numbers for the color: the document's RGB numbers unchanged,
+ // or the color converted into the device's space with the proof's intent.
+ let numbers = if proof.preserve_numbers {
+ self.srgb_to_rgb(srgb)
+ } else {
+ p.from_srgb(srgb, proof.intent).and_then(|v| Some([*v.first()?, *v.get(1)?, *v.get(2)?])).unwrap_or(srgb)
+ };
+ p.to_srgb(&numbers, Intent::RelativeColorimetric).unwrap_or(srgb)
}
Err(_) => srgb,
},
}
}
+ /// Display sRGB of color `c` proofed with Preserve Numbers on a CMYK or RGB device: its own
+ /// numbers go to the device unchanged. A CMYK device takes a CMYK color's inks as they are, a
+ /// gray as K only and another color's inks in this context's CMYK space (relative
+ /// colorimetric); an RGB device takes an RGB color's numbers as they are and another color's
+ /// numbers in this context's RGB space. Other targets proof the color's display sRGB
+ /// ([`Self::proof_srgb`]).
+ pub fn proof_color(&self, c: &Color, proof: &ProofSetup) -> [f32; 3] {
+ if !proof.preserve_numbers {
+ return self.proof_srgb(self.display_rgb(c), proof);
+ }
+ match &proof.target {
+ // A device whose profile is not loaded leaves the color as it is, as for a pixel.
+ ProofTarget::Cmyk(name) if cmyk_space(name).is_err() => self.display_rgb(c),
+ ProofTarget::WorkingCmyk | ProofTarget::Cmyk(_) => self.proof_cmyk_to_srgb(self.to_cmyk(c, Intent::RelativeColorimetric), proof),
+ ProofTarget::Rgb(name) => {
+ // A CMYK color converts straight into the RGB space, so a wide space keeps it.
+ let numbers = match self.convert(c, Model::Rgb, Intent::RelativeColorimetric) {
+ Color::Rgb { r, g, b } => [r, g, b],
+ other => self.srgb_to_rgb(self.display_rgb(&other)),
+ }
+ .map(|v| v.clamp(0.0, 1.0));
+ match rgb_space(canonical_name(name)) {
+ Ok(RgbSpace::Srgb) => numbers,
+ Ok(RgbSpace::Icc(p)) => p.to_srgb(&numbers, Intent::RelativeColorimetric).unwrap_or(numbers),
+ Err(_) => self.display_rgb(c),
+ }
+ }
+ _ => self.proof_srgb(self.display_rgb(c), proof),
+ }
+ }
+
+ /// The CMYK numbers display sRGB `srgb` has in this context's CMYK space (relative
+ /// colorimetric), which Preserve CMYK Numbers sends to the simulated device unchanged: for
+ /// pixels whose own numbers are not known (an RGB image's pixels, art drawn over other art).
+ /// A color whose numbers are known proofs through [`Self::proof_color`].
+ fn preserved_cmyk(&self, srgb: [f32; 3]) -> [f32; 4] {
+ self.srgb_to_cmyk(srgb, Intent::RelativeColorimetric)
+ }
+
/// Display sRGB of CMYK inks in the proof's CMYK space (this context's CMYK space for RGB
- /// targets).
+ /// targets). Simulate Paper Color shows the paper's color and the press black (absolute
+ /// colorimetric); else Simulate Black Ink shows the press black as the dark gray it prints
+ /// (media-relative, without black-point compensation).
pub fn proof_cmyk_to_srgb(&self, cmyk: [f32; 4], proof: &ProofSetup) -> [f32; 3] {
+ let black = proof.simulate_black && !proof.simulate_paper;
match &proof.target {
ProofTarget::Cmyk(name) => match cmyk_space(name) {
+ Ok(sp) if black => Self::black_ink_srgb(&sp, cmyk),
Ok(sp) => Self::cmyk_to_srgb_in(&sp, cmyk, proof.simulate_paper, self.settings.bpc),
Err(_) => self.cmyk_to_srgb(cmyk, proof.simulate_paper),
},
+ ProofTarget::WorkingCmyk if black => Self::black_ink_srgb(&self.working_cms().cmyk, cmyk),
ProofTarget::WorkingCmyk => self.working_cms().cmyk_to_srgb(cmyk, proof.simulate_paper),
_ => self.cmyk_to_srgb(cmyk, proof.simulate_paper),
}
}
+ /// Display sRGB of `cmyk` in `space`, media-relative and without black-point compensation, so
+ /// the darkest ink the space prints shows as the gray it is rather than as black.
+ fn black_ink_srgb(space: &CmykSpace, cmyk: [f32; 4]) -> [f32; 3] {
+ let cmyk = cmyk.map(|v| v.clamp(0.0, 1.0));
+ if let CmykSpace::Icc(p) = space
+ && let Some(srgb) = builtin_rgb_cache(SRGB)
+ && let Some(v) = p.to_rgb_of(&srgb, &cmyk, Intent::RelativeColorimetric, false)
+ {
+ return v;
+ }
+ Self::cmyk_to_srgb_in(space, cmyk, false, false)
+ }
+
/// The context of the working settings: the one [`use_document_profiles`] put a document's
/// profiles in place of, else this one.
fn working_cms(&self) -> &Cms {
@@ -711,7 +796,10 @@ impl Cms {
/// A cached 3-D lookup table implementing [`Cms::proof_srgb`] for 8-bit pixels.
pub fn proof_lut(&self, proof: &ProofSetup) -> Arc {
let working = self.working.as_ref().map(|w| &w.settings);
- let key = format!("{:?}|{working:?}|{:?}|{:?}|{}", self.settings, proof.target, proof.intent, proof.simulate_paper);
+ let key = format!(
+ "{:?}|{working:?}|{:?}|{:?}|{}|{}|{}",
+ self.settings, proof.target, proof.intent, proof.simulate_paper, proof.preserve_numbers, proof.simulate_black
+ );
let mut cache = PROOF_CACHE.lock().unwrap_or_else(|e| e.into_inner());
if let Some((_, l)) = cache.iter().find(|(k, _)| *k == key) {
return l.clone();
@@ -860,6 +948,8 @@ pub enum ProofTarget {
WorkingCmyk,
/// A specific CMYK profile (Customize…).
Cmyk(String),
+ /// A specific RGB profile (Customize…): the color as that RGB device shows it.
+ Rgb(String),
/// Legacy Macintosh RGB (Gamma 1.8).
LegacyMacRgb,
/// Internet Standard RGB (sRGB).
@@ -879,6 +969,9 @@ impl ProofTarget {
if let Some(p) = s.strip_prefix("cmyk:") {
return Some(ProofTarget::Cmyk(p.to_string()));
}
+ if let Some(p) = s.strip_prefix("rgb:") {
+ return Some(ProofTarget::Rgb(p.to_string()));
+ }
Some(match s {
"workingCmyk" | "cmyk" => ProofTarget::WorkingCmyk,
"legacyMacRgb" | "macRgb" => ProofTarget::LegacyMacRgb,
@@ -894,6 +987,7 @@ impl ProofTarget {
match self {
ProofTarget::WorkingCmyk => "workingCmyk".into(),
ProofTarget::Cmyk(p) => format!("cmyk:{p}"),
+ ProofTarget::Rgb(p) => format!("rgb:{p}"),
ProofTarget::LegacyMacRgb => "legacyMacRgb".into(),
ProofTarget::Srgb => "srgb".into(),
ProofTarget::MonitorRgb => "monitorRgb".into(),
@@ -917,6 +1011,15 @@ pub struct ProofSetup {
/// Simulate Paper Color (absolute colorimetric display of the press).
#[serde(default)]
pub simulate_paper: bool,
+ /// Preserve CMYK Numbers (a CMYK device) or Preserve RGB Numbers (an RGB device): the colors'
+ /// numbers go to the device unchanged instead of being converted into its space with
+ /// `intent`.
+ #[serde(default)]
+ pub preserve_numbers: bool,
+ /// Simulate Black Ink: the press black shows as the dark gray it prints (a CMYK device; implied
+ /// by `simulate_paper`).
+ #[serde(default)]
+ pub simulate_black: bool,
/// Separations Preview: names of the visible plates ("Cyan", "Magenta", "Yellow", "Black",
/// spot swatch names). `None` = normal composite proof.
#[serde(default, skip_serializing_if = "Option::is_none")]
diff --git a/crates/color/src/cms/tests.rs b/crates/color/src/cms/tests.rs
index 836ff9fdb6..853dfb4637 100644
--- a/crates/color/src/cms/tests.rs
+++ b/crates/color/src/cms/tests.rs
@@ -194,6 +194,100 @@ fn colour_blindness_proofs() {
assert_eq!(ProofTarget::parse(&ProofTarget::Cmyk("X".into()).id()), Some(ProofTarget::Cmyk("X".into())));
}
+/// Proof Setup › Customize: Simulate Black Ink shows the press black of a CMYK device as the dark
+/// gray it prints, where the proof otherwise shows it as black; Simulate Paper Color shows it so
+/// as well, on the paper's color.
+#[test]
+fn simulate_black_ink_shows_the_press_black_as_gray() {
+ let c = cms();
+ let device = ProofSetup { target: ProofTarget::Cmyk(GENERIC_CMYK.into()), ..Default::default() };
+ let black = ProofSetup { simulate_black: true, ..device.clone() };
+ let paper = ProofSetup { simulate_paper: true, ..device.clone() };
+ let plain = c.proof_srgb([0.0; 3], &device);
+ let gray = c.proof_srgb([0.0; 3], &black);
+ assert!(plain.iter().all(|v| *v < 0.02), "black stays black: {plain:?}");
+ assert!(gray.iter().all(|v| *v > 0.05), "the press black shows as a gray: {gray:?}");
+ assert_eq!(c.proof_srgb([1.0; 3], &black), [1.0; 3], "the paper stays white");
+ assert!(c.proof_srgb([0.0; 3], &paper).iter().all(|v| *v > 0.05));
+ // The working CMYK target, and the inks Separations Preview shows, follow it too.
+ let working = ProofSetup { target: ProofTarget::WorkingCmyk, simulate_black: true, ..Default::default() };
+ assert_eq!(c.proof_srgb([0.0; 3], &working), gray);
+ assert!(c.proof_cmyk_to_srgb([0.0, 0.0, 0.0, 1.0], &black)[0] > c.proof_cmyk_to_srgb([0.0, 0.0, 0.0, 1.0], &device)[0] + 0.05);
+ // The table the canvas draws through is made for each setting.
+ assert!(de(c.proof_lut(&black).apply([0.0; 3]), gray) < 2.5);
+ assert!(de(c.proof_lut(&device).apply([0.0; 3]), plain) < 2.5);
+}
+
+/// Preserve CMYK Numbers sends the color's CMYK numbers in the document's space to the simulated
+/// device unchanged: with Device CMYK as the working space, K50 shows as the simulated press
+/// prints K50 (darker, with its dot gain). Without it the color is converted into the device's
+/// space with the intent, and the gray looks as it does on screen.
+#[test]
+fn preserve_cmyk_numbers_sends_the_numbers_unchanged() {
+ let dev = Cms::new(&ColorSettings { cmyk: DEVICE_CMYK.into(), ..Default::default() }).unwrap();
+ let press = Cms::new(&ColorSettings::default()).unwrap();
+ let k50 = [0.0, 0.0, 0.0, 0.5];
+ let gray = dev.cmyk_to_srgb(k50, false);
+ let device = ProofSetup { target: ProofTarget::Cmyk(GENERIC_CMYK.into()), ..Default::default() };
+ let preserved = dev.proof_srgb(gray, &ProofSetup { preserve_numbers: true, ..device.clone() });
+ let want = press.cmyk_to_srgb(k50, false);
+ assert!(de(preserved, want) < 0.5, "{preserved:?} vs {want:?}");
+ let converted = dev.proof_srgb(gray, &device);
+ assert!(de(converted, gray) < 1.5, "{converted:?} vs {gray:?}");
+ assert!(de(converted, preserved) > 3.0, "{converted:?} vs {preserved:?}");
+ // With the numbers preserved the intent is not used.
+ let perceptual = ProofSetup { intent: Intent::Perceptual, preserve_numbers: true, ..device };
+ assert_eq!(dev.proof_srgb(gray, &perceptual), preserved);
+}
+
+/// An RGB profile as the device to simulate: with Preserve RGB Numbers the document's RGB numbers
+/// show as that device shows them (sRGB numbers on a Display P3 device look more saturated);
+/// without it a color the device can show looks the same, and one it can't show is clipped.
+#[test]
+fn rgb_device_proofs_show_the_device_numbers() {
+ let c = cms();
+ let p3 = ProofSetup { target: ProofTarget::Rgb(DISPLAY_P3.into()), ..Default::default() };
+ assert_eq!(ProofTarget::parse(&p3.target.id()), Some(p3.target.clone()));
+ assert_eq!(p3.target.id(), format!("rgb:{DISPLAY_P3}"));
+ assert!(!p3.target.is_cmyk());
+ let red = [0.7, 0.3, 0.25];
+ let converted = c.proof_srgb(red, &p3);
+ assert!(de(converted, red) < 1.0, "{converted:?}");
+ let preserved = c.proof_srgb(red, &ProofSetup { preserve_numbers: true, ..p3.clone() });
+ assert!(preserved[0] > red[0] + 0.02 && preserved[1] < red[1] - 0.02, "{preserved:?}");
+ // An RGB color's own numbers give the same proof.
+ let own = c.proof_color(&Color::rgb(red[0], red[1], red[2]), &ProofSetup { preserve_numbers: true, ..p3.clone() });
+ assert!(de(own, preserved) < 0.01, "{own:?} vs {preserved:?}");
+ // sRGB numbers on an sRGB device: as they are either way.
+ let srgb = ProofSetup { target: ProofTarget::Rgb(SRGB.into()), preserve_numbers: true, ..Default::default() };
+ assert!(de(c.proof_srgb(red, &srgb), red) < 0.01);
+ // A wider working space's numbers on an sRGB device: its green clips to sRGB green.
+ let wide = Cms::new(&ColorSettings { rgb: WIDE_GAMUT_RGB.into(), ..Default::default() }).unwrap();
+ let green = wide.rgb_to_srgb([0.2, 0.8, 0.2]);
+ let shown = wide.proof_srgb(green, &srgb);
+ assert!(de(shown, green) > 3.0, "the wide space's numbers show as sRGB numbers: {shown:?}");
+ // A profile that is gone leaves the colors as they are.
+ let gone = ProofSetup { target: ProofTarget::Rgb("Nope".into()), ..Default::default() };
+ assert_eq!(c.proof_srgb(red, &gone), red);
+}
+
+/// A CMYK device whose profile is not loaded leaves a color as the screen shows it, with Preserve
+/// CMYK Numbers on as well as off, the same as for a pixel of that color.
+#[test]
+fn missing_cmyk_device_leaves_colors_as_they_are() {
+ let c = cms();
+ let gone = ProofSetup { target: ProofTarget::Cmyk("Nope".into()), preserve_numbers: true, ..Default::default() };
+ let blue = Color::rgb(0.0, 0.0, 1.0);
+ let shown = c.display_rgb(&blue);
+ assert_eq!(c.proof_color(&blue, &gone), shown);
+ assert_eq!(c.proof_srgb(shown, &gone), shown);
+ let off = ProofSetup { preserve_numbers: false, ..gone.clone() };
+ assert_eq!(c.proof_color(&blue, &off), shown);
+ // A CMYK color keeps its inks' display color.
+ let ink = Color::Cmyk { c: 0.2, m: 0.7, y: 0.1, k: 0.05 };
+ assert!(de(c.proof_color(&ink, &gone), c.display_rgb(&ink)) < 0.01);
+}
+
/// The expected colors were computed separately with NumPy from the same published inputs (linear
/// sRGB to XYZ from IEC 61966-2-1, Smith & Pokorny's XYZ to LMS, Judd-Vos XYZ at 485 nm and 660 nm),
/// following Brettel, Viénot & Mollon (1997) with the display's white as the neutral axis.
diff --git a/crates/color/src/cms/tests_icc.rs b/crates/color/src/cms/tests_icc.rs
index 2c1d96638b..3506bcb856 100644
--- a/crates/color/src/cms/tests_icc.rs
+++ b/crates/color/src/cms/tests_icc.rs
@@ -187,6 +187,25 @@ fn black_point_compensation_maps_the_darkest_ink_to_rgb_black() {
assert_eq!(abs(true), abs(false));
}
+/// A loaded ICC CMYK profile as Proof Setup's device shows its darkest ink with the settings'
+/// black-point compensation, as the working CMYK proof of the same profile does, and Simulate
+/// Black Ink shows it as the lighter gray the press prints.
+#[test]
+fn simulate_black_ink_shows_a_loaded_cmyk_profiles_black_as_gray() {
+ let c = icc_cmyk(true);
+ let k100 = [0.0, 0.0, 0.0, 1.0];
+ let device = ProofSetup { target: ProofTarget::Cmyk(c.settings().cmyk.clone()), ..Default::default() };
+ let plain = c.proof_cmyk_to_srgb(k100, &device);
+ let working = c.proof_cmyk_to_srgb(k100, &ProofSetup { target: ProofTarget::WorkingCmyk, ..Default::default() });
+ assert!(plain.iter().zip(working).all(|(a, b)| (a - b).abs() < 0.01), "device {plain:?}, working {working:?}");
+ let black = c.proof_cmyk_to_srgb(k100, &ProofSetup { simulate_black: true, ..device.clone() });
+ assert!(plain.iter().zip(black).all(|(a, b)| b > a + 0.03), "black ink {black:?}, without {plain:?}");
+ // Without black-point compensation the device shows the darkest ink as the press prints it.
+ let off = icc_cmyk(false);
+ let plain_off = off.proof_cmyk_to_srgb(k100, &ProofSetup { target: ProofTarget::Cmyk(off.settings().cmyk.clone()), ..Default::default() });
+ assert!(plain_off.iter().zip(black).all(|(a, b)| (a - b).abs() < 0.02), "without compensation {plain_off:?}, black ink {black:?}");
+}
+
/// #1584: every built-in profile (RGB, CMYK and gray) has each tag on a 4-byte boundary and a size
/// that is a multiple of 4 (ICC.1 §7.1.2), and still reads back as the same space.
#[test]
diff --git a/crates/color/src/gradient.rs b/crates/color/src/gradient.rs
index 05b7f4839c..b88253b714 100644
--- a/crates/color/src/gradient.rs
+++ b/crates/color/src/gradient.rs
@@ -621,7 +621,8 @@ impl Gradient {
}
/// Stops expanded so that midpoints are represented as explicit stops (for renderers without
/// midpoints), and a Perceptual gradient's segments as stops on its curve (for renderers that
- /// mix linearly; within [`PERCEPTUAL_TOLERANCE`] of it).
+ /// mix linearly; within [`PERCEPTUAL_TOLERANCE`] of it). A stop between two stops of the same
+ /// color is that color, as it is, so paper white or a tint stays exact.
pub fn expanded_stops(&self) -> Vec<(f32, Color, f32)> {
self.expanded().map(|(t, c, o, _)| (t, c, o)).collect()
}
@@ -638,6 +639,9 @@ impl Gradient {
// Otherwise (repeated or unsorted offsets) each midpoint is looked up as `sample` would
// find it, but by binary search: a scan of all the stops per midpoint cost their square.
let reach = if increasing || !self.method.is_classic() { None } else { Some(StopReach::new(&self.stops)) };
+ // Two stops of the same color mix to that color, as it is: a mix through display RGB or
+ // OKLab would change its model or round its numbers.
+ let mix = move |a: &Color, b: &Color, v| if a == b { *a } else { self.method.mix(a, b, v) };
self.stops.iter().enumerate().flat_map(move |(i, s)| {
let next = self.stops.get(i + 1);
let off_centre = (s.midpoint - 0.5).abs() > 1e-3;
@@ -646,7 +650,6 @@ impl Gradient {
let t = s.offset + (n.offset - s.offset) * s.midpoint;
// Mixed from the two stops it lies between, as `sample` would: searching all the
// stops again for each midpoint made many stops cost their square.
- let mix = |a: &Color, b: &Color, v| self.method.mix(a, b, v);
let (c, o) = match &reach {
Some(reach) => reach.sample_with(&self.stops, t, &mix),
None => between(s, n, t, &mix),
@@ -661,7 +664,7 @@ impl Gradient {
let mid = v == 0.5;
let t = curve_offset(s, n, v);
let o = s.opacity + (n.opacity - s.opacity) * v;
- (t, self.method.mix(&s.color, &n.color, v), o, (mid && off_centre).then_some(s.midpoint), None)
+ (t, mix(&s.color, &n.color, v), o, (mid && off_centre).then_some(s.midpoint), None)
})
});
std::iter::once((s.offset, s.color, s.opacity, None, Some(i))).chain(classic).chain(perceptual.into_iter().flatten())
diff --git a/crates/color/src/lib.rs b/crates/color/src/lib.rs
index fa8cd564f2..c3d74615ae 100644
--- a/crates/color/src/lib.rs
+++ b/crates/color/src/lib.rs
@@ -10,6 +10,7 @@ pub mod freeform;
pub mod gradient;
pub mod harmony;
pub mod libraries;
+pub mod oklab;
pub mod palette_io;
pub mod recolor;
pub mod swatch;
@@ -340,6 +341,49 @@ pub fn hsb_to_rgb([h, s, v]: [f32; 3]) -> [f32; 3] {
[r + m, g + m, b + m]
}
+/// HSL (hue in degrees 0..360, saturation and lightness 0..1) of RGB numbers 0..1, with no color
+/// conversion, as CSS Color 4 converts sRGB to HSL
+/// (). The hue is 0 while the saturation is
+/// powerless, and a color outside 0..1 that gives a negative saturation turns its hue by 180°. As in
+/// the specification's conversion, a lightness of 0.00001 or less, a lightness less than 0.00001
+/// below 1, or a saturation of 0.00001 or less reads as a gray.
+pub fn rgb_to_hsl([r, g, b]: [f32; 3]) -> [f32; 3] {
+ const EPSILON: f32 = 1e-5;
+ let max = r.max(g).max(b);
+ let min = r.min(g).min(b);
+ let d = max - min;
+ let l = (max + min) / 2.0;
+ if d <= 0.0 {
+ return [0.0, 0.0, l];
+ }
+ let mut s = if l.abs() <= EPSILON || (1.0 - l).abs() < EPSILON { 0.0 } else { (max - l) / l.min(1.0 - l) };
+ let mut h = rgb_to_hsb([r, g, b])[0];
+ if s < 0.0 {
+ h += 180.0;
+ s = -s;
+ }
+ if s <= EPSILON {
+ return [0.0, 0.0, l];
+ }
+ let h = h.rem_euclid(360.0);
+ [if h >= 360.0 { 0.0 } else { h }, s, l]
+}
+
+/// RGB numbers 0..1 of HSL `[h, s, l]` (hue in degrees, saturation and lightness 0..1), as CSS
+/// Color 4 converts HSL to sRGB (): the inverse of
+/// [`rgb_to_hsl`]. A hue outside 0..360 wraps into that range before the conversion, so -120°
+/// gives the color of 240° and a hue of 10,000,000,000° the color of 280°. The specification's
+/// sample code uses JavaScript's remainder operator and gives a different color for a negative hue.
+pub fn hsl_to_rgb([h, s, l]: [f32; 3]) -> [f32; 3] {
+ let h = h.rem_euclid(360.0);
+ let a = s * l.min(1.0 - l);
+ let f = |n: f32| {
+ let k = (n + h / 30.0).rem_euclid(12.0);
+ l - a * (k - 3.0).min(9.0 - k).clamp(-1.0, 1.0)
+ };
+ [f(0.0), f(8.0), f(4.0)]
+}
+
/// `new` expressed in the colour model of `orig` ([`Color::in_model`]): results of colour operations
/// (harmonies, blends, inversions, recolouring) keep the model of the colour they came from.
pub fn keep_model(orig: Color, new: Color) -> Color {
@@ -499,6 +543,59 @@ mod tests {
}
}
+ /// The HSL examples of CSS Color 4, section 7 (),
+ /// the first six rows, and two hues outside 0..360 that wrap into that range.
+ #[test]
+ fn hsl_follows_css_color_4() {
+ for (hsl, hex) in [
+ ([0.0, 1.0, 0.5], "#ff0000"),
+ ([120.0, 1.0, 0.5], "#00ff00"),
+ ([120.0, 1.0, 0.25], "#008000"),
+ ([120.0, 1.0, 0.75], "#80ff80"),
+ ([240.0, 1.0, 0.5], "#0000ff"),
+ ([60.0, 1.0, 0.5], "#ffff00"),
+ ([360.0, 1.0, 0.5], "#ff0000"),
+ ([-120.0, 1.0, 0.5], "#0000ff"),
+ ] {
+ let [r, g, b] = hsl_to_rgb(hsl);
+ assert_eq!(Color::rgb(r, g, b).to_hex(), hex, "{hsl:?}");
+ }
+ let [h, s, l] = rgb_to_hsl([1.0, 0.5, 0.0]);
+ assert!((h - 30.0).abs() < 1e-4 && (s - 1.0).abs() < 1e-6 && (l - 0.5).abs() < 1e-6, "{h} {s} {l}");
+ let [h, s, l] = rgb_to_hsl(Color::rgb8(255, 128, 0).to_rgb_uncalibrated());
+ assert!((h - 30.0).abs() < 0.2 && (s - 1.0).abs() < 1e-6 && (l - 0.5).abs() < 1e-3, "{h} {s} {l}");
+ // A gray has no hue: the hue is 0 and the saturation 0, at any lightness.
+ for v in [0.0, 0.25, 0.5, 1.0] {
+ assert_eq!(rgb_to_hsl([v, v, v]), [0.0, 0.0, v]);
+ }
+ // Black and white keep any hue and saturation they are given.
+ assert_eq!(hsl_to_rgb([200.0, 0.7, 0.0]), [0.0, 0.0, 0.0]);
+ assert_eq!(hsl_to_rgb([200.0, 0.7, 1.0]), [1.0, 1.0, 1.0]);
+ // A color past the gamut that gives a negative saturation turns its hue by 180°.
+ let [h, s, _] = rgb_to_hsl([1.2, 1.5, 1.4]);
+ assert!(s > 0.0 && (h - (160.0 + 180.0)).abs() < 1e-3, "{h} {s}");
+ // A huge hue wraps before the channels are worked out: 10,000,000,000° is 280°.
+ let (huge, wrapped) = (hsl_to_rgb([10_000_000_000.0, 1.0, 0.5]), hsl_to_rgb([280.0, 1.0, 0.5]));
+ assert!((0..3).all(|i| (huge[i] - wrapped[i]).abs() < 1e-6), "{huge:?} {wrapped:?}");
+ }
+
+ /// The 216 web colors go to HSL and back to the same 8-bit color.
+ #[test]
+ fn hsl_roundtrip() {
+ let steps = [0x00, 0x33, 0x66, 0x99, 0xcc, 0xff];
+ for r in steps {
+ for g in steps {
+ for b in steps {
+ let c = Color::rgb8(r, g, b);
+ let [h, s, l] = rgb_to_hsl(c.to_rgb_uncalibrated());
+ assert!((0.0..360.0).contains(&h) && (0.0..=1.0).contains(&s) && (0.0..=1.0).contains(&l), "{}", c.to_hex());
+ let back = hsl_to_rgb([h, s, l]).map(|v| (v * 255.0).round() as u8);
+ assert_eq!(back, [r, g, b], "{}", c.to_hex());
+ }
+ }
+ }
+ }
+
#[test]
fn cmyk_conversions() {
assert_eq!(Color::cmyk(0.0, 0.0, 0.0, 1.0).to_rgb_uncalibrated(), [0.0, 0.0, 0.0]);
diff --git a/crates/color/src/libraries.rs b/crates/color/src/libraries.rs
index 5fc952a061..c2946d92a2 100644
--- a/crates/color/src/libraries.rs
+++ b/crates/color/src/libraries.rs
@@ -99,18 +99,24 @@ pub fn builtin_library(id: &str) -> Option> {
// ---------- colour construction ----------
-/// sRGB (0..=1, gamma encoded) of OKLab `(l, a, b)`, unclamped.
+/// sRGB (0..=1, gamma encoded) of OKLab `(l, a, b)`, unclamped. A linear channel below
+/// −0.0031308 is encoded with the curve's sign turned, as CSS Color 4's extended sRGB does
+/// ().
pub(crate) fn oklab_to_srgb(l: f64, a: f64, b: f64) -> [f64; 3] {
+ oklab_to_linear_srgb(l, a, b).map(|v| if v.abs() <= 0.003_130_8 { 12.92 * v } else { v.signum() * (1.055 * v.abs().powf(1.0 / 2.4) - 0.055) })
+}
+
+/// Linear sRGB of OKLab `(l, a, b)`, unclamped.
+pub(crate) fn oklab_to_linear_srgb(l: f64, a: f64, b: f64) -> [f64; 3] {
let l_ = l + 0.396_337_777_4 * a + 0.215_803_757_3 * b;
let m_ = l - 0.105_561_345_8 * a - 0.063_854_172_8 * b;
let s_ = l - 0.089_484_177_5 * a - 1.291_485_548_0 * b;
let (l3, m3, s3) = (l_ * l_ * l_, m_ * m_ * m_, s_ * s_ * s_);
- let lin = [
+ [
4.076_741_662_1 * l3 - 3.307_711_591_3 * m3 + 0.230_969_929_2 * s3,
-1.268_438_004_6 * l3 + 2.609_757_401_1 * m3 - 0.341_319_396_5 * s3,
-0.004_196_086_3 * l3 - 0.703_418_614_7 * m3 + 1.707_614_701_0 * s3,
- ];
- lin.map(|v| if v <= 0.003_130_8 { 12.92 * v } else { 1.055 * v.powf(1.0 / 2.4) - 0.055 })
+ ]
}
/// OKLab `[l, a, b]` of a colour's display RGB.
@@ -118,11 +124,13 @@ pub fn to_oklab(c: &Color) -> [f64; 3] {
srgb_to_oklab(c.to_rgb_uncalibrated())
}
-/// OKLab `[l, a, b]` of sRGB `rgb` (0..=1, gamma encoded).
+/// OKLab `[l, a, b]` of sRGB `rgb` (0..=1, gamma encoded). A channel below −0.04045 is decoded
+/// with the curve's sign turned, as CSS Color 4's extended sRGB does
+/// ().
pub(crate) fn srgb_to_oklab(rgb: [f32; 3]) -> [f64; 3] {
let [r, g, b] = rgb.map(|v| {
let v = f64::from(v);
- if v <= 0.040_45 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) }
+ if v.abs() <= 0.040_45 { v / 12.92 } else { v.signum() * ((v.abs() + 0.055) / 1.055).powf(2.4) }
});
let l = (0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b).cbrt();
let m = (0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b).cbrt();
diff --git a/crates/color/src/oklab.rs b/crates/color/src/oklab.rs
new file mode 100644
index 0000000000..31500d1ac5
--- /dev/null
+++ b/crates/color/src/oklab.rs
@@ -0,0 +1,266 @@
+//! OKLCH, the polar form of Oklab, as CSS Color 4 defines it
+//! (): lightness L from 0 to 1, chroma
+//! C (CSS reads 100% as 0.4) and hue H in degrees from the positive `a` axis. The conversions take
+//! and give gamma-encoded sRGB through the Oklab matrices of [`crate::libraries`].
+
+use crate::libraries::{oklab_to_linear_srgb, oklab_to_srgb, srgb_to_oklab};
+
+/// The chroma CSS reads as 100%.
+pub const CHROMA_FULL: f64 = 0.4;
+
+/// Chroma at or below which the hue is powerless (CSS Color 4's ε); [`to_oklch`] gives hue 0 there.
+pub const POWERLESS_CHROMA: f64 = 0.000_004;
+
+/// How far outside 0..=1 an sRGB component may be and still count as inside the gamut.
+const GAMUT_SLACK: f64 = 1e-4;
+
+/// OKLCH `[l, c, h°]` of sRGB `rgb` (gamma encoded). Values outside 0..=1 are converted as they
+/// are. The hue is in 0..360, and 0 while the chroma is powerless.
+pub fn to_oklch(rgb: [f32; 3]) -> [f64; 3] {
+ let [l, a, b] = srgb_to_oklab(rgb);
+ let c = a.hypot(b);
+ if c <= POWERLESS_CHROMA {
+ return [l, 0.0, 0.0];
+ }
+ [l, c, b.atan2(a).to_degrees().rem_euclid(360.0)]
+}
+
+/// sRGB (gamma encoded) of OKLCH `(l, c, h°)`, unclamped.
+pub fn oklch_to_srgb(l: f64, c: f64, h: f64) -> [f64; 3] {
+ let (sin, cos) = h.to_radians().sin_cos();
+ oklab_to_srgb(l, c * cos, c * sin)
+}
+
+/// Whether sRGB `rgb` lies inside the sRGB gamut.
+pub fn in_srgb(rgb: [f64; 3]) -> bool {
+ rgb.iter().all(|v| (-GAMUT_SLACK..=1.0 + GAMUT_SLACK).contains(v))
+}
+
+/// The largest chroma sRGB holds at lightness `l` and hue `h°`: 0 at or outside black and white.
+pub fn max_chroma(l: f64, h: f64) -> f64 {
+ largest_fitting_chroma(l, h, f64::INFINITY)
+}
+
+/// The largest chroma no more than `limit` that sRGB holds at lightness `l` and hue `h°`: 0 at or
+/// outside black and white.
+///
+/// The chromas sRGB holds along the ray can come in several stretches: at the lightness and hue of
+/// blue the ray leaves sRGB at a chroma of about 0.266 and comes back at blue itself, about 0.313,
+/// and near black the gamut slack opens stretches of its own. Each linear sRGB channel is a cubic
+/// in the chroma, so every stretch ends where a channel's cubic meets a bound of the gamut. The
+/// search finds each such chroma between the cubic's turning points and takes the largest one that
+/// fits.
+fn largest_fitting_chroma(l: f64, h: f64, limit: f64) -> f64 {
+ if !(l > 0.0 && l < 1.0) || !h.is_finite() {
+ return 0.0;
+ }
+ let top = limit.min(0.5);
+ if top <= 0.0 {
+ return 0.0;
+ }
+ let fits = |c: f64| in_srgb(oklch_to_srgb(l, c, h));
+ if fits(top) {
+ return top;
+ }
+ let (sin, cos) = h.to_radians().sin_cos();
+ let lin = |c: f64| oklab_to_linear_srgb(l, c * cos, c * sin);
+ // The linear channels at chromas 0, s, 2s and 3s give each cubic's coefficients in t = c / s.
+ let s = top / 3.0;
+ let y = [lin(0.0), lin(s), lin(2.0 * s), lin(3.0 * s)];
+ let bounds = [-GAMUT_SLACK / 12.92, ((1.0 + GAMUT_SLACK + 0.055) / 1.055).powf(2.4)];
+ let mut ends = vec![0.0];
+ for ch in 0..3 {
+ let [y0, y1, y2, y3] = [y[0][ch], y[1][ch], y[2][ch], y[3][ch]];
+ let (d1, d2, d3) = (y1 - y0, y2 - 2.0 * y1 + y0, y3 - 3.0 * y2 + 3.0 * y1 - y0);
+ let k = [y0, d1 - d2 / 2.0 + d3 / 3.0, d2 / 2.0 - d3 / 2.0, d3 / 6.0];
+ let p = |t: f64| ((k[3] * t + k[2]) * t + k[1]) * t + k[0];
+ // The cubic rises or falls on each stretch between its turning points.
+ let mut cuts = vec![0.0, 3.0];
+ cuts.extend(turning_points(3.0 * k[3], 2.0 * k[2], k[1]).into_iter().filter(|t| *t > 0.0 && *t < 3.0));
+ cuts.sort_by(f64::total_cmp);
+ ends.extend(cuts.iter().map(|t| t * s));
+ for w in cuts.windows(2) {
+ for bound in bounds {
+ let (mut a, mut b) = (w[0], w[1]);
+ let fa = p(a) - bound;
+ if fa * (p(b) - bound) > 0.0 {
+ continue;
+ }
+ for _ in 0..60 {
+ let mid = (a + b) / 2.0;
+ if (p(mid) - bound) * fa > 0.0 { a = mid } else { b = mid }
+ }
+ ends.extend([a * s, b * s]);
+ }
+ }
+ }
+ ends.sort_by(|a, b| b.total_cmp(a));
+ ends.into_iter().flat_map(|c| [c, c - 1e-9]).find(|c| (0.0..=top).contains(c) && fits(*c)).unwrap_or(0.0)
+}
+
+/// The real roots of `a t² + b t + c`.
+fn turning_points(a: f64, b: f64, c: f64) -> Vec {
+ if a.abs() < 1e-15 {
+ return if b.abs() < 1e-15 { Vec::new() } else { vec![-c / b] };
+ }
+ let disc = b * b - 4.0 * a * c;
+ if disc < 0.0 {
+ return Vec::new();
+ }
+ let r = disc.sqrt();
+ vec![(-b - r) / (2.0 * a), (-b + r) / (2.0 * a)]
+}
+
+/// The sRGB color (gamma encoded, 0..=1) of OKLCH `(l, c, h°)`, and whether its chroma was lowered:
+/// a color outside sRGB keeps its lightness and hue and takes the largest chroma below it that
+/// fits. Lightness is clamped to 0..=1 and chroma to 0 or more.
+pub fn from_oklch(l: f64, c: f64, h: f64) -> ([f32; 3], bool) {
+ let l = if l.is_nan() { 0.0 } else { l.clamp(0.0, 1.0) };
+ let c = if c.is_nan() { 0.0 } else { c.max(0.0) };
+ let h = if h.is_finite() { h } else { 0.0 };
+ let exact = oklch_to_srgb(l, c, h);
+ let (rgb, lowered) = if in_srgb(exact) { (exact, false) } else { (oklch_to_srgb(l, largest_fitting_chroma(l, h, c), h), true) };
+ (rgb.map(|v| v.clamp(0.0, 1.0) as f32), lowered)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn eight(rgb: [f32; 3]) -> [u8; 3] {
+ rgb.map(|v| (v * 255.0).round() as u8)
+ }
+
+ #[test]
+ fn red_has_the_oklch_of_the_oklab_matrices_and_converts_back() {
+ let [l, c, h] = to_oklch([1.0, 0.0, 0.0]);
+ assert!((l - 0.6280).abs() < 5e-5 && (c - 0.2577).abs() < 5e-5 && (h - 29.23).abs() < 5e-3, "{l} {c} {h}");
+ let (rgb, lowered) = from_oklch(l, c, h);
+ assert_eq!((eight(rgb), lowered), ([255, 0, 0], false));
+ }
+
+ /// CSS Color 4's examples convert to the hue its oklab() and oklch() forms give.
+ #[test]
+ fn the_polar_form_matches_the_css_examples() {
+ for ([l, a, b], [cl, cc, ch]) in
+ [([0.40101, 0.1147, 0.0453], [0.40101, 0.12332, 21.555]), ([0.65125, -0.0320, 0.1274], [0.65125, 0.13138, 104.097])]
+ {
+ let rgb = oklab_to_srgb(l, a, b).map(|v| v as f32);
+ let [ol, oc, oh] = to_oklch(rgb);
+ assert!((ol - cl).abs() < 1e-4 && (oc - cc).abs() < 1e-4 && (oh - ch).abs() < 0.05, "{ol} {oc} {oh}");
+ }
+ }
+
+ #[test]
+ fn the_216_web_colors_round_trip() {
+ let steps = [0u8, 0x33, 0x66, 0x99, 0xcc, 0xff];
+ for r in steps {
+ for g in steps {
+ for b in steps {
+ let rgb = [r, g, b].map(|v| f32::from(v) / 255.0);
+ let [l, c, h] = to_oklch(rgb);
+ assert_eq!(eight(from_oklch(l, c, h).0), [r, g, b], "{l} {c} {h}");
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn grays_have_no_chroma_and_hue_zero() {
+ for v in [0.0, 0.5, 1.0] {
+ let [_, c, h] = to_oklch([v, v, v]);
+ assert!(c <= POWERLESS_CHROMA && h == 0.0, "{c} {h}");
+ }
+ }
+
+ /// A chroma past the gamut gives a color inside it with the same lightness and hue, and says so.
+ #[test]
+ fn a_chroma_past_the_gamut_is_lowered_keeping_lightness_and_hue() {
+ let (l, h) = (0.7, 150.0);
+ let max = max_chroma(l, h);
+ assert!(max > 0.05 && max < CHROMA_FULL, "{max}");
+ assert!(in_srgb(oklch_to_srgb(l, max, h)) && !in_srgb(oklch_to_srgb(l, max + 1e-3, h)));
+ let (rgb, lowered) = from_oklch(l, CHROMA_FULL, h);
+ assert!(lowered);
+ let [ol, oc, oh] = to_oklch(rgb);
+ assert!((ol - l).abs() < 2e-3 && (oh - h).abs() < 1.0 && (oc - max).abs() < 2e-3, "{ol} {oc} {oh}");
+ assert!(!from_oklch(l, max * 0.5, h).1);
+ }
+
+ /// At the lightness and hue of blue the ray leaves sRGB and comes back at blue itself, so the
+ /// largest chroma is blue's, and a chroma past it gives blue.
+ #[test]
+ fn the_largest_chroma_at_blues_hue_is_blues() {
+ let [l, c, h] = to_oklch([0.0, 0.0, 1.0]);
+ let max = max_chroma(l, h);
+ assert!((max - c).abs() < 1e-4 && in_srgb(oklch_to_srgb(l, max, h)), "{max} {c}");
+ let (rgb, lowered) = from_oklch(l, CHROMA_FULL, h);
+ assert_eq!((eight(rgb), lowered), ([0, 0, 255], true));
+ // A chroma between the two stretches takes the end of the first one, inside sRGB.
+ let (rgb, lowered) = from_oklch(l, 0.29, h);
+ let [_, gc, _] = to_oklch(rgb);
+ assert!(lowered && gc < 0.27 && in_srgb(oklch_to_srgb(l, gc, h)), "{gc}");
+ // A hue just past blue's: a narrow second stretch ends just below the line from black to blue.
+ let (l, h) = (0.44, 264.06);
+ let max = max_chroma(l, h);
+ assert!(max > 0.304 && max < 0.305 && in_srgb(oklch_to_srgb(l, max, h)), "{max}");
+ let [_, got, _] = to_oklch(from_oklch(l, 0.35, h).0);
+ assert!(got > 0.303, "{got}");
+ // A darker blue on the line from black to blue.
+ let [l, c, h] = to_oklch([0.0, 0.0, 0.25]);
+ assert!((max_chroma(l, h) - c).abs() < 1e-4, "{} {c}", max_chroma(l, h));
+ }
+
+ /// Just below blue's lightness the line from black to blue passes a chroma of 0.3125, where a
+ /// search from 0 to 0.5 lands first. A chroma asked for below that line still gives a color
+ /// inside sRGB with the lightness and hue asked for.
+ #[test]
+ fn a_chroma_below_the_line_from_black_to_blue_stays_inside_srgb() {
+ let [bl, bc, h] = to_oklch([0.0, 0.0, 1.0]);
+ let l = bl * 0.3125 / bc;
+ let (rgb, lowered) = from_oklch(l, 0.29, h);
+ let [gl, gc, gh] = to_oklch(rgb);
+ assert!(lowered && gc < 0.29 && in_srgb(oklch_to_srgb(l, gc, h)), "{gc}");
+ assert!((gl - l).abs() < 2e-3 && (gh - h).abs() < 1.0, "{gl} {gh}");
+ }
+
+ /// sRGB channels below 0 go through the transfer curve with its sign turned, as CSS Color 4's
+ /// extended sRGB does, in both directions.
+ #[test]
+ fn negative_channels_use_the_signed_transfer_curve() {
+ let linear = -((0.5_f64 + 0.055) / 1.055).powf(2.4);
+ let [l, c, _] = to_oklch([-0.5; 3]);
+ assert!((l - linear.cbrt()).abs() < 1e-4 && c <= POWERLESS_CHROMA, "{l} {c}");
+ for v in oklch_to_srgb(linear.cbrt(), 0.0, 0.0) {
+ assert!((v + 0.5).abs() < 1e-4, "{v}");
+ }
+ // Small values near 0 keep the straight part of the curve.
+ let [l, _, _] = to_oklch([-0.01; 3]);
+ assert!((l - (-0.01_f64 / 12.92).cbrt()).abs() < 1e-4, "{l}");
+ }
+
+ /// The largest chroma fits and is at least the largest one a scan in steps of 0.0005 finds, at
+ /// every hue and at lightnesses near black too, where the ray can come back into sRGB away from
+ /// any primary color's hue (L 0.02 and H 242° fit up to about 0.022 after leaving near 0.012).
+ #[test]
+ fn the_largest_chroma_is_never_below_a_scan_of_the_ray() {
+ let scan = |l: f64, h: f64| (0..=1000).map(|i| f64::from(i) * 0.0005).filter(|c| in_srgb(oklch_to_srgb(l, *c, h))).fold(0.0, f64::max);
+ assert!(max_chroma(0.02, 242.0) > 0.02, "{}", max_chroma(0.02, 242.0));
+ for l in [0.005, 0.02, 0.05, 0.1, 0.3, 0.44, 0.6, 0.8, 0.95, 0.99] {
+ for h in (0..72).map(|i| f64::from(i) * 5.0 + 2.0) {
+ let max = max_chroma(l, h);
+ assert!(in_srgb(oklch_to_srgb(l, max, h)) && max >= scan(l, h), "L {l} H {h}: {max} < {}", scan(l, h));
+ }
+ }
+ }
+
+ #[test]
+ fn black_white_and_bad_numbers_hold_no_chroma() {
+ assert_eq!(max_chroma(0.0, 30.0), 0.0);
+ assert_eq!(max_chroma(1.0, 30.0), 0.0);
+ assert_eq!(max_chroma(f64::NAN, 30.0), 0.0);
+ assert_eq!(max_chroma(0.5, f64::INFINITY), 0.0);
+ assert_eq!(eight(from_oklch(f64::NAN, f64::NAN, f64::NAN).0), [0, 0, 0]);
+ assert_eq!(eight(from_oklch(2.0, -1.0, 0.0).0), [255, 255, 255]);
+ }
+}
diff --git a/crates/doc/src/appearance/layers.rs b/crates/doc/src/appearance/layers.rs
index 1728b7e323..11d2b0664d 100644
--- a/crates/doc/src/appearance/layers.rs
+++ b/crates/doc/src/appearance/layers.rs
@@ -195,12 +195,14 @@ impl StrokeLayer {
wheel: None,
}
}
+ /// The least weight an arrowhead is drawn at, in points ([`Self::arrow_weight`]).
+ pub const LEAST_ARROW_WEIGHT: f64 = 0.25;
/// Weight of the start (`end == false`) or end arrowhead: stroke weight × its scale, at least
- /// a quarter point. A head of weight `hw` fits a box about `4·hw` long and wide (see
+ /// [`Self::LEAST_ARROW_WEIGHT`]. A head of weight `hw` fits a box about `4·hw` long and wide (see
/// [`Arrowhead::reach`] and [`Arrowhead::half_width`]).
pub fn arrow_weight(&self, end: bool) -> f64 {
let pct = if end { self.arrow_scale.1 } else { self.arrow_scale.0 };
- (self.width * pct / 100.0).max(0.25)
+ (self.width * pct / 100.0).max(Self::LEAST_ARROW_WEIGHT)
}
/// How far the start (`end == false`) or end arrowhead can reach from its end point (0
/// without one): the head's diagonal, or with [`ArrowAlign::Extend`] its length, plus the cap.
diff --git a/crates/doc/src/appearance/stroke_style.rs b/crates/doc/src/appearance/stroke_style.rs
index 18b226c676..7a39d6cbb2 100644
--- a/crates/doc/src/appearance/stroke_style.rs
+++ b/crates/doc/src/appearance/stroke_style.rs
@@ -68,6 +68,10 @@ pub struct CustomArrowhead {
/// across it, positive to the right of the direction the head points. A head is 4 units wide,
/// as the built-in heads are, and a unit is the head's weight.
pub path: PathData,
+ /// Where the stroke ends under the head, in head units back from the tip, when the head says
+ /// so ([`Self::with_stop`]); `None`: halfway along its length ([`Self::stop`]).
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub stop: Option,
}
#[derive(Deserialize)]
@@ -75,11 +79,17 @@ struct CustomArrowheadData {
name: String,
#[serde(default)]
path: PathData,
+ #[serde(default)]
+ stop: Option,
}
impl From for CustomArrowhead {
fn from(d: CustomArrowheadData) -> Self {
- CustomArrowhead::new(d.name, d.path)
+ let head = CustomArrowhead::new(d.name, d.path);
+ match d.stop {
+ Some(stop) => head.with_stop(stop),
+ None => head,
+ }
}
}
@@ -94,7 +104,17 @@ impl CustomArrowhead {
/// than [`Self::MAX_UNITS`] from the tip is dropped: the head then draws nothing.
pub fn new(name: String, path: PathData) -> Self {
let path = if Self::fits(&path) { path } else { PathData::default() };
- CustomArrowhead { name, path }
+ CustomArrowhead { name, path, stop: None }
+ }
+ /// The head with the stroke ending `stop` head units back from its tip (an arrowhead an
+ /// Illustrator file defines draws its line to a point of its own). A stop that is not finite,
+ /// is negative or is farther than [`Self::MAX_UNITS`] is left out: the stroke then ends
+ /// halfway along the head.
+ /// A head whose outline was dropped ([`Self::new`]) draws nothing and keeps no stop.
+ pub fn with_stop(mut self, stop: f64) -> Self {
+ let fits = !self.path.subpaths.is_empty() && stop.is_finite() && (0.0..=Self::MAX_UNITS).contains(&stop);
+ self.stop = fits.then_some(stop);
+ self
}
/// Whether outline `path` has at most [`Self::MAX_ANCHORS`] anchors and as many subpaths, with
/// finite points within [`Self::MAX_UNITS`] only.
@@ -116,10 +136,10 @@ impl CustomArrowhead {
pub fn half_width(&self) -> f64 {
self.bounds().map_or(0.0, |b| b.y0.abs().max(b.y1.abs()))
}
- /// Where the stroke ends under the head, in head units back from the tip: halfway along the
- /// head's length.
+ /// Where the stroke ends under the head, in head units back from the tip: its own stop
+ /// ([`Self::with_stop`]), else halfway along the head's length.
pub fn stop(&self) -> f64 {
- self.bounds().map_or(0.0, |b| b.x1.max(0.0) / 2.0)
+ self.stop.unwrap_or_else(|| self.bounds().map_or(0.0, |b| b.x1.max(0.0) / 2.0))
}
}
diff --git a/crates/doc/src/appearance/tests.rs b/crates/doc/src/appearance/tests.rs
index caad4f6edc..ab0ba559f0 100644
--- a/crates/doc/src/appearance/tests.rs
+++ b/crates/doc/src/appearance/tests.rs
@@ -383,6 +383,15 @@ fn custom_arrowheads_carry_their_art_and_measure_it() {
assert_eq!(head.half_width(), 2.0);
let Arrowhead::Custom(c) = &head else { panic!("custom") };
assert_eq!(c.stop(), 1.5, "the line stops halfway along the head");
+ // A head with a stop of its own (an Illustrator file's arrowhead) keeps it, saved and read back.
+ let stopped = (**c).clone().with_stop(0.5);
+ assert_eq!(stopped.stop(), 0.5);
+ let back: CustomArrowhead = serde_json::from_value(serde_json::to_value(&stopped).unwrap()).unwrap();
+ assert_eq!(back, stopped);
+ assert!(!serde_json::to_string(&**c).unwrap().contains("stop"), "a head without one writes none");
+ for odd in [f64::NAN, -0.5, CustomArrowhead::MAX_UNITS + 1.0] {
+ assert_eq!((**c).clone().with_stop(odd).stop(), 1.5, "{odd} is left out");
+ }
// Saved with the stroke, art and all, beside the built-in heads' names.
let mut st = StrokeLayer::new(Paint::solid(Color::BLACK), 2.0);
(st.start_arrow, st.end_arrow) = (Some(Arrowhead::Triangle), Some(head.clone()));
@@ -404,7 +413,7 @@ fn custom_arrowheads_out_of_bounds_draw_nothing() {
let mut path = c.path.clone();
path.subpaths[0].anchors[1] = vectorcraft_geom::Anchor::corner(vectorcraft_geom::Point::new(1e9, 0.0));
// A file can hold what `new` drops: reading it drops it too.
- let json = serde_json::to_value(CustomArrowhead { name: "Wedge".into(), path }).unwrap();
+ let json = serde_json::to_value(CustomArrowhead { name: "Wedge".into(), path, stop: None }).unwrap();
let far: CustomArrowhead = serde_json::from_value(json).unwrap();
assert_eq!((far.name.as_str(), far.path.subpaths.len()), ("Wedge", 0));
assert_eq!((far.reach(), far.half_width(), far.stop()), (0.0, 0.0, 0.0));
@@ -415,7 +424,7 @@ fn custom_arrowheads_out_of_bounds_draw_nothing() {
let mut hollow = c.path.clone();
hollow.subpaths.extend(std::iter::repeat_n(vectorcraft_geom::SubPath::new(vec![], false), CustomArrowhead::MAX_ANCHORS));
assert!(!CustomArrowhead::fits(&hollow), "too many subpaths");
- let json = serde_json::to_value(CustomArrowhead { name: "Hollow".into(), path: hollow }).unwrap();
+ let json = serde_json::to_value(CustomArrowhead { name: "Hollow".into(), path: hollow, stop: None }).unwrap();
let hollow: CustomArrowhead = serde_json::from_value(json).unwrap();
assert!(hollow.path.subpaths.is_empty(), "too many subpaths, read back");
}
diff --git a/crates/doc/src/blend.rs b/crates/doc/src/blend.rs
index 7c7429acc2..02458af8c5 100644
--- a/crates/doc/src/blend.rs
+++ b/crates/doc/src/blend.rs
@@ -1156,6 +1156,17 @@ impl Lerp {
(NodeKind::PlacedDocument(o), NodeKind::PlacedDocument(x), NodeKind::PlacedDocument(y)) => o.xf = lerp_affine(x.xf, y.xf, t),
_ => {}
}
+ // Between distorted images, each step's corners lie between the keys' corners. A
+ // step whose corners would fold keeps the nearer key's.
+ if (a.is_distorted_image() || b.is_distorted_image())
+ && let (Some(qa), Some(qb)) = (a.image_corners(), b.image_corners())
+ {
+ let near = if t < 0.5 { qa } else { qb };
+ if n.set_image_corners([0, 1, 2, 3].map(|i| qa[i].lerp(qb[i], t))).is_err() {
+ // The nearer key's corners passed the same check when it was distorted.
+ let _ = n.set_image_corners(near);
+ }
+ }
n.extras_mut().mask = None;
n
}
@@ -2297,6 +2308,43 @@ mod tests {
assert_eq!(m.subpaths[0].anchors[0].p, Point::new(55.0, 0.0));
}
+ /// A step between two distorted images has its corners between the keys' corners.
+ #[test]
+ fn steps_between_distorted_images_have_corners_between_theirs() {
+ let image = |q: [(f64, f64); 4]| {
+ let im = crate::ImageObject {
+ key: "k".into(),
+ width: 10,
+ height: 10,
+ xf: Affine::IDENTITY,
+ link: None,
+ placement: Default::default(),
+ pixels: None,
+ };
+ let mut n = Node::new(NodeId(1), NodeKind::Image(Box::new(im)));
+ n.set_image_corners(q.map(|(x, y)| Point::new(x, y))).unwrap();
+ n
+ };
+ let a = image([(40.0, 0.0), (60.0, 0.0), (100.0, 100.0), (0.0, 100.0)]);
+ let b = image([(200.0, 0.0), (300.0, 0.0), (280.0, 100.0), (220.0, 100.0)]);
+ let mid = Lerp::new(&a, &b, (None, None)).at(0.5);
+ let want = [(120.0, 0.0), (180.0, 0.0), (190.0, 100.0), (110.0, 100.0)];
+ let got = mid.image_corners().unwrap();
+ for (g, (x, y)) in got.iter().zip(want) {
+ assert!(g.distance(Point::new(x, y)) < 1e-9, "{got:?}");
+ }
+ // Toward a key flipped left to right, the middle step's corners would meet: each step
+ // there keeps the nearer key's corners, whether that key is distorted or not.
+ let flipped = image([(60.0, 0.0), (40.0, 0.0), (0.0, 100.0), (100.0, 100.0)]);
+ let mirror = image([(100.0, 0.0), (0.0, 0.0), (0.0, 100.0), (100.0, 100.0)]);
+ assert!(!mirror.is_distorted_image());
+ for (b, t) in [(&flipped, 0.5), (&mirror, 0.5), (&mirror, 0.45)] {
+ let got = Lerp::new(&a, b, (None, None)).at(t).image_corners().unwrap();
+ let near = (if t < 0.5 { &a } else { b }).image_corners().unwrap();
+ assert!(got.iter().zip(near).all(|(g, w)| g.distance(w) < 1e-9), "{t}: {got:?} against {near:?}");
+ }
+ }
+
fn key(x: f64) -> Arc {
Arc::new(Node::path(NodeId(1), vectorcraft_geom::shapes::rectangle(Rect::new(x, 0.0, x + 10.0, 10.0)), Appearance::default()))
}
diff --git a/crates/doc/src/dimension.rs b/crates/doc/src/dimension.rs
index 9e78d17d4d..4d66f5d74c 100644
--- a/crates/doc/src/dimension.rs
+++ b/crates/doc/src/dimension.rs
@@ -124,6 +124,54 @@ impl ArrowStyle {
}
}
+/// `arrowHead`: null, or a built-in stroke arrowhead by its name (`Barbed`, as `stroke.set` takes
+/// it). A custom arrowhead and an unknown name are refused.
+mod arrow_head {
+ use crate::Arrowhead;
+ use serde::de::{Error, IntoDeserializer, Visitor};
+ use serde::{Deserialize, Deserializer};
+
+ pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result