Merge pull request #10877 from dotCooCoo/fix/dwt-dws-open

DWG: .dwt templates and .dws standards files open as DWG drawings
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-04 17:59:00 -08:00
commit 0fb3f00a4b
10 files changed
+171 -35

No files matched your search

+1 -1
View File
@@ -184,7 +184,7 @@ pub use formats::{
DOC_EXTS, DOCX_EXTS, FORMATS, Format, FormatOption, OPEN_EXTS, PLACE_EXTS, RTF_EXTS, TEXT_EXTS, UNASSOCIATED_EXTS, builtin_open_filters,
export_extensions, extension, file_stem, format, format_for_name, has_own_title, importer_formats, library_open_filters, open_extensions,
open_filters, opens_as_other, opens_with_importer, place_dialog_filters, place_filters, places_with_importer, plugin_formats, read_extensions,
readable_format, readable_format_for_name, titled_for_export, writable_format,
readable_format, readable_format_for_name, reads_as_dwg, titled_for_export, writable_format,
};
#[cfg(test)]
+6 -4
View File
@@ -113,14 +113,16 @@ pub fn unsupported(id_or_ext: &str) -> Option<&'static Unsupported> {
UNSUPPORTED.iter().find(|u| u.id == k || u.extensions.contains(&k.as_str()))
}
/// Formats VectorCraft opens but doesn't write, with what to export instead.
const READ_ONLY_HINTS: &[(&str, &str)] = &[("dwg", "DWG files open but can't be written: export DXF instead, which CAD apps open")];
/// Formats VectorCraft opens but doesn't write (by id or extension), with what to export instead.
const READ_ONLY_HINTS: &[(&[&str], &str)] =
&[(&["dwg", "dws", "dwt"], "DWG files open but can't be written: export DXF instead, which CAD apps open")];
/// What to write instead of the format an id or extension (any case, leading dot allowed) names,
/// when that format can't be written: an unsupported format's hint, or a read-only one's (DWG).
/// when that format can't be written: an unsupported format's hint, or a read-only one's (DWG,
/// also a `.dws` or `.dwt` file).
pub fn write_hint(id_or_ext: &str) -> Option<&'static str> {
let k = id_or_ext.trim_start_matches('.').to_ascii_lowercase();
unsupported(&k).map(|u| u.hint).or_else(|| READ_ONLY_HINTS.iter().find(|(id, _)| *id == k).map(|(_, hint)| *hint))
unsupported(&k).map(|u| u.hint).or_else(|| READ_ONLY_HINTS.iter().find(|(ids, _)| ids.contains(&k.as_str())).map(|(_, hint)| *hint))
}
impl Unsupported {
+17 -4
View File
@@ -577,10 +577,19 @@ pub const FORMATS: &[Format] = &[
// composite, the layers combined, or the preview with a note. Exports don't write them.
reader("pcraft", "PCRAFT", &["pcraft"], "application/x-pcraft", true),
// DWG drawings, converted to DXF by craft-dwg (`vectorcraft_cad::dwg`) and read by the DXF
// reader with the DXF import options. Exports don't write them.
reader("dwg", "DWG", &["dwg"], "image/vnd.dwg", false),
// reader with the DXF import options; `.dws` drawing standards files are DWG drawings too.
// Exports don't write them.
reader("dwg", "DWG", &["dwg", "dws"], "image/vnd.dwg", false),
// `.dwt` drawing templates, DWG drawings read as `dwg` is; a template opens as a new untitled
// document. Exports don't write them.
reader("dwt", "DWG Template", &["dwt"], "image/vnd.dwg", false),
];
/// Is `id` a format read as a DWG drawing: `dwg` (also `.dws` files) or a `dwt` template?
pub fn reads_as_dwg(id: &str) -> bool {
matches!(id, "dwg" | "dwt")
}
/// Every extension `document.open` reads (the "All readable files" filter of open dialogs).
pub const OPEN_EXTS: &[&str] = &[
"vectorcraft",
@@ -641,6 +650,8 @@ pub const OPEN_EXTS: &[&str] = &[
"cmx",
"pcraft",
"dwg",
"dws",
"dwt",
];
/// Extensions in [`OPEN_EXTS`] the packaging declares no type for: Photoshop documents belong to
@@ -649,10 +660,10 @@ pub const OPEN_EXTS: &[&str] = &[
/// PNG and BMP files (File › Open and Place still read them all). On Linux the desktop entry's EPS
/// type (shared-mime-info's) also covers `.epsf`, so file managers offer VectorCraft for it.
/// The packaging declares no type for HP-GL plot files, PICT pictures, layered raster `.pcraft`
/// documents or DWG drawings either.
/// documents or DWG drawings (`.dwg`, `.dws` and `.dwt`) either.
pub const UNASSOCIATED_EXTS: &[&str] = &[
"psd", "pdd", "psb", "epsf", "ps", "pns", "dib", "rle", "tga", "vda", "icb", "vst", "pcx", "pxr", "jpf", "jpx", "jp2", "j2k", "j2c", "jpc",
"heic", "heif", "jxl", "cdr", "cdt", "cmx", "plt", "hpgl", "hgl", "hpg", "pct", "pic", "pict", "pcraft", "dwg",
"heic", "heif", "jxl", "cdr", "cdt", "cmx", "plt", "hpgl", "hgl", "hpg", "pct", "pic", "pict", "pcraft", "dwg", "dws", "dwt",
];
/// The extension that picks each writable format when exporting (the format's first; PNG-8 shares
@@ -744,6 +755,8 @@ pub const PLACE_EXTS: &[&str] = &[
"cmx",
"pcraft",
"dwg",
"dws",
"dwt",
"txt",
"rtf",
"docx",
+14 -11
View File
@@ -47,12 +47,14 @@ impl Loaded {
/// PDF, an EPS or `.ai` without ruler units, a raster image, a metafile, an Affinity file or
/// what an importer plug-in reads, as the reference app opens such files (#5820). A native
/// document (also one that an SVG, PDF, `.ai` or EPS file carries, `restored`), an SVG (the
/// units of its root's size, pixels when it gives none), a DXF or DWG drawing (the unit it was
/// read in) and a `.ai` or EPS with ruler units keep theirs. Only the units the document shows
/// change, not its art.
/// units of its root's size, pixels when it gives none), a DXF or DWG drawing (also a DWG
/// template; the unit it was read in) and a `.ai` or EPS with ruler units keep theirs. Only the
/// units the document shows change, not its art.
pub(crate) fn with_unit_prefs(mut self, prefs: &Prefs) -> Self {
let records_units =
self.restored || self.doc.units_from_file || matches!(self.format.id, "vectorcraft" | "template" | "svg" | "svgz" | "dxf" | "dwg");
let records_units = self.restored
|| self.doc.units_from_file
|| matches!(self.format.id, "vectorcraft" | "template" | "svg" | "svgz" | "dxf")
|| super::reads_as_dwg(self.format.id);
if !records_units {
self.doc.units = crate::units::pref_unit(&prefs.units_general);
}
@@ -126,7 +128,8 @@ pub fn detect(name: &str, bytes: &[u8]) -> Option<&'static Format> {
return format("dxf");
}
if vectorcraft_cad::is_dwg(bytes) {
return format("dwg");
// A template keeps its meaning from the extension.
return by_name.filter(|f| f.id == "dwt").or_else(|| format("dwg"));
}
if let Some(kind) = vectorcraft_metafile::sniff(bytes) {
return format(kind.id());
@@ -563,8 +566,8 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
}
read
}
// A DWG drawing is read as the DXF craft-dwg converts it to.
"dxf" | "dwg" => {
// A DWG drawing (or template) is read as the DXF craft-dwg converts it to.
"dxf" | "dwg" | "dwt" => {
let (doc, warnings) = super::dxfimport::import(bytes, &opts.dxf)?;
(doc, warnings, false)
}
@@ -1021,9 +1024,9 @@ fn open_loaded(
.cloned()
.collect();
let source_path = path.clone().filter(|_| !losses.is_empty());
// A template (saved by Save as Template, or an .ait, .vctemplate or .cdt file) opens as a new
// untitled document.
let template = as_template || doc.template || matches!(format.id, "ait" | "template" | "cdt");
// A template (saved by Save as Template, or an .ait, .vctemplate, .cdt or .dwt file) opens as a
// new untitled document.
let template = as_template || doc.template || matches!(format.id, "ait" | "template" | "cdt" | "dwt");
if template {
doc.template = false;
doc.title = s.next_untitled();
@@ -140,3 +140,69 @@ fn dwg_is_read_only_and_detected_by_content() {
assert!(!r["writable"].as_array().unwrap().contains(&json!("dwg")));
assert!(r["unsupported"].as_array().unwrap().iter().all(|u| u["id"] != "dwg"));
}
/// A `.dwt` drawing template opens as a new untitled document and a `.dws` standards file as the
/// drawing it is, each read as a `.dwg` with the same content is; a DXF named `.dwt` stays a DXF.
#[test]
fn a_dwt_template_opens_untitled_and_a_dws_opens_as_its_drawing() {
let dir = std::env::temp_dir().join(format!("vc-dwt-open-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let dwg = plan_dwg();
let mut s = Session::new();
open(&mut s, "plan.dwg", &dwg, json!({})).unwrap();
let (want_layers, want_leaves) = (layer_names(&s), leaves(&s).len());
let template = dir.join("plan.dwt");
std::fs::write(&template, &dwg).unwrap();
let r = s.execute("document.open", &json!({"path": template.to_string_lossy()})).unwrap();
assert_eq!(r["format"], "dwt");
assert!(r["title"].as_str().is_some_and(|t| t.starts_with("Untitled")), "a template opens untitled: {}", r["title"]);
let st = s.doc().unwrap();
assert!(st.path.is_none());
assert_eq!(st.doc.units, vectorcraft_doc::Unit::Millimeters, "the drawing's unit");
assert_eq!((layer_names(&s), leaves(&s).len()), (want_layers.clone(), want_leaves));
let standards = dir.join("plan.dws");
std::fs::write(&standards, &dwg).unwrap();
let r = s.execute("document.open", &json!({"path": standards.to_string_lossy()})).unwrap();
assert_eq!((r["format"].as_str(), r["title"].as_str()), (Some("dwg"), Some("plan.dws")));
assert_eq!((layer_names(&s), leaves(&s).len()), (want_layers, want_leaves));
assert_eq!(detect("plan.dwt", &plan()).map(|f| f.id), Some("dxf"), "the content tells");
let _ = std::fs::remove_dir_all(&dir);
}
/// File › Place reads a `.dwt` or `.dws` drawing as it reads a `.dwg`: fitted to the artboard with
/// the same `dxf` options, in one undo step.
#[test]
fn a_dwt_or_dws_drawing_places_as_a_dwg_does() {
let dwg = plan_dwg();
let place = |name: &str| {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap();
let undo = s.doc().unwrap().history.undo.len();
let r = s.execute("file.place", &json!({"name": name, "dataBase64": b64(&dwg), "dxf": {"fit": true, "center": false}})).unwrap();
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "{name}: one undo step");
let id = vectorcraft_doc::NodeId(r["ids"][0].as_u64().unwrap());
let b = s.doc().unwrap().doc.node(id).unwrap().geometric_bounds().unwrap();
(r["format"].as_str().map(str::to_string), [b.x0, b.y0, b.x1, b.y1])
};
let (format, want) = place("plan.dwg");
assert_eq!(format.as_deref(), Some("dwg"));
assert_eq!(place("plan.dws"), (Some("dwg".to_string()), want));
assert_eq!(place("plan.dwt"), (Some("dwt".to_string()), want));
}
#[test]
fn dwt_and_dws_are_read_only_and_exporting_them_says_to_write_dxf() {
let f = format("dwt").unwrap();
assert!(f.read && !f.write);
assert_eq!(readable_format("dws").map(|f| f.id), Some("dwg"));
for ext in ["dws", "dwt"] {
assert!(OPEN_EXTS.contains(&ext) && PLACE_EXTS.contains(&ext) && UNASSOCIATED_EXTS.contains(&ext), "{ext}");
let mut s = Session::new();
s.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
let e = s.execute("document.export", &json!({"format": ext})).unwrap_err().to_string();
assert!(e.contains("export DXF instead"), "{ext}: {e}");
}
}
+2 -2
View File
@@ -357,7 +357,7 @@ fn load_into(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, slices_o
let (natural, warnings) = (s.frame, s.warnings.clone());
return Ok(Loaded { name, format, art: Art::Document(s, link.clone(), !crop), natural, warnings, link: Some(link), board: None });
}
let anchored = matches!(format.id, "dxf" | "dwg") && (opts.dxf.fit || !opts.dxf.center);
let anchored = (format.id == "dxf" || fileio::reads_as_dwg(format.id)) && (opts.dxf.fit || !opts.dxf.center);
let (mut doc, warnings) = {
// Of the open options, only a DXF or DWG drawing's apply (the colour mode stays the file's).
let o = fileio::LoadOptions { dxf: opts.dxf, ..Default::default() };
@@ -380,7 +380,7 @@ fn load_into(p: &Value, cmd: &str, board: Option<Rect>, link_pdf: bool, slices_o
let board = doc.artboards.first().map(|a| a.rect).filter(|_| anchored);
let layers = std::mem::take(&mut doc.layers);
let symbols = doc.symbol_boxes();
let (nodes, clip) = if matches!(format.id, "svg" | "svgz" | "dxf" | "dwg" | "hpgl") {
let (nodes, clip) = if matches!(format.id, "svg" | "svgz" | "dxf" | "hpgl") || fileio::reads_as_dwg(format.id) {
// An SVG with `crop: "crop"` asked for is framed and clipped by its viewBox (its artboard),
// as a PDF by its page: art drawn on a shared canvas keeps its place and scale (#788). By
// default, as Illustrator places one, it is its art's bounds.
+56 -8
View File
@@ -332,9 +332,16 @@ impl HoldsOk for DxfImportDialog {
}
}
/// Is `ext` the extension of a drawing this dialog opens (DXF, or DWG converted to DXF)?
/// Is `ext` the extension (or format id) of a drawing this dialog opens (DXF, or DWG converted to
/// DXF)?
pub(crate) fn is_drawing_ext(ext: &str) -> bool {
matches!(ext, "dxf" | "dwg")
ext == "dxf" || is_dwg_ext(ext)
}
/// Is `ext` the extension (or format id) of a DWG drawing: `.dwg`, a `.dws` standards file or a
/// `.dwt` template?
pub(crate) fn is_dwg_ext(ext: &str) -> bool {
fileio::readable_format(ext).is_some_and(|f| fileio::reads_as_dwg(f.id))
}
/// Open `bytes` (or place them with the `file.place` params `place`) through the dialog when they
@@ -351,7 +358,7 @@ pub fn offer(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option<St
/// drawing is converted on a job of its own ([`crate::opening::convert_drawing`]) and its dialog
/// opens once that is done ([`converted`]) → true; false when `bytes` aren't a DWG drawing.
pub fn convert_in_background(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option<String>, place: Option<&Value>) -> bool {
if !vectorcraft_cad::is_dwg(bytes) || fileio::detect(name, bytes).is_none_or(|f| f.id != "dwg") {
if !vectorcraft_cad::is_dwg(bytes) || fileio::detect(name, bytes).is_none_or(|f| !fileio::reads_as_dwg(f.id)) {
return false;
}
crate::opening::convert_drawing(app, name, bytes.to_vec(), path, place.cloned());
@@ -365,10 +372,10 @@ pub fn convert_in_background(app: &mut VectorcraftApp, name: &str, bytes: &[u8],
/// converted (true).
pub fn convert_place_in_background(app: &mut VectorcraftApp, p: &Value) -> bool {
let named = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension);
if p.get("dxf").is_some() || named.as_deref() != Some("dwg") {
if p.get("dxf").is_some() || !named.as_deref().is_some_and(is_dwg_ext) {
return false;
}
let Some((name, bytes, path)) = place_source(app, p, |ext| ext == "dwg") else { return false };
let Some((name, bytes, path)) = place_source(app, p, is_dwg_ext) else { return false };
if !vectorcraft_cad::is_dwg(&bytes) {
return false;
}
@@ -443,8 +450,8 @@ fn show(
open_held(app, dialog, move |app, choices| confirm(app, &source, choices)).is_some()
}
/// `file.place` with params `p` asks first (true) when they name a `.dxf` or `.dwg` drawing and no
/// `dxf` options.
/// `file.place` with params `p` asks first (true) when they name a `.dxf`, `.dwg`, `.dws` or `.dwt`
/// drawing and no `dxf` options.
pub fn offer_place(app: &mut VectorcraftApp, p: &Value) -> bool {
let named = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension);
if p.get("dxf").is_some() || !named.as_deref().is_some_and(is_drawing_ext) {
@@ -456,7 +463,8 @@ pub fn offer_place(app: &mut VectorcraftApp, p: &Value) -> bool {
/// The `dxf` options a drawing `file.place` params `p` name is placed with when Show Import Options
/// is off: the choices confirmed last (fit, lineweights, centring, layers), the drawing at 1:1 in
/// its own unit. `None` when `p` names no `.dxf` or `.dwg` drawing or already gives `dxf` options.
/// its own unit. `None` when `p` names no DXF or DWG drawing ([`is_drawing_ext`]) or already gives
/// `dxf` options.
pub fn last_options(app: &VectorcraftApp, p: &Value) -> Option<Value> {
let named = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension);
if p.get("dxf").is_some() || !named.as_deref().is_some_and(is_drawing_ext) {
@@ -808,6 +816,46 @@ mod tests {
});
}
/// A `.dwt` template and a `.dws` standards file are DWG drawings: they are converted off the UI
/// thread and go through the dialog as a `.dwg` does, and the template opens untitled.
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
#[test]
fn a_dwt_template_and_a_dws_file_open_and_place_as_dwg_drawings() {
vectorcraft_engine::dwg::allow_in_process();
let dwg = craft_dwg::dxf_to_dwg_as(&drawing(), "AC1018").unwrap();
let dir = crate::tests_folder::Folder::new("dxf-import-dwt-dws");
let (template, standards) = (dir.join("plan.dwt"), dir.join("plan.dws"));
std::fs::write(&template, &dwg).unwrap();
std::fs::write(&standards, &dwg).unwrap();
let (template, standards) = (template.to_string_lossy().into_owned(), standards.to_string_lossy().into_owned());
crate::opening::tests::with_threads(|| {
let mut app = host::app();
app.services.read = Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string())));
crate::io::open_file(&mut app, &template, true).unwrap();
assert!(!host::is_open(&app, KIND) && app.opening.converting.len() == 1, "the template is converted first");
finish_conversions(&mut app);
assert_eq!(host::fields(&app, KIND)["mode"], "open");
host::confirm(&mut app, KIND).unwrap();
let st = app.session.doc().unwrap();
assert!(st.doc.title.starts_with("Untitled"), "a template opens untitled: {}", st.doc.title);
let w = st.doc.artboards[0].rect.width();
assert!((w - 100.0 * Unit::Millimeters.points()).abs() < 1e-6, "the model space line at 1:1: {w}");
crate::io::open_file(&mut app, &standards, true).unwrap();
assert_eq!(app.opening.converting.len(), 1, "the standards file is converted first");
finish_conversions(&mut app);
host::confirm(&mut app, KIND).unwrap();
assert_eq!(app.session.doc().unwrap().doc.title, "plan.dws");
// Placed by the user, each is converted first and asks for its options.
for path in [&template, &standards] {
crate::place::run_for_user(&mut app, &json!({ "path": path })).unwrap();
assert!(!host::is_open(&app, KIND), "{path}");
finish_conversions(&mut app);
assert_eq!(host::fields(&app, KIND)["mode"], "place", "{path}");
host::cancel(&app, KIND);
}
});
}
/// Waits for the DWG conversions under way to finish, then lets [`crate::opening::poll`] hand
/// them on.
#[cfg(not(any(target_arch = "wasm32", all(target_os = "freebsd", target_arch = "aarch64"))))]
+3 -2
View File
@@ -735,7 +735,7 @@ fn set_aside_import_options(p: &mut Value) {
let ext = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::extension).unwrap_or_default();
let keys: &[&str] = match ext.as_str() {
"pdf" | "ai" | "ait" => &["page", "crop"],
"dxf" | "dwg" => &["dxf"],
e if crate::dialogs::dxf_import::is_drawing_ext(e) => &["dxf"],
"psd" | "pdd" | "psb" => &["layers", "hiddenLayers", "importSlices"],
_ if crate::dialogs::text_import::is_text(p) => &["text"],
_ => &[],
@@ -778,7 +778,8 @@ fn clicked_at_full_size(app: &VectorcraftApp, p: &Value) -> Value {
return p;
}
let Some(name) = p.get("path").or_else(|| p.get("name")).and_then(Value::as_str).map(fileio::file_name) else { return p };
if !matches!(fileio::extension(&name).as_str(), "pdf" | "ai" | "ait" | "dxf" | "dwg") {
let ext = fileio::extension(&name);
if !matches!(ext.as_str(), "pdf" | "ai" | "ait") && !crate::dialogs::dxf_import::is_drawing_ext(&ext) {
return p;
}
let r: Vec<f64> = p.get("rect").and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_f64).collect()).unwrap_or_default();
+5 -3
View File
@@ -880,7 +880,7 @@ ends the wait, so the sampler can be shown again. The BSDs and headless sessions
| `invoke_menu` | `{command, params?}` | Invokes a menu item by command id. UI commands such as `view.*` and `window.*` are in `command_list` with `ui: true`; running them needs the desktop app (`--connect`). The app refuses `attributes.openUrl`, `file.export.svg.browser`, `file.saveForWeb.browser` and `file.showPackage` for every control and MCP request, since each opens another app, so the headless error for them does not suggest `--connect`. |
| `open_panel` | `{panel}` | Remote only. `panel` is a panel id (`layers`, `swatches`, `colorGuide`, …, as `window.panel` takes) or its display label (`"Color Guide"`), in any case. |
| `screenshot` | `{path?, scale?, artboard?, window?, max_side?, traceViews?}` | Returns MCP image content (`image/png`, base64) plus a text block. Renders the artboard with the pixels of a PNG `export` with `background: "white"` at the same scale; `traceViews:true` draws Image Trace objects in the view set with `imageTrace.setView`, as in the app's window; `window:true` captures the app window (remote only), as `ui_screenshot` does, and `max_side` (1–4096, window captures only) scales the returned image down as described for `ui_screenshot`. With `path` the backend (the headless session or the app) writes the PNG there too; a window capture written there keeps its full size with `max_side`. An app that does not send the image back writes a window capture without `path` to a file in a new folder inside the system's temporary folder (on Unix only the user can open it); the server reads the file and then removes the folder, also when the capture or the read fails. |
| `open_file` | `{path, importer?, params?}` | Opens any readable file as a new active document: `.vectorcraft`/`.drawcraft`, `.vctemplate`, `.svg`/`.svgz`, `.pdf`/`.ai`, `.ait`, `.eps`/`.epsf`, `.ps`, `.dxf`, `.emf`, `.wmf`, PICT (`.pct`/`.pic`/`.pict`, and a version 2 picture of any extension), HP-GL (`.plt`/`.hpgl`/`.hgl`/`.hpg`, and a file of an extension no other format reads that starts with plotter instructions), PNG (`.png`/`.pns`), JPEG, GIF, WebP, TIFF, BMP (`.bmp`/`.dib`/`.rle`), Targa (`.tga`/`.vda`/`.icb`/`.vst`), PCX, Pixar (`.pxr`), JPEG 2000 (`.jpf`/`.jpx`/`.jp2`/`.j2k`/`.j2c`/`.jpc`), HEIC/HEIF (`.heic`/`.heif`), JPEG XL (`.jxl`), PSD (`.psd`/`.pdd`)/PSB (an image opens as a document of its pixel size; a PSD or PSB file with its layers as layers, or as its merged image through `run_command document.open` with `layers: false`; a JPEG XL file as its first frame), CDR drawings of versions 1 to 27 (`.cdr`, `.cdt`), CMX files with 32-bit coordinates (`.cmx`), layered raster `.pcraft` documents (as one image at the canvas size; a warning says when only the smaller preview could be read). Templates (`.vctemplate`, `.ait`, `.cdt`) open as a new untitled document. PDF, `.ai` and SVG files saved with Preserve Editing reopen as the document they carry. The reply is `document.open`'s: its `warnings` say what didn't come in as it was (an EPS whose PostScript can't be read opens as its preview, and the warning names the PostScript error, the operator and the procedure). A file of an extension only an installed importer plug-in lists opens with that importer ([Plug-ins](#plug-ins)); `importer: "plugin.<id>"` opens the file with the importer it names, which must list the file's extension, also one a built-in format reads (in the app, as File › Open With does), and `params` gives that importer's parameters (their defaults when omitted). `run_command document.formats` lists the formats. |
| `open_file` | `{path, importer?, params?}` | Opens any readable file as a new active document: `.vectorcraft`/`.drawcraft`, `.vctemplate`, `.svg`/`.svgz`, `.pdf`/`.ai`, `.ait`, `.eps`/`.epsf`, `.ps`, `.dxf`, `.emf`, `.wmf`, PICT (`.pct`/`.pic`/`.pict`, and a version 2 picture of any extension), HP-GL (`.plt`/`.hpgl`/`.hgl`/`.hpg`, and a file of an extension no other format reads that starts with plotter instructions), PNG (`.png`/`.pns`), JPEG, GIF, WebP, TIFF, BMP (`.bmp`/`.dib`/`.rle`), Targa (`.tga`/`.vda`/`.icb`/`.vst`), PCX, Pixar (`.pxr`), JPEG 2000 (`.jpf`/`.jpx`/`.jp2`/`.j2k`/`.j2c`/`.jpc`), HEIC/HEIF (`.heic`/`.heif`), JPEG XL (`.jxl`), PSD (`.psd`/`.pdd`)/PSB (an image opens as a document of its pixel size; a PSD or PSB file with its layers as layers, or as its merged image through `run_command document.open` with `layers: false`; a JPEG XL file as its first frame), CDR drawings of versions 1 to 27 (`.cdr`, `.cdt`), CMX files with 32-bit coordinates (`.cmx`), layered raster `.pcraft` documents (as one image at the canvas size; a warning says when only the smaller preview could be read), DWG drawings (`.dwg`, `.dws`, `.dwt`). Templates (`.vctemplate`, `.ait`, `.cdt`, `.dwt`) open as a new untitled document. PDF, `.ai` and SVG files saved with Preserve Editing reopen as the document they carry. The reply is `document.open`'s: its `warnings` say what didn't come in as it was (an EPS whose PostScript can't be read opens as its preview, and the warning names the PostScript error, the operator and the procedure). A file of an extension only an installed importer plug-in lists opens with that importer ([Plug-ins](#plug-ins)); `importer: "plugin.<id>"` opens the file with the importer it names, which must list the file's extension, also one a built-in format reads (in the app, as File › Open With does), and `params` gives that importer's parameters (their defaults when omitted). `run_command document.formats` lists the formats. |
| `save_file` | `{path?, compress?, version?, preview?, precision?, options?}` | Runs `document.save`: the document's own file in its own format (native `.vectorcraft` unless it was opened from or saved as SVG, PDF or a restorable `.ai`; then `warnings` say what that format loses). A path's extension picks the format (`.vectorcraft`, `.vctemplate`, `.pdf`, `.svg`, `.svgz`, `.ai`: a PDF carrying the native document, which reopens editable; `.eps`: by default one file whose bounding box fits the visible art, the first artboard when no art shows; `options.useArtboards: true` makes the chosen artboard the page and, with two or more chosen, the file at the path is the central file of the visible art and each artboard is also written to `<name>_<artboard>.eps` beside it, listed in the reply's `files`). For a native file, `compress: true` gzips it (default: the `useCompression` preference, Preferences › File Handling › Use Compression), `version` (1 to 4) writes it for an older VectorCraft (1 and 2 are never compressed, and `version: 2` with `compress: true` is an error; versions 1 to 3 get each live star as a plain path of its outline, without its point count and ratio), `preview: true` embeds a PNG of the first artboard, and `precision` (0 to 9) rounds path anchors and handles to that many decimal places for that save only (colors, transforms and type stay exact). `options` passes the format's save options as `run_command document.formats` lists them. When `compress`, `version`, `preview` or `precision` is given both at the top level and in `options` with different values, the call is an error (`` `compress: true` and `options.compress: false` disagree: give the option once ``) and nothing is written. A key in `options` that no save format takes is an error, and nothing is written (see Parameter keys). The save drops each option the written format doesn't read. The reply's `warnings` then name each such option given (for example `` `compress` was not used: SVG files don't read it `` for an `.svg` path, and `` `options.preview` was not used: … `` for a key in `options`; a PDF-compatible `.ai` file reads `compress` but not `version`, `preview`, `precision`, `outlineText`, `hiddenObjects`, `transparentImages` or `preserveEditing`, and a legacy `.ai` file reads only its own options). For a `.ai` file, these warnings name the kind of `.ai` written: a legacy .ai (version 7) for `aiVersion: "7"`, a non-PDF-compatible .ai for `pdfCompatible: false`, and a PDF-compatible .ai otherwise, including a save that reuses the options the document was last saved with. `run_command document.save` and the other save commands refuse any option given beside the path and in `options` with different values, and give the same warnings for each key given beside the path or in `options` that the file doesn't read. The headless session and the app receive the same `app.save` params, and the app is also sent `wait: true`: the call returns once the file is written, or with the error (such as a path outside the write root), even with Background Save on. When the save asks first (the question before replacing a file that opened with losses, or on macOS and Linux the file dialog for an untitled document without `path`), the reply is `{pending}` or `"cancelled"` as before, and the save that runs after the answer uses the Background Save preference. Location refusals return `READ_ONLY_LOCATION: <reason>` without a fallback panel for automation; see [Save location errors](#save-location-errors). In the desktop app, a save that runs in the background shows in the progress window after 0.4 s with a moving bar. `file.cancelSave` stops every such save before it replaces its file → `{cancelled: n}`: the file stays as it was, and the document keeps its file and format and stays modified. A save whose file was already being replaced finishes and is reported as saved. `file.saveInBackground` closes the window while the saves go on → `{hidden: n}`. |
| `export` | `{path?, format?, scale?, artboard?, range?, selection?, outlineText?, options?}` | `svg`, `svgz`, `pdf`, `ai` (the PDF-compatible `.ai` that Save writes, which carries the document when every artboard is written in order), `eps`, `dxf`, `emf`, `wmf`, `hpgl` (a `.plt` plot file for plotters and cutters), `png`, `jpg`, `webp`, `gif`, `png8` (an indexed `.png`), `tiff`, `bmp`, `tga`, `psd` (layered), `txt` (the document's text), `vectorcraft` or `template` (a native template). The tool's `format` enum and `document.formats` list them, generated from the engine's format table. When `format` is omitted, it comes from the path's extension. PDF and `.ai` write one page per artboard: all of them, or `artboard` (0-based) / `range` (`"1-3, 5"`, 1-based). SVG and SVGZ write one file per chosen artboard. EPS writes one file of the visible art; with `artboard`, `range`, `options.artboards` or `options: {"useArtboards": true}` it writes one file per chosen artboard, after a central file of the visible art when there are two or more, and `useArtboards: false` keeps the one file. Rasters, DXF, EMF, WMF and HP-GL write one artboard, or one file per chosen artboard with `options: {"useArtboards": true}`. Rasters also take `options: {"rect": [x, y, width, height]}` (page points, y down): that area of the page at the given `ppi`/`scale`, without an artboard and without changing the document; it is refused with `artboard`, `artboards`, `range` or `useArtboards`, with a non-positive or non-finite size, and for non-raster formats. `options` carries more format options (e.g. `{"quality": 80}` for JPEG). `selection: true` exports the selected objects cropped to their bounds (the reply adds their `bounds`, and reports `format` and the encoder's `warnings` as a whole-document export does); `outlineText: true` writes SVG text as paths. Template layers are left out, live effects are kept, and exporting `vectorcraft` never changes the document's path. Without `path` the bytes come back as `dataBase64`. Both backends run the same `document.export` call. |
| `add_text` | `{text, x?, y?, width?, height?, fit?, fitMinPercent?, path?, mode?, pathEffect?, size?, font?, color?, justify?, vertical?}` | Point type at (x, y) (`justify`: `left`, `center` or `right` starts, centres or ends each line on x); area type with `width`/`height` (`fit`: `none`, `autoHeight`, `shrinkText`, as `text.areaOptions`); or `path` + `mode` (`area`/`onPath`) to flow text in or along a path, with `pathEffect` for type on a path (`rainbow`, `skew`, `3dRibbon`, `stairStep`, `gravity`; SVG export writes type on a path with any effect other than `rainbow` as outlines, with a warning). An invalid effect is rejected before editing. `justify` (also `auto`, `justifyAll`) aligns the paragraphs of every kind, as `text.setStyle` does later. `vertical: true` uses the existing vertical writing mode for every kind (default `false`, horizontal). Returns `{id}`, with `overflow: true` when the text doesn't fit its frame or path. |
@@ -12733,8 +12733,8 @@ blending, opacity masks, raster effects, clipping) comes back in `warnings`. In
no linked file, and `warnings` carries "an image couldn't be decoded and is missing from the picture" once for all such
images.
DWG drawings open and place (see DXF import) but can't be written: `document.formats` lists `dwg` as readable and
not writable, and exporting to it answers with the hint to export DXF. PICT files open and place (see PICT
DWG drawings open and place (see DXF import) but can't be written: `document.formats` lists `dwg` and `dwt` as
readable and not writable, and exporting to `dwg`, `dws` or `dwt` answers with the hint to export DXF. PICT files open and place (see PICT
import) but can't be written.
```json
@@ -12766,6 +12766,8 @@ vertices are missing, unknown entities) is listed in `warnings`. ASCII and binar
DWG drawings (by content or the `.dwg` extension) open, place and answer `document.dxfInfo` the same way, with the
same `dxf` options: craft-dwg converts the drawing to DXF (acadrust 0.6.6, MPL-2.0) and the DXF reader reads that.
Drawing standards files (`.dws`) are read as DWG drawings, and drawing templates (`.dwt`, format `dwt`) too, except
that a template opens as a new untitled document.
In the desktop app and `vectorcraft-cli` the conversion runs in a copy of the program started with `--dwg-worker`, so
a damaged file stops that copy, not the app; it gives up after 30 minutes. Files over 512 MiB, or whose DXF would
pass 1 GiB, are refused. What the conversion skips (objects of types it can't read) is listed in `warnings`. R1.x and
+1
View File
@@ -2568,6 +2568,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- DXF export writes a path of straight segments and circular arcs (a slot, a D shape, a rounded rectangle, a pie) as one polyline whose vertices carry a bulge (group 42) for each arc: an LWPOLYLINE in R14 and later, a POLYLINE with VERTEX entities in R12 and R13, closed when the path is closed, and it reads back as the same outline (#1299, `crates/cad/src/tests.rs`). Such a path was written as one SPLINE (a flattened polyline in R12); a path with any other curve still is. A shallow curve becomes an ARC or a bulge only when it lies on the circle within 5e-4 of its own extent as well as of the radius, and the drawing extents (`$EXTMIN`, `$EXTMAX`) reach the furthest points of every ARC and bulge.
- DXF export with Use Artboards applies live effects and places symbols' art once for all the artboards' drawings instead of once for each drawing; each drawing's bytes, linked images, warnings and notes are the same as before (`drawings_apply_the_live_effects_once_and_match_drawings_written_alone`, `each_artboard_s_drawing_is_the_drawing_of_that_artboard_alone`).
- DWG drawings open and place in the desktop build, and `document.dxfInfo` reads them: craft-dwg converts the drawing to DXF, in a copy of the app started with `--dwg-worker`, off the UI thread when the user opens or places it, and the DXF reader reads it with the DXF Import Options. The web build and R1.x and R2.x drawings return an error that says to save the drawing as DXF. DWG is not written: Export As keeps it greyed out, exporting to it says to export DXF, and Save over the drawing is refused (`a_dwg_drawing_comes_in_as_its_dxf_does`, `document_open_reads_a_dwg_drawing_as_its_dxf`, `dxf_info_and_place_read_a_dwg`, `a_dwg_opened_is_never_written_back_as_dwg`; scores and estimates unchanged).
- `.dws` drawing standards files and `.dwt` drawing templates, which are DWG files, open and place as DWG drawings, are listed in the open and place dialogs, and go through the DXF Import Options; a `.dwt` opens as a new untitled document (`a_dwt_template_opens_untitled_and_a_dws_opens_as_its_drawing`, `a_dwt_or_dws_drawing_places_as_a_dwg_does`, `dwt_and_dws_are_read_only_and_exporting_them_says_to_write_dxf`; scores and estimates unchanged).
- Affinity documents in (AF.1–AF.4): `.af` (Affinity 3) and `.afdesign`/`.afphoto`/`.afpub` (Affinity 1 and 2, container versions 8–12) open and place as editable art: layers and sublayers, groups (pass-through or isolated), artboards (with their names and backgrounds) and Publisher pages side by side, curves with live corners, parametric shapes (rectangles with corner radii, ellipses, polygons, stars, pies, triangles, trapezoids), compound shapes, solid/linear/elliptical gradient fills and strokes (weight, dashes, alignment, scale-with-object), clipping by nesting, vector and pixel masks, artistic and frame text with fonts, sizes, tracking, leading and alignment, placed images (their original JPEG/PNG) and pixel layers (8/16-bit RGB, CMYK), opacity, visibility, locking and blend modes, at the document's resolution in points. Effects, adjustments, brushes and pressure profiles, transparency gradients, master pages, symbol instances (imported as their cached picture), special shapes (cloud, heart, cog…, imported as ellipses) and Affinity-only blend modes are named in the import warning. A file whose native data can't be read opens as its embedded preview with the reason, and that preview can't be placed. Save never writes back over the Affinity file and there is no Affinity export. AF.5 (from DesignCraft's import, storytold/designcraft#291) adds master pages (on a locked layer behind the pages that show them), tables (area type per cell and a line per edge), each paragraph's alignment, indents, spacing and leading, horizontal text scale, outlined text, frame text sized by its text scale, drop shadows and outer glows as live effects (inner shadows as inner glows), outline effects as strokes, colour and gradient overlays baked into the paint, embedded Affinity documents as editable content (their artboards don't become artboards), pixel layers over 64 MP at a reduced resolution and HEIC photos from their stored pixels; automatic leading (size plus the font's line gap) fitted on thumbnails; underlines and strikethrough; strokes whose style is None (every shape stores one) left out, which also brings 6 public files closer to their thumbnails; line breaks inside a paragraph; table cell text centred as Affinity centres it, also where it is taller than its cell; CMYK pixel layers converted through the document's embedded CMYK profile (relative colorimetric with black-point compensation, as each layer's colour settings name), or kept as CMYK images when there is none; outline effects on stroked shapes around their stroke; artistic text whose paragraphs align differently aligned within its longest line, a frame's first baseline at cap height, and frames whose last lines' descenders hang out made tall enough to show them (all measured on a local document's own PDF export: baselines match to 0.1 pt); a local 56-artboard document's mean thumbnail difference went from 16.2 to 11.4, and its pages' mean difference from the owner's PDF export from 12.9 to 9.3. AF.4 adds Affinity 3 artboard recognition and actual-outline clipping, source-backed JPEG/PNG raster tiles, Unicode text-run recovery, stored fallback/exact installed fonts, OpenType feature flags and compound-geometry limits. 51 public CC0/MIT/Apache-2.0 files (33 current `.af`), pinned and sha256-verified (`cargo xtask corpus --affinity`), test native retention and every-board native/SVG/PDF/PSD output for current files; selected files compare their saved thumbnails. No Affinity reopen or independent paired PSD oracle was available; [source audit and complex-font gaps](affinity-validation.md); [scope, provenance and limits](../crates/affinity/README.md).
- `.cdr` drawings of versions 1 to 27 open and place, and `.cdt` templates open as new untitled documents. `craft-cdr` reads the `WL` files of versions 1 and 2 (one page and one layer of rectangles, whole ellipses and curves with uniform fills and outlines), the RIFF chunk tree of versions 3 on and its compressed lists, and the ZIP packages of versions 14 on with the data streams of versions 16 on, and the importer maps pages to artboards side by side, layers by name, the master page's guidelines to guides on every page, groups, clipping containers (as clipping groups), curves and paths, rectangles (live, with each corner's radius), ellipses (live), arcs and polygons, uniform fills in CMYK, CMY, RGB, gray and registration, and outlines with their width (0.25 pt for a width of 0), caps, joins and dashes (behind the fill, or scaled with the object's matrix, where the file says so), an object without a fill or outline of its own taking its style's, hidden and locked layers, groups and objects, the winding flag as the nonzero fill rule, and a uniform transparency of version 13 and later as the object's opacity and blend mode. A library color stored with its name and values (version 13 and later, in a fill or an outline) becomes a spot swatch with its tint; one stored only by its number opens as a black spot color named by its palette and number, with a warning. Text, bitmaps, blends, contours, brush strokes, fountain, pattern, texture and PostScript fills, arrowheads, lenses, other transparency and the envelopes of version 3 are left out with a warning, and encrypted, ZIP64 and split packages are refused with a message. Every record layout has a source in `craft-cdr` (`storytold/craft-libs@9b28b56bc7`, `crates/cdr/PROVENANCE.md`). Reading is bounded by limits on input size, inflated size, package members, nesting, chunks, objects, coordinates and dashes, where an outline's dashes count for every shape that uses it (`craft-cdr` `crates/cdr/tests/it/read.rs`, `crates/engine/src/cmd/fileio/tests_cdr.rs`, `crates/engine/tests/import_fuzz.rs`).
- `.cmx` exchange files with 32-bit coordinates open and place: `craft-cdr` reads their color, pen, line type, dash and outline tables and each page's instructions, and the importer maps pages, layers (a layer that holds nothing is left out), groups and curves, with uniform fills and outlines, as it maps a `.cdr` drawing's. Text, images, rectangles, ellipses, clipping paths, other fills, arrowheads and lenses are named in the warnings, and big-endian files and files with 16-bit coordinates are refused with a message (`craft-cdr` `storytold/craft-libs@9b28b56bc7` `crates/cdr/tests/it/cmx.rs`, `crates/engine/src/cmd/fileio/tests_cmx.rs`, `crates/engine/tests/import_fuzz.rs`).