fix(web): honor selected DWG/DXF version when saving
The web save path discarded the chosen format version (`let _ = version`) and `save_to_bytes` never applied it, so every browser download was written at the document's default version (AC1032 / DWG 2018) regardless of the format picked in the Save dialog. (#122) Thread `version` into `save_to_bytes` and set `doc.version` there, the byte-buffer counterpart to `save_as_version`. Saving as DWG 2013 now writes an AC1027 file. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
da7905db61
commit
aafced76d7
2 changed files with 11 additions and 5 deletions
|
|
@ -976,8 +976,7 @@ impl OpenCADStudio {
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
let _ = version;
|
match crate::io::save_to_bytes(&self.tabs[i].scene.document, ext, version) {
|
||||||
match crate::io::save_to_bytes(&self.tabs[i].scene.document, ext) {
|
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
crate::sys::download_bytes(&filename, &bytes);
|
crate::sys::download_bytes(&filename, &bytes);
|
||||||
self.tabs[i].dirty = false;
|
self.tabs[i].dirty = false;
|
||||||
|
|
|
||||||
|
|
@ -357,10 +357,17 @@ pub fn save(doc: &CadDocument, path: &Path) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize a document to an in-memory byte buffer, format chosen by `ext`
|
/// Serialize a document to an in-memory byte buffer, format chosen by `ext`
|
||||||
/// (`dxf` → DXF, anything else → DWG). Used by the web build, which hands the
|
/// (`dxf` → DXF, anything else → DWG) at the given DXF version (overriding
|
||||||
/// bytes to a browser download instead of writing a path.
|
/// `doc.version`). Used by the web build, which hands the bytes to a browser
|
||||||
pub fn save_to_bytes(doc: &CadDocument, ext: &str) -> Result<Vec<u8>, String> {
|
/// download instead of writing a path — the byte-buffer counterpart to
|
||||||
|
/// [`save_as_version`].
|
||||||
|
pub fn save_to_bytes(
|
||||||
|
doc: &CadDocument,
|
||||||
|
ext: &str,
|
||||||
|
version: acadrust::DxfVersion,
|
||||||
|
) -> Result<Vec<u8>, String> {
|
||||||
let mut doc = doc.clone();
|
let mut doc = doc.clone();
|
||||||
|
doc.version = version;
|
||||||
sync_current_styles_on_save(&mut doc);
|
sync_current_styles_on_save(&mut doc);
|
||||||
match ext.to_lowercase().as_str() {
|
match ext.to_lowercase().as_str() {
|
||||||
"dxf" => DxfWriter::new(&doc).write_to_vec().map_err(|e| e.to_string()),
|
"dxf" => DxfWriter::new(&doc).write_to_vec().map_err(|e| e.to_string()),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue