Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into feat/cjk-and-fonts

Brandon Thomasaee756d6047b
diff --cc crates/engine/src/cmd/interchange.rs
index 6d16417f8,64f995909..030cf1b6c
--- a/crates/engine/src/cmd/interchange.rs
+++ b/crates/engine/src/cmd/interchange.rs
@@@ -71,13 -115,62 +115,68 @@@ pub(crate) fn open_idml(s: &mut Session
if let Some(n) = name {
d.title = n;
}
+ let (fonts, faces, warnings) = match str_param(p, "path").filter(|_| str_param(p, "base64").is_none()) {
+ Some(path) => super::file::load_document_fonts(&mut d, path),
+ None => (None, 0, Vec::new()),
+ };
// Never save over the .idml with the native format: the document starts unsaved.
- let i = s.add_document(DocState::new(d, None));
- Ok(json!({"index": i}))
+ let mut st = DocState::new(d, None);
+ st.fonts = fonts;
+ let i = s.add_document(st);
+ Ok(json!({"index": i, "documentFonts": faces, "warnings": warnings}))
}
+
+ #[cfg(all(test, not(target_arch = "wasm32")))]
+ mod tests {
+ use std::sync::Arc;
+
+ use super::*;
+
+ fn linked_idml(link: &str) -> Result<(Vec<u8>, Vec<u8>)> {
+ let png = designcraft_render::Rendered { width: 2, height: 2, pixels: vec![255; 16] }.to_png();
+ let mut session = Session::new();
+ session.execute("file.new", &json!({}))?;
+ session.execute("file.place", &json!({"base64": base64_encode(&png), "name": "logo.png"}))?;
+ session.edit(|doc, _| {
+ let asset = doc.assets.values_mut().next().ok_or_else(|| bad("fixture", "missing graphic"))?;
+ Arc::make_mut(asset).link = Some(link.into());
+ Ok(Value::Null)
+ })?;
+ let bytes = designcraft_idml::export_idml_with(&session.doc()?.doc, &designcraft_idml::ExportOptions { embed_images: false });
+ Ok((bytes, png))
+ }
+
+ #[test]
+ fn opens_nested_packaged_links_from_a_different_computer() {
+ let dir = std::env::temp_dir().join(format!("dc-idml-nested-links-{}", std::process::id()));
+ let path = dir.join("Links").join("illustrations").join("logo.png");
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
+ let (idml, png) = linked_idml("C:\\original-computer\\project\\Links\\illustrations\\logo.png").unwrap();
+ std::fs::write(&path, &png).unwrap();
+ std::fs::write(dir.join("logo.png"), b"a different file with the same basename").unwrap();
+
+ let doc = import(&idml, Some(&dir)).unwrap();
+ let asset = doc.assets.values().next().unwrap();
+ assert_eq!(*asset.data, png, "the packaged graphic must render even when its author-machine path no longer exists");
+ let resolved = std::path::absolute(&path).unwrap();
+ assert_eq!(asset.link.as_deref(), resolved.to_str(), "remember the resolved link so update and preflight use the packaged file");
+ assert_eq!(super::super::links::status(asset), "ok");
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[test]
+ fn remembers_flat_packaged_link_location() {
+ let dir = std::env::temp_dir().join(format!("dc-idml-flat-links-{}", std::process::id()));
+ let path = dir.join("Links").join("logo.png");
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
+ let (idml, png) = linked_idml("/original-computer/project/logo.png").unwrap();
+ std::fs::write(&path, &png).unwrap();
+
+ let doc = import(&idml, Some(&dir)).unwrap();
+ let asset = doc.assets.values().next().unwrap();
+ assert_eq!(*asset.data, png);
+ assert_eq!(asset.link.as_deref(), std::path::absolute(&path).unwrap().to_str());
+ assert_eq!(super::super::links::status(asset), "ok");
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+ }
diff --cc crates/ui-egui/Cargo.toml
index 36767afbf,025d33fec..369b101b7
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@@ -29,4 -29,7 +29,8 @@@ log = { workspace = true
[dev-dependencies]
# Headless (offscreen wgpu) rendering of the whole window for UI screenshots: `examples/ui_shot.rs`.
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
+designcraft-fonts = { workspace = true, features = ["testing"] }
+
+ [build-dependencies]
+ serde_json = { workspace = true }
+ toml = "1"