DWG: a canceled export stops before the next drawing's conversion

The DWG export converted every artboard's drawing before the export
checked for cancellation, so a canceled multi-artboard export kept the
background lane busy until all conversions finished. The export now
checks for cancellation before each conversion.
This commit is contained in:
dotCooCoo
2026-12-04 21:54:40 -08:00
parent 21c89d170c
commit a027a84b6c
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -277,6 +277,7 @@ pub(super) fn encode(doc: &Document, p: &Value, use_artboards: Option<bool>, dwg
for ((board, _, _), out) in drawings.into_iter().zip(outs) {
let mut warnings = out.warnings;
let bytes = if dwg {
vectorcraft_doc::cancel::check()?;
let (bytes, unwritten) = vectorcraft_cad::dwg::from_dxf(&out.bytes, opts.version).map_err(|e| bad(C, e))?;
for (kind, n) in unwritten {
*left_out.entry(kind).or_insert(0) += n;
@@ -136,6 +136,20 @@ fn document_export_writes_a_dwg_that_opens_as_the_drawing_its_dxf_holds() {
let _ = std::fs::remove_dir_all(&dir);
}
/// A canceled export stops before converting any drawing to DWG.
#[test]
fn a_canceled_dwg_export_converts_no_drawing() {
vectorcraft_cad::dwg::allow_in_process();
let mut s = Session::new();
s.execute("file.new", &json!({"width": 100, "height": 100, "artboards": 2})).unwrap();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 30, "height": 30})).unwrap();
let doc = &s.doc().unwrap().doc;
let token = crate::cancel::CancelToken::new();
token.cancel();
let r = crate::cancel::scope(&token, None, || super::dxf::encode(doc, &json!({}), Some(true), true));
assert!(matches!(r, Err(EngineError::Cancelled)), "{:?}", r.map(|e| e.files.len()));
}
#[test]
fn a_dwg_version_before_2000_is_refused_and_nothing_is_written() {
vectorcraft_cad::dwg::allow_in_process();