mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 17:56:50 -06:00
Save: decide the lost-artboards warning in the SVG handler
Move the Preserve Editing check out of save.rs into svg.rs, where it reads the options through `plan` as the encoder does; SaveJob::encode still puts the warning first. Review follow-up on #2994. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Opus 5.5
parent
c2a605ce8e
commit
f9e559156f
@@ -322,19 +322,6 @@ fn fidelity_warning(f: &Format) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// What an SVG save loses of a document with several artboards: the file is one artboard and
|
||||
/// reopens as one, unless it carries the native document (Preserve Editing Capabilities).
|
||||
fn artboards_warning(f: &Format, doc: &Document, params: &Value) -> Option<String> {
|
||||
let n = doc.artboards.len();
|
||||
let preserved = super::svg::options_map(params).ok().and_then(|m| m.get("preserveEditing").and_then(Value::as_bool)).unwrap_or(false);
|
||||
(is_svg(f) && n > 1 && !preserved).then(|| {
|
||||
format!(
|
||||
"{} keeps 1 of the document's {n} artboards (the first, unless one is chosen) and reopens with only that one: turn on Preserve Editing Capabilities or save as VectorCraft to keep them all",
|
||||
f.label
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// A save of the active document, snapshotted and ready to encode and write anywhere (Background
|
||||
/// Save does both on a worker thread): [`save_job`], then [`SaveJob::write`], then
|
||||
/// [`SaveJob::finish`]. Cheap to clone (the documents are shared).
|
||||
@@ -564,7 +551,8 @@ impl SaveJob {
|
||||
}
|
||||
// Lost artboards first: the status bar shows only the first warning.
|
||||
let f = self.plan.format;
|
||||
enc.warnings.splice(0..0, artboards_warning(f, &self.doc, &self.params).into_iter().chain(fidelity_warning(f)));
|
||||
let lost = if is_svg(f) { super::svg::lost_artboards_warning(&self.doc, &self.params, f.label) } else { None };
|
||||
enc.warnings.splice(0..0, lost.into_iter().chain(fidelity_warning(f)));
|
||||
Ok(enc)
|
||||
}
|
||||
|
||||
|
||||
@@ -147,6 +147,19 @@ fn plan(doc: &Document, p: &Value) -> Result<(ExportOptions, Vec<Option<usize>>,
|
||||
Ok((opts, named.unwrap_or_else(|| vec![0]).into_iter().map(Some).collect(), chosen))
|
||||
}
|
||||
|
||||
/// What a save of `doc` as SVG (format `label`) with options `p` loses of several artboards: the
|
||||
/// file is one artboard and reopens as one, unless it carries the native document (Preserve
|
||||
/// Editing Capabilities).
|
||||
pub(super) fn lost_artboards_warning(doc: &Document, p: &Value, label: &str) -> Option<String> {
|
||||
let n = doc.artboards.len();
|
||||
let preserved = plan(doc, p).is_ok_and(|(opts, ..)| opts.preserve_editing);
|
||||
(n > 1 && !preserved).then(|| {
|
||||
format!(
|
||||
"{label} keeps 1 of the document's {n} artboards (the first, unless one is chosen) and reopens with only that one: turn on Preserve Editing Capabilities or save as VectorCraft to keep them all"
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// Encode `doc` as SVG (or gzipped, SVGZ): one file per chosen artboard, with the images they
|
||||
/// link to and the writer's warnings.
|
||||
pub(super) fn encode(doc: &Document, p: &Value, compressed: bool) -> Result<Encoded, String> {
|
||||
|
||||
Reference in New Issue
Block a user