mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Route SVG parsing and drawing through craft-svg
This commit is contained in:
6 files changed
+257
-373
No files matched your search
Generated
+163
-111
@@ -1299,15 +1299,6 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
|
||||
|
||||
[[package]]
|
||||
name = "core_maths"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77745e017f5edba1a9c1d854f6f3a52dac8a12dd5af5d2f54aecf61e43d80d30"
|
||||
dependencies = [
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
@@ -1401,7 +1392,7 @@ version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d9b17697f#d9b17697f9a90555ac175ef56484d0e15a49ea9d"
|
||||
dependencies = [
|
||||
"craft-heif",
|
||||
"craft-jpeg",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
@@ -1413,8 +1404,30 @@ dependencies = [
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core 0.5.3",
|
||||
"zune-jpeg 0.5.15",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43#f7d76eec548a77a79fd2e056e7846a8655ee3f43"
|
||||
dependencies = [
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43)",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder",
|
||||
"png 0.18.1",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
@@ -1426,12 +1439,20 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43#f7d76eec548a77a79fd2e056e7846a8655ee3f43"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-kra"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d9b17697f#d9b17697f9a90555ac175ef56484d0e15a49ea9d"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-zip",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1453,7 +1474,7 @@ name = "craft-ora"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d9b17697f#d9b17697f9a90555ac175ef56484d0e15a49ea9d"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-zip",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1541,20 +1562,23 @@ dependencies = [
|
||||
"rayon",
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
"zune-core 0.5.3",
|
||||
"zune-jpeg 0.5.15",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d9b17697f#d9b17697f9a90555ac175ef56484d0e15a49ea9d"
|
||||
source = "git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43#f7d76eec548a77a79fd2e056e7846a8655ee3f43"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43)",
|
||||
"flate2",
|
||||
"kurbo 0.13.1",
|
||||
"resvg 0.48.1",
|
||||
"roxmltree 0.21.2",
|
||||
"thiserror 2.0.21",
|
||||
"usvg 0.48.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1640,6 +1664,15 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/dylanmtaylor/craft-libs?rev=f7d76eec548a77a79fd2e056e7846a8655ee3f43#f7d76eec548a77a79fd2e056e7846a8655ee3f43"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
@@ -2113,7 +2146,7 @@ dependencies = [
|
||||
"itertools 0.15.0",
|
||||
"log",
|
||||
"profiling",
|
||||
"resvg",
|
||||
"resvg 0.45.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2526,15 +2559,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fontdb"
|
||||
version = "0.23.0"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905"
|
||||
checksum = "2660c5e9157bf76d2db1294e4a9feba604ef610819a3b591088d0d8392a3290f"
|
||||
dependencies = [
|
||||
"fontconfig-parser",
|
||||
"log",
|
||||
"slotmap",
|
||||
"tinyvec",
|
||||
"ttf-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2805,16 +2837,6 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gif"
|
||||
version = "0.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae047235e33e2829703574b54fdec96bfbad892062d97fed2f76022287de61b"
|
||||
dependencies = [
|
||||
"color_quant",
|
||||
"weezl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gif"
|
||||
version = "0.14.2"
|
||||
@@ -3142,7 +3164,7 @@ dependencies = [
|
||||
"rustc-hash 2.1.3",
|
||||
"smallvec",
|
||||
"stringprep",
|
||||
"zune-jpeg 0.5.15",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3564,15 +3586,15 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"color_quant",
|
||||
"gif 0.14.2",
|
||||
"gif",
|
||||
"image-webp",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png 0.18.1",
|
||||
"qoi",
|
||||
"tiff",
|
||||
"zune-core 0.5.3",
|
||||
"zune-jpeg 0.5.15",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3591,6 +3613,12 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285"
|
||||
|
||||
[[package]]
|
||||
name = "imagesize"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65b27460c2c92b037f3f94c538ed9a3342f3fdf923606781629ccb35f82d042a"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.2"
|
||||
@@ -5302,7 +5330,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"core-graphics2",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-update",
|
||||
"dispatch2",
|
||||
"eframe",
|
||||
@@ -5328,7 +5356,7 @@ dependencies = [
|
||||
"photocraft-tablet",
|
||||
"photocraft-ui-egui",
|
||||
"plist",
|
||||
"resvg",
|
||||
"resvg 0.45.1",
|
||||
"rfd",
|
||||
"ron",
|
||||
"roxmltree 0.21.2",
|
||||
@@ -5368,7 +5396,7 @@ dependencies = [
|
||||
"base64 0.23.1",
|
||||
"cap-std",
|
||||
"clap",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-psd",
|
||||
"getrandom 0.3.4",
|
||||
"hmac",
|
||||
@@ -5401,7 +5429,7 @@ dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-psd",
|
||||
"photocraft-automation",
|
||||
"photocraft-cms",
|
||||
@@ -5471,7 +5499,7 @@ dependencies = [
|
||||
"blake3",
|
||||
"chrono",
|
||||
"craft-affinity",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-print",
|
||||
"craft-psd",
|
||||
"exr",
|
||||
@@ -5511,7 +5539,7 @@ name = "photocraft-format"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-pcraft-bundle",
|
||||
"craft-pcraft-format",
|
||||
"crc32fast",
|
||||
@@ -5566,7 +5594,7 @@ dependencies = [
|
||||
"blake3",
|
||||
"craft-affinity",
|
||||
"craft-docpath",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-kra",
|
||||
"craft-ora",
|
||||
"craft-pdf",
|
||||
@@ -5594,13 +5622,12 @@ dependencies = [
|
||||
"photocraft-text",
|
||||
"photocraft-vector",
|
||||
"proptest",
|
||||
"resvg",
|
||||
"roxmltree 0.21.2",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"ttf-parser",
|
||||
"zune-core 0.5.3",
|
||||
"zune-core",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
@@ -5671,7 +5698,7 @@ dependencies = [
|
||||
"photocraft-raw",
|
||||
"png 0.18.1",
|
||||
"rayon",
|
||||
"zune-core 0.5.3",
|
||||
"zune-core",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
@@ -5720,7 +5747,7 @@ dependencies = [
|
||||
"base64 0.23.1",
|
||||
"chrono",
|
||||
"craft-i18n",
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-print",
|
||||
"craft-psd",
|
||||
"craft-ui",
|
||||
@@ -5777,7 +5804,7 @@ dependencies = [
|
||||
name = "photocraft-web"
|
||||
version = "0.23.1"
|
||||
dependencies = [
|
||||
"craft-image-codecs",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=d9b17697f)",
|
||||
"craft-psd",
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -6549,15 +6576,30 @@ version = "0.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8928798c0a55e03c9ca6c4c6846f76377427d2c1e1f7e6de3c06ae57942df43"
|
||||
dependencies = [
|
||||
"gif 0.13.3",
|
||||
"log",
|
||||
"pico-args",
|
||||
"rgb",
|
||||
"svgtypes 0.15.3",
|
||||
"tiny-skia 0.11.4",
|
||||
"usvg 0.45.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "resvg"
|
||||
version = "0.48.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67e3803f97b999e80cbf7c6ecdd07a8102204d92e1633cf48783720c521196bd"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"gif",
|
||||
"image-webp",
|
||||
"log",
|
||||
"pico-args",
|
||||
"rgb",
|
||||
"svgtypes",
|
||||
"tiny-skia",
|
||||
"usvg",
|
||||
"zune-jpeg 0.4.21",
|
||||
"svgtypes 0.16.2",
|
||||
"tiny-skia 0.12.0",
|
||||
"usvg 0.48.1",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6848,24 +6890,6 @@ dependencies = [
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustybuzz"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd3c7c96f8a08ee34eff8857b11b49b07d71d1c3f4e88f8a88d4c9e9f90b1702"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"core_maths",
|
||||
"log",
|
||||
"smallvec",
|
||||
"ttf-parser",
|
||||
"unicode-bidi-mirroring",
|
||||
"unicode-ccc",
|
||||
"unicode-properties",
|
||||
"unicode-script",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruzstd"
|
||||
version = "0.9.1"
|
||||
@@ -6951,7 +6975,7 @@ checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec"
|
||||
dependencies = [
|
||||
"log",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"tiny-skia",
|
||||
"tiny-skia 0.11.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7598,6 +7622,16 @@ dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "svgtypes"
|
||||
version = "0.16.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f12b12995e3638c70618c1facb1ce65302f6a6f706b675f07c58a5d7391120e"
|
||||
dependencies = [
|
||||
"kurbo 0.13.1",
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@@ -7800,7 +7834,7 @@ dependencies = [
|
||||
"half",
|
||||
"quick-error 2.0.1",
|
||||
"weezl",
|
||||
"zune-jpeg 0.5.15",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7845,7 +7879,22 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"log",
|
||||
"png 0.17.16",
|
||||
"tiny-skia-path",
|
||||
"tiny-skia-path 0.11.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-skia"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"bytemuck",
|
||||
"cfg-if",
|
||||
"log",
|
||||
"png 0.18.1",
|
||||
"tiny-skia-path 0.12.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7859,6 +7908,17 @@ dependencies = [
|
||||
"strict-num",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-skia-path"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edca365c3faccca67d06593c5980fa6c57687de727a03131735bb85f01fdeeb9"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"bytemuck",
|
||||
"strict-num",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.4"
|
||||
@@ -8128,9 +8188,6 @@ name = "ttf-parser"
|
||||
version = "0.25.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
||||
dependencies = [
|
||||
"core_maths",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "twox-hash"
|
||||
@@ -8188,18 +8245,6 @@ version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi-mirroring"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfa6e8c60bb66d49db113e0125ee8711b7647b5579dc7f5f19c42357ed039fe"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ccc"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce61d488bcdc9bc8b5d1772c404828b17fc481c0a582b5581e95fb233aef503e"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-general-category"
|
||||
version = "1.1.0"
|
||||
@@ -8313,18 +8358,40 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"data-url",
|
||||
"flate2",
|
||||
"fontdb",
|
||||
"imagesize",
|
||||
"imagesize 0.13.0",
|
||||
"kurbo 0.11.3",
|
||||
"log",
|
||||
"pico-args",
|
||||
"roxmltree 0.20.0",
|
||||
"rustybuzz",
|
||||
"simplecss",
|
||||
"siphasher",
|
||||
"strict-num",
|
||||
"svgtypes",
|
||||
"tiny-skia-path",
|
||||
"svgtypes 0.15.3",
|
||||
"tiny-skia-path 0.11.4",
|
||||
"xmlwriter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usvg"
|
||||
version = "0.48.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "977d0a4abdef933f424a99fe09f95576e089b90aebc6f016a3bc813762493e91"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"data-url",
|
||||
"fontdb",
|
||||
"harfrust",
|
||||
"imagesize 0.15.0",
|
||||
"kurbo 0.13.1",
|
||||
"log",
|
||||
"pico-args",
|
||||
"roxmltree 0.21.2",
|
||||
"simplecss",
|
||||
"siphasher",
|
||||
"skrifa 0.44.0",
|
||||
"strict-num",
|
||||
"svgtypes 0.16.2",
|
||||
"tiny-skia-path 0.12.0",
|
||||
"unicode-bidi",
|
||||
"unicode-script",
|
||||
"unicode-vo",
|
||||
@@ -9878,12 +9945,6 @@ version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.3"
|
||||
@@ -9899,22 +9960,13 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.4.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713"
|
||||
dependencies = [
|
||||
"zune-core 0.4.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
|
||||
dependencies = [
|
||||
"zune-core 0.5.3",
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -9923,7 +9975,7 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4"
|
||||
dependencies = [
|
||||
"zune-core 0.5.3",
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f"
|
||||
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
craft-svg = { git = "https://github.com/dylanmtaylor/craft-libs", rev = "f7d76eec548a77a79fd2e056e7846a8655ee3f43", features = ["tree-render", "tree-render-system-fonts"] }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "d9b17697f" }
|
||||
# Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n
|
||||
|
||||
@@ -52,10 +52,7 @@ blake3 = { version = "1.8", default-features = false, features = ["pure"] }
|
||||
flate2 = { workspace = true }
|
||||
# ora.rs reads OpenRaster's stack.xml (already in the tree through usvg).
|
||||
roxmltree = "0.21"
|
||||
# SVG import (svg.rs): usvg parses, resvg rasterises what the shape model can't hold. Both are
|
||||
# already in the tree through the UI's icon loader; text shaping needs the fonts feature set.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
resvg = { version = "0.45", default-features = false, features = ["text", "system-fonts", "raster-images"] }
|
||||
# The SVG fallback font search keeps each font file's character map (already in the tree through usvg).
|
||||
ttf-parser = { version = "0.25", default-features = false }
|
||||
# PDF import (pdf_import.rs): craft-pdf rasterizes pages in pure Rust; no shared library ships.
|
||||
@@ -64,9 +61,6 @@ craft-pdf = { workspace = true }
|
||||
# This is the same kurbo 0.13 that craft-pdf already links; naming it adds no crate to the graph.
|
||||
kurbo = { version = "0.13", optional = true }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
resvg = { version = "0.45", default-features = false, features = ["text", "raster-images"] }
|
||||
|
||||
[dev-dependencies]
|
||||
lopdf = { version = "0.38", default-features = false }
|
||||
miniz_oxide = "0.9"
|
||||
|
||||
+89
-251
@@ -12,6 +12,8 @@
|
||||
|
||||
use std::sync::{Arc, Mutex, OnceLock, PoisonError};
|
||||
|
||||
use craft_svg::tree::draw::{self, tiny_skia};
|
||||
use craft_svg::tree::usvg;
|
||||
use photocraft_color::blend::BlendMode;
|
||||
use photocraft_color::{Color, ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_doc::effects::GradientStyle;
|
||||
@@ -19,32 +21,17 @@ use photocraft_doc::vector::{FillRule, Knot, LineCap, LineJoin, Path, PathOp, Sh
|
||||
use photocraft_doc::{Document, Fill, Group, Layer, LayerContent, MAX_GROUP_DEPTH};
|
||||
use photocraft_geom::{Point, Rect, Size};
|
||||
use photocraft_raster::Surface;
|
||||
use resvg::tiny_skia;
|
||||
use resvg::usvg;
|
||||
|
||||
use crate::{ImportResult, IoError};
|
||||
|
||||
#[cfg(test)]
|
||||
mod limits;
|
||||
|
||||
/// Largest canvas side an SVG opens at; a larger drawing is scaled down to fit.
|
||||
pub const MAX_SIDE: u32 = 16_384;
|
||||
/// A rasterised fallback layer or a smart-object render never exceeds this many pixels.
|
||||
const MAX_RASTER_PIXELS: u64 = 24_000_000;
|
||||
/// Largest decoded byte size (RGBA8) accepted for an embedded raster image before resvg decodes
|
||||
/// it. resvg/tiny-skia allocate the full intrinsic image before any destination-size scaling,
|
||||
/// so a highly compressed PNG or WebP could otherwise trigger gigabyte-scale allocation and
|
||||
/// decompression that the destination pixmap's size check never sees.
|
||||
const MAX_EMBEDDED_IMAGE_BYTES: u64 = MAX_RASTER_PIXELS * 4;
|
||||
|
||||
fn embedded_image_dimensions(mime: &str, data: &[u8]) -> Option<Option<(u32, u32)>> {
|
||||
let mime_supports_raster = matches!(mime, "image/png" | "image/webp" | "image/gif" | "image/jpeg" | "image/jpg");
|
||||
let plain_text_has_raster = mime == "text/plain"
|
||||
&& matches!(
|
||||
photocraft_codecs::detect(data),
|
||||
Some(photocraft_codecs::Format::Png | photocraft_codecs::Format::WebP | photocraft_codecs::Format::Gif | photocraft_codecs::Format::Jpeg)
|
||||
);
|
||||
if mime_supports_raster || plain_text_has_raster { Some(photocraft_codecs::probe_allocation_size(data).ok()) } else { None }
|
||||
}
|
||||
/// Aggregate memory for retained fallback surfaces in the document's pixel format.
|
||||
const MAX_PIXEL_BYTES: u64 = 1 << 30;
|
||||
/// Estimated peak during raster conversion (retained surfaces + RGBA8 pixmap + f32 staging + tiles).
|
||||
@@ -56,15 +43,19 @@ const MAX_RECURSION: usize = 200;
|
||||
/// Most filter work beyond the ordinary a drawing may ask of resvg, in pixel reads (see
|
||||
/// [`filter_cost`]): about ten seconds in a release build (resvg manages roughly 200 million reads
|
||||
/// a second, and its filters can't be interrupted).
|
||||
#[cfg(test)]
|
||||
const MAX_FILTER_COST: u64 = 2_000_000_000;
|
||||
/// Reads per pixel any primitive may take for free (a 16 × 16 morphology window or kernel, 16
|
||||
/// turbulence octaves), so ordinary filters open on any canvas.
|
||||
#[cfg(test)]
|
||||
const ORDINARY_FILTER_READS: u64 = 256;
|
||||
/// Most elements [`filter_cost`] visits, counting a shared mask, clip path or pattern once per
|
||||
/// use, as resvg renders it: patterns that fill and stroke with the next one double the work at
|
||||
/// each level, so a few dozen levels would keep the check (and the render) busy for hours.
|
||||
#[cfg(test)]
|
||||
const MAX_FILTER_VISITS: usize = 10_000_000;
|
||||
/// One `feTurbulence` octave per pixel, in pixel reads (it measures about 15 times a read).
|
||||
#[cfg(test)]
|
||||
const TURBULENCE_OCTAVE_COST: u64 = 16;
|
||||
/// Deepest element nesting accepted. The XML parser recurses once per level, so a file nested
|
||||
/// a few thousand deep (70 KB of `<g>`) overflows a 2 MB thread stack, an abort no guard can
|
||||
@@ -375,7 +366,7 @@ fn parse_at_depth<T: Send>(depth: usize, isolated: bool, parse: impl FnOnce(bool
|
||||
/// Supplies bounded parsing options to direct resolver tests without changing their existing interface.
|
||||
#[cfg(test)]
|
||||
fn options(fontdb: Arc<usvg::fontdb::Database>, depth_left: usize) -> usvg::Options<'static> {
|
||||
options_with_isolation(fontdb, depth_left, false, Arc::new(Mutex::new(None)))
|
||||
options_with_isolation(fontdb, depth_left, false, Arc::new(craft_svg::tree::ImageResolver::new(tree_limits(depth_left, MAX_RASTER_PIXELS))))
|
||||
}
|
||||
|
||||
/// Parse options for an untrusted drawing. `<image href>` resolves only `data:` URLs: a file path
|
||||
@@ -385,64 +376,11 @@ fn options(fontdb: Arc<usvg::fontdb::Database>, depth_left: usize) -> usvg::Opti
|
||||
/// parsed on top of the drawing's own recursion, so the two depths share [`MAX_XML_DEPTH`].
|
||||
fn options_with_isolation(
|
||||
fontdb: Arc<usvg::fontdb::Database>,
|
||||
depth_left: usize,
|
||||
isolated: bool,
|
||||
parser_error: Arc<Mutex<Option<IoError>>>,
|
||||
_depth_left: usize,
|
||||
_isolated: bool,
|
||||
image_resolver: Arc<craft_svg::tree::ImageResolver>,
|
||||
) -> usvg::Options<'static> {
|
||||
let default_resolver = usvg::ImageHrefResolver::default_data_resolver();
|
||||
let resolve_data: usvg::ImageHrefDataResolverFn<'static> = Box::new(move |mime, data, opts| {
|
||||
// Reject embedded images whose decoded RGBA storage would exceed the budget before
|
||||
// resvg (which allocates the full intrinsic image before any destination scaling) ever
|
||||
// sees them. Formats without a cheap header probe fall through unchanged; their decode
|
||||
// path is bounded elsewhere or accepted as-is, matching the previous behavior.
|
||||
let probed = embedded_image_dimensions(mime, &data);
|
||||
if let Some(probed) = probed {
|
||||
let (w, h) = probed?;
|
||||
let decoded = u64::from(w).saturating_mul(u64::from(h)).saturating_mul(4);
|
||||
if decoded > MAX_EMBEDDED_IMAGE_BYTES {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
// An embedded SVG (`image/svg+xml`, or `text/plain` that isn't one of the raster
|
||||
// formats probed above) is parsed by the default resolver with none of `parse_with`'s
|
||||
// checks, so they run here. It can itself be gzip-compressed (SVGZ-in-data-URL), and the
|
||||
// default resolver's sub-SVG loader would decompress again with no byte limit of its
|
||||
// own: hand it our bounded inflate's output instead, which no longer starts with the
|
||||
// gzip magic. Nesting deeper than `depth_left` drops the image rather than overflowing
|
||||
// the parser's stack.
|
||||
if mime == "image/svg+xml" || (mime == "text/plain" && probed.is_none()) {
|
||||
let (mime, xml) = match inflate(&data) {
|
||||
Ok(std::borrow::Cow::Borrowed(_)) => (mime, Arc::clone(&data)),
|
||||
Ok(std::borrow::Cow::Owned(xml)) if !xml.starts_with(&[0x1f, 0x8b]) => ("image/svg+xml", Arc::new(xml)),
|
||||
_ => return None,
|
||||
};
|
||||
let Ok(depth) = nesting_depth(&xml, depth_left) else { return None };
|
||||
if depth > depth_left {
|
||||
return None;
|
||||
}
|
||||
// An already isolated outer parse lends its fixed stack to the child. Otherwise a
|
||||
// deep child gets one worker of its own; usvg disables further embedded images there.
|
||||
let shared_depth = MAX_XML_DEPTH.saturating_sub(depth_left).saturating_add(depth);
|
||||
return match parse_at_depth(shared_depth, isolated, |_| Ok(default_resolver(mime, xml, opts))) {
|
||||
Ok(image) => image,
|
||||
Err(error) => {
|
||||
let mut failure = parser_error.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
if failure.is_none() {
|
||||
*failure = Some(error.into());
|
||||
}
|
||||
None
|
||||
}
|
||||
};
|
||||
}
|
||||
default_resolver(mime, data, opts)
|
||||
});
|
||||
usvg::Options {
|
||||
resources_dir: None,
|
||||
image_href_resolver: usvg::ImageHrefResolver { resolve_data, resolve_string: Box::new(|_, _| None) },
|
||||
fontdb,
|
||||
font_resolver: font_resolver(),
|
||||
..usvg::Options::default()
|
||||
}
|
||||
usvg::Options { resources_dir: None, image_href_resolver: image_resolver.resolver(), fontdb, font_resolver: font_resolver(), ..usvg::Options::default() }
|
||||
}
|
||||
|
||||
/// A parsed drawing.
|
||||
@@ -463,6 +401,17 @@ fn parse(bytes: &[u8]) -> Result<Parsed, IoError> {
|
||||
parse_with(bytes, fonts)
|
||||
}
|
||||
|
||||
fn tree_limits(depth: usize, raster_pixels: u64) -> craft_svg::tree::Limits {
|
||||
craft_svg::tree::Limits {
|
||||
bytes: usize::try_from(MAX_INFLATED_BYTES).unwrap_or(usize::MAX),
|
||||
depth,
|
||||
embedded_bytes: usize::try_from(MAX_BOUNDED_SVG_BYTES).unwrap_or(usize::MAX),
|
||||
embedded_depth: MAX_EMBEDDED_SVG_DEPTH,
|
||||
embedded_raster_pixels: raster_pixels.min(MAX_RASTER_PIXELS),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// [`parse`] with the font database `fonts` supplies (the tests hand in an empty one).
|
||||
fn parse_with(bytes: &[u8], fonts: fn() -> Arc<usvg::fontdb::Database>) -> Result<Parsed, IoError> {
|
||||
let xml = inflate(bytes)?;
|
||||
@@ -477,13 +426,11 @@ fn parse_with(bytes: &[u8], fonts: fn() -> Arc<usvg::fontdb::Database>) -> Resul
|
||||
// re-checks the gzip magic and would decompress a second time without our size limit if
|
||||
// the inflated content happened to start with a nested gzip stream.
|
||||
let text = std::str::from_utf8(&xml).map_err(|_| IoError::Svg("the SVG is not valid UTF-8".into()))?;
|
||||
let parser_error = Arc::new(Mutex::new(None));
|
||||
let image_resolver = Arc::new(craft_svg::tree::ImageResolver::new(tree_limits(MAX_XML_DEPTH, MAX_RASTER_PIXELS)));
|
||||
image_resolver.set_document_depth(depth);
|
||||
parse_at_depth(depth, false, |isolated| {
|
||||
let opt = options_with_isolation(fontdb, MAX_XML_DEPTH.saturating_sub(depth), isolated, Arc::clone(&parser_error));
|
||||
let tree = guarded(|| usvg::Tree::from_str(text, &opt));
|
||||
if let Some(error) = parser_error.lock().unwrap_or_else(PoisonError::into_inner).take() {
|
||||
return Err(error);
|
||||
}
|
||||
let opt = options_with_isolation(fontdb, MAX_XML_DEPTH.saturating_sub(depth), isolated, Arc::clone(&image_resolver));
|
||||
let tree = guarded(|| craft_svg::tree::parse_text(text, &tree_limits(MAX_XML_DEPTH, MAX_RASTER_PIXELS), &opt));
|
||||
let tree = tree.ok_or_else(|| IoError::Svg("the SVG parser failed on this drawing".into()))?.map_err(|error| IoError::Svg(error.to_string()))?;
|
||||
Ok(Parsed { tree, fontless_text })
|
||||
})
|
||||
@@ -516,14 +463,7 @@ struct ImageBudget {
|
||||
/// stored display preview must draw completely, or it isn't used.
|
||||
strict: bool,
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
/// Leave out an embedded image that can't be read, or with a strict budget record `error`.
|
||||
fn unreadable_image(budget: &Mutex<ImageBudget>, error: &str) -> Option<usvg::ImageKind> {
|
||||
if budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner).strict {
|
||||
image_error(budget, error);
|
||||
}
|
||||
None
|
||||
resolver: Arc<craft_svg::tree::ImageResolver>,
|
||||
}
|
||||
|
||||
/// Record the first budget or decoding failure seen while usvg resolves images. Resolver
|
||||
@@ -535,96 +475,10 @@ fn image_error(budget: &Mutex<ImageBudget>, error: impl Into<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Deduct one image's `width × height` decoded pixels from the shared budget before it is
|
||||
/// decoded. A zero-sized, overflowing or over-budget image records an error and returns `false`.
|
||||
fn charge_image(budget: &Mutex<ImageBudget>, width: usize, height: usize) -> bool {
|
||||
let pixels = u64::try_from(width).ok().zip(u64::try_from(height).ok()).and_then(|(w, h)| w.checked_mul(h));
|
||||
let mut budget = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
match pixels.filter(|pixels| *pixels != 0).and_then(|pixels| budget.pixels.checked_sub(pixels)) {
|
||||
Some(remaining) => {
|
||||
budget.pixels = remaining;
|
||||
true
|
||||
}
|
||||
None => {
|
||||
budget.error.get_or_insert_with(|| "embedded SVG raster images exceed the decoded pixel budget".into());
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// usvg's data-URL image resolver with budgets: nested SVG images are parsed with the same
|
||||
/// budget up to [`MAX_EMBEDDED_SVG_DEPTH`] and within the `xml_left` levels of XML nesting the
|
||||
/// drawing left them, and PNG/JPEG/GIF/WebP images are charged their largest declared frame
|
||||
/// before decoding. An overrun records an error and resolves to no image so the enclosing parse
|
||||
/// fails. An image that isn't one of those formats, is invalid, or has a MIME type usvg doesn't
|
||||
/// know is left out and the rest still draws, as usvg's own resolver does (with a strict budget
|
||||
/// it is an error too).
|
||||
fn bounded_data_image(
|
||||
mime: &str,
|
||||
data: Arc<Vec<u8>>,
|
||||
options: &usvg::Options,
|
||||
budget: &Arc<Mutex<ImageBudget>>,
|
||||
depth: usize,
|
||||
xml_left: usize,
|
||||
isolated: bool,
|
||||
) -> Option<usvg::ImageKind> {
|
||||
if budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner).error.is_some() {
|
||||
return None;
|
||||
}
|
||||
let format = photocraft_codecs::detect(&data);
|
||||
if mime == "image/svg+xml" || (mime == "text/plain" && format.is_none()) {
|
||||
if depth >= MAX_EMBEDDED_SVG_DEPTH {
|
||||
image_error(budget, "embedded SVG images exceed the nesting limit");
|
||||
return None;
|
||||
}
|
||||
// A budget overrun inside the image is already recorded; any other failure (not an
|
||||
// SVG, nested deeper than the drawing left room for) only leaves the image out.
|
||||
let Ok(tree) = parse_image_bounded(&data, budget.clone(), depth + 1, xml_left, isolated) else {
|
||||
return unreadable_image(budget, "can't parse an embedded SVG image");
|
||||
};
|
||||
let mut counter = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
counter.svg_images = counter.svg_images.saturating_add(1);
|
||||
counter.svg_chain = counter.svg_chain.max(u64::try_from(depth + 1).unwrap_or(u64::MAX));
|
||||
Some(usvg::ImageKind::SVG(tree))
|
||||
} else {
|
||||
let supported = matches!(
|
||||
format,
|
||||
Some(photocraft_codecs::Format::Png | photocraft_codecs::Format::Jpeg | photocraft_codecs::Format::Gif | photocraft_codecs::Format::WebP)
|
||||
);
|
||||
let dimensions = supported.then(|| photocraft_codecs::probe_allocation_size(&data).ok()).flatten();
|
||||
let Some((width, height)) = dimensions else { return unreadable_image(budget, "embedded SVG image has unsupported or invalid raster data") };
|
||||
// usvg's resolver only wraps the bytes (resvg decodes them when drawing): an image under
|
||||
// a MIME type it doesn't know, or with no pixels, is left out uncharged, as usvg would.
|
||||
let Some(image) = (usvg::ImageHrefResolver::default_data_resolver())(mime, data, options) else {
|
||||
return unreadable_image(budget, "embedded SVG raster image has an unsupported MIME type");
|
||||
};
|
||||
if width == 0 || height == 0 {
|
||||
return unreadable_image(budget, "embedded SVG image has no pixels");
|
||||
}
|
||||
if !charge_image(budget, width as usize, height as usize) {
|
||||
return None;
|
||||
}
|
||||
Some(image)
|
||||
}
|
||||
}
|
||||
|
||||
/// [`parse_image_bounded_with`] using the shared system font database.
|
||||
fn parse_image_bounded(bytes: &[u8], budget: Arc<Mutex<ImageBudget>>, depth: usize, xml_left: usize, isolated: bool) -> Result<usvg::Tree, IoError> {
|
||||
parse_image_bounded_with(bytes, budget, depth, xml_left, fonts, isolated)
|
||||
}
|
||||
|
||||
/// Parse one (possibly gzip-compressed) SVG at nesting `depth` against `budget`: the byte,
|
||||
/// inflated-size and XML-depth limits apply first, embedded images go through
|
||||
/// [`bounded_data_image`], and the tree's drawing-node count and repeatable image resources are
|
||||
/// added to the budget for the caller's work estimate. Fonts load only when text is present.
|
||||
/// usvg parses an embedded SVG on top of the drawing's own recursion, so the drawing and the
|
||||
/// images inside it share `xml_left` levels of XML nesting ([`MAX_XML_DEPTH`] for the drawing).
|
||||
/// Byte and decode overruns are also recorded in `budget`, so they fail the whole drawing; a
|
||||
/// nesting or syntax error only fails this SVG.
|
||||
/// Parse one bounded SVG with the shared tree parser and its format-neutral image resolver.
|
||||
fn parse_image_bounded_with(
|
||||
bytes: &[u8],
|
||||
budget: Arc<Mutex<ImageBudget>>,
|
||||
depth: usize,
|
||||
xml_left: usize,
|
||||
fonts: fn() -> Arc<usvg::fontdb::Database>,
|
||||
isolated: bool,
|
||||
@@ -637,48 +491,41 @@ fn parse_image_bounded_with(
|
||||
return Err(overrun(IoError::Svg("embedded SVG source exceeds the 16 MiB byte limit".into())));
|
||||
}
|
||||
let xml = inflate_with_limit(bytes, MAX_BOUNDED_SVG_BYTES).map_err(overrun)?;
|
||||
// Charged before anything can leave the image out, so skipped images still use up the budget.
|
||||
let xml_len = u64::try_from(xml.len()).unwrap_or(u64::MAX);
|
||||
let left = {
|
||||
let mut counter = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let left = counter.xml_bytes.checked_sub(xml_len);
|
||||
if let Some(left) = left {
|
||||
counter.xml_bytes = left;
|
||||
}
|
||||
left
|
||||
};
|
||||
if left.is_none() {
|
||||
return Err(overrun(IoError::Svg("embedded SVG XML exceeds the decoded byte budget".into())));
|
||||
}
|
||||
let nesting = nesting_depth(&xml, xml_left)?;
|
||||
if nesting > xml_left {
|
||||
return Err(IoError::Svg(format!("elements are nested more than {xml_left} levels deep")));
|
||||
}
|
||||
let shared_depth = MAX_XML_DEPTH.saturating_sub(xml_left).saturating_add(nesting);
|
||||
budget.lock().unwrap_or_else(PoisonError::into_inner).resolver.set_document_depth(nesting);
|
||||
parse_at_depth(shared_depth, isolated, |isolated| {
|
||||
let has_text = xml.windows(4).any(|w| w == b"text");
|
||||
let fontdb = if has_text { fonts() } else { Arc::new(usvg::fontdb::Database::new()) };
|
||||
if has_text && fontdb.faces().next().is_none() {
|
||||
budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner).fontless_text = true;
|
||||
budget.lock().unwrap_or_else(PoisonError::into_inner).fontless_text = true;
|
||||
}
|
||||
// The resolver below replaces `options`' own, so its embedded-SVG depth argument is unused.
|
||||
let mut opt = options_with_isolation(fontdb, 0, isolated, Arc::new(Mutex::new(None)));
|
||||
let shared = budget.clone();
|
||||
let image_xml_left = xml_left.saturating_sub(nesting);
|
||||
opt.image_href_resolver.resolve_data =
|
||||
Box::new(move |mime, data, options| bounded_data_image(mime, data, options, &shared, depth, image_xml_left, isolated));
|
||||
// The bounded inflate above is the only decompression step. from_data would detect a
|
||||
// nested gzip payload and inflate it again without the source-byte limit.
|
||||
let resolver = Arc::clone(&budget.lock().unwrap_or_else(PoisonError::into_inner).resolver);
|
||||
let opt = options_with_isolation(fontdb, xml_left, isolated, resolver);
|
||||
let text = std::str::from_utf8(&xml).map_err(|_| IoError::Svg("the SVG is not valid UTF-8".into()))?;
|
||||
let tree = guarded(|| usvg::Tree::from_str(text, &opt));
|
||||
if let Some(error) = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner).error.clone() {
|
||||
let limits = tree_limits(xml_left, MAX_RASTER_PIXELS);
|
||||
let tree = guarded(|| craft_svg::tree::parse_text(text, &limits, &opt));
|
||||
let tree = tree.ok_or_else(|| IoError::Svg("the SVG parser failed on this drawing".into()))?.map_err(|e| IoError::Svg(e.to_string()))?;
|
||||
let mut counter = budget.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
let usage = counter.resolver.usage();
|
||||
counter.pixels = counter.pixels.saturating_sub(usage.raster_pixels);
|
||||
counter.xml_bytes = counter.xml_bytes.saturating_sub(u64::try_from(usage.embedded_svg_bytes).unwrap_or(u64::MAX));
|
||||
counter.svg_images = usage.embedded_svg_count as u64;
|
||||
counter.svg_chain = usage.embedded_svg_depth as u64;
|
||||
if usage.raster_limit_images > 0 {
|
||||
counter.error.get_or_insert_with(|| "embedded SVG raster images exceed the decoded pixel budget".into());
|
||||
} else if counter.strict && (usage.svg_limit_images > 0 || usage.invalid_raster_images > 0 || usage.invalid_svg_images > 0) {
|
||||
counter.error.get_or_insert_with(|| "can't parse an embedded SVG image".into());
|
||||
}
|
||||
if let Some(error) = counter.error.clone() {
|
||||
return Err(IoError::Svg(error));
|
||||
}
|
||||
let tree = tree.ok_or_else(|| IoError::Svg("the SVG parser failed on this drawing".into()))?.map_err(|e| IoError::Svg(e.to_string()))?;
|
||||
// Include nested SVG trees too. Paint servers can reuse one parsed raster in many
|
||||
// drawing nodes, so the work estimate must not assume every source is decoded once.
|
||||
drop(counter);
|
||||
let nodes = u64::try_from(count_nodes_with_limit(tree.root(), true, usize::MAX, false)).unwrap_or(u64::MAX);
|
||||
let mut counter = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let mut counter = budget.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
counter.draw_nodes = counter.draw_nodes.saturating_add(nodes);
|
||||
let (raster, svg) = repeatable_image_resources(&tree);
|
||||
counter.repeatable_raster |= raster;
|
||||
@@ -687,8 +534,6 @@ fn parse_image_bounded_with(
|
||||
})
|
||||
.map_err(|failure| match failure {
|
||||
ParseFailure::Isolation(error) => {
|
||||
// A missing isolated parse must never silently remove embedded artwork,
|
||||
// even when ordinary invalid images are allowed to be omitted.
|
||||
image_error(&budget, error.to_string());
|
||||
error
|
||||
}
|
||||
@@ -797,8 +642,9 @@ fn parse_bounded_work_with(bytes: &[u8], max_pixels: u64, strict: bool, fonts: f
|
||||
fontless_text: false,
|
||||
strict,
|
||||
error: None,
|
||||
resolver: Arc::new(craft_svg::tree::ImageResolver::new(tree_limits(MAX_XML_DEPTH, max_pixels.min(MAX_RASTER_PIXELS)))),
|
||||
}));
|
||||
let tree = parse_image_bounded_with(bytes, budget.clone(), 0, MAX_XML_DEPTH, fonts, false)?;
|
||||
let tree = parse_image_bounded_with(bytes, budget.clone(), MAX_XML_DEPTH, fonts, false)?;
|
||||
let counter = budget.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let decoded = max_pixels.min(MAX_RASTER_PIXELS).saturating_sub(counter.pixels);
|
||||
Ok(ParsedWork {
|
||||
@@ -1135,10 +981,10 @@ fn import_parsed_with_limits(
|
||||
conv.warnings.push(format!("SVG: more than {MAX_NODES} elements; opened as one pixel layer instead of shapes"));
|
||||
}
|
||||
let (w, h) = (cv.size.width, cv.size.height);
|
||||
if let Some(mut pixmap) = pixmap(w, h) {
|
||||
check_render_memory(&tree, global, w, h)?;
|
||||
if guarded(|| resvg::render(&tree, global, &mut pixmap.as_mut())).is_some() {
|
||||
doc.layers.push(Layer::new("Background", LayerContent::Raster(surface(&pixmap, doc.bounds(), fmt))));
|
||||
if u64::from(w) * u64::from(h) <= MAX_RASTER_PIXELS {
|
||||
let rendered = guarded(|| draw::render(&tree, global, w, h, 0, MAX_PEAK_PIXEL_BYTES));
|
||||
if let Some(Ok(rendered)) = rendered {
|
||||
doc.layers.push(Layer::new("Background", LayerContent::Raster(surface(&rendered, doc.bounds(), fmt))));
|
||||
} else {
|
||||
conv.note("raster-panic", "SVG: the drawing could not be rendered".to_string());
|
||||
}
|
||||
@@ -1224,16 +1070,10 @@ fn render(tree: &usvg::Tree, k: f32) -> Result<tiny_skia::Pixmap, IoError> {
|
||||
check_filter_cost(tree, k)?;
|
||||
let side = |v: f32| ((v * k).ceil() as u32).max(1);
|
||||
let (w, h) = (side(tree.size().width()), side(tree.size().height()));
|
||||
let mut pixmap = pixmap(w, h).ok_or_else(|| IoError::Svg(format!("{w} × {h} px is too large to rasterise")))?;
|
||||
let ts = tiny_skia::Transform::from_scale(k, k);
|
||||
check_render_memory(tree, ts, w, h)?;
|
||||
guarded(|| resvg::render(tree, ts, &mut pixmap.as_mut())).ok_or_else(|| IoError::Svg("the drawing could not be rendered".into()))?;
|
||||
Ok(pixmap)
|
||||
}
|
||||
|
||||
/// An error when drawing the whole `tree` at `ts` onto a `w × h` pixmap would break a [`limits`] cap.
|
||||
fn check_render_memory(tree: &usvg::Tree, ts: tiny_skia::Transform, w: u32, h: u32) -> Result<(), IoError> {
|
||||
limits::check(tree.root().children(), ts, w, h, 0).map_err(|r| IoError::Svg(format!("can't rasterise this drawing: {}", r.message)))
|
||||
guarded(|| draw::render(tree, ts, w, h, 0, MAX_PEAK_PIXEL_BYTES))
|
||||
.ok_or_else(|| IoError::Svg("the drawing could not be rendered".into()))?
|
||||
.map_err(|r| IoError::Svg(format!("can't rasterise this drawing: {}", r.message)))
|
||||
}
|
||||
|
||||
/// A transparent pixmap, or `None` past [`MAX_RASTER_PIXELS`].
|
||||
@@ -1298,6 +1138,7 @@ fn count_nodes_with_limit(root: &usvg::Group, include_text: bool, limit: usize,
|
||||
/// count too, at the scale of the element that uses them, as resvg renders them. Past `visits`
|
||||
/// elements, or with a referenced root nested past [`MAX_RECURSION`], the drawing counts as too
|
||||
/// costly.
|
||||
#[cfg(test)]
|
||||
fn filter_cost(root: &usvg::Group, base: tiny_skia::Transform, rec: usize, visits: &mut usize) -> u64 {
|
||||
use usvg::filter::Kind;
|
||||
let mut cost = 0u64;
|
||||
@@ -1369,12 +1210,8 @@ fn filter_cost(root: &usvg::Group, base: tiny_skia::Transform, rec: usize, visit
|
||||
|
||||
/// An error when the drawing's filters are too costly to render at `scale` (see [`filter_cost`]).
|
||||
fn check_filter_cost(tree: &usvg::Tree, scale: f32) -> Result<(), IoError> {
|
||||
if filter_cost(tree.root(), tiny_skia::Transform::from_scale(scale, scale), 0, &mut { MAX_FILTER_VISITS }) > MAX_FILTER_COST {
|
||||
return Err(IoError::Svg(
|
||||
"the drawing's filters are too costly to render (a huge morphology radius, convolution kernel or turbulence octave count, or patterns nested too deep)".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
draw::check_filter_cost(tree, tiny_skia::Transform::from_scale(scale, scale), 2_000_000_000, 10_000_000, 200)
|
||||
.map_err(|refusal| IoError::Svg(format!("the drawing's filters are too costly to render: {}", refusal.message)))
|
||||
}
|
||||
|
||||
/// Converts a parsed tree into layers.
|
||||
@@ -1708,35 +1545,36 @@ impl Conv {
|
||||
};
|
||||
let canvas = tiny_skia::Transform::from_row(k, 0.0, 0.0, k, -(x0 as f32), -(y0 as f32));
|
||||
let ts = canvas.pre_concat(parent).pre_translate(shift.x(), shift.y());
|
||||
// resvg's own buffers for this element (nested layers, filters, clips, pattern tiles) come on
|
||||
// top of the layers already kept.
|
||||
if let Err(refusal) = limits::check(std::slice::from_ref(node), ts, w, h, self.retained_pixel_bytes) {
|
||||
let why = if refusal.complex {
|
||||
"is too complex to check"
|
||||
} else if refusal.memory {
|
||||
"needs too much memory to rasterise"
|
||||
} else {
|
||||
"exceeds a rasterising limit"
|
||||
};
|
||||
// one key per reason: a refusal for one reason must not hide a later one for another
|
||||
let key = if refusal.complex {
|
||||
"raster-scratch-complex"
|
||||
} else if refusal.memory {
|
||||
"raster-scratch-memory"
|
||||
} else {
|
||||
"raster-scratch-limit"
|
||||
};
|
||||
self.note(key, format!("SVG: an element was dropped because it {why}: {}", refusal.message));
|
||||
return None;
|
||||
}
|
||||
// resvg renders the node in its parent's space after shifting its absolute bounding box
|
||||
// to the origin: undo that shift, apply the parent's transform, then scale to the canvas
|
||||
// and shift so the pixmap starts at (x0, y0).
|
||||
let Some(rendered) = guarded(|| resvg::render_node(node, ts, &mut pixmap.as_mut())) else {
|
||||
// The shared renderer charges this element's scratch buffers on top of already retained layers.
|
||||
let Some(rendered) = guarded(|| draw::render_node(node, ts, &mut pixmap, self.retained_pixel_bytes, MAX_PEAK_PIXEL_BYTES)) else {
|
||||
self.note("raster-panic", "SVG: an element that could not be rendered was dropped".to_string());
|
||||
return None;
|
||||
};
|
||||
rendered?;
|
||||
let rendered = match rendered {
|
||||
Ok(rendered) => rendered,
|
||||
Err(refusal) => {
|
||||
let why = if refusal.complex {
|
||||
"is too complex to check"
|
||||
} else if refusal.memory {
|
||||
"needs too much memory to rasterise"
|
||||
} else {
|
||||
"exceeds a rasterising limit"
|
||||
};
|
||||
// one key per reason: a refusal for one reason must not hide a later one for another
|
||||
let key = if refusal.complex {
|
||||
"raster-scratch-complex"
|
||||
} else if refusal.memory {
|
||||
"raster-scratch-memory"
|
||||
} else {
|
||||
"raster-scratch-limit"
|
||||
};
|
||||
self.note(key, format!("SVG: an element was dropped because it {why}: {}", refusal.message));
|
||||
return None;
|
||||
}
|
||||
};
|
||||
if !rendered {
|
||||
return None;
|
||||
}
|
||||
let surf = surface(&pixmap, Rect::new(x0, y0, x1, y1), self.fmt);
|
||||
// Charge what the layer keeps: surface() prunes transparent tiles.
|
||||
let bytes = photocraft_raster::stored_tiles_bytes(surf.tile_count() as u64, &self.fmt);
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use resvg::tiny_skia;
|
||||
use resvg::usvg;
|
||||
use craft_svg::tree::draw::tiny_skia;
|
||||
use craft_svg::tree::usvg;
|
||||
|
||||
use super::MAX_PEAK_PIXEL_BYTES;
|
||||
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
|
||||
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 8 of 199 (target 0) |
|
||||
| [Type](#type) | 5 | 5 | 0 | |
|
||||
| [Automation](#automation) | 5 | 4 | 2 | 664 of 664 menu items live (100.0%) |
|
||||
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 29 of 29 crates; panic_hunt present |
|
||||
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 26 of 26 crates; panic_hunt present |
|
||||
| [Distribution](#distribution) | 5 | 5 | 1 | |
|
||||
| [Open bugs](#open-bugs) | 31 | 1 | 0 | |
|
||||
|
||||
@@ -277,7 +277,7 @@ Menu wiring (`docs/parity-checklist.md`): 664 of 664 menu items live (100.0%). T
|
||||
|
||||
## Reliability
|
||||
|
||||
Never-crash attribute on 29 of 29 crate roots.
|
||||
Never-crash attribute on 26 of 26 crate roots.
|
||||
|
||||
| Id | Target | Status | Issue | Note |
|
||||
|---|---|---|---|---|
|
||||
|
||||
Reference in new issue
Block a user