mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Merge main into fix/retrace-keeps-note-and-tags
This commit is contained in:
commit
8ce2c031c9
111 files changed
+4703
-611
No files matched your search
@@ -67,7 +67,8 @@ jobs:
|
||||
# The warm build runs as one `cache warm <k>/6` leg per shard, in parallel (each builds what
|
||||
# its shard builds), and `cache warm` puts their files into the one entry it saves.
|
||||
warm-split: true
|
||||
# The dependency cache also keeps the compiled workspace crates and test executables, so a
|
||||
# The dependency cache also keeps the compiled workspace crates and their library and binary
|
||||
# test executables (not the integration tests' executables), so a
|
||||
# pull request's shards rebuild only the crates its changes reach. Each main run's `cache
|
||||
# warm` leg saves a rolling entry of its own, every leg restores the newest one, and
|
||||
# cache-prune.yml deletes the one it replaced after each attempt. The nightly run restores
|
||||
|
||||
Generated
+129
-120
@@ -4,9 +4,8 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "acadrust"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8923c99ea1f151cb7fc17ce2fc14f8b1e330fa22611e535602d985c0cc3c89a2"
|
||||
version = "0.6.9"
|
||||
source = "git+https://github.com/storytold/acadrust.git?rev=468b9d8e317755209020d5d3f2f1c8a76210c47f#468b9d8e317755209020d5d3f2f1c8a76210c47f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.13.2",
|
||||
@@ -16,6 +15,7 @@ dependencies = [
|
||||
"foldhash 0.2.0",
|
||||
"indexmap",
|
||||
"itoa",
|
||||
"memchr",
|
||||
"memmap2",
|
||||
"nom 7.1.3",
|
||||
"oem_cp",
|
||||
@@ -24,6 +24,7 @@ dependencies = [
|
||||
"ryu",
|
||||
"thiserror 2.0.21",
|
||||
"web-time",
|
||||
"whichever",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1255,7 +1256,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-automation",
|
||||
"craft-behavior",
|
||||
@@ -1297,7 +1298,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-affinity"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -1318,7 +1319,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-appkit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"objc2 0.6.5",
|
||||
@@ -1330,7 +1331,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"rustix 1.1.6",
|
||||
]
|
||||
@@ -1338,7 +1339,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-automation"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -1363,11 +1364,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-behavior"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bitflags 2.13.2",
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
"craft-keymap",
|
||||
"craft-theme",
|
||||
"craft-tracked",
|
||||
@@ -1381,7 +1383,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-browse"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-docpath",
|
||||
@@ -1399,7 +1401,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cdr"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -1408,7 +1410,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cloud-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"egui",
|
||||
]
|
||||
@@ -1416,7 +1418,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-cms"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"md-5",
|
||||
"rayon",
|
||||
@@ -1425,12 +1427,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
|
||||
[[package]]
|
||||
name = "craft-color-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-cms",
|
||||
@@ -1450,7 +1452,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-ai-agents",
|
||||
"craft-atomic",
|
||||
@@ -1466,7 +1468,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-control-protocol"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"serde_json",
|
||||
@@ -1476,7 +1478,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -1484,7 +1486,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dialogs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"craft-appkit",
|
||||
@@ -1510,7 +1512,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-doc"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-ecproj-format",
|
||||
@@ -1526,7 +1528,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -1534,7 +1536,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-draw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1553,16 +1555,17 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-dwg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"acadrust",
|
||||
"craft-dxf",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-dxf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-codepage",
|
||||
"encoding_rs",
|
||||
@@ -1574,7 +1577,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ecproj-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1584,12 +1587,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
|
||||
[[package]]
|
||||
name = "craft-flags"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"dirs",
|
||||
@@ -1599,7 +1602,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-catalog"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust 0.13.3",
|
||||
@@ -1614,7 +1617,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-manager"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -1633,7 +1636,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-os-windows"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"windows-registry",
|
||||
"windows-sys 0.61.2",
|
||||
@@ -1642,7 +1645,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-font-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"cap-primitives",
|
||||
"craft-atomic",
|
||||
@@ -1665,12 +1668,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
|
||||
[[package]]
|
||||
name = "craft-gif"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"gif",
|
||||
]
|
||||
@@ -1678,7 +1681,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-gzip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
]
|
||||
@@ -1686,7 +1689,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-host"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-i18n",
|
||||
@@ -1699,7 +1702,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.2",
|
||||
@@ -1729,7 +1732,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-jpeg",
|
||||
@@ -1756,7 +1759,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-imaging"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-color-ui",
|
||||
@@ -1774,7 +1777,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1782,7 +1785,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-jxl"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"brotli-decompressor 5.0.3",
|
||||
"jixel",
|
||||
@@ -1793,7 +1796,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-keymap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-host",
|
||||
"craft-i18n",
|
||||
@@ -1808,7 +1811,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-layers"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
@@ -1822,7 +1825,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-menu"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -1840,7 +1843,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.3.2",
|
||||
"chrono",
|
||||
@@ -1852,7 +1855,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metafile"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"image",
|
||||
@@ -1863,7 +1866,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-mime"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-codepage",
|
||||
@@ -1873,7 +1876,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-nightly"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"uds_windows",
|
||||
"winsafe",
|
||||
@@ -1882,7 +1885,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pages"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -1898,7 +1901,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pbr"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-texture",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1907,7 +1910,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"serde",
|
||||
@@ -1918,7 +1921,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"hayro-interpret",
|
||||
"hayro-syntax",
|
||||
@@ -1930,7 +1933,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-platform"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-io",
|
||||
@@ -1963,7 +1966,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-plotter"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"kurbo 0.13.1",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1972,7 +1975,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -1996,7 +1999,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-proof"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"log",
|
||||
"miniz_oxide 0.9.1",
|
||||
@@ -2007,7 +2010,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-eps",
|
||||
"flate2",
|
||||
@@ -2021,7 +2024,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-psd"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -2032,7 +2035,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -2045,7 +2048,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-raster3d"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2054,7 +2057,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-review"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"craft-behavior",
|
||||
@@ -2073,7 +2076,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-settings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-host",
|
||||
@@ -2090,7 +2093,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-stream-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"fax",
|
||||
"hayro-ccitt",
|
||||
@@ -2101,7 +2104,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-xml",
|
||||
@@ -2122,7 +2125,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-table"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2134,7 +2137,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-text"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-manager",
|
||||
@@ -2159,7 +2162,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-texture"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -2167,7 +2170,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"craft-tracked",
|
||||
@@ -2182,7 +2185,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-theme-store"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"craft-behavior",
|
||||
@@ -2197,7 +2200,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2207,7 +2210,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-time"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2216,7 +2219,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-timeline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-keymap",
|
||||
@@ -2231,12 +2234,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tracked"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-cloud-ui",
|
||||
"craft-ui-canvas",
|
||||
@@ -2250,7 +2253,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-canvas"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-font-catalog",
|
||||
@@ -2267,7 +2270,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-contract"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"craft-behavior",
|
||||
@@ -2305,7 +2308,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -2316,7 +2319,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-panels"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2334,7 +2337,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-patterns"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2355,7 +2358,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-shell"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2376,7 +2379,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui-widgets"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-host",
|
||||
@@ -2395,7 +2398,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
@@ -2427,7 +2430,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-vectorcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"serde",
|
||||
@@ -2438,7 +2441,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-wayland"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"raw-window-handle",
|
||||
"wayland-backend",
|
||||
@@ -2448,7 +2451,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-web-api"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"serde_json",
|
||||
@@ -2459,7 +2462,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-win32"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"winsafe",
|
||||
]
|
||||
@@ -2467,7 +2470,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-window"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"craft-appkit",
|
||||
"craft-atomic",
|
||||
@@ -2499,7 +2502,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
@@ -2844,7 +2847,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -2877,7 +2880,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -2912,7 +2915,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -2931,7 +2934,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -2950,7 +2953,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"accesskit_winit",
|
||||
"arboard",
|
||||
@@ -2976,7 +2979,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"egui",
|
||||
@@ -2990,7 +2993,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -3003,7 +3006,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"dify",
|
||||
"eframe",
|
||||
@@ -3029,7 +3032,7 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
@@ -3110,7 +3113,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -3136,7 +3139,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=861d60a65c50850e995bbb3dcee7c1f3b06815f6#861d60a65c50850e995bbb3dcee7c1f3b06815f6"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=399fc6e0ea65059e37de680f11ebbd177bf7d4ff#399fc6e0ea65059e37de680f11ebbd177bf7d4ff"
|
||||
dependencies = [
|
||||
"brotli 9.1.3",
|
||||
"brotli-decompressor 6.3.2",
|
||||
@@ -3859,7 +3862,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a"
|
||||
[[package]]
|
||||
name = "hayro-cmap"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"brotli 8.0.4",
|
||||
"hayro-postscript",
|
||||
@@ -3868,7 +3871,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-interpret"
|
||||
version = "0.7.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"hayro-cmap",
|
||||
@@ -3886,7 +3889,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"fearless_simd",
|
||||
"hayro-ccitt",
|
||||
@@ -3904,12 +3907,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "hayro-postscript"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.7.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hayro-ccitt",
|
||||
@@ -4892,7 +4895,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bumpalo",
|
||||
@@ -5049,7 +5052,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4"
|
||||
[[package]]
|
||||
name = "linesweeper"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=c2a47dfea38b215245f739c675da3662c89f1e09#c2a47dfea38b215245f739c675da3662c89f1e09"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=4c330f6bd1f38dd536f830483ea9618db2cb2bd8#4c330f6bd1f38dd536f830483ea9618db2cb2bd8"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"kurbo 0.13.1",
|
||||
@@ -9663,19 +9666,6 @@ dependencies = [
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b6d8cf1eb2c1c31ed1f5643c88a6e53538129d4af80030c8cabd1f9fa884d91"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-wlr"
|
||||
version = "0.3.12"
|
||||
@@ -9976,6 +9966,26 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "whichever"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68887c9512981e597d730f1d95b2eb6abdd53385e4e76c35a95e7121e16232b0"
|
||||
dependencies = [
|
||||
"whichever-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "whichever-macros"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb15ad553239d9fdefac12e31e16c7682dc62a2106ba035aec69c5dd15835a7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.2.1"
|
||||
@@ -10219,7 +10229,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
[[package]]
|
||||
name = "winit"
|
||||
version = "0.30.13"
|
||||
source = "git+https://github.com/storytold/winit.git?rev=0dfcec0eb62fda5904137a63a6dd0c3d83295f45#0dfcec0eb62fda5904137a63a6dd0c3d83295f45"
|
||||
source = "git+https://github.com/storytold/winit.git?rev=3fd7ae64762f82a73b78bd24f453f82c4291067d#3fd7ae64762f82a73b78bd24f453f82c4291067d"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"android-activity",
|
||||
@@ -10258,7 +10268,6 @@ dependencies = [
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-plasma",
|
||||
"web-sys",
|
||||
"web-time",
|
||||
"windows-sys 0.52.0",
|
||||
|
||||
+54
-53
@@ -10,57 +10,57 @@ license = "MIT OR Apache-2.0"
|
||||
rust-version = "1.95"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09", default-features = false, features = ["interpret", "write"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8", default-features = false, features = ["interpret", "write"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# Language packs: the Craft apps' shared font store installs them (#4936).
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# 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 = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# `.pcraft` documents: their manifest, full-size composite, preview, layer pixels and ICC profile.
|
||||
craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09", features = ["pcraft-pixels"] }
|
||||
craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8", features = ["pcraft-pixels"] }
|
||||
# Native Affinity documents (craft-libs#914).
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# Bounded CDR (v1-v27) and CMX (32-bit) reader (craft-libs#778).
|
||||
craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# SVG parsing, limits, SVGZ and writer (craft-libs#778).
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09", features = ["tree"] }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8", features = ["tree"] }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# EPS container, previews, ASCII85 and DSC comments (craft-libs#778).
|
||||
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# DXF tags, reader and writer (craft-libs#778, #926, #927).
|
||||
craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# DWG to DXF bytes, in a child process on desktop builds (acadrust 0.6.6, MPL-2.0, unmodified).
|
||||
craft-dwg = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-dwg = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# WMF, EMF and EMF+ reader (craft-libs#778).
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09", default-features = false, features = ["read", "write"] }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8", default-features = false, features = ["read", "write"] }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# The metallic-roughness BRDF and environment light the 3D effects' Roughness and Metallic shade with.
|
||||
craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# The CPU rasterizer that draws a 3D effect's Render Settings › Rendered image: depth-buffered triangles, shadow maps.
|
||||
craft-raster3d = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-raster3d = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# The framework facade (`craft::ui`, `craft::settings`, `craft::platform`, ...). No default features: each crate names
|
||||
# the members it imports.
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# Below the egui layer, so not through the facade: the colour harmony rules and their settings (craft-color-ui
|
||||
# without its `ui` feature), the colour type they work in, and the craft-fonts tables the text crate's build writes.
|
||||
craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# Nightly profile isolation, launch protocol, and security fence.
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# internal
|
||||
vectorcraft-geom = { path = "crates/geom" }
|
||||
vectorcraft-color = { path = "crates/color" }
|
||||
@@ -200,24 +200,25 @@ lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "c2a47dfea38b215245f739c675da3662c89f1e09" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8" }
|
||||
# skrifa 0.44 (epaint, glifo, usvg) with the automatic hinter's long blue-zone exit (craft-libs vendor/skrifa).
|
||||
# It stays at this rev until craft-libs#5222 merges.
|
||||
skrifa = { git = "https://github.com/storytold/craft-libs", rev = "37d0532f42eb3421769c8a454e3e25a20fbcff97" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "861d60a65c50850e995bbb3dcee7c1f3b06815f6" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "0dfcec0eb62fda5904137a63a6dd0c3d83295f45" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "399fc6e0ea65059e37de680f11ebbd177bf7d4ff" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "3fd7ae64762f82a73b78bd24f453f82c4291067d" }
|
||||
@@ -124,6 +124,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap
|
||||
|
||||
## Progress log
|
||||
|
||||
- 2026-12-04: Raster Settings OK edits the objects selected when the dialog opened. It keeps the dialog open with the reason if its document is not active, was reverted or had an Undo, a Redo or a canceled edit that put back an earlier state, if a target was changed, deleted, locked or hidden, if another edit is in progress, or if the change is refused. Headline numbers unchanged.
|
||||
- 2026-12-04: Paste from CAD apps: on Windows, Paste reads the enhanced metafile CAD and office apps copy as vector art, and a `.dxf`, `.dwg` or HP-GL plot file copied in a file manager pastes as its drawing through the new command `clipboard.importCad` (#10819). Headline numbers unchanged.
|
||||
|
||||
- 2026-12-03: View › Show Curvature Comb (`view.curvatureComb`) draws the curvature comb of the selected paths and compound paths: teeth along the normal as long as the curvature, and a line through their tips that starts again where the path turns back on itself at a cusp, a straight segment included (#10659). Headline numbers unchanged.
|
||||
|
||||
@@ -196,8 +196,8 @@ USAGE:
|
||||
|
||||
/// The usage text plus the formats `document.open` reads and `document.export` writes.
|
||||
fn usage() -> String {
|
||||
use vectorcraft_engine::cmd::fileio::{OPEN_EXTS, export_extensions};
|
||||
format!("{USAGE}\nReadable formats: .{}\nWritable formats: .{}\n", OPEN_EXTS.join(", ."), export_extensions().join(", ."))
|
||||
use vectorcraft_engine::cmd::fileio::{export_extensions, open_exts};
|
||||
format!("{USAGE}\nReadable formats: .{}\nWritable formats: .{}\n", open_exts().join(", ."), export_extensions().join(", ."))
|
||||
}
|
||||
|
||||
/// Does a subcommand's `args` ask for the usage? `--help` or `-h` counts where an option goes, not as
|
||||
|
||||
@@ -28,7 +28,7 @@ egui_extras = { workspace = true }
|
||||
# `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback.
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] }
|
||||
# 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 = "c2a47dfea38b215245f739c675da3662c89f1e09", version = "0.1.0" }
|
||||
craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "4c330f6bd1f38dd536f830483ea9618db2cb2bd8", version = "0.1.0" }
|
||||
|
||||
wasm-bindgen = "0.2"
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
//! Block definitions and INSERT entities for the DXF writer.
|
||||
//!
|
||||
//! Temporary: `craft_dxf::drawing` at the pinned craft-libs revision writes only the model and
|
||||
//! paper space blocks. storytold/craft-libs#5381 adds `Block`, `Drawing::blocks` and
|
||||
//! `Codes::insert`; once it merges and the pin moves past it, this module is removed and
|
||||
//! `scene.rs` uses those instead. Until then [`write`] adds the user blocks to the file that
|
||||
//! `Drawing::write` returns, with the same group codes #5381 writes.
|
||||
|
||||
use craft_dxf::drawing::{Codes, Drawing, Handle, fixed};
|
||||
|
||||
/// A block definition: entities written once, which INSERT entities place ([`insert`]). Its base
|
||||
/// point is the origin.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Block {
|
||||
pub name: String,
|
||||
/// The handle of its BLOCK_RECORD (from R13), which owns its entities.
|
||||
pub record: Handle,
|
||||
/// The handles of its BLOCK and ENDBLK records.
|
||||
pub begin: Handle,
|
||||
pub end: Handle,
|
||||
/// The entities' group codes, written with `record` as their owner.
|
||||
pub entities: String,
|
||||
}
|
||||
|
||||
/// The start of an object: its type, and from R13 its handle, owner and first subclass.
|
||||
fn object(c: &mut Codes, kind: &str, h: Handle, owner: Handle, subclass: &str) {
|
||||
c.raw(0, kind);
|
||||
if c.v.handles() {
|
||||
c.handle(5, h);
|
||||
c.handle(330, owner);
|
||||
c.raw(100, subclass);
|
||||
}
|
||||
}
|
||||
|
||||
/// An INSERT entity owned by `owner` on `layer` that places block `block` at the origin, unscaled
|
||||
/// and unrotated. It has no color of its own (ByLayer).
|
||||
pub fn insert(c: &mut Codes, h: Handle, owner: Handle, layer: &str, block: &str) {
|
||||
object(c, "INSERT", h, owner, "AcDbEntity");
|
||||
c.str(8, layer);
|
||||
if c.v.handles() {
|
||||
c.raw(100, "AcDbBlockReference");
|
||||
}
|
||||
c.str(2, block);
|
||||
c.xyz(10, 0.0, 0.0);
|
||||
}
|
||||
|
||||
/// The whole file of `d` with `blocks` written after the model and paper space blocks.
|
||||
pub fn write(d: Drawing, blocks: &[Block]) -> String {
|
||||
let v = d.version;
|
||||
let out = d.write();
|
||||
if blocks.is_empty() {
|
||||
return out;
|
||||
}
|
||||
let mut defs = Codes::new(v);
|
||||
for b in blocks {
|
||||
object(&mut defs, "BLOCK", b.begin, b.record, "AcDbEntity");
|
||||
defs.raw(8, "0");
|
||||
if v.handles() {
|
||||
defs.raw(100, "AcDbBlockBegin");
|
||||
}
|
||||
defs.str(2, &b.name);
|
||||
defs.int(70, 0);
|
||||
defs.xyz(10, 0.0, 0.0);
|
||||
defs.str(3, &b.name);
|
||||
defs.raw(1, "");
|
||||
defs.append(&b.entities);
|
||||
object(&mut defs, "ENDBLK", b.end, b.record, "AcDbEntity");
|
||||
defs.raw(8, "0");
|
||||
if v.handles() {
|
||||
defs.raw(100, "AcDbBlockEnd");
|
||||
}
|
||||
}
|
||||
let defs = defs.into_string();
|
||||
if !v.handles() {
|
||||
// R12 has no model and paper space blocks: its BLOCKS section holds the user blocks only.
|
||||
let at = " 0\nSECTION\n 2\nENTITIES\n";
|
||||
return match out.find(at) {
|
||||
Some(i) => format!("{} 0\nSECTION\n 2\nBLOCKS\n{defs} 0\nENDSEC\n{}", &out[..i], &out[i..]),
|
||||
None => out,
|
||||
};
|
||||
}
|
||||
let mut records = Codes::new(v);
|
||||
for b in blocks {
|
||||
object(&mut records, "BLOCK_RECORD", b.record, fixed::BLOCK_RECORD_TABLE, "AcDbSymbolTableRecord");
|
||||
records.raw(100, "AcDbBlockTableRecord");
|
||||
records.str(2, &b.name);
|
||||
if v.r2000() {
|
||||
records.handle(340, Handle(0));
|
||||
records.int(70, 0);
|
||||
records.int(280, 1);
|
||||
records.int(281, 0);
|
||||
}
|
||||
}
|
||||
let records = records.into_string();
|
||||
let (Some(table), Some(blocks_at)) = (out.find(" 0\nTABLE\n 2\nBLOCK_RECORD\n"), out.find(" 0\nSECTION\n 2\nBLOCKS\n")) else {
|
||||
return out;
|
||||
};
|
||||
let count = " 70\n2\n";
|
||||
let (Some(c), Some(t_end), Some(b_end)) = (
|
||||
out[table..].find(count).map(|i| table + i),
|
||||
out[table..].find(" 0\nENDTAB\n").map(|i| table + i),
|
||||
out[blocks_at..].find(" 0\nENDSEC\n").map(|i| blocks_at + i),
|
||||
) else {
|
||||
return out;
|
||||
};
|
||||
let mut s = String::with_capacity(out.len() + records.len() + defs.len());
|
||||
s.push_str(&out[..c]);
|
||||
s.push_str(&format!(" 70\n{}\n", 2 + blocks.len()));
|
||||
s.push_str(&out[c + count.len()..t_end]);
|
||||
s.push_str(&records);
|
||||
s.push_str(&out[t_end..b_end]);
|
||||
s.push_str(&defs);
|
||||
s.push_str(&out[b_end..]);
|
||||
s
|
||||
}
|
||||
@@ -13,6 +13,9 @@ use web_time::Instant;
|
||||
|
||||
pub use craft_dwg::{WORKER_ARG, allow_in_process, use_own_worker};
|
||||
|
||||
/// Whether this build decodes DWG drawings. Web builds and FreeBSD on 64-bit ARM have no DWG decoder.
|
||||
pub const DECODES: bool = !cfg!(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64")));
|
||||
|
||||
/// The worker argument after [`WORKER_ARG`] that gives its deadline in milliseconds since the UNIX epoch
|
||||
/// ([`use_own_worker_for`]).
|
||||
const WORKER_UNTIL_ARG: &str = "--dwg-worker-until";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! or with the drawing's origin on the artboard's bottom-left corner. Each DXF layer holding art
|
||||
//! becomes a layer (hidden, frozen, locked and non-plotting layers keep that), or all art goes on
|
||||
//! one. Lines, polylines with arc segments, circles, arcs, ellipses, splines (NURBS), solid
|
||||
//! hatches and solids become paths; text and multiline text point type; named blocks symbols
|
||||
//! hatches, solids and regions become paths; text and multiline text point type; named blocks symbols
|
||||
//! (anonymous ones, such as dimensions, groups of their art). Colours (indexed and true colour),
|
||||
//! lineweights, linetypes and transparency come through layers and blocks as CAD apps resolve
|
||||
//! them. What can't come in is listed in the warnings.
|
||||
@@ -16,8 +16,10 @@
|
||||
//! - `entity`: entities to items (geometry and properties).
|
||||
//! - `curve`: bulges, arcs, ellipses and NURBS as Bézier paths.
|
||||
//! - `text`: text values to plain text.
|
||||
//! - `acis`: a region's solid-modeler data as its outline.
|
||||
//! - `build`: items to the document.
|
||||
|
||||
mod acis;
|
||||
mod build;
|
||||
mod curve;
|
||||
mod entity;
|
||||
@@ -237,3 +239,5 @@ pub fn import(bytes: &[u8], o: &ImportOptions) -> Result<Imported, String> {
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
mod tests_dwg;
|
||||
#[cfg(test)]
|
||||
mod tests_region;
|
||||
@@ -0,0 +1,779 @@
|
||||
//! The solid-modeler data of a REGION as a filled outline: each face's loops of edges, in world x
|
||||
//! and y (drawing units). The data comes as text (DXF before 2013, ciphered or not) or binary
|
||||
//! (DXF 2013 and later keep it in the ACDSDATA section).
|
||||
//!
|
||||
//! The model is a list of records pointing at each other: a body holds lumps, a lump shells, a
|
||||
//! shell faces, a face loops, a loop a ring of coedges. Each coedge uses an edge (forward or
|
||||
//! reversed), and each edge runs between two vertices along a line, an ellipse or a spline. A
|
||||
//! curve of any other kind comes in as a straight line between its vertices.
|
||||
//!
|
||||
//! The REGION groups are in the DXF Reference
|
||||
//! (<https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-644BF0F0-FD79-4C5E-AD5A-0053FCC5A5A4>); which
|
||||
//! DXF versions hold text and which binary data is in <https://ezdxf.mozman.at/docs/acis.html>.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use kurbo::{BezPath, ParamCurve, ParamCurveArclen, ParamCurveNearest, PathSeg};
|
||||
use vectorcraft_geom::{Affine, Point};
|
||||
|
||||
use super::curve;
|
||||
|
||||
/// The most bytes of one region's data read.
|
||||
pub(crate) const MAX_BYTES: usize = 16 << 20;
|
||||
/// The most records one region's outline may visit: bodies, lumps, shells, faces and coedges
|
||||
/// (a loop counts as one at least).
|
||||
const MAX_VISITS: usize = 1_000_000;
|
||||
/// The first bytes of binary data: ACIS's, or ASM's (DXF 2018 writes either).
|
||||
const BINARY_MAGIC: [&[u8]; 2] = [b"ACIS BinaryFile", b"ASM BinaryFile4"];
|
||||
/// From this version on, every record starts with its attribute, a history number and one more
|
||||
/// pointer; before it, with its attribute alone.
|
||||
const LONG_HEADER_VERSION: u32 = 700;
|
||||
|
||||
type P3 = [f64; 3];
|
||||
/// A B-spline: degree, knots, control points, weights (none: all 1).
|
||||
type Spline = (usize, Vec<f64>, Vec<P3>, Option<Vec<f64>>);
|
||||
|
||||
/// One value of a record.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Tok {
|
||||
Ptr(i64),
|
||||
Num(f64),
|
||||
Word(String),
|
||||
/// `forward` (false) or `reversed` (true).
|
||||
Sense(bool),
|
||||
Open,
|
||||
Close,
|
||||
}
|
||||
|
||||
/// A record: its type (`body`, `plane-surface`…) and its values after the ones every record
|
||||
/// starts with.
|
||||
#[derive(Debug)]
|
||||
struct Rec {
|
||||
kind: String,
|
||||
toks: Vec<Tok>,
|
||||
}
|
||||
|
||||
impl Rec {
|
||||
/// The type `base` or one derived from it (`tedge-edge` is an edge).
|
||||
fn is(&self, base: &str) -> bool {
|
||||
self.kind == base || self.kind.strip_suffix(base).is_some_and(|k| k.ends_with('-'))
|
||||
}
|
||||
|
||||
/// The `n`th pointer (-1: none).
|
||||
fn ptr(&self, n: usize) -> i64 {
|
||||
self.toks.iter().filter_map(|t| if let Tok::Ptr(p) = t { Some(*p) } else { None }).nth(n).unwrap_or(-1)
|
||||
}
|
||||
|
||||
/// The sense right after the `n`th pointer: true when reversed (old files write 1).
|
||||
fn sense_after(&self, n: usize) -> Option<bool> {
|
||||
let mut ptrs = 0;
|
||||
for t in &self.toks {
|
||||
if ptrs > n {
|
||||
return match t {
|
||||
Tok::Sense(r) => Some(*r),
|
||||
Tok::Num(v) if v.is_finite() => Some(*v != 0.0),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
if matches!(t, Tok::Ptr(_)) {
|
||||
ptrs += 1;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The numbers, in order.
|
||||
fn nums(&self) -> Vec<f64> {
|
||||
self.toks.iter().filter_map(|t| if let Tok::Num(v) = t { Some(*v) } else { None }).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// The records of one body, and how pointers find them.
|
||||
struct Model {
|
||||
recs: Vec<Rec>,
|
||||
/// Record number by index, when the records carry their own.
|
||||
at: HashMap<i64, usize>,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
fn get(&self, p: i64) -> Option<&Rec> {
|
||||
if p < 0 {
|
||||
return None;
|
||||
}
|
||||
if self.at.is_empty() { self.recs.get(usize::try_from(p).ok()?) } else { self.recs.get(*self.at.get(&p)?) }
|
||||
}
|
||||
|
||||
/// The record `p` points at when it is of type `base`.
|
||||
fn get_is(&self, p: i64, base: &str) -> Option<&Rec> {
|
||||
self.get(p).filter(|r| r.is(base))
|
||||
}
|
||||
|
||||
/// The records of type `base` from `first` along their `next` pointer (pointer `next`), each
|
||||
/// once. Missing records, wrong types and cycles outside coedge rings set `broken`.
|
||||
fn chain(&self, first: i64, base: &str, next: usize, broken: &mut bool) -> Vec<&Rec> {
|
||||
let mut out = vec![];
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut p = first;
|
||||
while p >= 0 {
|
||||
if !seen.insert(p) {
|
||||
*broken |= base != "coedge";
|
||||
break;
|
||||
}
|
||||
let Some(r) = self.get_is(p, base) else {
|
||||
*broken = true;
|
||||
break;
|
||||
};
|
||||
out.push(r);
|
||||
p = r.ptr(next);
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// A region's outline: its faces' loops, closed; `approximated` when an edge of a curve type
|
||||
/// this reader doesn't draw came in as a straight line; `broken` when a topology chain breaks
|
||||
/// off or a loop's ring of coedges doesn't come back to its first; `ambiguous` when an edge's
|
||||
/// endpoint lies on separate parts of its curve.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Outline {
|
||||
pub path: BezPath,
|
||||
pub approximated: bool,
|
||||
pub broken: bool,
|
||||
pub ambiguous: bool,
|
||||
}
|
||||
|
||||
/// Text data, ciphered as DXF writes it or not.
|
||||
pub(crate) fn from_text(text: &str) -> Option<Outline> {
|
||||
if text.len() > MAX_BYTES {
|
||||
return None;
|
||||
}
|
||||
let plain;
|
||||
let text = if text.trim_start().starts_with(|c: char| c.is_ascii_digit()) {
|
||||
text
|
||||
} else {
|
||||
plain = decipher(text);
|
||||
&plain
|
||||
};
|
||||
outline(&sat_model(text)?)
|
||||
}
|
||||
|
||||
/// Binary data.
|
||||
pub(crate) fn from_binary(bytes: &[u8]) -> Option<Outline> {
|
||||
if bytes.len() > MAX_BYTES {
|
||||
return None;
|
||||
}
|
||||
outline(&sab_model(bytes)?)
|
||||
}
|
||||
|
||||
/// DXF's cipher of text data undone: each printable character is mapped back, and the space
|
||||
/// written after a mapped `A` (a caret, which DXF reads as a control code) is dropped.
|
||||
fn decipher(s: &str) -> String {
|
||||
let mut out = String::with_capacity(s.len());
|
||||
let mut chars = s.chars().peekable();
|
||||
while let Some(c) = chars.next() {
|
||||
out.push(match c {
|
||||
' ' | '\n' | '\r' | '\t' => c,
|
||||
'@'..='_' => char::from(159 - c as u8),
|
||||
c if c.is_ascii() && !c.is_ascii_control() => char::from(c as u8 ^ 0x5F),
|
||||
c => c,
|
||||
});
|
||||
if c == '^' && chars.peek() == Some(&' ') {
|
||||
chars.next();
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// How many values every record starts with in data of `version`.
|
||||
fn header_len(version: u32) -> usize {
|
||||
if version >= LONG_HEADER_VERSION { 3 } else { 1 }
|
||||
}
|
||||
|
||||
/// A text value as a value.
|
||||
fn sat_tok(w: &str) -> Tok {
|
||||
match w {
|
||||
"{" => Tok::Open,
|
||||
"}" => Tok::Close,
|
||||
"forward" | "forward_v" => Tok::Sense(false),
|
||||
"reversed" | "reversed_v" => Tok::Sense(true),
|
||||
_ => {
|
||||
if let Some(p) = w.strip_prefix('$').and_then(|p| p.parse::<i64>().ok()) {
|
||||
return Tok::Ptr(p);
|
||||
}
|
||||
match w.parse::<f64>() {
|
||||
Ok(v) if v.is_finite() => Tok::Num(v),
|
||||
_ => Tok::Word(w.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Does this line start a record (`[-<index>] <type> $<attribute> …`)?
|
||||
fn starts_record(line: &str) -> bool {
|
||||
let mut words = line.split_whitespace();
|
||||
let first = words.next().unwrap_or_default();
|
||||
let (kind, next) = if first.starts_with('-') && first[1..].parse::<u64>().is_ok() {
|
||||
(words.next().unwrap_or_default(), words.next().unwrap_or_default())
|
||||
} else {
|
||||
(first, words.next().unwrap_or_default())
|
||||
};
|
||||
kind.starts_with(|c: char| c.is_ascii_alphabetic()) && next.starts_with('$')
|
||||
}
|
||||
|
||||
/// Text data's records: a version line, product and tolerance lines, then records ending in `#`.
|
||||
fn sat_model(text: &str) -> Option<Model> {
|
||||
let version = text.split_whitespace().next()?.parse::<f64>().ok().filter(|v| v.is_finite() && *v >= 0.0)? as u32;
|
||||
let skip = header_len(version);
|
||||
let mut offset = text.find('\n')? + 1;
|
||||
let start = loop {
|
||||
let rest = text.get(offset..)?;
|
||||
let line = rest.split('\n').next().unwrap_or_default();
|
||||
if starts_record(line) {
|
||||
break offset;
|
||||
}
|
||||
offset += line.len() + 1;
|
||||
};
|
||||
let body = text.get(start..)?;
|
||||
let (mut recs, mut at) = (Vec::new(), HashMap::new());
|
||||
let mut cur: Vec<Tok> = vec![];
|
||||
let (mut kind, mut index): (Option<String>, Option<i64>) = (None, None);
|
||||
let mut i = 0;
|
||||
let b = body.as_bytes();
|
||||
while i < b.len() {
|
||||
if b[i].is_ascii_whitespace() {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
let end = b[i..].iter().position(u8::is_ascii_whitespace).map_or(b.len(), |n| i + n);
|
||||
let word = body.get(i..end)?;
|
||||
i = end;
|
||||
// A counted string: `@<n>`, a space, then n bytes.
|
||||
if let Some(n) = word.strip_prefix('@').and_then(|n| n.parse::<usize>().ok()) {
|
||||
let from = (i + 1).min(b.len());
|
||||
let to = from.checked_add(n)?.min(b.len());
|
||||
cur.push(Tok::Word(body.get(from..to)?.to_string()));
|
||||
i = to;
|
||||
continue;
|
||||
}
|
||||
let (word, ends) = match word.strip_suffix('#') {
|
||||
Some(w) => (w, true),
|
||||
None => (word, false),
|
||||
};
|
||||
if !word.is_empty() {
|
||||
match &kind {
|
||||
None if index.is_none() && word.starts_with('-') && word[1..].parse::<i64>().is_ok() => {
|
||||
index = word[1..].parse().ok();
|
||||
}
|
||||
None => {
|
||||
if word.starts_with("End-of-") || word.starts_with("Begin-of-") {
|
||||
break;
|
||||
}
|
||||
kind = Some(word.to_string());
|
||||
}
|
||||
Some(_) => cur.push(sat_tok(word)),
|
||||
}
|
||||
}
|
||||
if ends {
|
||||
let toks = cur.split_off(skip.min(cur.len()));
|
||||
cur.clear();
|
||||
if let Some(n) = index.take() {
|
||||
at.insert(n, recs.len());
|
||||
}
|
||||
recs.push(Rec { kind: kind.take().unwrap_or_default(), toks });
|
||||
}
|
||||
}
|
||||
Some(Model { recs, at })
|
||||
}
|
||||
|
||||
/// Reads binary data's little-endian values.
|
||||
struct Bytes<'b> {
|
||||
b: &'b [u8],
|
||||
i: usize,
|
||||
}
|
||||
|
||||
impl Bytes<'_> {
|
||||
fn take(&mut self, n: usize) -> Option<&[u8]> {
|
||||
let s = self.b.get(self.i..self.i.checked_add(n)?)?;
|
||||
self.i += n;
|
||||
Some(s)
|
||||
}
|
||||
fn u8(&mut self) -> Option<u8> {
|
||||
self.take(1).map(|s| s[0])
|
||||
}
|
||||
fn i16(&mut self) -> Option<f64> {
|
||||
self.take(2).map(|s| f64::from(i16::from_le_bytes([s[0], s[1]])))
|
||||
}
|
||||
fn u16(&mut self) -> Option<usize> {
|
||||
self.take(2).map(|s| usize::from(u16::from_le_bytes([s[0], s[1]])))
|
||||
}
|
||||
fn i32(&mut self) -> Option<i32> {
|
||||
self.take(4).map(|s| i32::from_le_bytes([s[0], s[1], s[2], s[3]]))
|
||||
}
|
||||
fn u32(&mut self) -> Option<u32> {
|
||||
self.take(4).map(|s| u32::from_le_bytes([s[0], s[1], s[2], s[3]]))
|
||||
}
|
||||
fn f64(&mut self) -> Option<f64> {
|
||||
let s = self.take(8)?;
|
||||
Some(f64::from_le_bytes([s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]]))
|
||||
}
|
||||
fn text(&mut self, n: usize) -> Option<String> {
|
||||
self.take(n).map(|s| String::from_utf8_lossy(s).into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
/// Binary data's records: the magic, four numbers (version first), product and tolerance values,
|
||||
/// then records of tagged values, each type name made of its parts.
|
||||
fn sab_model(b: &[u8]) -> Option<Model> {
|
||||
let mut r = Bytes { b: BINARY_MAGIC.iter().find_map(|m| b.strip_prefix(*m))?, i: 0 };
|
||||
let version = r.u32()?;
|
||||
r.take(12)?;
|
||||
let skip = header_len(version);
|
||||
let mut recs = vec![];
|
||||
let (mut parts, mut kind, mut cur): (Vec<String>, Option<String>, Vec<Tok>) = (vec![], None, vec![]);
|
||||
while r.i < r.b.len() {
|
||||
let tag = r.u8()?;
|
||||
let tok = match tag {
|
||||
0x02 => Tok::Num(f64::from(i8::from_le_bytes([r.u8()?]))),
|
||||
0x03 => Tok::Num(r.i16()?),
|
||||
0x04 | 0x15 => Tok::Num(f64::from(r.i32()?)),
|
||||
0x05 => Tok::Num(f64::from(f32::from_le_bytes(r.take(4)?.try_into().ok()?))),
|
||||
0x06 | 0x17 => Tok::Num(r.f64()?),
|
||||
0x07 => {
|
||||
let n = usize::from(r.u8()?);
|
||||
Tok::Word(r.text(n)?)
|
||||
}
|
||||
0x08 => {
|
||||
let n = r.u16()?;
|
||||
Tok::Word(r.text(n)?)
|
||||
}
|
||||
0x09 | 0x12 => {
|
||||
let n = usize::try_from(r.u32()?).ok()?;
|
||||
Tok::Word(r.text(n)?)
|
||||
}
|
||||
0x0A => Tok::Sense(true),
|
||||
0x0B => Tok::Sense(false),
|
||||
0x0C => Tok::Ptr(i64::from(r.i32()?)),
|
||||
0x0D | 0x0E => {
|
||||
let n = usize::from(r.u8()?);
|
||||
let name = r.text(n)?;
|
||||
if kind.is_some() {
|
||||
Tok::Word(name)
|
||||
} else {
|
||||
parts.push(name);
|
||||
if tag == 0x0D {
|
||||
let k = parts.join("-");
|
||||
parts.clear();
|
||||
if k.starts_with("End-of-") || k.starts_with("Begin-of-") {
|
||||
break;
|
||||
}
|
||||
kind = Some(k);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
0x0F => Tok::Open,
|
||||
0x10 => Tok::Close,
|
||||
0x11 => {
|
||||
if let Some(k) = kind.take() {
|
||||
let toks = cur.split_off(skip.min(cur.len()));
|
||||
recs.push(Rec { kind: k, toks });
|
||||
}
|
||||
cur.clear();
|
||||
continue;
|
||||
}
|
||||
0x13 | 0x14 => {
|
||||
for _ in 0..3 {
|
||||
cur.push(Tok::Num(r.f64()?));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
0x16 => {
|
||||
for _ in 0..2 {
|
||||
cur.push(Tok::Num(r.f64()?));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
// Values before the first record are the header's.
|
||||
if kind.is_some() {
|
||||
cur.push(tok);
|
||||
}
|
||||
}
|
||||
Some(Model { recs, at: HashMap::new() })
|
||||
}
|
||||
|
||||
/// A body's placement: `p · m · scale + t`.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Xf {
|
||||
m: [P3; 3],
|
||||
scale: f64,
|
||||
t: P3,
|
||||
}
|
||||
|
||||
impl Xf {
|
||||
const IDENTITY: Xf = Xf { m: [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], scale: 1.0, t: [0.0; 3] };
|
||||
|
||||
/// A `transform` record's: nine matrix numbers row by row, the translation, the scale.
|
||||
fn read(r: &Rec) -> Option<Xf> {
|
||||
let n: Vec<f64> = r.toks.iter().map_while(|t| if let Tok::Num(v) = t { Some(*v) } else { None }).collect();
|
||||
if n.iter().any(|v| !v.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let v = |i: usize| n.get(i).copied();
|
||||
let row = |i: usize| Some([v(i)?, v(i + 1)?, v(i + 2)?]);
|
||||
let scale = v(12)?;
|
||||
Some(Xf { m: [row(0)?, row(3)?, row(6)?], t: row(9)?, scale })
|
||||
}
|
||||
|
||||
fn vector(&self, p: P3) -> P3 {
|
||||
let [a, b, c] = self.m;
|
||||
std::array::from_fn(|i| (p[0] * a[i] + p[1] * b[i] + p[2] * c[i]) * self.scale)
|
||||
}
|
||||
|
||||
fn point(&self, p: P3) -> P3 {
|
||||
let v = self.vector(p);
|
||||
std::array::from_fn(|i| v[i] + self.t[i])
|
||||
}
|
||||
}
|
||||
|
||||
/// Seen from above: x and y.
|
||||
fn flat(p: P3) -> Point {
|
||||
Point::new(p[0], p[1])
|
||||
}
|
||||
|
||||
fn sub(a: P3, b: P3) -> P3 {
|
||||
[a[0] - b[0], a[1] - b[1], a[2] - b[2]]
|
||||
}
|
||||
|
||||
fn dot(a: P3, b: P3) -> f64 {
|
||||
a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
|
||||
}
|
||||
|
||||
fn cross(a: P3, b: P3) -> P3 {
|
||||
[a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
|
||||
}
|
||||
|
||||
fn p3(n: &[f64], i: usize) -> Option<P3> {
|
||||
Some([*n.get(i)?, *n.get(i + 1)?, *n.get(i + 2)?])
|
||||
}
|
||||
|
||||
/// Endpoints farther apart than rounding at their coordinate size allows.
|
||||
fn endpoints_apart(a: Point, b: Point) -> bool {
|
||||
a.distance(b) > 1e-6 * (1.0 + a.x.hypot(a.y).max(b.x.hypot(b.y)))
|
||||
}
|
||||
|
||||
/// Every face's loops of every body, as one path (filled even-odd).
|
||||
fn outline(m: &Model) -> Option<Outline> {
|
||||
let mut o = Outline { path: BezPath::new(), approximated: false, broken: false, ambiguous: false };
|
||||
// Records visited at every level together: chains shared between records are walked again
|
||||
// each time.
|
||||
let mut visits = 0usize;
|
||||
let mut spend = |n: usize| {
|
||||
visits = visits.saturating_add(n.max(1));
|
||||
(visits <= MAX_VISITS).then_some(())
|
||||
};
|
||||
for body in m.recs.iter().filter(|r| r.is("body")) {
|
||||
spend(1)?;
|
||||
let xf = if body.ptr(2) == -1 { Xf::IDENTITY } else { Xf::read(m.get_is(body.ptr(2), "transform")?)? };
|
||||
for lump in m.chain(body.ptr(0), "lump", 0, &mut o.broken) {
|
||||
spend(1)?;
|
||||
for shell in m.chain(lump.ptr(1), "shell", 0, &mut o.broken) {
|
||||
spend(1)?;
|
||||
for face in m.chain(shell.ptr(2), "face", 0, &mut o.broken) {
|
||||
spend(1)?;
|
||||
for lp in m.chain(face.ptr(1), "loop", 0, &mut o.broken) {
|
||||
let ring = m.chain(lp.ptr(1), "coedge", 0, &mut o.broken);
|
||||
spend(ring.len())?;
|
||||
let complete = ring.last().is_some_and(|c| c.ptr(0) == lp.ptr(1));
|
||||
o.broken |= !complete;
|
||||
let mut bp = BezPath::new();
|
||||
for c in ring {
|
||||
let edge = m.get_is(c.ptr(3), "edge")?;
|
||||
let (seg, ambiguous) = edge_path(m, edge, c.sense_after(3)?, &xf, &mut o.approximated)?;
|
||||
o.ambiguous |= ambiguous;
|
||||
if let (Some(end), Some(start)) =
|
||||
(bp.elements().last().and_then(|e| e.end_point()), seg.elements().first().and_then(|e| e.end_point()))
|
||||
{
|
||||
o.broken |= endpoints_apart(end, start);
|
||||
}
|
||||
super::entity::append(&mut bp, &seg);
|
||||
if o.path.elements().len().saturating_add(bp.elements().len()) > super::build::MAX_ELEMENTS {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if !bp.elements().is_empty() {
|
||||
if complete
|
||||
&& let (Some(end), Some(start)) =
|
||||
(bp.elements().last().and_then(|e| e.end_point()), bp.elements().first().and_then(|e| e.end_point()))
|
||||
{
|
||||
o.broken |= endpoints_apart(end, start);
|
||||
}
|
||||
// A loop of one curve ending where it starts is split in two: as one
|
||||
// segment, its start and end would become one anchor.
|
||||
if let [seg] = bp.segments().collect::<Vec<_>>()[..]
|
||||
&& !matches!(seg, PathSeg::Line(_))
|
||||
{
|
||||
let (a, b) = seg.subdivide();
|
||||
bp = BezPath::from_path_segments([a, b].into_iter());
|
||||
}
|
||||
bp.close_path();
|
||||
if o.path.elements().len().saturating_add(bp.elements().len()) > super::build::MAX_ELEMENTS {
|
||||
return None;
|
||||
}
|
||||
o.path.extend(bp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let ok = !o.path.elements().is_empty() && curve::bounds(&o.path).is_some();
|
||||
ok.then_some(o)
|
||||
}
|
||||
|
||||
/// A vertex's position.
|
||||
fn vertex(m: &Model, p: i64) -> Option<P3> {
|
||||
let v = m.get_is(p, "vertex")?;
|
||||
let n = m.get_is(v.ptr(1), "point")?.nums();
|
||||
p3(&n, 0).filter(|p| p.iter().all(|c| c.is_finite()))
|
||||
}
|
||||
|
||||
/// The edge as a coedge runs it (`reversed`: from its end vertex to its start), from the first
|
||||
/// point.
|
||||
fn edge_path(m: &Model, edge: &Rec, reversed: bool, xf: &Xf, approximated: &mut bool) -> Option<(BezPath, bool)> {
|
||||
let (sv, ev) = (vertex(m, edge.ptr(0))?, vertex(m, edge.ptr(1))?);
|
||||
let closed = edge.ptr(0) == edge.ptr(1);
|
||||
let (from, to) = if reversed { (ev, sv) } else { (sv, ev) };
|
||||
// Against the curve's own direction?
|
||||
let back = edge.sense_after(3)? != reversed;
|
||||
let drawn = match m.get(edge.ptr(3)) {
|
||||
// Only -1 means the edge has no curve.
|
||||
None => {
|
||||
*approximated |= edge.ptr(3) != -1;
|
||||
None
|
||||
}
|
||||
Some(c) if c.is("straight-curve") => None,
|
||||
Some(c) => {
|
||||
let bp = if c.is("ellipse-curve") {
|
||||
ellipse(c, from, to, closed, back, xf).map(|bp| (bp, false))
|
||||
} else if c.is("intcurve-curve") {
|
||||
spline(c, from, to, closed, back, xf)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
*approximated |= bp.is_none();
|
||||
bp
|
||||
}
|
||||
};
|
||||
if let Some(bp) = drawn {
|
||||
return Some(bp);
|
||||
}
|
||||
let mut bp = BezPath::new();
|
||||
bp.move_to(flat(xf.point(from)));
|
||||
bp.line_to(flat(xf.point(to)));
|
||||
Some((bp, false))
|
||||
}
|
||||
|
||||
/// An `ellipse-curve` (centre, normal, major axis, ratio) from `from` to `to`; the whole curve
|
||||
/// when the edge starts and ends at one vertex. It runs counter-clockwise about its normal,
|
||||
/// clockwise when `back`.
|
||||
fn ellipse(c: &Rec, from: P3, to: P3, closed: bool, back: bool, xf: &Xf) -> Option<BezPath> {
|
||||
let n = c.nums();
|
||||
let (centre, normal, major, ratio) = (p3(&n, 0)?, p3(&n, 3)?, p3(&n, 6)?, *n.get(9)?);
|
||||
let len = dot(normal, normal).sqrt();
|
||||
if !(len > 1e-12 && ratio > 0.0 && ratio.is_finite() && dot(major, major) > 1e-24) {
|
||||
return None;
|
||||
}
|
||||
let minor = cross(normal, major).map(|v| v / len * ratio);
|
||||
let angle = |p: P3| {
|
||||
let d = sub(p, centre);
|
||||
(dot(d, minor) / dot(minor, minor)).atan2(dot(d, major) / dot(major, major))
|
||||
};
|
||||
let (a, b) = (angle(from), angle(to));
|
||||
let tau = std::f64::consts::TAU;
|
||||
let sweep = match (closed, back) {
|
||||
(true, false) => tau,
|
||||
(true, true) => -tau,
|
||||
(false, false) => (b - a).rem_euclid(tau),
|
||||
(false, true) => -(a - b).rem_euclid(tau),
|
||||
};
|
||||
let (o, u, v) = (flat(xf.point(centre)), flat(xf.vector(major)), flat(xf.vector(minor)));
|
||||
curve::ellipse(Affine::new([u.x, u.y, v.x, v.y, o.x, o.y]), a, sweep)
|
||||
}
|
||||
|
||||
/// An `intcurve-curve`'s B-spline (`nubs`, or `nurbs` with weights): degree, form, the knots
|
||||
/// with their multiplicities (without the end knots, or with them), the control points.
|
||||
fn bspline(toks: &[Tok]) -> Option<Spline> {
|
||||
let at = toks.iter().position(|t| matches!(t, Tok::Word(w) if matches!(w.as_str(), "nubs" | "nurbs" | "nullbs")))?;
|
||||
let rational = match &toks[at] {
|
||||
Tok::Word(w) if w == "nurbs" => true,
|
||||
Tok::Word(w) if w == "nubs" => false,
|
||||
_ => return None,
|
||||
};
|
||||
let num = |i: usize| if let Some(Tok::Num(v)) = toks.get(i) { Some(*v) } else { None };
|
||||
let degree = num(at + 1).filter(|d| (1.0..=32.0).contains(d))? as usize;
|
||||
let count = num(at + 3).filter(|n| *n >= 1.0 && *n <= toks.len() as f64)? as usize;
|
||||
let mut knots = vec![];
|
||||
let mut i = at + 4;
|
||||
for _ in 0..count {
|
||||
let (k, mult) = (num(i)?, num(i + 1)?);
|
||||
if !(mult >= 1.0 && mult <= (degree + 1) as f64) {
|
||||
return None;
|
||||
}
|
||||
knots.extend(std::iter::repeat_n(k, mult as usize));
|
||||
i += 2;
|
||||
}
|
||||
let stride = if rational { 4 } else { 3 };
|
||||
let values: Vec<f64> = toks[i.min(toks.len())..].iter().map_while(|t| if let Tok::Num(v) = t { Some(*v) } else { None }).collect();
|
||||
let available = values.len() / stride;
|
||||
// The data leaves out the first and last knots; data that keeps them has two points fewer.
|
||||
let short = (knots.len() + 1).checked_sub(degree)?;
|
||||
let n = if available >= short {
|
||||
let (first, last) = (*knots.first()?, *knots.last()?);
|
||||
knots.insert(0, first);
|
||||
knots.push(last);
|
||||
short
|
||||
} else {
|
||||
knots.len().checked_sub(degree + 1)?
|
||||
};
|
||||
if n == 0 || n > available {
|
||||
return None;
|
||||
}
|
||||
let pts = values.chunks(stride).take(n).map(|c| [c[0], c[1], c[2]]).collect();
|
||||
let weights = rational.then(|| values.chunks(stride).take(n).map(|c| c[3]).collect());
|
||||
Some((degree, knots, pts, weights))
|
||||
}
|
||||
|
||||
/// The distinct parameters of a cubic's self-intersection, when both lie on the curve.
|
||||
fn cubic_crossing(cubic: kurbo::CubicBez) -> Option<(f64, f64)> {
|
||||
let b = (cubic.p1 - cubic.p0) * 3.0;
|
||||
let c = (cubic.p2 - cubic.p1) * 3.0 - b;
|
||||
let d = (cubic.p3 - cubic.p0) - b - c;
|
||||
let det = c.cross(d);
|
||||
if det == 0.0 {
|
||||
return None;
|
||||
}
|
||||
// Dividing P(s) - P(t) by s - t gives b + c*u + d*(u*u - v) = 0,
|
||||
// where u = s + t and v = s*t.
|
||||
let u = -b.cross(d) / det;
|
||||
let v = u * u - b.cross(c) / det;
|
||||
let discriminant = u * u - 4.0 * v;
|
||||
if !discriminant.is_finite() || discriminant <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
let root = discriminant.sqrt();
|
||||
let (s, t) = ((u - root) * 0.5, (u + root) * 0.5);
|
||||
(0.0 <= s && s < t && t <= 1.0).then_some((s, t))
|
||||
}
|
||||
|
||||
/// An `intcurve-curve` from `from` to `to` (the part of its spline between them), the whole
|
||||
/// ring when the edge starts and ends at one vertex; also whether trimming is ambiguous.
|
||||
fn spline(c: &Rec, from: P3, to: P3, closed: bool, back: bool, xf: &Xf) -> Option<(BezPath, bool)> {
|
||||
// The curve's own sense comes before its data.
|
||||
let open = c.toks.iter().position(|t| *t == Tok::Open)?;
|
||||
let curve_back = c.toks[..open].contains(&Tok::Sense(true));
|
||||
let (degree, knots, pts, weights) = bspline(&c.toks[open..])?;
|
||||
let ctrl: Vec<Point> = pts.into_iter().map(|p| flat(xf.point(p))).collect();
|
||||
let full = curve::nurbs(degree, &knots, &ctrl, weights.as_deref())?;
|
||||
let back = back != curve_back;
|
||||
let segs: Vec<PathSeg> = full.segments().collect();
|
||||
let (first, last) = (segs.first()?.start(), segs.last()?.end());
|
||||
let ring = first.distance(last) <= 1e-9 * (1.0 + first.to_vec2().hypot());
|
||||
let mut lengths = vec![0.0];
|
||||
for s in &segs {
|
||||
lengths.push(lengths.last()? + s.arclen(1e-9));
|
||||
}
|
||||
let total = *lengths.last()?;
|
||||
let at = |p: P3| {
|
||||
let p = flat(xf.point(p));
|
||||
let near: Vec<_> = segs.iter().enumerate().map(|(i, s)| (s.nearest(p, 1e-9), i)).collect();
|
||||
let (n, i) = near.iter().min_by(|a, b| a.0.distance_sq.total_cmp(&b.0.distance_sq))?;
|
||||
let along = |i: usize, t: f64| lengths[i] + segs[i].subsegment(0.0..t).arclen(1e-9);
|
||||
let tolerance = 1e-6 * (1.0 + p.x.hypot(p.y));
|
||||
let mut locations: Vec<_> =
|
||||
near.iter().filter(|(n, i)| !endpoints_apart(p, segs[*i].eval(n.t))).map(|(n, i)| (*i as f64 + n.t, along(*i, n.t))).collect();
|
||||
for (i, s) in segs.iter().enumerate() {
|
||||
if let PathSeg::Cubic(cubic) = s
|
||||
&& let Some((a, b)) = cubic_crossing(*cubic)
|
||||
&& !endpoints_apart(p, cubic.eval(a))
|
||||
{
|
||||
locations.extend([a, b].map(|t| (i as f64 + t, along(i, t))));
|
||||
}
|
||||
}
|
||||
// Nearby ends at a segment joint, or at a closed curve's seam, are one location.
|
||||
locations.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
locations.dedup_by(|a, b| (a.1 - b.1).abs() <= 4.0 * tolerance);
|
||||
if ring && locations.len() > 1 && (total - (locations.last()?.1 - locations.first()?.1)).abs() <= 4.0 * tolerance {
|
||||
locations.pop();
|
||||
}
|
||||
Some((*i as f64 + n.t, locations))
|
||||
};
|
||||
let mut ambiguous = false;
|
||||
let part = if closed && ring {
|
||||
let (_, locations) = at(from)?;
|
||||
ambiguous = locations.len() > 1;
|
||||
full
|
||||
} else {
|
||||
let bounds = if closed {
|
||||
let (_, locations) = at(from)?;
|
||||
if let [a, b] = locations.as_slice() {
|
||||
Some((a.0, b.0))
|
||||
} else {
|
||||
ambiguous = true;
|
||||
None
|
||||
}
|
||||
} else {
|
||||
let ((ga, a), (gb, b)) = (at(from)?, at(to)?);
|
||||
ambiguous = a.len() > 1 || b.len() > 1;
|
||||
Some((ga, gb))
|
||||
};
|
||||
if let Some((ga, gb)) = bounds {
|
||||
let (lo, hi) = if back { (gb, ga) } else { (ga, gb) };
|
||||
let pieces = if lo <= hi || !ring {
|
||||
piece(&segs, lo.min(hi), hi.max(lo))
|
||||
} else {
|
||||
[piece(&segs, lo, segs.len() as f64), piece(&segs, 0.0, hi)].concat()
|
||||
};
|
||||
if pieces.is_empty() {
|
||||
return None;
|
||||
}
|
||||
BezPath::from_path_segments(pieces.into_iter())
|
||||
} else {
|
||||
full
|
||||
}
|
||||
};
|
||||
Some((if back { part.reverse_subpaths() } else { part }, ambiguous))
|
||||
}
|
||||
|
||||
/// The parts of `segs` from `lo` to `hi`, counted in segments (2.5: halfway along the third).
|
||||
fn piece(segs: &[PathSeg], lo: f64, hi: f64) -> Vec<PathSeg> {
|
||||
let mut out = vec![];
|
||||
for (i, s) in segs.iter().enumerate() {
|
||||
let (t0, t1) = ((lo - i as f64).max(0.0), (hi - i as f64).min(1.0));
|
||||
if t1 > t0 {
|
||||
out.push(s.subsegment(t0..t1));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cubic_crossings_have_two_distinct_parameters() {
|
||||
let cubic = kurbo::CubicBez::new((36.0, -18.0), (-28.0, 26.0), (-28.0, -26.0), (36.0, 18.0));
|
||||
let (s, t) = cubic_crossing(cubic).unwrap();
|
||||
assert!((s - 0.25).abs() < 1e-12 && (t - 0.75).abs() < 1e-12, "{s}, {t}");
|
||||
let plain = kurbo::CubicBez::new((0.0, 0.0), (30.0, 50.0), (70.0, -50.0), (100.0, 0.0));
|
||||
assert!(cubic_crossing(plain).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deciphering_maps_each_character_back_and_drops_the_caret_space() {
|
||||
// "Ab@_ 7#" ciphered: A→^ (and a space), b→=, @→_, _→@, 7→h, #→|.
|
||||
assert_eq!(decipher("^ =_@ h|"), "Ab@_ 7#");
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ const MAX_NODES: usize = 2_000_000;
|
||||
/// per item of the block looked at for it (art on hidden layers too).
|
||||
const MAX_VISITS: usize = if cfg!(test) { 1_000_000 } else { 20_000_000 };
|
||||
/// The most path elements an import makes (blocks drawn as art are copied for every placement).
|
||||
const MAX_ELEMENTS: usize = if cfg!(test) { 1_000_000 } else { 4_000_000 };
|
||||
pub(crate) const MAX_ELEMENTS: usize = if cfg!(test) { 1_000_000 } else { 4_000_000 };
|
||||
/// The most dash lengths an import keeps (every dashed path holds its own copy of its pattern).
|
||||
const MAX_DASH_VALUES: usize = if cfg!(test) { 1_000 } else { 4_000_000 };
|
||||
/// The most bytes of text, font names and symbol names an import copies into objects (a block's
|
||||
@@ -128,7 +128,7 @@ impl<'d, 'a> Build<'d, 'a> {
|
||||
Self {
|
||||
d,
|
||||
o,
|
||||
conv: Converter::default(),
|
||||
conv: Converter::new(d.regions.clone()),
|
||||
doc: Document::new(1.0, 1.0),
|
||||
blocks: HashMap::new(),
|
||||
bounds: HashMap::new(),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Entities to drawing items: their geometry in world coordinates (drawing units, y up) and the
|
||||
//! properties they take from their layer or block (resolved when the items become art).
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::rc::Rc;
|
||||
|
||||
use kurbo::{BezPath, PathEl};
|
||||
use vectorcraft_doc::Justify;
|
||||
@@ -9,6 +10,7 @@ use vectorcraft_geom::{Affine, Point, Vec2};
|
||||
|
||||
use craft_dxf::model::{self, EntityRecord, Groups, HatchEdge, HatchPath};
|
||||
|
||||
use super::acis;
|
||||
use super::curve::{self, Vertex};
|
||||
use super::reader::{aci_paper, point};
|
||||
|
||||
@@ -174,6 +176,8 @@ pub(crate) struct Converter {
|
||||
pub warnings: Vec<String>,
|
||||
/// Array insert copies made so far, against [`MAX_TOTAL_CELLS`].
|
||||
cells: i64,
|
||||
/// The binary solid-modeler data of regions, by handle (DXF 2013 and later).
|
||||
regions: Rc<HashMap<u64, Vec<u8>>>,
|
||||
}
|
||||
|
||||
const PATTERN_HATCH: &str = "pattern hatches come in as their boundaries";
|
||||
@@ -182,8 +186,16 @@ const MESH_VERTICES: &str = "polygon meshes and polyface mesh faces whose vertic
|
||||
const BIG_ARRAY: &str = "array inserts are limited to 10,000 copies each";
|
||||
const MANY_ARRAYS: &str = "array inserts are limited to 2,000,000 copies in all";
|
||||
const FAR_AWAY: &str = "entities with coordinates out of range are left out";
|
||||
const REGION_CURVES: &str = "region edges of some curve types come in as straight lines";
|
||||
const REGION_BROKEN: &str = "regions whose outlines break off are closed with straight lines";
|
||||
const REGION_AMBIGUOUS: &str = "region edges on curves that cross themselves may come in along the wrong part of the curve";
|
||||
|
||||
impl Converter {
|
||||
/// A converter reading regions' binary data from `regions`.
|
||||
pub fn new(regions: Rc<HashMap<u64, Vec<u8>>>) -> Self {
|
||||
Self { regions, ..Self::default() }
|
||||
}
|
||||
|
||||
fn warn(&mut self, w: &str) {
|
||||
if !self.warnings.iter().any(|x| x == w) {
|
||||
self.warnings.push(w.to_string());
|
||||
@@ -255,6 +267,7 @@ impl Converter {
|
||||
model::EntityKind::Dimension(d) => {
|
||||
Some(Geom::Insert(InsertItem { block: d.block.as_ref()?.to_uppercase(), cells: vec![Affine::IDENTITY], attribs: vec![] }))
|
||||
}
|
||||
_ if e.kind == "REGION" => self.region(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -378,6 +391,41 @@ impl Converter {
|
||||
out
|
||||
}
|
||||
|
||||
/// A region as a filled path: its solid-modeler data as text in groups 1 (a line each) and 3
|
||||
/// (the rest of a long line), or, from DXF 2013 on, binary data kept by handle.
|
||||
fn region(&mut self, e: &EntityRecord<'_>) -> Option<Geom> {
|
||||
let g = e.groups();
|
||||
let own = g.subclass("AcDbModelerGeometry");
|
||||
let tags = if own.0.is_empty() { g.0 } else { own.0 };
|
||||
let mut text = String::new();
|
||||
for t in tags {
|
||||
match t.code {
|
||||
1 => {
|
||||
if !text.is_empty() {
|
||||
text.push('\n');
|
||||
}
|
||||
text.push_str(t.str_ref().unwrap_or_default());
|
||||
}
|
||||
3 => text.push_str(t.str_ref().unwrap_or_default()),
|
||||
_ => {}
|
||||
}
|
||||
if text.len() > acis::MAX_BYTES {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
let outline = if text.trim().is_empty() { acis::from_binary(self.regions.get(&e.record().handle()?)?) } else { acis::from_text(&text) }?;
|
||||
if outline.approximated {
|
||||
self.warn(REGION_CURVES);
|
||||
}
|
||||
if outline.broken {
|
||||
self.warn(REGION_BROKEN);
|
||||
}
|
||||
if outline.ambiguous {
|
||||
self.warn(REGION_AMBIGUOUS);
|
||||
}
|
||||
Some(Geom::Path { bp: outline.path, fill: true, width: 0.0 })
|
||||
}
|
||||
|
||||
fn hatch(&mut self, h: &model::Hatch, ocs: Affine) -> Option<Geom> {
|
||||
let mut bp = BezPath::new();
|
||||
for l in &h.loops {
|
||||
@@ -601,7 +649,7 @@ fn boundary(path: &HatchPath) -> Option<BezPath> {
|
||||
}
|
||||
|
||||
/// `seg` continuing `bp`: joined by a line when it starts elsewhere.
|
||||
fn append(bp: &mut BezPath, seg: &BezPath) {
|
||||
pub(super) fn append(bp: &mut BezPath, seg: &BezPath) {
|
||||
for el in seg.elements() {
|
||||
match *el {
|
||||
PathEl::MoveTo(p) => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! What the import uses of a drawing, from `craft_dxf::model`: header variables; the layer,
|
||||
//! linetype and text style tables; the blocks; the entities; the layouts.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft_dxf::model::{self, EntityRecord};
|
||||
use vectorcraft_geom::Point;
|
||||
@@ -81,6 +82,9 @@ pub(crate) struct Drawing<'a> {
|
||||
pub layouts: Vec<LayoutDef>,
|
||||
/// How many sections the file has (none: not a drawing).
|
||||
pub sections: usize,
|
||||
/// The binary solid-modeler data of the regions, by handle (DXF 2013 and later keep it in
|
||||
/// the ACDSDATA section).
|
||||
pub regions: Rc<HashMap<u64, Vec<u8>>>,
|
||||
}
|
||||
|
||||
/// The colour of index `i` on paper: index 7 (white on a CAD screen) is black.
|
||||
@@ -112,6 +116,7 @@ impl<'a> Drawing<'a> {
|
||||
}
|
||||
let block_names = doc.block_names();
|
||||
d.layouts = layouts(&doc, &block_names);
|
||||
d.regions = Rc::new(region_data(&doc));
|
||||
for b in doc.blocks {
|
||||
if b.name.is_empty() {
|
||||
continue;
|
||||
@@ -148,6 +153,69 @@ impl<'a> Drawing<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The binary data of each region in the ACDSDATA section: an `ACDSRECORD` names its entity's
|
||||
/// handle (320), then holds the bytes (310 chunks) after `2 ASM_Data`, their count in 94.
|
||||
fn region_data(doc: &model::Document<'_>) -> HashMap<u64, Vec<u8>> {
|
||||
let records = doc.entities.iter().chain(doc.blocks.iter().flat_map(|b| &b.entities));
|
||||
let wanted: HashSet<u64> = records.filter(|e| e.kind == "REGION").filter_map(|e| e.record().handle()).collect();
|
||||
let mut out = HashMap::new();
|
||||
if wanted.is_empty() {
|
||||
return out;
|
||||
}
|
||||
for section in doc.other_sections.iter().filter(|s| s.name.eq_ignore_ascii_case("ACDSDATA")) {
|
||||
for r in model::records(section.tags).into_iter().filter(|r| r.kind == "ACDSRECORD") {
|
||||
let Some(handle) = r.tags.iter().find(|t| t.code == 320).and_then(|t| model::parse_handle(&t.str())) else { continue };
|
||||
if !wanted.contains(&handle) || out.contains_key(&handle) {
|
||||
continue;
|
||||
}
|
||||
let Some(at) = r.tags.iter().position(|t| t.code == 2 && t.str_ref().is_some_and(|s| s.trim() == "ASM_Data")) else { continue };
|
||||
let data = r.tags.get(at + 1..).unwrap_or_default();
|
||||
let size = data.iter().find(|t| t.code == 94).and_then(|t| usize::try_from(t.i64()).ok());
|
||||
let mut bytes = Vec::new();
|
||||
let mut whole = true;
|
||||
for t in data.iter().filter(|t| t.code == 310) {
|
||||
whole = hex_bytes(t.str_ref().unwrap_or_default().trim(), &mut bytes);
|
||||
if !whole || bytes.len() > super::acis::MAX_BYTES {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !whole {
|
||||
continue;
|
||||
}
|
||||
if let Some(bytes) = sized_region(bytes, size, super::acis::MAX_BYTES) {
|
||||
out.insert(handle, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A region's `bytes` cut to its declared `size`, or `None` when the record declares more bytes
|
||||
/// than it holds (the data was cut short or damaged) or the data is longer than `limit`.
|
||||
pub(super) fn sized_region(mut bytes: Vec<u8>, size: Option<usize>, limit: usize) -> Option<Vec<u8>> {
|
||||
match size {
|
||||
Some(n) if n <= bytes.len() => bytes.truncate(n),
|
||||
Some(_) => return None,
|
||||
None => {}
|
||||
}
|
||||
(bytes.len() <= limit).then_some(bytes)
|
||||
}
|
||||
|
||||
/// Hex digits' bytes, two digits each, onto `out`. False when `hex` has a character that is not
|
||||
/// a hex digit or an odd number of digits.
|
||||
pub(super) fn hex_bytes(hex: &str, out: &mut Vec<u8>) -> bool {
|
||||
let digit = |c: u8| (c as char).to_digit(16).and_then(|d| u8::try_from(d).ok());
|
||||
let (pairs, rest) = hex.as_bytes().as_chunks::<2>();
|
||||
if !rest.is_empty() {
|
||||
return false;
|
||||
}
|
||||
for pair in pairs {
|
||||
let (Some(hi), Some(lo)) = (digit(pair[0]), digit(pair[1])) else { return false };
|
||||
out.push(hi << 4 | lo);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn point(p: model::Point) -> Point {
|
||||
Point::new(p[0], p[1])
|
||||
}
|
||||
|
||||
@@ -0,0 +1,686 @@
|
||||
//! Regions: solid-modeler data in text (ciphered or not, lines split over groups 1 and 3) and in
|
||||
//! binary form (the ACDSDATA section) comes in as one filled path of the region's loops; lines,
|
||||
//! circles, ellipses and spline edges keep their shape, coedge and edge senses are followed, a
|
||||
//! body's transform is applied, and damaged data is left out without hanging.
|
||||
|
||||
use kurbo::{BezPath, Shape};
|
||||
use vectorcraft_doc::{Document, Node, NodeKind, Unit};
|
||||
use vectorcraft_geom::{FillRule, Point, Rect};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A curve an edge runs along.
|
||||
#[derive(Clone)]
|
||||
enum Curve {
|
||||
Line,
|
||||
/// A circle about the z axis (`-z`: clockwise) of this centre and radius.
|
||||
Circle {
|
||||
c: [f64; 2],
|
||||
r: f64,
|
||||
down: bool,
|
||||
},
|
||||
/// A curve record's text after its first three values.
|
||||
Raw(String),
|
||||
}
|
||||
|
||||
/// An edge of a loop, from `a` to `b` as the loop runs it. `flip`: the edge is stored from `b`
|
||||
/// to `a` and the coedge runs it reversed; `against`: the edge also runs against its curve.
|
||||
#[derive(Clone)]
|
||||
struct E {
|
||||
a: [f64; 2],
|
||||
b: [f64; 2],
|
||||
curve: Curve,
|
||||
flip: bool,
|
||||
against: bool,
|
||||
}
|
||||
|
||||
fn line(a: [f64; 2], b: [f64; 2]) -> E {
|
||||
E { a, b, curve: Curve::Line, flip: false, against: false }
|
||||
}
|
||||
|
||||
fn circle(c: [f64; 2], r: f64, down: bool) -> E {
|
||||
let p = [c[0] + r, c[1]];
|
||||
E { a: p, b: p, curve: Curve::Circle { c, r, down }, flip: false, against: false }
|
||||
}
|
||||
|
||||
fn square(lo: f64, hi: f64) -> Vec<E> {
|
||||
vec![line([lo, lo], [hi, lo]), line([hi, lo], [hi, hi]), line([hi, hi], [lo, hi]), line([lo, hi], [lo, lo])]
|
||||
}
|
||||
|
||||
/// Text data (version 700) of one face with `loops`, placed by `transform` (12 numbers and a
|
||||
/// scale) when given.
|
||||
fn sat(loops: &[Vec<E>], transform: Option<&str>) -> String {
|
||||
let mut recs: Vec<String> = vec![];
|
||||
let xf = if transform.is_some() { "$5" } else { "$-1" };
|
||||
recs.push(format!("body $-1 -1 $-1 $1 $-1 {xf}"));
|
||||
recs.push("lump $-1 -1 $-1 $-1 $2 $0".into());
|
||||
recs.push("shell $-1 -1 $-1 $-1 $-1 $3 $-1 $1".into());
|
||||
recs.push("face $-1 -1 $-1 $-1 $6 $2 $-1 $4 forward single".into());
|
||||
recs.push("plane-surface $-1 -1 $-1 0 0 0 0 0 1 1 0 0 forward_v I I I I".into());
|
||||
recs.push(format!("transform $-1 -1 $-1 {} no_rotate no_reflect no_shear", transform.unwrap_or("1 0 0 0 1 0 0 0 1 0 0 0 1")));
|
||||
let mut base = 6;
|
||||
for (l, edges) in loops.iter().enumerate() {
|
||||
let next_loop = if l + 1 < loops.len() { format!("${}", base + 1 + 7 * edges.len()) } else { "$-1".into() };
|
||||
recs.push(format!("loop $-1 -1 $-1 {next_loop} ${} $3", base + 1));
|
||||
let n = edges.len();
|
||||
for (j, e) in edges.iter().enumerate() {
|
||||
let at = |k: usize| base + 1 + 7 * k;
|
||||
let i = at(j);
|
||||
let (coedge, edge, sv, ev, sp, ep, cv) = (i, i + 1, i + 2, i + 3, i + 4, i + 5, i + 6);
|
||||
let (start, end) = if e.flip { (e.b, e.a) } else { (e.a, e.b) };
|
||||
let ev = if start == end { sv } else { ev };
|
||||
let sense = |r: bool| if r { "reversed" } else { "forward" };
|
||||
recs.push(format!("coedge $-1 -1 $-1 ${} ${} $-1 ${edge} {} ${base} $-1", at((j + 1) % n), at((j + n - 1) % n), sense(e.flip)));
|
||||
recs.push(format!("edge $-1 -1 $-1 ${sv} 0 ${ev} 1 ${coedge} ${cv} {} @7 unknown", sense(e.against)));
|
||||
recs.push(format!("vertex $-1 -1 $-1 ${edge} ${sp}"));
|
||||
recs.push(format!("vertex $-1 -1 $-1 ${edge} ${ep}"));
|
||||
recs.push(format!("point $-1 -1 $-1 {} {} 0", start[0], start[1]));
|
||||
recs.push(format!("point $-1 -1 $-1 {} {} 0", end[0], end[1]));
|
||||
recs.push(match &e.curve {
|
||||
Curve::Line => format!("straight-curve $-1 -1 $-1 {} {} 0 {} {} 0 I I", start[0], start[1], end[0] - start[0], end[1] - start[1]),
|
||||
Curve::Circle { c, r, down } => {
|
||||
format!("ellipse-curve $-1 -1 $-1 {} {} 0 0 0 {} {r} 0 0 1 I I", c[0], c[1], if *down { -1 } else { 1 })
|
||||
}
|
||||
Curve::Raw(s) => s.clone(),
|
||||
});
|
||||
}
|
||||
base += 1 + 7 * n;
|
||||
}
|
||||
let mut s = String::from("700 0 1 0\n9 Synthetic 3 ASM 4 none\n1 9.9999999999999995e-07 1e-10\n");
|
||||
for r in recs {
|
||||
s.push_str(&r);
|
||||
s.push_str(" #\n");
|
||||
}
|
||||
s.push_str("End-of-ACIS-data\n");
|
||||
s
|
||||
}
|
||||
|
||||
/// DXF's cipher of text data: each printable character mapped, a space after each caret.
|
||||
fn encipher(s: &str) -> String {
|
||||
let mut out = String::new();
|
||||
for c in s.chars() {
|
||||
let m = match c {
|
||||
' ' | '\n' => c,
|
||||
'@'..='_' => char::from(159 - c as u8),
|
||||
c => char::from(c as u8 ^ 0x5F),
|
||||
};
|
||||
out.push(m);
|
||||
if m == '^' {
|
||||
out.push(' ');
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// A drawing of `version` with `entities` and, when given, an ACDSDATA section.
|
||||
fn drawing(version: &str, entities: &[(i32, String)], acds: &[(i32, String)]) -> Vec<u8> {
|
||||
let mut s = format!(" 0\nSECTION\n 2\nHEADER\n 9\n$ACADVER\n 1\n{version}\n 0\nENDSEC\n 0\nSECTION\n 2\nENTITIES\n");
|
||||
let put = |pairs: &[(i32, String)], s: &mut String| {
|
||||
for (c, v) in pairs {
|
||||
s.push_str(&format!("{c:>3}\n{v}\n"));
|
||||
}
|
||||
};
|
||||
put(entities, &mut s);
|
||||
s.push_str(" 0\nENDSEC\n");
|
||||
if !acds.is_empty() {
|
||||
s.push_str(" 0\nSECTION\n 2\nACDSDATA\n");
|
||||
put(acds, &mut s);
|
||||
s.push_str(" 0\nENDSEC\n");
|
||||
}
|
||||
s.push_str(" 0\nEOF\n");
|
||||
s.into_bytes()
|
||||
}
|
||||
|
||||
/// A REGION entity holding `lines` of text data (`split`: each line over 40 characters goes on
|
||||
/// in group 3 from inside a word).
|
||||
fn region_text(lines: &str, split: bool) -> Vec<(i32, String)> {
|
||||
let mut e = vec![
|
||||
(0, "REGION".to_string()),
|
||||
(5, "2A".into()),
|
||||
(8, "0".into()),
|
||||
(100, "AcDbEntity".into()),
|
||||
(100, "AcDbModelerGeometry".into()),
|
||||
(70, "1".into()),
|
||||
];
|
||||
for l in lines.lines() {
|
||||
let b = l.as_bytes();
|
||||
let cut = (40..b.len()).find(|&i| !b[i - 1].is_ascii_whitespace() && !b[i].is_ascii_whitespace());
|
||||
if let Some(at) = cut.filter(|_| split) {
|
||||
e.push((1, l[..at].to_string()));
|
||||
e.push((3, l[at..].to_string()));
|
||||
} else {
|
||||
e.push((1, l.to_string()));
|
||||
}
|
||||
}
|
||||
e
|
||||
}
|
||||
|
||||
fn points() -> ImportOptions {
|
||||
ImportOptions { unit: Some(Unit::Points), scale: Some(1.0), center: false, ..ImportOptions::default() }
|
||||
}
|
||||
|
||||
/// Every leaf path of the document as one path, in document coordinates.
|
||||
fn outline(doc: &Document) -> BezPath {
|
||||
let mut bp = BezPath::new();
|
||||
doc.walk(|n: &Node| {
|
||||
if let NodeKind::Path { path, .. } = &n.kind {
|
||||
bp.extend(path.to_bezpath());
|
||||
}
|
||||
});
|
||||
bp
|
||||
}
|
||||
|
||||
/// Inside the path by the even-odd rule.
|
||||
fn filled(bp: &BezPath, p: Point) -> bool {
|
||||
bp.winding(p) % 2 != 0
|
||||
}
|
||||
|
||||
/// The region (drawing `x, y`) is filled at `inside` and not at `outside`.
|
||||
fn check(doc: &Document, inside: &[[f64; 2]], outside: &[[f64; 2]]) {
|
||||
let h = doc.artboards[0].rect.height();
|
||||
let (bp, at) = (outline(doc), |p: &[f64; 2]| Point::new(p[0], h - p[1]));
|
||||
for p in inside {
|
||||
assert!(filled(&bp, at(p)), "{p:?} should be filled");
|
||||
}
|
||||
for p in outside {
|
||||
assert!(!filled(&bp, at(p)), "{p:?} should be empty");
|
||||
}
|
||||
}
|
||||
|
||||
/// The only top-level object: filled, without a stroke.
|
||||
fn filled_object(doc: &Document) -> Node {
|
||||
let [n] = &doc.layers[0].children().unwrap()[..] else { panic!("{:?}", doc.layers[0].children()) };
|
||||
assert!(n.appearance.fill().is_some_and(|f| !f.paint.is_none()), "regions are filled");
|
||||
assert!(n.appearance.stroke().is_none_or(|s| s.paint.is_none()), "regions have no stroke");
|
||||
n.as_ref().clone()
|
||||
}
|
||||
|
||||
fn square_with_hole() -> Vec<Vec<E>> {
|
||||
vec![square(0.0, 100.0), vec![circle([50.0, 50.0], 20.0, true)]]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ciphered_text_data_comes_in_as_a_filled_path_with_its_hole() {
|
||||
let text = encipher(&sat(&square_with_hole(), None));
|
||||
let r = import(&drawing("AC1015", ®ion_text(&text, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
let n = filled_object(&r.document);
|
||||
let NodeKind::Compound { rule, .. } = &n.kind else { panic!("{:?}", n.kind) };
|
||||
assert_eq!(*rule, FillRule::EvenOdd);
|
||||
assert!((n.geometric_bounds().unwrap().area() - 10_000.0).abs() < 1e-6);
|
||||
check(&r.document, &[[10.0, 10.0], [50.0, 75.0], [90.0, 50.0]], &[[50.0, 50.0], [60.0, 55.0], [110.0, 50.0]]);
|
||||
// The hole is a circle.
|
||||
let h = r.document.artboards[0].rect.height();
|
||||
let bp = outline(&r.document);
|
||||
let centre = Point::new(50.0, h - 50.0);
|
||||
let on_hole: Vec<f64> = bp.segments().map(|s| kurbo::ParamCurve::eval(&s, 0.5).distance(centre)).filter(|d| *d < 30.0).collect();
|
||||
assert!(!on_hole.is_empty() && on_hole.iter().all(|d| (d - 20.0).abs() < 1e-3), "{on_hole:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_text_split_over_groups_one_and_three_reads_alike() {
|
||||
let text = sat(&square_with_hole(), None);
|
||||
let r = import(&drawing("AC1021", ®ion_text(&text, true), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
filled_object(&r.document);
|
||||
check(&r.document, &[[10.0, 10.0]], &[[50.0, 50.0]]);
|
||||
// Before version 700 a record starts with its attribute alone.
|
||||
let old: String = text.replacen("700 0 1 0", "400 0 1 0", 1).lines().map(|l| format!("{}\n", l.replacen(" $-1 -1 $-1 ", " $-1 ", 1))).collect();
|
||||
assert!(old.contains("body $-1 $1 $-1 $-1 #"), "{old}");
|
||||
let r = import(&drawing("AC1012", ®ion_text(&old, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
check(&r.document, &[[10.0, 10.0]], &[[50.0, 50.0]]);
|
||||
}
|
||||
|
||||
/// Binary data of the same records: tagged values, type names in parts.
|
||||
fn sab(text: &str) -> Vec<u8> {
|
||||
let mut b = b"ACIS BinaryFile".to_vec();
|
||||
for v in [700u32, 0, 1, 0] {
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
let string = |b: &mut Vec<u8>, tag: u8, s: &str| {
|
||||
b.push(tag);
|
||||
b.push(u8::try_from(s.len()).unwrap());
|
||||
b.extend(s.as_bytes());
|
||||
};
|
||||
string(&mut b, 0x07, "Synthetic");
|
||||
b.push(0x06);
|
||||
b.extend(1.0f64.to_le_bytes());
|
||||
for line in text.lines().skip(3) {
|
||||
if line.starts_with("End-of") {
|
||||
break;
|
||||
}
|
||||
let mut words = line.split_whitespace().peekable();
|
||||
let kind = words.next().unwrap();
|
||||
let parts: Vec<&str> = kind.split('-').collect();
|
||||
for (i, p) in parts.iter().enumerate() {
|
||||
string(&mut b, if i + 1 == parts.len() { 0x0D } else { 0x0E }, p);
|
||||
}
|
||||
while let Some(w) = words.next() {
|
||||
match w {
|
||||
"#" => {}
|
||||
"forward" | "forward_v" => b.push(0x0B),
|
||||
"reversed" | "reversed_v" => b.push(0x0A),
|
||||
"{" => b.push(0x0F),
|
||||
"}" => b.push(0x10),
|
||||
w if w.starts_with('$') => {
|
||||
b.push(0x0C);
|
||||
b.extend(w[1..].parse::<i32>().unwrap().to_le_bytes());
|
||||
}
|
||||
w if w.starts_with('@') => {
|
||||
let s = words.next().unwrap();
|
||||
string(&mut b, 0x07, s);
|
||||
}
|
||||
w => match w.parse::<f64>() {
|
||||
Ok(v) => {
|
||||
b.push(0x06);
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
Err(_) => string(&mut b, 0x07, w),
|
||||
},
|
||||
}
|
||||
}
|
||||
b.push(0x11);
|
||||
}
|
||||
for p in ["End", "of", "ASM"] {
|
||||
string(&mut b, 0x0E, p);
|
||||
}
|
||||
string(&mut b, 0x0D, "data");
|
||||
b
|
||||
}
|
||||
|
||||
/// An ACDSDATA record holding `bytes` for the entity with handle 2A, in 50-byte chunks.
|
||||
fn acds(bytes: &[u8]) -> Vec<(i32, String)> {
|
||||
let mut a = vec![
|
||||
(0, "ACDSRECORD".to_string()),
|
||||
(90, "1".into()),
|
||||
(2, "AcDbDs::ID".into()),
|
||||
(280, "10".into()),
|
||||
(320, "2A".into()),
|
||||
(2, "ASM_Data".into()),
|
||||
(280, "15".into()),
|
||||
(94, bytes.len().to_string()),
|
||||
];
|
||||
for c in bytes.chunks(50) {
|
||||
a.push((310, c.iter().map(|b| format!("{b:02X}")).collect()));
|
||||
}
|
||||
a
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binary_data_in_the_acdsdata_section_reads_alike() {
|
||||
let bytes = sab(&sat(&square_with_hole(), None));
|
||||
let e = vec![(0, "REGION".to_string()), (5, "2A".into()), (8, "0".into()), (100, "AcDbModelerGeometry".into()), (290, "0".into())];
|
||||
// ASM's signature in place of ACIS's, as DXF 2018 may write it.
|
||||
let asm = [b"ASM BinaryFile4".as_slice(), &bytes[b"ACIS BinaryFile".len()..]].concat();
|
||||
for data in [&bytes, &asm] {
|
||||
let r = import(&drawing("AC1032", &e, &acds(data)), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
filled_object(&r.document);
|
||||
check(&r.document, &[[10.0, 10.0], [50.0, 75.0]], &[[50.0, 50.0]]);
|
||||
}
|
||||
// Without its data the region is left out and listed.
|
||||
let r = import(&drawing("AC1027", &e, &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{:?}", r.warnings);
|
||||
// Data shorter than its declared size is left out and listed too.
|
||||
let mut short = acds(&bytes);
|
||||
short[7].1 = (bytes.len() + 1).to_string();
|
||||
let r = import(&drawing("AC1032", &e, &short), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{:?}", r.warnings);
|
||||
// A chunk with an odd number of digits or a character that is not a hex digit fails to read.
|
||||
let mut out = Vec::new();
|
||||
assert!(super::reader::hex_bytes("0aFf", &mut out));
|
||||
assert_eq!(out, [0x0A, 0xFF]);
|
||||
for hex in ["0aF", "0aZZ", "0 aF"] {
|
||||
assert!(!super::reader::hex_bytes(hex, &mut Vec::new()), "{hex}");
|
||||
}
|
||||
// Data longer than the limit is left out, unless its declared size cuts it within the limit.
|
||||
let sized = |len: usize, size: Option<usize>| super::reader::sized_region(vec![7; len], size, 8).map(|b| b.len());
|
||||
assert_eq!(sized(10, None), None);
|
||||
assert_eq!(sized(10, Some(9)), None);
|
||||
assert_eq!(sized(10, Some(11)), None);
|
||||
assert_eq!(sized(10, Some(5)), Some(5));
|
||||
assert_eq!(sized(8, None), Some(8));
|
||||
}
|
||||
|
||||
/// A drawing the export writes (R2000, millimetres) with a region added to its entities.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
fn exported_with_region() -> Vec<u8> {
|
||||
let d = Document::new(200.0, 200.0);
|
||||
let o =
|
||||
crate::DxfOptions { version: crate::DxfVersion::R2000, region: d.artboards[0].rect, unit: Unit::Millimeters, ..crate::DxfOptions::default() };
|
||||
let dxf = String::from_utf8(crate::export(&d, &o).unwrap().bytes).unwrap();
|
||||
let mut region = String::new();
|
||||
for (c, v) in region_text(&encipher(&sat(&square_with_hole(), None)), false) {
|
||||
let v = if c == 5 { "FFF0".to_string() } else { v };
|
||||
region.push_str(&format!("{c:>3}\n{v}\n"));
|
||||
}
|
||||
let at = dxf.find("ENTITIES\n").unwrap() + "ENTITIES\n".len();
|
||||
format!("{}{region}{}", &dxf[..at], &dxf[at..]).into_bytes()
|
||||
}
|
||||
|
||||
/// The converter writes a region's data as text in a 2004 drawing and as binary data in the
|
||||
/// ACDSDATA section of a 2013 one; both come in as the DXF does.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
#[test]
|
||||
fn regions_in_dwg_drawings_come_in_from_text_and_binary_data() {
|
||||
crate::dwg::allow_in_process();
|
||||
let dxf = exported_with_region();
|
||||
let o = ImportOptions { unit: Some(Unit::Millimeters), scale: Some(1.0), center: false, ..ImportOptions::default() };
|
||||
let want = import(&dxf, &o).unwrap();
|
||||
assert!(want.warnings.is_empty(), "{:?}", want.warnings);
|
||||
let want = filled_object(&want.document).geometric_bounds().unwrap();
|
||||
for version in ["AC1018", "AC1027"] {
|
||||
let dwg = craft_dwg::dxf_to_dwg_as(&dxf, version).unwrap();
|
||||
let back = craft_dwg::dwg_to_dxf(&dwg).unwrap();
|
||||
let binary = String::from_utf8_lossy(&back).contains("ACDSDATA");
|
||||
assert_eq!(binary, version == "AC1027", "{version}: the data's form");
|
||||
let r = import(&dwg, &o).unwrap();
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("REGION")), "{version}: {:?}", r.warnings);
|
||||
let got = filled_object(&r.document).geometric_bounds().unwrap();
|
||||
assert!((got.area() - want.area()).abs() < 1e-6 && got.origin().distance(want.origin()) < 1e-6, "{version}: {got:?} {want:?}");
|
||||
let mm = 72.0 / 25.4;
|
||||
check_at(&r.document, mm, &[[10.0, 10.0], [50.0, 75.0]], &[[50.0, 50.0]]);
|
||||
}
|
||||
}
|
||||
|
||||
/// [`check`] for art at `k` points per drawing unit.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
fn check_at(doc: &Document, k: f64, inside: &[[f64; 2]], outside: &[[f64; 2]]) {
|
||||
let scale = |ps: &[[f64; 2]]| ps.iter().map(|p| [p[0] * k, p[1] * k]).collect::<Vec<_>>();
|
||||
check(doc, &scale(inside), &scale(outside));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reversed_coedges_and_edges_run_their_curves_backwards() {
|
||||
// A quarter of a circle from (100, 0) to (0, 100): on a counter-clockwise circle run along
|
||||
// it, or on a clockwise one run against it, with the edge stored either way round.
|
||||
for (down, flip, against) in [(false, true, true), (true, false, true), (true, true, false), (false, false, false)] {
|
||||
let quarter = E { a: [100.0, 0.0], b: [0.0, 100.0], curve: Curve::Circle { c: [0.0, 0.0], r: 100.0, down }, flip, against };
|
||||
let flipped_line = E { flip: true, against: true, ..line([0.0, 100.0], [0.0, 0.0]) };
|
||||
let quadrant = vec![line([0.0, 0.0], [100.0, 0.0]), quarter, flipped_line];
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[quadrant], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
// A quarter disc, not the three quarters the other way round.
|
||||
check(&r.document, &[[20.0, 20.0], [10.0, 50.0], [65.0, 65.0]], &[[80.0, 80.0], [-50.0, 50.0], [50.0, -50.0]]);
|
||||
let b = filled_object(&r.document).geometric_bounds().unwrap();
|
||||
assert!((b.width() - 100.0).abs() < 1e-6 && (b.height() - 100.0).abs() < 1e-6, "{down} {flip} {against}: {b:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_spline_edge_keeps_only_its_part_of_the_curve() {
|
||||
// A parabola from (0, 0) through (100, -50) to (200, 0); the edge runs its first half,
|
||||
// stored from its end and run reversed.
|
||||
let curve = "intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 2 open 2 0 2 1 2 0 0 0 100 -100 0 200 0 0 0 } I I".to_string();
|
||||
let half = E { a: [0.0, 0.0], b: [100.0, -50.0], curve: Curve::Raw(curve), flip: true, against: true };
|
||||
let shape = vec![half, line([100.0, -50.0], [100.0, 50.0]), line([100.0, 50.0], [0.0, 0.0])];
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[shape], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
let b = filled_object(&r.document).geometric_bounds().unwrap();
|
||||
assert!((b.width() - 100.0).abs() < 1e-6, "only the first half of the curve: {b:?}");
|
||||
assert!((b.height() - 100.0).abs() < 1e-6, "down to the curve's midpoint: {b:?}");
|
||||
// Below the chord from (0, 0) to (100, -50), above the curve.
|
||||
check(&r.document, &[[50.0, -30.0], [90.0, 0.0]], &[[50.0, -45.0], [150.0, 0.0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_spline_edge_warns_when_an_endpoint_lies_on_separate_parts_of_its_curve() {
|
||||
// The first and last spans both pass through (0, 0), away from their ends.
|
||||
let curve = "intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 1 open 4 0 2 1 1 2 1 3 2 -100 -100 0 100 100 0 -100 100 0 100 -100 0 } I I";
|
||||
for back in [false, true] {
|
||||
let (a, b) = if back { ([100.0, 100.0], [0.0, 0.0]) } else { ([0.0, 0.0], [100.0, 100.0]) };
|
||||
let edge = E { a, b, curve: Curve::Raw(curve.into()), flip: false, against: back };
|
||||
let shape = vec![edge, line(b, [100.0, 0.0]), line([100.0, 0.0], a)];
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[shape], None), false), &[]), &points()).unwrap();
|
||||
assert_eq!(r.warnings, ["region edges on curves that cross themselves may come in along the wrong part of the curve"]);
|
||||
assert!(!outline(&r.document).elements().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_spline_edge_warns_when_an_endpoint_is_at_one_cubic_spans_crossing() {
|
||||
let curve = "intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 3 open 2 0 3 1 3 36 -18 0 -28 26 0 -28 -26 0 36 18 0 } I I";
|
||||
let edge = E { a: [0.0, 0.0], b: [36.0, 18.0], curve: Curve::Raw(curve.into()), flip: false, against: false };
|
||||
let shape = vec![edge, line([36.0, 18.0], [36.0, 0.0]), line([36.0, 0.0], [0.0, 0.0])];
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[shape], None), false), &[]), &points()).unwrap();
|
||||
assert_eq!(r.warnings, ["region edges on curves that cross themselves may come in along the wrong part of the curve"]);
|
||||
assert!(!outline(&r.document).elements().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_closed_spline_edge_keeps_the_loop_at_one_cubic_spans_crossing() {
|
||||
// The curve crosses (0, 0) at 0.25 and 0.75; the loop reaches (-12, 0) at 0.5.
|
||||
let curve = "intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 3 open 2 0 3 1 3 36 -18 0 -28 26 0 -28 -26 0 36 18 0 } I I";
|
||||
for back in [false, true] {
|
||||
let edge = E { a: [0.0, 0.0], b: [0.0, 0.0], curve: Curve::Raw(curve.into()), flip: false, against: back };
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[vec![edge]], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
check(&r.document, &[[-6.0, 0.0]], &[[30.0, 0.0]]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_closed_spline_ring_warns_only_when_its_vertex_is_at_the_crossing() {
|
||||
// The first and third spans cross (0, 0) halfway along each; the seam is (-100, -100).
|
||||
let curve = "intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 1 closed 5 0 2 1 1 2 1 3 1 4 2 -100 -100 0 100 100 0 -100 100 0 100 -100 0 -100 -100 0 } I I";
|
||||
for a in [[0.0, 0.0], [-100.0, -100.0]] {
|
||||
for back in [false, true] {
|
||||
let edge = E { a, b: a, curve: Curve::Raw(curve.into()), flip: false, against: back };
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[vec![edge]], None), false), &[]), &points()).unwrap();
|
||||
if a == [0.0, 0.0] {
|
||||
assert_eq!(r.warnings, ["region edges on curves that cross themselves may come in along the wrong part of the curve"]);
|
||||
} else {
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
}
|
||||
check(&r.document, &[[0.0, 50.0], [0.0, -50.0]], &[[75.0, 0.0], [-75.0, 0.0]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spline_joints_and_a_closed_curves_seam_do_not_warn() {
|
||||
for (curve, a) in [
|
||||
("intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 1 open 3 0 2 1 1 2 2 0 0 0 100 0 0 100 100 0 } I I", [100.0, 0.0]),
|
||||
(
|
||||
"intcurve-curve $-1 -1 $-1 forward { exactcur 0 nubs 1 closed 5 0 2 1 1 2 1 3 1 4 2 0 0 0 100 0 0 100 100 0 0 100 0 0 0 0 } I I",
|
||||
[0.0, 0.0],
|
||||
),
|
||||
] {
|
||||
let edge = E { a, b: [100.0, 100.0], curve: Curve::Raw(curve.into()), flip: false, against: false };
|
||||
let shape = vec![edge, line([100.0, 100.0], [0.0, 100.0]), line([0.0, 100.0], a)];
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[shape], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
assert!(!outline(&r.document).elements().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_transform_places_the_body() {
|
||||
// Twice the size, moved 1000 along x.
|
||||
let text = sat(&[square(0.0, 10.0)], Some("1 0 0 0 1 0 0 0 1 1000 0 0 2"));
|
||||
let r = import(&drawing("AC1015", ®ion_text(&text, false), &[]), &points()).unwrap();
|
||||
let b = filled_object(&r.document).geometric_bounds().unwrap();
|
||||
assert!((b.width() - 20.0).abs() < 1e-9 && (b.height() - 20.0).abs() < 1e-9, "{b:?}");
|
||||
let h = r.document.artboards[0].rect.height();
|
||||
assert!(Rect::new(b.x0, h - b.y1, b.x1, h - b.y0).contains(Point::new(1010.0, 10.0)), "{b:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_or_unreadable_body_transforms_leave_the_region_out() {
|
||||
let text = sat(&[square(0.0, 10.0)], Some("1 0 0 0 1 0 0 0 1 1000 0 0 2"));
|
||||
for damaged in [
|
||||
text.replacen("body $-1 -1 $-1 $1 $-1 $5", "body $-1 -1 $-1 $1 $-1 $99999", 1),
|
||||
text.replacen("body $-1 -1 $-1 $1 $-1 $5", "body $-1 -1 $-1 $1 $-1 $4", 1),
|
||||
text.replacen("1 0 0 0 1 0 0 0 1 1000 0 0 2 no_rotate", "1 0 0 0 1 0 0 0 1 1000 0 no_rotate", 1),
|
||||
text.replacen("1000 0 0 2 no_rotate", "1000 0 0 no_rotate", 1),
|
||||
text.replacen("1000 0 0 2 no_rotate", "1000 0 0 unreadable no_rotate", 1),
|
||||
text.replacen("1 0 0 0 1 0 0 0 1 1000", "1 unreadable 0 0 0 1 0 0 0 1 1000", 1),
|
||||
] {
|
||||
assert_ne!(damaged, text);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&damaged, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{:?}", r.warnings);
|
||||
assert!(outline(&r.document).elements().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_or_unreadable_edge_and_coedge_senses_leave_the_region_out() {
|
||||
let text = sat(&[square(0.0, 10.0)], None);
|
||||
for before in ["$8 forward $6", "$13 forward @7 unknown"] {
|
||||
assert!(text.contains(before), "{text}");
|
||||
for sense in ["", "unreadable"] {
|
||||
let damaged = text.replacen(before, &before.replace("forward", sense), 1);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&damaged, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{before} {sense}: {:?}", r.warnings);
|
||||
assert!(outline(&r.document).elements().is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_curve_records_warn_when_edges_come_in_straight() {
|
||||
let text = sat(&square_with_hole(), None);
|
||||
let before = "$42 forward @7 unknown";
|
||||
assert!(text.contains(before), "{text}");
|
||||
let damaged = text.replacen(before, "$99999 forward @7 unknown", 1);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&damaged, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("straight lines")), "{:?}", r.warnings);
|
||||
check(&r.document, &[[10.0, 10.0], [50.0, 50.0]], &[[110.0, 50.0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disconnected_edges_warn_even_when_the_coedge_ring_is_complete() {
|
||||
let mut edges = square(0.0, 100.0);
|
||||
edges[1].a[0] += 5.0;
|
||||
edges[1].b[0] += 5.0;
|
||||
let mut closing = square(0.0, 100.0);
|
||||
closing[3].b[0] += 5.0;
|
||||
for edges in [edges, closing] {
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[edges], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("break off")), "{:?}", r.warnings);
|
||||
check(&r.document, &[[50.0, 50.0]], &[[110.0, 50.0]]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_curves_come_in_straight_and_damaged_data_is_left_out() {
|
||||
let mut edges = square(0.0, 100.0);
|
||||
edges[0].curve = Curve::Raw("helix-curve $-1 -1 $-1 0 0 0".into());
|
||||
let r = import(&drawing("AC1015", ®ion_text(&sat(&[edges], None), false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("straight lines")), "{:?}", r.warnings);
|
||||
check(&r.document, &[[50.0, 50.0]], &[]);
|
||||
// A ring of coedges whose second points at itself ends there; a body pointing out of range
|
||||
// and text that isn't data are listed as left out.
|
||||
let ring = sat(&[square(0.0, 10.0)], None);
|
||||
assert!(ring.contains("coedge $-1 -1 $-1 $21 $7 $-1"));
|
||||
let ring = ring.replace("coedge $-1 -1 $-1 $21 $7 $-1", "coedge $-1 -1 $-1 $14 $7 $-1");
|
||||
let wild = sat(&[square(0.0, 10.0)], None).replace("body $-1 -1 $-1 $1", "body $-1 -1 $-1 $99999");
|
||||
let mut e = region_text(&ring, false);
|
||||
for text in [wild.as_str(), "not data", "700 0 1 0\n"] {
|
||||
e.extend(region_text(text, false));
|
||||
}
|
||||
let r = import(&drawing("AC1015", &e, &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("3 REGION")), "{:?}", r.warnings);
|
||||
assert!(r.warnings.iter().any(|w| w.contains("break off")), "{:?}", r.warnings);
|
||||
// The ring's two edges and the line that closes them.
|
||||
check(&r.document, &[[8.0, 2.0]], &[[2.0, 8.0]]);
|
||||
// A hole whose ring of coedges is missing is listed, not dropped quietly.
|
||||
let holed = sat(&[square(0.0, 100.0), square(40.0, 60.0)], None);
|
||||
assert!(holed.contains("loop $-1 -1 $-1 $-1 $36 $3"), "{holed}");
|
||||
let holed = holed.replace("loop $-1 -1 $-1 $-1 $36 $3", "loop $-1 -1 $-1 $-1 $99999 $3");
|
||||
let r = import(&drawing("AC1015", ®ion_text(&holed, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("break off")), "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_topology_chains_are_walked_within_a_limit() {
|
||||
// 100 lumps share one chain of 100 shells, each shell one chain of 100 faces: the first face
|
||||
// a square, the others without loops. That is 1,000,000 faces visited, over the limit of
|
||||
// records visited, though only 40,000 coedges.
|
||||
let one = sat(&[square(0.0, 10.0)], None);
|
||||
let mut recs: Vec<String> = one.lines().skip(3).take_while(|l| !l.starts_with("End-of")).map(str::to_string).collect();
|
||||
let (lumps, shells, faces) = (recs.len(), recs.len() + 100, recs.len() + 200);
|
||||
recs[0] = format!("body $-1 -1 $-1 ${lumps} $-1 $-1 #");
|
||||
let next = |i: usize, n: usize, at: usize| if i + 1 < n { format!("${}", at + i + 1) } else { "$-1".into() };
|
||||
for i in 0..100 {
|
||||
recs.push(format!("lump $-1 -1 $-1 {} ${shells} $0 #", next(i, 100, lumps)));
|
||||
}
|
||||
for i in 0..100 {
|
||||
recs.push(format!("shell $-1 -1 $-1 {} $-1 ${faces} $-1 ${lumps} #", next(i, 100, shells)));
|
||||
}
|
||||
for i in 0..100 {
|
||||
let lp = if i == 0 { "$6" } else { "$-1" };
|
||||
recs.push(format!("face $-1 -1 $-1 {} {lp} ${shells} $-1 $4 forward single #", next(i, 100, faces)));
|
||||
}
|
||||
let text = format!("{}\n{}\nEnd-of-ACIS-data\n", one.lines().take(3).collect::<Vec<_>>().join("\n"), recs.join("\n"));
|
||||
let r = import(&drawing("AC1015", ®ion_text(&text, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{:?}", r.warnings);
|
||||
// One lump, shell and face of the same records come in.
|
||||
let small = text.replacen(&format!("lump $-1 -1 $-1 ${} ", lumps + 1), "lump $-1 -1 $-1 $-1 ", 1);
|
||||
let small = small.replacen(&format!("shell $-1 -1 $-1 ${} ", shells + 1), "shell $-1 -1 $-1 $-1 ", 1);
|
||||
let small = small.replacen(&format!("face $-1 -1 $-1 ${} ", faces + 1), "face $-1 -1 $-1 $-1 ", 1);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&small, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
check(&r.document, &[[5.0, 5.0]], &[[15.0, 5.0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn broken_topology_chains_warn_when_the_next_record_is_missing_or_the_wrong_type() {
|
||||
let text = sat(&[square(0.0, 100.0), square(40.0, 60.0)], None);
|
||||
for (before, prefix) in [
|
||||
("lump $-1 -1 $-1 $-1", "lump $-1 -1 $-1"),
|
||||
("shell $-1 -1 $-1 $-1", "shell $-1 -1 $-1"),
|
||||
("face $-1 -1 $-1 $-1", "face $-1 -1 $-1"),
|
||||
("loop $-1 -1 $-1 $35", "loop $-1 -1 $-1"),
|
||||
] {
|
||||
for next in ["$99999", "$4"] {
|
||||
assert!(text.contains(before), "{before}");
|
||||
let broken = text.replacen(before, &format!("{prefix} {next}"), 1);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&broken, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("break off")), "{before} {next}: {:?}", r.warnings);
|
||||
check(&r.document, &[[10.0, 10.0]], &[[110.0, 10.0]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_spline_loops_are_left_out_when_their_generated_outline_is_too_large() {
|
||||
// Many faces share one loop. Its degree-one spline follows a square with many knot spans,
|
||||
// so generated elements reach their limit well before topology visits do.
|
||||
let spans = 1024;
|
||||
let mut curve = format!("intcurve-curve $-1 -1 $-1 forward {{ exactcur 0 nubs 1 closed {} 0 2", spans + 1);
|
||||
for i in 1..spans {
|
||||
curve.push_str(&format!(" {i} 1"));
|
||||
}
|
||||
curve.push_str(&format!(" {spans} 2"));
|
||||
for i in 0..=spans {
|
||||
let t = (i % (spans / 4)) as f64 / (spans / 4) as f64;
|
||||
let (x, y) = match i / (spans / 4) {
|
||||
0 => (t, 0.0),
|
||||
1 => (1.0, t),
|
||||
2 => (1.0 - t, 1.0),
|
||||
_ => (0.0, 1.0 - t),
|
||||
};
|
||||
let (x, y) = if i == spans { (0.0, 0.0) } else { (x, y) };
|
||||
curve.push_str(&format!(" {x} {y} 0"));
|
||||
}
|
||||
curve.push_str(" } I I");
|
||||
let edge = E { a: [0.0, 0.0], b: [0.0, 0.0], curve: Curve::Raw(curve), flip: false, against: false };
|
||||
let one = sat(&[vec![edge]], None);
|
||||
let r = import(&drawing("AC1015", ®ion_text(&one, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.is_empty(), "{:?}", r.warnings);
|
||||
check(&r.document, &[[0.5, 0.5]], &[[1.5, 0.5]]);
|
||||
let mut recs: Vec<String> = one.lines().skip(3).take_while(|l| !l.starts_with("End-of")).map(str::to_string).collect();
|
||||
let faces = recs.len();
|
||||
let count = super::build::MAX_ELEMENTS / (spans + 2) + 1;
|
||||
recs[2] = format!("shell $-1 -1 $-1 $-1 $-1 ${faces} $-1 $1 #");
|
||||
for i in 0..count {
|
||||
let next = if i + 1 < count { format!("${}", faces + i + 1) } else { "$-1".into() };
|
||||
recs.push(format!("face $-1 -1 $-1 {next} $6 $2 $-1 $4 forward single #"));
|
||||
}
|
||||
let text = format!("{}\n{}\nEnd-of-ACIS-data\n", one.lines().take(3).collect::<Vec<_>>().join("\n"), recs.join("\n"));
|
||||
let r = import(&drawing("AC1015", ®ion_text(&text, false), &[]), &points()).unwrap();
|
||||
assert!(r.warnings.iter().any(|w| w.contains("1 REGION")), "{:?}", r.warnings);
|
||||
assert!(outline(&r.document).elements().is_empty());
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
//! layer (hidden ones switched off, locked ones locked, non-printing ones not plotted), paths
|
||||
//! become polylines (straight segments) or cubic splines (curves), fills their outlines and solid
|
||||
//! hatches, type text entities or glyph outlines, and placed images image entities linked to PNG
|
||||
//! or JPEG files the caller writes next to the drawing. Coordinates are y-up, in drawing units: `scale` units per
|
||||
//! or JPEG files the caller writes next to the drawing; with [`DxfOptions::group_blocks`] groups
|
||||
//! become blocks placed by INSERT entities. Coordinates are y-up, in drawing units: `scale` units per
|
||||
//! `unit` of the art, with the origin at the bottom-left corner of [`DxfOptions::region`].
|
||||
//! [`export_drawings`] writes one such drawing for each of several regions, applying the live
|
||||
//! effects once for all of them.
|
||||
@@ -26,6 +27,8 @@
|
||||
#![doc(test(attr(deny(unsafe_code))))]
|
||||
|
||||
mod aci;
|
||||
// Temporary until storytold/craft-libs#5381 merges and the craft-libs pin moves past it.
|
||||
mod blocks_compat;
|
||||
pub mod dwg;
|
||||
#[cfg(test)]
|
||||
mod expansion_test;
|
||||
@@ -316,6 +319,10 @@ pub struct DxfOptions {
|
||||
pub alter_paths: bool,
|
||||
/// Type is written as glyph outlines (always with [`Preserve::Appearance`]).
|
||||
pub outline_text: bool,
|
||||
/// Always Export Group as Block Reference: each group is written as a block definition of its
|
||||
/// contents, placed by an INSERT entity on the group's layer (groups inside it are blocks
|
||||
/// placed inside that block). Off: a group's contents are written as plain entities.
|
||||
pub group_blocks: bool,
|
||||
/// The drawing's origin is this region's bottom-left corner (document space).
|
||||
pub region: Rect,
|
||||
/// Leave out objects entirely outside `region` (one drawing per artboard).
|
||||
@@ -336,6 +343,7 @@ impl Default for DxfOptions {
|
||||
preserve: Preserve::default(),
|
||||
alter_paths: false,
|
||||
outline_text: false,
|
||||
group_blocks: false,
|
||||
region: Rect::ZERO,
|
||||
crop: false,
|
||||
}
|
||||
|
||||
+51
-13
@@ -2,7 +2,8 @@
|
||||
//! order. Fills are their outlines then solid hatches (the outlines alone in R12 or with
|
||||
//! hatches left out), placed images are linked image files unless left out, strokes
|
||||
//! polylines (with bulges for circular arcs) and cubic splines with a lineweight and dashes, or
|
||||
//! filled outlines where the look needs them.
|
||||
//! filled outlines where the look needs them. With [`DxfOptions::group_blocks`] each group is a
|
||||
//! block, placed by an INSERT.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -14,6 +15,8 @@ use vectorcraft_geom::{Affine, BezPath, FillRule, PathData, Point, Rect, Vec2};
|
||||
|
||||
use crate::aci::nearest_aci;
|
||||
use crate::{CAP_HEIGHT, ColorDepth, DxfImage, DxfOptions, DxfOutput, MAX_NEST, Preserve, RasterFormat};
|
||||
// Block and the INSERT writer come from craft-libs#5381 once it merges; see `blocks_compat`.
|
||||
use crate::blocks_compat::Block;
|
||||
use craft_dxf::drawing::{Codes, Drawing, EntityStyle, Handle, ImageDef, Layer, LineType, STANDARD_STYLE, fixed};
|
||||
|
||||
/// Curves are flattened to within this distance (points) where DXF needs straight segments
|
||||
@@ -503,8 +506,13 @@ pub(crate) struct Scene<'a> {
|
||||
to_dxf: Affine,
|
||||
/// Drawing units per point.
|
||||
k: f64,
|
||||
/// The entities written so far.
|
||||
/// The entities written so far: those of model space, or of the group block being written.
|
||||
e: Codes,
|
||||
/// The owner of the entities in `e`: model space, or the group block's record.
|
||||
owner: Handle,
|
||||
/// Group blocks written so far ([`DxfOptions::group_blocks`]), each after the blocks it inserts.
|
||||
blocks: Vec<Block>,
|
||||
block_names: Names,
|
||||
next: u32,
|
||||
layers: Vec<Layer>,
|
||||
layer_names: Names,
|
||||
@@ -544,6 +552,9 @@ impl<'a> Scene<'a> {
|
||||
to_dxf: Affine::new([k, 0.0, 0.0, -k, -r.x0 * k, r.y1 * k]),
|
||||
k,
|
||||
e: Codes::new(o.version.into()),
|
||||
owner: fixed::MODEL_RECORD,
|
||||
blocks: vec![],
|
||||
block_names: Names::with(&["*Model_Space", "*Paper_Space"]),
|
||||
next: fixed::FIRST_FREE,
|
||||
layers: vec![],
|
||||
layer_names: Names::with(&["0", "Defpoints"]),
|
||||
@@ -593,7 +604,12 @@ impl<'a> Scene<'a> {
|
||||
metric: matches!(self.o.unit, Unit::Millimeters | Unit::Centimeters | Unit::Meters),
|
||||
next: self.next,
|
||||
};
|
||||
DxfOutput { bytes: drawing.write().into_bytes(), images: self.files, warnings: self.warnings, setting_notes: self.setting_notes }
|
||||
DxfOutput {
|
||||
bytes: crate::blocks_compat::write(drawing, &self.blocks).into_bytes(),
|
||||
images: self.files,
|
||||
warnings: self.warnings,
|
||||
setting_notes: self.setting_notes,
|
||||
}
|
||||
}
|
||||
|
||||
/// Note `w`, once, about something of the document that the drawing leaves out or that reaches
|
||||
@@ -660,6 +676,7 @@ impl<'a> Scene<'a> {
|
||||
self.children(children, *clip);
|
||||
(self.layer, self.flags) = outer;
|
||||
}
|
||||
NodeKind::Group { children, clip } if self.o.group_blocks => self.group_block(n, children, *clip),
|
||||
NodeKind::Group { children, clip } => self.children(children, *clip),
|
||||
NodeKind::Path { path, rule, guide, .. } => {
|
||||
if !*guide {
|
||||
@@ -754,6 +771,27 @@ impl<'a> Scene<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Group `n` as a block of its children's entities and an INSERT that places it on the current
|
||||
/// layer ([`DxfOptions::group_blocks`]). The block's base point is the drawing's origin, so its
|
||||
/// entities keep their coordinates. A group that writes no entity writes no block.
|
||||
fn group_block(&mut self, n: &Node, children: &[std::sync::Arc<Node>], clip: bool) {
|
||||
let (record, begin, end, insert) = (self.handle(), self.handle(), self.handle(), self.handle());
|
||||
let outer = std::mem::replace(&mut self.e, Codes::new(self.o.version.into()));
|
||||
let owner = std::mem::replace(&mut self.owner, record);
|
||||
self.children(children, clip);
|
||||
let entities = std::mem::replace(&mut self.e, outer).into_string();
|
||||
self.owner = owner;
|
||||
if entities.is_empty() {
|
||||
return;
|
||||
}
|
||||
let long = self.o.version.r2000();
|
||||
let base = symbol_name(n.name.as_deref().unwrap_or_default(), long);
|
||||
let base = if base.is_empty() { symbol_name("Group", long) } else { base };
|
||||
let name = self.block_names.unique(&base, if long { 255 } else { 31 });
|
||||
crate::blocks_compat::insert(&mut self.e, insert, self.owner, &self.layer, &name);
|
||||
self.blocks.push(Block { name, record, begin, end, entities });
|
||||
}
|
||||
|
||||
/// Warn about what DXF can't hold in `n`'s look.
|
||||
fn note_losses(&mut self, n: &Node) {
|
||||
if n.blend != vectorcraft_color::BlendMode::Normal {
|
||||
@@ -959,7 +997,7 @@ impl<'a> Scene<'a> {
|
||||
}
|
||||
let h = self.handle();
|
||||
let layer = self.layer.clone();
|
||||
self.e.entity("HATCH", h, fixed::MODEL_RECORD, &layer, style, "AcDbHatch");
|
||||
self.e.entity("HATCH", h, self.owner, &layer, style, "AcDbHatch");
|
||||
self.e.xyz(10, 0.0, 0.0);
|
||||
self.e.normal();
|
||||
self.e.raw(2, "SOLID");
|
||||
@@ -1040,7 +1078,7 @@ impl<'a> Scene<'a> {
|
||||
let (a, b) = (self.pt(a), self.pt(b));
|
||||
let layer = self.layer.clone();
|
||||
let h = self.handle();
|
||||
self.e.entity("LINE", h, fixed::MODEL_RECORD, &layer, style, "AcDbLine");
|
||||
self.e.entity("LINE", h, self.owner, &layer, style, "AcDbLine");
|
||||
self.e.xyz(10, a.x, a.y);
|
||||
self.e.xyz(11, b.x, b.y);
|
||||
}
|
||||
@@ -1058,7 +1096,7 @@ impl<'a> Scene<'a> {
|
||||
// Bit 128: a linetype runs on through the vertices instead of restarting at each one.
|
||||
let flags = i64::from(closed) | if style.linetype.is_some() { 128 } else { 0 };
|
||||
if self.o.version.lwpolyline() {
|
||||
self.e.entity("LWPOLYLINE", h, fixed::MODEL_RECORD, &layer, style, "AcDbPolyline");
|
||||
self.e.entity("LWPOLYLINE", h, self.owner, &layer, style, "AcDbPolyline");
|
||||
self.e.int(90, pts.len() as i64);
|
||||
self.e.int(70, flags);
|
||||
if let Some(w) = width {
|
||||
@@ -1072,7 +1110,7 @@ impl<'a> Scene<'a> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.e.entity("POLYLINE", h, fixed::MODEL_RECORD, &layer, style, "AcDb2dPolyline");
|
||||
self.e.entity("POLYLINE", h, self.owner, &layer, style, "AcDb2dPolyline");
|
||||
self.e.int(66, 1);
|
||||
self.e.xyz(10, 0.0, 0.0);
|
||||
self.e.int(70, flags);
|
||||
@@ -1134,7 +1172,7 @@ impl<'a> Scene<'a> {
|
||||
let layer = self.layer.clone();
|
||||
let h = self.handle();
|
||||
if sub.closed {
|
||||
self.e.entity("CIRCLE", h, fixed::MODEL_RECORD, &layer, style, "AcDbCircle");
|
||||
self.e.entity("CIRCLE", h, self.owner, &layer, style, "AcDbCircle");
|
||||
self.e.xyz(10, centre.x, centre.y);
|
||||
self.e.num(40, radius);
|
||||
self.e.normal();
|
||||
@@ -1150,7 +1188,7 @@ impl<'a> Scene<'a> {
|
||||
if !on_ccw_arc(a0, a1, am) {
|
||||
std::mem::swap(&mut a0, &mut a1);
|
||||
}
|
||||
self.e.entity("ARC", h, fixed::MODEL_RECORD, &layer, style, "AcDbCircle");
|
||||
self.e.entity("ARC", h, self.owner, &layer, style, "AcDbCircle");
|
||||
self.e.xyz(10, centre.x, centre.y);
|
||||
self.e.num(40, radius);
|
||||
self.e.normal();
|
||||
@@ -1197,7 +1235,7 @@ impl<'a> Scene<'a> {
|
||||
|
||||
let layer = self.layer.clone();
|
||||
let h = self.handle();
|
||||
self.e.entity("ELLIPSE", h, fixed::MODEL_RECORD, &layer, style, "AcDbEllipse");
|
||||
self.e.entity("ELLIPSE", h, self.owner, &layer, style, "AcDbEllipse");
|
||||
self.e.xyz(10, centre.x, centre.y);
|
||||
self.e.xyz(11, axis.x, axis.y);
|
||||
self.e.normal();
|
||||
@@ -1232,7 +1270,7 @@ impl<'a> Scene<'a> {
|
||||
let ctrl: Vec<Point> = ctrl.iter().map(|p| self.pt(*p)).collect();
|
||||
let layer = self.layer.clone();
|
||||
let h = self.handle();
|
||||
self.e.entity("SPLINE", h, fixed::MODEL_RECORD, &layer, style, "AcDbSpline");
|
||||
self.e.entity("SPLINE", h, self.owner, &layer, style, "AcDbSpline");
|
||||
self.e.normal();
|
||||
// Planar (bit 3) and, if the subpath is closed, also closed (bit 0). A geometrically
|
||||
// closed cut needs the closed flag set so CAM/CAM tools (e.g. VCarve) treat it as a
|
||||
@@ -1308,7 +1346,7 @@ impl<'a> Scene<'a> {
|
||||
let p = self.pt(t.xf * origin);
|
||||
let layer = self.layer.clone();
|
||||
let h = self.handle();
|
||||
self.e.entity("TEXT", h, fixed::MODEL_RECORD, &layer, &style, "AcDbText");
|
||||
self.e.entity("TEXT", h, self.owner, &layer, &style, "AcDbText");
|
||||
self.e.xyz(10, p.x, p.y);
|
||||
self.e.num(40, height);
|
||||
let s: String = s.chars().take(MAX_TEXT).collect();
|
||||
@@ -1368,7 +1406,7 @@ impl<'a> Scene<'a> {
|
||||
let def = def.handle;
|
||||
let layer = self.layer.clone();
|
||||
let style = EntityStyle { aci: 7, ..EntityStyle::default() };
|
||||
self.e.entity("IMAGE", handle, fixed::MODEL_RECORD, &layer, &style, "AcDbRasterImage");
|
||||
self.e.entity("IMAGE", handle, self.owner, &layer, &style, "AcDbRasterImage");
|
||||
self.e.int(90, 0);
|
||||
self.e.xyz(10, at.x, at.y);
|
||||
self.e.xyz(11, u.x, u.y);
|
||||
|
||||
@@ -8,6 +8,8 @@ use vectorcraft_geom::{Affine, ParamCurve, PathData, Point, Rect, Shape, shapes}
|
||||
|
||||
use crate::*;
|
||||
|
||||
mod blocks;
|
||||
|
||||
type Pairs = Vec<(i32, String)>;
|
||||
|
||||
/// The `(code, value)` pairs of a DXF file.
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
//! Always Export Group as Block Reference: groups written as blocks placed by INSERT entities.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The user blocks of a drawing (not model or paper space): each its name and the entities
|
||||
/// between its BLOCK and its ENDBLK.
|
||||
fn blocks(out: &DxfOutput) -> Vec<(String, Vec<Pairs>)> {
|
||||
let mut found: Vec<(String, Vec<Pairs>)> = vec![];
|
||||
let mut open = false;
|
||||
for o in section(&pairs(&out.bytes), "BLOCKS") {
|
||||
match kind(&o) {
|
||||
"BLOCK" => {
|
||||
found.push((get(&o, 2).unwrap_or_default().to_string(), vec![]));
|
||||
open = true;
|
||||
}
|
||||
"ENDBLK" => open = false,
|
||||
_ if open => found.last_mut().expect("a block").1.push(o),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
found.retain(|(name, _)| !name.starts_with('*'));
|
||||
found
|
||||
}
|
||||
|
||||
/// A filled square outside any group; the group `Frame` holding a stroked rectangle and the group
|
||||
/// `Ring` holding a circle, on a second layer `Parts`.
|
||||
fn grouped_doc() -> Document {
|
||||
let mut d = doc_with(|d| vec![path(d, shapes::rectangle(Rect::new(150.0, 10.0, 170.0, 30.0)), Paint::solid(Color::BLACK), Paint::None, 0.0)]);
|
||||
let parts = d.add_layer(Some("Parts"));
|
||||
let rect = path(&mut d, shapes::rectangle(Rect::new(10.0, 10.0, 110.0, 60.0)), Paint::None, Paint::solid(Color::BLACK), 1.0);
|
||||
let circle = path(&mut d, shapes::ellipse(Rect::new(40.0, 20.0, 70.0, 50.0)), Paint::None, Paint::solid(Color::rgb(0.0, 0.0, 1.0)), 1.0);
|
||||
let mut ring = Node::group(d.alloc_id(), vec![Arc::new(circle)]);
|
||||
ring.name = Some("Ring".into());
|
||||
let mut frame = Node::group(d.alloc_id(), vec![Arc::new(rect), Arc::new(ring)]);
|
||||
frame.name = Some("Frame".into());
|
||||
d.insert(Some(parts), usize::MAX, frame).unwrap();
|
||||
d
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_are_blocks_placed_by_inserts_in_every_version() {
|
||||
let d = grouped_doc();
|
||||
for v in DxfVersion::ALL {
|
||||
let out = export(&d, &DxfOptions { version: v, group_blocks: true, ..opts(&d) }).unwrap();
|
||||
let top = entities(&out);
|
||||
let inserts: Vec<&Pairs> = top.iter().filter(|e| kind(e) == "INSERT").collect();
|
||||
assert_eq!(inserts.len(), 1, "{v:?}: the outer group alone is placed in model space");
|
||||
// Before 2000, names are capitals, letters, digits and $-_ only.
|
||||
let long = v >= DxfVersion::R2000;
|
||||
let (frame, ring, parts, first) = if long { ("Frame", "Ring", "Parts", "Layer 1") } else { ("FRAME", "RING", "PARTS", "LAYER_1") };
|
||||
assert_eq!((get(inserts[0], 2), get(inserts[0], 8)), (Some(frame), Some(parts)), "{v:?}");
|
||||
assert!(top.iter().any(|e| kind(e) != "INSERT" && get(e, 8) == Some(first)), "{v:?}: the loose square stays in model space");
|
||||
let found = blocks(&out);
|
||||
let names: Vec<&str> = found.iter().map(|b| b.0.as_str()).collect();
|
||||
assert_eq!(names, [ring, frame], "{v:?}: the inner block comes first");
|
||||
let (ring_entities, frame_entities) = (&found[0].1, &found[1].1);
|
||||
assert!(!ring_entities.is_empty() && ring_entities.iter().all(|e| kind(e) != "INSERT"), "{v:?}: the circle is in its group's block");
|
||||
let nested: Vec<&Pairs> = frame_entities.iter().filter(|e| kind(e) == "INSERT").collect();
|
||||
assert_eq!(nested.len(), 1, "{v:?}: the inner group is placed inside the outer block");
|
||||
assert_eq!(get(nested[0], 2), Some(ring), "{v:?}");
|
||||
assert!(frame_entities.iter().any(|e| kind(e) != "INSERT"), "{v:?}: the rectangle is in the outer block");
|
||||
if v >= DxfVersion::R13 {
|
||||
// Each block's entities are owned by its BLOCK_RECORD, and the INSERTs by what holds them.
|
||||
let records = table(&out, "BLOCK_RECORD");
|
||||
let record = |name: &str| records.iter().find(|r| get(r, 2) == Some(name)).and_then(|r| get(r, 5).map(str::to_string));
|
||||
for (name, ents) in &found {
|
||||
let owner = record(name).unwrap_or_else(|| panic!("{v:?}: no BLOCK_RECORD for {name}"));
|
||||
// A polyline's vertices and its SEQEND are owned by the polyline.
|
||||
let owned: Vec<&Pairs> = ents.iter().filter(|e| !matches!(kind(e), "VERTEX" | "SEQEND")).collect();
|
||||
assert!(!owned.is_empty() && owned.iter().all(|e| get(e, 330) == Some(owner.as_str())), "{v:?}: {name}");
|
||||
}
|
||||
assert_eq!(get(inserts[0], 330).map(str::to_string), record("*Model_Space"), "{v:?}: the outer INSERT is in model space");
|
||||
assert_eq!(get(nested[0], 330).map(str::to_string), record(frame), "{v:?}: the inner INSERT is in the outer block");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_the_option_groups_are_written_as_their_contents() {
|
||||
let d = grouped_doc();
|
||||
let out = export(&d, &opts(&d)).unwrap();
|
||||
assert!(blocks(&out).is_empty());
|
||||
assert!(!kinds(&out).iter().any(|k| k == "INSERT"));
|
||||
let with = export(&d, &DxfOptions { group_blocks: true, ..opts(&d) }).unwrap();
|
||||
// The same entities are written, moved into blocks.
|
||||
let count = |o: &DxfOutput| {
|
||||
let drawn = |ents: &[Pairs]| ents.iter().filter(|e| kind(e) != "INSERT").count();
|
||||
drawn(&entities(o)) + blocks(o).iter().map(|b| drawn(&b.1)).sum::<usize>()
|
||||
};
|
||||
assert_eq!(count(&out), count(&with));
|
||||
assert_eq!(header(&pairs(&out.bytes), "$EXTMIN"), header(&pairs(&with.bytes), "$EXTMIN"));
|
||||
assert_eq!(header(&pairs(&out.bytes), "$EXTMAX"), header(&pairs(&with.bytes), "$EXTMAX"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blocks_read_back_at_the_place_their_group_was() {
|
||||
let d = grouped_doc();
|
||||
let o = ImportOptions { unit: Some(Unit::Points), scale: Some(1.0), center: false, ..ImportOptions::default() };
|
||||
let plain = import(&export(&d, &opts(&d)).unwrap().bytes, &o).unwrap().document;
|
||||
let blocked = import(&export(&d, &DxfOptions { group_blocks: true, ..opts(&d) }).unwrap().bytes, &o).unwrap().document;
|
||||
let names: Vec<&str> = blocked.symbols.iter().map(|s| s.name.as_str()).collect();
|
||||
assert!(names.contains(&"Frame") && names.contains(&"Ring"), "{names:?}");
|
||||
let (a, b) = (plain.art_bounds().unwrap(), blocked.art_bounds().unwrap());
|
||||
assert!(close_to(&[a.x0, a.y0, a.x1, a.y1], &[b.x0, b.y0, b.x1, b.y1], 1e-6), "{a:?} against {b:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_with_nothing_written_is_no_block_and_names_stay_unique() {
|
||||
let mut d = Document::new(200.0, 100.0);
|
||||
let layer = d.layers[0].id;
|
||||
let mut hidden = path(&mut d, shapes::rectangle(Rect::new(0.0, 0.0, 5.0, 5.0)), Paint::solid(Color::BLACK), Paint::None, 0.0);
|
||||
hidden.visible = false;
|
||||
let empty = Node::group(d.alloc_id(), vec![Arc::new(hidden)]);
|
||||
d.insert(Some(layer), usize::MAX, empty).unwrap();
|
||||
for name in [Some("Part"), Some("part"), None, Some("*Model_Space")] {
|
||||
let p = path(&mut d, shapes::rectangle(Rect::new(10.0, 10.0, 20.0, 20.0)), Paint::solid(Color::BLACK), Paint::None, 0.0);
|
||||
let mut g = Node::group(d.alloc_id(), vec![Arc::new(p)]);
|
||||
g.name = name.map(str::to_string);
|
||||
d.insert(Some(layer), usize::MAX, g).unwrap();
|
||||
}
|
||||
let out = export(&d, &DxfOptions { group_blocks: true, ..opts(&d) }).unwrap();
|
||||
let names: Vec<String> = blocks(&out).into_iter().map(|b| b.0).collect();
|
||||
assert_eq!(names, ["Part", "part_2", "Group", "_Model_Space"], "the hidden-only group writes no block");
|
||||
assert_eq!(kinds(&out).iter().filter(|k| *k == "INSERT").count(), 4);
|
||||
}
|
||||
@@ -178,14 +178,14 @@ pub(crate) use export_names::{
|
||||
artboard_file_names_keeping_dots, default_name, merge, unique_file_names_keeping_dots, with_black_output, write_or_return,
|
||||
};
|
||||
use export_names::{distinct_names_by, write_encoded};
|
||||
pub(crate) use formats::is_own_title;
|
||||
use formats::{ARTBOARD, ARTBOARDS, RANGE, USE_ARTBOARDS, import_name, writable};
|
||||
pub use formats::{
|
||||
DOC_EXTS, DOCX_EXTS, FORMATS, Format, FormatOption, OPEN_EXTS, PLACE_EXTS, RTF_EXTS, TEXT_EXTS, UNASSOCIATED_EXTS, builtin_open_filters,
|
||||
export_extensions, extension, file_stem, format, format_for_name, has_own_title, importer_formats, library_open_filters, open_extensions,
|
||||
open_filters, opens_as_other, opens_with_importer, place_dialog_filters, place_filters, places_with_importer, plugin_formats, read_extensions,
|
||||
readable_format, readable_format_for_name, reads_as_dwg, titled_for_export, writable_format,
|
||||
open_exts, open_filters, opens_as_other, opens_with_importer, place_dialog_filters, place_exts, place_filters, places_with_importer,
|
||||
plugin_formats, read_extensions, readable_format, readable_format_for_name, reads_as_dwg, titled_for_export, writable_format,
|
||||
};
|
||||
pub(crate) use formats::{is_own_title, reads};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -785,7 +785,7 @@ fn is_openable(path: &str) -> bool {
|
||||
if ext.is_empty() {
|
||||
return false;
|
||||
}
|
||||
open_extensions().iter().any(|e| *e == ext) || FORMATS.iter().any(|f| f.read && f.extensions.iter().any(|e| *e == ext))
|
||||
open_extensions().iter().any(|e| *e == ext) || FORMATS.iter().any(|f| super::formats::reads(f) && f.extensions.iter().any(|e| *e == ext))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Export DXF",
|
||||
[],
|
||||
None,
|
||||
"{path?, dxfPreset?: custom (default)|cnc (CNC / CAM: version 2000, the oldest version that has both lightweight polylines and lineweights; unit mm, scale 1; colors 256, all 2000 holds; preserve editability and alterPaths false, so strokes stay center lines; outlineText true, so type is paths; includeImages and includeHatches false, so fills are their outlines and no image files are written; rasterFormat png; the options given override it), version?: R12|R13|R14|2000|2004|2007|2010|2013|2018 (default), unit?: mm (default; any unit name: pt, in, cm…), scale?: 1 (drawing units per unit), scaleLineweights?: false, colors?: 8|16|256|true (default; true colour needs 2004+, else 256), rasterFormat?: png (default)|jpeg (placed images, written next to the file), includeImages?: true (false: placed images and their files are left out), includeHatches?: true (false: fills are their outlines, without solid hatches), preserve?: appearance (default: type as outlines; strokes a CAD line can't draw as filled outlines; brush art)|editability (type as text; every stroke a line with its lineweight and dashes), alterPaths?: false (strokes a CAD line can't draw as their filled outlines, with editability too; also strokes wider than 2.11 mm, and every stroke in R13 and R14), outlineText?: false, selectedOnly?: false (the selected objects, in their layers), artboard?: 0 (the origin is its bottom-left corner), useArtboards?: true (one drawing per chosen artboard, artboards?/range?, holding the art over it: {stem}-{artboard}.dxf) | false (the origin at the art's bounds)} → {path, bytes, warnings, files?, linked?: [image files]}; no path → {dataBase64, …, linked?: [{name, dataBase64}]}. Layers become DXF layers (hidden: off; locked; non-printing: not plotted); paths become polylines and splines, fills their outlines (which laser and cutter software reads) and solid hatches. Same as document.export {format: dxf}. A key DXF doesn't take is refused",
|
||||
"{path?, dxfPreset?: custom (default)|cnc (CNC / CAM: version 2000, the oldest version that has both lightweight polylines and lineweights; unit mm, scale 1; colors 256, all 2000 holds; preserve editability and alterPaths false, so strokes stay center lines; outlineText true, so type is paths; includeImages and includeHatches false, so fills are their outlines and no image files are written; rasterFormat png; the options given override it), version?: R12|R13|R14|2000|2004|2007|2010|2013|2018 (default), unit?: mm (default; any unit name: pt, in, cm…), scale?: 1 (drawing units per unit), scaleLineweights?: false, colors?: 8|16|256|true (default; true colour needs 2004+, else 256), rasterFormat?: png (default)|jpeg (placed images, written next to the file), includeImages?: true (false: placed images and their files are left out), includeHatches?: true (false: fills are their outlines, without solid hatches), preserve?: appearance (default: type as outlines; strokes a CAD line can't draw as filled outlines; brush art)|editability (type as text; every stroke a line with its lineweight and dashes), alterPaths?: false (strokes a CAD line can't draw as their filled outlines, with editability too; also strokes wider than 2.11 mm, and every stroke in R13 and R14), outlineText?: false, groupBlocks?: false (Always Export Group as Block Reference: each group a block of its contents, nested groups blocks inside it, placed by an INSERT on the group's layer), selectedOnly?: false (the selected objects, in their layers), artboard?: 0 (the origin is its bottom-left corner), useArtboards?: true (one drawing per chosen artboard, artboards?/range?, holding the art over it: {stem}-{artboard}.dxf) | false (the origin at the art's bounds)} → {path, bytes, warnings, files?, linked?: [image files]}; no path → {dataBase64, …, linked?: [{name, dataBase64}]}. Layers become DXF layers (hidden: off; locked; non-printing: not plotted); paths become polylines and splines, fills their outlines (which laser and cutter software reads) and solid hatches. Same as document.export {format: dxf}. A key DXF doesn't take is refused",
|
||||
has_doc,
|
||||
export_dxf
|
||||
)]
|
||||
@@ -86,6 +86,12 @@ pub(crate) const OPTIONS: &[FormatOption] = &[
|
||||
description: "Alter Paths for Appearance: strokes a CAD line can't draw as their filled outlines, with editability too; also strokes wider than 2.11 mm, and every stroke in R13 and R14",
|
||||
},
|
||||
FormatOption { name: "outlineText", ty: "boolean", default: "false", description: "type as glyph outlines (always with preserve: appearance)" },
|
||||
FormatOption {
|
||||
name: "groupBlocks",
|
||||
ty: "boolean",
|
||||
default: "false",
|
||||
description: "Always Export Group as Block Reference: each group is a block, placed by an INSERT on its layer",
|
||||
},
|
||||
FormatOption { name: "selectedOnly", ty: "boolean", default: "false", description: "only the selected objects, in their layers" },
|
||||
];
|
||||
|
||||
@@ -149,6 +155,7 @@ struct Params {
|
||||
preserve: Option<String>,
|
||||
alter_paths: Option<bool>,
|
||||
outline_text: Option<bool>,
|
||||
group_blocks: Option<bool>,
|
||||
}
|
||||
|
||||
/// A string or number param as text (`2018` and `"2018"` alike).
|
||||
@@ -194,6 +201,7 @@ fn parse(p: &Value) -> Result<(DxfOptions, ArtboardPick)> {
|
||||
preserve: choice("preserve", q.preserve, Preserve::from_id, d.preserve, "appearance or editability")?,
|
||||
alter_paths: q.alter_paths.unwrap_or(d.alter_paths),
|
||||
outline_text: q.outline_text.unwrap_or(d.outline_text),
|
||||
group_blocks: q.group_blocks.unwrap_or(d.group_blocks),
|
||||
..d
|
||||
};
|
||||
Ok((opts, q.boards))
|
||||
|
||||
@@ -389,7 +389,10 @@ impl RasterOptions {
|
||||
top_down: self.flip_rows.unwrap_or(false),
|
||||
gray: color_model == jpeg::ColorModel::Gray,
|
||||
},
|
||||
tga: tga::TgaOptions { depth: self.depth.unwrap_or(24) },
|
||||
tga: {
|
||||
let gray = color_model == jpeg::ColorModel::Gray;
|
||||
tga::TgaOptions { depth: self.depth.unwrap_or_else(|| tga::TgaOptions::default_depth(gray)), gray }
|
||||
},
|
||||
psd: psd::PsdOptions {
|
||||
color_model,
|
||||
layers: self.layers.unwrap_or(true),
|
||||
@@ -413,12 +416,12 @@ fn bmp_layout(s: &str) -> Option<bool> {
|
||||
}
|
||||
|
||||
/// Refuse options `format` can't write together: BMP and Targa depths and layouts, and colour
|
||||
/// models (BMP is RGB or grey, Targa RGB).
|
||||
/// models (BMP and Targa are RGB or grey).
|
||||
fn check_options(format: RasterFormat, o: &RasterExportOptions) -> Result<()> {
|
||||
let model = o.jpeg.color_model;
|
||||
let r = match format {
|
||||
RasterFormat::Bmp if model == jpeg::ColorModel::Cmyk => Err("BMP files are RGB or grayscale: colorModel rgb or gray".to_string()),
|
||||
RasterFormat::Tga if model != jpeg::ColorModel::Rgb => Err("Targa files are RGB: colorModel rgb".to_string()),
|
||||
RasterFormat::Tga if model == jpeg::ColorModel::Cmyk => Err("Targa files are RGB or grayscale: colorModel rgb or gray".to_string()),
|
||||
RasterFormat::Psd if o.psd.preserve_text && !o.psd.layers => Err("preserveText writes type layers: it needs layers: true".to_string()),
|
||||
RasterFormat::Bmp => o.bmp.check(),
|
||||
RasterFormat::Tga => o.tga.check(),
|
||||
|
||||
@@ -315,14 +315,18 @@ const BMP_OPTIONS: &[FormatOption] = &[
|
||||
DITHER_AMOUNT,
|
||||
];
|
||||
|
||||
const TGA_COLOR_MODEL: FormatOption =
|
||||
FormatOption { name: "colorModel", ty: "string", default: "\"rgb\"", description: "rgb (true color) or gray (grayscale)" };
|
||||
|
||||
const TGA_DEPTH: FormatOption = FormatOption {
|
||||
name: "depth",
|
||||
ty: "integer",
|
||||
default: "24",
|
||||
description: "bits per pixel: 16 (one-bit alpha), 24 (flattened on white) or 32 (keeps transparency)",
|
||||
description: "bits per pixel: with rgb 16 (one-bit alpha), 24 (flattened on white) or 32 (keeps transparency); with gray 8 (the default, flattened on white) or 16 (keeps transparency)",
|
||||
};
|
||||
|
||||
const TGA_OPTIONS: &[FormatOption] = &[ARTBOARD, ARTBOARDS, RANGE, USE_ARTBOARDS, RECT, PPI, SCALE, WIDTH, HEIGHT, BACKGROUND, ANTI_ALIAS, TGA_DEPTH];
|
||||
const TGA_OPTIONS: &[FormatOption] =
|
||||
&[ARTBOARD, ARTBOARDS, RANGE, USE_ARTBOARDS, RECT, PPI, SCALE, WIDTH, HEIGHT, BACKGROUND, ANTI_ALIAS, TGA_COLOR_MODEL, TGA_DEPTH];
|
||||
|
||||
const PSD_LAYERS: FormatOption = FormatOption {
|
||||
name: "layers",
|
||||
@@ -603,6 +607,7 @@ pub const OPEN_EXTS: &[&str] = &[
|
||||
"pns",
|
||||
"jpg",
|
||||
"jpeg",
|
||||
"jpe",
|
||||
"gif",
|
||||
"webp",
|
||||
"tif",
|
||||
@@ -656,14 +661,15 @@ pub const OPEN_EXTS: &[&str] = &[
|
||||
|
||||
/// Extensions in [`OPEN_EXTS`] the packaging declares no type for: Photoshop documents belong to
|
||||
/// raster editors, so Finder and file managers don't offer a vector app for them, and there is no
|
||||
/// `.epsf`, `.ps`, Targa, PCX, Pixar, JPEG 2000, HEIC/HEIF, JPEG XL, `.cdr` or `.cmx` type, nor one for the `.pns`, `.dib` and `.rle` names of
|
||||
/// PNG and BMP files (File › Open and Place still read them all). On Linux the desktop entry's EPS
|
||||
/// type (shared-mime-info's) also covers `.epsf`, so file managers offer VectorCraft for it.
|
||||
/// `.epsf`, `.ps`, Targa, PCX, Pixar, JPEG 2000, HEIC/HEIF, JPEG XL, `.cdr` or `.cmx` type, nor one for the `.pns`, `.dib`, `.rle` and `.jpe`
|
||||
/// names of PNG, BMP and JPEG files (File › Open and Place still read them all). On Linux the desktop
|
||||
/// entry's EPS and JPEG types (shared-mime-info's) also cover `.epsf` and `.jpe`, so file managers
|
||||
/// offer VectorCraft for them.
|
||||
/// The packaging declares no type for HP-GL plot files, PICT pictures, layered raster `.pcraft`
|
||||
/// documents or DWG drawings (`.dwg`, `.dws` and `.dwt`) either.
|
||||
pub const UNASSOCIATED_EXTS: &[&str] = &[
|
||||
"psd", "pdd", "psb", "epsf", "ps", "pns", "dib", "rle", "tga", "vda", "icb", "vst", "pcx", "pxr", "jpf", "jpx", "jp2", "j2k", "j2c", "jpc",
|
||||
"heic", "heif", "jxl", "cdr", "cdt", "cmx", "plt", "hpgl", "hgl", "hpg", "pct", "pic", "pict", "pcraft", "dwg", "dws", "dwt",
|
||||
"psd", "pdd", "psb", "epsf", "ps", "pns", "dib", "rle", "jpe", "tga", "vda", "icb", "vst", "pcx", "pxr", "jpf", "jpx", "jp2", "j2k", "j2c",
|
||||
"jpc", "heic", "heif", "jxl", "cdr", "cdt", "cmx", "plt", "hpgl", "hgl", "hpg", "pct", "pic", "pict", "pcraft", "dwg", "dws", "dwt",
|
||||
];
|
||||
|
||||
/// The extension that picks each writable format when exporting (the format's first; PNG-8 shares
|
||||
@@ -708,6 +714,7 @@ pub const PLACE_EXTS: &[&str] = &[
|
||||
"pns",
|
||||
"jpg",
|
||||
"jpeg",
|
||||
"jpe",
|
||||
"gif",
|
||||
"webp",
|
||||
"tif",
|
||||
@@ -763,13 +770,14 @@ pub const PLACE_EXTS: &[&str] = &[
|
||||
"doc",
|
||||
];
|
||||
|
||||
/// The extensions File › Open and Place read PNG, BMP and Photoshop files by: the format's own,
|
||||
/// then the other names its files have (`.pns`, `.dib` and `.rle`, `.pdd`). Exports write only
|
||||
/// the format's own extension.
|
||||
const READ_ALIASES: &[(&str, &[&str])] = &[("png", &["png", "pns"]), ("bmp", &["bmp", "dib", "rle"]), ("psd", &["psd", "pdd"])];
|
||||
/// The extensions File › Open and Place read PNG, JPEG, BMP and Photoshop files by: the format's
|
||||
/// own, then the other names its files have (`.pns`, `.jpe`, `.dib` and `.rle`, `.pdd`). Exports
|
||||
/// write only the format's own extensions.
|
||||
const READ_ALIASES: &[(&str, &[&str])] =
|
||||
&[("png", &["png", "pns"]), ("jpg", &["jpg", "jpeg", "jpe"]), ("bmp", &["bmp", "dib", "rle"]), ("psd", &["psd", "pdd"])];
|
||||
|
||||
/// The extensions File › Open and Place read format `f` by: its own, and for PNG, BMP and PSD
|
||||
/// those of [`READ_ALIASES`].
|
||||
/// The extensions File › Open and Place read format `f` by: its own, and for PNG, JPEG, BMP and
|
||||
/// PSD those of [`READ_ALIASES`].
|
||||
pub fn read_extensions(f: &Format) -> &'static [&'static str] {
|
||||
READ_ALIASES.iter().find(|(id, _)| *id == f.id).map_or(f.extensions, |(_, exts)| *exts)
|
||||
}
|
||||
@@ -777,9 +785,52 @@ pub fn read_extensions(f: &Format) -> &'static [&'static str] {
|
||||
/// The built-in readable format of extension `ext` (any case, leading dot allowed): [`format`]'s
|
||||
/// when it reads, else the one [`READ_ALIASES`] gives it (`.dib` is BMP). Importer plug-ins are
|
||||
/// not looked at ([`importer_formats`]).
|
||||
/// DWG drawings are readable only in a build with a DWG decoder ([`vectorcraft_cad::dwg::DECODES`]).
|
||||
pub fn readable_format(ext: &str) -> Option<&'static Format> {
|
||||
readable_format_in(ext, vectorcraft_cad::dwg::DECODES)
|
||||
}
|
||||
|
||||
/// The built-in format a file of extension `ext` is taken for ([`super::load::detect`]): [`readable_format`]'s,
|
||||
/// with DWG also in a build without a DWG decoder.
|
||||
pub(crate) fn recognized_format(ext: &str) -> Option<&'static Format> {
|
||||
readable_format_in(ext, true)
|
||||
}
|
||||
|
||||
/// [`readable_format`] in a build that decodes DWG drawings when `dwg`.
|
||||
fn readable_format_in(ext: &str, dwg: bool) -> Option<&'static Format> {
|
||||
let k = ext.trim_start_matches('.').to_ascii_lowercase();
|
||||
builtin(&k).filter(|f| f.read).or_else(|| READ_ALIASES.iter().find(|(_, exts)| exts.contains(&k.as_str())).and_then(|(id, _)| builtin(id)))
|
||||
builtin(&k)
|
||||
.filter(|f| reads_in(f, dwg))
|
||||
.or_else(|| READ_ALIASES.iter().find(|(_, exts)| exts.contains(&k.as_str())).and_then(|(id, _)| builtin(id)))
|
||||
}
|
||||
|
||||
/// Whether format `f` reads in this build: DWG drawings only where a DWG decoder is built in.
|
||||
pub(crate) fn reads(f: &Format) -> bool {
|
||||
reads_in(f, vectorcraft_cad::dwg::DECODES)
|
||||
}
|
||||
|
||||
/// Whether format `f` reads in a build that decodes DWG drawings when `dwg`.
|
||||
fn reads_in(f: &Format, dwg: bool) -> bool {
|
||||
f.read && (dwg || !reads_as_dwg(f.id))
|
||||
}
|
||||
|
||||
/// `exts` less `.dwg`, `.dws` and `.dwt` in a build without a DWG decoder (`dwg` false).
|
||||
fn listed_in(exts: &[&'static str], dwg: bool) -> Vec<&'static str> {
|
||||
exts.iter().copied().filter(|e| dwg || !matches!(*e, "dwg" | "dws" | "dwt")).collect()
|
||||
}
|
||||
|
||||
/// The extensions File › Open reads as a document in this build: [`OPEN_EXTS`], less `.dwg`, `.dws` and `.dwt` where
|
||||
/// no DWG decoder is built in ([`vectorcraft_cad::dwg::DECODES`]).
|
||||
pub fn open_exts() -> &'static [&'static str] {
|
||||
static EXTS: std::sync::LazyLock<Vec<&'static str>> = std::sync::LazyLock::new(|| listed_in(OPEN_EXTS, vectorcraft_cad::dwg::DECODES));
|
||||
&EXTS
|
||||
}
|
||||
|
||||
/// The extensions File › Place reads in this build: [`PLACE_EXTS`], less `.dwg` where no DWG
|
||||
/// decoder is built in ([`vectorcraft_cad::dwg::DECODES`]).
|
||||
pub fn place_exts() -> &'static [&'static str] {
|
||||
static EXTS: std::sync::LazyLock<Vec<&'static str>> = std::sync::LazyLock::new(|| listed_in(PLACE_EXTS, vectorcraft_cad::dwg::DECODES));
|
||||
&EXTS
|
||||
}
|
||||
|
||||
/// The readable format a file name's extension names ([`readable_format`]).
|
||||
@@ -789,7 +840,12 @@ pub fn readable_format_for_name(name: &str) -> Option<&'static Format> {
|
||||
|
||||
/// One dialog filter per readable format.
|
||||
fn format_filters() -> impl Iterator<Item = (&'static str, &'static [&'static str])> {
|
||||
FORMATS.iter().filter(|f| f.read).map(|f| (f.label, read_extensions(f)))
|
||||
format_filters_in(vectorcraft_cad::dwg::DECODES)
|
||||
}
|
||||
|
||||
/// [`format_filters`] in a build that decodes DWG drawings when `dwg`.
|
||||
fn format_filters_in(dwg: bool) -> impl Iterator<Item = (&'static str, &'static [&'static str])> {
|
||||
FORMATS.iter().filter(move |f| reads_in(f, dwg)).map(|f| (f.label, read_extensions(f)))
|
||||
}
|
||||
|
||||
/// Whether a file named `name` can only be opened, by an importer plug-in: an installed importer lists
|
||||
@@ -798,7 +854,7 @@ fn format_filters() -> impl Iterator<Item = (&'static str, &'static [&'static st
|
||||
pub fn opens_with_importer(name: &str) -> bool {
|
||||
let ext = extension(name);
|
||||
!ext.is_empty()
|
||||
&& !PLACE_EXTS.contains(&ext.as_str())
|
||||
&& !place_exts().contains(&ext.as_str())
|
||||
&& !vectorcraft_plugins::import::for_extension(&ext).is_empty()
|
||||
&& !places_with_importer(name)
|
||||
}
|
||||
@@ -810,7 +866,7 @@ pub fn places_with_importer(name: &str) -> bool {
|
||||
let ext = extension(name);
|
||||
!ext.is_empty()
|
||||
&& readable_format(&ext).is_none()
|
||||
&& !PLACE_EXTS.contains(&ext.as_str())
|
||||
&& !place_exts().contains(&ext.as_str())
|
||||
&& !vectorcraft_plugins::import::placing(&ext).is_empty()
|
||||
}
|
||||
|
||||
@@ -856,7 +912,7 @@ fn importer_open_part() -> ImporterPart {
|
||||
{
|
||||
return part.clone();
|
||||
}
|
||||
let mut exts: Vec<&'static str> = OPEN_EXTS.to_vec();
|
||||
let mut exts: Vec<&'static str> = open_exts().to_vec();
|
||||
let mut filters = Vec::new();
|
||||
for f in importer_formats() {
|
||||
let own: Vec<&'static str> = f.extensions.iter().copied().filter(|e| readable_format(e).is_none() && !opens_as_other(e)).collect();
|
||||
@@ -871,7 +927,7 @@ fn importer_open_part() -> ImporterPart {
|
||||
let own: &'static [&'static str] = if own.len() == f.extensions.len() { f.extensions } else { Box::leak(own.into_boxed_slice()) };
|
||||
filters.push((f.label, own));
|
||||
}
|
||||
let exts: &'static [&'static str] = if exts.len() == OPEN_EXTS.len() { OPEN_EXTS } else { Box::leak(exts.into_boxed_slice()) };
|
||||
let exts: &'static [&'static str] = if exts.len() == open_exts().len() { open_exts() } else { Box::leak(exts.into_boxed_slice()) };
|
||||
let part = (exts, filters);
|
||||
*made = Some((revision, part.clone()));
|
||||
part
|
||||
@@ -898,7 +954,7 @@ pub fn open_filters() -> impl Iterator<Item = (&'static str, &'static [&'static
|
||||
/// open dialogs whose files the built-in readers read (New from Template, Load Styles, a document
|
||||
/// picked for its swatches, symbols, brushes or graphic styles).
|
||||
pub fn builtin_open_filters() -> impl Iterator<Item = (&'static str, &'static [&'static str])> {
|
||||
std::iter::once(("All readable files", OPEN_EXTS)).chain(format_filters()).chain(other_open_filters())
|
||||
std::iter::once(("All readable files", open_exts())).chain(format_filters()).chain(other_open_filters())
|
||||
}
|
||||
|
||||
/// The open-dialog filters after the document formats: swatch and graphic style libraries,
|
||||
@@ -934,7 +990,7 @@ pub fn library_open_filters(
|
||||
/// File → Place dialog filters: "All placeable files", then one per placeable format, then text,
|
||||
/// RTF and Word (`.docx` and `.doc`).
|
||||
pub fn place_filters() -> impl Iterator<Item = (&'static str, &'static [&'static str])> {
|
||||
std::iter::once(("All placeable files", PLACE_EXTS))
|
||||
std::iter::once(("All placeable files", place_exts()))
|
||||
.chain(format_filters().filter(|(_, exts)| exts.iter().all(|ext| PLACE_EXTS.contains(ext))))
|
||||
.chain(std::iter::once(("Text", TEXT_EXTS)))
|
||||
.chain(std::iter::once(("RTF", RTF_EXTS)))
|
||||
@@ -956,12 +1012,16 @@ fn importer_place_part() -> ImporterPart {
|
||||
{
|
||||
return part.clone();
|
||||
}
|
||||
let mut exts: Vec<&'static str> = PLACE_EXTS.to_vec();
|
||||
let mut exts: Vec<&'static str> = place_exts().to_vec();
|
||||
let mut filters = Vec::new();
|
||||
for p in import::installed().into_iter().filter(|p| p.manifest().place) {
|
||||
let m = p.manifest();
|
||||
let own: Vec<&'static str> =
|
||||
m.extensions.iter().filter(|e| readable_format(e).is_none() && !PLACE_EXTS.contains(&e.as_str())).map(|e| registry::intern(e)).collect();
|
||||
let own: Vec<&'static str> = m
|
||||
.extensions
|
||||
.iter()
|
||||
.filter(|e| readable_format(e).is_none() && !place_exts().contains(&e.as_str()))
|
||||
.map(|e| registry::intern(e))
|
||||
.collect();
|
||||
if own.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -973,7 +1033,7 @@ fn importer_place_part() -> ImporterPart {
|
||||
let own: &'static [&'static str] = Box::leak(own.into_boxed_slice());
|
||||
filters.push((registry::intern(&m.name), own));
|
||||
}
|
||||
let exts: &'static [&'static str] = if exts.len() == PLACE_EXTS.len() { PLACE_EXTS } else { Box::leak(exts.into_boxed_slice()) };
|
||||
let exts: &'static [&'static str] = if exts.len() == place_exts().len() { place_exts() } else { Box::leak(exts.into_boxed_slice()) };
|
||||
let part = (exts, filters);
|
||||
*made = Some((revision, part.clone()));
|
||||
part
|
||||
@@ -1138,6 +1198,9 @@ pub(super) fn formats(_: &mut Session, _: &Value) -> Result<Value> {
|
||||
let ids = |pick: fn(&Format) -> bool| all().filter(|f| pick(f)).map(|f| f.id).collect::<Vec<_>>();
|
||||
let listed = |f: &Format| {
|
||||
let mut v = f.to_json();
|
||||
if f.read && !reads(f) {
|
||||
v["read"] = json!(false);
|
||||
}
|
||||
if let Some(id) = vectorcraft_plugins::export::plugin_id(f.id) {
|
||||
v["plugin"] = json!(id);
|
||||
if vectorcraft_plugins::import::by_format(f.id).is_some_and(|p| p.manifest().place) {
|
||||
@@ -1148,9 +1211,37 @@ pub(super) fn formats(_: &mut Session, _: &Value) -> Result<Value> {
|
||||
};
|
||||
Ok(json!({
|
||||
"formats": all().map(listed).collect::<Vec<_>>(),
|
||||
"readable": ids(|f| f.read),
|
||||
"readable": ids(reads),
|
||||
"writable": ids(|f| f.write),
|
||||
"openExtensions": open_extensions(),
|
||||
"unsupported": UNSUPPORTED.iter().map(Unsupported::to_json).collect::<Vec<_>>(),
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod dwg_listing_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn dwg_is_listed_only_in_a_build_that_decodes_it() {
|
||||
assert_eq!(readable_format_in("dwg", true).map(|f| f.id), Some("dwg"));
|
||||
assert_eq!(listed_in(OPEN_EXTS, true), OPEN_EXTS);
|
||||
assert_eq!(listed_in(PLACE_EXTS, true), PLACE_EXTS);
|
||||
assert!(format_filters_in(true).any(|(_, exts)| exts.contains(&"dwg")));
|
||||
// Without a decoder, nothing offers DWG drawings, standards files or templates.
|
||||
for e in ["dwg", "dws", "dwt"] {
|
||||
assert!(readable_format_in(e, false).is_none(), ".{e} is not readable");
|
||||
assert!(!listed_in(OPEN_EXTS, false).contains(&e), "File › Open does not list .{e}");
|
||||
assert!(!listed_in(PLACE_EXTS, false).contains(&e), "File › Place does not list .{e}");
|
||||
assert!(format_filters_in(false).all(|(_, exts)| !exts.contains(&e)), "no filter lists .{e}");
|
||||
}
|
||||
assert!(readable_format_in("dxf", false).is_some(), "DXF still is");
|
||||
let drawing_exts = OPEN_EXTS.iter().filter(|e| matches!(**e, "dwg" | "dws" | "dwt")).count();
|
||||
assert_eq!(listed_in(OPEN_EXTS, false).len(), OPEN_EXTS.len() - drawing_exts, "every other extension stays");
|
||||
// This build lists DWG exactly when it decodes it.
|
||||
let dwg = vectorcraft_cad::dwg::DECODES;
|
||||
assert_eq!(open_exts().contains(&"dwg"), dwg);
|
||||
assert_eq!(place_exts().contains(&"dwg"), dwg);
|
||||
assert_eq!(readable_format("dwg").is_some(), dwg);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
//! layers and artboards (its manifest's `outputKinds`): the artboards it returns replace the one
|
||||
//! around the art of a new document, and File › Place leaves them out.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::Value;
|
||||
@@ -61,7 +62,7 @@ pub(super) fn pick(name: &str, bytes: &[u8], p: &Value) -> Result<Option<Arc<Plu
|
||||
check_extension(C, plugin.manifest(), name)?;
|
||||
return Ok(Some(plugin));
|
||||
}
|
||||
if detect(name, bytes).is_some() {
|
||||
if detect(name, bytes).is_some_and(super::formats::reads) {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(import::for_extension(&extension(name)).into_iter().next())
|
||||
@@ -97,7 +98,7 @@ fn importer_reads(ext: &str, mode: Mode) -> bool {
|
||||
super::readable_format(ext).is_none()
|
||||
&& match mode {
|
||||
Mode::Import => !import::for_extension(ext).is_empty(),
|
||||
Mode::Place => !super::PLACE_EXTS.contains(&ext) && !import::placing(ext).is_empty(),
|
||||
Mode::Place => !super::place_exts().contains(&ext) && !import::placing(ext).is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ fn check_data_for(p: &Value, mode: Mode, cmd: &str) -> Result<()> {
|
||||
if !explicit {
|
||||
let start: Vec<u8> = b64.bytes().filter(|b| !b.is_ascii_whitespace()).take(SNIFF_BYTES / 3 * 4).collect();
|
||||
let head = std::str::from_utf8(&start).ok().and_then(vectorcraft_format::base64_decode);
|
||||
if head.is_some_and(|head| detect(name, &head).is_some()) {
|
||||
if head.is_some_and(|head| detect(name, &head).is_some_and(super::formats::reads)) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -171,7 +172,7 @@ fn read_path_for(path: &str, p: &Value, mode: Mode, cmd: &str) -> Result<Vec<u8>
|
||||
if head.len() < SNIFF_BYTES {
|
||||
return Ok(head);
|
||||
}
|
||||
if detect(path, &head).is_some() {
|
||||
if detect(path, &head).is_some_and(super::formats::reads) {
|
||||
return super::read_file(path);
|
||||
}
|
||||
read_for_importer(path, mode)
|
||||
@@ -202,17 +203,43 @@ fn read_path_for(path: &str, _: &Value, _: Mode, _: &str) -> Result<Vec<u8>> {
|
||||
/// The file `file.place`'s params `p` name, as [`super::source`] reads it for command `cmd`, except
|
||||
/// that a file an importer would place (one `importer` names, or an extension no built-in format
|
||||
/// reads that an importer which places its files lists) is read, or decoded, only when it is at
|
||||
/// most [`import::MAX_INPUT_BYTES`] long.
|
||||
pub(crate) fn place_source<'a>(p: &'a Value, cmd: &str) -> Result<Source<'a>> {
|
||||
/// most [`import::MAX_INPUT_BYTES`] long. `given`: the bytes of the file `path` names, read already,
|
||||
/// which are borrowed instead of reading the path again (by the same size rule).
|
||||
pub(crate) fn place_source<'a, 'b>(p: &'a Value, cmd: &str, given: Option<&'b [u8]>) -> Result<PlaceSource<'a, 'b>> {
|
||||
match str_param(p, "path") {
|
||||
Some(path) => Ok(Source { name: path, bytes: read_path_for(path, p, Mode::Place, cmd)?, path: Some(path) }),
|
||||
Some(path) => {
|
||||
let bytes: Cow<'b, [u8]> = match given {
|
||||
Some(bytes) => {
|
||||
// The roots in force now still apply to the path, though it is not read again.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
super::may_read(path)?;
|
||||
let explicit = named(p, cmd)?.is_some();
|
||||
let importer = explicit || importer_reads(&extension(path), Mode::Place);
|
||||
let built_in = !explicit && detect(path, bytes.get(..SNIFF_BYTES).unwrap_or(bytes)).is_some();
|
||||
if importer && !built_in && bytes.len() > import::MAX_INPUT_BYTES {
|
||||
return Err(too_large(path, Mode::Place));
|
||||
}
|
||||
Cow::Borrowed(bytes)
|
||||
}
|
||||
None => Cow::Owned(read_path_for(path, p, Mode::Place, cmd)?),
|
||||
};
|
||||
Ok(PlaceSource { name: path, bytes, path: Some(path) })
|
||||
}
|
||||
None => {
|
||||
check_data_for(p, Mode::Place, cmd)?;
|
||||
super::source(p, cmd)
|
||||
let Source { name, bytes, path } = super::source(p, cmd)?;
|
||||
Ok(PlaceSource { name, bytes: Cow::Owned(bytes), path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The file [`place_source`] gives: as [`Source`], its bytes borrowed when they were given.
|
||||
pub(crate) struct PlaceSource<'a, 'b> {
|
||||
pub name: &'a str,
|
||||
pub bytes: Cow<'b, [u8]>,
|
||||
pub path: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// What [`read`] gives: the importer's format, the new document, its objects' ids, the artboards
|
||||
/// the importer returned and its warnings.
|
||||
type Read = (&'static Format, Document, Vec<NodeId>, Vec<import::OutArtboard>, Vec<String>);
|
||||
|
||||
@@ -8,7 +8,7 @@ use vectorcraft_render::effects::pixel::LoadedTexture;
|
||||
use super::super::fileinfo::imported_title;
|
||||
use super::super::{Result, Session, bad, bool_or, clipboard, parse_range, str_param};
|
||||
use super::pdfimport::LoadOptions;
|
||||
use super::{Format, SAVE_FORMATS, absolute_path, file_stamp, format, jxlread, psdread, read_file, readable_format_for_name};
|
||||
use super::{Format, SAVE_FORMATS, absolute_path, file_stamp, format, jxlread, psdread, read_file};
|
||||
use crate::cmd::links::Resolved;
|
||||
use crate::{EngineError, Prefs};
|
||||
|
||||
@@ -93,7 +93,7 @@ pub fn file_name(name: &str) -> String {
|
||||
/// The readable format of a file: from its content (magic bytes) when that tells, else from the
|
||||
/// extension of `name`.
|
||||
pub fn detect(name: &str, bytes: &[u8]) -> Option<&'static Format> {
|
||||
let by_name = readable_format_for_name(name);
|
||||
let by_name = super::formats::recognized_format(&super::extension(name));
|
||||
if vectorcraft_affinity::is_affinity(bytes) {
|
||||
return format("affinity");
|
||||
}
|
||||
|
||||
@@ -453,14 +453,14 @@ fn open_exts_cover_every_readable_format() {
|
||||
assert!(OPEN_EXTS.contains(e), "OPEN_EXTS lacks .{e} ({})", f.label);
|
||||
}
|
||||
}
|
||||
for e in OPEN_EXTS {
|
||||
assert!(readable_format(e).is_some(), ".{e} in OPEN_EXTS is no readable format");
|
||||
for e in open_exts() {
|
||||
assert!(readable_format(e).is_some(), ".{e} in open_exts() is no readable format");
|
||||
}
|
||||
let filters: Vec<_> = open_filters().collect();
|
||||
assert_eq!(filters[0], ("All readable files", OPEN_EXTS));
|
||||
assert_eq!(filters[0], ("All readable files", open_exts()));
|
||||
assert_eq!(
|
||||
filters.len(),
|
||||
13 + FORMATS.iter().filter(|f| f.read).count(),
|
||||
13 + FORMATS.iter().filter(|f| formats::reads(f)).count(),
|
||||
"and swatch and graphic style libraries, libraries, flattener, PDF, print, perspective grid and export presets, composite \
|
||||
fonts, shortcut sets, scripts, plug-ins"
|
||||
);
|
||||
@@ -484,7 +484,7 @@ fn library_open_filters_list_library_formats_first() {
|
||||
let filters: Vec<_> = library_open_filters("Swatch libraries", crate::cmd::swatchlib::LIBRARY_EXTS).collect();
|
||||
assert_eq!(filters[0], ("Swatch libraries", crate::cmd::swatchlib::LIBRARY_EXTS));
|
||||
assert!(filters[0].1.contains(&"ase"));
|
||||
assert_eq!(filters[1], ("All readable files", OPEN_EXTS));
|
||||
assert_eq!(filters[1], ("All readable files", open_exts()));
|
||||
let styles: &'static [&'static str] = std::slice::from_ref(&vectorcraft_doc::style_libs::STYLES_EXT);
|
||||
for (label, exts) in [("Swatch libraries", crate::cmd::swatchlib::LIBRARY_EXTS), ("Graphic Style Libraries", styles)] {
|
||||
let filters: Vec<_> = library_open_filters(label, exts).collect();
|
||||
@@ -576,7 +576,7 @@ fn formats_query_lists_readers_writers_and_options() {
|
||||
assert!(ids("readable").contains(&"tiff".to_string()) && ids("readable").contains(&"ait".to_string()));
|
||||
let png = r["formats"].as_array().unwrap().iter().find(|f| f["id"] == "png").unwrap();
|
||||
assert_eq!(png["options"]["scale"]["default"], Value::Null);
|
||||
assert_eq!(r["openExtensions"].as_array().unwrap().len(), OPEN_EXTS.len());
|
||||
assert_eq!(r["openExtensions"].as_array().unwrap().len(), open_exts().len());
|
||||
}
|
||||
|
||||
/// The format ids `command`'s params text lists for `format` (`a|b (default)|c (…)`, up to the
|
||||
|
||||
@@ -174,6 +174,27 @@ fn placed_images_come_back_as_linked_files() {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
/// `groupBlocks` writes a group as an INSERT of a block holding its contents; off by default, and
|
||||
/// not set by CNC / CAM.
|
||||
#[test]
|
||||
fn group_blocks_write_a_group_as_an_insert() {
|
||||
let mut s = two_boards();
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let plain = s.execute("document.exportDxf", &json!({})).unwrap();
|
||||
assert_eq!(entities(&text(&plain)), ["LWPOLYLINE", "HATCH", "LWPOLYLINE", "HATCH"]);
|
||||
for (cmd, p) in
|
||||
[("document.exportDxf", json!({"groupBlocks": true})), ("document.export", json!({"format": "dxf", "dxfPreset": "cnc", "groupBlocks": true}))]
|
||||
{
|
||||
let dxf = text(&s.execute(cmd, &p).unwrap());
|
||||
assert_eq!(entities(&dxf), ["INSERT"], "{p}");
|
||||
let blocks = &dxf[dxf.find("\nBLOCKS\n").unwrap()..dxf.find("\nENTITIES\n").unwrap()];
|
||||
assert_eq!(blocks.matches("\nLWPOLYLINE\n").count(), 2, "{p}: the group's rectangles are in its block");
|
||||
}
|
||||
let cnc = s.execute("document.exportDxf", &json!({"dxfPreset": "cnc"})).unwrap();
|
||||
assert!(!entities(&text(&cnc)).contains(&"INSERT".to_string()));
|
||||
}
|
||||
|
||||
/// `includeImages` and `includeHatches` leave out placed images (with their files) and fill
|
||||
/// hatches, each on its own, through both commands, with and without a path; CNC / CAM leaves
|
||||
/// out both, and the options given override it.
|
||||
@@ -259,6 +280,7 @@ fn bad_dxf_options_are_refused() {
|
||||
json!({"alterPaths": "yes"}),
|
||||
json!({"includeImages": "no"}),
|
||||
json!({"includeHatches": 0}),
|
||||
json!({"groupBlocks": "yes"}),
|
||||
] {
|
||||
let e = s.execute("document.exportDxf", &p).unwrap_err().to_string();
|
||||
assert!(e.contains("DXF"), "{p}: {e}");
|
||||
@@ -286,6 +308,7 @@ fn formats_list_dxf_and_what_can_not_be_written() {
|
||||
"preserve",
|
||||
"alterPaths",
|
||||
"outlineText",
|
||||
"groupBlocks",
|
||||
"selectedOnly",
|
||||
"useArtboards",
|
||||
] {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! JPEG Options: colour model, coding method, scans, profile and image maps.
|
||||
//! JPEG Options: colour model, coding method, scans, profile and image maps; JPEG files named
|
||||
//! `.jpe` open and place.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -87,3 +88,28 @@ fn image_maps_list_the_objects_with_a_url() {
|
||||
// One file only: Export for Screens can't add the map.
|
||||
assert!(s.execute("document.exportForScreens", &json!({"formats": [{"format": "jpg", "imageMap": "client"}]})).is_err());
|
||||
}
|
||||
|
||||
/// JPEG files named `.jpe` open and place as JPEG, in any case; the dialogs and a drop on the
|
||||
/// window take them by their extension, the desktop packaging doesn't associate them, and exports
|
||||
/// still write `.jpg`.
|
||||
#[test]
|
||||
fn jpe_files_open_and_place() {
|
||||
let mut s = session();
|
||||
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
let jpg = b64(&s.execute("document.export", &json!({"format": "jpg"})).unwrap());
|
||||
let data = vectorcraft_format::base64_encode(&jpg);
|
||||
for name in ["art.jpe", "ART.JPE"] {
|
||||
assert_eq!(readable_format_for_name(name).map(|f| f.id), Some("jpg"), "{name}");
|
||||
let r = s.execute("document.open", &json!({"name": name, "dataBase64": data})).unwrap();
|
||||
assert_eq!((&r["format"], &r["warnings"]), (&json!("jpg"), &json!([])), "{name}: {r}");
|
||||
s.execute("file.new", &json!({"width": 600, "height": 600})).unwrap();
|
||||
let r = s.execute("file.place", &json!({"name": name, "dataBase64": data})).unwrap();
|
||||
assert_eq!((&r["format"], r["ids"].as_array().map(Vec::len)), (&json!("jpg"), Some(1)), "{name}: {r}");
|
||||
}
|
||||
assert!(OPEN_EXTS.contains(&"jpe") && PLACE_EXTS.contains(&"jpe") && UNASSOCIATED_EXTS.contains(&"jpe"));
|
||||
let jpeg = ("JPEG", &["jpg", "jpeg", "jpe"][..]);
|
||||
assert!(open_filters().any(|f| f == jpeg) && place_filters().any(|f| f == jpeg));
|
||||
assert!(!export_extensions().contains(&"jpe"));
|
||||
assert!(format_for_name("x.jpe").is_none() && writable_format(None, Some("x.jpe")).is_err());
|
||||
assert!(s.execute("document.export", &json!({"path": "x.jpe"})).is_err());
|
||||
}
|
||||
@@ -138,8 +138,38 @@ fn targa_depth_reaches_the_file() {
|
||||
}
|
||||
let tga = export(&mut s, json!({"format": "tga"}));
|
||||
assert_eq!(tga[16], 24, "24 bits by default");
|
||||
for bad in [json!({"depth": 8}), json!({"colorModel": "gray"})] {
|
||||
assert!(s.execute("document.export", &merge(json!({"format": "tga"}), bad.clone())).is_err(), "{bad}");
|
||||
for bad in [
|
||||
json!({"depth": 8}),
|
||||
json!({"colorModel": "cmyk"}),
|
||||
json!({"colorModel": "lab"}),
|
||||
json!({"colorModel": "gray", "depth": 24}),
|
||||
json!({"colorModel": "gray", "depth": 32}),
|
||||
] {
|
||||
let e = s.execute("document.export", &merge(json!({"format": "tga"}), bad.clone())).unwrap_err();
|
||||
assert!(matches!(e, EngineError::BadParams { .. }), "{bad}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn targa_color_model_gray_writes_grayscale() {
|
||||
let mut s = session();
|
||||
let gray = export(&mut s, json!({"format": "tga", "colorModel": "gray"}));
|
||||
assert_eq!((gray[2], gray[16], gray[17]), (3, 8, 0), "grayscale, 8 bits by default, no alpha");
|
||||
let img = image::load_from_memory_with_format(&gray, image::ImageFormat::Tga).unwrap().to_rgba8();
|
||||
assert_eq!(img.dimensions(), (60, 40));
|
||||
assert_eq!(img.get_pixel(5, 5).0, [255; 4], "flattened on white");
|
||||
let black = img.get_pixel(40, 20).0;
|
||||
assert!(black[0] == black[1] && black[1] == black[2] && black[0] < 80, "{black:?}");
|
||||
|
||||
let alpha = export(&mut s, json!({"format": "tga", "colorModel": "gray", "depth": 16}));
|
||||
assert_eq!((alpha[2], alpha[16], alpha[17]), (3, 16, 8), "grayscale with an 8-bit alpha");
|
||||
let img = image::load_from_memory_with_format(&alpha, image::ImageFormat::Tga).unwrap().to_rgba8();
|
||||
assert_eq!(img.get_pixel(5, 5).0[3], 0, "transparent where nothing is drawn");
|
||||
assert_eq!(img.get_pixel(40, 20).0[3], 255);
|
||||
|
||||
for file in [gray, alpha] {
|
||||
let r = s.execute("document.open", &json!({"name": "back.tga", "dataBase64": vectorcraft_format::base64_encode(&file)})).unwrap();
|
||||
assert_eq!(r["format"], "tga");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3061,6 +3061,22 @@ fn unembed_bytes(blob: &vectorcraft_doc::ImageBlob, ext: &str) -> std::result::R
|
||||
if same { Ok(blob.bytes.to_vec()) } else { convert_image(&blob.bytes, ext) }
|
||||
}
|
||||
|
||||
/// `path` with `.ext` added when it has no extension: the file Unembed writes for a `path` given.
|
||||
fn with_unembed_extension(path: &str, ext: &str) -> String {
|
||||
if fileio::extension(path).is_empty() { format!("{path}.{ext}") } else { path.to_string() }
|
||||
}
|
||||
|
||||
/// The file `links.unembed {id, path}` writes embedded image `id` of the active document to: `path`
|
||||
/// with the extension of the format the image is stored in added when `path` has none. `None` when
|
||||
/// `id` is not an embedded image there.
|
||||
pub fn unembed_path(s: &Session, id: u64, path: &str) -> Option<String> {
|
||||
let st = s.doc().ok()?;
|
||||
let doc = with_brush_art(&st.doc);
|
||||
let im = image_of(&doc, NodeId(id)).filter(|im| im.link.is_none())?;
|
||||
let blob = st.doc.images.get(&im.key)?;
|
||||
Some(with_unembed_extension(path, stored_extension(blob)))
|
||||
}
|
||||
|
||||
fn unembed(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "links.unembed";
|
||||
let given = |k: &str| p.get(k).is_some_and(|v| !v.is_null());
|
||||
@@ -3097,7 +3113,7 @@ fn unembed(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let stem = Path::new(&name).file_stem().map_or_else(|| name.clone(), |s| s.to_string_lossy().into_owned());
|
||||
return Ok(json!({ "name": format!("{stem}.{ext}"), "dataBase64": vectorcraft_format::base64_encode(&bytes) }));
|
||||
};
|
||||
let path = absolute_path(&if fileio::extension(path).is_empty() { format!("{path}.{ext}") } else { path.to_string() });
|
||||
let path = absolute_path(&with_unembed_extension(path, &ext));
|
||||
// Read before writing: pixels that can't be read leave no file behind.
|
||||
let img = linked_image(&bytes, Some(&path))?;
|
||||
write_file(&path, &bytes)?;
|
||||
|
||||
@@ -1089,45 +1089,82 @@ fn reverse(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
None => path.subpaths.iter().map(|sp| want.is_none_or(|ccw| (sp.signed_area() < 0.0) != ccw)).collect(),
|
||||
}
|
||||
};
|
||||
let changed = super::overprint::edit_counted(s, "Reverse Path Direction", |d| {
|
||||
// A compound path's own strokes run along its members' subpaths in order, so they turn
|
||||
// with them, read before any member turns.
|
||||
let compounds: BTreeSet<NodeId> = ids.iter().map(|id| compound_or_self(d, *id)).filter(|c| ids.binary_search(c).is_err()).collect();
|
||||
for c in compounds {
|
||||
let Some(NodeKind::Compound { children, .. }) = d.node(c).map(|n| &n.kind) else { continue };
|
||||
let flip: Vec<bool> = children
|
||||
.iter()
|
||||
.filter_map(|m| m.path_data().map(|pd| if ids.binary_search(&m.id).is_ok() { flip_of(pd) } else { vec![false; pd.subpaths.len()] }))
|
||||
.flatten()
|
||||
.collect();
|
||||
if flip.contains(&true)
|
||||
&& let Some(n) = d.node_mut(c)
|
||||
{
|
||||
vectorcraft_doc::blend::reverse_stroke_records(n, &flip);
|
||||
let mut d = (*s.doc()?.doc).clone();
|
||||
// A compound path's own strokes run along its members' subpaths in order, so they turn
|
||||
// with them, read before any member turns.
|
||||
let compounds: BTreeSet<NodeId> = ids.iter().map(|id| compound_or_self(&d, *id)).filter(|c| ids.binary_search(c).is_err()).collect();
|
||||
for c in compounds {
|
||||
let Some(NodeKind::Compound { children, .. }) = d.node(c).map(|n| &n.kind) else { continue };
|
||||
let flip: Vec<bool> = children
|
||||
.iter()
|
||||
.filter_map(|m| m.path_data().map(|pd| if ids.binary_search(&m.id).is_ok() { flip_of(pd) } else { vec![false; pd.subpaths.len()] }))
|
||||
.flatten()
|
||||
.collect();
|
||||
if flip.contains(&true)
|
||||
&& let Some(n) = d.node_mut(c)
|
||||
{
|
||||
vectorcraft_doc::blend::reverse_stroke_records(n, &flip);
|
||||
}
|
||||
}
|
||||
let mut turned = Vec::new();
|
||||
for id in &ids {
|
||||
let path = path_mut(&mut d, *id)?;
|
||||
let flip = flip_of(path);
|
||||
if !flip.contains(&true) {
|
||||
continue;
|
||||
}
|
||||
// The stroke's width profile and pen recordings turn with the path, read before it turns.
|
||||
if let Some(n) = d.node_mut(*id) {
|
||||
vectorcraft_doc::blend::reverse_stroke_records(n, &flip);
|
||||
}
|
||||
let path = path_mut(&mut d, *id)?;
|
||||
for (sp, f) in path.subpaths.iter_mut().zip(&flip) {
|
||||
if *f {
|
||||
sp.reverse();
|
||||
}
|
||||
}
|
||||
let mut changed = 0;
|
||||
for id in &ids {
|
||||
let path = path_mut(d, *id)?;
|
||||
let flip = flip_of(path);
|
||||
if !flip.contains(&true) {
|
||||
continue;
|
||||
}
|
||||
// The stroke's width profile and pen recordings turn with the path, read before it turns.
|
||||
if let Some(n) = d.node_mut(*id) {
|
||||
vectorcraft_doc::blend::reverse_stroke_records(n, &flip);
|
||||
}
|
||||
let path = path_mut(d, *id)?;
|
||||
for (sp, f) in path.subpaths.iter_mut().zip(flip) {
|
||||
if f {
|
||||
sp.reverse();
|
||||
turned.push((*id, flip));
|
||||
}
|
||||
if !turned.is_empty() {
|
||||
s.edit("Reverse Path Direction", |doc, sel| {
|
||||
*doc = d;
|
||||
for (id, flip) in &turned {
|
||||
if let Some(path) = doc.node(*id).and_then(Node::path_data) {
|
||||
reverse_selected_anchors(sel, *id, path, flip);
|
||||
}
|
||||
}
|
||||
changed += 1;
|
||||
}
|
||||
Ok(changed)
|
||||
})?;
|
||||
Ok(json!({ "changed": changed }))
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
Ok(json!({ "changed": turned.len() }))
|
||||
}
|
||||
|
||||
/// Point the selected anchors, selected segments and key anchor of `sel` on path `id` at the same
|
||||
/// points after the subpaths of `path` marked in `flip` were reversed ([`SubPath::reverse`]). In a
|
||||
/// reversed subpath of `n` anchors, anchor `i` becomes anchor `n - 1 - i` and segment `j` becomes
|
||||
/// segment `n - 2 - j`; a closed subpath's closing segment (`n - 1`) stays its closing segment.
|
||||
fn reverse_selected_anchors(sel: &mut Selection, id: NodeId, path: &PathData, flip: &[bool]) {
|
||||
let reversed = |si: usize| path.subpaths.get(si).filter(|_| flip.get(si) == Some(&true)).map(|sp| (sp.anchors.len(), sp.closed));
|
||||
let anchor = |(si, ai): AnchorRef| match reversed(si) {
|
||||
Some((n, _)) if ai < n => (si, n - 1 - ai),
|
||||
_ => (si, ai),
|
||||
};
|
||||
let segment = |(si, j): SegmentRef| match reversed(si) {
|
||||
Some((n, true)) if j < n => (si, (2 * n - 2 - j) % n),
|
||||
Some((n, false)) if j < n.saturating_sub(1) => (si, n - 2 - j),
|
||||
_ => (si, j),
|
||||
};
|
||||
if let Some(set) = sel.anchors.get_mut(&id) {
|
||||
*set = set.iter().map(|r| anchor(*r)).collect();
|
||||
}
|
||||
if let Some(set) = sel.segments.get_mut(&id) {
|
||||
*set = set.iter().map(|r| segment(*r)).collect();
|
||||
}
|
||||
if let Some((key, r)) = sel.key_anchor
|
||||
&& key == id
|
||||
{
|
||||
sel.key_anchor = Some((id, anchor(r)));
|
||||
}
|
||||
}
|
||||
|
||||
/// First and last anchor points of a subpath.
|
||||
@@ -2413,8 +2450,9 @@ fn stretch_weights(anchors: &Anchors, closed: bool, roles: &[Stretch]) -> Vec<[f
|
||||
shares
|
||||
}
|
||||
|
||||
/// After an anchor is added at `(si, added)` of path `id`, number the direct-selected anchors and
|
||||
/// selected segments after it on that subpath one higher, so the selection keeps the same points.
|
||||
/// After an anchor is added at `(si, added)` of path `id`, number the direct-selected anchors,
|
||||
/// selected segments and key anchor after it on that subpath one higher, so the selection keeps
|
||||
/// the same points.
|
||||
/// A selected segment that the new anchor splits stays selected as its two halves, and the new
|
||||
/// anchor joins its ends in the anchors that move with it.
|
||||
fn renumber_after_insert(sel: &mut Selection, id: NodeId, si: usize, added: usize) {
|
||||
@@ -2423,6 +2461,14 @@ fn renumber_after_insert(sel: &mut Selection, id: NodeId, si: usize, added: usiz
|
||||
// renumbering saturates instead of overflowing.
|
||||
*set = set.iter().map(|&(s, a)| if s == si && a >= added { (s, a.saturating_add(1)) } else { (s, a) }).collect();
|
||||
}
|
||||
// The key anchor moves along with the anchors after the new one.
|
||||
if let Some((key, (s, a))) = sel.key_anchor
|
||||
&& key == id
|
||||
&& s == si
|
||||
&& a >= added
|
||||
{
|
||||
sel.key_anchor = Some((id, (s, a.saturating_add(1))));
|
||||
}
|
||||
let split = added.checked_sub(1);
|
||||
if sel.segments.get(&id).is_some_and(|set| split.is_some_and(|g| set.contains(&(si, g)))) {
|
||||
sel.anchors.entry(id).or_default().insert((si, added));
|
||||
|
||||
@@ -183,13 +183,13 @@ pub(crate) fn pt_per_px(ppi: Option<(f64, f64)>) -> (f64, f64) {
|
||||
|
||||
/// [`load_sliced`] without the slices.
|
||||
fn load(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool) -> Result<Loaded> {
|
||||
load_into(p, cmd, board, link_pdf, &mut vec![])
|
||||
load_into(p, cmd, board, link_pdf, None, &mut vec![])
|
||||
}
|
||||
|
||||
/// [`load_into`], with the slices of a PSD or PSB file that `importSlices` brings in.
|
||||
fn load_sliced(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool) -> Result<(Loaded, Slices)> {
|
||||
fn load_sliced(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, given: Option<&[u8]>) -> Result<(Loaded, Slices)> {
|
||||
let mut slices = vec![];
|
||||
let l = load_into(p, cmd, board, link_pdf, &mut slices)?;
|
||||
let l = load_into(p, cmd, board, link_pdf, given, &mut slices)?;
|
||||
Ok((l, slices))
|
||||
}
|
||||
|
||||
@@ -197,9 +197,10 @@ fn load_sliced(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool) -> Res
|
||||
/// (unless the params name their own box). A PDF/.ai page or an EPS file read from a path is placed
|
||||
/// linked with Link when `link_pdf` (false for the queries, which read it embedded). A PSD or PSB
|
||||
/// file's slices go to `slices`. A file an importer plug-in places (the one `importer` names, or one
|
||||
/// no built-in format reads) is read by it ([`plugin_art`]).
|
||||
fn load_into(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, slices_out: &mut Slices) -> Result<Loaded> {
|
||||
let src = fileio::importer::place_source(p, cmd)?;
|
||||
/// no built-in format reads) is read by it ([`plugin_art`]). `given`: the bytes of the file `p`'s
|
||||
/// `path` names, read already ([`PlaceJob::with_bytes`]).
|
||||
fn load_into(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, given: Option<&[u8]>, slices_out: &mut Slices) -> Result<Loaded> {
|
||||
let src = fileio::importer::place_source(p, cmd, given)?;
|
||||
let name = fileio::file_name(src.name);
|
||||
if let Some(plugin) = fileio::importer::named_for_place(src.name, p, cmd)? {
|
||||
return plugin_art(name, src.name, &src.bytes, &plugin, p, cmd);
|
||||
@@ -238,11 +239,14 @@ fn load_into(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, slices_o
|
||||
}
|
||||
return Ok(Loaded { name, format: &doc::FORMAT, art: Art::Text(story), natural: TEXT_FRAME, warnings, link: None, board: None });
|
||||
}
|
||||
let Some(format) = fileio::detect(src.name, &src.bytes) else {
|
||||
return match fileio::importer::for_place(src.name) {
|
||||
Some(plugin) => plugin_art(name, src.name, &src.bytes, &plugin, p, cmd),
|
||||
None => Err(bad(cmd, format!("can't place `{name}`: not a format VectorCraft reads (see document.formats)"))),
|
||||
};
|
||||
let format = fileio::detect(src.name, &src.bytes);
|
||||
if format.is_none_or(|f| !fileio::reads(f))
|
||||
&& let Some(plugin) = fileio::importer::for_place(src.name)
|
||||
{
|
||||
return plugin_art(name, src.name, &src.bytes, &plugin, p, cmd);
|
||||
}
|
||||
let Some(format) = format else {
|
||||
return Err(bad(cmd, format!("can't place `{name}`: not a format VectorCraft reads (see document.formats)")));
|
||||
};
|
||||
let page = match p.get("page") {
|
||||
None => 1,
|
||||
@@ -760,8 +764,13 @@ pub struct PlaceJob {
|
||||
/// The object Replace swaps as it was when Place started.
|
||||
replaced: Option<Node>,
|
||||
target: Option<Rect>,
|
||||
/// The bytes of the file `path` names, read already ([`PlaceJob::with_bytes`]).
|
||||
bytes: Option<GivenBytes>,
|
||||
}
|
||||
|
||||
/// The bytes of a file read already, shared with whoever read them ([`PlaceJob::with_bytes`]).
|
||||
pub type GivenBytes = Arc<dyn AsRef<[u8]> + Send + Sync>;
|
||||
|
||||
/// A file [`PlaceJob::read`] read, which [`Session::place_read`] places.
|
||||
pub struct PlaceRead {
|
||||
job: PlaceJob,
|
||||
@@ -775,6 +784,14 @@ impl PlaceJob {
|
||||
str_param(&self.params, "path").or_else(|| str_param(&self.params, "name")).map(fileio::file_name).unwrap_or_else(|| "Untitled".into())
|
||||
}
|
||||
|
||||
/// The job placing `bytes` as the file its `path` names, which [`PlaceJob::read`] then does not
|
||||
/// read again: the placed object's link and the journaled params keep the path. Without a
|
||||
/// `path` the bytes are not used.
|
||||
pub fn with_bytes(mut self, bytes: GivenBytes) -> Self {
|
||||
self.bytes = Some(bytes);
|
||||
self
|
||||
}
|
||||
|
||||
/// Read and decode the file, as `file.place` does, without the session. The pixels of a PNG,
|
||||
/// JPEG, GIF or WebP file are decoded here to check that they can be read (an error when they
|
||||
/// can't), a linked image's preview is made from that decode, and the decoded pixels are kept in
|
||||
@@ -782,7 +799,7 @@ impl PlaceJob {
|
||||
/// ([`super::links::readable_and_kept`]).
|
||||
pub fn read(self) -> Result<PlaceRead> {
|
||||
crate::cancel::check()?;
|
||||
let (mut loaded, slices) = load_sliced(&self.params, PLACE, self.target, true)?;
|
||||
let (mut loaded, slices) = load_sliced(&self.params, PLACE, self.target, true, self.bytes.as_deref().map(AsRef::as_ref))?;
|
||||
let linked = loaded.link.is_some() && bool_or(&self.params, "link", true);
|
||||
match &mut loaded.art {
|
||||
Art::Image(img, _) => {
|
||||
@@ -941,12 +958,12 @@ fn prepare(s: &Session, p: &Value) -> Result<PlaceJob> {
|
||||
(true, _) => return Err(bad(PLACE, "replace: select the one object to replace")),
|
||||
};
|
||||
let replaced = old.and_then(|id| st.doc.node(id)).cloned();
|
||||
Ok(PlaceJob { doc: st.uid, params: s.prefs.with_pdf_font_choice(p), old, replaced, target: board_at(&st.doc, at) })
|
||||
Ok(PlaceJob { doc: st.uid, params: s.prefs.with_pdf_font_choice(p), old, replaced, target: board_at(&st.doc, at), bytes: None })
|
||||
}
|
||||
|
||||
/// Place the file `read` holds in the active document.
|
||||
fn apply(s: &mut Session, read: PlaceRead) -> Result<Value> {
|
||||
let PlaceRead { job: PlaceJob { params, old, target: read_for, .. }, mut loaded, slices: read_slices } = read;
|
||||
let PlaceRead { job: PlaceJob { params, old, target: read_for, bytes, .. }, mut loaded, slices: read_slices } = read;
|
||||
let p = ¶ms;
|
||||
let template = bool_or(p, "template", false);
|
||||
let at = at_param(p)?;
|
||||
@@ -957,10 +974,11 @@ fn apply(s: &mut Session, read: PlaceRead) -> Result<Value> {
|
||||
None => None,
|
||||
};
|
||||
// The artboard under `at` as it is now, as a replay of the journal finds it: a DXF drawing laid
|
||||
// out on the artboard it was read for is read again when that artboard changed meanwhile.
|
||||
// out on the artboard it was read for is read again when that artboard changed meanwhile, from
|
||||
// the same bytes when the job was given them.
|
||||
let target = board_at(&st.doc, at);
|
||||
if loaded.board.is_some() && target != read_for {
|
||||
loaded = load(p, PLACE, target, true)?;
|
||||
loaded = load_into(p, PLACE, target, true, bytes.as_deref().map(AsRef::as_ref), &mut vec![])?;
|
||||
}
|
||||
// Type reflows rather than scales: its frame takes the size it is placed at.
|
||||
let is_text = matches!(loaded.art, Art::Text(_));
|
||||
@@ -1347,7 +1365,7 @@ pub fn read_info(p: &Value) -> Result<Value> {
|
||||
check_switches(p, &["link"], "file.place.info")?;
|
||||
check_numbers(p, &["thumbnail"], "file.place.info")?;
|
||||
// A PDF/.ai page linked or not has the same size and art.
|
||||
let (mut l, slices) = load_sliced(p, "file.place.info", None, false)?;
|
||||
let (mut l, slices) = load_sliced(p, "file.place.info", None, false, None)?;
|
||||
let natural = l.natural;
|
||||
let mut out = json!({
|
||||
"name": l.name,
|
||||
|
||||
@@ -603,12 +603,19 @@ fn collect_resources(src: &Document, nodes: &mut [Node], composites: bool) -> (U
|
||||
pub(crate) fn adopt(dst: &mut Document, src: &Document, nodes: &mut [Node], cmd: &str) -> Result<()> {
|
||||
let composites = !src.composite_fonts.is_empty() || !dst.composite_fonts.is_empty();
|
||||
let (used, mut src_brushes, families, dimension_families) = collect_resources(src, nodes, composites);
|
||||
let fonts = src.composite_fonts.iter().filter(|font| families.contains(&font.name.to_lowercase())).cloned().collect::<Vec<_>>();
|
||||
// The source's type was measured without its composite fonts that fail their checks or are
|
||||
// named like an installed font (the font database does not lend them), so they don't come in.
|
||||
let db = vectorcraft_text::FontDb::global();
|
||||
let fonts = src
|
||||
.composite_fonts
|
||||
.iter()
|
||||
.filter(|font| families.contains(&font.name.to_lowercase()) && font.check().is_ok() && !db.has_installed_family(&font.name))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
// A family the source does not define as a composite font, which the destination defines as
|
||||
// one, would draw in the destination's composite font after placement.
|
||||
let undefined_clash = families
|
||||
.iter()
|
||||
.any(|family| CompositeFont::named(&src.composite_fonts, family).is_none() && CompositeFont::named(&dst.composite_fonts, family).is_some());
|
||||
let undefined_clash =
|
||||
families.iter().any(|family| CompositeFont::named(&fonts, family).is_none() && CompositeFont::named(&dst.composite_fonts, family).is_some());
|
||||
// All representability/validation errors precede incoming or destination mutation.
|
||||
let plan = if fonts.is_empty() && !undefined_clash { None } else { Some(plan_import(fonts, families, dimension_families, dst, cmd)?) };
|
||||
let staged;
|
||||
|
||||
@@ -118,7 +118,7 @@ pub struct DocState {
|
||||
/// pasted bitmap) is dropped when this has changed by the time it finishes; edits do not
|
||||
/// change it, and a batch that fails puts it back with the document.
|
||||
pub reverts: u64,
|
||||
/// Advances when Undo or Redo restores an older document snapshot. The same node ID can name different objects
|
||||
/// Advances when Undo, Redo or a canceled undo group restores an older document snapshot. The same node ID can name different objects
|
||||
/// across that boundary.
|
||||
pub history_restores: u64,
|
||||
/// Preferences › User Interface › Open Documents As Tabs when the document opened: cleared,
|
||||
|
||||
@@ -19,6 +19,10 @@ pub struct Interaction {
|
||||
/// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an
|
||||
/// interaction runs its commands inside it.
|
||||
pub(crate) tool: bool,
|
||||
/// A dialog's live preview began it: a command from outside the dialog runs as a step of its
|
||||
/// own under it, as it does under a drag, so the next preview, OK and Cancel keep its edit
|
||||
/// (a `file.*` command still runs inside it).
|
||||
pub dialog: bool,
|
||||
/// A tool began or joined this interaction through `Action::Begin`.
|
||||
pub(crate) tool_joined: bool,
|
||||
/// A replaced or canceled preview restores these new-art paints from before the interaction.
|
||||
@@ -100,6 +104,10 @@ pub(crate) struct HeldInteraction {
|
||||
/// The new-art paints when the command began: a change the command makes to them stays when
|
||||
/// the interaction's next preview or a cancel puts back the paints it began with.
|
||||
pub(crate) paint: vectorcraft_tools::PaintDefaults,
|
||||
/// The command's own selection steps went into the journal before it ran.
|
||||
pub(crate) journaled: bool,
|
||||
/// The command returned an error.
|
||||
pub(crate) refused: bool,
|
||||
}
|
||||
|
||||
/// The per-document state an interaction puts back when it is canceled, besides the document and
|
||||
|
||||
@@ -98,6 +98,10 @@ pub struct ScriptDialog {
|
||||
/// `showColorPicker`: the run's active document is in CMYK when the picker opens, so the app
|
||||
/// gives an RGB pick back as CMYK. False for the other dialogs.
|
||||
pub cmyk_document: bool,
|
||||
/// `showColorPicker`: the RGB and CMYK profiles the run's active document is assigned (`None`:
|
||||
/// none) when the picker opens, which the app converts the pick through. `(None, None)` for the
|
||||
/// other dialogs.
|
||||
pub profiles: (Option<String>, Option<String>),
|
||||
}
|
||||
|
||||
/// The answer to a [`ScriptDialog`].
|
||||
@@ -705,7 +709,10 @@ fn open(host: &Host, kind: DialogKind, args: &[Data]) -> Result<Data, HostError>
|
||||
if preset.len() > MAX_PROMPT_BYTES {
|
||||
return Err(HostError::Range(format!("{name}: the text the field starts with is longer than 16 KiB")));
|
||||
}
|
||||
wait_or_answer(host, ScriptDialog { kind, message, title, error_icon, no_as_default, preset, color: None, cmyk_document: false })
|
||||
wait_or_answer(
|
||||
host,
|
||||
ScriptDialog { kind, message, title, error_icon, no_as_default, preset, color: None, cmyk_document: false, profiles: (None, None) },
|
||||
)
|
||||
}
|
||||
|
||||
/// `app.showColorPicker(color)`: the Color Picker on `color`. It returns the color picked for OK,
|
||||
@@ -713,7 +720,11 @@ fn open(host: &Host, kind: DialogKind, args: &[Data]) -> Result<Data, HostError>
|
||||
pub(super) fn show_color_picker(host: &Host, color: Color) -> Result<Data, HostError> {
|
||||
// During a slice the session holds the run's working copy, whose active document may be one
|
||||
// the script made; between slices the app sees the documents as they were before the run.
|
||||
let cmyk_document = host.session.borrow().active().is_some_and(|s| s.doc.color_mode == crate::doc::ColorMode::Cmyk);
|
||||
let (cmyk_document, profiles) = host
|
||||
.session
|
||||
.borrow()
|
||||
.active()
|
||||
.map_or((false, (None, None)), |s| (s.doc.color_mode == crate::doc::ColorMode::Cmyk, crate::cmd::colormgmt::doc_profiles(&s.doc)));
|
||||
let dialog = ScriptDialog {
|
||||
kind: DialogKind::ColorPicker,
|
||||
message: String::new(),
|
||||
@@ -723,6 +734,7 @@ pub(super) fn show_color_picker(host: &Host, color: Color) -> Result<Data, HostE
|
||||
preset: String::new(),
|
||||
color: Some(color),
|
||||
cmyk_document,
|
||||
profiles,
|
||||
};
|
||||
wait_or_answer(host, dialog)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ pub(super) use colors::of_color as color_data;
|
||||
#[cfg(test)]
|
||||
pub(crate) use paths::index_builds;
|
||||
#[cfg(test)]
|
||||
pub(crate) use paths::{PATH_LIST_BUILDS, POINT_LOOKS};
|
||||
pub(crate) use paths::{PATH_LIST_BUILDS, POINT_LOOKS, REMOVE_ALL_VISITS};
|
||||
|
||||
pub(super) use resources::{Kind as ResourceKind, gone as resources_gone, held as holds_resources};
|
||||
pub use variables::{MAX_HANDLES, STALE_DATASET, STALE_VARIABLE};
|
||||
|
||||
@@ -707,14 +707,20 @@ fn items_index(h: &super::Host, a: &[Data]) -> Answer {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// How many objects [`items_remove_all`] walked on this thread, for the tests.
|
||||
pub(crate) static REMOVE_ALL_VISITS: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// `pathItems.removeAll()`: deletes every path the collection lists in one command. A hidden or
|
||||
/// locked path, one in a hidden or locked layer or group, or one on a locked artboard stops it
|
||||
/// before anything is deleted, as `PageItems.removeAll()` does. A compound path's
|
||||
/// `pathItems.removeAll()` leaves the compound path, empty, as `remove()` of its last path does.
|
||||
/// It also throws and deletes nothing when it would delete the clipping path of a group or layer
|
||||
/// that keeps other objects, or leave a compound path or group that clips one with no visible path
|
||||
/// or visible type that lays out glyphs to clip by, or leave an image first in an ordinary group
|
||||
/// named as a tracing.
|
||||
/// that keeps other objects, or leave a compound path or group that clips one with no visible path,
|
||||
/// image, placed document or visible type that lays out glyphs to clip by, or leave an image first
|
||||
/// in an ordinary group named as a tracing.
|
||||
fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
let (doc, c) = items_scope(h, a)?;
|
||||
let (ids, refused, on_locked, masks, tracing) = with_doc(h, doc, |_, st| {
|
||||
@@ -728,9 +734,42 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
let refused: Vec<u64> = ids.iter().filter(|i| !editable(d, **i)).map(|i| i.0).take(20).collect();
|
||||
let locks = d.locked_artboards();
|
||||
let on_locked: Vec<u64> = ids.iter().filter(|i| locks.holds_id(**i)).map(|i| i.0).take(20).collect();
|
||||
let mut next: Vec<_> = d.layers.iter().collect();
|
||||
// The document's list is checked against every object. A layer's or group's list is checked
|
||||
// against the container's subtree, or, when the container lies in the clipping path of a
|
||||
// clipping group above it, against the subtree of the highest such clipping path and the
|
||||
// group it clips; no other outline holds its paths. An empty list is not walked.
|
||||
let mut next: Vec<&Arc<crate::doc::Node>> = Vec::new();
|
||||
let mut nodes = Vec::new();
|
||||
if !ids.is_empty() {
|
||||
match c.and_then(|c| d.index_path(c)) {
|
||||
None => next.extend(d.layers.iter()),
|
||||
Some(at) => {
|
||||
// A damaged file can give two objects one id; a path that the id finds outside
|
||||
// the container would be deleted in place of the container's own.
|
||||
if let Some(id) = ids.iter().find(|i| d.index_path(**i).is_none_or(|p| p.len() != at.len() + 1 || !p.starts_with(&at))) {
|
||||
return Err(HostError::Error(format!("cannot delete PathItem {}: its id also names another object", id.0)));
|
||||
}
|
||||
let mut line: Vec<&Arc<crate::doc::Node>> = Vec::with_capacity(at.len());
|
||||
let mut kids = d.layers.as_slice();
|
||||
for &i in &at {
|
||||
let Some(n) = kids.get(i) else { break };
|
||||
line.push(n);
|
||||
kids = n.children().map_or(&[][..], Vec::as_slice);
|
||||
}
|
||||
// A clipping path is its group's first child, found by place, not by id.
|
||||
let clip = (1..line.len()).find(|&k| line[k - 1].clips() && at[k] == 0);
|
||||
if let Some(k) = clip {
|
||||
#[cfg(test)]
|
||||
REMOVE_ALL_VISITS.with(|v| v.set(v.get() + 1));
|
||||
nodes.push(line[k - 1]);
|
||||
}
|
||||
next.extend(line.get(clip.unwrap_or(line.len().saturating_sub(1))).copied());
|
||||
}
|
||||
}
|
||||
}
|
||||
while let Some(n) = next.pop() {
|
||||
#[cfg(test)]
|
||||
REMOVE_ALL_VISITS.with(|v| v.set(v.get() + 1));
|
||||
nodes.push(n);
|
||||
next.extend(n.children().into_iter().flatten());
|
||||
}
|
||||
@@ -766,12 +805,15 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
if c.is_none() && matches!(n.kind, NodeKind::Compound { .. }) && !kids.is_empty() && kids.iter().all(|k| going.contains(&k.id)) {
|
||||
going.insert(n.id);
|
||||
}
|
||||
// A clip outline takes in visible paths and the glyphs of visible type, as
|
||||
// `push_clip_shapes` does; type that lays out no glyphs (blank, or overset) gives no
|
||||
// outline. A list marker is a glyph too, so whitespace-only type is laid out as well.
|
||||
// A clip outline takes in visible paths, the frames of visible images and placed
|
||||
// documents that enclose an area, and the glyphs of visible type, as `push_clip_shapes` does; type that lays
|
||||
// out no glyphs (blank, or overset) gives no outline. A list marker is a glyph too, so
|
||||
// whitespace-only type is laid out as well.
|
||||
let shape = n.visible
|
||||
&& match &n.kind {
|
||||
NodeKind::Path { .. } => true,
|
||||
// A frame collapsed to a line or a point encloses nothing to clip by.
|
||||
NodeKind::Image(_) | NodeKind::PlacedDocument(_) => n.clip_shapes(None).iter().any(|(frame, _)| encloses(frame)),
|
||||
NodeKind::Text(t) => {
|
||||
in_mask.contains(&n.id) && !vectorcraft_text::layout(vectorcraft_text::FontDb::global(), t).to_bezpath().elements().is_empty()
|
||||
}
|
||||
@@ -783,10 +825,18 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
if n.visible && ((shape && !going.contains(&n.id)) || inner) {
|
||||
geometry.insert(n.id);
|
||||
}
|
||||
// The live geometry effects of what stays in the clipping path reshape the region it
|
||||
// clips by, as the renderer draws it; deleting paths that lets an effect shrink the
|
||||
// region to nothing leaves no outline. A region that was empty before is left as it is.
|
||||
// The region is the area the outline fills under its fill rule, so outlines that run
|
||||
// opposite ways over the same area under nonzero fill nothing.
|
||||
let reshaped_empty = |m: &vectorcraft_doc::Node| {
|
||||
vectorcraft_render::effects::reshaped_clip_outline(m).is_some_and(|o| !o.is_some_and(|(bp, rule)| fills(&bp, rule)))
|
||||
};
|
||||
if n.clips()
|
||||
&& let Some(mask) = kids.first()
|
||||
&& affected.contains(&mask.id)
|
||||
&& !geometry.contains(&mask.id)
|
||||
&& (!geometry.contains(&mask.id) || (reshaped_empty(&without(mask, &going, &affected)) && !reshaped_empty(mask)))
|
||||
&& kids.iter().skip(1).any(|k| !going.contains(&k.id) && !matches!(k.kind, NodeKind::RulerGuide { .. }))
|
||||
&& masks.len() < 20
|
||||
{
|
||||
@@ -817,6 +867,57 @@ fn items_remove_all(h: &super::Host, a: &[Data]) -> Answer {
|
||||
Ok(Data::Undefined)
|
||||
}
|
||||
|
||||
/// Whether a subpath of `outline` encloses an area. Each subpath's area is measured from its first
|
||||
/// point, so its position does not change the result, and an area within roundoff of its own
|
||||
/// bounding box's is counted as none.
|
||||
fn encloses(outline: &kurbo::BezPath) -> bool {
|
||||
let mut subpaths: Vec<kurbo::BezPath> = Vec::new();
|
||||
for el in outline.elements() {
|
||||
if matches!(el, kurbo::PathEl::MoveTo(_)) || subpaths.is_empty() {
|
||||
subpaths.push(kurbo::BezPath::new());
|
||||
}
|
||||
if let Some(last) = subpaths.last_mut() {
|
||||
last.push(*el);
|
||||
}
|
||||
}
|
||||
subpaths.into_iter().any(|mut sub| {
|
||||
let Some(start) = sub.elements().iter().find_map(|e| e.end_point()) else { return false };
|
||||
sub.apply_affine(kurbo::Affine::translate(-start.to_vec2()));
|
||||
let area = kurbo::Shape::area(&sub).abs();
|
||||
area > 0.0 && area > 64.0 * f64::EPSILON * kurbo::Shape::bounding_box(&sub).area()
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `outline` fills an area under `rule`: a subpath encloses an area ([`encloses`]) and the
|
||||
/// outline with its overlaps resolved, thin strips included, has an area. An outline the path
|
||||
/// operations refuse is judged by [`encloses`] alone.
|
||||
fn fills(outline: &kurbo::BezPath, rule: vectorcraft_geom::FillRule) -> bool {
|
||||
if !encloses(outline) {
|
||||
return false;
|
||||
}
|
||||
match vectorcraft_pathops::try_area(&vectorcraft_geom::PathData::from_bezpath(outline), rule) {
|
||||
Ok(area) => area > 0.0,
|
||||
Err(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// `n` without the members in `going`, at every depth. Only the members in `affected` (those that
|
||||
/// hold a member in `going`) are copied; the others are shared.
|
||||
fn without(
|
||||
n: &vectorcraft_doc::Node,
|
||||
going: &std::collections::HashSet<NodeId>,
|
||||
affected: &std::collections::HashSet<NodeId>,
|
||||
) -> vectorcraft_doc::Node {
|
||||
let mut m = n.clone();
|
||||
if let Some(kids) = m.children_mut() {
|
||||
kids.retain(|k| !going.contains(&k.id));
|
||||
for k in kids.iter_mut().filter(|k| affected.contains(&k.id)) {
|
||||
*k = Arc::new(without(k, going, affected));
|
||||
}
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
/// The id in the JSON result of a command that made an object, read exactly, as the text creators
|
||||
/// read it.
|
||||
fn made_id(r: &(Data, Value)) -> std::result::Result<NodeId, HostError> {
|
||||
|
||||
@@ -281,6 +281,7 @@ fn set_warning(h: &Host, on: bool) -> Answer {
|
||||
preset: String::new(),
|
||||
color: None,
|
||||
cmyk_document: false,
|
||||
profiles: (None, None),
|
||||
};
|
||||
if !h.dialogs.ask(question, OnYes::ExternalScriptWarningOff) {
|
||||
return Err(HostError::Error(WARNING_OFF_NEEDS_A_PERSON.into()));
|
||||
|
||||
@@ -343,19 +343,26 @@ impl Session {
|
||||
/// it updates Recent Colors and converts or remaps the new-art paints at once, as it does with
|
||||
/// no drag in progress.
|
||||
///
|
||||
/// The interaction stays as it is, and the command runs inside it, for an interaction a dialog
|
||||
/// or a panel began (it builds its preview from commands), for typing in progress
|
||||
/// A dialog's live preview ([`crate::Interaction::dialog`]) is set aside the same way, except
|
||||
/// for a command that acts on the drawing on show ([`reads_preview`]). Outside commands use
|
||||
/// the shown selection with objects absent from the base document removed, and without a path
|
||||
/// whose selected anchors the preview renumbered. A selection of only preview objects becomes
|
||||
/// empty. The journal records that selection before the command, and records the dialog's
|
||||
/// own selection again when the command is refused. The interaction stays as it is, and the command runs
|
||||
/// inside it, for an interaction a panel or
|
||||
/// another dialog began (it builds its preview from commands), for typing in progress
|
||||
/// ([`Session::edit`] keeps it as a step of its own), for the Quick Pen (an edit made outside
|
||||
/// it ends the path it draws), and for a copy made with `object.transform` during a drag that
|
||||
/// copies (it copies the document as the drag's move left it). A command that settles,
|
||||
/// commits or cancels the interaction, or that hands the active tool actions to apply, gets it
|
||||
/// back first ([`Session::put_back_interaction`]), as it found it.
|
||||
pub(crate) fn outside_interaction(&mut self, id: &str, params: &Value, f: impl FnOnce(&mut Self) -> Result<Value>) -> Result<Value> {
|
||||
if cmd::typing_in_progress(self) || self.tool_id() == vectorcraft_tools::quickpen::ID {
|
||||
let dialog = self.active().and_then(|st| st.interaction.as_ref()).is_some_and(|it| it.dialog);
|
||||
if cmd::typing_in_progress(self) || (!dialog && self.tool_id() == vectorcraft_tools::quickpen::ID) {
|
||||
return f(self);
|
||||
}
|
||||
let Some(st) = self.active_mut() else { return f(self) };
|
||||
let Some(it) = st.interaction.as_ref().filter(|it| it.tool) else { return f(self) };
|
||||
let Some(it) = st.interaction.as_ref().filter(|it| it.tool || (it.dialog && !reads_preview(id))) else { return f(self) };
|
||||
// A drag that copies: its latest preview, applied or held back by Real-time Drawing off, copies.
|
||||
let copying = it.preview.as_ref().is_some_and(|(c, p)| c == "object.transform" && p.get("copy").and_then(Value::as_bool) == Some(true));
|
||||
if copying && id == "object.transform" && params.get("copy").and_then(Value::as_bool) == Some(true) {
|
||||
@@ -367,36 +374,57 @@ impl Session {
|
||||
let shown = previewed.then(|| (st.doc.clone(), st.selection.clone()));
|
||||
if previewed {
|
||||
st.doc = interaction.doc.clone();
|
||||
st.selection.clone_from(&interaction.selection);
|
||||
if let Some((shown_doc, _)) = shown.as_ref().filter(|_| interaction.dialog) {
|
||||
shown_base_selection(&mut st.selection, shown_doc, &st.doc);
|
||||
} else {
|
||||
st.selection.clone_from(&interaction.selection);
|
||||
}
|
||||
st.revision += 1;
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
// The journal holds the dialog's base selection, so the command replays on the one it acts on.
|
||||
let reselect = (interaction.dialog && st.selection != *interaction.selection)
|
||||
.then(|| selection_steps(&st.selection, &interaction.selection, &st.doc, st.active_layer, &st.highlighted_rows()));
|
||||
let (uid, state) = (st.uid, crate::interaction::ViewState::of(st));
|
||||
let paint = self.paint.clone();
|
||||
self.held_interaction = Some(crate::HeldInteraction { uid, interaction, shown, state, paint });
|
||||
let journaled = reselect.is_some();
|
||||
if let Some(steps) = reselect {
|
||||
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
|
||||
for step in steps {
|
||||
self.journal.push(step);
|
||||
}
|
||||
self.journal_in_undo_groups(Some(uid), &grouped, from);
|
||||
}
|
||||
self.held_interaction = Some(crate::HeldInteraction { uid, interaction, shown, state, paint, journaled, refused: false });
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
let r = f(self);
|
||||
if let Some(held) = self.held_interaction.as_mut().filter(|_| r.is_err()) {
|
||||
held.refused = true;
|
||||
}
|
||||
self.put_back_interaction();
|
||||
r
|
||||
}
|
||||
|
||||
/// Put back the interaction [`Session::outside_interaction`] set aside. When the command left
|
||||
/// the document and the selection as it found them, the preview on show before it is on show
|
||||
/// again. Otherwise the interaction starts from the document the command left and from its
|
||||
/// own selection, without the objects the command removed, hid or locked, and the preview that Real-time
|
||||
/// Drawing showed is applied to it again. The warning or the error of that preview goes to
|
||||
/// again. Otherwise a tool drag starts from the document the command left and from its own
|
||||
/// selection, without the objects the command removed, hid or locked. The preview that
|
||||
/// Real-time Drawing showed is applied to it again. The warning or the error of that preview goes to
|
||||
/// the command's result ([`Session::note_settled_warning`]); a preview that fails leaves the
|
||||
/// interaction with nothing to commit. An interaction whose document the command closed ends,
|
||||
/// and so does one with anchors or segments selected on a path the command changed in more
|
||||
/// than a move. A document
|
||||
/// the command left an interaction of its own on keeps that one.
|
||||
/// than a move. A document the command left an interaction of its own on keeps that one.
|
||||
/// A dialog adopts the command's selection and paints and reruns its preview on its next pass.
|
||||
pub(crate) fn put_back_interaction(&mut self) {
|
||||
let Some(crate::HeldInteraction { uid, interaction: mut it, shown, state, paint }) = self.held_interaction.take() else { return };
|
||||
let Some(crate::HeldInteraction { uid, interaction: mut it, shown, state, paint, journaled, refused }) = self.held_interaction.take() else {
|
||||
return;
|
||||
};
|
||||
// A selection command loaded the paints of the selection it made into the fill and stroke
|
||||
// proxies. The drag goes on with its own selection, so they show its paints again.
|
||||
if self.paint != paint
|
||||
if !it.dialog
|
||||
&& self.paint != paint
|
||||
&& let Some(st) = self.active_mut().filter(|d| d.uid == uid && d.interaction.is_none())
|
||||
{
|
||||
let own = drag_selection(&it.selection, &st.doc);
|
||||
@@ -450,7 +478,19 @@ impl Session {
|
||||
// isolation stays when the interaction is canceled.
|
||||
state.rebase(crate::interaction::ViewState::of(st), &mut it);
|
||||
let previewed = shown.is_some();
|
||||
if Arc::ptr_eq(&st.doc, &it.doc) && st.selection == *it.selection {
|
||||
// A refused command leaves the selection it was given: a dialog's is the one on show without
|
||||
// preview objects. A command that ran (Deselect) and left that selection keeps it.
|
||||
let given = match shown.as_ref().filter(|_| it.dialog && refused) {
|
||||
Some((shown_doc, selection)) => {
|
||||
let mut given = selection.clone();
|
||||
shown_base_selection(&mut given, shown_doc, &it.doc);
|
||||
given
|
||||
}
|
||||
None => (*it.selection).clone(),
|
||||
};
|
||||
if Arc::ptr_eq(&st.doc, &it.doc) && st.selection == given {
|
||||
// The journal goes back to the dialog's base selection, as the preview on show again holds it.
|
||||
let back = (journaled && active).then(|| selection_steps(&it.selection, &given, &st.doc, st.active_layer, &st.highlighted_rows()));
|
||||
if let Some((doc, selection)) = shown {
|
||||
st.doc = doc;
|
||||
st.selection = selection;
|
||||
@@ -458,6 +498,13 @@ impl Session {
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
st.interaction = Some(it);
|
||||
if let Some(steps) = back {
|
||||
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
|
||||
for step in steps {
|
||||
self.journal.push(step);
|
||||
}
|
||||
self.journal_in_undo_groups(Some(uid), &grouped, from);
|
||||
}
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
@@ -472,8 +519,17 @@ impl Session {
|
||||
}
|
||||
let began = std::mem::replace(&mut it.doc, st.doc.clone());
|
||||
// The drag acts on the objects it began with: a selection the command made (a paste, a
|
||||
// duplicate, Select All) does not change what the drag moves.
|
||||
it.selection = Arc::new(drag_selection(&it.selection, &st.doc));
|
||||
// duplicate, Select All) does not change what the drag moves. A dialog's preview acts on
|
||||
// the selection the command left, and its dialog previews again on its next pass, from the
|
||||
// values it shows then, so nothing is applied here.
|
||||
if it.dialog {
|
||||
if st.selection != *it.selection {
|
||||
it.selection = Arc::new(st.selection.clone());
|
||||
}
|
||||
it.preview = None;
|
||||
} else {
|
||||
it.selection = Arc::new(drag_selection(&it.selection, &st.doc));
|
||||
}
|
||||
// The journal holds the selection the command left. The drag's own selection is journaled
|
||||
// after it, so the drag and the commands after it replay on the objects they act on.
|
||||
let reselect = (active && st.selection != *it.selection)
|
||||
@@ -569,6 +625,7 @@ impl Session {
|
||||
revision: st.revision,
|
||||
preview: None,
|
||||
tool: false,
|
||||
dialog: false,
|
||||
tool_joined: false,
|
||||
paint,
|
||||
used_defaults_only: false,
|
||||
@@ -944,6 +1001,39 @@ fn take_changed_paints(
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether command `id` acts on the drawing as a dialog's preview shows it (a copy, a save, a
|
||||
/// revert), so it runs inside that preview rather than as a step of its own.
|
||||
fn reads_preview(id: &str) -> bool {
|
||||
id == "edit.copy" || (id.starts_with("file.") && id != "file.documentColorMode")
|
||||
}
|
||||
|
||||
/// The selection on show in a dialog's preview `shown`, as a command from outside the dialog acts
|
||||
/// on it in the base document `base`: without the objects the preview made, and without a path
|
||||
/// whose selected anchors or segments are numbered in a shape the preview changed in more than a
|
||||
/// move (Set Corners recut it), since those numbers can name other points in `base`.
|
||||
fn shown_base_selection(selection: &mut Selection, shown: &Document, base: &Document) {
|
||||
selection.prune(base);
|
||||
let recut: Vec<_> = selection
|
||||
.anchors
|
||||
.keys()
|
||||
.chain(selection.segments.keys())
|
||||
.copied()
|
||||
.filter(|&id| {
|
||||
let path = |d: &Document| d.node(id).and_then(|n| n.path_data()).map(|p| p.subpaths.clone());
|
||||
match (path(shown), path(base)) {
|
||||
(Some(now), Some(was)) => !moved_whole(&was, &now),
|
||||
(now, was) => now.is_some() != was.is_some(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
for id in recut {
|
||||
selection.objects.retain(|o| *o != id);
|
||||
selection.anchors.remove(&id);
|
||||
selection.segments.remove(&id);
|
||||
}
|
||||
selection.prune(base);
|
||||
}
|
||||
|
||||
/// The selection a drag began with, without the objects that a command run during it removed,
|
||||
/// hid or locked in `doc`.
|
||||
fn drag_selection(began: &Selection, doc: &Document) -> Selection {
|
||||
|
||||
@@ -123,6 +123,7 @@ impl Session {
|
||||
st.sync_new_art();
|
||||
cmd::globaledit::follow_history(st);
|
||||
st.drop_stale_variables_highlight();
|
||||
st.history_restores += 1;
|
||||
st.revision += 1;
|
||||
// The journal drops only the canceled groups' own entries and keeps the ones made in other documents meanwhile.
|
||||
journal.extend(g.journal);
|
||||
@@ -280,6 +281,9 @@ impl Session {
|
||||
st.drop_stale_variables_highlight();
|
||||
deselect_hidden(&menu, &st.doc, &mut st.selection);
|
||||
st.history.recost_last(&st.doc);
|
||||
if !Arc::ptr_eq(&undone, &st.doc) {
|
||||
st.history_restores += 1;
|
||||
}
|
||||
st.revision += 1;
|
||||
if colors_changed {
|
||||
self.paint = scope.paint;
|
||||
|
||||
@@ -180,6 +180,106 @@ fn reverse_path_direction_on_and_off_set_the_winding() {
|
||||
assert!(s.execute("path.reverse", &json!({})).is_err(), "nothing to reverse");
|
||||
}
|
||||
|
||||
/// Points of what is direct-selected on one path, rounded to whole points.
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Picked {
|
||||
/// The selected anchors' points, sorted.
|
||||
anchors: Vec<(i64, i64)>,
|
||||
/// The end points of the selected segments, each pair and the list sorted.
|
||||
segments: Vec<[(i64, i64); 2]>,
|
||||
/// The key anchor's point, when the key anchor is on the path.
|
||||
key: Option<(i64, i64)>,
|
||||
}
|
||||
|
||||
/// What is direct-selected on path `id`, as points.
|
||||
fn picked_points(s: &Session, id: NodeId) -> Picked {
|
||||
let st = s.doc().unwrap();
|
||||
let sp = &st.doc.node(id).unwrap().path_data().unwrap().subpaths;
|
||||
let at = |(si, ai): (usize, usize)| {
|
||||
let p = sp[si].anchors[ai].p;
|
||||
(p.x.round() as i64, p.y.round() as i64)
|
||||
};
|
||||
let mut anchors: Vec<_> = st.selection.anchors.get(&id).into_iter().flatten().map(|r| at(*r)).collect();
|
||||
anchors.sort_unstable();
|
||||
let mut segments: Vec<_> = st
|
||||
.selection
|
||||
.segments
|
||||
.get(&id)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|&(si, j)| {
|
||||
let mut ends = [at((si, j)), at((si, (j + 1) % sp[si].anchors.len()))];
|
||||
ends.sort_unstable();
|
||||
ends
|
||||
})
|
||||
.collect();
|
||||
segments.sort_unstable();
|
||||
let key = st.selection.key_anchor.filter(|(k, _)| *k == id).map(|(_, r)| at(r));
|
||||
Picked { anchors, segments, key }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reverse_path_direction_keeps_the_same_anchors_and_segments_direct_selected() {
|
||||
let mut s = session();
|
||||
let path = |s: &mut Session, anchors: Value, closed: bool| {
|
||||
NodeId(run(s, "path.create", json!({"anchors": anchors, "closed": closed}))["id"].as_u64().unwrap())
|
||||
};
|
||||
let open = path(&mut s, json!([{"x": 0, "y": 50}, {"x": 40, "y": 50}, {"x": 100, "y": 50}]), false);
|
||||
let closed = path(&mut s, json!([{"x": 10, "y": 10}, {"x": 90, "y": 10}, {"x": 90, "y": 90}, {"x": 10, "y": 90}]), true);
|
||||
run(&mut s, "select.anchorsMany", json!({"items": [{"id": open.0, "anchors": [[0, 0]]}, {"id": closed.0, "anchors": [[0, 1], [0, 2]]}]}));
|
||||
run(&mut s, "select.key", json!({"id": closed.0, "anchor": [0, 1]}));
|
||||
let before = [picked_points(&s, open), picked_points(&s, closed)];
|
||||
assert_eq!(before[0].anchors, [(0, 50)]);
|
||||
assert_eq!((before[1].anchors.clone(), before[1].key), (vec![(90, 10), (90, 90)], Some((90, 10))));
|
||||
assert_eq!(run(&mut s, "path.reverse", json!({}))["changed"], 2);
|
||||
let first = |s: &Session, id: NodeId| s.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().subpaths[0].anchors[0].p;
|
||||
assert_eq!((first(&s, open).x, first(&s, closed).y), (100.0, 90.0), "both paths turned");
|
||||
assert_eq!([picked_points(&s, open), picked_points(&s, closed)], before, "the same points stay direct-selected after Reverse Path Direction");
|
||||
// Undo turns the paths back with the selection they had.
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(first(&s, open).x, 0.0);
|
||||
assert_eq!([picked_points(&s, open), picked_points(&s, closed)], before, "undo");
|
||||
|
||||
// Selected segments, the closing segment of a closed path included, stay the same segments.
|
||||
run(&mut s, "select.segments", json!({"id": closed.0, "segments": [[0, 0], [0, 3]], "mode": "set"}));
|
||||
run(&mut s, "select.segments", json!({"id": open.0, "segments": [[0, 0]], "mode": "add"}));
|
||||
let before = [picked_points(&s, open), picked_points(&s, closed)];
|
||||
assert_eq!(before[0].segments, [[(0, 50), (40, 50)]]);
|
||||
assert_eq!(before[1].segments, [[(10, 10), (10, 90)], [(10, 10), (90, 10)]]);
|
||||
assert_eq!(run(&mut s, "path.reverse", json!({}))["changed"], 2);
|
||||
assert_eq!([picked_points(&s, open), picked_points(&s, closed)], before, "the same segments stay selected after Reverse Path Direction");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reverse_path_direction_of_one_subpath_leaves_the_others_selection_as_it_is() {
|
||||
let mut s = session();
|
||||
let id = NodeId(run(&mut s, "path.create", json!({"d": "M0 0 L40 0 L100 0 M0 200 L40 200 L100 200"}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "select.anchorsMany", json!({"items": [{"id": id.0, "anchors": [[0, 0], [1, 0]]}]}));
|
||||
run(&mut s, "select.key", json!({"id": id.0, "anchor": [0, 0]}));
|
||||
let before = picked_points(&s, id);
|
||||
assert_eq!((before.anchors.clone(), before.key), (vec![(0, 0), (0, 200)], Some((0, 0))));
|
||||
assert_eq!(run(&mut s, "path.reverse", json!({"subpath": 1}))["changed"], 1);
|
||||
let first = |s: &Session, si: usize| s.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().subpaths[si].anchors[0].p;
|
||||
assert_eq!((first(&s, 0).x, first(&s, 1).x), (0.0, 100.0), "only the second subpath turned");
|
||||
assert_eq!(picked_points(&s, id), before, "the same points stay direct-selected on both subpaths");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_anchor_point_keeps_the_key_anchor_on_its_point() {
|
||||
let mut s = session();
|
||||
let anchors = json!([{"x": 10, "y": 10}, {"x": 90, "y": 10}, {"x": 90, "y": 90}, {"x": 10, "y": 90}]);
|
||||
let id = NodeId(run(&mut s, "path.create", json!({"anchors": anchors, "closed": true}))["id"].as_u64().unwrap());
|
||||
run(&mut s, "select.anchorsMany", json!({"items": [{"id": id.0, "anchors": [[0, 1], [0, 2]]}]}));
|
||||
run(&mut s, "select.key", json!({"id": id.0, "anchor": [0, 2]}));
|
||||
let before = picked_points(&s, id);
|
||||
assert_eq!((before.anchors.clone(), before.key), (vec![(90, 10), (90, 90)], Some((90, 90))));
|
||||
run(&mut s, "path.insertAnchor", json!({"id": id.0, "segment": 0}));
|
||||
assert_eq!(s.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().subpaths[0].anchors.len(), 5);
|
||||
assert_eq!(picked_points(&s, id), before, "the key anchor and the selected anchors stay on their points after Add Anchor Point");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(picked_points(&s, id), before, "undo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reverse_path_direction_turns_the_width_profile_and_pen_records_with_the_path() {
|
||||
use vectorcraft_doc::{AngleProfile, PressureProfile, WidthProfile};
|
||||
|
||||
@@ -175,6 +175,32 @@ fn an_undo_group_lets_no_other_documents_steps_go_until_it_ends() {
|
||||
assert!(history_bytes(&s) <= s.history_budget);
|
||||
}
|
||||
|
||||
/// A canceled undo group, and a canceled undo scope that joined one, put back an older snapshot:
|
||||
/// both advance the document's history restores, as Undo does, and a kept one does not.
|
||||
#[test]
|
||||
fn canceled_undo_groups_and_scopes_count_as_history_restores() {
|
||||
let mut s = session_with_rects(2);
|
||||
let restores = |s: &Session| s.docs[0].history_restores;
|
||||
s.begin_undo_group();
|
||||
moves(&mut s, 2);
|
||||
s.end_undo_group(false);
|
||||
assert_eq!(restores(&s), 0, "a kept group restores nothing");
|
||||
s.begin_undo_group();
|
||||
moves(&mut s, 2);
|
||||
s.end_undo_group(true);
|
||||
assert_eq!(restores(&s), 1, "a canceled group");
|
||||
s.begin_undo_group();
|
||||
moves(&mut s, 1);
|
||||
let scope = s.begin_undo_scope().unwrap();
|
||||
moves(&mut s, 2);
|
||||
s.end_undo_scope(scope, true);
|
||||
assert_eq!(restores(&s), 2, "a canceled scope that joined the open group");
|
||||
let scope = s.begin_undo_scope().unwrap();
|
||||
s.end_undo_scope(scope, true);
|
||||
assert_eq!(restores(&s), 2, "a canceled scope that made no edit puts back the same snapshot");
|
||||
s.end_undo_group(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steps_kept_outside_a_command_keep_to_the_shared_budget() {
|
||||
let mut s = session_with_rects(50);
|
||||
|
||||
@@ -179,6 +179,7 @@ fn a_framed_run_waits_at_each_dialog_and_takes_the_persons_answer() {
|
||||
preset: String::new(),
|
||||
color: None,
|
||||
cmyk_document: false,
|
||||
profiles: (None, None),
|
||||
};
|
||||
assert_eq!(s.script_dialog(), Some(want));
|
||||
assert!(!s.script_answer(DialogAnswer::Ok), "an answer for another kind of dialog is refused");
|
||||
|
||||
@@ -4095,6 +4095,55 @@ const CAUGHT_PATHS_REMOVE_ALL: &str = "var p = app.activeDocument.pathItems, m =
|
||||
try { p.removeAll(); } catch (e) { m = e.message; }\
|
||||
vc.log(m); vc.log(p.length);";
|
||||
|
||||
/// A group's `pathItems.removeAll()` walks the group, not the document: emptying a group of two
|
||||
/// paths beside 500 other paths looks at a handful of objects, and an empty group's looks at none.
|
||||
#[test]
|
||||
fn group_path_items_remove_all_walks_only_the_group() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
for i in 0..500 {
|
||||
rect(&mut s, f64::from(i % 25) * 10.0, f64::from(i / 25) * 10.0, 5.0, 5.0);
|
||||
}
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let start = crate::script::dom::REMOVE_ALL_VISITS.with(|n| n.get());
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var g = app.activeDocument.groupItems[0]; g.pathItems.removeAll(); g.pathItems.removeAll();\
|
||||
vc.log(g.pathItems.length); vc.log(app.activeDocument.pathItems.length);",
|
||||
);
|
||||
let visits = crate::script::dom::REMOVE_ALL_VISITS.with(|n| n.get()) - start;
|
||||
assert_eq!(out, vec![json!(0), json!(500)]);
|
||||
assert!(visits <= 3, "{visits} objects walked to empty a group of two paths");
|
||||
}
|
||||
|
||||
/// In a damaged document where a path outside a group has the same id as a path in it, the
|
||||
/// group's `pathItems.removeAll()` throws and deletes nothing, instead of deleting the outside path.
|
||||
#[test]
|
||||
fn group_path_items_remove_all_refuses_an_id_found_outside_the_group() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let c = rect(&mut s, 200.0, 200.0, 20.0, 20.0);
|
||||
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
|
||||
s.execute("object.arrange.sendToBack", &json!({})).unwrap();
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let d = std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc);
|
||||
d.node_mut(c).unwrap().id = a;
|
||||
d.drop_lookup_cache();
|
||||
// The first object in tree order with the id is the one outside the group.
|
||||
assert_eq!(d.index_path(a).map(|p| p.len()), Some(2));
|
||||
let n = d.layers[0].children().map_or(0, Vec::len);
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var d = app.activeDocument, m = ''; try { d.groupItems[0].pathItems.removeAll(); } catch (e) { m = e.message; }\
|
||||
vc.log(m); vc.log(d.groupItems[0].pathItems.length);",
|
||||
);
|
||||
assert_eq!(out, vec![json!(format!("cannot delete PathItem {}: its id also names another object", a.0)), json!(2)]);
|
||||
let d = &s.active().unwrap().doc;
|
||||
assert_eq!(d.layers[0].children().map_or(0, Vec::len), n, "the path outside the group is kept");
|
||||
}
|
||||
|
||||
/// The document's `pathItems.removeAll()` refuses to delete the path that clips a group while the
|
||||
/// group keeps other art, and deletes nothing, as the scoped collections do.
|
||||
#[test]
|
||||
@@ -4420,6 +4469,103 @@ fn document_path_items_remove_all_refuses_to_empty_a_clipping_group_with_an_empt
|
||||
assert_eq!(undo_steps(&s), steps);
|
||||
}
|
||||
|
||||
/// An image's frame clips as a clipping path does, so a clipping group whose clipping path keeps
|
||||
/// an image still has an outline after its paths are deleted.
|
||||
#[test]
|
||||
fn document_path_items_remove_all_keeps_a_clipping_group_whose_clipping_path_keeps_an_image() {
|
||||
for frame in [Frame::Square, Frame::Line, Frame::Far, Frame::Inset, Frame::Mirrored, Frame::Strip] {
|
||||
remove_all_beside_an_image(frame);
|
||||
}
|
||||
}
|
||||
|
||||
/// The image frame of [`remove_all_beside_an_image`].
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum Frame {
|
||||
/// 40 pt square.
|
||||
Square,
|
||||
/// Collapsed to a line.
|
||||
Line,
|
||||
/// 1/64 pt square 3,500,000 pt from the origin.
|
||||
Far,
|
||||
/// 40 pt square with a live Offset Path of -30 pt, which leaves nothing.
|
||||
Inset,
|
||||
/// 40 pt square with a live Transform effect that adds one copy reflected about its center:
|
||||
/// the two outlines run opposite ways over the same area and fill nothing under nonzero.
|
||||
Mirrored,
|
||||
/// 40 pt square with a live Transform effect that scales it to 0.004 pt high, which still
|
||||
/// clips to a thin strip.
|
||||
Strip,
|
||||
}
|
||||
|
||||
/// A clipping group whose clipping path is a group of one path and an image with `frame`, then the
|
||||
/// document's `pathItems.removeAll()`.
|
||||
fn remove_all_beside_an_image(frame: Frame) {
|
||||
let flat = matches!(frame, Frame::Line | Frame::Inset | Frame::Mirrored);
|
||||
let (mut s, a, b) = doc();
|
||||
let t = NodeId(s.execute("text.create", &json!({"x": 10, "y": 250, "text": "hi"})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
let mask = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let image = s
|
||||
.edit("Place", |d, _| {
|
||||
let id = d.alloc_id();
|
||||
let im = vectorcraft_doc::ImageObject {
|
||||
key: "pic".into(),
|
||||
width: 4,
|
||||
height: 4,
|
||||
xf: match frame {
|
||||
Frame::Square | Frame::Inset | Frame::Mirrored | Frame::Strip => kurbo::Affine::scale(10.0),
|
||||
Frame::Line => kurbo::Affine::scale_non_uniform(10.0, 0.0),
|
||||
Frame::Far => kurbo::Affine::translate((3_500_000.0, 3_500_000.0)) * kurbo::Affine::scale(1.0 / 256.0),
|
||||
},
|
||||
link: None,
|
||||
placement: Default::default(),
|
||||
pixels: None,
|
||||
};
|
||||
d.insert(Some(mask), 0, vectorcraft_doc::Node::new(id, NodeKind::Image(Box::new(im))))?;
|
||||
Ok(id)
|
||||
})
|
||||
.unwrap();
|
||||
if frame == Frame::Inset {
|
||||
s.execute("effect.apply", &json!({"effect": "path.offsetPath", "params": {"offset": -30}, "ids": [image.0], "item": null})).unwrap();
|
||||
}
|
||||
if frame == Frame::Mirrored {
|
||||
s.execute(
|
||||
"effect.apply",
|
||||
&json!({"effect": "distort.transform", "params": {"reflectX": true, "copies": 1, "reference": 4}, "ids": [image.0], "item": null}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
if frame == Frame::Strip {
|
||||
s.execute("effect.apply", &json!({"effect": "distort.transform", "params": {"scaleV": 0.01}, "ids": [image.0], "item": null})).unwrap();
|
||||
}
|
||||
s.execute("select.set", &json!({"ids": [mask.0, t.0]})).unwrap();
|
||||
let outer = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
s.edit("Clip", |d, _| {
|
||||
if let Some(NodeKind::Group { children, clip }) = d.node_mut(outer).map(|n| &mut n.kind) {
|
||||
children.sort_by_key(|c| c.id != mask);
|
||||
*clip = true;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let before = s.active().unwrap().doc.clone();
|
||||
let out = log(&mut s, CAUGHT_PATHS_REMOVE_ALL);
|
||||
if flat {
|
||||
assert_eq!(
|
||||
out[0],
|
||||
json!(format!("cannot delete a clipping path while its group or layer keeps other objects; release the clipping mask first: {}", mask.0))
|
||||
);
|
||||
assert_eq!(s.active().unwrap().doc, before);
|
||||
return;
|
||||
}
|
||||
assert_eq!(out, [json!(""), json!(0)]);
|
||||
let d = &s.active().unwrap().doc;
|
||||
assert!(d.node(a).is_none() && d.node(b).is_none());
|
||||
assert!(d.node(outer).unwrap().clips());
|
||||
assert_eq!(d.parent_of(image), Some(mask));
|
||||
assert!(d.node(t).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn document_path_items_remove_all_keeps_empty_groups_but_removes_empty_compounds() {
|
||||
for compound in [false, true] {
|
||||
|
||||
@@ -106,6 +106,7 @@ fn yes_to_the_confirm_turns_the_warning_off() {
|
||||
preset: String::new(),
|
||||
color: None,
|
||||
cmyk_document: false,
|
||||
profiles: (None, None),
|
||||
};
|
||||
assert_eq!(s.script_dialog(), Some(want));
|
||||
assert!(s.script_dialog_turns_warning_off());
|
||||
|
||||
@@ -1160,7 +1160,7 @@ fn place_reads_what_open_reads_and_text_files() {
|
||||
assert_eq!(PLACE_EXTS, [OPEN_EXTS, TEXT_EXTS, RTF_EXTS, DOCX_EXTS, DOC_EXTS].concat());
|
||||
let filters: Vec<_> = cmd::fileio::place_filters().collect();
|
||||
let word: (&str, &[&str]) = ("Word", &["docx", "doc"]);
|
||||
assert_eq!((filters.first(), filters.last()), (Some(&("All placeable files", PLACE_EXTS)), Some(&word)));
|
||||
assert_eq!((filters.first(), filters.last()), (Some(&("All placeable files", cmd::fileio::place_exts())), Some(&word)));
|
||||
assert_eq!(filters.get(filters.len() - 3..), Some(&[("Text", TEXT_EXTS), ("RTF", RTF_EXTS), word][..]));
|
||||
assert!(
|
||||
!cmd::fileio::open_filters().any(|(_, exts)| ["txt", "rtf", "docx", "doc"].iter().any(|e| exts.contains(e))),
|
||||
|
||||
@@ -3711,12 +3711,20 @@ fn arb_dxf_entity() -> impl Strategy<Value = Vec<(i32, String)>> {
|
||||
"ATTRIB",
|
||||
"DIMENSION",
|
||||
"VIEWPORT",
|
||||
"REGION",
|
||||
]);
|
||||
let code = prop::sample::select(vec![
|
||||
2, 6, 7, 8, 10, 11, 12, 13, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 48, 50, 51, 60, 62, 66, 67, 70, 71, 72, 73, 74, 75, 76, 90, 91, 92, 93,
|
||||
94, 95, 96, 97, 210, 220, 230, 370, 420, 440, 450,
|
||||
1, 2, 3, 6, 7, 8, 10, 11, 12, 13, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 48, 50, 51, 60, 62, 66, 67, 70, 71, 72, 73, 74, 75, 76, 90, 91, 92,
|
||||
93, 94, 95, 96, 97, 210, 220, 230, 370, 420, 440, 450,
|
||||
]);
|
||||
let value = prop_oneof![arb_num(), Just("B".to_string()), Just("*U1".to_string()), Just(r"{\fA;x}\P%%c^".to_string())];
|
||||
let value = prop_oneof![
|
||||
arb_num(),
|
||||
Just("B".to_string()),
|
||||
Just("*U1".to_string()),
|
||||
Just(r"{\fA;x}\P%%c^".to_string()),
|
||||
Just("700 0 1 0".to_string()),
|
||||
Just("body $-1 -1 $-1 $0 $-1 $-1 #".to_string()),
|
||||
];
|
||||
(kind, prop::collection::vec((code, value), 0..24)).prop_map(|(k, g)| std::iter::once((0, k.to_string())).chain(g).collect())
|
||||
}
|
||||
|
||||
@@ -3730,6 +3738,107 @@ fn hostile_dxf(block: &[Vec<(i32, String)>], body: &[Vec<(i32, String)>]) -> Vec
|
||||
dxf_text(&all).into_bytes()
|
||||
}
|
||||
|
||||
/// A region's solid-modeler text data: one face whose loop is two lines and a quarter circle,
|
||||
/// (0, 0) to (100, 0), round to (0, 100) and back.
|
||||
const REGION_SAT: &str = "700 0 1 0
|
||||
4 Fuzz 3 ASM 4 none
|
||||
1 9.9999999999999995e-07 1e-10
|
||||
body $-1 -1 $-1 $1 $-1 $-1 #
|
||||
lump $-1 -1 $-1 $-1 $2 $0 #
|
||||
shell $-1 -1 $-1 $-1 $-1 $3 $-1 $1 #
|
||||
face $-1 -1 $-1 $-1 $4 $2 $-1 $-1 forward single #
|
||||
loop $-1 -1 $-1 $-1 $5 $3 #
|
||||
coedge $-1 -1 $-1 $6 $7 $-1 $8 forward $4 $-1 #
|
||||
coedge $-1 -1 $-1 $7 $5 $-1 $9 forward $4 $-1 #
|
||||
coedge $-1 -1 $-1 $5 $6 $-1 $10 forward $4 $-1 #
|
||||
edge $-1 -1 $-1 $11 0 $12 1 $5 $-1 forward @7 unknown #
|
||||
edge $-1 -1 $-1 $12 0 $13 1 $6 $17 forward @7 unknown #
|
||||
edge $-1 -1 $-1 $13 0 $11 1 $7 $-1 forward @7 unknown #
|
||||
vertex $-1 -1 $-1 $8 $14 #
|
||||
vertex $-1 -1 $-1 $9 $15 #
|
||||
vertex $-1 -1 $-1 $10 $16 #
|
||||
point $-1 -1 $-1 0 0 0 #
|
||||
point $-1 -1 $-1 100 0 0 #
|
||||
point $-1 -1 $-1 0 100 0 #
|
||||
ellipse-curve $-1 -1 $-1 0 0 0 0 0 1 100 0 0 1 I I #
|
||||
End-of-ACIS-data
|
||||
";
|
||||
|
||||
/// [`REGION_SAT`]'s records as binary data: tagged values, type names in parts.
|
||||
fn region_sab() -> Vec<u8> {
|
||||
let mut b = b"ACIS BinaryFile".to_vec();
|
||||
for v in [700u32, 0, 1, 0] {
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
let string = |b: &mut Vec<u8>, tag: u8, s: &str| {
|
||||
b.push(tag);
|
||||
b.push(u8::try_from(s.len()).unwrap_or(0));
|
||||
b.extend(s.as_bytes());
|
||||
};
|
||||
for line in REGION_SAT.lines().skip(3).take_while(|l| !l.starts_with("End-of")) {
|
||||
let mut words = line.split_whitespace();
|
||||
let parts: Vec<&str> = words.next().unwrap_or_default().split('-').collect();
|
||||
for (i, p) in parts.iter().enumerate() {
|
||||
string(&mut b, if i + 1 == parts.len() { 0x0D } else { 0x0E }, p);
|
||||
}
|
||||
while let Some(w) = words.next() {
|
||||
match w {
|
||||
"#" => {}
|
||||
"forward" => b.push(0x0B),
|
||||
"reversed" => b.push(0x0A),
|
||||
w if w.starts_with('$') => {
|
||||
b.push(0x0C);
|
||||
b.extend(w[1..].parse::<i32>().unwrap_or(-1).to_le_bytes());
|
||||
}
|
||||
w if w.starts_with('@') => string(&mut b, 0x07, words.next().unwrap_or_default()),
|
||||
w => match w.parse::<f64>() {
|
||||
Ok(v) => {
|
||||
b.push(0x06);
|
||||
b.extend(v.to_le_bytes());
|
||||
}
|
||||
Err(_) => string(&mut b, 0x07, w),
|
||||
},
|
||||
}
|
||||
}
|
||||
b.push(0x11);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
/// A drawing with one REGION: `text` as its data in groups 1 (DXF 2000), or `binary` in the
|
||||
/// ACDSDATA section (DXF 2013).
|
||||
fn region_dxf(text: &str, binary: Option<&[u8]>) -> Vec<u8> {
|
||||
let version = if binary.is_some() { "AC1027" } else { "AC1015" };
|
||||
let mut p: Vec<(i32, String)> =
|
||||
[(0, "SECTION"), (2, "HEADER"), (9, "$ACADVER"), (1, version), (0, "ENDSEC"), (0, "SECTION"), (2, "ENTITIES"), (0, "REGION"), (5, "2A")]
|
||||
.iter()
|
||||
.map(|(c, v)| (*c, v.to_string()))
|
||||
.collect();
|
||||
p.extend([(8, "0".to_string()), (100, "AcDbEntity".into()), (100, "AcDbModelerGeometry".into()), (70, "1".into())]);
|
||||
p.extend(text.lines().map(|l| (1, l.to_string())));
|
||||
p.push((0, "ENDSEC".into()));
|
||||
if let Some(bytes) = binary {
|
||||
p.extend([(0, "SECTION"), (2, "ACDSDATA"), (0, "ACDSRECORD"), (320, "2A"), (2, "ASM_Data")].iter().map(|(c, v)| (*c, v.to_string())));
|
||||
p.push((94, bytes.len().to_string()));
|
||||
p.extend(bytes.chunks(127).map(|c| (310, c.iter().map(|b| format!("{b:02X}")).collect())));
|
||||
p.push((0, "ENDSEC".into()));
|
||||
}
|
||||
p.push((0, "EOF".into()));
|
||||
dxf_text(&p).into_bytes()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn region_seeds_open_as_a_filled_path() {
|
||||
let o = vectorcraft_cad::ImportOptions::default();
|
||||
for bytes in [region_dxf(REGION_SAT, None), region_dxf("", Some(®ion_sab()))] {
|
||||
let r = vectorcraft_cad::import(&bytes, &o).expect("opens");
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("REGION")), "{:?}", r.warnings);
|
||||
let mut paths = 0;
|
||||
r.document.walk(|n: &vectorcraft_doc::Node| paths += usize::from(matches!(n.kind, vectorcraft_doc::NodeKind::Path { .. })));
|
||||
assert_eq!(paths, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Import with every option at once, and place it; whatever comes back must render and export.
|
||||
fn survive_dxf(what: &str, bytes: &[u8], fit: bool) -> Result<(), TestCaseError> {
|
||||
let o = vectorcraft_cad::ImportOptions { fit, center: !fit, merge_layers: fit, ..Default::default() };
|
||||
@@ -3783,6 +3892,23 @@ proptest! {
|
||||
bytes.truncate(cut.max(8));
|
||||
survive_dxf("mutated dxf", &bytes, cut % 2 == 0)?;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dxf_mutated_regions_never_panic(
|
||||
binary in any::<bool>(),
|
||||
cut in 0usize..2_000,
|
||||
edits in prop::collection::vec((0usize..2_000, prop::sample::select(vec![b'0', b'1', b'9', b'-', b'.', b'e', b'$', b'#', b' ', b'@', 0xFF, 0x0C])), 0..12),
|
||||
) {
|
||||
let mut data = if binary { region_sab() } else { REGION_SAT.as_bytes().to_vec() };
|
||||
for &(at, b) in &edits {
|
||||
let n = data.len();
|
||||
// Text stays ASCII, as group values are.
|
||||
data[at % n] = if binary || (b' '..0x80).contains(&b) { b } else { b' ' };
|
||||
}
|
||||
data.truncate(cut.max(8));
|
||||
let bytes = if binary { region_dxf("", Some(&data)) } else { region_dxf(&String::from_utf8_lossy(&data), None) };
|
||||
survive_dxf("mutated region", &bytes, cut % 2 == 0)?;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Windows metafiles: opened, placed and pasted ----------
|
||||
|
||||
@@ -102,6 +102,27 @@ fn kept_text(session: &mut Session, font: &CompositeFont) -> (NodeId, Node) {
|
||||
(id, document(session).node(id).unwrap().clone())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placing_a_document_whose_composite_font_names_an_installed_font_keeps_the_installed_font() {
|
||||
let _context = FontContext::hold();
|
||||
assert!(FontDb::global().has_installed_family("Source Sans 3"), "CONTROL: the bundled test face is installed");
|
||||
let mut source = destination(&[]);
|
||||
source.execute("text.create", &json!({"x": 4, "y": 16, "text": "Ab", "font": "Source Sans 3"})).unwrap();
|
||||
let mut doc: Document = document(&source).clone();
|
||||
*doc.composite_fonts = vec![CompositeFont::new("Source Sans 3", "NativeInstalledNamePart", "Regular")];
|
||||
let dir = TempDir::new("native-composite-installed");
|
||||
let path = dir.join("installed.vectorcraft");
|
||||
let options = vectorcraft_format::SaveOptions { include_linked: true, precision: None, ..Default::default() };
|
||||
std::fs::write(&path, vectorcraft_format::save_with(&doc, &options).unwrap()).unwrap();
|
||||
for linked in [false, true] {
|
||||
let mut session = destination(&[]);
|
||||
let id = place(&mut session, &path, linked);
|
||||
assert_eq!(placed_family(&session, id), "Source Sans 3", "the placed type keeps the installed family it was measured in");
|
||||
let fonts = &document(&session).composite_fonts;
|
||||
assert!(fonts.is_empty(), "no composite font comes in for a name the source could not use: {fonts:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_composite_meanings_survive_editable_and_embedded_placement() {
|
||||
let _context = FontContext::hold();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! [`Backend`].
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, OPEN_EXTS, SAVE_FORMATS, format, writable_format};
|
||||
use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, SAVE_FORMATS, format, open_exts, writable_format};
|
||||
|
||||
use crate::backend::Backend;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::dispatch::{BRIEF, MAX_SIDE_WINDOW, MENU_FILTER, TRACE_VIEWS};
|
||||
use super::handlers::MAX_DIALOG_FIELDS;
|
||||
use super::{FORMATS, OPEN_EXTS, SAVE_FORMATS, Value, format, json};
|
||||
use super::{FORMATS, SAVE_FORMATS, Value, format, json, open_exts};
|
||||
|
||||
// ---------- schemas ----------
|
||||
|
||||
@@ -365,7 +365,7 @@ pub fn tool_definitions() -> Vec<Value> {
|
||||
"Open file",
|
||||
&format!(
|
||||
"Open a file as a new, active document: .{} (see run_command document.formats). Templates (.ait, native templates) open as a new untitled document. The reply's `warnings` say what didn't come in as it was (an EPS shown as its preview image says why its PostScript couldn't be read). A file of an extension no built-in format reads opens with the installed importer plug-in that lists it; `importer` names the importer to use (File › Open With), also for an extension a built-in format reads, and `params` gives that importer's parameters.",
|
||||
OPEN_EXTS.join(", .")
|
||||
open_exts().join(", .")
|
||||
),
|
||||
obj(
|
||||
json!({
|
||||
|
||||
@@ -1780,7 +1780,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.placementOptionsDialog",
|
||||
"Placement Options…",
|
||||
"",
|
||||
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo or Redo there (reopen the dialog)",
|
||||
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo, a Redo or a canceled edit that put back an earlier state there (reopen the dialog)",
|
||||
),
|
||||
(
|
||||
"ui.relinkDialog",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Targa export: depths, alpha and the footer.
|
||||
//! Targa export: depths, grayscale, alpha and the footer.
|
||||
|
||||
use super::on_white;
|
||||
use super::tests_bmp::{art, decode, u16_at};
|
||||
@@ -9,7 +9,7 @@ fn targa_depths_alpha_and_footer() {
|
||||
let (w, h) = (7, 3);
|
||||
let px = art(w, h);
|
||||
for (depth, alpha_bits) in [(16, 1), (24, 0), (32, 8)] {
|
||||
let file = tga::encode(&px, w, h, &TgaOptions { depth }).unwrap();
|
||||
let file = tga::encode(&px, w, h, &TgaOptions { depth, gray: false }).unwrap();
|
||||
assert_eq!((file[2], file[16], file[17]), (2, depth, alpha_bits), "true colour, the depth byte, alpha bits");
|
||||
assert_eq!((u16_at(&file, 12), u16_at(&file, 14)), (7, 3));
|
||||
assert_eq!(file.len(), 18 + (w * h) as usize * usize::from(depth / 8) + 26);
|
||||
@@ -18,13 +18,39 @@ fn targa_depths_alpha_and_footer() {
|
||||
assert_eq!(img.dimensions(), (w, h));
|
||||
let want = on_white(px[(2 * w as usize + 3) * 4..][..4].try_into().unwrap());
|
||||
let got = img.get_pixel(3, 2).0;
|
||||
assert!(got[..3].iter().zip(want).all(|(a, b)| a.abs_diff(b) <= 8), "depth {depth}: {got:?} vs {want:?}");
|
||||
for c in 0..3 {
|
||||
assert!(got[c].abs_diff(want[c]) <= 8, "depth {depth}, channel {c}: {got:?} vs {want:?}");
|
||||
}
|
||||
match depth {
|
||||
32 => assert_eq!((img.get_pixel(0, 0).0[3], img.get_pixel(1, 0).0[3]), (0, 128), "8-bit alpha"),
|
||||
24 => assert_eq!(img.get_pixel(0, 0).0, [255; 4], "flattened on white"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert!(tga::encode(&px, w, h, &TgaOptions { depth: 8 }).is_err());
|
||||
assert!(tga::encode(&px, w, h, &TgaOptions { depth: 8, gray: false }).is_err());
|
||||
assert!(tga::encode(&px, 70_000, 1, &TgaOptions::default()).is_err(), "too wide");
|
||||
}
|
||||
|
||||
/// Grayscale Targa files are image type 3: 8 bits flattened on white, or 16 with an 8-bit alpha.
|
||||
#[test]
|
||||
fn targa_grayscale_writes_lightness() {
|
||||
let (w, h) = (7, 3);
|
||||
let px = art(w, h);
|
||||
for (depth, alpha_bits) in [(8, 0), (16, 8)] {
|
||||
let file = tga::encode(&px, w, h, &TgaOptions { depth, gray: true }).unwrap();
|
||||
assert_eq!((file[2], file[16], file[17]), (3, depth, alpha_bits), "grayscale, the depth byte, alpha bits");
|
||||
assert_eq!(file.len(), 18 + (w * h) as usize * usize::from(depth / 8) + 26);
|
||||
let img = decode(&file, craft_image_codecs::Format::Tga);
|
||||
assert_eq!(img.dimensions(), (w, h));
|
||||
// (0, 2) is opaque red 230, 40, 30: Rec. 601 lightness 96, the same in every channel.
|
||||
let [r, g, b, a] = img.get_pixel(0, 2).0;
|
||||
assert!(r == g && g == b && r.abs_diff(96) <= 1 && a == 255, "depth {depth}: {:?}", [r, g, b, a]);
|
||||
match depth {
|
||||
8 => assert_eq!(img.get_pixel(0, 0).0, [255; 4], "flattened on white"),
|
||||
_ => assert_eq!((img.get_pixel(0, 0).0[3], img.get_pixel(1, 0).0[3]), (0, 128), "8-bit alpha"),
|
||||
}
|
||||
}
|
||||
for depth in [24, 32] {
|
||||
assert!(tga::encode(&px, w, h, &TgaOptions { depth, gray: true }).is_err(), "{depth} bits gray");
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,55 @@
|
||||
//! Targa export: uncompressed true colour at 16 bits per pixel (5-5-5 and a one-bit alpha), 24 or
|
||||
//! 32 (8-bit alpha), rows bottom-up, with the version 2 footer.
|
||||
//! 32 (8-bit alpha), or uncompressed grayscale at 8 bits or 16 (8-bit alpha), rows bottom-up, with
|
||||
//! the version 2 footer.
|
||||
|
||||
use super::on_white;
|
||||
use super::quantize::luma;
|
||||
|
||||
/// Bits per pixel a Targa export can have.
|
||||
/// Bits per pixel a true-colour Targa export can have.
|
||||
pub const DEPTHS: [u8; 3] = [16, 24, 32];
|
||||
|
||||
/// Bits per pixel a grayscale Targa export can have.
|
||||
pub const GRAY_DEPTHS: [u8; 2] = [8, 16];
|
||||
|
||||
/// The Targa options of a raster export.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct TgaOptions {
|
||||
/// Bits per pixel ([`DEPTHS`]).
|
||||
/// Bits per pixel ([`DEPTHS`], or [`GRAY_DEPTHS`] when `gray`).
|
||||
pub depth: u8,
|
||||
/// Grayscale (image type 3) instead of true colour (image type 2).
|
||||
pub gray: bool,
|
||||
}
|
||||
|
||||
impl Default for TgaOptions {
|
||||
fn default() -> Self {
|
||||
Self { depth: 24 }
|
||||
Self { depth: Self::default_depth(false), gray: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl TgaOptions {
|
||||
/// The depth a colour model starts with: 24 bits for true colour, 8 for grayscale.
|
||||
pub fn default_depth(gray: bool) -> u8 {
|
||||
if gray { 8 } else { 24 }
|
||||
}
|
||||
|
||||
/// The depths the colour model can be written at.
|
||||
pub fn depths(gray: bool) -> &'static [u8] {
|
||||
if gray { &GRAY_DEPTHS } else { &DEPTHS }
|
||||
}
|
||||
|
||||
/// Why these options can't be written, if they can't.
|
||||
pub fn check(&self) -> Result<(), String> {
|
||||
if DEPTHS.contains(&self.depth) { Ok(()) } else { Err(format!("Targa depth {}: 16, 24 or 32 bits per pixel", self.depth)) }
|
||||
match (self.gray, Self::depths(self.gray).contains(&self.depth)) {
|
||||
(_, true) => Ok(()),
|
||||
(false, false) => Err(format!("Targa depth {}: 16, 24 or 32 bits per pixel", self.depth)),
|
||||
(true, false) => Err(format!("grayscale Targa depth {}: 8 or 16 bits per pixel", self.depth)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Straight-alpha RGBA pixels as a Targa file. 24 bits blend partly transparent pixels over white;
|
||||
/// at 16 bits a pixel is opaque from half opacity up, else transparent.
|
||||
/// Straight-alpha RGBA pixels as a Targa file. 24 bits and 8-bit grayscale blend partly
|
||||
/// transparent pixels over white; at 16 bits true colour a pixel is opaque from half opacity up,
|
||||
/// else transparent.
|
||||
pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result<Vec<u8>, String> {
|
||||
o.check()?;
|
||||
let (Ok(w16), Ok(h16)) = (u16::try_from(width), u16::try_from(height)) else {
|
||||
@@ -40,21 +62,23 @@ pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result<Ve
|
||||
}
|
||||
let px = rgba.as_chunks::<4>().0;
|
||||
let mut out = Vec::with_capacity((w * h).saturating_mul(usize::from(o.depth / 8)).saturating_add(18 + 26));
|
||||
// No image id or colour map, uncompressed true colour, origin (0, 0).
|
||||
out.extend([0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
// No image id or colour map, uncompressed true colour (2) or grayscale (3), origin (0, 0).
|
||||
out.extend([0, 0, if o.gray { 3 } else { 2 }, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
out.extend(w16.to_le_bytes());
|
||||
out.extend(h16.to_le_bytes());
|
||||
// Bits per pixel, then the alpha bits (rows bottom-up, left to right).
|
||||
let alpha_bits = match o.depth {
|
||||
16 => 1,
|
||||
32 => 8,
|
||||
let alpha_bits = match (o.gray, o.depth) {
|
||||
(false, 16) => 1,
|
||||
(true, 16) | (false, 32) => 8,
|
||||
_ => 0,
|
||||
};
|
||||
out.extend([o.depth, alpha_bits]);
|
||||
for row in px.chunks(w).rev() {
|
||||
for p in row {
|
||||
match o.depth {
|
||||
16 => {
|
||||
match (o.gray, o.depth) {
|
||||
(true, 8) => out.push(luma(on_white(p))),
|
||||
(true, _) => out.extend([luma([p[0], p[1], p[2]]), p[3]]),
|
||||
(false, 16) => {
|
||||
let v = if p[3] >= 128 {
|
||||
let [r, g, b] = [p[0], p[1], p[2]].map(|c| u16::from(c >> 3));
|
||||
0x8000 | r << 10 | g << 5 | b
|
||||
@@ -63,7 +87,7 @@ pub fn encode(rgba: &[u8], width: u32, height: u32, o: &TgaOptions) -> Result<Ve
|
||||
};
|
||||
out.extend(v.to_le_bytes());
|
||||
}
|
||||
24 => {
|
||||
(false, 24) => {
|
||||
let [r, g, b] = on_white(p);
|
||||
out.extend([b, g, r]);
|
||||
}
|
||||
|
||||
@@ -298,6 +298,28 @@ fn add_artboard_guides_does_not_replace_a_deleted_artboard_with_its_neighbor() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_artboard_guides_preview_keeps_an_artboard_deleted_while_it_shows() {
|
||||
let (mut app, _, _) = app();
|
||||
app.run("artboard.new", json!({"x": 600, "y": 0, "width": 200, "height": 100})).unwrap();
|
||||
app.view_mut().unwrap().artboard = 0;
|
||||
click(&mut app, "Add Artboard Guides…");
|
||||
let id = host::dialog_id(&app);
|
||||
host::set(&app, id, "preview", json!(true));
|
||||
host::frame(&mut app);
|
||||
assert_eq!(artboard_guides(&app).len(), 1);
|
||||
app.run("artboard.delete", json!({"index": 0})).unwrap();
|
||||
assert!(artboard_guides(&app).is_empty(), "the remaining artboard gets no guide");
|
||||
host::frame(&mut app);
|
||||
assert_eq!(app.session.doc().unwrap().doc.artboards.len(), 1);
|
||||
assert!(artboard_guides(&app).is_empty());
|
||||
assert!(host::confirm(&app, id));
|
||||
host::frame(&mut app);
|
||||
assert_eq!(app.session.doc().unwrap().doc.artboards.len(), 1);
|
||||
assert!(artboard_guides(&app).is_empty());
|
||||
assert_eq!(app.ui.status, "The artboard no longer exists.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artboard_guides_menu_dialog_is_available_without_a_selection() {
|
||||
let (mut app, _, _) = app();
|
||||
|
||||
@@ -165,6 +165,10 @@ fn pump_commit(app: &mut VectorcraftApp) {
|
||||
Some(Err(error.clone()))
|
||||
}
|
||||
};
|
||||
// Edit Points Only previews a selection, which an outside command (Clear) has to see as shown.
|
||||
if spec.command != super::select::points_only::COMMAND {
|
||||
preview.keep_outside_edits(app);
|
||||
}
|
||||
app.addon_dialogs.preview = preview;
|
||||
if spec.command == super::select::points_only::COMMAND {
|
||||
match &answer {
|
||||
|
||||
@@ -318,6 +318,154 @@ fn opening_a_second_add_on_dialog_closes_the_first_and_rolls_back_its_preview()
|
||||
assert_eq!(x0(&app, 1), 100.0, "the first preview rolled back");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clearing_a_dialog_preview_uses_only_the_shown_base_objects() {
|
||||
for include_base_object in [false, true] {
|
||||
let mut app = two_rects_filled();
|
||||
let original = app.session.active().unwrap().doc.clone();
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let undo = undo_len(&app);
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
let params = json!({});
|
||||
assert!(preview.run(&mut app, true, "Flood Fill Artboards", "addon.document.floodFillArtboards", ¶ms).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
assert!(!app.session.active().unwrap().selection.objects.is_empty());
|
||||
assert!(app.session.active().unwrap().selection.objects.iter().all(|id| original.node(*id).is_none()));
|
||||
if include_base_object {
|
||||
app.session.active_mut().unwrap().selection.add(selected[0]);
|
||||
}
|
||||
|
||||
let result = app.run("edit.clear", json!({}));
|
||||
if include_base_object {
|
||||
result.unwrap();
|
||||
}
|
||||
preview.cancel(&mut app);
|
||||
let state = app.session.active().unwrap();
|
||||
assert!(state.doc.node(selected[1]).is_some(), "Clear must keep hidden selected artwork");
|
||||
if include_base_object {
|
||||
assert!(state.doc.node(selected[0]).is_none(), "Clear deletes a shown object present in the base document");
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().doc, original);
|
||||
} else {
|
||||
assert_eq!(state.doc, original, "Cancel keeps all artwork when only preview objects were selected");
|
||||
assert_eq!(undo_len(&app), undo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clearing_anchors_of_a_path_the_preview_recut_keeps_the_base_path() {
|
||||
let mut app = two_rects_filled();
|
||||
let original = app.session.active().unwrap().doc.clone();
|
||||
let ids = app.session.active().unwrap().selection.objects.clone();
|
||||
app.run("select.anchors", json!({"id": ids[0].0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Set Corners", "addon.pathtools.cornerSet", &json!({"radius": 2, "kind": "chamfer"})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
assert!(!app.session.active().unwrap().selection.anchors.is_empty(), "anchors on the recut path are on show");
|
||||
let _refused = app.run("edit.clear", json!({}));
|
||||
preview.cancel(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc, original, "Clear deletes no anchor of the base path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_outside_command_keeps_the_dialog_selection() {
|
||||
let mut app = two_rects_filled();
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Flood Fill Artboards", "addon.document.floodFillArtboards", &json!({})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
let shown = app.session.active().unwrap().selection.clone();
|
||||
assert!(app.run("edit.clear", json!({})).is_err(), "only preview objects are selected");
|
||||
let state = app.session.active().unwrap();
|
||||
assert_eq!(state.interaction.as_ref().unwrap().selection.objects, selected, "the dialog keeps its own selection");
|
||||
assert_eq!(state.selection, shown, "the preview's selection is on show again");
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
assert!(app.session.active().unwrap().interaction.as_ref().unwrap().selection.objects.is_empty(), "Deselect still deselects");
|
||||
preview.cancel(&mut app);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_outside_command_journals_the_selection_it_acts_on() {
|
||||
let mut app = two_rects_filled();
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Flood Fill Artboards", "addon.document.floodFillArtboards", &json!({})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
app.session.active_mut().unwrap().selection.add(selected[0]);
|
||||
let start = app.session.journal_for_action(0).len();
|
||||
app.run("edit.clear", json!({})).unwrap();
|
||||
let action = app.session.journal_for_action(start);
|
||||
let clear = action.iter().position(|(id, _)| id == "edit.clear").unwrap();
|
||||
assert!(action[..clear].iter().any(|(id, _)| id.starts_with("select.")), "Clear replays on the shown selection: {action:?}");
|
||||
preview.cancel(&mut app);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_dialog_preview_retries_after_an_outside_selection_change() {
|
||||
let mut app = two_rects();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
let params = json!({"offset": 5});
|
||||
assert!(preview.run(&mut app, true, "Contour", "addon.contour.set", ¶ms).unwrap().is_err());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
assert!(preview.run(&mut app, true, "Contour", "addon.contour.set", ¶ms).is_none());
|
||||
let document = app.session.active().unwrap().doc.clone();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
assert!(std::sync::Arc::ptr_eq(&app.session.active().unwrap().doc, &document));
|
||||
assert!(preview.run(&mut app, true, "Contour", "addon.contour.set", ¶ms).unwrap().is_ok());
|
||||
assert!(count(&app) > 2);
|
||||
preview.cancel(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc, document);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_outside_dialog_selection_keeps_its_paints_after_cancel() {
|
||||
let mut app = two_rects();
|
||||
let ids = app.session.active().unwrap().selection.objects.clone();
|
||||
app.run("select.set", json!({"ids": [ids[0].0]})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
app.run("select.set", json!({"ids": [ids[1].0]})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap();
|
||||
let expected = app.session.paint.clone();
|
||||
app.run("select.set", json!({"ids": [ids[0].0]})).unwrap();
|
||||
assert_ne!(app.session.paint, expected);
|
||||
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Move", "object.move", &json!({"dx": 10, "dy": 0})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
app.run("select.set", json!({"ids": [ids[1].0]})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![ids[1]]);
|
||||
assert_eq!(app.session.paint, expected);
|
||||
preview.cancel(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![ids[1]]);
|
||||
assert_eq!(app.session.paint, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_add_on_preview_keeps_an_edit_made_outside_the_dialog() {
|
||||
let mut app = two_rects();
|
||||
open_item(&mut app, "Arrange Tools", "Arrange in Grid…");
|
||||
let id = dialog_id(&app);
|
||||
set(&app, id, "layout", json!("row"));
|
||||
set(&app, id, "preview", json!(true));
|
||||
frame(&mut app);
|
||||
assert_eq!(x0(&app, 1), 30.0, "previewed");
|
||||
let undo = undo_len(&app);
|
||||
app.run("shape.rectangle", json!({"x": 300, "y": 300, "width": 10, "height": 10})).unwrap();
|
||||
assert_eq!(undo_len(&app), undo + 1, "the rectangle is a step of its own");
|
||||
set(&app, id, "layout", json!("column"));
|
||||
frame(&mut app);
|
||||
assert_eq!(count(&app), 3, "the next preview keeps the rectangle");
|
||||
cancel(&app, id);
|
||||
frame(&mut app);
|
||||
assert!(!app.session.in_interaction());
|
||||
assert_eq!(count(&app), 3, "Cancel keeps the rectangle");
|
||||
assert_eq!(x0(&app, 1), 100.0, "Cancel rolls the preview back");
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_add_on_preview_waits_for_its_opening_drawing() {
|
||||
let mut app = two_drawings();
|
||||
|
||||
@@ -167,6 +167,7 @@ impl VectorcraftApp {
|
||||
hover_object: None,
|
||||
grab: None,
|
||||
carry_target: None,
|
||||
removed_press: false,
|
||||
last_drag: None,
|
||||
escaped_press: false,
|
||||
pressed_at: None,
|
||||
@@ -291,6 +292,7 @@ impl VectorcraftApp {
|
||||
prefs_changed: false,
|
||||
touch_screen: false,
|
||||
automation_roots: None,
|
||||
confined_drop: None,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
agents: None,
|
||||
pending_plugin_install: None,
|
||||
@@ -365,9 +367,19 @@ impl VectorcraftApp {
|
||||
}
|
||||
|
||||
/// The folders this pass may read and write: the automation roots while the pass carries
|
||||
/// input the control channel injected, anywhere otherwise.
|
||||
/// input the control channel injected, or delivers files the OS dropped in such a pass;
|
||||
/// anywhere otherwise.
|
||||
fn automation_scope(&self, ctx: &egui::Context) -> Option<Arc<AutomationRoots>> {
|
||||
WindowHost::of(ctx).injected_pass().then(|| self.automation_roots.clone()).flatten()
|
||||
let delivers = self.confined_drop.is_some_and(|last| ctx.cumulative_frame_nr_for(egui::ViewportId::ROOT) <= last);
|
||||
(WindowHost::of(ctx).injected_pass() || delivers).then(|| self.automation_roots.clone()).flatten()
|
||||
}
|
||||
|
||||
/// Notes files the OS dropped in a pass that carries injected input: the drag session delivers
|
||||
/// them in the next root frame, which [`Self::automation_scope`] confines too.
|
||||
fn note_confined_drop(&mut self, ctx: &egui::Context) {
|
||||
if WindowHost::of(ctx).injected_pass() && ctx.input(|i| !i.raw.dropped_files.is_empty()) {
|
||||
self.confined_drop = Some(ctx.cumulative_frame_nr_for(egui::ViewportId::ROOT) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,10 +734,6 @@ impl VectorcraftApp {
|
||||
let Ok(mut app) = app.try_borrow_mut() else { return };
|
||||
let app: &mut VectorcraftApp = &mut app;
|
||||
app.canvas.windows.area = Some(ui.available_rect_before_wrap());
|
||||
// Only the shown pass starts the frame's panes: a measuring run before it would drop the last frame's.
|
||||
if !craft::ui::runtime::measure::active(ui.ctx()) {
|
||||
app.canvas.windows.last_noted = std::mem::take(&mut app.canvas.windows.noted);
|
||||
}
|
||||
let floats = crate::doc_windows::current_floats(app);
|
||||
// The current window's body is in its floating window, drawn after this pane: the pane's drop catcher
|
||||
// waits for it ([`crate::doc_windows::show`]).
|
||||
@@ -761,6 +769,7 @@ impl VectorcraftApp {
|
||||
self.perf.early_events_ms = 0.0;
|
||||
}
|
||||
self.adopt_context(&ctx);
|
||||
self.note_confined_drop(&ctx);
|
||||
let confined = self.automation_scope(&ctx);
|
||||
if let Err(msg) = file_access::confine(confined.as_ref(), || {
|
||||
vectorcraft_engine::guard::catch_panic(|| {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft::ui::dialog::UnsavedChangesDialog;
|
||||
use craft::ui::dialog::HostedUnsavedChangesDialog;
|
||||
use craft::ui::shell::embed::{self, CloseDecision};
|
||||
use craft::ui::testing::Fixture;
|
||||
use serde_json::json;
|
||||
@@ -57,9 +57,9 @@ fn close_frame(app: &mut VectorcraftApp, ctx: &egui::Context) -> Option<CloseDec
|
||||
}
|
||||
|
||||
/// Whether the window's dialog host shows the Unsaved Changes question.
|
||||
// PLAN: assumed shell-w15's `unsaved::close_all` opens `UnsavedChangesDialog` itself on the window's host (the sheet's Tests row names it).
|
||||
// PLAN: assumed shell-w15's `unsaved::close_all` opens `HostedUnsavedChangesDialog` itself on the window's host (the sheet's Tests row names it).
|
||||
fn asks_about_unsaved(app: &VectorcraftApp) -> bool {
|
||||
app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.get::<UnsavedChangesDialog>().is_some()))
|
||||
app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.get::<HostedUnsavedChangesDialog>().is_some()))
|
||||
}
|
||||
|
||||
/// The window's close asks about unsaved documents instead of closing the window: with a modified
|
||||
|
||||
@@ -126,6 +126,9 @@ pub struct CanvasCache {
|
||||
/// The uid of the document a tab rest showed while art carried off the canvas waits over it: only its canvas takes
|
||||
/// the art, so a target closed or left by other means carries nothing (`canvas::drops`).
|
||||
pub carry_target: Option<u64>,
|
||||
/// The tool host ended the tool's press with a `Removed` cancel in this pass: the canvas was hidden for a pass, as
|
||||
/// when art carried off it rests on another document's tab and comes back (`tool_adapter::resume_carry`).
|
||||
pub removed_press: bool,
|
||||
/// The last drag the tool was sent and the screen point it was at: when the view scrolls under the held
|
||||
/// pointer, the drag goes on at that point in the scrolled view.
|
||||
pub last_drag: Option<(egui::Pos2, vectorcraft_tools::PointerEvent)>,
|
||||
|
||||
@@ -213,16 +213,11 @@ impl Component for CanvasDrops<'_> {
|
||||
/// the carry it catches: the pane's area is noted instead.
|
||||
pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKind) {
|
||||
let rect = ui.max_rect();
|
||||
if kind == BodyKind::Pane {
|
||||
if let Some(later) = &mut app.canvas.panes.drops {
|
||||
later.push((win, rect, ui.layer_id()));
|
||||
return;
|
||||
}
|
||||
// A pane outside Tile (a floating window's, the main window's while the current window floats), as shown: a
|
||||
// measuring run's area is not where it draws.
|
||||
if !craft::ui::runtime::measure::active(ui.ctx()) {
|
||||
app.canvas.windows.noted.push((win, rect));
|
||||
}
|
||||
if kind == BodyKind::Pane
|
||||
&& let Some(later) = &mut app.canvas.panes.drops
|
||||
{
|
||||
later.push((win, rect, ui.layer_id()));
|
||||
return;
|
||||
}
|
||||
let view = match kind {
|
||||
BodyKind::Live => app.canvas_view(),
|
||||
@@ -230,7 +225,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKi
|
||||
};
|
||||
let (Some(view), Some((document, reverts))) = (view, app.session.documents().get(win.0).map(|d| (d.uid, d.reverts))) else { return };
|
||||
let contents = app.session.documents().iter().map(|d| (d.uid, d.reverts)).collect();
|
||||
let sources = app.session.documents().iter().map(|d| (d.uid, d.revision)).chain(app.canvas.panes.released_from).collect();
|
||||
let sources = app.session.documents().iter().map(|d| (d.uid, d.revision)).collect();
|
||||
// A tab rest leaves the art to the document it showed while that is the current one: any canvas or pane takes it
|
||||
// then, and nothing once that document was closed or left by other means.
|
||||
let current = app.session.active().map(|d| d.uid);
|
||||
@@ -280,17 +275,6 @@ pub(crate) fn drop_on_pane(app: &mut VectorcraftApp, win: Win, drop: &Dropped) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Art carried off the canvas and released at `at` (screen) over a pane this pass noted, or a pane outside Tile the
|
||||
/// last frame drew (the front one first), in the frame the pointer reached it, before the pane could take it as a drop:
|
||||
/// the pane's window and the drop there.
|
||||
pub(crate) fn released_on_pane(app: &VectorcraftApp, art: CarriedArt, at: Pos2, op: DropOperation) -> Option<(Win, Dropped)> {
|
||||
let outside = app.canvas.windows.last_noted.iter().rev();
|
||||
let waiting = app.canvas.panes.drops.iter().flatten().rev().map(|(win, rect, _)| (*win, *rect));
|
||||
let (win, rect) = outside.copied().chain(waiting).find(|(_, rect)| rect.contains(at))?;
|
||||
let view = pane_view(app, win, rect)?;
|
||||
Some((win, Dropped { payload: Payload::Art(art), at: view.to_doc(at), zoom: view.zoom, op }))
|
||||
}
|
||||
|
||||
/// Starts carrying the art of a Selection, Direct Selection or Group Selection move that left the canvas, handing it
|
||||
/// to the drag session. Moves of anchors or segments stay reshapes. `covered`: another window is over the canvas at the
|
||||
/// pointer. → whether a carry runs.
|
||||
|
||||
@@ -101,11 +101,6 @@ pub struct Panes {
|
||||
/// panes drawn so far, by window, with their layers. Their drop catchers show after the current window's body
|
||||
/// ([`super::drops::show`]).
|
||||
pub(crate) drops: Option<Vec<(Win, egui::Rect, egui::LayerId)>>,
|
||||
/// Art released over a pane in the frame the pointer reached it, applied after the current window's body.
|
||||
pub(crate) released: Option<(Win, super::drops::Dropped)>,
|
||||
/// The `(uid, revision)` of the document whose carried art was released this pass, before the release gave up its
|
||||
/// move: the drop catchers that run after the release still take that art.
|
||||
pub(crate) released_from: Option<(u64, u64)>,
|
||||
}
|
||||
|
||||
impl Panes {
|
||||
@@ -387,7 +382,6 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
|
||||
show_body(app, ui, w, cell, BodyKind::Live);
|
||||
}
|
||||
catch_waiting(app, ui);
|
||||
drop_released(app);
|
||||
note_fits(app, &areas, &unfitted);
|
||||
});
|
||||
let activated = split.output.activated;
|
||||
@@ -400,15 +394,6 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Drops the art released over a pane in the frame the pointer reached it ([`super::drops::released_on_pane`]), once
|
||||
/// the panes that could have taken it as a drop have drawn.
|
||||
pub(crate) fn drop_released(app: &mut VectorcraftApp) {
|
||||
app.canvas.panes.released_from = None;
|
||||
if let Some((w, drop)) = app.canvas.panes.released.take() {
|
||||
super::drops::drop_on_pane(app, w, &drop);
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the drop catchers of the panes that waited ([`super::drops::show`]) for the current window's body, whose tool
|
||||
/// may start the carry they catch.
|
||||
pub(crate) fn catch_waiting(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
//! The document tool as the framework's `CanvasTool`: the pointer and key calls of the tool host go to the engine
|
||||
//! session, and what the session asks of the UI is applied here.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::{Cell, RefCell, RefMut};
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::behavior::{CancelReason, CanvasView, Cursor, DropOperation, PointerKind as Device, PressPhase};
|
||||
use craft::behavior::{CancelReason, CanvasView, Cursor, PointerKind as Device, PressPhase};
|
||||
use craft::keymap::{Chord, Key};
|
||||
use craft::ui::canvas::ToolPath;
|
||||
use craft::ui::canvas::{
|
||||
Autoscroll, CanvasTool, Momentary, MomentaryCommands, MomentaryShift, ToolAction, ToolClaims, ToolContext, ToolHost, ToolHostResponse, ToolKey,
|
||||
ToolPass, ToolPointer,
|
||||
};
|
||||
use craft::ui::contract::DragPreview;
|
||||
use craft::ui::runtime::drag;
|
||||
use craft::ui::runtime::env::Env;
|
||||
use serde_json::json;
|
||||
use vectorcraft_engine::ViewInfo;
|
||||
use vectorcraft_geom::Point;
|
||||
@@ -392,20 +397,15 @@ impl CanvasTool for SessionTool<'_> {
|
||||
// The press ends where it went up, with the keys held at its release.
|
||||
let up = self.at_release(pointer, pointer_event(PointerKind::Up, pointer, cx));
|
||||
let covered = self.covered(pointer);
|
||||
let carried = super::drops::carried(&self.app(), cx, pointer, covered);
|
||||
self.app().canvas.panes.released_from = carried.as_ref().map(|art| (art.document, art.revision));
|
||||
let given_up = cx.over_drop_target() || carried.is_some();
|
||||
// Carried art released off the canvas goes to the target the drag session resolves in this pass, a pane drawn
|
||||
// later in the pass included: the session delivers the drop in the next pass.
|
||||
let carried = super::drops::carried(&self.app(), cx, pointer, covered).is_some();
|
||||
let given_up = cx.over_drop_target() || carried;
|
||||
if given_up {
|
||||
// The art goes to the drop target, or nowhere off the canvas: the move is given up where it started.
|
||||
self.send_samples();
|
||||
let _ = self.app().session.cancel_interaction();
|
||||
}
|
||||
if let Some(art) = carried.filter(|_| !cx.over_drop_target()) {
|
||||
// Released over a pane in the frame the pointer reached it: no target could take it yet.
|
||||
let op = if up.mods.alt { DropOperation::Copy } else { DropOperation::Move };
|
||||
let mut app = self.app();
|
||||
app.canvas.panes.released = super::drops::released_on_pane(&app, art, pointer.pos, op);
|
||||
}
|
||||
self.app().canvas.grab = None;
|
||||
// When the pointer moved or the keys changed since the drag's last move, the tool gets a move where the press went
|
||||
// up first, as it does while held: the last move of the release's pass still sizes the shape, and Shift pressed in
|
||||
@@ -452,6 +452,9 @@ impl CanvasTool for SessionTool<'_> {
|
||||
fn cancel(&mut self, reason: CancelReason, cx: &mut ToolContext<'_>) {
|
||||
self.send_samples();
|
||||
let mut app = self.app();
|
||||
if reason == CancelReason::Removed {
|
||||
app.canvas.removed_press = true;
|
||||
}
|
||||
if app.ui.screen_mode == 3 {
|
||||
// The tool had no press of Presentation Mode's.
|
||||
app.canvas.last_drag = None;
|
||||
@@ -739,6 +742,8 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
app.canvas.keys_at = Some(ui.input(|i| i.time));
|
||||
}
|
||||
let view_info = app.view_info();
|
||||
let carry = carried_session(ui.ctx());
|
||||
app.canvas.removed_press = false;
|
||||
let mut picked = ToolHostResponse::default();
|
||||
let mut response = if crate::dialogs::recolor::edit_tab::with_theme_pick(app, |app, tool| picked = host_run(app, ui, pass, tool)) {
|
||||
picked
|
||||
@@ -772,6 +777,7 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
drop(tool);
|
||||
response
|
||||
};
|
||||
resume_carry(app, ui, pass, carry);
|
||||
// The framework ends a press at Escape; the engine's tool still takes the release that ends it.
|
||||
if app.canvas.escaped_press && !ui.input(|i| i.pointer.primary_down()) {
|
||||
app.canvas.escaped_press = false;
|
||||
@@ -820,6 +826,28 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
response
|
||||
}
|
||||
|
||||
/// The art a move carries off the canvas and what the panels see of it, while that drag session runs.
|
||||
type Carry = (Arc<super::drops::CarriedArt>, Arc<crate::panel_drag::PanelDrag>);
|
||||
|
||||
/// The drag session of art carried off the canvas, when one runs.
|
||||
fn carried_session(ctx: &egui::Context) -> Option<Carry> {
|
||||
Some((drag::active::<super::drops::CarriedArt>(ctx)?, drag::active::<crate::panel_drag::PanelDrag>(ctx)?))
|
||||
}
|
||||
|
||||
/// Starts the drag session `carry` again when the tool host ended it in this pass with the press's `Removed` cancel
|
||||
/// while the button is still held. The canvas was hidden for a pass, as when the art rests on another document's tab
|
||||
/// and comes back, and the release then drops the art where it lands.
|
||||
// Workaround: storytold/craft-libs#5281 keeps the session running; remove this with the pin bump that takes it.
|
||||
fn resume_carry(app: &mut VectorcraftApp, ui: &Ui, pass: &ToolPass, carry: Option<Carry>) {
|
||||
let removed = std::mem::take(&mut app.canvas.removed_press);
|
||||
let Some((art, panel)) = carry else { return };
|
||||
if !removed || drag::active::<super::drops::CarriedArt>(ui.ctx()).is_some() || !ui.input(|i| i.pointer.primary_down()) {
|
||||
return;
|
||||
}
|
||||
let also: Arc<dyn Any + Send + Sync> = panel;
|
||||
drag::start(ui.ctx(), pass.id, &Env::of(ui).view(), art, vec![also], DragPreview::None);
|
||||
}
|
||||
|
||||
fn host_run_session(tool: &mut SessionTool<'_>, ui: &Ui, pass: &ToolPass) -> ToolHostResponse {
|
||||
let mut app = tool.app();
|
||||
// The host borrows the tool and the app both through the cell, one call at a time.
|
||||
|
||||
@@ -528,7 +528,7 @@ fn the_title_bars_close_button_closes_the_window() {
|
||||
.textures_delta
|
||||
.clear();
|
||||
assert_eq!(decision, Some(craft::ui::shell::embed::CloseDecision::Hold), "the modified document keeps the window open");
|
||||
let asks = app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.get::<craft::ui::dialog::UnsavedChangesDialog>().is_some()));
|
||||
let asks = app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.get::<craft::ui::dialog::HostedUnsavedChangesDialog>().is_some()));
|
||||
assert!(asks, "the close asks about the modified document");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,9 @@ pub(crate) enum Target {
|
||||
/// A colour row `key` of the open dialog `parent`.
|
||||
Answer { parent: DialogId, key: String },
|
||||
/// The answer to a running script's `app.showColorPicker`, which opened it on `color`; `cmyk`:
|
||||
/// the run's active document is in CMYK.
|
||||
Script { color: Color, cmyk: bool },
|
||||
/// the run's active document is in CMYK; `profiles`: the RGB and CMYK profiles that document is
|
||||
/// assigned, which the pick converts through.
|
||||
Script { color: Color, cmyk: bool, profiles: (Option<String>, Option<String>) },
|
||||
}
|
||||
|
||||
impl Target {
|
||||
@@ -242,6 +243,28 @@ fn working_cmyk() -> Option<CmykConverter> {
|
||||
CmykConverter::new(Arc::new(Profile::parse(&bytes).ok()?)).ok()
|
||||
}
|
||||
|
||||
/// The color a script's picker gives for `picked` in the script's document assigned `profiles`
|
||||
/// (`cmyk`: a CMYK document), which separates through that document's CMYK profile. A pick in
|
||||
/// display sRGB (a hex value, a sample, HSB) is that sRGB color in the document's RGB space; RGB
|
||||
/// values typed into the picker are in the active RGB space, and convert from it to the document's
|
||||
/// RGB space when the two differ. CMYK, gray and Lab values stay as they are.
|
||||
fn script_pick(picked: &PickedColor, cmyk: bool, profiles: &(Option<String>, Option<String>)) -> Color {
|
||||
let shown = cms::active();
|
||||
let own = cms::for_document(profiles.0.as_deref(), profiles.1.as_deref());
|
||||
let c = match picked.model.as_ref().map(|v| v.model) {
|
||||
None | Some("hsb") => screen_color::sampled(&own, [picked.color.r, picked.color.g, picked.color.b]),
|
||||
Some(_) => {
|
||||
let c = color_of(picked);
|
||||
if matches!(c, Color::Rgb { .. }) && shown.settings().rgb != own.settings().rgb {
|
||||
shown.convert_into(&own, &c, own.settings().intent)
|
||||
} else {
|
||||
c
|
||||
}
|
||||
}
|
||||
};
|
||||
cms::with_active(own, || in_model(cmyk, c))
|
||||
}
|
||||
|
||||
/// `ui.colorPicker {stroke?, artboard?, color?}`: open the picker for the fill (or stroke) proxy,
|
||||
/// or for artboard `artboard`'s background color, starting from `color`, else the proxy's color
|
||||
/// or the artboard's color (white when it has none).
|
||||
@@ -322,16 +345,17 @@ fn picker(app: &VectorcraftApp, key: &str, color: &Color, cmyk: bool) -> ColorPi
|
||||
}
|
||||
|
||||
/// Opens the Color Picker a running script's `app.showColorPicker` waits at, on `color`; `cmyk`:
|
||||
/// the run's own active document is in CMYK, which the session does not show between slices. It
|
||||
/// the run's own active document is in CMYK, which the session does not show between slices;
|
||||
/// `profiles`: the RGB and CMYK profiles that document is assigned, which OK converts the pick through. It
|
||||
/// previews nothing; its OK and Cancel answer the run ([`finish`]).
|
||||
pub(crate) fn open_for_script(app: &mut VectorcraftApp, color: Color, cmyk: bool) {
|
||||
pub(crate) fn open_for_script(app: &mut VectorcraftApp, color: Color, cmyk: bool, profiles: (Option<String>, Option<String>)) {
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
// The given colour's own values, so that OK can tell an untouched pick from another model's.
|
||||
// The Only Web Colors setting of earlier pickers is not recalled, so the colour opens as given.
|
||||
let dialog = picker(app, SCRIPT_KEY, &color, cmyk).kept(model_values(&color)).web_colors_remembered(false);
|
||||
let id = dialogs.with(|h| h.open(dialog));
|
||||
app.color_dialogs.pickers.retain(|o| o.id != id);
|
||||
let target = Target::Script { color, cmyk };
|
||||
let target = Target::Script { color, cmyk, profiles };
|
||||
app.color_dialogs.pickers.push(Open {
|
||||
id,
|
||||
target,
|
||||
@@ -503,9 +527,11 @@ fn finish(
|
||||
}
|
||||
}
|
||||
// OK on the colour it opened with, in the model it opened with, gives that colour back.
|
||||
(Some(DialogResult::Ok(r)), Target::Script { color: given, cmyk }) => {
|
||||
// Between slices the window's front document sets the active profiles; the pick converts
|
||||
// through the profiles of the script's document instead.
|
||||
(Some(DialogResult::Ok(r)), Target::Script { color: given, cmyk, profiles }) => {
|
||||
let untouched = r.picked.color == open.start && r.picked.model == Some(model_values(given));
|
||||
let picked = if untouched { *given } else { in_model(*cmyk, color_of(&r.picked)) };
|
||||
let picked = if untouched { *given } else { script_pick(&r.picked, *cmyk, profiles) };
|
||||
app.session.script_answer(DialogAnswer::ColorPicker(Some(picked)));
|
||||
}
|
||||
(_, Target::Script { .. }) => {
|
||||
|
||||
@@ -358,7 +358,7 @@ pub fn offer(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option<St
|
||||
/// drawing is converted on a job of its own ([`crate::opening::convert_drawing`]) and its dialog
|
||||
/// opens once that is done ([`converted`]) → true; false when `bytes` aren't a DWG drawing.
|
||||
pub fn convert_in_background(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option<String>, place: Option<&Value>) -> bool {
|
||||
if !vectorcraft_cad::is_dwg(bytes) || fileio::detect(name, bytes).is_none_or(|f| !fileio::reads_as_dwg(f.id)) {
|
||||
if !vectorcraft_cad::dwg::DECODES || !vectorcraft_cad::is_dwg(bytes) || fileio::detect(name, bytes).is_none_or(|f| !fileio::reads_as_dwg(f.id)) {
|
||||
return false;
|
||||
}
|
||||
crate::opening::convert_drawing(app, name, bytes.to_vec(), path, place.cloned());
|
||||
@@ -372,7 +372,7 @@ pub fn convert_in_background(app: &mut VectorcraftApp, name: &str, bytes: &[u8],
|
||||
/// converted (true).
|
||||
pub fn convert_place_in_background(app: &mut VectorcraftApp, p: &Value) -> bool {
|
||||
let named = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension);
|
||||
if p.get("dxf").is_some() || !named.as_deref().is_some_and(is_dwg_ext) {
|
||||
if !vectorcraft_cad::dwg::DECODES || p.get("dxf").is_some() || !named.as_deref().is_some_and(is_dwg_ext) {
|
||||
return false;
|
||||
}
|
||||
let Some((name, bytes, path)) = place_source(app, p, is_dwg_ext) else { return false };
|
||||
@@ -532,8 +532,14 @@ fn confirm(app: &mut VectorcraftApp, source: &Source, choices: &DxfChoices) -> R
|
||||
if let Some(converted) = &source.converted {
|
||||
app.placing.keep_next = Some(Box::new(converted.held.clone()));
|
||||
}
|
||||
// The drawing placed is the one the dialog showed, not the file as it is on disk now;
|
||||
// its link and the journal keep the path.
|
||||
if let Some(path) = &source.path {
|
||||
app.placing.bytes_next = Some((path.clone(), source.file.clone()));
|
||||
}
|
||||
let r = crate::place::run_for_user(app, &p).map(|_| ());
|
||||
app.placing.keep_next = None;
|
||||
app.placing.bytes_next = None;
|
||||
if let (Some(current), Some(insertion)) = (current, restore) {
|
||||
current.restore_changed(&insertion, app);
|
||||
}
|
||||
@@ -965,6 +971,56 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
/// A DWG drawing placed through its dialog is the drawing the dialog previewed: a file written
|
||||
/// over it on disk while the dialog is open is not placed.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
#[test]
|
||||
fn ok_places_the_drawing_the_dialog_previewed() {
|
||||
fn placed_size(app: &mut VectorcraftApp) -> (f64, f64) {
|
||||
while !app.placing.pending.is_empty() {
|
||||
crate::placing::wait(app);
|
||||
crate::placing::poll(app);
|
||||
}
|
||||
let st = app.session.doc().unwrap();
|
||||
let mut out: Option<vectorcraft_geom::Rect> = None;
|
||||
st.doc.node(st.selection.objects[0]).unwrap().walk(&mut |c| {
|
||||
if let Some(b) = c.path_data().and_then(vectorcraft_geom::PathData::bounds) {
|
||||
out = Some(out.map_or(b, |o| o.union(b)));
|
||||
}
|
||||
});
|
||||
let r = out.unwrap();
|
||||
(r.width(), r.height())
|
||||
}
|
||||
vectorcraft_engine::dwg::allow_in_process();
|
||||
let (_dir, plan) = dwg_file("dxf-import-dwg-previewed");
|
||||
let flatter = String::from_utf8(drawing()).unwrap().replace(" 21\n50\n", " 21\n10\n");
|
||||
crate::opening::tests::with_threads(|| {
|
||||
let mut app = host::app();
|
||||
app.services.read = Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string())));
|
||||
app.run("file.new", json!({"width": 600, "height": 400})).unwrap();
|
||||
crate::place::run_for_user(&mut app, &json!({ "path": plan })).unwrap();
|
||||
finish_conversions(&mut app);
|
||||
host::confirm(&mut app, KIND).unwrap();
|
||||
let previewed = placed_size(&mut app);
|
||||
crate::place::run_for_user(&mut app, &json!({ "path": plan })).unwrap();
|
||||
finish_conversions(&mut app);
|
||||
assert_eq!(host::fields(&app, KIND)["mode"], "place");
|
||||
std::fs::write(&plan, craft_dwg::dxf_to_dwg_as(flatter.as_bytes(), "AC1018").unwrap()).unwrap();
|
||||
let before = app.session.doc().unwrap().selection.objects.clone();
|
||||
host::confirm(&mut app, KIND).unwrap();
|
||||
let size = placed_size(&mut app);
|
||||
assert_ne!(app.session.doc().unwrap().selection.objects, before, "OK places a new object");
|
||||
assert_eq!(size, previewed, "OK places the drawing the dialog opened on");
|
||||
assert!(app.placing.bytes_next.is_none());
|
||||
// Placed again, the file as it is on disk now is read.
|
||||
let before = app.session.doc().unwrap().selection.objects.clone();
|
||||
crate::place::run_for_user(&mut app, &json!({ "path": plan, "showImportOptions": false })).unwrap();
|
||||
let size = placed_size(&mut app);
|
||||
assert_ne!(app.session.doc().unwrap().selection.objects, before, "the place adds a new object");
|
||||
assert_ne!(size, previewed, "a later place reads the new file");
|
||||
});
|
||||
}
|
||||
|
||||
/// A DWG drawing converted off the UI thread and placed keeps its conversion until the place
|
||||
/// read off the UI thread is done.
|
||||
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//! cutting software and shows Custom again once one is changed), version, scale (1 unit of the
|
||||
//! art = N drawing units) and lineweights, number of colours, the format of placed images and
|
||||
//! Include Placed Images, Preserve Appearance or Maximize Editability, and Export Selected Art
|
||||
//! Only, Alter Paths for Appearance, Outline Text and Include Fill Hatches.
|
||||
//! Only, Alter Paths for Appearance, Outline Text, Include Fill Hatches and Always Export Group as
|
||||
//! Block Reference (not set by a preset).
|
||||
//!
|
||||
//! Fields: `document.export` params (`format: dxf`, `path?`, the artboard choice) and the DXF
|
||||
//! options of `document.exportDxf`. OK remembers the options for next time and writes the file
|
||||
@@ -37,6 +38,7 @@ fn defaults() -> Map<String, Value> {
|
||||
let mut m = preset_fields(DxfPreset::Custom);
|
||||
m.insert(PRESET.into(), json!(DxfPreset::Custom.id()));
|
||||
m.insert("selectedOnly".into(), json!(false));
|
||||
m.insert("groupBlocks".into(), json!(DxfPreset::Custom.options().group_blocks));
|
||||
m
|
||||
}
|
||||
|
||||
@@ -132,6 +134,7 @@ fn rows(selection: bool, has_selection: bool, note: bool) -> Vec<Param> {
|
||||
// Preserve Appearance always outlines type.
|
||||
check_param("outlineText", tl!("Outline Text")).enabled_when("preserve", FieldValue::Text(Preserve::Editability.id().into())),
|
||||
check_param("includeHatches", tl!("Include Fill Hatches")),
|
||||
check_param("groupBlocks", tl!("Always Export Group as Block Reference")),
|
||||
]);
|
||||
rows
|
||||
}
|
||||
|
||||
@@ -556,10 +556,24 @@ fn list_templates(app: &mut VectorcraftApp) -> (Vec<(String, String)>, Option<St
|
||||
|
||||
/// Save Metadata Template…: the fields as they are in the dialog, at the path a save pick answered. A name
|
||||
/// typed without `.xmp` takes it, so the templates list shows the file; a file already there under the
|
||||
/// completed name is replaced only after a question.
|
||||
/// completed name is replaced only after a question. In the document portal, which takes only the name
|
||||
/// answered, the save pick opens again with the completed name in the answer's folder.
|
||||
fn save_template(app: &mut VectorcraftApp, picked: PathBuf, fields: Info) -> Result<(), String> {
|
||||
let picked = picked.to_string_lossy().into_owned();
|
||||
let path = if picked.to_ascii_lowercase().ends_with(&format!(".{XMP_EXT}")) { picked.clone() } else { format!("{picked}.{XMP_EXT}") };
|
||||
if let Some((name, folder)) = crate::io::save::portal_ask_again(app, &picked, &path) {
|
||||
let mut request = template_request(name);
|
||||
if let Some(folder) = folder {
|
||||
request = request.directory(folder);
|
||||
}
|
||||
file_asks::ask(app, request, file_asks::Owner::Free, move |app, picked| {
|
||||
if let Some(path) = picked.first_path() {
|
||||
save_template(app, path, fields)?;
|
||||
}
|
||||
Ok(Value::Null)
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
// The save pick does not ask about the completed name.
|
||||
app.session.execute("file.info.templates", &json!({ "create": true })).map_err(|e| e.to_string())?;
|
||||
let save = {
|
||||
@@ -573,6 +587,11 @@ fn save_template(app: &mut VectorcraftApp, picked: PathBuf, fields: Info) -> Res
|
||||
save(app).map(|_| ())
|
||||
}
|
||||
|
||||
/// A save pick for a metadata template, suggesting `name`.
|
||||
fn template_request(name: String) -> PickRequest {
|
||||
PickRequest::save(PURPOSE).file_name(name).suggested_extension(XMP_EXT).filter(tl!("XMP metadata templates"), &[XMP_EXT])
|
||||
}
|
||||
|
||||
/// Save the draft through the browser's file service. Serializing it changes neither drawing nor draft.
|
||||
fn download_template(app: &mut VectorcraftApp, fields: Info) -> Result<(), String> {
|
||||
let title = text_of(&fields, "title");
|
||||
@@ -580,8 +599,7 @@ fn download_template(app: &mut VectorcraftApp, fields: Info) -> Result<(), Strin
|
||||
let name = format!("{stem}.{XMP_EXT}");
|
||||
let result = app.run("file.info.saveTemplate", json!({"fields": fields}))?;
|
||||
let data = result["data"].as_str().ok_or("the metadata template contains no data")?.as_bytes().to_vec();
|
||||
let request = PickRequest::save(PURPOSE).file_name(name).suggested_extension(XMP_EXT).filter(tl!("XMP metadata templates"), &[XMP_EXT]);
|
||||
file_asks::save(app, request, data, file_asks::Owner::Free, |app, picked| {
|
||||
file_asks::save(app, template_request(name), data, file_asks::Owner::Free, |app, picked| {
|
||||
match picked {
|
||||
Picked::Downloaded(name) => app.status(format!("Saved {name}")),
|
||||
Picked::Saved { path, .. } => app.status(format!("Saved {}", path.display())),
|
||||
@@ -884,6 +902,32 @@ mod tests {
|
||||
assert!(app.session.active().unwrap().history.undo.is_empty());
|
||||
}
|
||||
|
||||
/// In the document portal, which takes only the name the save pick answered, Save Metadata
|
||||
/// Template… writes nothing under the completed name (`Card` for `Card.xmp`): the save pick opens
|
||||
/// again in the answer's folder suggesting `Card.xmp`, and its answer is written.
|
||||
#[test]
|
||||
fn a_template_save_asks_again_for_a_name_the_document_portal_did_not_grant() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("ui-file-info-portal");
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let picker = crate::tests::picks::scripted(&mut app);
|
||||
app.session.attach_metadata_templates_dir(dir.join("Metadata Templates"));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let portal = "/run/user/1000/doc/a1b2c3d4";
|
||||
let fields = json!({"author": "Ada"}).as_object().cloned().unwrap_or_default();
|
||||
super::save_template(&mut app, format!("{portal}/Card").into(), fields).unwrap();
|
||||
let requests = picker.requests();
|
||||
let [again] = requests.as_slice() else { panic!("the save pick opens again: {requests:?}") };
|
||||
assert_eq!(again.file_name.as_deref(), Some("Card.xmp"));
|
||||
assert_eq!(again.directory.as_deref(), Some(std::path::Path::new(portal)));
|
||||
assert!(app.ui.status.contains("Card.xmp"), "{}", app.ui.status);
|
||||
let granted = dir.join("Card.xmp");
|
||||
picker.answer_saved(&granted.to_string_lossy(), None);
|
||||
let ctx = app.ui_ctx.clone().unwrap_or_default();
|
||||
crate::tests::picks::poll(&mut app, &ctx);
|
||||
assert!(std::fs::read_to_string(&granted).is_ok_and(|xmp| xmp.contains("Ada")), "the granted name is written");
|
||||
assert_eq!(picker.requests().len(), 1, "a granted name is written without asking again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_imported_template_fills_the_fields_and_ok_is_one_undo_step() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("ui-file-info-template");
|
||||
|
||||
@@ -69,6 +69,13 @@ impl DialogFile {
|
||||
}
|
||||
}
|
||||
|
||||
/// The file's bytes, as a place given them reads them ([`vectorcraft_engine::cmd::place::GivenBytes`]).
|
||||
impl AsRef<[u8]> for DialogFile {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&self.bytes
|
||||
}
|
||||
}
|
||||
|
||||
/// Equal by token: a token names one file's bytes, so a dialog's values compare without reading them.
|
||||
impl PartialEq for DialogFile {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
|
||||
@@ -148,7 +148,7 @@ impl MosaicSource {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned());
|
||||
}
|
||||
if st.history_restores != self.history_restores {
|
||||
return Err(tl!("Reopen Create Object Mosaic after Undo or Redo.").to_owned());
|
||||
return Err(tl!("Reopen Create Object Mosaic after Undo, Redo or a canceled edit.").to_owned());
|
||||
}
|
||||
match selected_image(app) {
|
||||
Some((source, size)) if source == self => Ok(size),
|
||||
|
||||
@@ -75,7 +75,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned());
|
||||
}
|
||||
if Some(active.history_restores) != opening["historyRestores"].as_u64() {
|
||||
return Err(tl!("Reopen Placement Options after Undo or Redo.").to_owned());
|
||||
return Err(tl!("Reopen Placement Options after Undo, Redo or a canceled edit.").to_owned());
|
||||
}
|
||||
let align = f.int("align").and_then(|i| usize::try_from(i).ok()).and_then(|i| ALIGN.get(i).copied()).unwrap_or(ALIGN[CENTRE]);
|
||||
let params = json!({ "ids": opening["ids"], "preserve": f.text("preserve"), "align": align, "clip": f.bool("clip").unwrap_or(false) });
|
||||
|
||||
@@ -93,8 +93,10 @@ pub(crate) fn open_with(app: &mut VectorcraftApp, f: &Format, mut params: Value,
|
||||
let initial = fields_of(&raster_rows(id, false, size, &DialogFields::new()), &map);
|
||||
let dialog = HostedParamDialog::new(&ctx, key.clone(), initial, move |fields| {
|
||||
normalize_colors(fields);
|
||||
if id == "bmp" {
|
||||
tiff_bmp_tga::normalize_bmp(fields);
|
||||
match id {
|
||||
"bmp" => tiff_bmp_tga::normalize_bmp(fields),
|
||||
"tga" => tiff_bmp_tga::normalize_tga(fields),
|
||||
_ => {}
|
||||
}
|
||||
ParamDialog::new(key.clone(), heading(label), raster_rows(id, false, size, fields)).values(Bind::bound(fields)).ok_label(tl!("Export").into())
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use serde_json::Value;
|
||||
use vectorcraft_doc::Selection;
|
||||
use vectorcraft_doc::{Document, Selection};
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
@@ -13,15 +13,22 @@ use crate::VectorcraftApp;
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct LivePreview {
|
||||
previewed: Option<(String, Value)>,
|
||||
/// The last preview ran without an error, so its result is on show.
|
||||
shown: bool,
|
||||
/// The document the last preview ran on. A change to it or the owner's selection snapshot
|
||||
/// reruns the preview, including one that failed.
|
||||
snapshot: Weak<Document>,
|
||||
owner: Option<Owner>,
|
||||
}
|
||||
|
||||
/// The interaction a preview ran in: its document's `uid` and `reverts`, and the selection snapshot the interaction
|
||||
/// began with, which no other interaction shares.
|
||||
/// began with, which no other interaction shares. A marked interaction ([`LivePreview::keep_outside_edits`]) is
|
||||
/// known by its mark instead, since a command from outside the dialog can give it a new selection.
|
||||
#[derive(Clone)]
|
||||
struct Owner {
|
||||
document: (u64, u64),
|
||||
selection: Weak<Selection>,
|
||||
marked: bool,
|
||||
}
|
||||
|
||||
impl LivePreview {
|
||||
@@ -30,7 +37,9 @@ impl LivePreview {
|
||||
let Some(owner) = &self.owner else { return false };
|
||||
app.session.active().is_some_and(|state| {
|
||||
(state.uid, state.reverts) == owner.document
|
||||
&& state.interaction.as_ref().is_some_and(|interaction| owner.selection.as_ptr() == Arc::as_ptr(&interaction.selection))
|
||||
&& state.interaction.as_ref().is_some_and(|interaction| {
|
||||
owner.selection.as_ptr() == Arc::as_ptr(&interaction.selection) || (owner.marked && interaction.dialog)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -43,8 +52,9 @@ impl LivePreview {
|
||||
}
|
||||
|
||||
/// While `on`, runs `cmd` with `params` on the interaction's snapshot whenever they differ from the last preview
|
||||
/// or its interaction has ended; `label` names the undo step. Returns the command's answer when this call ran a
|
||||
/// preview, and `None` when nothing ran: the same values again (a pass reruns nothing), a preview that could not
|
||||
/// or its interaction has ended or changed its document or selection snapshot; `label` names the undo step.
|
||||
/// Returns the command's answer when this call ran a preview, and `None` when nothing ran:
|
||||
/// the same values and snapshots again, a preview that could not
|
||||
/// begin, another edit in progress, or `on` off, which rolls a shown preview back. Typing in progress is kept as
|
||||
/// its own step first. A refusal's text is written for the user, without the command's id.
|
||||
pub(crate) fn run(&mut self, app: &mut VectorcraftApp, on: bool, label: &str, cmd: &str, params: &Value) -> Option<Result<Value, String>> {
|
||||
@@ -56,8 +66,14 @@ impl LivePreview {
|
||||
self.owner = None;
|
||||
return None;
|
||||
}
|
||||
// A command from outside the dialog took a shown preview off its interaction: it runs again.
|
||||
let taken_off = app.session.active().and_then(|state| state.interaction.as_ref()).is_some_and(|it| {
|
||||
(self.shown && it.preview.is_none())
|
||||
|| self.snapshot.as_ptr() != Arc::as_ptr(&it.doc)
|
||||
|| self.owner.as_ref().is_some_and(|owner| owner.selection.as_ptr() != Arc::as_ptr(&it.selection))
|
||||
});
|
||||
let same = self.previewed.as_ref().is_some_and(|(c, p)| c == cmd && p == params);
|
||||
if same {
|
||||
if same && !taken_off {
|
||||
return None;
|
||||
}
|
||||
// Another dialog's, a panel's or a tool's edit in progress gets no preview of this one.
|
||||
@@ -87,9 +103,11 @@ impl LivePreview {
|
||||
}
|
||||
};
|
||||
self.previewed = Some((cmd.to_string(), params.clone()));
|
||||
self.shown = answer.is_ok();
|
||||
self.owner = app.session.active().and_then(|state| {
|
||||
let interaction = state.interaction.as_ref()?;
|
||||
Some(Owner { document: (state.uid, state.reverts), selection: Arc::downgrade(&interaction.selection) })
|
||||
self.snapshot = Arc::downgrade(&interaction.doc);
|
||||
Some(Owner { document: (state.uid, state.reverts), selection: Arc::downgrade(&interaction.selection), marked: interaction.dialog })
|
||||
});
|
||||
Some(answer)
|
||||
}
|
||||
@@ -131,6 +149,18 @@ impl LivePreview {
|
||||
Self::default().commit(app, cmd, params)
|
||||
}
|
||||
|
||||
/// Has a command from outside the dialog (a panel's Delete) run as an undo step of its own while this preview
|
||||
/// shows, so that the next preview, OK and Cancel keep its edit.
|
||||
pub(crate) fn keep_outside_edits(&mut self, app: &mut VectorcraftApp) {
|
||||
if self.owns(app)
|
||||
&& let Some(interaction) = app.session.active_mut().and_then(|state| state.interaction.as_mut())
|
||||
&& let Some(owner) = &mut self.owner
|
||||
{
|
||||
interaction.dialog = true;
|
||||
owner.marked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancel: rolls a shown preview back, and leaves any other edit in progress as it is.
|
||||
pub(crate) fn cancel(self, app: &mut VectorcraftApp) {
|
||||
if self.previewed.is_some() && self.owns(app) {
|
||||
|
||||
@@ -1222,6 +1222,7 @@ mod tests {
|
||||
preset: String::new(),
|
||||
color: None,
|
||||
cmyk_document: false,
|
||||
profiles: (None, None),
|
||||
};
|
||||
let ctx = egui::Context::default();
|
||||
// A script's own confirm with the same text takes Yes.
|
||||
|
||||
@@ -151,6 +151,29 @@ fn include_placed_images_and_fill_hatches_follow_the_preset_and_a_change_shows_c
|
||||
assert_eq!(shown(&app), ("custom".into(), true, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn always_export_group_as_block_reference_writes_an_insert_and_stays_through_a_preset() {
|
||||
let (mut app, written) = app(1);
|
||||
app.run("object.group", json!({})).unwrap();
|
||||
app.run("ui.dxfOptionsDialog", json!({"path": "/out/a.dxf"})).unwrap();
|
||||
frame(&mut app);
|
||||
assert_eq!(fields(&app).bool("groupBlocks"), Some(false), "off by default");
|
||||
set(&mut app, "groupBlocks", json!(true));
|
||||
// A preset sets the fields it sets and leaves this one as it is.
|
||||
set(&mut app, "dxfPreset", json!("cnc"));
|
||||
frame(&mut app);
|
||||
assert_eq!((show(&fields(&app), "dxfPreset"), fields(&app).bool("groupBlocks")), ("cnc".into(), Some(true)));
|
||||
confirm(&mut app);
|
||||
let dxf = text(&written.borrow()[0].1);
|
||||
let start = dxf.find("\nENTITIES\n").unwrap();
|
||||
let entities = &dxf[start..start + dxf[start..].find("\nENDSEC\n").unwrap()];
|
||||
assert_eq!(entities.matches("\n 0\n").count(), 1, "the group alone, as one entity: {entities}");
|
||||
assert!(entities.contains("\n 0\nINSERT\n"), "{entities}");
|
||||
assert_eq!(app.ui.dxf_options["groupBlocks"].as_bool(), Some(true), "remembered for the next export");
|
||||
crate::menus::invoke(&mut app, "ui.dxfOptionsDialog", json!({}));
|
||||
assert_eq!(fields(&app).bool("groupBlocks"), Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_dxf_options_keep_the_dialog_open() {
|
||||
let (mut app, written) = app(1);
|
||||
|
||||
@@ -39,9 +39,32 @@ fn bmp_options_keep_their_choices_writable() {
|
||||
assert_eq!((&bmp[..2], bmp[28], bmp[30]), (&b"BM"[..], 8, 1), "8-bit RLE8");
|
||||
}
|
||||
|
||||
/// Targa at 24 bits is flattened on white; its other depths keep transparency.
|
||||
/// Targa at 24 bits, and grayscale at 8, is flattened on white; 16 and 32 bits keep transparency.
|
||||
#[test]
|
||||
fn targa_keeps_transparency_above_24_bits() {
|
||||
fn targa_keeps_transparency_at_16_and_32_bits() {
|
||||
assert!(!tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("depth", "24")])));
|
||||
assert!(tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("depth", "32")])));
|
||||
assert!(!tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("colorModel", "gray"), ("depth", "8")])));
|
||||
assert!(tiff_bmp_tga::keeps_alpha("tga", &DialogFields::from_pairs([("colorModel", "gray"), ("depth", "16")])));
|
||||
}
|
||||
|
||||
/// Targa Options' Color Model writes a grayscale file, and a change of model moves the depth to
|
||||
/// one that model has.
|
||||
#[test]
|
||||
fn targa_color_model_reaches_the_file() {
|
||||
let (mut app, written) = app(1);
|
||||
app.run("file.exportAs", json!({"format": "tga"})).unwrap();
|
||||
confirm(&mut app);
|
||||
assert_eq!(kind(&app).as_deref(), Some("tgaOptions"));
|
||||
let f = fields(&app);
|
||||
assert_eq!((f.text("colorModel"), f.text("depth")), (Some("rgb"), Some("24")));
|
||||
frame(&mut app);
|
||||
// Grayscale has no 24 bits: the depth moves to 8.
|
||||
set(&mut app, "colorModel", json!("gray"));
|
||||
frame(&mut app);
|
||||
assert_eq!(fields(&app).text("depth"), Some("8"));
|
||||
confirm(&mut app);
|
||||
let (path, tga) = written.borrow()[0].clone();
|
||||
assert_eq!(path, "/out/Untitled-1.tga");
|
||||
assert_eq!((tga[2], tga[16]), (3, 8), "8-bit grayscale");
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The options of TIFF (colour model, byte order, LZW, profile), BMP (colour model, layout, depth,
|
||||
//! palette, RLE, row order) and Targa (depth), after the raster export rows they share with PNG
|
||||
//! palette, RLE, row order) and Targa (colour model, depth), after the raster export rows they share with PNG
|
||||
//! Options ([`super::png_options`]): the `tiffOptions`, `bmpOptions` and `tgaOptions` dialogs.
|
||||
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, Param};
|
||||
@@ -12,14 +12,15 @@ use vectorcraft_render::encode::tiff::{ByteOrder, TiffOptions};
|
||||
|
||||
use super::png_options::{check, choice};
|
||||
|
||||
/// BMP colour models and layouts: param values and labels.
|
||||
/// BMP and Targa colour models and BMP layouts: param values and labels.
|
||||
const BMP_MODELS: [&str; 2] = ["rgb", "gray"];
|
||||
const BMP_MODEL_LABELS: [&str; 2] = ["RGB", "Grayscale"];
|
||||
const LAYOUTS: [&str; 2] = ["windows", "os2"];
|
||||
const LAYOUT_LABELS: [&str; 2] = ["Windows", "OS/2"];
|
||||
/// Labels of [`bmp::DEPTHS`] and [`tga::DEPTHS`].
|
||||
/// Labels of [`bmp::DEPTHS`], [`tga::DEPTHS`] and [`tga::GRAY_DEPTHS`].
|
||||
const BMP_DEPTH_LABELS: [&str; 6] = ["1 bit", "4 bit", "8 bit", "16 bit", "24 bit", "32 bit"];
|
||||
const TGA_DEPTH_LABELS: [&str; 3] = ["16 bits/pixel", "24 bits/pixel", "32 bits/pixel"];
|
||||
const TGA_GRAY_DEPTH_LABELS: [&str; 2] = ["8 bits/pixel", "16 bits/pixel"];
|
||||
|
||||
/// The options format `id` starts with (`cmyk`: a CMYK document exports CMYK TIFFs).
|
||||
pub(super) fn defaults(id: &str, cmyk: bool, o: &mut Map<String, Value>) {
|
||||
@@ -47,7 +48,8 @@ pub(super) fn defaults(id: &str, cmyk: bool, o: &mut Map<String, Value>) {
|
||||
]);
|
||||
}
|
||||
"tga" => {
|
||||
o.insert("depth".into(), json!(TgaOptions::default().depth.to_string()));
|
||||
let t = TgaOptions::default();
|
||||
o.extend([("colorModel".into(), json!(BMP_MODELS[usize::from(t.gray)])), ("depth".into(), json!(t.depth.to_string()))]);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -64,7 +66,7 @@ pub(super) fn keeps_alpha(id: &str, f: &DialogFields) -> bool {
|
||||
"jpg" => false,
|
||||
"tiff" => ColorModel::from_id(f.text("colorModel").unwrap_or_default()).unwrap_or_default() == ColorModel::Rgb,
|
||||
"bmp" => depth(f) == 32.0,
|
||||
"tga" => depth(f) != 24.0,
|
||||
"tga" => matches!(depth(f) as u8, 16 | 32),
|
||||
// A flat PSD is flattened; its layers keep transparency.
|
||||
"psd" => f.text("layers") == Some("true"),
|
||||
_ => true,
|
||||
@@ -81,11 +83,33 @@ pub(super) fn params(id: &str, fields: &DialogFields) -> Vec<Param> {
|
||||
check("embedIcc", tl!("Embed ICC Profile"), true),
|
||||
],
|
||||
"bmp" => bmp_params(fields),
|
||||
"tga" => vec![choice("depth", tl!("Depth:"), &tga::DEPTHS.map(|d| d.to_string()), &TGA_DEPTH_LABELS)],
|
||||
"tga" => {
|
||||
let depth = if tga_gray(fields) {
|
||||
choice("depth", tl!("Depth:"), &tga::GRAY_DEPTHS.map(|d| d.to_string()), &TGA_GRAY_DEPTH_LABELS)
|
||||
} else {
|
||||
choice("depth", tl!("Depth:"), &tga::DEPTHS.map(|d| d.to_string()), &TGA_DEPTH_LABELS)
|
||||
};
|
||||
vec![choice("colorModel", tl!("Color Model:"), &BMP_MODELS, &BMP_MODEL_LABELS), depth]
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Does the Targa dialog hold the grayscale colour model?
|
||||
fn tga_gray(f: &DialogFields) -> bool {
|
||||
f.text("colorModel") == Some(BMP_MODELS[1])
|
||||
}
|
||||
|
||||
/// Keep the Targa depth one the colour model has: a change of model starts the depth at that
|
||||
/// model's default (24 bits for RGB, 8 for grayscale).
|
||||
pub(super) fn normalize_tga(f: &mut DialogFields) {
|
||||
let gray = tga_gray(f);
|
||||
let bits = depth(f);
|
||||
if !TgaOptions::depths(gray).iter().any(|d| f64::from(*d) == bits) {
|
||||
f.set("depth", TgaOptions::default_depth(gray).to_string());
|
||||
}
|
||||
}
|
||||
|
||||
fn bmp_params(fields: &DialogFields) -> Vec<Param> {
|
||||
let os2 = fields.text("fileFormat") == Some(LAYOUTS[1]);
|
||||
let depths = bmp::DEPTHS.map(|d| d.to_string());
|
||||
|
||||
@@ -131,10 +131,6 @@ pub struct Windows {
|
||||
known: Vec<u64>,
|
||||
/// The documents' views beyond the one each shows ([`views`]).
|
||||
pub(crate) views: Views,
|
||||
/// The panes drawn outside Tile in this frame so far (the floating windows', the main window's while the current
|
||||
/// window floats), back to front, with the art area each takes drops in; and those of the last frame.
|
||||
pub(crate) noted: Vec<(Win, egui::Rect)>,
|
||||
pub(crate) last_noted: Vec<(Win, egui::Rect)>,
|
||||
/// The main window's density and the floating windows' ([`floating_ppi`]) when the views were
|
||||
/// last settled each frame ([`VectorcraftApp::settle_screen_ppi_if_changed`]).
|
||||
pub(crate) settled: Option<(crate::ScreenPpi, Vec<FloatingPpi>)>,
|
||||
@@ -373,12 +369,10 @@ pub(crate) fn focus_main_window(app: &VectorcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
/// Draw the floating document windows, after the main window's canvas, then the drop catcher of the main window's
|
||||
/// pane, which waited for the current window's body. Call once per frame from the main window. Art released over a
|
||||
/// pane in the frame the pointer reached it drops there then.
|
||||
/// pane, which waited for the current window's body. Call once per frame from the main window.
|
||||
pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
|
||||
show_windows(app, ui);
|
||||
crate::canvas::panes::catch_waiting(app, ui);
|
||||
crate::canvas::panes::drop_released(app);
|
||||
}
|
||||
|
||||
/// [`show`]'s windows.
|
||||
|
||||
@@ -127,13 +127,14 @@ impl VectorcraftApp {
|
||||
/// after losing its graphics), everything uploaded to the old one is made again: the fonts and
|
||||
/// theme, the canvas, the place cursor's thumbnails and every [`TexCache`]. The host hands it
|
||||
/// the window's context when it creates the app, so the first frame's input has the app's
|
||||
/// commands.
|
||||
/// commands. Each new context draws its text without hinting ([`crate::ui_fonts::hinting_off`]).
|
||||
pub fn adopt_context(&mut self, ctx: &egui::Context) {
|
||||
let tag = context_tag(ctx);
|
||||
self.ui_ctx = Some(ctx.clone());
|
||||
if self.context == tag {
|
||||
return;
|
||||
}
|
||||
crate::ui_fonts::hinting_off(ctx);
|
||||
if self.context != 0 {
|
||||
log::info!("vectorcraft: new graphics context: uploading the UI again");
|
||||
forget_textures();
|
||||
|
||||
@@ -235,9 +235,43 @@ fn write_step(app: &mut VectorcraftApp, uid: u64, path: &str, target: SaveTarget
|
||||
let path = with_picked_type(&answered, &suggested, picked_ext.as_deref(), first.format, mode);
|
||||
// The flow ends here: the questions and options dialogs that follow run on the path alone.
|
||||
app.saves.release(uid);
|
||||
if portal_renamed(&answered, &path) {
|
||||
let name = confirm_portal_name(app, &answered, &path);
|
||||
let folder = Path::new(&answered).parent().map(Path::to_path_buf);
|
||||
return ask_again(app, mode, ¶ms, ask, target, retrying, (name, folder));
|
||||
}
|
||||
replaces_unasked(app, &answered, &path, move |app, path| finish_picked(app, mode, ¶ms, ask, &path, retrying))
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// The save panel again for the active document's save (`mode`, `params`), in the folder the last
|
||||
/// answer was in and suggesting `name` in the format its extension names, as a new flow with the
|
||||
/// same options question (`ask_options`) and `target`. A read-only retry (`retrying`) that changes
|
||||
/// format drops the options it carries and asks for the new format's, as [`finish_picked`] does.
|
||||
fn ask_again(
|
||||
app: &mut VectorcraftApp,
|
||||
mode: SaveMode,
|
||||
params: &Value,
|
||||
mut ask_options: bool,
|
||||
target: SaveTarget,
|
||||
retrying: bool,
|
||||
(name, directory): (String, Option<PathBuf>),
|
||||
) -> Result<Value, String> {
|
||||
let original = plan(app, mode, &acknowledged(params))?.format.id;
|
||||
let mut q = if params.is_object() { params.clone() } else { json!({}) };
|
||||
if let Some(f) = fileio::format_for_name(&name) {
|
||||
if retrying && f.id != original {
|
||||
if let Some(o) = q.as_object_mut() {
|
||||
o.remove("options");
|
||||
}
|
||||
ask_options = true;
|
||||
}
|
||||
q["format"] = json!(f.id);
|
||||
}
|
||||
let first = plan(app, mode, &acknowledged(&q))?;
|
||||
start_flow(app, &first, Start { mode, params: &q, ask_options, target, retry: None, name, directory, retrying })
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// What [`start_flow`] needs besides the plan.
|
||||
struct Start<'a> {
|
||||
@@ -456,7 +490,7 @@ fn ask_path(
|
||||
return then(app, with_written_extension(&name, &ext, &keeps));
|
||||
}
|
||||
let mut request = PickRequest::save("export").file_name(name);
|
||||
request.filters = filters;
|
||||
request.filters = filters.clone();
|
||||
if let Some(folder) = folder {
|
||||
request = request.directory(folder);
|
||||
}
|
||||
@@ -464,10 +498,54 @@ fn ask_path(
|
||||
let Picked::Saved { path: picked, .. } = picked else { return Err("cancelled".into()) };
|
||||
let picked = picked.to_string_lossy().into_owned();
|
||||
let path = with_written_extension(&picked, &ext, &keeps);
|
||||
if let Some((name, folder)) = portal_ask_again(app, &picked, &path) {
|
||||
let folder = folder.map(|p| p.to_string_lossy().into_owned());
|
||||
return ask_path(app, None, name, folder, filters, ext, keeps, then);
|
||||
}
|
||||
replaces_unasked(app, &picked, &path, then)
|
||||
}))
|
||||
}
|
||||
|
||||
/// Whether `path` is a file in a folder of the document portal (`/run/user/<uid>/doc/<id>/` or
|
||||
/// `/run/flatpak/doc/<id>/`), where the save panel's answers point in a Flatpak sandbox. The portal
|
||||
/// puts only the name the panel answered into the folder picked in it: a file written there under
|
||||
/// another name is written without an error, and the folder gets no file.
|
||||
fn in_document_portal(path: &str) -> bool {
|
||||
let rest = path.strip_prefix("/run/flatpak/doc/").or_else(|| {
|
||||
let (uid, rest) = path.strip_prefix("/run/user/")?.split_once('/')?;
|
||||
if uid.is_empty() || !uid.bytes().all(|b| b.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
rest.strip_prefix("doc/")
|
||||
});
|
||||
rest.and_then(|r| r.split_once('/')).is_some_and(|(id, name)| !id.is_empty() && !name.is_empty() && !name.contains('/'))
|
||||
}
|
||||
|
||||
/// Whether the save panel's answer `picked` was made into another name, `path`, in a folder of the
|
||||
/// document portal ([`in_document_portal`]).
|
||||
fn portal_renamed(picked: &str, path: &str) -> bool {
|
||||
path != picked && in_document_portal(picked)
|
||||
}
|
||||
|
||||
/// The file name of `path`, for the save panel to ask with again in place of the answer `picked`;
|
||||
/// the status bar says why the panel opens again.
|
||||
fn confirm_portal_name(app: &mut VectorcraftApp, picked: &str, path: &str) -> String {
|
||||
let name = fileio::file_name(path);
|
||||
app.status(format!("The file chooser can only save “{}”: confirm “{name}” to save it", fileio::file_name(picked)));
|
||||
name
|
||||
}
|
||||
|
||||
/// When `path`, the file the save panel's answer `picked` was made into, is another name in a
|
||||
/// folder of the document portal ([`portal_renamed`]): the name for the save panel to ask with
|
||||
/// again and the folder of the answer, for it to open in. The status bar says why.
|
||||
pub(crate) fn portal_ask_again(app: &mut VectorcraftApp, picked: &str, path: &str) -> Option<(String, Option<PathBuf>)> {
|
||||
if !portal_renamed(picked, path) {
|
||||
return None;
|
||||
}
|
||||
let name = confirm_portal_name(app, picked, path);
|
||||
Some((name, std::path::Path::new(picked).parent().map(std::path::Path::to_path_buf)))
|
||||
}
|
||||
|
||||
/// `path` as typed in a save panel for a file with extension `ext`: kept when its extension is
|
||||
/// `ext` in any letter case, or names the format `ext` names (`photo.jpeg` for a `.jpg` file) or
|
||||
/// a format `keeps` takes. An extension that names another format (`card.svg` for a `.png` file)
|
||||
|
||||
@@ -310,6 +310,31 @@ fn readonly_changed_format_asks_for_its_options_before_writing() {
|
||||
assert_eq!(files.lock().unwrap().attempts, ["/locked/Poster.svg"]);
|
||||
}
|
||||
|
||||
/// The retry's save panel in the document portal, with PDF picked and `Poster.svg` kept: the panel
|
||||
/// opens again for `Poster.pdf`, and its answer asks for the PDF options before writing.
|
||||
#[test]
|
||||
fn readonly_changed_format_in_the_document_portal_asks_for_its_options_before_writing() {
|
||||
let portal = "/run/user/1000/doc/a1b2c3d4";
|
||||
let (mut app, files) = app("svg", ErrorKind::PermissionDenied);
|
||||
let before = state(&app);
|
||||
let picker = scripted(&mut app);
|
||||
assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "fileDialog");
|
||||
let pdf = picker.requests()[0].filters.iter().position(|f| f.extensions.iter().any(|e| e == "pdf"));
|
||||
assert!(pdf.is_some(), "the retry's save panel offers PDF");
|
||||
picker.answer_saved(&format!("{portal}/Poster.svg"), pdf);
|
||||
poll(&mut app);
|
||||
assert!(fields_of(&app, "pdf-export").is_none(), "no options before the name is granted");
|
||||
assert_eq!(picker.requests().len(), 2, "the save panel opens again");
|
||||
assert_eq!(picker.requests()[1].file_name.as_deref(), Some("Poster.pdf"));
|
||||
picker.answer_saved(&format!("{portal}/Poster.pdf"), None);
|
||||
poll(&mut app);
|
||||
assert!(fields_of(&app, "pdf-export").is_some(), "the picked format's Save dialog");
|
||||
let job = app.save_pdf.as_ref().and_then(|open| open.job.as_ref());
|
||||
assert_eq!(job.and_then(|job| job.path.clone()), Some(format!("{portal}/Poster.pdf")));
|
||||
assert_eq!(state(&app), before);
|
||||
assert_eq!(files.lock().unwrap().attempts, ["/locked/Poster.svg"]);
|
||||
}
|
||||
|
||||
/// Typed saves keep the sidecar preflight both before the refused write and at the retry's
|
||||
/// destination. Confirming the ordinary Save still permits its one read-only fallback.
|
||||
#[test]
|
||||
|
||||
@@ -354,6 +354,9 @@ pub struct VectorcraftApp {
|
||||
/// (`--automation-read-root`, `--automation-write-root`); `None`: anywhere. See
|
||||
/// [`Self::with_automation_roots`].
|
||||
automation_roots: Option<Arc<AutomationRoots>>,
|
||||
/// The last root frame of a drop of files the OS made in a pass that carried injected input: the drag session
|
||||
/// delivers that drop in the next frame, which [`Self::ui`] confines to the automation roots as well.
|
||||
confined_drop: Option<u64>,
|
||||
/// The agents link while the ArtCraft Launcher's switch may let agents in ([`Self::with_agents`]).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) agents: Option<Box<agents::Agents>>,
|
||||
|
||||
@@ -1781,7 +1781,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.placementOptionsDialog",
|
||||
"Placement Options…",
|
||||
"",
|
||||
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo or Redo there (reopen the dialog)",
|
||||
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo, a Redo or a canceled edit that put back an earlier state there (reopen the dialog)",
|
||||
),
|
||||
(
|
||||
"ui.relinkDialog",
|
||||
|
||||
@@ -1326,19 +1326,15 @@ pub(crate) fn os_window_at(app: &VectorcraftApp, ctx: &egui::Context, pos: egui:
|
||||
if app.dock_rt.windows.is_empty() {
|
||||
return false;
|
||||
}
|
||||
// Workaround for craft-libs#4739: `WindowHost::viewports_at` still lists palette windows that are minimized, or
|
||||
// hidden while a dialog or popup shows. Remove these checks when the craft-libs pin includes craft-libs#4739.
|
||||
// A dialog hides the palette windows a few passes after it opens, and `WindowHost::viewports_at` lists them until
|
||||
// then: while a dialog is open, none counts.
|
||||
if app.any_dialog_open() {
|
||||
return false;
|
||||
}
|
||||
let origin = ctx.input(|i| i.raw.viewports.get(&i.raw.viewport_id).and_then(|v| v.inner_rect).map(|r| r.min.to_vec2()));
|
||||
let Some(origin) = origin else { return false };
|
||||
let host = craft::ui::runtime::windows::WindowHost::of(ctx);
|
||||
let under = host.viewports_at(pos + origin);
|
||||
// Workaround for craft-libs#4739 (see above).
|
||||
let restored =
|
||||
|viewport: &egui::ViewportId| host.facts(*viewport).is_some_and(|facts| facts.state != craft::host::target::WindowState::Minimized);
|
||||
under.iter().filter(|viewport| restored(viewport)).any(|viewport| app.dock_rt.windows.iter().any(|(_, shown)| shown == viewport))
|
||||
let under = craft::ui::runtime::windows::WindowHost::of(ctx).viewports_at(pos + origin);
|
||||
under.iter().any(|viewport| app.dock_rt.windows.iter().any(|(_, shown)| shown == viewport))
|
||||
}
|
||||
|
||||
/// Brings the OS window of the floating window holding `panel` forward, as it was last drawn.
|
||||
|
||||
@@ -696,7 +696,8 @@ fn a_hidden_palette_window_does_not_cover_the_canvas() {
|
||||
let id = h.app.dialogs().expect("a window").with(|host| host.open_dialogs().last().map(|d| d.id)).expect("a dialog is open");
|
||||
assert!(h.app.dialogs().expect("a window").with(|host| host.cancel_by_id(&ctx, id)), "the dialog took the answer");
|
||||
crate::dialogs::host::pump(&mut h.app, &ctx);
|
||||
h.frames(2);
|
||||
// The palettes show again in the pass after the one that saw the dialog gone, which that pass asks for.
|
||||
h.frames(3);
|
||||
assert!(!h.app.any_dialog_open(), "the dialog closed");
|
||||
assert!(os_window_at(&h.app, &h.ctx, middle), "the palette covers the canvas again once the dialog closes");
|
||||
}
|
||||
@@ -2,7 +2,7 @@ use super::tests_support::*;
|
||||
use super::*;
|
||||
use craft::automation::actions::{Action, ActionList, ActionStep};
|
||||
use craft::quit::CloseAnswer;
|
||||
use craft::ui::dialog::{DialogHost, UnsavedChangesDialog};
|
||||
use craft::ui::dialog::{DialogHost, HostedUnsavedChangesDialog};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
/// The list index of the first action of the first set: the action the fixtures build and these tests edit.
|
||||
@@ -507,8 +507,8 @@ fn closing_the_playing_document_ends_a_paced_playback() {
|
||||
let close = |app: &mut VectorcraftApp, p: Value| {
|
||||
assert_eq!(app.run("file.close", p).unwrap(), json!({"pending": crate::unsaved::KIND}));
|
||||
on_host(app, |host, ctx| {
|
||||
host.get_mut::<UnsavedChangesDialog>().unwrap().set_answer(CloseAnswer::DontSave);
|
||||
host.confirm::<UnsavedChangesDialog>(ctx)
|
||||
host.get_mut::<HostedUnsavedChangesDialog>().unwrap().set_answer(CloseAnswer::DontSave);
|
||||
host.confirm::<HostedUnsavedChangesDialog>(ctx)
|
||||
});
|
||||
};
|
||||
// Step by Step, the only document closed: no document is active when the next step is due.
|
||||
|
||||
@@ -599,11 +599,12 @@ fn cmd_click_on_the_gradient_fill_box_resets_only_the_selected_characters() {
|
||||
}
|
||||
|
||||
// PLAN: assumed color-w10's Swatches panel: each swatch tile is named by its swatch's name and drags a `PanelDrag::Paint` with `params {swatch}` (wg.S7).
|
||||
/// The Swatches panel over the Gradient panel: a swatch tile dragged onto the slider is a real drop.
|
||||
/// The Gradient panel over the Swatches panel, which fills the room under it: a swatch tile dragged onto the slider is
|
||||
/// a real drop.
|
||||
fn with_swatches(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
super::super::swatches::show(app, ui);
|
||||
show(app, ui);
|
||||
super::super::swatches::show(app, ui);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -428,7 +428,22 @@ pub(crate) fn unembed(app: &mut VectorcraftApp, id: u64, name: &str) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
ask(app, PickRequest::save("links").file_name(name), move |app, path| {
|
||||
ask_unembed(app, id, PickRequest::save("links").file_name(name));
|
||||
}
|
||||
|
||||
/// Asks `request`'s save panel where to write embedded image `id`, and unembeds it there. In the
|
||||
/// document portal, which takes only the name answered, a name without an extension opens the panel
|
||||
/// again with the stored format's extension added, in the answer's folder.
|
||||
fn ask_unembed(app: &mut VectorcraftApp, id: u64, request: PickRequest) {
|
||||
ask(app, request, move |app, path| {
|
||||
let written = vectorcraft_engine::cmd::links::unembed_path(&app.session, id, &path);
|
||||
if let Some((name, folder)) = written.and_then(|written| crate::io::save::portal_ask_again(app, &path, &written)) {
|
||||
let mut request = PickRequest::save("links").file_name(name);
|
||||
if let Some(folder) = folder {
|
||||
request = request.directory(folder);
|
||||
}
|
||||
return ask_unembed(app, id, request);
|
||||
}
|
||||
let r = app.run("links.unembed", json!({ "id": id, "path": path }));
|
||||
report(app, r, |v| format!("Unembedded to {}", v["path"].as_str().unwrap_or_default()));
|
||||
});
|
||||
|
||||
@@ -1616,11 +1616,13 @@ fn two_corner_radii(panel: &Panel, a: u64, b: u64) -> (Vec<f64>, Vec<f64>) {
|
||||
(corner_radii(&app, a), corner_radii(&app, b))
|
||||
}
|
||||
|
||||
/// The radius of each corner of live-cornered path `id`, in document lengths.
|
||||
/// The radius at each anchor of live-cornered path `id`, by anchor index counted across subpaths,
|
||||
/// in document lengths. An anchor that is not a corner, such as an open subpath's end, reads 0.
|
||||
fn corner_radii(app: &VectorcraftApp, id: u64) -> Vec<f64> {
|
||||
let n = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().clone();
|
||||
let lc = vectorcraft_doc::LiveCorners::of(&n).unwrap();
|
||||
(0..lc.all().len()).map(|k| crate::panels::corner_length(&lc, k)).collect()
|
||||
let anchors = lc.base.subpaths.iter().map(|sp| sp.anchors.len()).sum();
|
||||
(0..anchors).map(|k| if lc.corner(k).is_some() { crate::panels::corner_length(&lc, k) } else { 0.0 }).collect()
|
||||
}
|
||||
|
||||
/// A corner radius typed and not yet entered is dropped when the selection moves to other corners
|
||||
@@ -1729,11 +1731,12 @@ fn rounding_a_direct_selected_corner_keeps_the_corner_fields_target() {
|
||||
assert_eq!(target(&app), before, "the same corner is the target");
|
||||
}
|
||||
|
||||
/// Reversing a path drops an unfinished radius when the picked index names a different corner:
|
||||
/// an expanded rectangle, a path whose first corner and last corner have sides of the same
|
||||
/// lengths and turn the same way, a crossing path whose corners share a position, a path whose
|
||||
/// reversed corner has sides in the same directions, a path with two corners at the same point
|
||||
/// whose sides lean the same ways, and a small subpath beside a very large one.
|
||||
/// Reversing a path drops an unfinished radius, both while the picked anchor follows its point to
|
||||
/// its new index and when the old index is picked again and names a different corner: an expanded
|
||||
/// rectangle, a path whose first corner and last corner have sides of the same lengths and turn
|
||||
/// the same way, a crossing path whose corners share a position, a path whose reversed corner has
|
||||
/// sides in the same directions, a path with two corners at the same point whose sides lean the
|
||||
/// same ways, and a small subpath beside a very large one.
|
||||
#[test]
|
||||
fn an_unfinished_corner_radius_is_dropped_when_the_path_is_reversed() {
|
||||
let mut app = new_app();
|
||||
@@ -1757,24 +1760,48 @@ fn an_unfinished_corner_radius_is_dropped_when_the_path_is_reversed() {
|
||||
("coincident corners", coincident, 1),
|
||||
("small subpath", small, 1),
|
||||
] {
|
||||
// Where the corner at `index` is and the directions its sides leave it in.
|
||||
let corner = |app: &VectorcraftApp| {
|
||||
// Where corner `k` is and the directions its sides leave it in.
|
||||
let corner = |app: &VectorcraftApp, k: usize| {
|
||||
let node = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap();
|
||||
let c = *vectorcraft_doc::LiveCorners::of(node).unwrap().corner(index).unwrap();
|
||||
let c = *vectorcraft_doc::LiveCorners::of(node).unwrap().corner(k).unwrap();
|
||||
(c.at, c.u, c.v)
|
||||
};
|
||||
// The anchors of the first subpath, where `index` is.
|
||||
let first_subpath = |app: &VectorcraftApp| {
|
||||
app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().path_data().unwrap().subpaths[0].anchors.len()
|
||||
};
|
||||
|
||||
// The picked anchor follows its point to its new index, and the draft is dropped.
|
||||
panel.app().run("select.anchors", json!({"id": id, "anchors": [[0, index]], "mode": "set"})).unwrap();
|
||||
panel.frame();
|
||||
let before = corner(&panel.app());
|
||||
let before = corner(&panel.app(), index);
|
||||
let reversed = first_subpath(&panel.app()) - 1 - index;
|
||||
finish_after_change(&mut panel, case, "Corner Radius", "0 pt", |app| {
|
||||
app.run("path.reverse", json!({"ids": [id]})).unwrap();
|
||||
});
|
||||
let app = panel.app();
|
||||
assert_ne!(corner(&app), before, "{case}: index {index} names a different corner");
|
||||
let mut app = panel.app();
|
||||
let picked = picked_corner(&app);
|
||||
assert_eq!(picked, index, "{case}: the picked corner index stays the same");
|
||||
assert_eq!(picked, reversed, "{case}: the picked anchor follows its point");
|
||||
assert_eq!(corner(&app, picked), (before.0, before.2, before.1), "{case}: the same corner, its sides swapped");
|
||||
let radii = corner_radii(&app, id);
|
||||
assert_eq!(radii[picked], 1.0, "{case}: the corner now picked takes 1 pt");
|
||||
assert_eq!(radii[picked], 1.0, "{case}: the picked corner takes 1 pt");
|
||||
assert!(radii.iter().all(|&radius| radius != 4.0), "{case}: no corner takes the unfinished 3+1 draft");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
drop(app);
|
||||
|
||||
// Picking `index` again after the reversal names a different corner and drops the draft.
|
||||
panel.app().run("select.anchors", json!({"id": id, "anchors": [[0, index]], "mode": "set"})).unwrap();
|
||||
panel.frame();
|
||||
let before = corner(&panel.app(), index);
|
||||
finish_after_change(&mut panel, case, "Corner Radius", "0 pt", |app| {
|
||||
app.run("path.reverse", json!({"ids": [id]})).unwrap();
|
||||
app.run("select.anchors", json!({"id": id, "anchors": [[0, index]], "mode": "set"})).unwrap();
|
||||
});
|
||||
let app = panel.app();
|
||||
assert_ne!(corner(&app, index), before, "{case}: index {index} names a different corner");
|
||||
assert_eq!(picked_corner(&app), index, "{case}: index {index} is picked");
|
||||
let radii = corner_radii(&app, id);
|
||||
assert_eq!(radii[index], 1.0, "{case}: the corner now picked takes 1 pt");
|
||||
assert!(radii.iter().all(|&radius| radius != 4.0), "{case}: no corner takes the unfinished 3+1 draft");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1037,6 +1037,33 @@ fn unembed_writes_several_images_to_one_picked_folder() {
|
||||
assert_eq!(app.ui.status, format!("Unembedded 2 images to {picked}"));
|
||||
}
|
||||
|
||||
/// In the document portal, which takes only the name its save panel answered, Unembed… writes
|
||||
/// nothing under a name it had to complete (`photo` for a PNG): the panel opens again in the answer's
|
||||
/// folder suggesting `photo.png`, and its answer is written and linked.
|
||||
#[test]
|
||||
fn unembed_asks_again_for_a_name_the_document_portal_did_not_grant() {
|
||||
use crate::tests::picks::{poll, scripted};
|
||||
let dir = Folder::new("unembed-portal");
|
||||
let (mut app, _, embedded) = app(&dir);
|
||||
let picker = scripted(&mut app);
|
||||
let ctx = crate::testing::ui_context();
|
||||
let portal = "/run/user/1000/doc/a1b2c3d4";
|
||||
super::links::unembed(&mut app, embedded, "embedded.png");
|
||||
picker.answer_saved(&format!("{portal}/photo"), None);
|
||||
poll(&mut app, &ctx);
|
||||
assert_eq!(app.run("links.info", json!({"id": embedded})).unwrap()["status"], "embedded", "nothing is written or linked");
|
||||
let requests = picker.requests();
|
||||
let [_, again] = requests.as_slice() else { panic!("the save panel opens again: {requests:?}") };
|
||||
assert_eq!(again.file_name.as_deref(), Some("photo.png"));
|
||||
assert_eq!(again.directory.as_deref(), Some(std::path::Path::new(portal)));
|
||||
assert!(app.ui.status.contains("photo.png"), "{}", app.ui.status);
|
||||
let granted = dir.0.join("photo.png").to_string_lossy().into_owned();
|
||||
picker.answer_saved(&granted, None);
|
||||
poll(&mut app, &ctx);
|
||||
assert_eq!(app.run("links.info", json!({"id": embedded})).unwrap()["path"], granted.as_str());
|
||||
assert_eq!(picker.requests().len(), 2, "a granted name is written without asking again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn switching_documents_dismisses_a_links_row_menu() {
|
||||
let dir = Folder::new("context-switched-document");
|
||||
|
||||
@@ -1789,6 +1789,243 @@ fn raster_settings_rendered_warning_reaches_the_status_bar() {
|
||||
panel.frame();
|
||||
assert_eq!(render_of(&panel.app(), id)["resolution"].as_f64(), Some(2400.0));
|
||||
assert_eq!(panel.app().ui.status, vectorcraft_effects::rendered::TOO_LARGE);
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, dialog, "resolution", json!(1))).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, dialog));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert_eq!(render_of(&panel.app(), id)["resolution"].as_f64(), Some(1.0));
|
||||
assert_eq!(panel.app().ui.status, "", "a resolution that renders again clears the warning");
|
||||
}
|
||||
|
||||
/// Raster Settings OK keeps a rendered warning that a selected object outside the dialog still
|
||||
/// gives after the objects the dialog opened on render again.
|
||||
#[test]
|
||||
fn raster_settings_keeps_the_warning_of_another_selected_object() {
|
||||
use craft::ui::dialog::dialog_id;
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let mut app = app();
|
||||
let render = json!({"render": {"mode": "rendered", "quality": "low", "resolution": 2400}});
|
||||
let mut big = || {
|
||||
let id = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 3000, "height": 3000})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": render})).unwrap();
|
||||
id
|
||||
};
|
||||
let (p, q) = (big(), big());
|
||||
// An object with a gradient fill, selected first, gives another warning.
|
||||
let o = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
let gradient = json!({"kind": "linear", "stops": [{"offset": 0, "color": "#000000"}, {"offset": 1, "color": "#ffffff"}]});
|
||||
app.run("paint.setFill", json!({"gradient": gradient})).unwrap();
|
||||
app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": {"render": {"mode": "rendered", "quality": "low"}}})).unwrap();
|
||||
app.run("select.set", json!({"ids": [o]})).unwrap();
|
||||
assert_eq!(super::rendered_warning_of(&app, &[o]).as_deref(), Some(vectorcraft_effects::rendered::OPAQUE_ONLY));
|
||||
app.run("select.set", json!({"ids": [q]})).unwrap();
|
||||
app.ui.status = vectorcraft_effects::rendered::TOO_LARGE.to_owned();
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
let (dialog, ctx) = (dialog_id(super::raster::KIND), panel.ctx().clone());
|
||||
panel.app().run("select.set", json!({"ids": [o, p, q]})).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, dialog, "resolution", json!(1))).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, dialog));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert_eq!(render_of(&panel.app(), q)["resolution"].as_f64(), Some(1.0));
|
||||
assert_eq!(render_of(&panel.app(), p)["resolution"].as_f64(), Some(2400.0));
|
||||
assert_eq!(panel.app().ui.status, vectorcraft_effects::rendered::TOO_LARGE, "the other selected object still falls back");
|
||||
}
|
||||
|
||||
/// After an undo group that created the object Raster Settings opened on is canceled, OK keeps the
|
||||
/// dialog open even when the same steps make an equal object with the same id again.
|
||||
#[test]
|
||||
fn raster_settings_ok_is_refused_after_a_canceled_undo_group() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, _) = two_renders();
|
||||
let make = |app: &mut VectorcraftApp| {
|
||||
let c = app.run("shape.rectangle", json!({"x": 500, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null})).unwrap();
|
||||
let render = json!({"mode": "rendered", "resolution": 150});
|
||||
app.run("effect.setParams", json!({"index": 0, "item": null, "params": {"render": render}})).unwrap();
|
||||
c
|
||||
};
|
||||
app.session.begin_undo_group();
|
||||
let c = make(&mut app);
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
panel.app().session.end_undo_group(true);
|
||||
assert!(panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(c)).is_none());
|
||||
assert_eq!(make(&mut panel.app()), c, "the same steps make an object with the same id");
|
||||
assert_refused(&mut panel, a, c);
|
||||
}
|
||||
|
||||
/// While a Shape Builder merge is computed on another thread, Raster Settings OK keeps the dialog
|
||||
/// open and the merge pending, and leaves the render settings as they are.
|
||||
#[test]
|
||||
fn raster_settings_ok_is_refused_while_a_tool_edit_is_pending() {
|
||||
use craft::ui::dialog::{HeldOk, dialog_id};
|
||||
use vectorcraft_tools::{Mods, PointerEvent, PointerKind};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, b) = two_renders();
|
||||
let rects: Vec<u64> = (0..40)
|
||||
.map(|k| app.run("shape.rectangle", json!({"x": 1000 + k * 10, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap())
|
||||
.collect();
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
{
|
||||
let mut app = panel.app();
|
||||
app.run("select.set", json!({"ids": rects})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
let view = app.view_info();
|
||||
let at = |kind| PointerEvent {
|
||||
kind,
|
||||
pos: vectorcraft_geom::Point::new(1015.0, 10.0),
|
||||
mods: Mods::default(),
|
||||
pressure: 1.0,
|
||||
backquote: false,
|
||||
pen: None,
|
||||
};
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Move), view);
|
||||
app.session.tool_poll(view, true).unwrap();
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Down), view);
|
||||
crate::canvas::dispatch(&mut app, &at(PointerKind::Up), view);
|
||||
assert!(app.session.tool_editing(), "the merge is being computed");
|
||||
}
|
||||
let history = undo_len(&panel.app());
|
||||
assert_refused(&mut panel, a, b);
|
||||
let dialog = dialog_id(super::raster::KIND);
|
||||
let refused = panel.app().dialogs().unwrap().with(|h| h.held_state(dialog));
|
||||
assert!(matches!(refused, Some(HeldOk::Refused(reason)) if format!("{reason:?}").contains("Finish the active edit first.")));
|
||||
assert!(panel.app().session.tool_editing(), "the merge stays pending");
|
||||
assert_eq!(undo_len(&panel.app()), history);
|
||||
}
|
||||
|
||||
/// Raster Settings OK sets the objects the dialog opened on: an object selected after it opened
|
||||
/// keeps its render settings.
|
||||
#[test]
|
||||
fn raster_settings_ok_keeps_the_objects_it_opened_on() {
|
||||
use craft::ui::dialog::dialog_id;
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, b) = two_renders();
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
let a_before = render_of(&app, a);
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
let (dialog, ctx) = (dialog_id(super::raster::KIND), panel.ctx().clone());
|
||||
panel.app().run("select.set", json!({"ids": [a]})).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, dialog, "resolution", json!(300))).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, dialog));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert_eq!(render_of(&panel.app(), a), a_before, "the object selected after the dialog opened keeps its settings");
|
||||
assert_eq!(render_of(&panel.app(), b)["resolution"].as_f64(), Some(300.0), "OK sets the object the dialog opened on");
|
||||
}
|
||||
|
||||
/// After an Undo while Raster Settings is open, OK keeps the dialog open and changes nothing: the
|
||||
/// objects it opened on may no longer be the ones with their ids.
|
||||
#[test]
|
||||
fn raster_settings_ok_is_refused_after_undo() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, b) = two_renders();
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
panel.app().run("edit.undo", json!({})).unwrap();
|
||||
assert_refused(&mut panel, a, b);
|
||||
}
|
||||
|
||||
/// An object locked while Raster Settings is open keeps its settings: OK keeps the dialog open.
|
||||
#[test]
|
||||
fn raster_settings_ok_is_refused_after_a_lock() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, b) = two_renders();
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
panel.app().run("object.lock", json!({})).unwrap();
|
||||
assert_refused(&mut panel, a, b);
|
||||
}
|
||||
|
||||
/// Raster Settings OK keeps another object's preview in progress and leaves its undo history unchanged.
|
||||
#[test]
|
||||
fn raster_settings_ok_is_refused_during_another_preview() {
|
||||
use craft::ui::dialog::{HeldOk, dialog_id};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (mut app, a, b) = two_renders();
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
let mut panel = Panel::new(app, show_with_dialogs);
|
||||
panel.frame();
|
||||
panel.click("Render Settings");
|
||||
panel.click("Raster Settings…");
|
||||
panel.frame();
|
||||
panel.app().run("select.set", json!({"ids": [a]})).unwrap();
|
||||
let before = panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(a)).unwrap().clone();
|
||||
panel.app().session.begin_interaction("Change fill").unwrap();
|
||||
panel.app().session.preview("paint.setFill", &json!({"color": "#00ff00"})).unwrap();
|
||||
let preview = panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(a)).unwrap().clone();
|
||||
assert_ne!(preview, before, "the other object has a previewed edit");
|
||||
let history = undo_len(&panel.app());
|
||||
assert_refused(&mut panel, a, b);
|
||||
let dialog = dialog_id(super::raster::KIND);
|
||||
let refused = panel.app().dialogs().unwrap().with(|h| h.held_state(dialog));
|
||||
assert!(matches!(refused, Some(HeldOk::Refused(reason)) if format!("{reason:?}").contains("Finish the active edit first.")));
|
||||
assert_eq!(panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(a)), Some(&preview));
|
||||
assert!(panel.app().session.in_interaction(), "the other edit stays in progress");
|
||||
assert_eq!(undo_len(&panel.app()), history);
|
||||
panel.app().session.cancel_interaction().unwrap();
|
||||
assert_eq!(panel.app().session.active().unwrap().doc.node(vectorcraft_doc::NodeId(a)), Some(&before));
|
||||
}
|
||||
|
||||
/// Raster Settings, open, is given a resolution and OK: it stays open, and `a` and `b` keep their
|
||||
/// render settings.
|
||||
fn assert_refused(panel: &mut crate::tests::panel_harness::Panel, a: u64, b: u64) {
|
||||
use craft::ui::dialog::{HeldOk, dialog_id};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let (dialog, ctx) = (dialog_id(super::raster::KIND), panel.ctx().clone());
|
||||
let renders = |panel: &Panel| {
|
||||
let app = panel.app();
|
||||
[render_of(&app, a), render_of(&app, b)]
|
||||
};
|
||||
let before = renders(panel);
|
||||
panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, dialog, "resolution", json!(300))).unwrap();
|
||||
panel.app().dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, dialog));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let refused = panel.app().dialogs().unwrap().with(|h| matches!(h.held_state(dialog), Some(HeldOk::Refused(_))));
|
||||
assert!(refused, "OK is refused and the dialog stays open");
|
||||
assert_eq!(renders(panel), before);
|
||||
}
|
||||
|
||||
/// The panel with the window's dialogs run and their held answers applied, as in the app's frame.
|
||||
|
||||
@@ -190,9 +190,16 @@ struct Plan {
|
||||
}
|
||||
|
||||
fn plan(app: &VectorcraftApp) -> Plan {
|
||||
let selection: Vec<u64> = app.session.active().map(|st| st.selection.objects.iter().map(|id| id.0).collect()).unwrap_or_default();
|
||||
plan_of(app, &selection)
|
||||
}
|
||||
|
||||
/// The plan of a change to the objects `ids` of the active document, with the current selection
|
||||
/// as its selection; ids no longer in the document are left out.
|
||||
fn plan_of(app: &VectorcraftApp, ids: &[u64]) -> Plan {
|
||||
let Some(st) = app.session.active() else { return Plan { selection: vec![], targets: vec![] } };
|
||||
let selection: Vec<u64> = st.selection.objects.iter().map(|id| id.0).collect();
|
||||
let found: Vec<(u64, Target)> = st.selection.objects.iter().filter_map(|id| Some((id.0, find(st.doc.node(*id)?)?))).collect();
|
||||
let found: Vec<(u64, Target)> = ids.iter().filter_map(|id| Some((*id, find(st.doc.node(NodeId(*id))?)?))).collect();
|
||||
let lights = |t: &Target| vectorcraft_effects::merged_params(&t.effect, &t.params).get("lights").cloned();
|
||||
let first = found.first().map(|(_, t)| lights(t));
|
||||
let targets = found
|
||||
@@ -205,6 +212,20 @@ fn plan(app: &VectorcraftApp) -> Plan {
|
||||
Plan { selection, targets }
|
||||
}
|
||||
|
||||
/// Commits the settings `changed` to the 3D effects of the objects `ids` as one undo step.
|
||||
/// An active edit is left in progress and returns an error; ids no longer in the document are left out.
|
||||
pub(crate) fn send_to(app: &mut VectorcraftApp, changed: Map<String, Value>, ids: &[u64]) -> Result<(), String> {
|
||||
if app.session.in_interaction() {
|
||||
return Err(tl!("Finish the active edit first.").to_owned());
|
||||
}
|
||||
let steps = settings_steps(&plan_of(app, ids), &changed);
|
||||
match steps.as_slice() {
|
||||
[] => Ok(()),
|
||||
[step] => app.run("effect.setParams", step["params"].clone()).map(|_| ()),
|
||||
_ => app.run("command.batch", json!({"label": LABEL, "commands": steps})).map(|_| ()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends the settings `changed` to the 3D effect of each selected object (only the settings its
|
||||
/// effect takes; objects without a 3D effect are left as they are): previews them while the
|
||||
/// gesture runs (`Live::Dragging`) and commits them as one undo step when it ends. Settings
|
||||
@@ -227,8 +248,20 @@ pub(crate) fn send(app: &mut VectorcraftApp, changed: Map<String, Value>, phase:
|
||||
let held = app.three_d.plan.take().unwrap_or_else(|| plan(app));
|
||||
let mut pending = std::mem::take(&mut app.three_d.pending);
|
||||
pending.extend(changed);
|
||||
let steps: Vec<Value> = held
|
||||
.targets
|
||||
let steps = settings_steps(&held, &pending);
|
||||
match steps.as_slice() {
|
||||
[] => {}
|
||||
[step] => live_run(app, LABEL, "effect.setParams", step["params"].clone(), phase),
|
||||
_ => live_run(app, LABEL, "command.batch", json!({"label": LABEL, "commands": steps}), phase),
|
||||
}
|
||||
if dragging {
|
||||
app.three_d.pending = pending;
|
||||
app.three_d.plan = Some(held);
|
||||
}
|
||||
}
|
||||
|
||||
fn settings_steps(held: &Plan, pending: &Map<String, Value>) -> Vec<Value> {
|
||||
held.targets
|
||||
.iter()
|
||||
.filter_map(|(id, t, same_lights)| {
|
||||
let takes = vectorcraft_effects::default_params(&t.effect).unwrap_or(Value::Null);
|
||||
@@ -262,16 +295,7 @@ pub(crate) fn send(app: &mut VectorcraftApp, changed: Map<String, Value>, phase:
|
||||
(!params.is_empty())
|
||||
.then(|| json!({"command": "effect.setParams", "params": {"ids": [id], "index": t.index, "item": t.item, "params": params}}))
|
||||
})
|
||||
.collect();
|
||||
match steps.as_slice() {
|
||||
[] => {}
|
||||
[step] => live_run(app, LABEL, "effect.setParams", step["params"].clone(), phase),
|
||||
_ => live_run(app, LABEL, "command.batch", json!({"label": LABEL, "commands": steps}), phase),
|
||||
}
|
||||
if dragging {
|
||||
app.three_d.pending = pending;
|
||||
app.three_d.plan = Some(held);
|
||||
}
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Applies the edits of one pass of the panel's rows: `Begin` takes the plan and the settings as
|
||||
@@ -606,21 +630,34 @@ pub(crate) fn set_render(app: &mut VectorcraftApp, mode: &str, quality: Option<&
|
||||
|
||||
/// Shows the first rendered fallback warning for selected objects whose effects take render settings.
|
||||
pub(crate) fn show_rendered_warning(app: &mut VectorcraftApp) {
|
||||
if let Some(st) = app.session.active()
|
||||
&& let Some(message) = st
|
||||
.selection
|
||||
.objects
|
||||
.iter()
|
||||
.filter_map(|id| st.doc.node(*id))
|
||||
.filter(|n| {
|
||||
find(n).is_some_and(|t| vectorcraft_effects::default_params(&t.effect).is_some_and(|p| p.get(vectorcraft_effects::RENDER).is_some()))
|
||||
})
|
||||
.find_map(|n| vectorcraft_effects::rendered_warning(&st.doc, n))
|
||||
{
|
||||
let selection: Vec<u64> = app.session.active().map(|st| st.selection.objects.iter().map(|id| id.0).collect()).unwrap_or_default();
|
||||
show_rendered_warning_of(app, &selection);
|
||||
}
|
||||
|
||||
/// Shows the first rendered fallback warning for the objects `ids` whose effects take render settings.
|
||||
pub(crate) fn show_rendered_warning_of(app: &mut VectorcraftApp, ids: &[u64]) {
|
||||
if let Some(message) = rendered_warning_of(app, ids) {
|
||||
app.ui.status = message;
|
||||
}
|
||||
}
|
||||
|
||||
/// The first rendered fallback warning for the objects `ids` whose effects take render settings.
|
||||
pub(crate) fn rendered_warning_of(app: &VectorcraftApp, ids: &[u64]) -> Option<String> {
|
||||
rendered_warnings(app, ids).next()
|
||||
}
|
||||
|
||||
/// The rendered fallback warnings for the objects `ids` whose effects take render settings, in
|
||||
/// their order, each checked only when it is asked for.
|
||||
pub(crate) fn rendered_warnings<'a>(app: &'a VectorcraftApp, ids: &'a [u64]) -> impl Iterator<Item = String> + 'a {
|
||||
let st = app.session.active();
|
||||
ids.iter()
|
||||
.filter_map(move |id| Some((st?, st?.doc.node(NodeId(*id))?)))
|
||||
.filter(|(_, n)| {
|
||||
find(n).is_some_and(|t| vectorcraft_effects::default_params(&t.effect).is_some_and(|p| p.get(vectorcraft_effects::RENDER).is_some()))
|
||||
})
|
||||
.filter_map(|(st, n)| vectorcraft_effects::rendered_warning(&st.doc, n))
|
||||
}
|
||||
|
||||
/// Runs what a click in the Materials page's Graphics asked for: maps the graphic onto the selected
|
||||
/// objects, its row then selected, or keeps art as a new graphic. An error goes to the status bar.
|
||||
fn run_action(app: &mut VectorcraftApp, action: materials::Action) {
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
//!
|
||||
//! Fields: `document` (Use Document Raster Effects Resolution), `resolution` (1 to 2400 ppi) and
|
||||
//! `background` (`transparent` or `white`). A field the selected objects hold differently opens
|
||||
//! blank, and OK leaves it as each object has it. OK runs one `effect.setParams` over the
|
||||
//! selection, one undo step, which records none when every object already holds what it sets.
|
||||
//! blank, and OK leaves it as each object has it. OK runs one `effect.setParams` over the objects
|
||||
//! selected when the dialog opened, one undo step, which records none when every object already
|
||||
//! holds what it sets. While another document is the active one, or after the document was
|
||||
//! reverted or had an Undo, Redo or canceled edit, OK keeps the dialog open with the reason.
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_doc::Node;
|
||||
|
||||
use super::{Live, finish, selected_renders, send, shared_render, show_rendered_warning};
|
||||
use super::{find, rendered_warning_of, rendered_warnings, selected_renders, send_to, shared_render, takes_render};
|
||||
use crate::VectorcraftApp;
|
||||
use crate::dialogs::host::open_held;
|
||||
|
||||
@@ -53,7 +56,22 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
}
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, |fields| dialog().values(Bind::bound(fields)));
|
||||
let opened = Opened { document, resolution: opening, background };
|
||||
let (doc, targets) = app
|
||||
.session
|
||||
.active()
|
||||
.map(|st| {
|
||||
let targets = st
|
||||
.selection
|
||||
.objects
|
||||
.iter()
|
||||
.filter_map(|id| st.doc.node(*id))
|
||||
.filter(|n| find(n).is_some_and(|t| takes_render(&t.effect)))
|
||||
.cloned()
|
||||
.collect();
|
||||
(Some((st.uid, st.reverts, st.history_restores)), targets)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let opened = Opened { document, resolution: opening, background, doc, targets };
|
||||
open_held(app, dialog, move |app, answer| ok(app, answer, &opened)).ok_or("no window")?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -83,6 +101,11 @@ struct Opened {
|
||||
document: Option<bool>,
|
||||
resolution: Option<f64>,
|
||||
background: Option<String>,
|
||||
/// The document the dialog opened on: its uid, and its revert count and history restore count (Undo, Redo or a canceled edit) then.
|
||||
doc: Option<(u64, u64, u64)>,
|
||||
/// The selected objects whose render settings the dialog opened on, as they were then: OK sets
|
||||
/// these.
|
||||
targets: Vec<Node>,
|
||||
}
|
||||
|
||||
/// The render settings the answer `f` sets, given the values the dialog opened on: a field left
|
||||
@@ -115,17 +138,63 @@ fn edited(f: &DialogFields, opened: &Opened) -> Result<Map<String, Value>, Strin
|
||||
Ok(render)
|
||||
}
|
||||
|
||||
/// OK: sets the edited render settings on every selected object's 3D effect, one undo step.
|
||||
/// OK: sets the edited render settings on the 3D effect of every object the dialog opened on, one
|
||||
/// undo step. While another document is the active one, after that document was reverted or had an
|
||||
/// Undo, Redo or canceled edit, once one of those objects was changed, deleted, locked or hidden, or while another
|
||||
/// edit is in progress, OK keeps the dialog open with the reason.
|
||||
fn ok(app: &mut VectorcraftApp, answer: &ParamResult, opened: &Opened) -> Result<(), String> {
|
||||
let render = edited(&answer.fields, opened)?;
|
||||
if render.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
finish(app);
|
||||
let Some((uid, reverts, restores)) = opened.doc else { return Ok(()) };
|
||||
let st = app
|
||||
.session
|
||||
.active()
|
||||
.filter(|st| st.uid == uid)
|
||||
.ok_or_else(|| tl!("Return to the original drawing to change its raster settings.").to_owned())?;
|
||||
if st.reverts != reverts {
|
||||
return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned());
|
||||
}
|
||||
if st.history_restores != restores {
|
||||
return Err(tl!("Reopen Raster Settings after Undo, Redo or a canceled edit.").to_owned());
|
||||
}
|
||||
let stale = {
|
||||
let editable = st.doc.editable();
|
||||
opened.targets.is_empty() || opened.targets.iter().any(|t| st.doc.node(t.id) != Some(t) || !editable(t.id))
|
||||
};
|
||||
if stale {
|
||||
return Err(tl!("The objects were changed, deleted or locked. Reopen Raster Settings to continue.").to_owned());
|
||||
}
|
||||
// A pending tool edit would be applied before the change, after these checks.
|
||||
if app.session.tool_editing() {
|
||||
return Err(tl!("Finish the active edit first.").to_owned());
|
||||
}
|
||||
let ids: Vec<u64> = opened.targets.iter().map(|t| t.id.0).collect();
|
||||
let status = app.ui.status.clone();
|
||||
let shown = (!status.is_empty() && rendered_warnings(app, &ids).any(|w| w == status)).then_some(status);
|
||||
let mut changed = Map::new();
|
||||
changed.insert(vectorcraft_effects::RENDER.into(), Value::Object(render));
|
||||
send(app, changed, Live::Released);
|
||||
show_rendered_warning(app);
|
||||
send_to(app, changed, &ids)?;
|
||||
match rendered_warning_of(app, &ids) {
|
||||
Some(message) => app.ui.status = message,
|
||||
// The objects' earlier warning goes once they render, while the status line still shows it:
|
||||
// a selected object that still gives it keeps it, and otherwise the selection's first
|
||||
// warning, if any, takes its place.
|
||||
None if shown.is_some_and(|w| w == app.ui.status) => {
|
||||
let selection: Vec<u64> = app.session.active().map(|st| st.selection.objects.iter().map(|id| id.0).collect()).unwrap_or_default();
|
||||
let mut first = None;
|
||||
let kept = rendered_warnings(app, &selection).any(|w| {
|
||||
let same = w == app.ui.status;
|
||||
first.get_or_insert(w);
|
||||
same
|
||||
});
|
||||
if !kept {
|
||||
app.ui.status = first.unwrap_or_default();
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -157,12 +226,12 @@ mod tests {
|
||||
/// resolution sets nothing and a changed one sets it.
|
||||
#[test]
|
||||
fn ok_needs_a_resolution_and_keeps_blank_fields() {
|
||||
let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()) };
|
||||
let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()), doc: None, targets: vec![] };
|
||||
assert_eq!(edited(&fields(&[("document", FieldValue::Bool(false))]), &on), Err(NO_RESOLUTION.to_string()));
|
||||
let own = Opened { document: Some(false), resolution: None, background: Some("transparent".into()) };
|
||||
let own = Opened { document: Some(false), resolution: None, background: Some("transparent".into()), doc: None, targets: vec![] };
|
||||
let kept = edited(&fields(&[("document", FieldValue::Bool(false)), ("background", FieldValue::Text("white".into()))]), &own).unwrap();
|
||||
assert_eq!(kept, Map::from_iter([("background".to_string(), json!("white"))]));
|
||||
let mixed = Opened { document: None, resolution: Some(150.0), background: None };
|
||||
let mixed = Opened { document: None, resolution: Some(150.0), background: None, doc: None, targets: vec![] };
|
||||
assert_eq!(edited(&fields(&[("resolution", FieldValue::Number(150.0))]), &mixed), Ok(Map::new()));
|
||||
let changed = edited(&fields(&[("resolution", FieldValue::Number(200.0))]), &mixed).unwrap();
|
||||
assert_eq!(changed.get("resolution").and_then(Value::as_f64), Some(200.0));
|
||||
@@ -174,14 +243,14 @@ mod tests {
|
||||
/// mixed one sets it.
|
||||
#[test]
|
||||
fn ok_on_unchanged_values_sets_nothing() {
|
||||
let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()) };
|
||||
let on = Opened { document: Some(true), resolution: Some(72.0), background: Some("transparent".into()), doc: None, targets: vec![] };
|
||||
let unchanged = fields(&[
|
||||
("document", FieldValue::Bool(true)),
|
||||
("resolution", FieldValue::Number(72.0)),
|
||||
("background", FieldValue::Text("transparent".into())),
|
||||
]);
|
||||
assert_eq!(edited(&unchanged, &on), Ok(Map::new()));
|
||||
let own = Opened { document: Some(false), resolution: Some(150.0), background: Some("transparent".into()) };
|
||||
let own = Opened { document: Some(false), resolution: Some(150.0), background: Some("transparent".into()), doc: None, targets: vec![] };
|
||||
let kept = fields(&[("document", FieldValue::Bool(false)), ("resolution", FieldValue::Number(150.0))]);
|
||||
assert_eq!(edited(&kept, &own), Ok(Map::new()));
|
||||
let raised = edited(&fields(&[("document", FieldValue::Bool(false)), ("resolution", FieldValue::Number(200.0))]), &own).unwrap();
|
||||
@@ -190,7 +259,7 @@ mod tests {
|
||||
assert_eq!(switched, Map::from_iter([("resolution".to_string(), Value::Null)]));
|
||||
let white = edited(&fields(&[("background", FieldValue::Text("white".into()))]), &on).unwrap();
|
||||
assert_eq!(white, Map::from_iter([("background".to_string(), json!("white"))]));
|
||||
let mixed = Opened { document: Some(true), resolution: Some(72.0), background: None };
|
||||
let mixed = Opened { document: Some(true), resolution: Some(72.0), background: None, doc: None, targets: vec![] };
|
||||
let picked = edited(&fields(&[("background", FieldValue::Text("transparent".into()))]), &mixed).unwrap();
|
||||
assert_eq!(picked, Map::from_iter([("background".to_string(), json!("transparent"))]));
|
||||
}
|
||||
|
||||
@@ -346,7 +346,27 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
|
||||
}
|
||||
r
|
||||
}
|
||||
_ => engine(app, "file.place", &p),
|
||||
_ => match crate::placing::given_bytes(app, &p) {
|
||||
// A drawing placed through its import options places the bytes the dialog showed.
|
||||
Some(bytes) => {
|
||||
// The edit the tool computes on another thread comes first; when it fails, nothing
|
||||
// is placed, as `file.place` run as a command does.
|
||||
let r = app.session.finish_tool_edit();
|
||||
let failed = r.as_ref().err().map(ToString::to_string);
|
||||
crate::canvas::apply_requests(app, r);
|
||||
if let Some(e) = failed {
|
||||
return Err(e);
|
||||
}
|
||||
let job = app.session.prepare_place(&p).and_then(|job| job.with_bytes(bytes).read());
|
||||
let r = job.and_then(|read| app.session.place_read(read)).map_err(|e| e.to_string());
|
||||
app.sync_views();
|
||||
if let Err(e) = &r {
|
||||
app.status(e.clone());
|
||||
}
|
||||
r
|
||||
}
|
||||
None => engine(app, "file.place", &p),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,6 +202,10 @@ pub struct Placing {
|
||||
/// dropped: the conversion of a DWG drawing placed through its import options, which the read
|
||||
/// then finds without converting the drawing again.
|
||||
pub(crate) keep_next: Option<Box<dyn std::any::Any + Send>>,
|
||||
/// The path and the bytes of a drawing placed through its import options: the next place of
|
||||
/// that path ([`crate::place::run_for_user`]) places these bytes, the ones the dialog showed,
|
||||
/// instead of reading the file again.
|
||||
pub(crate) bytes_next: Option<(String, vectorcraft_engine::cmd::place::GivenBytes)>,
|
||||
/// A deferred paste awaiting its own Swatch Conflict dialog.
|
||||
swatch_paste: Option<PendingSwatch>,
|
||||
/// Set by unit tests whose app reads the files the user places off the UI thread.
|
||||
@@ -305,12 +309,23 @@ pub fn start(app: &mut VectorcraftApp, p: &Value, dropped: bool) -> Result<Value
|
||||
// one selected after it.
|
||||
let r = app.session.finish_tool_edit();
|
||||
crate::canvas::apply_requests(app, r);
|
||||
let job = app.session.prepare_place(p).map_err(|e| e.to_string())?;
|
||||
let given = given_bytes(app, p);
|
||||
let mut job = app.session.prepare_place(p).map_err(|e| e.to_string())?;
|
||||
if let Some(bytes) = given {
|
||||
job = job.with_bytes(bytes);
|
||||
}
|
||||
let name = job.name();
|
||||
let insertion = Insertion::of(app).ok_or("no document")?;
|
||||
spawn(app, name.clone(), name, dropped, move || job.read().map(|r| Read::Place(Box::new(r), insertion)).map_err(|e| e.to_string()))
|
||||
}
|
||||
|
||||
/// The bytes [`Placing::bytes_next`] holds for the file `p`'s `path` names, taken; `None` (and the
|
||||
/// bytes dropped) for any other place.
|
||||
pub(crate) fn given_bytes(app: &mut VectorcraftApp, p: &Value) -> Option<vectorcraft_engine::cmd::place::GivenBytes> {
|
||||
let (path, bytes) = app.placing.bytes_next.take()?;
|
||||
(p.get("path").and_then(Value::as_str) == Some(path.as_str())).then_some(bytes)
|
||||
}
|
||||
|
||||
/// `file.place.queue` with `p` for the active document, its files read and their thumbnails made off
|
||||
/// the UI thread → `{background: true, status}`; the place cursor is loaded once they are ready.
|
||||
/// `asks`: the cursor's files ask for their import options when placed ([`crate::place::show_thumbnails`]).
|
||||
|
||||
@@ -247,7 +247,7 @@ fn ask(app: &mut VectorcraftApp) -> bool {
|
||||
&& !script_run::busy(app)
|
||||
&& let Some(color) = dialog.color
|
||||
{
|
||||
color_picker::open_for_script(app, color, dialog.cmyk_document);
|
||||
color_picker::open_for_script(app, color, dialog.cmyk_document, dialog.profiles.clone());
|
||||
}
|
||||
} else if script_run::can_ask(app) {
|
||||
script_run::open_notice(app, &dialog);
|
||||
|
||||
@@ -1703,24 +1703,7 @@ fn export_text(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
}
|
||||
let shown = format.unwrap_or(TextFormat::Text);
|
||||
if !crate::io::is_web(app) {
|
||||
let offered: Vec<TextFormat> = format.map_or_else(|| TextFormat::ALL.to_vec(), |f| vec![f]);
|
||||
let request = offered.iter().fold(PickRequest::save(SHORTCUT_SETS).file_name(shown.file_name()), |r, f| f.filter(r));
|
||||
let (km, set) = (keymap.clone(), name.clone());
|
||||
let asked = file_asks::ask(app, request, Owner::Free, move |app, picked| {
|
||||
let Picked::Saved { path, file_type } = picked else { return Err("cancelled".into()) };
|
||||
let answer = path.to_string_lossy().into_owned();
|
||||
let typed = file_type.and_then(|i| offered.get(i)).copied();
|
||||
let picked = format.unwrap_or_else(|| TextFormat::picked(&answer, typed.map(TextFormat::extension)));
|
||||
// The format that `format` names, or that the dialog reports as the type picked, gives
|
||||
// the name its extension. A file already at a path changed that way, which the dialog
|
||||
// did not check, is replaced only after asking.
|
||||
let path = if format.is_some() || typed.is_some() { TextFormat::with_extension(&answer, picked) } else { answer.clone() };
|
||||
if path != answer && std::path::Path::new(&path).exists() {
|
||||
let to = path.clone();
|
||||
return Ok(file_asks::ask_replace(app, &path, &answer, move |app| write_text_file(app, &km, &set, picked, page, Some(to))));
|
||||
}
|
||||
write_text_file(app, &km, &set, picked, page, Some(path))
|
||||
});
|
||||
let asked = ask_text_file(app, format, (shown.file_name(), None), keymap.clone(), name.clone(), page);
|
||||
if !asked.is_null() {
|
||||
return Ok(asked);
|
||||
}
|
||||
@@ -1728,6 +1711,43 @@ fn export_text(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
write_text_file(app, &keymap, &name, shown, page, None)
|
||||
}
|
||||
|
||||
/// Export Text's save panel, suggesting `file` in `folder` (the last folder used when `None`) and
|
||||
/// offering the file type `format` names, or every one. The answer is written as [`export_text`]
|
||||
/// says; an answer in the document portal that would be written under another name opens the panel
|
||||
/// again with that name in the answer's folder, for the picked format.
|
||||
fn ask_text_file(
|
||||
app: &mut VectorcraftApp,
|
||||
format: Option<TextFormat>,
|
||||
(file, folder): (String, Option<std::path::PathBuf>),
|
||||
km: Keymap,
|
||||
set: String,
|
||||
page: PageSize,
|
||||
) -> Value {
|
||||
let offered: Vec<TextFormat> = format.map_or_else(|| TextFormat::ALL.to_vec(), |f| vec![f]);
|
||||
let mut request = offered.iter().fold(PickRequest::save(SHORTCUT_SETS).file_name(file), |r, f| f.filter(r));
|
||||
if let Some(folder) = folder {
|
||||
request = request.directory(folder);
|
||||
}
|
||||
file_asks::ask(app, request, Owner::Free, move |app, picked| {
|
||||
let Picked::Saved { path, file_type } = picked else { return Err("cancelled".into()) };
|
||||
let answer = path.to_string_lossy().into_owned();
|
||||
let typed = file_type.and_then(|i| offered.get(i)).copied();
|
||||
let picked = format.unwrap_or_else(|| TextFormat::picked(&answer, typed.map(TextFormat::extension)));
|
||||
// The format that `format` names, or that the dialog reports as the type picked, gives
|
||||
// the name its extension. A file already at a path changed that way, which the dialog
|
||||
// did not check, is replaced only after asking.
|
||||
let path = if format.is_some() || typed.is_some() { TextFormat::with_extension(&answer, picked) } else { answer.clone() };
|
||||
if let Some(again) = crate::io::save::portal_ask_again(app, &answer, &path) {
|
||||
return Ok(ask_text_file(app, Some(picked), again, km, set, page));
|
||||
}
|
||||
if path != answer && std::path::Path::new(&path).exists() {
|
||||
let to = path.clone();
|
||||
return Ok(file_asks::ask_replace(app, &path, &answer, move |app| write_text_file(app, &km, &set, picked, page, Some(to))));
|
||||
}
|
||||
write_text_file(app, &km, &set, picked, page, Some(path))
|
||||
})
|
||||
}
|
||||
|
||||
/// Writes Export Text's file to `path`; with none, downloads it, or returns it.
|
||||
fn write_text_file(
|
||||
app: &mut VectorcraftApp,
|
||||
|
||||
@@ -608,6 +608,21 @@ fn control_render_draws_the_trace_view_with_trace_views() {
|
||||
/// file the person drops outside them is refused in it, and opened in the passes after.
|
||||
#[test]
|
||||
fn a_pass_with_injected_input_runs_inside_the_roots() {
|
||||
// A key is injected as a press and, in the next pass, its release.
|
||||
drop_in_an_injected_pass_is_confined("ui.key", json!({"key": "Escape"}));
|
||||
}
|
||||
|
||||
/// Text is injected in one pass: the drag session delivers a drop of files made in that pass in the
|
||||
/// next one, which carries no injected input, and the drop is still refused.
|
||||
#[test]
|
||||
fn a_drop_in_a_pass_with_one_step_of_injected_input_is_confined_when_delivered() {
|
||||
drop_in_an_injected_pass_is_confined("ui.text", json!({"text": "a"}));
|
||||
}
|
||||
|
||||
/// Injects `method` with `params`, has the person drop a file outside the automation roots in the
|
||||
/// same pass, and checks that the drop opens nothing, then that a later drop of the person's opens
|
||||
/// the file.
|
||||
fn drop_in_an_injected_pass_is_confined(method: &str, params: Value) {
|
||||
#[derive(Debug)]
|
||||
struct Dropped(PathBuf);
|
||||
impl egui::DroppedFile for Dropped {
|
||||
@@ -618,7 +633,7 @@ fn a_pass_with_injected_input_runs_inside_the_roots() {
|
||||
std::fs::read(&self.0).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
let (mut app, tx, base) = confined("synthetic");
|
||||
let (mut app, tx, base) = confined(&format!("synthetic-{method}"));
|
||||
let ctx = crate::testing::ui_context();
|
||||
let outside = base.join("outside/b.svg");
|
||||
// The OS holds the file over the window in the pass before it drops it (`hovered`), as a desktop drag does.
|
||||
@@ -634,15 +649,18 @@ fn a_pass_with_injected_input_runs_inside_the_roots() {
|
||||
app.session.documents().len()
|
||||
};
|
||||
pass(&mut app, true, false);
|
||||
let (req, _reply) = ControlRequest::new("ui.key", json!({"key": "Escape"}));
|
||||
let (req, _reply) = ControlRequest::new(method, params);
|
||||
tx.send(req).unwrap();
|
||||
app.run_control(&ctx);
|
||||
assert_eq!(pass(&mut app, false, true), 0, "the pass carrying the key is confined");
|
||||
pass(&mut app, false, true);
|
||||
// The drag session delivers a drop of files in the pass after the one the OS dropped them in.
|
||||
assert_eq!(pass(&mut app, false, false), 0, "{method}: the drop of the pass carrying the input is confined");
|
||||
for _ in 0..4 {
|
||||
pass(&mut app, false, false);
|
||||
}
|
||||
pass(&mut app, true, false);
|
||||
assert_eq!(pass(&mut app, false, true), 1, "the person's pass is not");
|
||||
pass(&mut app, false, true);
|
||||
assert_eq!(pass(&mut app, false, false), 1, "{method}: the person's pass is not");
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ fn samples_show_the_text_in_the_family_or_a_generic_sample() {
|
||||
|
||||
/// A face with no hinting instructions draws a sample in a context the app has adopted, as the font list and the
|
||||
/// font picker draw each family's sample in its own face (a document face of the context): a Hebrew letter that is a
|
||||
/// bar 20 by 700 thousandths of an em. The context hints text in both themes, so the sample goes through skrifa's
|
||||
/// automatic hinter, whose blue-zone search for such a letter ends with the pinned skrifa. The face is served to the
|
||||
/// fixture's context only, so the font database other tests read does not change. The sample is one rasterized glyph
|
||||
/// from that face. It is drawn on a thread of its own, and the test fails when it has not ended after 300 s.
|
||||
/// bar 20 by 700 thousandths of an em, whose blue zones the automatic hinter of skrifa 0.44 never finishes measuring.
|
||||
/// The face is served to the fixture's context only, so the font database other tests read does not change. The
|
||||
/// sample is one rasterized glyph from that face. It is drawn on a thread of its own, and the test fails when it has
|
||||
/// not ended after 300 s.
|
||||
#[test]
|
||||
fn a_face_without_hinting_instructions_draws_its_sample() {
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -145,9 +145,9 @@ fn a_face_without_hinting_instructions_draws_its_sample() {
|
||||
let (texts, [hinting, light_hinting, dark_hinting], fixture_has_glyph, nonempty_glyph) =
|
||||
rx.recv_timeout(std::time::Duration::from_secs(300)).unwrap_or_else(|e| panic!("drawing the sample: {e}"));
|
||||
assert!(texts.iter().any(|t| t == "\u{5d1}"), "the sample is the letter, in the face: {texts:?}");
|
||||
assert!(hinting, "a context the app adopts hints text");
|
||||
assert!(light_hinting, "the light theme hints text");
|
||||
assert!(dark_hinting, "the dark theme hints text");
|
||||
assert!(!hinting, "a context the app adopts draws text without hinting");
|
||||
assert!(!light_hinting, "the light theme draws text without hinting");
|
||||
assert!(!dark_hinting, "the dark theme draws text without hinting");
|
||||
assert!(fixture_has_glyph, "the sample's face maps U+05D1");
|
||||
assert!(nonempty_glyph, "the sample is one rasterized glyph for U+05D1");
|
||||
}
|
||||
|
||||
@@ -597,6 +597,37 @@ fn keyboard_shortcuts_export_text_writes_the_format_picked_in_its_save_dialog()
|
||||
}
|
||||
}
|
||||
|
||||
/// In the document portal, which takes only the name its save panel answered, Export Text writes
|
||||
/// nothing under a name it had to change (`list` with the sheet picked): the panel opens again in the
|
||||
/// answer's folder, suggesting `list.pdf` and offering only the sheet, and its answer is written.
|
||||
#[test]
|
||||
fn keyboard_shortcuts_export_text_asks_again_for_a_name_the_document_portal_did_not_grant() {
|
||||
let portal = "/run/user/1000/doc/a1b2c3d4";
|
||||
let mut app = app();
|
||||
let picker = scripted(&mut app);
|
||||
let files: Rc<RefCell<Vec<String>>> = Default::default();
|
||||
let f = files.clone();
|
||||
app.services.write = Some(Box::new(move |path: &str, _: &[u8]| {
|
||||
f.borrow_mut().push(path.to_string());
|
||||
Ok(())
|
||||
}));
|
||||
app_frame(&app.ui_ctx.clone().unwrap(), &mut app, false);
|
||||
let _ = app.run("shortcuts.exportText", json!({}));
|
||||
picker.answer_saved(&format!("{portal}/list"), Some(1));
|
||||
settle(&mut app);
|
||||
assert!(files.borrow().is_empty(), "nothing is written under a name the portal did not grant: {:?}", files.borrow());
|
||||
let requests = picker.requests();
|
||||
let [_, again] = requests.as_slice() else { panic!("the save panel opens again: {requests:?}") };
|
||||
assert_eq!(again.file_name.as_deref(), Some("list.pdf"));
|
||||
assert_eq!(again.directory.as_deref(), Some(std::path::Path::new(portal)));
|
||||
assert_eq!(again.filters.iter().map(|f| f.extensions.join(",")).collect::<Vec<_>>(), ["pdf"]);
|
||||
assert!(app.ui.status.contains("list.pdf"), "{}", app.ui.status);
|
||||
picker.answer_saved(&format!("{portal}/list.pdf"), Some(0));
|
||||
settle(&mut app);
|
||||
assert_eq!(files.borrow().as_slice(), [format!("{portal}/list.pdf")]);
|
||||
assert_eq!(picker.requests().len(), 2, "a granted name is written without asking again");
|
||||
}
|
||||
|
||||
/// Keyboard Shortcuts' Import opens a shortcut set another app saved as text (`.kys`) in a review
|
||||
/// over the dialog when its file dialog answers; Cancel shows Keyboard Shortcuts again.
|
||||
#[test]
|
||||
|
||||
Loaded 100 of 111 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user