mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-10 01:50:22 -06:00
Native format: document.save can write path coordinates at a fixed precision
Native files store every anchor and handle as a full double, such as 3.4876474632797176, so a file of traced art is larger than it needs to be. document.save, file.saveAs, file.saveCopy and file.saveAsTemplate take precision (0 to 9) for native files. The save rounds the anchors and handles of path objects, Live Corners' uncut outlines, blend spines, envelope outlines, Intertwine areas and brush art to that many decimal places, in the layers, symbols, graph designs, patterns and opacity masks, and in the art that placed documents become in files for older versions. Colors, transforms, opacity and type are written exactly. Without precision the file is written as before, and Save does not remember the option. A .ai file, saved or exported, ignores precision. The VectorCraft Options dialog shows no row for it. A save given precision beside the path for a format that does not read it (SVG, PDF, .ai and .ait) says so in its warnings, as it does for compress, version and preview. MCP save_file passes precision on to the save as it passes the other native options, and its schema, description and docs/mcp.md list it.
This commit is contained in:
@@ -229,11 +229,26 @@ pub struct SaveOptions {
|
||||
pub profiles: BTreeMap<String, Vec<u8>>,
|
||||
/// Create PDF-Compatible File: a PDF of the document to carry.
|
||||
pub pdf: Option<Vec<u8>>,
|
||||
/// Decimal places to round path anchors and handles to ([`Document::round_geometry`]), at
|
||||
/// most [`MAX_PRECISION`] (a larger value rounds to that many); `None` writes them exactly.
|
||||
pub precision: Option<u8>,
|
||||
}
|
||||
|
||||
/// The most decimal places [`SaveOptions::precision`] rounds path geometry to.
|
||||
pub const MAX_PRECISION: u8 = 9;
|
||||
|
||||
impl Default for SaveOptions {
|
||||
fn default() -> Self {
|
||||
Self { pretty: false, compress: false, version: VERSION, preview: None, include_linked: false, profiles: BTreeMap::new(), pdf: None }
|
||||
Self {
|
||||
pretty: false,
|
||||
compress: false,
|
||||
version: VERSION,
|
||||
preview: None,
|
||||
include_linked: false,
|
||||
profiles: BTreeMap::new(),
|
||||
pdf: None,
|
||||
precision: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +314,8 @@ struct Body {
|
||||
}
|
||||
|
||||
/// `doc` as [`save_to`] writes it with `o`: without editing-mode working copies, with placed
|
||||
/// documents as their art for older versions, and its images taken out.
|
||||
/// documents as their art for older versions, path geometry rounded to `o.precision`, and its
|
||||
/// images taken out.
|
||||
fn body(doc: &Document, o: &SaveOptions) -> Result<Body, FormatError> {
|
||||
let version = o.version;
|
||||
let mut d = doc.without_edit_modes().into_owned();
|
||||
@@ -311,6 +327,10 @@ fn body(doc: &Document, o: &SaveOptions) -> Result<Body, FormatError> {
|
||||
} else {
|
||||
d.drop_placed_resources();
|
||||
}
|
||||
// The art placed documents became for older versions is rounded too.
|
||||
if let Some(decimals) = o.precision {
|
||||
d.round_geometry(decimals.min(MAX_PRECISION));
|
||||
}
|
||||
let linked = d.linked_only_images();
|
||||
// The blobs go in the file's `images` (only those the document uses).
|
||||
let blobs = std::mem::take(&mut d.images);
|
||||
|
||||
Reference in New Issue
Block a user