diff --git a/Cargo.lock b/Cargo.lock index 0367fb6bd..4d0f6a9d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,6 +116,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aes" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1" +dependencies = [ + "cipher", + "cpubits", + "cpufeatures 0.3.1", +] + [[package]] name = "ahash" version = "0.8.12" @@ -536,6 +547,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bit_field" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1" + [[package]] name = "bitflags" version = "1.3.2" @@ -557,6 +574,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + [[package]] name = "block2" version = "0.5.1" @@ -794,6 +820,16 @@ dependencies = [ "windows-link", ] +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "crypto-common 0.2.2", + "inout", +] + [[package]] name = "clipboard-win" version = "5.4.3" @@ -812,6 +848,12 @@ dependencies = [ "cc", ] +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "cmpv2" version = "0.2.0" @@ -830,7 +872,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730" dependencies = [ - "const-oid", + "const-oid 0.9.6", "der", "spki", "x509-cert", @@ -906,6 +948,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a" + [[package]] name = "core-foundation" version = "0.9.4" @@ -983,6 +1031,12 @@ dependencies = [ "libm", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -1009,14 +1063,45 @@ dependencies = [ "rustix 1.1.5", ] +[[package]] +name = "craft-cfb" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" + [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ + "md-5", "rayon", ] +[[package]] +name = "craft-codepage" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" + +[[package]] +name = "craft-csv" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=387c64892b30fdad491b263cc3d9eac660d88dcc#387c64892b30fdad491b263cc3d9eac660d88dcc" +dependencies = [ + "thiserror 2.0.21", +] + +[[package]] +name = "craft-designcraft-format" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca#93d0998383aa150fa50a2ffbf49ef37786e37eca" +dependencies = [ + "craft-document-bundle", + "craft-eps 0.1.0 (git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca)", + "serde", + "serde_json", + "thiserror 2.0.21", +] + [[package]] name = "craft-dialogs" version = "0.1.0" @@ -1035,6 +1120,108 @@ name = "craft-docpath" version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +[[package]] +name = "craft-document-bundle" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca#93d0998383aa150fa50a2ffbf49ef37786e37eca" +dependencies = [ + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca)", + "serde_json", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-docx" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "base64 0.23.1", + "chrono", + "craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "craft-math", + "craft-offcrypto", + "craft-opc 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "craft-wordmodel", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "log", + "quick-xml 0.41.0", + "thiserror 2.0.21", + "unicode-bidi", + "zeroize", +] + +[[package]] +name = "craft-drawingml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "kurbo", + "log", + "serde", +] + +[[package]] +name = "craft-drawingml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "kurbo", + "log", + "serde", +] + +[[package]] +name = "craft-drawingml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f6cab1980#f6cab1980bbe422cc00c4b19d9f0f9ba337e1316" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "kurbo", + "log", + "serde", +] + +[[package]] +name = "craft-eps" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca#93d0998383aa150fa50a2ffbf49ef37786e37eca" + +[[package]] +name = "craft-eps" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" + +[[package]] +name = "craft-eps" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" + +[[package]] +name = "craft-epub" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-file-formats" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "craft-eps 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "serde", + "serde_json", +] + [[package]] name = "craft-fonts-build" version = "0.1.0" @@ -1063,6 +1250,124 @@ dependencies = [ "writeable", ] +[[package]] +name = "craft-idml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=1ad5f35bf#1ad5f35bf0b33f5846fd8aec782f0ba5a9e3b596" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-idml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-image-codecs" +version = "0.1.0" +source = "git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895#2e670cf9377b523112f3fe4b409399772c745895" +dependencies = [ + "craft-jpeg 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", + "exr", + "flate2", + "half", + "image", + "image-webp", + "jpeg-encoder", + "png", + "rayon", + "serde_json", + "thiserror 2.0.21", + "tiff", + "zune-core", + "zune-jpeg", + "zune-jpegxl", +] + +[[package]] +name = "craft-image-codecs" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f#cc23ffd4d26f3074808e2187d332564817624f8f" +dependencies = [ + "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", + "exr", + "flate2", + "half", + "image", + "image-webp", + "jpeg-encoder", + "png", + "rayon", + "serde_json", + "thiserror 2.0.21", + "tiff", + "zune-core", + "zune-jpeg", + "zune-jpegxl", +] + +[[package]] +name = "craft-image-codecs" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "exr", + "flate2", + "half", + "image", + "image-webp", + "jpeg-encoder", + "png", + "rayon", + "serde_json", + "thiserror 2.0.21", + "tiff", + "zune-core", + "zune-jpeg", + "zune-jpegxl", +] + +[[package]] +name = "craft-indd" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=47bf5650b0d503b97bfb5e841746c4957897d11f#47bf5650b0d503b97bfb5e841746c4957897d11f" +dependencies = [ + "indd", +] + +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895#2e670cf9377b523112f3fe4b409399772c745895" +dependencies = [ + "thiserror 2.0.21", +] + +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f#cc23ffd4d26f3074808e2187d332564817624f8f" +dependencies = [ + "thiserror 2.0.21", +] + +[[package]] +name = "craft-jpeg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "craft-keymap" version = "0.1.0" @@ -1075,23 +1380,111 @@ dependencies = [ "serde_json", ] +[[package]] +name = "craft-math" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "serde", +] + +[[package]] +name = "craft-offcrypto" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "aes", + "base64 0.23.1", + "craft-cfb", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "getrandom 0.3.4", + "hmac", + "sha1 0.11.0", + "sha2 0.11.1", + "thiserror 2.0.21", + "zeroize", +] + +[[package]] +name = "craft-opc" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "log", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-opc" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551)", + "log", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-opc" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "log", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-opc" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f6cab1980#f6cab1980bbe422cc00c4b19d9f0f9ba337e1316" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "log", + "thiserror 2.0.21", +] + [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "bytemuck", + "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f)", "hayro", "hayro-interpret", "hayro-syntax", "krilla", + "krilla-svg", + "thiserror 2.0.21", + "usvg 0.47.0", +] + +[[package]] +name = "craft-pptx" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f6cab1980#f6cab1980bbe422cc00c4b19d9f0f9ba337e1316" +dependencies = [ + "craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "craft-opc 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f6cab1980)", + "kurbo", + "log", + "serde", + "serde_json", "thiserror 2.0.21", ] [[package]] name = "craft-prepress" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "craft-cms", "craft-pdf", @@ -1114,6 +1507,72 @@ dependencies = [ "winsafe", ] +[[package]] +name = "craft-psd" +version = "0.1.0" +source = "git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895#2e670cf9377b523112f3fe4b409399772c745895" +dependencies = [ + "encoding_rs", + "flate2", + "rayon", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-rtf" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "craft-codepage", + "encoding_rs", +] + +[[package]] +name = "craft-sheet" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" + +[[package]] +name = "craft-svg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" +dependencies = [ + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f)", + "flate2", + "kurbo", + "roxmltree 0.21.2", + "thiserror 2.0.21", + "usvg 0.48.1", +] + +[[package]] +name = "craft-svg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f#cc23ffd4d26f3074808e2187d332564817624f8f" +dependencies = [ + "craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", + "flate2", + "kurbo", + "resvg 0.48.1", + "roxmltree 0.21.2", + "thiserror 2.0.21", + "usvg 0.48.1", +] + +[[package]] +name = "craft-svg" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "flate2", + "kurbo", + "roxmltree 0.21.2", + "thiserror 2.0.21", +] + [[package]] name = "craft-ui" version = "0.1.0" @@ -1152,7 +1611,7 @@ dependencies = [ "semver", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "tar", "tempfile", "ureq", @@ -1181,6 +1640,184 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "craft-wordmodel" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "base64 0.23.1", + "craft-math", + "log", + "serde", + "serde_json", + "thiserror 2.0.21", + "unicode-segmentation", +] + +[[package]] +name = "craft-xlsx" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" +dependencies = [ + "craft-drawingml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "craft-opc 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "craft-sheet", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119)", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=1ad5f35bf#1ad5f35bf0b33f5846fd8aec782f0ba5a9e3b596" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f#cc23ffd4d26f3074808e2187d332564817624f8f" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1#f23b0f33f0d00b157476533a43cbbcfd901aa1f1" +dependencies = [ + "quick-xml 0.41.0", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f6cab1980#f6cab1980bbe422cc00c4b19d9f0f9ba337e1316" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=1ad5f35bf#1ad5f35bf0b33f5846fd8aec782f0ba5a9e3b596" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=2b9a325f57624804ed423aded16695eddb815119#2b9a325f57624804ed423aded16695eddb815119" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=93d0998383aa150fa50a2ffbf49ef37786e37eca#93d0998383aa150fa50a2ffbf49ef37786e37eca" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#6d0b33c0cd63ae4250c180a04eb4a4d66ab81448" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f6cab1980#f6cab1980bbe422cc00c4b19d9f0f9ba337e1316" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + [[package]] name = "crc32fast" version = "1.5.3" @@ -1252,6 +1889,24 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +dependencies = [ + "cmov", +] + [[package]] name = "cursor-icon" version = "1.2.0" @@ -1270,7 +1925,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "der_derive", "flagset", "pem-rfc7468", @@ -1334,6 +1989,8 @@ dependencies = [ name = "designcraft-cli" version = "0.20.1" dependencies = [ + "craft-file-formats", + "craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -1398,9 +2055,15 @@ version = "0.20.1" dependencies = [ "caseless", "craft-atomic", + "craft-csv", "craft-docpath", + "craft-file-formats", + "craft-indd", "craft-prepress", "craft-print", + "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -1418,10 +2081,8 @@ dependencies = [ "hayro-cmap", "hayro-interpret", "hayro-syntax", - "indd", "kurbo", "log", - "quick-xml 0.41.0", "same-file", "serde", "serde_json", @@ -1436,7 +2097,7 @@ dependencies = [ name = "designcraft-epub" version = "0.20.1" dependencies = [ - "chrono", + "craft-epub", "designcraft-color", "designcraft-doc", "zip 3.0.0", @@ -1459,11 +2120,9 @@ dependencies = [ name = "designcraft-format" version = "0.20.1" dependencies = [ + "craft-designcraft-format", "designcraft-doc", - "designcraft-images", - "serde", "serde_json", - "thiserror 2.0.21", "zip 3.0.0", ] @@ -1484,13 +2143,16 @@ dependencies = [ name = "designcraft-idml" version = "0.20.1" dependencies = [ + "craft-file-formats", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", + "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", "designcraft-color", "designcraft-compose", "designcraft-doc", "designcraft-geom", "designcraft-images", "log", - "quick-xml 0.41.0", "thiserror 2.0.21", "zip 3.0.0", ] @@ -1500,6 +2162,11 @@ name = "designcraft-images" version = "0.20.1" dependencies = [ "craft-cms", + "craft-eps 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)", + "craft-file-formats", + "craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", + "craft-psd", + "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", "designcraft-color", "designcraft-fonts", "flate2", @@ -1507,17 +2174,15 @@ dependencies = [ "jpeg-decoder", "log", "quick-xml 0.41.0", - "resvg", "skrifa 0.47.0", "tiff", - "zune-core", - "zune-jpeg", ] [[package]] name = "designcraft-mcp" version = "0.20.1" dependencies = [ + "craft-file-formats", "designcraft-engine", "designcraft-geom", "designcraft-render", @@ -1533,6 +2198,7 @@ version = "0.20.1" dependencies = [ "chrono", "craft-cms", + "craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", "craft-pdf", "craft-prepress", "designcraft-color", @@ -1544,11 +2210,10 @@ dependencies = [ "flate2", "hayro-cmap", "hayro-interpret", - "hayro-syntax", "image", - "krilla-svg", "kurbo", "log", + "skrifa 0.47.0", "thiserror 2.0.21", "tiff", ] @@ -1558,6 +2223,9 @@ name = "designcraft-pptx" version = "0.20.1" dependencies = [ "chrono", + "craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", + "craft-opc 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551)", + "craft-pptx", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -1576,6 +2244,7 @@ name = "designcraft-render" version = "0.20.1" dependencies = [ "bytemuck", + "craft-image-codecs 0.1.0 (git+https://github.com/dylanmtaylor/craft-libs?rev=2e670cf9377b523112f3fe4b409399772c745895)", "craft-pdf", "designcraft-color", "designcraft-compose", @@ -1595,8 +2264,13 @@ dependencies = [ name = "designcraft-textimport" version = "0.20.1" dependencies = [ + "craft-docx", + "craft-file-formats", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=1ad5f35bf)", + "craft-rtf", + "craft-wordmodel", + "craft-xlsx", "designcraft-doc", - "quick-xml 0.41.0", "zip 3.0.0", ] @@ -1617,6 +2291,7 @@ name = "designcraft-ui-egui" version = "0.20.1" dependencies = [ "craft-dialogs", + "craft-file-formats", "craft-keymap", "craft-prepress", "craft-ui", @@ -1684,8 +2359,20 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid 0.10.3", + "crypto-common 0.2.2", + "ctutils", ] [[package]] @@ -2064,6 +2751,22 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "exr" +version = "1.74.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb29d0be702adf92c645d9b2f93472906ba83d400e59f98adb3770ce5c18c2f6" +dependencies = [ + "bit_field", + "half", + "lebe", + "miniz_oxide 0.8.9", + "multiversion", + "rayon-core", + "smallvec", + "zune-inflate", +] + [[package]] name = "fancy-regex" version = "0.19.2" @@ -2265,6 +2968,17 @@ dependencies = [ "ttf-parser", ] +[[package]] +name = "fontdb" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2660c5e9157bf76d2db1294e4a9feba604ef610819a3b591088d0d8392a3290f" +dependencies = [ + "log", + "slotmap", + "tinyvec", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -2430,9 +3144,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 5.3.0", "wasip2", + "wasm-bindgen", ] [[package]] @@ -2693,7 +3409,7 @@ dependencies = [ [[package]] name = "hayro" version = "0.7.1" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "bytemuck", "hayro-interpret", @@ -2713,7 +3429,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-cmap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "brotli", "hayro-postscript", @@ -2722,7 +3438,7 @@ dependencies = [ [[package]] name = "hayro-interpret" version = "0.7.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "bitflags 2.13.2", "hayro-cmap", @@ -2740,7 +3456,7 @@ dependencies = [ [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "fearless_simd", "hayro-ccitt", @@ -2758,12 +3474,12 @@ dependencies = [ [[package]] name = "hayro-postscript" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "flate2", "hayro-ccitt", @@ -2811,6 +3527,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", +] + [[package]] name = "http" version = "1.5.0" @@ -2850,6 +3575,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "hyper" version = "1.12.0" @@ -3154,6 +3888,7 @@ dependencies = [ "moxcms", "num-traits", "png", + "qoi", "tiff", "zune-core", "zune-jpeg", @@ -3175,6 +3910,12 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09e54e57b4c48b40f7aec75635392b12b3421fa26fe8b4332e63138ed278459c" +[[package]] +name = "imagesize" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b27460c2c92b037f3f94c538ed9a3342f3fdf923606781629ccb35f82d042a" + [[package]] name = "indd" version = "0.1.0" @@ -3190,6 +3931,15 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "inout" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a580c13f0ffc335ef42dd3f6b1a41b726051c5e1656d9a3aa6fddb3c5dfbbf9" +dependencies = [ + "hybrid-array", +] + [[package]] name = "ipnet" version = "2.12.2" @@ -3313,6 +4063,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00810f1d8b74be64b13dbf3db89ac67740615d6c891f0e7b6179326533011a07" +[[package]] +name = "jpeg-encoder" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f" + [[package]] name = "js-sys" version = "0.3.106" @@ -3364,7 +4120,7 @@ dependencies = [ [[package]] name = "krilla" version = "0.8.2" -source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0" +source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f" dependencies = [ "base64 0.22.1", "bumpalo", @@ -3373,7 +4129,7 @@ dependencies = [ "gif", "hayro-write", "image-webp", - "imagesize", + "imagesize 0.14.0", "indexmap", "pdf-writer", "png", @@ -3396,13 +4152,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1237d7c37b16ca9fbc2e72dde13a10d321f9a44aceee35c062bc0a43bfc7ce16" dependencies = [ "flate2", - "fontdb", + "fontdb 0.23.0", "krilla", - "resvg", + "resvg 0.47.0", "skrifa 0.42.1", "smallvec", "tiny-skia 0.12.0", - "usvg", + "usvg 0.47.0", ] [[package]] @@ -3424,6 +4180,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" +[[package]] +name = "lebe" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8" + [[package]] name = "libc" version = "0.2.191" @@ -3525,6 +4287,16 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest 0.10.7", +] + [[package]] name = "memchr" version = "2.8.3" @@ -3624,6 +4396,28 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "multiversion" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb8a68be21d0755f83bfe47e79b896cc732687cf1903f0e50585e8d6ecc53076" +dependencies = [ + "multiversion-macros", + "target-features", +] + +[[package]] +name = "multiversion-macros" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a05e0c3c3e4edaa21d87c645852ed0b0c3663752bcc6ec43353bd6189dce35e1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "target-features", +] + [[package]] name = "multiversion_no_op" version = "1.0.0" @@ -4619,6 +5413,15 @@ version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "qrcodegen" version = "1.8.0" @@ -4979,7 +5782,25 @@ dependencies = [ "rgb", "svgtypes", "tiny-skia 0.12.0", - "usvg", + "usvg 0.47.0", + "zune-jpeg", +] + +[[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 0.12.0", + "usvg 0.48.1", "zune-jpeg", ] @@ -5406,7 +6227,18 @@ checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" dependencies = [ "cfg-if", "cpufeatures 0.2.17", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", ] [[package]] @@ -5417,7 +6249,18 @@ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures 0.2.17", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", ] [[package]] @@ -5471,12 +6314,12 @@ checksum = "da90c3d9af638898a5fdc347479b18f950bb0dde11ecf2244f94cd28135da53b" dependencies = [ "aws-lc-rs", "base64 0.22.1", - "const-oid", + "const-oid 0.9.6", "der", - "digest", + "digest 0.10.7", "pem", "rand_core 0.10.1", - "sha2", + "sha2 0.10.9", "signature", "sigstore-types", "spki", @@ -5545,7 +6388,7 @@ dependencies = [ "chrono", "cmpv2", "cms", - "const-oid", + "const-oid 0.9.6", "der", "hex", "rand", @@ -5584,7 +6427,7 @@ dependencies = [ "base64 0.22.1", "chrono", "cms", - "const-oid", + "const-oid 0.9.6", "hex", "pem", "rustls-pki-types", @@ -5974,6 +6817,12 @@ dependencies = [ "xattr", ] +[[package]] +name = "target-features" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1bbb9f3c5c463a01705937a24fdabc5047929ac764b2d5b9cf681c1f5041ed5" + [[package]] name = "tempfile" version = "3.27.0" @@ -6539,8 +7388,8 @@ dependencies = [ "base64 0.22.1", "data-url", "flate2", - "fontdb", - "imagesize", + "fontdb 0.23.0", + "imagesize 0.14.0", "kurbo", "log", "pico-args", @@ -6558,6 +7407,33 @@ dependencies = [ "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 0.24.0", + "harfrust 0.12.0", + "imagesize 0.15.0", + "kurbo", + "log", + "pico-args", + "roxmltree 0.21.2", + "simplecss", + "siphasher", + "skrifa 0.44.0", + "strict-num", + "svgtypes", + "tiny-skia-path 0.12.0", + "unicode-bidi", + "unicode-script", + "unicode-vo", + "xmlwriter", +] + [[package]] name = "utf16_iter" version = "1.0.5" @@ -7608,9 +8484,9 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" dependencies = [ - "const-oid", + "const-oid 0.9.6", "der", - "sha1", + "sha1 0.10.7", "signature", "spki", "tls_codec", @@ -7986,6 +8862,15 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b" +[[package]] +name = "zune-inflate" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +dependencies = [ + "simd-adler32", +] + [[package]] name = "zune-jpeg" version = "0.5.15" @@ -7995,6 +8880,15 @@ dependencies = [ "zune-core", ] +[[package]] +name = "zune-jpegxl" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba11ecd07cc23351500e840ae03841b7e4997923ec8e4832ee3ae199ea0b6b4" +dependencies = [ + "zune-core", +] + [[package]] name = "zvariant" version = "5.15.1" diff --git a/Cargo.toml b/Cargo.toml index d90986f91..34cd5cbc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,29 @@ repository = "https://github.com/storytold/designcraft" [workspace.dependencies] # Shared reader and writer; publish the immutable revision before this consumer. -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", default-features = false } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.1.0", default-features = false } +craft-designcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "93d0998383aa150fa50a2ffbf49ef37786e37eca", version = "=0.1.0" } +craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } +craft-epub = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "1ad5f35bf", version = "=0.1.0" } +craft-indd = { git = "https://github.com/storytold/craft-libs", rev = "47bf5650b0d503b97bfb5e841746c4957897d11f", version = "=0.1.0" } +craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "cc23ffd4d26f3074808e2187d332564817624f8f", version = "=0.1.0", features = ["tree-render", "tree-text"] } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "1ad5f35bf", version = "=0.1.0" } +craft-xml-dtd = { package = "craft-xml", git = "https://github.com/storytold/craft-libs", rev = "f23b0f33f0d00b157476533a43cbbcfd901aa1f1", version = "=0.1.0" } +craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } +craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "2b9a325f57624804ed423aded16695eddb815119", version = "=0.1.0" } +craft-docx = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } +craft-wordmodel = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } +craft-csv = { git = "https://github.com/storytold/craft-libs", rev = "387c64892b30fdad491b263cc3d9eac660d88dcc", version = "=0.1.0" } +craft-image-codecs = { git = "https://github.com/dylanmtaylor/craft-libs", rev = "2e670cf9377b523112f3fe4b409399772c745895", version = "=0.1.0" } +craft-psd = { git = "https://github.com/dylanmtaylor/craft-libs", rev = "2e670cf9377b523112f3fe4b409399772c745895", version = "=0.1.0" } +craft-file-formats = { git = "https://github.com/storytold/craft-libs", rev = "eed3c28cf016723d004d6f2c79c61424c15d4558", version = "=0.1.0" } +craft-opc = { git = "https://github.com/storytold/craft-libs", rev = "8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551", version = "=0.1.0" } +craft-pptx = { git = "https://github.com/storytold/craft-libs", rev = "f6cab1980", version = "=0.1.0" } # Shared keyboard bindings: chords, overrides, conflicts, egui dispatch, the Keyboard Shortcuts dialog. craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", features = ["egui", "ui"] } # Separations, ink coverage and the ink manager; same revision as craft-pdf and the krilla patch. -craft-prepress = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0", features = ["flatten"] } +craft-prepress = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.1.0", features = ["flatten"] } # craft-update: app-specific pretend versions apply to startup and manual checks. craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] } # internal @@ -66,25 +84,15 @@ vello_cpu = "0.2" vello_common = { version = "0.2", default-features = false } # Decoded image buffers become pixmap pixels without a copy; the version vello_common uses. bytemuck = { version = "1.25", features = ["extern_crate_alloc"] } -image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] } +image = { version = "0.25", default-features = false } # CMYK TIFF samples for PDF export (`image` decodes them to RGB); the version `image` uses. tiff = "0.11" -# SVG (same usvg as krilla-svg). -resvg = { version = "0.47", default-features = false, features = ["text"] } -krilla-svg = "=0.8.1" # Boolean operations on Bézier paths (Pathfinder). flo_curves = "0.8" # QR codes (Object › Generate QR Code); MIT. qrcodegen = "1.8" quick-xml = "0.41" zip = { version = "3", default-features = false, features = ["deflate"] } -# INDD/INDT → IDML conversion for File › Open: storytold/indd-utils, pinned by rev as every other -# git dependency here is. It parses untrusted INDD files, and `branch = "main"` meant any -# `cargo update` -- Dependabot runs them -- pulled whatever was on that branch into the parser -# without review (#1599). -# (MIT OR Apache-2.0, no dependencies, builds for wasm). -indd = { git = "https://github.com/storytold/indd-utils", rev = "7f3060e5bce78d21ea70e0d5eacb96edce15dfbe" } - # Which paths stored in documents may be followed (craft-libs). craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" } # Atomic file replacement for saves and exports (craft-libs). @@ -93,7 +101,7 @@ craft-atomic = { version = "0.1.0", git = "https://github.com/storytold/craft-li craft-print = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" } # ICC colour management: working spaces, transforms, black point compensation (craft-libs). -craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" } +craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f" } # ui # Shared frontend components; keep this dependency above the engine boundary. @@ -143,16 +151,16 @@ debug = 0 # Opt-in cancelable macOS termination on the pinned winit 0.30 line. [patch.crates-io] -krilla = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.8.2" } +krilla = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.8.2" } winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" } # The hayro crates from craft-libs' vendor/ directory (pdfcraft's, plus the plate mode and decode # limits craft-pdf and craft-prepress need); same revision as craft-pdf. -hayro = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.7.1" } -hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.7.0" } -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.3.0" } -hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0" } -hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", version = "=0.1.0" } +hayro = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.7.1" } +hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.7.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.3.0" } +hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.1.0" } +hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "40525913633942f84b06d4837a8d90534a55d63f", version = "=0.1.0" } ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" } diff --git a/ROADMAP.md b/ROADMAP.md index 02630738a..d5b6dec2a 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -394,6 +394,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m ## Progress log +- **2026-11-14** · IDML export keeps each endnote reference as its number in superscript text, as the endnote frame lists it, instead of dropping it; the endnotes are still written as plain text, without IDML's endnote elements (#2753). No readiness percentage change. - **2026-11-14** · Object › Text Frame Options shows the inset spacing (one Inset for a non-rectangular frame), the column width and gutter and the paragraph spacing limit in the document's ruler units, as the Properties panel does, instead of always in picas, and a bare number typed in any of its measure fields is in those units (#2739). No readiness percentage change. - **2026-11-13** · PDF exports outside PDF/X-1a and PDF/A-2b attach the CMYK working space's ICC profile as `/DefaultCMYK` (`[/ICCBased …]`) on every page, inherited `/Pages` resource dict, Form XObject, SMask form, tiling pattern, and Type3 font resource scope (#2743). Plain print exports and booklets embed one shared Flate-compressed `/N 4` profile stream without adding `/OutputIntents` or `/Trapped`; PDF/X-4 reuses its catalog `/DestOutputProfile`; RGB-blend documents attach `/DefaultCMYK` when they draw in `DeviceCMYK` and skip it for pure RGB. Viewers that honor `/DefaultCMYK` instead of `/OutputIntents` (including Apple Quartz and MuPDF) now render CMYK colors consistently with the working space across both plain and PDF/X-4 exports. No readiness percentage change. - **2026-11-12** · Properties › Text Frame shows the frame's inset spacing (Top, Bottom, Left and Right with a link that makes all four the same; one Inset for a non-rectangular frame) and four Vertical Justification buttons (Top, Center, Bottom, Justify), and the section also shows with the Type tool in a frame, where it changes the frame that shows the insertion point. No readiness percentage change. diff --git a/apps/designcraft-cli/Cargo.toml b/apps/designcraft-cli/Cargo.toml index ab2464147..d214b9d84 100644 --- a/apps/designcraft-cli/Cargo.toml +++ b/apps/designcraft-cli/Cargo.toml @@ -22,5 +22,7 @@ designcraft-compose = { workspace = true } designcraft-format = { workspace = true } designcraft-pdf = { workspace = true } designcraft-mcp = { workspace = true } +craft-file-formats = { workspace = true } +craft-image-codecs = { workspace = true } image = { workspace = true } serde_json = { workspace = true } diff --git a/apps/designcraft-cli/src/main.rs b/apps/designcraft-cli/src/main.rs index 79997e0ae..1e39e906e 100644 --- a/apps/designcraft-cli/src/main.rs +++ b/apps/designcraft-cli/src/main.rs @@ -319,16 +319,17 @@ fn names_the_same_file(input: &std::path::Path, out: &std::path::Path) -> bool { /// as it is; it is decoded anyway, so a broken one is an error rather than an unreadable thumbnail. fn fit_png(png: Vec, size: Option) -> Result, String> { // The preview comes from the file: it may claim any size. - let mut limits = image::Limits::default(); - limits.max_image_width = Some(4096); - limits.max_image_height = Some(4096); - let mut reader = image::ImageReader::with_format(std::io::Cursor::new(&png), image::ImageFormat::Png); - reader.limits(limits); - let img = reader.decode().map_err(|e| e.to_string())?; - let Some(size) = size.filter(|s| img.width().max(img.height()) > *s) else { return Ok(png) }; - let mut out = std::io::Cursor::new(Vec::new()); - img.resize(size, size, image::imageops::FilterType::Triangle).write_to(&mut out, image::ImageFormat::Png).map_err(|e| e.to_string())?; - Ok(out.into_inner()) + let info = craft_image_codecs::inspect_raster(&png).map_err(|e| e.to_string())?.ok_or("invalid PNG preview")?; + if info.width > 4096 || info.height > 4096 { + return Err("preview is larger than 4096 pixels".into()); + } + let decoded = craft_image_codecs::decode(&png).map_err(|e| e.to_string())?; + let Some(size) = size.filter(|s| decoded.width().max(decoded.height()) > *s) else { return Ok(png) }; + let rgba = image::RgbaImage::from_raw(decoded.width(), decoded.height(), decoded.to_rgba8()).ok_or("invalid PNG pixel data")?; + let resized = image::DynamicImage::ImageRgba8(rgba).resize(size, size, image::imageops::FilterType::Triangle).to_rgba8(); + let encoded = craft_image_codecs::Image::from_u8(resized.width(), resized.height(), craft_image_codecs::ChannelLayout::Rgba, resized.into_raw()) + .map_err(|e| e.to_string())?; + craft_image_codecs::encode(&encoded, craft_image_codecs::Format::Png, &Default::default()).map_err(|e| e.to_string()) } /// `mcp` (headless, in-process engine) or `mcp --connect PORT|HOST:PORT` (drive a running app @@ -597,8 +598,8 @@ fn export(s: &mut Session, out: &str, page: usize, scale: f64) -> Result<(), Str let img = r .render_page(&st.doc, &s.cache, page, scale, true, &designcraft_render::RenderOptions { printing_only: true, ..Default::default() }) .ok_or("no such page")?; - let lower = out.to_lowercase(); - let bytes = if lower.ends_with(".jpg") || lower.ends_with(".jpeg") { img.to_jpeg(90) } else { img.to_png() }; + let jpeg = craft_file_formats::detect(out, &[]) == Some(craft_file_formats::Format::Jpeg); + let bytes = if jpeg { img.to_jpeg(90) } else { img.to_png() }; designcraft_engine::atomic::write_atomic(std::path::Path::new(out), &bytes).map_err(|e| format!("{out}: {e}"))?; eprintln!("wrote {out} ({}×{}, {:.1} ms, {} glyphs)", img.width, img.height, t.elapsed().as_secs_f64() * 1000.0, r.stats.glyphs); Ok(()) @@ -645,7 +646,7 @@ fn script(args: &[String]) -> Result<(), String> { match a.as_str() { "--in" => { let p = val()?; - let cmd = if p.to_lowercase().ends_with(".idml") { "file.openIdml" } else { "file.open" }; + let cmd = if craft_file_formats::detect(&p, &[]) == Some(craft_file_formats::Format::Idml) { "file.openIdml" } else { "file.open" }; setup.push((cmd.into(), json!({"path": p}))); } "--sample" => setup.push(("file.newSample".into(), json!({}))), diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 6b6a43a87..292025c33 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -30,12 +30,16 @@ designcraft-pdf = { workspace = true } craft-prepress = { workspace = true } designcraft-tools = { workspace = true } designcraft-idml = { workspace = true } -indd = { workspace = true } +craft-file-formats = { workspace = true } +craft-csv = { workspace = true } +craft-indd = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } log = { workspace = true } -quick-xml = { workspace = true } +craft-xml = { workspace = true } +craft-xml-dtd = { workspace = true } +craft-svg = { workspace = true } caseless = { workspace = true } unicode-segmentation = { workspace = true } diff --git a/crates/engine/src/cmd/book.rs b/crates/engine/src/cmd/book.rs index 29f95741d..6160598df 100644 --- a/crates/engine/src/cmd/book.rs +++ b/crates/engine/src/cmd/book.rs @@ -59,7 +59,7 @@ fn load(path: &str) -> Result { let _ = path; vec![] }; - if path.to_lowercase().ends_with(".idml") { + if craft_file_formats::detect(path, &bytes) == Some(craft_file_formats::Format::Idml) { return super::interchange::import_idml_confined(&bytes, Some(std::path::Path::new(path))) .map_err(|e| EngineError::Other(format!("{path}: {e}"))); } @@ -132,7 +132,11 @@ impl ChapterBatch { fn writable_chapter(s: &Session, path: &str, command: &'static str) -> Result<()> { use std::path::Path; - if Path::new(path).extension().and_then(std::ffi::OsStr::to_str).is_some_and(|ext| ext.eq_ignore_ascii_case("idml")) { + if Path::new(path) + .extension() + .and_then(std::ffi::OsStr::to_str) + .is_some_and(|ext| craft_file_formats::from_extension(ext) == Some(craft_file_formats::Format::Idml)) + { return Err(bad(command, format!("cannot change imported IDML chapter {path}; convert it to a native DesignCraft document first"))); } let target = crate::io::canonicalize(path).map_err(|e| EngineError::Other(format!("{path}: {e}")))?; diff --git a/crates/engine/src/cmd/datamerge.rs b/crates/engine/src/cmd/datamerge.rs index d34558423..cecc3938c 100644 --- a/crates/engine/src/cmd/datamerge.rs +++ b/crates/engine/src/cmd/datamerge.rs @@ -19,7 +19,7 @@ use serde_json::{Value, json}; use super::{CommandSpec, bad, cmd, has_doc, id_param, ok, str_param}; use crate::{DocState, Result, Session}; use fill::{FillReport, ImageCache, Maps, MissingImage, Sources, copy_item, fill_row, identity_map}; -use parse::{Table, TileInput, extension, relative_between, select_records, status_of, table_from_bytes, table_from_grid, table_from_objects, tile}; +use parse::{Table, TileInput, relative_between, select_records, status_of, table_from_bytes, table_from_grid, table_from_objects, tile}; #[cfg(not(target_arch = "wasm32"))] pub(crate) use parse::fingerprint_from; @@ -827,11 +827,10 @@ fn take_file(p: &Value) -> std::result::Result<(Vec, String, Option) } fn parse_file(bytes: &[u8], name: &str, delimiter: Option, sheet: Option<&str>) -> std::result::Result { - let ext = extension(name); - if ext == "xls" || ext == "xlsm" { - return Err(format!("{ext} workbooks are not supported")); + if craft_file_formats::detect(name, &[]) == Some(craft_file_formats::Format::LegacyExcel) { + return Err("legacy Excel .xls/.xlsm workbooks are not supported".into()); } - if ext == "xlsx" { + if craft_file_formats::detect(name, bytes) == Some(craft_file_formats::Format::Xlsx) { let grid = designcraft_textimport::xlsx_records(bytes, sheet).map_err(|e| e.to_string())?; return table_from_grid(grid, Delimiter::Comma); } diff --git a/crates/engine/src/cmd/datamerge/parse.rs b/crates/engine/src/cmd/datamerge/parse.rs index ca3a61b27..435188f99 100644 --- a/crates/engine/src/cmd/datamerge/parse.rs +++ b/crates/engine/src/cmd/datamerge/parse.rs @@ -366,102 +366,20 @@ pub fn status_of(path: &Path, previous: Option) -> SourceStatus { } fn decode_utf8(bytes: &[u8], name: &str) -> Result { - let bytes = bytes.strip_prefix(&[0xEF, 0xBB, 0xBF]).unwrap_or(bytes); - let mut text = String::from_utf8(bytes.to_vec()).map_err(|_| format!("{name} is not UTF-8"))?; - if text.starts_with('\u{FEFF}') { - text.replace_range(..'\u{FEFF}'.len_utf8(), ""); - } - Ok(text) + craft_csv::decode_utf8(bytes).map_err(|_| format!("{name} is not UTF-8")) } fn sniff(name: &str, text: &str) -> Delimiter { - let ext = extension(name); - if ext == "tsv" || ext == "tab" { - return Delimiter::Tab; + match craft_file_formats::detect(name, &[]) { + Some(craft_file_formats::Format::Tsv) => return Delimiter::Tab, + Some(craft_file_formats::Format::Csv) => return Delimiter::Comma, + _ => {} } - if ext == "csv" { - return Delimiter::Comma; + match craft_csv::sniff_delimiter(text, '"') { + b'\t' => Delimiter::Tab, + b';' => Delimiter::Semicolon, + _ => Delimiter::Comma, } - let tab = header_delimiter_candidate(text, '\t'); - let semicolon = header_delimiter_candidate(text, ';'); - let comma = header_delimiter_candidate(text, ','); - // Prefer formats with coherent quoted-field boundaries. If none separates fields, - // retain the legacy permissive choice; this is detection, not record validation. - let prefer_coherent = [&tab, &semicolon, &comma].iter().any(|c| c.found && c.coherent); - let eligible = |c: &HeaderDelimiterCandidate| c.found && (!prefer_coherent || c.coherent); - if eligible(&tab) { - Delimiter::Tab - } else if eligible(&semicolon) && !eligible(&comma) { - Delimiter::Semicolon - } else { - Delimiter::Comma - } -} - -pub fn extension(name: &str) -> String { - Path::new(name).extension().and_then(std::ffi::OsStr::to_str).unwrap_or("").to_ascii_lowercase() -} - -struct HeaderDelimiterCandidate { - found: bool, - coherent: bool, -} - -/// A candidate separator outside quotes in its first nonempty logical record. -/// Only that candidate starts a new field. Quotes in an unquoted field stay literal; -/// Non-whitespace text after a quoted field closes lowers coherence, not validity. -fn header_delimiter_candidate(text: &str, delimiter: char) -> HeaderDelimiterCandidate { - let mut found = false; - let mut coherent = true; - let mut quoted = false; - let mut after_quote = false; - let mut field_start = true; - let mut nonempty = false; - let mut chars = text.chars().peekable(); - while let Some(c) = chars.next() { - if quoted { - if c == '"' { - if chars.peek() == Some(&'"') { - chars.next(); - nonempty = true; - } else { - quoted = false; - after_quote = true; - } - } else if !c.is_whitespace() { - nonempty = true; - } - continue; - } - match c { - '"' if field_start => { - quoted = true; - field_start = false; - } - separator if separator == delimiter => { - found = true; - field_start = true; - after_quote = false; - } - '\r' | '\n' => { - if nonempty { - break; - } - found = false; - coherent = true; - field_start = true; - after_quote = false; - } - _ => { - // Whitespace may follow a closing quote, but does not start a new field - // or allow a later non-whitespace suffix to regain coherence. - coherent &= !after_quote || c.is_whitespace(); - nonempty |= !c.is_whitespace(); - field_start = false; - } - } - } - HeaderDelimiterCandidate { found, coherent: coherent && !quoted } } /// Header cell: trim, drop one leading apostrophe, then `@` is image and `#` is qr. @@ -523,121 +441,59 @@ fn table_from_raw(raw: &[RawRow]) -> Result { Ok(Table { fields, rows, warnings, delimiter: Delimiter::Comma }) } -/// Split `s` on `delim`. Quoted fields keep commas, doubled quotes, and newlines. -/// More than 200 header columns, or the 100,001st non-empty data row, is an error and -/// the oversized row is not kept. +/// Parse delimited text with the shared CSV grammar, then apply DesignCraft's table limits and row policy. fn parse_delimited(s: &str, delim: char) -> Result, String> { - let mut rows: Vec = Vec::new(); - let mut row: Vec = Vec::new(); - let mut field = String::new(); - let mut quoted = false; - let mut field_start = true; + let mut rows = Vec::new(); let mut line = 1usize; - let mut row_line = 1usize; - let mut data_rows = 0usize; - let mut header_width: Option = None; - let mut discarding = false; - let mut chars = s.chars().peekable(); - - let finish = |row: &mut Vec, - field: &mut String, - rows: &mut Vec, - data_rows: &mut usize, - header_width: &mut Option, - row_line: usize, - discarding: &mut bool| - -> Result<(), String> { - if !*discarding { - row.push(std::mem::take(field)); - } else { - field.clear(); - } - *discarding = false; - let empty = row.iter().all(|c| c.trim().is_empty()); - if empty { - row.clear(); - return Ok(()); - } - match *header_width { - None => { - if row.len() > DATA_MERGE_MAX_COLS { - return Err(format!("the file has {} columns; the limit is {DATA_MERGE_MAX_COLS}", row.len())); - } - *header_width = Some(row.len()); - rows.push(RawRow { line: row_line, cells: std::mem::take(row) }); - } - Some(width) => { - *data_rows = data_rows.saturating_add(1); - if *data_rows > DATA_MERGE_MAX_ROWS { - return Err(format!("the file has more than {DATA_MERGE_MAX_ROWS} data rows")); - } - if row.len() > width.saturating_add(1) { - row.truncate(width.saturating_add(1)); - } - rows.push(RawRow { line: row_line, cells: std::mem::take(row) }); - } - } - Ok(()) - }; - - while let Some(c) = chars.next() { - if c == '\n' || (c == '\r' && chars.peek() != Some(&'\n')) { - line = line.saturating_add(1); - } - if quoted { - match c { - '"' if chars.peek() == Some(&'"') => { - if !discarding { - field.push('"'); + let mut error = None; + craft_csv::parse_records(s, delim, '"', DATA_MERGE_MAX_COLS.saturating_add(1), |cells| { + let row_line = line; + let inside_newlines = cells + .iter() + .map(|cell| { + let mut count = 0usize; + let mut previous_cr = false; + for c in cell.chars() { + if c == '\r' { + count = count.saturating_add(1); + previous_cr = true; + } else if c == '\n' { + if !previous_cr { + count = count.saturating_add(1); + } + previous_cr = false; + } else { + previous_cr = false; } - chars.next(); } - '"' => quoted = false, - _ if !discarding => field.push(c), - _ => {} - } - continue; + count + }) + .sum::(); + line = line.saturating_add(inside_newlines).saturating_add(1); + if cells.iter().all(|cell| cell.trim().is_empty()) { + return true; } - if c == delim { - field_start = true; - if discarding { - field.clear(); - continue; - } - row.push(std::mem::take(&mut field)); - if header_width.is_none() && row.len() > DATA_MERGE_MAX_COLS { - return Err(format!("the file has {} columns; the limit is {DATA_MERGE_MAX_COLS}", row.len())); - } - if header_width.is_some_and(|w| row.len() > w.saturating_add(1)) { - row.pop(); - discarding = true; - } - continue; + if rows.is_empty() && cells.len() > DATA_MERGE_MAX_COLS { + error = Some(format!("the file has {} columns; the limit is {DATA_MERGE_MAX_COLS}", cells.len())); + return false; } - match c { - '"' if field_start => { - quoted = true; - field_start = false; - } - '\r' | '\n' => { - if c == '\r' && chars.peek() == Some(&'\n') { - chars.next(); - line = line.saturating_add(1); - } - finish(&mut row, &mut field, &mut rows, &mut data_rows, &mut header_width, row_line, &mut discarding)?; - row_line = line; - field_start = true; - } - _ => { - field_start = false; - if !discarding { - field.push(c); - } - } + if !rows.is_empty() && rows.len() > DATA_MERGE_MAX_ROWS { + error = Some(format!("the file has more than {DATA_MERGE_MAX_ROWS} data rows")); + return false; } + rows.push(RawRow { line: row_line, cells }); + true + }); + if let Some(error) = error { + return Err(error); } - if !field.is_empty() || !row.is_empty() || discarding { - finish(&mut row, &mut field, &mut rows, &mut data_rows, &mut header_width, row_line, &mut discarding)?; + let Some(width) = rows.first().map(|row| row.cells.len()) else { + return Ok(rows); + }; + for row in rows.iter_mut().skip(1) { + if row.cells.len() > width.saturating_add(1) { + row.cells.truncate(width.saturating_add(1)); + } } Ok(rows) } diff --git a/crates/engine/src/cmd/export/formats.rs b/crates/engine/src/cmd/export/formats.rs index 4474d8ae7..c4f3c628b 100644 --- a/crates/engine/src/cmd/export/formats.rs +++ b/crates/engine/src/cmd/export/formats.rs @@ -136,7 +136,7 @@ pub(super) fn export_text(s: &mut Session, p: &Value) -> Result { Some(f @ ("rtf" | "tagged")) => f, Some("txt") | Some("text") => "txt", Some(f) => return Err(bad(ID, format!("unknown format `{f}` (txt, rtf, tagged)"))), - None if path.is_some_and(|x| x.to_ascii_lowercase().ends_with(".rtf")) => "rtf", + None if path.is_some_and(|x| craft_file_formats::detect(x, &[]) == Some(craft_file_formats::Format::Rtf)) => "rtf", None => "txt", }; let text = match format { diff --git a/crates/engine/src/cmd/file/bytes.rs b/crates/engine/src/cmd/file/bytes.rs index 5fd6d4e0b..c5468d016 100644 --- a/crates/engine/src/cmd/file/bytes.rs +++ b/crates/engine/src/cmd/file/bytes.rs @@ -21,7 +21,7 @@ fn save_bytes(d: &Document, preview: Option<&[u8]>) -> Result> { pub fn with_document_extension(path: &str) -> String { let p = std::path::Path::new(path); let ext = p.extension().and_then(std::ffi::OsStr::to_str); - if p.file_name().is_none() || ext.is_some_and(|e| e.eq_ignore_ascii_case(designcraft_format::EXTENSION)) { + if p.file_name().is_none() || ext.is_some_and(|e| craft_file_formats::from_extension(e) == Some(craft_file_formats::Format::DesignCraft)) { return path.to_string(); } format!("{path}.{}", designcraft_format::EXTENSION) @@ -32,7 +32,7 @@ pub fn with_document_extension(path: &str) -> String { /// that kept it would name the file `Brochure.designcraft.designcraft`. A bare `.designcraft` stays. pub(super) fn without_native_extension(name: &str) -> &str { match name.rsplit_once('.') { - Some((stem, ext)) if !stem.is_empty() && ext.eq_ignore_ascii_case(designcraft_format::EXTENSION) => stem, + Some((stem, ext)) if !stem.is_empty() && craft_file_formats::from_extension(ext) == Some(craft_file_formats::Format::DesignCraft) => stem, _ => name, } } @@ -41,7 +41,10 @@ pub(super) fn without_native_extension(name: &str) -> &str { /// The first [`DOCUMENT_SNIFF_BYTES`] of a file are enough for packages that start with their /// `mimetype` entry, as both formats write them. pub fn is_document(bytes: &[u8]) -> bool { - designcraft_idml::is_idml(bytes) || designcraft_format::starts_designcraft(bytes) || designcraft_format::is_designcraft(bytes) + matches!( + craft_file_formats::detect("", bytes), + Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson | craft_file_formats::Format::Idml) + ) } /// How much of a file [`is_document`] needs to recognise a package by its `mimetype` entry. diff --git a/crates/engine/src/cmd/file/open.rs b/crates/engine/src/cmd/file/open.rs index 529ec2d96..9cb94f5ab 100644 --- a/crates/engine/src/cmd/file/open.rs +++ b/crates/engine/src/cmd/file/open.rs @@ -84,15 +84,22 @@ fn open_path(s: &mut Session, p: &Value) -> Result { let bytes = crate::io::read_file(path).map_err(EngineError::Other)?; // The content decides first: a file's extension may be missing or wrong. The extension // then routes files whose content isn't recognised to the reader that explains why. - let ext = std::path::Path::new(path).extension().and_then(std::ffi::OsStr::to_str).unwrap_or_default().to_ascii_lowercase(); - let native = designcraft_format::is_designcraft(&bytes) || bytes.trim_ascii_start().starts_with(b"{"); - if designcraft_idml::is_idml(&bytes) || (!native && (crate::cmd::interchange::is_indd(path, &bytes) || ext == "idml")) { + let format = craft_file_formats::detect(path, &bytes); + let native = matches!( + craft_file_formats::detect("", &bytes), + Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson) + ); + let legacy = (format == Some(craft_file_formats::Format::Indd) && !native).then(|| load_bytes(&bytes).ok()).flatten(); + if format == Some(craft_file_formats::Format::Idml) || (!native && format == Some(craft_file_formats::Format::Indd) && legacy.is_none()) { return crate::cmd::interchange::open_idml(s, p); } - if !native && ext != designcraft_format::EXTENSION { + if !native && legacy.is_none() { return Err(bad("file.open", format!("{path}: not a DesignCraft or IDML file"))); } - let (mut d, mut warnings) = load_bytes(&bytes)?; + let (mut d, mut warnings) = match legacy { + Some(loaded) => loaded, + None => load_bytes(&bytes)?, + }; crate::cmd::interchange::resolve_packaged_links(&mut d, Some(std::path::Path::new(path))); crate::cmd::datamerge::resolve_sources_on_open(&mut d, Some(std::path::Path::new(path))); let (fonts, faces, font_warnings) = load_document_fonts(&mut d, path); @@ -156,10 +163,18 @@ pub(super) fn file_open_bytes(s: &mut Session, p: &Value) -> Result { let b = base64_decode(str_param(p, "base64").unwrap_or("")); // IDML packages are recognised by their stored `mimetype` first entry, INDD files by their // signature (or their name). - if designcraft_idml::is_idml(&b) || crate::cmd::interchange::is_indd(str_param(p, "name").unwrap_or_default(), &b) { + let name = str_param(p, "name").unwrap_or_default(); + let format = craft_file_formats::detect(name, &b); + let native = + matches!(craft_file_formats::detect("", &b), Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson)); + let legacy = (format == Some(craft_file_formats::Format::Indd) && !native).then(|| load_bytes(&b).ok()).flatten(); + if format == Some(craft_file_formats::Format::Idml) || (!native && format == Some(craft_file_formats::Format::Indd) && legacy.is_none()) { return crate::cmd::interchange::open_idml(s, p); } - let (mut d, warnings) = load_bytes(&b)?; + let (mut d, warnings) = match legacy { + Some(loaded) => loaded, + None => load_bytes(&b)?, + }; crate::cmd::datamerge::resolve_sources_on_open(&mut d, None); if let Some(n) = str_param(p, "name") { // Titled as an IDML file opened from bytes is: without its extension. @@ -507,7 +522,17 @@ mod open_bytes_tests { maker.execute("file.new", &json!({})).unwrap(); let idml = designcraft_idml::export_idml(&maker.doc().unwrap().doc); let base64 = super::super::bytes::base64_encode(&idml); - let legacy = super::super::bytes::base64_encode(&serde_json::to_vec(&maker.doc().unwrap().doc).unwrap()); + let legacy_bytes = serde_json::to_vec(&maker.doc().unwrap().doc).unwrap(); + let legacy = super::super::bytes::base64_encode(&legacy_bytes); + #[cfg(not(target_arch = "wasm32"))] + { + let legacy_path = std::env::temp_dir().join(format!("dc-legacy-indd-{}.indd", std::process::id())); + std::fs::write(&legacy_path, &legacy_bytes).unwrap(); + let mut by_path = Session::new(); + by_path.execute("file.open", &json!({"path": legacy_path})).unwrap(); + assert_eq!(by_path.documents().len(), 1, "legacy JSON must win over an InDesign extension"); + let _ = std::fs::remove_file(&legacy_path); + } for name in ["Brochure.indd", "Brochure.INDT"] { let mut s = Session::new(); s.execute("file.openBytes", &json!({"name": name, "base64": legacy})).unwrap(); diff --git a/crates/engine/src/cmd/file/place.rs b/crates/engine/src/cmd/file/place.rs index e0d285702..56f5b646f 100644 --- a/crates/engine/src/cmd/file/place.rs +++ b/crates/engine/src/cmd/file/place.rs @@ -32,9 +32,9 @@ pub(super) fn file_place(s: &mut Session, p: &Value) -> Result { return Err(bad("file.place", "the frame is locked")); } // A page of another layout (IDML or DesignCraft): its objects, as one group. - let lname = name.to_lowercase(); - if lname.ends_with(".idml") || lname.ends_with(".designcraft") { - return place_layout_page(s, p, &name, &bytes); + let format = craft_file_formats::detect(&name, &bytes); + if matches!(format, Some(craft_file_formats::Format::Idml | craft_file_formats::Format::DesignCraft)) { + return place_layout_page(s, p, &bytes, format); } // Keep the EPS source for link comparison; rendering uses its preview at the bounding box size. let eps_size = eps_size(&bytes, "file.place")?; @@ -57,11 +57,11 @@ pub(super) fn file_place(s: &mut Session, p: &Value) -> Result { }) .transpose()?; // Image Import Options: which page of a PDF (1-based). - if designcraft_render::is_pdf(&bytes) { + if format == Some(craft_file_formats::Format::Pdf) { designcraft_render::check_pdf_input_size(bytes.len()).map_err(|e| bad("file.place", e.to_string()))?; } let pdf_page = match p.get("pdfPage").and_then(Value::as_u64) { - Some(n) if designcraft_render::is_pdf(&bytes) => { + Some(n) if format == Some(craft_file_formats::Format::Pdf) => { let count = designcraft_render::pdf_page_count(&bytes).unwrap_or(1); let invalid_page = || bad("file.place", format!("the PDF has {count} page(s)")); let one_based = usize::try_from(n).map_err(|_| invalid_page())?; @@ -83,7 +83,7 @@ pub(super) fn file_place(s: &mut Session, p: &Value) -> Result { // and SVGs keep their exact size: rounding it to whole points would stretch them unevenly. let (nw, nh) = eps_size.or_else(|| designcraft_render::natural_size(&bytes, pdf_page as usize)).unwrap_or((pw as f64, ph as f64)); // Image Import Options › Crop to: the graphic spans that box of the PDF page. - let is_pdf = designcraft_render::is_pdf(&bytes); + let is_pdf = format == Some(craft_file_formats::Format::Pdf); let pdf_crop = match str_param(p, "pdfCrop") { Some(k) if is_pdf => PdfCrop::from_name(k) .ok_or_else(|| bad("file.place", format!("unknown pdfCrop `{k}` (crop, art, trim, bleed, media, contentVisible, contentAll)")))?, @@ -347,9 +347,9 @@ pub(super) fn place_drop(s: &mut Session, p: &Value) -> Result { /// File › Place of an IDML or DesignCraft document: the objects of one page (`layoutPage`, /// 1-based) grouped, top-left at x/y (default: the source position on the first page). -fn place_layout_page(s: &mut Session, p: &Value, name: &str, bytes: &[u8]) -> Result { +fn place_layout_page(s: &mut Session, p: &Value, bytes: &[u8], format: Option) -> Result { const ID: &str = "file.place"; - let src = if name.to_lowercase().ends_with(".idml") { + let src = if format == Some(craft_file_formats::Format::Idml) { crate::cmd::interchange::import_idml_confined(bytes, str_param(p, "path").map(std::path::Path::new)).map_err(|e| bad(ID, e.to_string()))? } else { from_bytes(bytes)? diff --git a/crates/engine/src/cmd/file/save.rs b/crates/engine/src/cmd/file/save.rs index d94a02ab9..d12bf03fa 100644 --- a/crates/engine/src/cmd/file/save.rs +++ b/crates/engine/src/cmd/file/save.rs @@ -89,11 +89,11 @@ pub(super) fn file_revert(s: &mut Session, _: &Value) -> Result { let path = s.doc()?.path.clone().ok_or_else(|| bad("file.revert", "the document has never been saved"))?; #[cfg(not(target_arch = "wasm32"))] { - let mut d = if path.to_ascii_lowercase().ends_with(".idml") { - let bytes = crate::io::read_file(&path).map_err(EngineError::Other)?; + let bytes = crate::io::read_file(&path).map_err(EngineError::Other)?; + let mut d = if craft_file_formats::detect(&path, &bytes) == Some(craft_file_formats::Format::Idml) { crate::cmd::interchange::import_idml_confined(&bytes, Some(std::path::Path::new(&path))).map_err(|e| EngineError::Other(e.to_string()))? } else { - from_bytes(&crate::io::read_file(&path).map_err(EngineError::Other)?)? + from_bytes(&bytes)? }; // As opened again: the fonts beside it now (unchanged files are shared, not read again). let (fonts, _, _) = load_document_fonts(&mut d, &path); diff --git a/crates/engine/src/cmd/interchange.rs b/crates/engine/src/cmd/interchange.rs index e84c28103..8387ff981 100644 --- a/crates/engine/src/cmd/interchange.rs +++ b/crates/engine/src/cmd/interchange.rs @@ -422,7 +422,7 @@ pub(crate) fn open_idml(s: &mut Session, p: &Value) -> Result { let mut previews = std::collections::HashMap::new(); let bytes = if is_indd(&file, &bytes) { // What the converter can't read still comes over as IDML (#21). - let conversion = indd::convert(&bytes, &file).map_err(|e| { + let conversion = craft_indd::convert(&bytes, &file).map_err(|e| { EngineError::Other(format!( "can't convert the InDesign file: {e}. In InDesign, choose File ▸ Export… ▸ InDesign Markup (IDML) and open the .idml in DesignCraft." )) @@ -474,19 +474,17 @@ fn warning_item( /// the bytes are neither a recognized DesignCraft document nor IDML. The converter explains /// unrecognized data with an InDesign extension. pub(crate) fn is_indd(name: &str, bytes: &[u8]) -> bool { - bytes.starts_with(&indd::header::SIGNATURE) - || (has_indd_extension(name) && !super::file::is_document(bytes) && !bytes.trim_ascii_start().starts_with(b"{")) -} - -pub(crate) fn has_indd_extension(name: &str) -> bool { - let n = name.to_ascii_lowercase(); - n.ends_with(".indd") || n.ends_with(".indt") + craft_file_formats::detect(name, bytes) == Some(craft_file_formats::Format::Indd) && !super::file::is_document(bytes) } /// `name` without a trailing .idml, .indd or .indt (any case). fn without_document_extension(name: &str) -> &str { match name.rsplit_once('.') { - Some((stem, ext)) if ["idml", "indd", "indt"].iter().any(|e| ext.eq_ignore_ascii_case(e)) => stem, + Some((stem, ext)) + if matches!(craft_file_formats::from_extension(ext), Some(craft_file_formats::Format::Idml | craft_file_formats::Format::Indd)) => + { + stem + } _ => name, } } @@ -687,7 +685,7 @@ mod tests { /// name) go to the converter, and what it can't read is an open error that adds no document. #[test] fn indd_files_go_through_the_converter_and_its_errors_are_open_errors() { - let mut signed = indd::header::SIGNATURE.to_vec(); + let mut signed = craft_indd::SIGNATURE.to_vec(); signed.resize(4096, 0); let cases = [(signed, "Brochure"), (vec![0; 4096], "Brochure.indd"), (b"not an InDesign file".to_vec(), "Template.INDT")]; let mut s = Session::new(); diff --git a/crates/engine/src/cmd/load_styles.rs b/crates/engine/src/cmd/load_styles.rs index 762f7b1fc..154306048 100644 --- a/crates/engine/src/cmd/load_styles.rs +++ b/crates/engine/src/cmd/load_styles.rs @@ -85,7 +85,7 @@ fn source(p: &Value, id: &str) -> Result { (Some(path), None) => (crate::io::read_file(path).map_err(|e| bad(id, e))?, path.to_string()), _ => return Err(bad(id, "give `path` or `base64`")), }; - if name.to_lowercase().ends_with(".idml") { + if craft_file_formats::detect(&name, &bytes) == Some(craft_file_formats::Format::Idml) { designcraft_idml::import_idml(&bytes).map_err(|e| bad(id, e.to_string())) } else { super::file::from_bytes(&bytes).map_err(|e| bad(id, e.to_string())) diff --git a/crates/engine/src/cmd/paste_svg.rs b/crates/engine/src/cmd/paste_svg.rs index fa3c1cffc..ea3013e2a 100644 --- a/crates/engine/src/cmd/paste_svg.rs +++ b/crates/engine/src/cmd/paste_svg.rs @@ -5,9 +5,9 @@ use std::collections::{HashMap, HashSet}; +use craft_svg::tree::document::{Document as SvgDocument, LineCap, LineJoin, Node as SvgNode, Paint as SvgPaint, Segment}; use designcraft_doc::{Content, Fill, Item, ItemId, Selection, Shape, Stroke, StrokeType}; use designcraft_geom::{Affine, BezPath, PathData, Point, Rect}; -use designcraft_images::usvg; use serde_json::{Value, json}; use super::{CommandSpec, Result, Session, bad, cmd, has_doc, spread_param, str_param}; @@ -29,7 +29,7 @@ pub fn is_svg_markup(text: &str) -> bool { designcraft_images::is_svg(text.as_bytes()) } -/// Cap conversion nesting too; the shared image parser bounds XML before usvg runs. +/// Cap conversion nesting too; the shared SVG scene builder enforces this limit. const MAX_DEPTH: usize = 64; /// A converted SVG node, in points. @@ -70,20 +70,15 @@ struct Notes { too_deep: bool, } -fn paint(p: &usvg::Paint, opacity: f32, notes: &mut Notes) -> Option { - let rgb = match p { - usvg::Paint::Color(c) => [c.red, c.green, c.blue], - // Gradients and patterns come in as their first colour (InDesign keeps Illustrator - // gradients; DesignCraft's swatch gradients can't be made from SVG stops yet). - usvg::Paint::LinearGradient(g) => { +fn paint(p: &SvgPaint, notes: &mut Notes) -> Option { + let (rgb, opacity) = match p { + SvgPaint::Color { rgb, opacity } => (*rgb, *opacity), + // Gradients and patterns are retained as their first color where available. + SvgPaint::Gradient { first_rgb, opacity } => { notes.gradients += 1; - g.stops().first().map(|s| [s.color().red, s.color().green, s.color().blue])? + (*first_rgb.as_ref()?, *opacity) } - usvg::Paint::RadialGradient(g) => { - notes.gradients += 1; - g.stops().first().map(|s| [s.color().red, s.color().green, s.color().blue])? - } - usvg::Paint::Pattern(_) => { + SvgPaint::Pattern => { notes.gradients += 1; return None; } @@ -96,56 +91,43 @@ fn round(v: f64) -> f64 { (v * 10_000.0).round() / 10_000.0 } -/// `t` (SVG px space) then px → pt. -fn to_affine(t: usvg::Transform) -> Affine { - let pt = designcraft_images::PT_PER_PX; - Affine::scale(pt) * Affine::new([f64::from(t.sx), f64::from(t.ky), f64::from(t.kx), f64::from(t.sy), f64::from(t.tx), f64::from(t.ty)]) -} - -fn bezpath(data: &usvg::tiny_skia_path::Path, xf: Affine) -> BezPath { - use usvg::tiny_skia_path::PathSegment as S; - let p = |q: usvg::tiny_skia_path::Point| xf * Point::new(f64::from(q.x), f64::from(q.y)); +fn bezpath(segments: &[Segment]) -> BezPath { + let p = |q: [f64; 2]| Point::new(q[0] * designcraft_images::PT_PER_PX, q[1] * designcraft_images::PT_PER_PX); let mut bp = BezPath::new(); - for seg in data.segments() { + for seg in segments { match seg { - S::MoveTo(a) => bp.move_to(p(a)), - S::LineTo(a) => bp.line_to(p(a)), - S::QuadTo(a, b) => bp.quad_to(p(a), p(b)), - S::CubicTo(a, b, c) => bp.curve_to(p(a), p(b), p(c)), - S::Close => bp.close_path(), + Segment::MoveTo(a) => bp.move_to(p(*a)), + Segment::LineTo(a) => bp.line_to(p(*a)), + Segment::QuadTo(a, b) => bp.quad_to(p(*a), p(*b)), + Segment::CubicTo(a, b, c) => bp.curve_to(p(*a), p(*b), p(*c)), + Segment::Close => bp.close_path(), } } bp } -fn convert(g: &usvg::Group, depth: usize, notes: &mut Notes, out: &mut Vec) { - for node in g.children() { +fn convert(nodes: &[SvgNode], notes: &mut Notes, out: &mut Vec) { + for node in nodes { match node { - usvg::Node::Path(path) => { - if !path.is_visible() || path.data().is_empty() { - continue; - } - let xf = to_affine(path.abs_transform()); - let fill = path.fill().and_then(|f| paint(f.paint(), f.opacity().get(), notes)); - let stroke = path.stroke().and_then(|s| { - let c = paint(s.paint(), s.opacity().get(), notes)?; - // A stroke scales with the art: its width in points. - let scale = xf.determinant().abs().sqrt(); - let width = round(f64::from(s.width().get()) * scale); - let dashes = s.dasharray().map(|d| d.iter().map(|v| round(f64::from(*v) * scale)).collect::>()); + SvgNode::Path(path) => { + let fill = path.fill.as_ref().and_then(|p| paint(p, notes)); + let stroke = path.stroke.as_ref().and_then(|s| { + let c = paint(&s.paint, notes)?; + let width = round(s.width * designcraft_images::PT_PER_PX); + let dashes = s.dash_array.as_ref().map(|d| d.iter().map(|v| round(v * designcraft_images::PT_PER_PX)).collect::>()); let style = StrokeStyle { width, - cap: match s.linecap() { - usvg::LineCap::Butt => designcraft_doc::Cap::Butt, - usvg::LineCap::Round => designcraft_doc::Cap::Round, - usvg::LineCap::Square => designcraft_doc::Cap::Projecting, + cap: match s.cap { + LineCap::Butt => designcraft_doc::Cap::Butt, + LineCap::Round => designcraft_doc::Cap::Round, + LineCap::Square => designcraft_doc::Cap::Projecting, }, - join: match s.linejoin() { - usvg::LineJoin::Round => designcraft_doc::Join::Round, - usvg::LineJoin::Bevel => designcraft_doc::Join::Bevel, + join: match s.join { + LineJoin::Round => designcraft_doc::Join::Round, + LineJoin::Bevel => designcraft_doc::Join::Bevel, _ => designcraft_doc::Join::Miter, }, - miter: f64::from(s.miterlimit().get()), + miter: s.miter_limit, dashes, }; Some((c, style)) @@ -158,38 +140,22 @@ fn convert(g: &usvg::Group, depth: usize, notes: &mut Notes, out: &mut Vec) { notes.mixed_opacity += 1; } - out.push(Art::Path { path: bezpath(path.data(), xf), fill, stroke, opacity: 1.0 }); + out.push(Art::Path { path: bezpath(&path.segments), fill, stroke, opacity: 1.0 }); } - usvg::Node::Group(child) => { - if depth >= MAX_DEPTH { - notes.too_deep = true; - continue; - } + SvgNode::Group { children, opacity } => { let mut items = Vec::new(); - convert(child, depth + 1, notes, &mut items); + convert(children, notes, &mut items); // usvg wraps nodes in groups for transforms and opacity; only a group of several // objects stays a group. Its opacity goes to what it holds. - let opacity = child.opacity().get(); if items.len() > 1 { - out.push(Art::Group(items, opacity)); + out.push(Art::Group(items, *opacity)); } else { for mut a in items { - a.fade(opacity); + a.fade(*opacity); out.push(a); } } } - // Text arrives as outlines, as Illustrator's Create Outlines would give it. - usvg::Node::Text(text) => { - let mut items = Vec::new(); - convert(text.flattened(), depth + 1, notes, &mut items); - if items.len() > 1 { - out.push(Art::Group(items, 1.0)); - } else { - out.extend(items); - } - } - usvg::Node::Image(_) => notes.images += 1, } } } @@ -312,9 +278,10 @@ fn paste_svg(s: &mut Session, p: &Value) -> Result { return Err(bad(ID, "the clipboard doesn't hold SVG markup")); } let tree = designcraft_images::svg_tree(svg.as_bytes()).ok_or_else(|| bad(ID, "the SVG on the clipboard can't be read"))?; - let mut notes = Notes::default(); + let scene = SvgDocument::from_tree(&tree, MAX_DEPTH); + let mut notes = Notes { images: scene.images, too_deep: scene.too_deep, ..Default::default() }; let mut art = Vec::new(); - convert(tree.root(), 0, &mut notes, &mut art); + convert(&scene.nodes, &mut notes, &mut art); let b = bounds(&art).ok_or_else(|| bad(ID, "the SVG on the clipboard has no paths to paste"))?; let sr = spread_param(p, ID)?; let layer = s.doc()?.active_layer; diff --git a/crates/engine/src/cmd/xml.rs b/crates/engine/src/cmd/xml.rs index 949d96436..31010dae3 100644 --- a/crates/engine/src/cmd/xml.rs +++ b/crates/engine/src/cmd/xml.rs @@ -136,61 +136,38 @@ struct Element { } fn parse(xml: &str) -> std::result::Result, String> { - use quick_xml::events::Event; - let mut r = quick_xml::Reader::from_str(xml); - let mut depth = 0usize; - let mut out: Vec = Vec::new(); - let mut child: Option<(String, String)> = None; - loop { - match r.read_event().map_err(|e| e.to_string())? { - Event::Start(e) => { - depth += 1; - let name = String::from_utf8_lossy(e.local_name().as_ref()).to_string(); - match depth { - 2 => out.push(Element { name, text: String::new(), children: vec![] }), - 3 => child = Some((name, String::new())), - _ => {} - } + fn descendant_text(element: &craft_xml::El, into: &mut String) { + for node in &element.children { + match node { + craft_xml::Node::Text(text) | craft_xml::Node::CData(text) => into.push_str(text), + craft_xml::Node::El(child) => descendant_text(child, into), + craft_xml::Node::Pi { .. } | craft_xml::Node::Comment(_) => {} } - Event::Empty(e) if depth == 1 => { - out.push(Element { name: String::from_utf8_lossy(e.local_name().as_ref()).to_string(), text: String::new(), children: vec![] }); - } - ev @ (Event::Text(_) | Event::GeneralRef(_) | Event::CData(_)) => { - let s = match ev { - Event::Text(t) => t.decode().map_err(|e| e.to_string())?.to_string(), - Event::CData(t) => String::from_utf8_lossy(&t).to_string(), - Event::GeneralRef(g) => match g.resolve_char_ref().map_err(|e| e.to_string())? { - Some(c) => c.to_string(), - None => match g.decode().map_err(|e| e.to_string())?.as_ref() { - "amp" => "&".into(), - "lt" => "<".into(), - "gt" => ">".into(), - "quot" => "\"".into(), - "apos" => "'".into(), - _ => String::new(), - }, - }, - _ => String::new(), - }; - match (depth, child.as_mut(), out.last_mut()) { - (3.., Some(c), _) => c.1.push_str(&s), - (2, _, Some(el)) => el.text.push_str(&s), - _ => {} - } - } - Event::End(_) => { - if depth == 3 - && let (Some(c), Some(el)) = (child.take(), out.last_mut()) - { - el.children.push(c); - } - depth = depth.saturating_sub(1); - } - Event::Eof => break, - _ => {} } } - Ok(out) + + let mut options = craft_xml::Options::local(); + options.strict = true; + let root = options.parse(xml.as_bytes()).map_err(|e| e.to_string())?; + root.elements() + .map(|element| { + let mut children = Vec::new(); + for child in element.elements() { + let mut text = String::new(); + descendant_text(child, &mut text); + children.push((child.name.clone(), text)); + } + let mut text = String::new(); + for node in &element.children { + match node { + craft_xml::Node::Text(value) | craft_xml::Node::CData(value) => text.push_str(value), + craft_xml::Node::Pi { .. } | craft_xml::Node::Comment(_) => {} + craft_xml::Node::El(_) => {} + } + } + Ok(Element { name: element.name.clone(), text, children }) + }) + .collect() } pub fn specs() -> Vec { diff --git a/crates/engine/src/dtd.rs b/crates/engine/src/dtd.rs index c0d45d820..6eda1fff5 100644 --- a/crates/engine/src/dtd.rs +++ b/crates/engine/src/dtd.rs @@ -1,862 +1,3 @@ -//! Document Type Definitions: element declarations (content models) and required attributes, and -//! validation of an XML document against them (Structure ▸ Validate). +//! XML DTD command adapter backed by craft-xml. -use std::collections::HashMap; - -/// How much text parameter entities may add during expansion (a pass count is not an output -/// bound: each pass replaces whole strings, so references can inflate multiplicatively). -const MAX_EXPANDED_BYTES: usize = 1024 * 1024; - -/// A content particle: a name, a sequence, a choice, or one of those repeated (`?`, `*`, `+`). -#[derive(Clone, Debug, PartialEq)] -enum Cp { - Name(String), - Seq(Vec), - Choice(Vec), - Rep(Box, char), -} - -#[derive(Clone, Debug, PartialEq)] -enum Model { - Empty, - Any, - /// `(#PCDATA | a | b)*`: text and these elements in any order. - Mixed(Vec), - Children(Cp), -} - -/// A parsed DTD. -#[derive(Clone, Debug, Default)] -pub struct Dtd { - elements: Vec<(String, Model)>, - /// Each declared name's first declaration (which wins), by name. - index: HashMap, - /// Element → its `#REQUIRED` attributes. - required: HashMap>, -} - -/// A problem found by validation: where (an element path such as `Root/story[2]`) and what. -#[derive(Clone, Debug, PartialEq, serde::Serialize)] -pub struct Problem { - pub path: String, - pub message: String, -} - -impl Dtd { - /// Declared element names, in order. - pub fn element_names(&self) -> impl Iterator { - self.elements.iter().map(|(n, _)| n.as_str()) - } - - fn model(&self, name: &str) -> Option<&Model> { - self.elements.get(*self.index.get(name)?).map(|(_, m)| m) - } -} - -/// Markup declarations (``) with comments removed and quoted strings kept whole. -fn declarations(src: &str) -> Vec { - let mut out = Vec::new(); - let mut rest = src; - while let Some(i) = rest.find("").map_or("", |j| &rest[j + 3..]); - continue; - } - let mut quote = None; - let mut end = rest.len(); - for (k, c) in rest.char_indices().skip(2) { - match (quote, c) { - (Some(q), c) if c == q => quote = None, - (None, '"' | '\'') => quote = Some(c), - (None, '>') => { - end = k; - break; - } - _ => {} - } - } - out.push(rest[2..end].to_string()); - rest = rest.get(end + 1..).unwrap_or(""); - } - out -} - -fn tokens(s: &str) -> Vec { - let mut out = Vec::new(); - let mut cur = String::new(); - for c in s.chars() { - if c.is_whitespace() || "(),|?*+".contains(c) { - if !cur.is_empty() { - out.push(std::mem::take(&mut cur)); - } - if !c.is_whitespace() { - out.push(c.to_string()); - } - } else { - cur.push(c); - } - } - if !cur.is_empty() { - out.push(cur); - } - out -} - -/// How deeply groups may nest in a content model; parsing, matching (`ends`) and printing (`show`) -/// recurse once per level. -const MAX_CONTENT_MODEL_DEPTH: usize = 64; - -/// Parse a content particle from `t[*i..]`, inside `depth` enclosing groups. -fn particle(t: &[String], i: &mut usize, depth: usize) -> Result { - let base = match t.get(*i).map(String::as_str) { - Some("(") => { - if depth >= MAX_CONTENT_MODEL_DEPTH { - return Err(format!("content model nested more than {MAX_CONTENT_MODEL_DEPTH} levels")); - } - *i += 1; - let mut items = vec![particle(t, i, depth + 1)?]; - let mut sep = None; - loop { - match t.get(*i).map(String::as_str) { - Some(")") => { - *i += 1; - break; - } - Some(s @ ("," | "|")) => { - if sep.is_some_and(|p| p != s) { - return Err("mixed `,` and `|` in one group".into()); - } - sep = Some(if s == "," { "," } else { "|" }); - *i += 1; - items.push(particle(t, i, depth + 1)?); - } - other => return Err(format!("unexpected `{}` in a content model", other.unwrap_or("end"))), - } - } - if sep == Some("|") { Cp::Choice(items) } else { Cp::Seq(items) } - } - Some(n) if !"),|?*+".contains(n) => { - *i += 1; - Cp::Name(n.to_string()) - } - other => return Err(format!("unexpected `{}` in a content model", other.unwrap_or("end"))), - }; - Ok(match t.get(*i).map(String::as_str) { - Some(r @ ("?" | "*" | "+")) => { - *i += 1; - Cp::Rep(Box::new(base), r.chars().next().unwrap_or('*')) - } - _ => base, - }) -} - -fn parse_model(s: &str) -> Result { - let s = s.trim(); - match s { - "EMPTY" => return Ok(Model::Empty), - "ANY" => return Ok(Model::Any), - _ => {} - } - if s.contains("#PCDATA") { - let t = tokens(&s.replace("#PCDATA", " #PCDATA ")); - return Ok(Model::Mixed(t.into_iter().filter(|x| !"()|*".contains(x.as_str()) && x != "#PCDATA").collect())); - } - let t = tokens(s); - let mut i = 0; - let cp = particle(&t, &mut i, 0)?; - if i != t.len() { - return Err(format!("unexpected `{}` after the content model", t[i])); - } - Ok(Model::Children(cp)) -} - -/// How deeply parameter entities may nest: a reference in the DTD is level 1, a reference in its -/// value level 2, and so on. -const MAX_PARAMETER_ENTITY_DEPTH: usize = 64; - -/// Expand `%name;` references, one level per round, until a round changes nothing. -fn expand_parameter_entities(src: &str, ents: &[(String, String)]) -> Result { - let mut entities = HashMap::new(); - for (name, value) in ents { - entities.entry(name.as_str()).or_insert(value.as_str()); - } - let limit = src.len().saturating_add(MAX_EXPANDED_BYTES); - let append = |out: &mut String, value: &str| -> Result<(), String> { - if value.len() > limit.saturating_sub(out.len()) { - return Err(format!("parameter entities expand the DTD beyond {limit} bytes")); - } - out.push_str(value); - Ok(()) - }; - let too_deep = || format!("parameter entities refer to themselves or nest deeper than {MAX_PARAMETER_ENTITY_DEPTH} levels"); - let mut text = src.to_string(); - // The round after the deepest level changes nothing, hence one more round than levels. - for _ in 0..=MAX_PARAMETER_ENTITY_DEPTH { - let mut out = String::with_capacity(text.len()); - let mut rest = text.as_str(); - let mut changed = false; - while let Some(i) = rest.find('%') { - let (prefix, reference) = rest.split_at(i); - append(&mut out, prefix)?; - // `find` points to an ASCII `%`, so both split positions are UTF-8 boundaries. - rest = reference.split_at(1).1; - // A name has no whitespace and no `%` (`parse` ends a name at whitespace), whatever its - // length: the search for the closing `;` stops at the first of those, so the searches of - // a round never overlap and a round stays linear in the text. - let end = - rest.bytes().position(|b| matches!(b, b';' | b'%') || b.is_ascii_whitespace()).filter(|&k| rest.as_bytes().get(k) == Some(&b';')); - if let Some(end) = end - && let Some(value) = rest.get(..end).and_then(|name| entities.get(name)) - { - // A value that is its own reference (``) never gets anywhere. - if reference.get(..end + 2) == Some(*value) { - return Err(too_deep()); - } - append(&mut out, value)?; - changed = true; - rest = rest.split_at(end + 1).1; - continue; - } - append(&mut out, "%")?; - } - append(&mut out, rest)?; - text = out; - if !changed { - return Ok(text); - } - } - Err(too_deep()) -} - -/// Parse a DTD (its element and attribute-list declarations; parameter entities are expanded). -pub fn parse(src: &str) -> Result { - // Parameter entities first, then expand references and read the declarations again. - let mut ents: Vec<(String, String)> = Vec::new(); - for d in declarations(src) { - if let Some(rest) = d.strip_prefix("ENTITY") { - let rest = rest.trim_start(); - if let Some(rest) = rest.strip_prefix('%') { - let rest = rest.trim_start(); - let name: String = rest.chars().take_while(|c| !c.is_whitespace()).collect(); - let val = rest[name.len()..].trim(); - let q = val.chars().next().unwrap_or('"'); - if let Some(v) = val.strip_prefix(q).and_then(|v| v.find(q).map(|e| &v[..e])) { - ents.push((name, v.to_string())); - } - } - } - } - let text = expand_parameter_entities(src, &ents)?; - let mut dtd = Dtd::default(); - for d in declarations(&text) { - if let Some(rest) = d.strip_prefix("ELEMENT") { - let rest = rest.trim_start(); - let name: String = rest.chars().take_while(|c| !c.is_whitespace()).collect(); - let model = parse_model(&rest[name.len()..]).map_err(|e| format!(": {e}"))?; - dtd.index.entry(name.clone()).or_insert(dtd.elements.len()); - dtd.elements.push((name, model)); - } else if let Some(rest) = d.strip_prefix("ATTLIST") { - // name (attr type default)*; only `#REQUIRED` matters here. - let mut words = Vec::new(); - let mut cur = String::new(); - let mut quote = None; - let mut group = 0; - for c in rest.chars() { - match (quote, c) { - (Some(q), c) if c == q => { - quote = None; - cur.push(c); - } - (Some(_), c) => cur.push(c), - (None, '"' | '\'') => { - quote = Some(c); - cur.push(c); - } - (None, '(') => { - group += 1; - cur.push(c); - } - (None, ')') => { - group -= 1; - cur.push(c); - } - (None, c) if c.is_whitespace() && group == 0 => { - if !cur.is_empty() { - words.push(std::mem::take(&mut cur)); - } - } - (None, c) => cur.push(c), - } - } - if !cur.is_empty() { - words.push(cur); - } - let Some((el, attrs)) = words.split_first() else { continue }; - let mut k = 0; - while k + 2 < attrs.len() { - let name = &attrs[k]; - let default = attrs.get(k + 2).map(String::as_str).unwrap_or(""); - if default == "#REQUIRED" { - dtd.required.entry(el.clone()).or_default().push(name.clone()); - } - k += if default == "#FIXED" { 4 } else { 3 }; - } - } - } - if dtd.elements.is_empty() { - return Err("no element declarations".into()); - } - Ok(dtd) -} - -/// What `ends` has worked out for one sequence of children: the end positions of a group (by the -/// address of its node, which lives as long as the model) from a position. -struct EndsMemo { - map: HashMap<(usize, usize), Vec>, - /// Matching steps left (shared by a whole validation); at zero `ends` stops and `over` is set. - left: usize, - /// End positions held in `map`; past [`MAX_STORED_ENDS`] results are no longer kept. - stored: usize, - over: bool, -} - -/// Matching steps one validation may take across all its elements (a step is a position handled or -/// compared). Valid documents with thousands of children per element use a small fraction. -const MAX_MATCH_STEPS: usize = 8 * 1024 * 1024; -/// End positions the memo may hold at once (8 bytes each). -const MAX_STORED_ENDS: usize = 4 * 1024 * 1024; -/// Element nesting depth: `check` recurses and keeps each level's full path. -const MAX_XML_DEPTH: usize = 256; -/// Elements in the document being validated. -const MAX_XML_NODES: usize = 4 * 1024 * 1024; -/// Problems reported before the list stops. -const MAX_PROBLEMS: usize = 10_000; - -impl EndsMemo { - /// Spend `n` steps; false once the budget is gone. - fn spend(&mut self, n: usize) -> bool { - if self.over || n > self.left { - self.left = 0; - self.over = true; - return false; - } - self.left -= n; - true - } -} - -/// End positions after `cp` matches a prefix of `seq[i..]`. -/// -/// The positions of each group are worked out once per start position (`memo`): nested repetitions -/// such as `((a*)*)*` ask the inner group for the same positions again and again, which is -/// exponential in their depth without it. -fn ends(cp: &Cp, seq: &[&str], i: usize, memo: &mut EndsMemo) -> Vec { - if let Cp::Name(n) = cp { - return if seq.get(i) == Some(&n.as_str()) { vec![i + 1] } else { vec![] }; - } - let key = (std::ptr::from_ref(cp) as usize, i); - if let Some(done) = memo.map.get(&key) { - // Charged before the clone, and a failed charge ends the match. - let len = done.len(); - if !memo.spend(len) { - return vec![]; - } - return memo.map.get(&key).cloned().unwrap_or_default(); - } - if !memo.spend(1) { - return vec![]; - } - let mut out: Vec = match cp { - Cp::Name(_) => vec![], - // Keep the positions after each item a set: as a list of every path, `(a?, a?, …)` doubles per item. - Cp::Seq(items) => { - let mut at = vec![i]; - for c in items { - let mut next = Vec::new(); - for p in at { - next.extend(ends(c, seq, p, memo)); - } - if !memo.spend(next.len()) { - return vec![]; - } - next.sort_unstable(); - next.dedup(); - at = next; - } - at - } - Cp::Choice(items) => { - let mut all = Vec::new(); - for c in items { - all.extend(ends(c, seq, i, memo)); - } - all - } - Cp::Rep(c, r) => { - let mut all = if *r == '+' { vec![] } else { vec![i] }; - // `all` as a set too: a list search per position made long repeats quadratic. - let mut have: std::collections::HashSet = all.iter().copied().collect(); - let mut frontier = ends(c, seq, i, memo); - if *r == '?' { - all.extend(frontier); - } else { - while !frontier.is_empty() { - if !memo.spend(frontier.len()) { - break; - } - let new: Vec = frontier.iter().copied().filter(|p| have.insert(*p)).collect(); - all.extend(&new); - let mut next = Vec::new(); - for p in new.into_iter().filter(|&p| p > i) { - next.extend(ends(c, seq, p, memo).into_iter().filter(|p| !have.contains(p))); - } - // Two paths to one position are one position: kept apart they multiply per round. - next.sort_unstable(); - next.dedup(); - frontier = next; - } - } - all - } - }; - out.sort_unstable(); - out.dedup(); - if !memo.over && memo.stored + out.len() <= MAX_STORED_ENDS { - memo.stored += out.len(); - memo.map.insert(key, out.clone()); - } - out -} - -fn show(cp: &Cp) -> String { - match cp { - Cp::Name(n) => n.clone(), - Cp::Seq(v) => format!("({})", v.iter().map(show).collect::>().join(", ")), - Cp::Choice(v) => format!("({})", v.iter().map(show).collect::>().join(" | ")), - Cp::Rep(c, r) => format!("{}{r}", show(c)), - } -} - -/// An element of the document being validated. -struct Node { - name: String, - attrs: Vec, - children: Vec, - text: bool, -} - -fn read_tree(xml: &str) -> Result { - use quick_xml::events::Event; - let mut r = quick_xml::Reader::from_str(xml); - let mut stack: Vec = Vec::new(); - let mut count = 0usize; - let node = |e: &quick_xml::events::BytesStart| Node { - name: String::from_utf8_lossy(e.name().as_ref()).to_string(), - attrs: e.attributes().flatten().map(|a| String::from_utf8_lossy(a.key.as_ref()).to_string()).collect(), - children: vec![], - text: false, - }; - loop { - let event = r.read_event().map_err(|e| e.to_string())?; - if matches!(event, Event::Start(_) | Event::Empty(_)) { - count += 1; - if count > MAX_XML_NODES { - return Err(format!("more than {MAX_XML_NODES} elements")); - } - } - match event { - Event::Start(e) => { - if stack.len() >= MAX_XML_DEPTH { - return Err(format!("elements nested more than {MAX_XML_DEPTH} deep")); - } - stack.push(node(&e)); - } - Event::Empty(e) => { - let n = node(&e); - match stack.last_mut() { - Some(p) => p.children.push(n), - None => return Ok(n), - } - } - Event::End(_) => { - let n = stack.pop().ok_or("unbalanced end tag")?; - match stack.last_mut() { - Some(p) => p.children.push(n), - None => return Ok(n), - } - } - Event::Text(t) => { - if let Some(p) = stack.last_mut() - && !t.iter().all(u8::is_ascii_whitespace) - { - p.text = true; - } - } - Event::CData(_) | Event::GeneralRef(_) => { - if let Some(p) = stack.last_mut() { - p.text = true; - } - } - Event::Eof => return Err("no root element".into()), - _ => {} - } - } -} - -fn check(dtd: &Dtd, n: &Node, path: &str, out: &mut Vec, steps: &mut usize) { - if out.len() >= MAX_PROBLEMS { - return; - } - let mut problem = |m: String| { - if out.len() < MAX_PROBLEMS { - out.push(Problem { path: path.to_string(), message: m }); - } - }; - match dtd.model(&n.name) { - None => problem(format!("`{}` isn't declared in the DTD", n.name)), - Some(Model::Any) => {} - Some(Model::Empty) => { - if n.text || !n.children.is_empty() { - problem(format!("`{}` should be empty", n.name)); - } - } - Some(Model::Mixed(allowed)) => { - for c in &n.children { - if !allowed.contains(&c.name) { - problem(format!("`{}` isn't allowed in `{}`", c.name, n.name)); - } - } - } - Some(Model::Children(cp)) => { - if n.text { - problem(format!("`{}` can't contain text", n.name)); - } - let seq: Vec<&str> = n.children.iter().map(|c| c.name.as_str()).collect(); - let mut memo = EndsMemo { map: HashMap::new(), left: *steps, stored: 0, over: false }; - let matched = ends(cp, &seq, 0, &mut memo).contains(&seq.len()); - *steps = memo.left; - if memo.over { - problem(format!("`{}` has too many children to check against its content model", n.name)); - } else if !matched { - let got = if seq.is_empty() { "nothing".to_string() } else { seq.join(", ") }; - problem(format!("`{}` contains {got}; the DTD asks for {}", n.name, show(cp))); - } - } - } - for a in dtd.required.get(&n.name).into_iter().flatten() { - if !n.attrs.contains(a) { - problem(format!("`{}` is missing the required attribute `{a}`", n.name)); - } - } - let mut seen: HashMap<&str, usize> = HashMap::new(); - for c in &n.children { - let k = seen.entry(c.name.as_str()).or_default(); - *k += 1; - check(dtd, c, &format!("{path}/{}[{k}]", c.name), out, steps); - } -} - -/// Validate `xml` against `dtd`; an empty list when it's valid. -pub fn validate(dtd: &Dtd, xml: &str) -> Vec { - match read_tree(xml) { - Ok(root) => { - let mut out = Vec::new(); - let path = root.name.clone(); - check(dtd, &root, &path, &mut out, &mut { MAX_MATCH_STEPS }); - if out.len() >= MAX_PROBLEMS { - out.push(Problem { path: String::new(), message: "further problems are not listed".into() }); - } - out - } - Err(e) => vec![Problem { path: String::new(), message: format!("not well-formed XML: {e}") }], - } -} - -#[cfg(test)] -mod tests { - use super::*; - - const DTD: &str = r##" - - - - - - - - - - b" kind (photo|chart) "photo">"##; - - #[test] - fn content_models_and_required_attributes() { - let dtd = parse(DTD).unwrap(); - assert_eq!(dtd.element_names().count(), 8); - let ok = r#"T <em>x</em>ab
"#; - assert_eq!(validate(&dtd, ok), vec![]); - let bad = r#"no title
x