mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-14 14:22:39 +00:00
Use shared format probes for document opens
This commit is contained in:
6 files changed
+55
-35
No files matched your search
Generated
+41
-17
@@ -1104,7 +1104,7 @@ name = "craft-document-bundle"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"craft-zip",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.1",
|
||||
@@ -1144,12 +1144,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b4ada28f1#b4ada28f19067d4693e902e0e5f32eb292241e3a"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
|
||||
[[package]]
|
||||
name = "craft-eps"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
|
||||
[[package]]
|
||||
name = "craft-epub"
|
||||
@@ -1157,17 +1157,21 @@ version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-zip",
|
||||
"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=b4ada28f1#b4ada28f19067d4693e902e0e5f32eb292241e3a"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
dependencies = [
|
||||
"craft-eps 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b4ada28f1)",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b4ada28f1)",
|
||||
"craft-eps 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1204,7 +1208,17 @@ version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-zip",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-idml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
@@ -1290,7 +1304,7 @@ version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-zip",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"log",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1362,9 +1376,9 @@ source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad605
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b4ada28f1#b4ada28f19067d4693e902e0e5f32eb292241e3a"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b4ada28f1)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"flate2",
|
||||
"kurbo",
|
||||
"roxmltree 0.21.2",
|
||||
@@ -1374,9 +1388,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-svg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309)",
|
||||
"flate2",
|
||||
"kurbo",
|
||||
"roxmltree 0.21.2",
|
||||
@@ -1479,7 +1493,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b4ada28f1#b4ada28f19067d4693e902e0e5f32eb292241e3a"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1488,7 +1502,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf#ba24fe2435adb3c81ad6057faf36365fbba736cf"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
@@ -1504,6 +1518,16 @@ dependencies = [
|
||||
"zip 9.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=fccc0082711b8ae4e19824dd20339a8473d47309#fccc0082711b8ae4e19824dd20339a8473d47309"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.3"
|
||||
@@ -1828,7 +1852,7 @@ dependencies = [
|
||||
name = "designcraft-idml"
|
||||
version = "0.20.1"
|
||||
dependencies = [
|
||||
"craft-idml",
|
||||
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"designcraft-color",
|
||||
"designcraft-compose",
|
||||
@@ -1944,7 +1968,7 @@ version = "0.20.1"
|
||||
dependencies = [
|
||||
"craft-docx",
|
||||
"craft-file-formats",
|
||||
"craft-idml",
|
||||
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba24fe2435adb3c81ad6057faf36365fbba736cf)",
|
||||
"craft-rtf",
|
||||
"craft-wordmodel",
|
||||
"craft-xlsx",
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ craft-docx = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe243
|
||||
craft-wordmodel = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "a47b78256c6acf3d7fdc4bc7cfbc25c373eac522", version = "=0.1.0" }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "a47b78256c6acf3d7fdc4bc7cfbc25c373eac522", version = "=0.1.0" }
|
||||
craft-file-formats = { git = "https://github.com/storytold/craft-libs", rev = "b4ada28f1", version = "=0.1.0" }
|
||||
craft-file-formats = { git = "https://github.com/storytold/craft-libs", rev = "fccc0082711b8ae4e19824dd20339a8473d47309", 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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -85,13 +85,8 @@ fn open_path(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// 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 format = craft_file_formats::detect(path, &bytes);
|
||||
let native = format == Some(craft_file_formats::Format::DesignCraft)
|
||||
|| designcraft_format::is_designcraft(&bytes)
|
||||
|| bytes.trim_ascii_start().starts_with(b"{");
|
||||
if format == Some(craft_file_formats::Format::Idml)
|
||||
|| designcraft_idml::is_idml(&bytes)
|
||||
|| (!native && format == Some(craft_file_formats::Format::Indd))
|
||||
{
|
||||
let native = matches!(format, Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson));
|
||||
if format == Some(craft_file_formats::Format::Idml) || (!native && format == Some(craft_file_formats::Format::Indd)) {
|
||||
return crate::cmd::interchange::open_idml(s, p);
|
||||
}
|
||||
if !native {
|
||||
@@ -163,11 +158,8 @@ pub(super) fn file_open_bytes(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// signature (or their name).
|
||||
let name = str_param(p, "name").unwrap_or_default();
|
||||
let format = craft_file_formats::detect(name, &b);
|
||||
let native = designcraft_format::is_designcraft(&b) || b.trim_ascii_start().starts_with(b"{");
|
||||
if format == Some(craft_file_formats::Format::Idml)
|
||||
|| designcraft_idml::is_idml(&b)
|
||||
|| (!native && format == Some(craft_file_formats::Format::Indd))
|
||||
{
|
||||
let native = matches!(format, Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson));
|
||||
if format == Some(craft_file_formats::Format::Idml) || (!native && format == Some(craft_file_formats::Format::Indd)) {
|
||||
return crate::cmd::interchange::open_idml(s, p);
|
||||
}
|
||||
let (mut d, warnings) = load_bytes(&b)?;
|
||||
|
||||
@@ -470,9 +470,7 @@ 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 {
|
||||
craft_file_formats::detect(name, bytes) == Some(craft_file_formats::Format::Indd)
|
||||
&& !super::file::is_document(bytes)
|
||||
&& !bytes.trim_ascii_start().starts_with(b"{")
|
||||
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).
|
||||
|
||||
@@ -138,7 +138,10 @@ impl DesignApp {
|
||||
return self.run("style.load", params);
|
||||
}
|
||||
let layout = opens_as_document(&file.name)
|
||||
|| (std::path::Path::new(&file.name).extension().is_none() && designcraft_engine::cmd::is_document(&file.bytes));
|
||||
|| matches!(
|
||||
format,
|
||||
Some(craft_file_formats::Format::DesignCraft | craft_file_formats::Format::DesignCraftJson | craft_file_formats::Format::Idml)
|
||||
);
|
||||
let place = file.request.purpose == "place"
|
||||
|| (matches!(file.request.purpose.as_str(), "drop" | "open") && !layout && format != Some(craft_file_formats::Format::Ase));
|
||||
if place || format == Some(craft_file_formats::Format::Ase) || file.request.purpose == "swatches" {
|
||||
|
||||
Reference in new issue
Block a user