mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 12:03:31 +00:00
.ai save: envelopes on a large canvas stay editable
The editing copy of a large canvas wrote every envelope as its drawn art. It now writes warp, mesh and top object envelopes live at 1/10 of their size with the rest of the art, under the same checks as on a normal canvas, and the reader opens them at their size from the editing data alone or beside the PDF part. Read from the editing data alone, a Large Canvas copy also gets: - an envelope's saved box size compared with its contents at the declared scale, so a bounds margin kept with Distort Appearance is no longer lost; - every path's stroke weight, dashes and dash offset at the declared scale, not at 1/10.
This commit is contained in:
@@ -10810,6 +10810,129 @@ fn unreachable_envelope() -> ! {
|
||||
panic!("not an envelope")
|
||||
}
|
||||
|
||||
/// `doc` with its first artboard 20,000.5 points wide: it is written on a large canvas, at 1/10.
|
||||
fn on_large_canvas(mut doc: Document) -> Document {
|
||||
doc.artboards[0].rect = Rect::new(0.0, 0.0, 20_000.5, 100.0);
|
||||
doc
|
||||
}
|
||||
|
||||
/// A route an envelope was read back by: its name, the envelope and the reader's notes.
|
||||
type EnvelopeRoute = (&'static str, Node, Vec<String>);
|
||||
|
||||
/// The envelope `doc` holds alone on its first layer, read back from the editing data alone and
|
||||
/// beside a page that draws as `doc` does ([`read_with_page`]); and the writer's warnings.
|
||||
fn envelope_both_routes(doc: &Document) -> (Vec<EnvelopeRoute>, Vec<String>) {
|
||||
let (alone, warnings, notes) = envelope_back(doc);
|
||||
let (paged, _, page_notes) = read_with_page(doc);
|
||||
assert_eq!(paged.len(), 1, "{paged:#?} {page_notes:?}");
|
||||
(vec![("alone", alone, notes), ("beside its page", (*paged[0]).clone(), page_notes)], warnings)
|
||||
}
|
||||
|
||||
/// On a large canvas, a warp, a mesh and a top object envelope, with Edit Contents off and on, are
|
||||
/// written live at 1/10 and open as the same envelope at their size, from the editing data alone
|
||||
/// and beside the page: contents, Fidelity, Edit Contents, Envelope Options, shape and name as
|
||||
/// saved. Saved again as they opened, they open as the same envelope again.
|
||||
#[test]
|
||||
fn large_canvas_envelope_kinds_round_trip_on_both_ai_routes() {
|
||||
// GUARDS: an envelope on a large canvas was written as its drawn art, with a warning.
|
||||
use vectorcraft_doc::live::EnvelopeOptions;
|
||||
for (name, kind) in live_envelope_kinds() {
|
||||
for editing in [false, true] {
|
||||
let what = format!("{name}, editing {editing}");
|
||||
let doc = on_large_canvas(envelope_doc(kind.clone(), 50.0, editing, EnvelopeOptions::NEW));
|
||||
let text = program(&doc);
|
||||
assert!(text.contains("%AI24_LargeCanvasScale: 10\n") && text.contains("AIDeformOptionsKey"), "{what}");
|
||||
let (routes, warnings) = envelope_both_routes(&doc);
|
||||
assert!(!warnings.iter().any(|w| w == writer::ENVELOPES), "{what}: {warnings:?}");
|
||||
for (route, back, notes) in routes {
|
||||
let what = format!("{what}, {route}");
|
||||
assert!(!notes.iter().any(|w| w == crate::import::ENVELOPE_DRAWN), "{what}: {notes:?}");
|
||||
let NodeKind::Envelope { content, kind: got, fidelity, editing: e, options, frame } = &back.kind else {
|
||||
panic!("{what}: {back:#?} {notes:?}")
|
||||
};
|
||||
assert_eq!((*fidelity, *e, *options, **frame), (50.0, editing, EnvelopeOptions::NEW, Affine::IDENTITY), "{what}");
|
||||
assert!(same_envelope_kind(&kind, got), "{what}: {got:?}");
|
||||
assert_eq!(back.name.as_deref(), Some("Bent"), "{what}");
|
||||
let colors: Vec<Option<Color>> = content.iter().map(|c| c.appearance.fill_paint().color()).collect();
|
||||
assert_eq!(colors, [Some(Color::rgb(1.0, 0.0, 0.0)), Some(Color::rgb(0.0, 0.0, 1.0))], "{what}");
|
||||
let b = content.iter().filter_map(|c| c.visual_bounds()).reduce(|a, b| a.union(b)).unwrap();
|
||||
let want = Rect::new(40.0, 20.0, 160.0, 80.0);
|
||||
assert!([b.x0 - want.x0, b.y0 - want.y0, b.x1 - want.x1, b.y1 - want.y1].iter().all(|d| d.abs() < 1e-2), "{what}: {b:?}");
|
||||
}
|
||||
let (back, _, _) = envelope_back(&doc);
|
||||
let mut again = on_large_canvas(Document::new(200.0, 100.0));
|
||||
let layer = again.layers[0].id;
|
||||
again.insert(Some(layer), usize::MAX, back).unwrap();
|
||||
let (twice, warnings, notes) = envelope_back(&again);
|
||||
assert!(!warnings.iter().any(|w| w == writer::ENVELOPES), "{what}, saved again: {warnings:?}");
|
||||
let NodeKind::Envelope { kind: twice, .. } = &twice.kind else { panic!("{what}, saved again: {twice:#?} {notes:?}") };
|
||||
assert!(same_envelope_kind(&kind, twice), "{what}, saved again: {twice:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On a large canvas, envelopes with Distort Appearance whose stroked contents (at fractional places)
|
||||
/// map from their bounds with their strokes keep that margin, the contents' 8-point strokes and the
|
||||
/// Distort Linear Gradients and Distort Pattern Fills switches, from the editing data alone and
|
||||
/// beside the page.
|
||||
#[test]
|
||||
fn large_canvas_envelope_stroke_margin_round_trips_on_both_ai_routes() {
|
||||
// GUARDS: read from the editing data alone, the saved size was compared at 1/10 with contents at
|
||||
// their size, and the contents' strokes came back at 1/10: the margin was lost.
|
||||
use vectorcraft_doc::live::{EnvelopeOptions, envelope_content_boxes, envelope_stroke_margin};
|
||||
for (name, kind) in live_envelope_kinds() {
|
||||
for editing in [false, true] {
|
||||
let what = format!("{name}, editing {editing}");
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let switches = EnvelopeOptions { distort_linear_gradients: editing, distort_pattern_fills: !editing, ..EnvelopeOptions::NEW };
|
||||
let mut envelope = envelope_node(&mut doc, kind.clone(), 50.0, editing, switches);
|
||||
let NodeKind::Envelope { content, options, .. } = &mut envelope.kind else { unreachable_envelope() };
|
||||
for c in content.iter_mut() {
|
||||
let c = Arc::make_mut(c);
|
||||
c.transform(Affine::translate((0.25, 0.375)), true);
|
||||
let fill = c.appearance.fill_paint();
|
||||
c.appearance = Appearance::basic(fill, solid(Color::BLACK), 8.0).into();
|
||||
}
|
||||
let (stroked, plain) = envelope_content_boxes(content, Affine::IDENTITY).unwrap();
|
||||
options.bounds_margin = envelope_stroke_margin(stroked, plain).unwrap();
|
||||
let want = *options;
|
||||
assert!(want.bounds_margin.iter().all(|m| *m > 0.0), "{what}: {want:?}");
|
||||
let layer = doc.layers[0].id;
|
||||
doc.insert(Some(layer), usize::MAX, envelope).unwrap();
|
||||
let (routes, warnings) = envelope_both_routes(&on_large_canvas(doc));
|
||||
assert!(!warnings.iter().any(|w| w == writer::ENVELOPES), "{what}: {warnings:?}");
|
||||
for (route, back, notes) in routes {
|
||||
let what = format!("{what}, {route}");
|
||||
let NodeKind::Envelope { content, options, .. } = &back.kind else { panic!("{what}: {back:#?} {notes:?}") };
|
||||
let margin = options.bounds_margin;
|
||||
assert!(margin.iter().zip(want.bounds_margin).all(|(a, b)| (a - b).abs() < 1e-4), "{what}: {margin:?} {want:?}");
|
||||
assert_eq!(EnvelopeOptions { bounds_margin: want.bounds_margin, ..*options }, want, "{what}");
|
||||
let widths: Vec<f64> = content.iter().filter_map(|c| c.appearance.stroke().map(|s| s.width)).collect();
|
||||
assert!(widths.len() == 2 && widths.iter().all(|w| (w - 8.0).abs() < 1e-4), "{what}: {widths:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On a large canvas a path's stroke weight and dashes, written at 1/10, come back at their size
|
||||
/// from the editing data alone.
|
||||
#[test]
|
||||
fn a_large_canvas_path_keeps_its_stroke_weight_and_dashes_read_alone() {
|
||||
// GUARDS: read from the editing data alone, the stroke's weight, dashes and dash offset came
|
||||
// back at 1/10 while the path came back at its size.
|
||||
let mut doc = on_large_canvas(Document::new(200.0, 100.0));
|
||||
let mut n =
|
||||
Node::path(doc.alloc_id(), shapes::line((20.0, 50.0).into(), (180.0, 50.0).into()), Appearance::basic(Paint::None, solid(Color::BLACK), 6.0));
|
||||
n.appearance.stroke_mut().unwrap().dash = Some(Dash { pattern: vec![12.0, 4.5], offset: 3.0, align_corners: false });
|
||||
put(&mut doc, n);
|
||||
let back = read_back(&doc);
|
||||
let st = back.layers[0].children().unwrap()[0].appearance.stroke().cloned().unwrap();
|
||||
assert!((st.width - 6.0).abs() < 1e-6, "{st:?}");
|
||||
let dash = st.dash.unwrap();
|
||||
assert!(dash.pattern.len() == 2 && (dash.pattern[0] - 12.0).abs() < 1e-6 && (dash.pattern[1] - 4.5).abs() < 1e-6, "{dash:?}");
|
||||
assert!((dash.offset - 3.0).abs() < 1e-6, "{dash:?}");
|
||||
}
|
||||
|
||||
/// The record is written in the order the reader reads it: on `%_` lines the group holding the
|
||||
/// grid, its dictionary with the options, the contents' block and the kind, then the distorted art
|
||||
/// on plain lines and the plugin's `XP`. While the contents are edited, the group holds them and
|
||||
@@ -10923,7 +11046,10 @@ fn envelopes_the_reader_cannot_open_live_are_written_as_their_art() {
|
||||
("fractional fidelity", fractional),
|
||||
("margin kept", margin_kept),
|
||||
];
|
||||
for (what, doc) in cases {
|
||||
// On a large canvas too.
|
||||
let large: Vec<(String, Document)> =
|
||||
cases.iter().map(|(what, doc)| (format!("{what}, on a large canvas"), on_large_canvas(doc.clone()))).collect();
|
||||
for (what, doc) in cases.into_iter().map(|(what, doc)| (what.to_string(), doc)).chain(large) {
|
||||
let text = program(&doc);
|
||||
assert!(!text.contains("AIDeformOptionsKey"), "{what}: {text}");
|
||||
let (back, warnings, _) = envelope_back(&doc);
|
||||
|
||||
@@ -27,7 +27,7 @@ use super::{MAX_NEST, Writer, Xy, hide};
|
||||
use crate::import::{DEFORM_PLUGIN, EnvelopeGridPoint as GridPoint, envelope_outline, envelope_upright, warp_number};
|
||||
use crate::ps;
|
||||
|
||||
pub(in crate::ai_editing) const ENVELOPES: &str = "envelopes whose type is threaded, has text wrap options or is written as its outlines, envelopes without contents, envelopes in opacity masks, pattern tiles, art cut to a clipping object or other envelopes' contents, envelopes on the layers of a large canvas or in a turned or mirrored frame, warps drawn without their style's net, meshes and top objects that the data would open in another shape, envelopes with a Fidelity that isn't a whole number, envelopes that map from a box other than their contents' bounds with or without strokes or keep bounds margins with Distort Appearance off, envelopes after the first 256 envelopes and images with a Warp, and envelopes nested more than 8 deep are written as their art in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const ENVELOPES: &str = "envelopes whose type is threaded, has text wrap options or is written as its outlines, envelopes without contents, envelopes in opacity masks, pattern tiles, art cut to a clipping object or other envelopes' contents, envelopes in a turned or mirrored frame, warps drawn without their style's net, meshes and top objects that the data would open in another shape, envelopes with a Fidelity that isn't a whole number, envelopes that map from a box other than their contents' bounds with or without strokes or keep bounds margins with Distort Appearance off, envelopes after the first 256 envelopes and images with a Warp, and envelopes nested more than 8 deep are written as their art in the editing data for other apps";
|
||||
|
||||
/// The most rows or columns of an envelope's grid written (Make with Mesh's own limit, and the
|
||||
/// reader's).
|
||||
@@ -356,15 +356,17 @@ fn top_object_grid(path: &PathData, corners: Option<[u32; 4]>) -> Option<(usize,
|
||||
|
||||
impl Writer<'_> {
|
||||
/// Envelope `n`, of transparency `xy`, as a live envelope (see the module's form), outside opacity
|
||||
/// masks' art, pattern tiles, art cut to a clipping object and the layers of a large canvas. Type
|
||||
/// in its contents is written as type, which the reader makes the envelope's contents again.
|
||||
/// masks' art, pattern tiles and art cut to a clipping object. On a large canvas it is written at
|
||||
/// the document's reduced size, its saved box size included, which the reader reads at the
|
||||
/// declared scale. Type in its contents is written as type, which the reader makes the
|
||||
/// envelope's contents again.
|
||||
/// False, writing nothing, where it is written as its art instead: where the reader would open it
|
||||
/// in another shape, or with its type as drawn art (threaded type, type with text wrap options,
|
||||
/// type written as its outlines), or some of it is left out for the object limit
|
||||
/// ([`Self::take_objects`]).
|
||||
pub(super) fn envelope(&mut self, n: &Node, xy: Xy) -> bool {
|
||||
let NodeKind::Envelope { content, kind, fidelity, editing, options, frame } = &n.kind else { return false };
|
||||
if self.hidden > 0 || self.clip.is_some() || self.nest >= MAX_NEST || !self.symbols_live || self.checks_left == 0 {
|
||||
if self.hidden > 0 || self.clip.is_some() || self.nest >= MAX_NEST || self.checks_left == 0 {
|
||||
return false;
|
||||
}
|
||||
if content.iter().any(|c| holds_type(c)) && !content.iter().all(|c| type_reads_back(c, self.doc)) {
|
||||
|
||||
@@ -121,11 +121,12 @@ pub(super) fn options(o: &Obj) -> Option<(EnvelopeOptions, f64)> {
|
||||
|
||||
/// The margins of `content` when the size the file saves for it (`AIDeformArtWidthKey`,
|
||||
/// `AIDeformArtHeightKey`) matches its bounds with its strokes within [`SAVED_SIZE_SLACK`] and lies
|
||||
/// nearer them than its geometric bounds. None without that size, or for contents with no width or
|
||||
/// no height.
|
||||
fn saved_margin(o: &Obj, content: &[Arc<Node>]) -> Option<[f32; 4]> {
|
||||
/// nearer them than its geometric bounds. The saved size is in art space, and `scale` takes it to the
|
||||
/// contents' space (a Large Canvas copy read at its declared scale). None without that size, or for
|
||||
/// contents with no width or no height.
|
||||
fn saved_margin(o: &Obj, content: &[Arc<Node>], scale: f64) -> Option<[f32; 4]> {
|
||||
let saved = |key: &str| match o.nums(key).as_slice() {
|
||||
[v] if v.is_finite() => Some(*v),
|
||||
[v] if v.is_finite() => Some(*v * scale).filter(|v| v.is_finite()),
|
||||
_ => None,
|
||||
};
|
||||
let (w, h) = (saved("AIDeformArtWidthKey")?, saved("AIDeformArtHeightKey")?);
|
||||
@@ -508,9 +509,10 @@ fn unwrapped(mut nodes: Vec<Node>) -> Vec<Arc<Node>> {
|
||||
}
|
||||
|
||||
/// The live envelope of dictionary `o`, the group on `%_` lines before it (`before`) and the art
|
||||
/// in its `AIDeformArtKey` block (`inner`); `None` where they don't make one.
|
||||
pub(super) fn live(o: &Obj, before: Option<Node>, inner: Vec<Node>) -> Option<NodeKind> {
|
||||
envelope_as(o, before, inner, false)
|
||||
/// in its `AIDeformArtKey` block (`inner`); `None` where they don't make one. `scale` takes sizes in
|
||||
/// art space to the space the art was read into ([`saved_margin`]).
|
||||
pub(super) fn live(o: &Obj, before: Option<Node>, inner: Vec<Node>, scale: f64) -> Option<NodeKind> {
|
||||
envelope_as(o, before, inner, false, scale)
|
||||
}
|
||||
|
||||
/// Is the envelope of dictionary `o` a warp?
|
||||
@@ -521,12 +523,12 @@ fn is_warp(o: &Obj) -> bool {
|
||||
/// [`live`] for a warp, as a mesh envelope on the grid its editing data saves (the mesh that shapes
|
||||
/// it), its points and handles as saved: it draws as that grid does, without the warp's style, bend
|
||||
/// and distortions. `None` for an envelope that isn't a warp, or whose grid doesn't read.
|
||||
fn live_on_saved_grid(o: &Obj, before: Option<Node>, inner: Vec<Node>) -> Option<NodeKind> {
|
||||
envelope_as(o, before, inner, true)
|
||||
fn live_on_saved_grid(o: &Obj, before: Option<Node>, inner: Vec<Node>, scale: f64) -> Option<NodeKind> {
|
||||
envelope_as(o, before, inner, true, scale)
|
||||
}
|
||||
|
||||
/// [`live`], or with `on_grid` [`live_on_saved_grid`].
|
||||
fn envelope_as(o: &Obj, before: Option<Node>, inner: Vec<Node>, on_grid: bool) -> Option<NodeKind> {
|
||||
fn envelope_as(o: &Obj, before: Option<Node>, inner: Vec<Node>, on_grid: bool, scale: f64) -> Option<NodeKind> {
|
||||
let editing = switch(o, "AIDeformEditModeKey")?;
|
||||
let (mut options, fidelity) = options(o)?;
|
||||
let before = before?;
|
||||
@@ -546,7 +548,7 @@ fn envelope_as(o: &Obj, before: Option<Node>, inner: Vec<Node>, on_grid: bool) -
|
||||
return None;
|
||||
}
|
||||
if options.distort_appearance {
|
||||
options.bounds_margin = saved_margin(o, &content).unwrap_or_default();
|
||||
options.bounds_margin = saved_margin(o, &content, scale).unwrap_or_default();
|
||||
}
|
||||
let kind = match (whole(o, "AIDeformStyle")??, on_grid) {
|
||||
(1, false) => warp(o)?,
|
||||
@@ -637,14 +639,15 @@ pub(super) struct WarpedLook {
|
||||
|
||||
/// An envelope of type read with its drawn art: its dictionary, the group on `%_` lines before it
|
||||
/// and the art in its `AIDeformArtKey` block, as [`live`] takes them (their text slots still
|
||||
/// empty), and the id of its drawn art in the document. Type is laid out after the layers are read,
|
||||
/// so it waits for that ([`WarpedType::settle_envelopes`]).
|
||||
/// empty), the id of its drawn art in the document, and the scale [`live`] takes. Type is laid out
|
||||
/// after the layers are read, so it waits for that ([`WarpedType::settle_envelopes`]).
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TypedEnvelope {
|
||||
pub(super) obj: Obj,
|
||||
pub(super) before: Option<Node>,
|
||||
pub(super) inner: Vec<Node>,
|
||||
pub(super) drawn: NodeId,
|
||||
pub(super) scale: f64,
|
||||
}
|
||||
|
||||
/// Why an envelope of type kept its drawn art.
|
||||
@@ -788,7 +791,7 @@ impl WarpedType {
|
||||
shown: &BTreeSet<NodeId>,
|
||||
waiting: usize,
|
||||
) -> Result<(NodeId, Vec<Node>), TypeKept> {
|
||||
let TypedEnvelope { obj, mut before, mut inner, drawn } = envelope;
|
||||
let TypedEnvelope { obj, mut before, mut inner, drawn, scale } = envelope;
|
||||
let art = doc.node(drawn).cloned().ok_or(TypeKept::Read)?;
|
||||
// The text slots in the contents, in the order the reader put their hidden copies in.
|
||||
let mut slots = vec![];
|
||||
@@ -813,13 +816,13 @@ impl WarpedType {
|
||||
}
|
||||
// A warp that VectorCraft's own warp doesn't draw as its drawn art may still draw as the
|
||||
// grid the file saves for it: then it opens as a mesh envelope on that grid.
|
||||
let on_grid = if is_warp(&obj) { live_on_saved_grid(&obj, before.clone(), inner.clone()) } else { None };
|
||||
let on_grid = if is_warp(&obj) { live_on_saved_grid(&obj, before.clone(), inner.clone(), scale) } else { None };
|
||||
// With Distort Appearance, a file's envelope may map its type from its glyphs grown by half
|
||||
// their strokes' weight or from the glyphs alone, and for type the size the file saves for
|
||||
// that box is often out of date (not the size of the type there now): each is checked.
|
||||
// After all of those, each is checked mapping from what its type paints, where that box is
|
||||
// another: it is measured only when such a check comes and one is left.
|
||||
let kinds: Vec<NodeKind> = live(&obj, before, inner).into_iter().chain(on_grid).collect();
|
||||
let kinds: Vec<NodeKind> = live(&obj, before, inner, scale).into_iter().chain(on_grid).collect();
|
||||
if kinds.is_empty() {
|
||||
return Err(TypeKept::Read);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use super::containers::close;
|
||||
use super::document::TEXT_SLOT;
|
||||
use super::raster::{self, Limits, Shape};
|
||||
use super::types::{
|
||||
FLIP, Frame, IMAGE_TOO_LARGE, Kind, LARGE_IMAGES, LINKED_PLACEHOLDERS, LINKED_PREVIEWS, MAX_PIXELS, MAX_PLACED_ELSEWHERE, MAX_POINTS, MAX_SIDE,
|
||||
NON_NATIVE_ART, NON_NATIVE_ART_UNREAD, PLACED_CROP, PLACED_PAGE, Place, PlacedPage, PlacedTail,
|
||||
FLIP, Frame, GState, IMAGE_TOO_LARGE, Kind, LARGE_IMAGES, LINKED_PLACEHOLDERS, LINKED_PREVIEWS, MAX_PIXELS, MAX_PLACED_ELSEWHERE, MAX_POINTS,
|
||||
MAX_SIDE, NON_NATIVE_ART, NON_NATIVE_ART_UNREAD, PLACED_CROP, PLACED_PAGE, Place, PlacedPage, PlacedTail,
|
||||
};
|
||||
use super::{
|
||||
Affine, AnchorKind, Appearance, AppearanceItem, Arc, BezPath, CANVAS_CENTRE, FillLayer, ImageBlob, ImageObject, Inks, Instance, LinkInfo, Node,
|
||||
@@ -224,12 +224,7 @@ impl<'a> Reader<'a> {
|
||||
items.push(AppearanceItem::Fill(FillLayer { overprint: gs.overprint_fill, ..FillLayer::new(fill_paint.unwrap_or(gs.fill.clone())) }));
|
||||
}
|
||||
if stroke {
|
||||
let mut st = StrokeLayer::new(stroke_paint.unwrap_or(gs.stroke.clone()), gs.line_width());
|
||||
st.cap = gs.cap;
|
||||
st.join = gs.join;
|
||||
st.miter_limit = gs.miter;
|
||||
st.dash = gs.dash.clone();
|
||||
st.overprint = gs.overprint_stroke;
|
||||
let st = self.stroke_layer(stroke_paint.unwrap_or(gs.stroke.clone()), &gs);
|
||||
items.push(AppearanceItem::Stroke(st));
|
||||
}
|
||||
let kind = NodeKind::Path { path, rule: gs.rule, live: None, clipping: clip, guide };
|
||||
@@ -330,17 +325,29 @@ impl<'a> Reader<'a> {
|
||||
if !matches!(n.kind, NodeKind::Path { .. }) || n.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(_))) {
|
||||
return;
|
||||
}
|
||||
let mut st = StrokeLayer::new(gs.stroke.clone(), gs.line_width());
|
||||
st.cap = gs.cap;
|
||||
st.join = gs.join;
|
||||
st.miter_limit = gs.miter;
|
||||
st.dash = gs.dash.clone();
|
||||
st.overprint = gs.overprint_stroke;
|
||||
let st = self.stroke_layer(gs.stroke.clone(), &gs);
|
||||
let Some(n) = self.frames.last_mut().and_then(|f| f.children.last_mut()) else { return };
|
||||
let mut a = (*n.appearance).clone();
|
||||
a.items.push(AppearanceItem::Stroke(st));
|
||||
n.appearance = a.into();
|
||||
}
|
||||
|
||||
/// A stroke of `paint` with graphics state `gs`'s weight, caps, joins, miter limit, dashes and
|
||||
/// overprint, its weight and dashes at the scale the art is read at ([`Self::space_scale`]).
|
||||
fn stroke_layer(&mut self, paint: Paint, gs: &GState) -> StrokeLayer {
|
||||
let k = self.space_scale();
|
||||
let mut st = StrokeLayer::new(paint, gs.line_width() * k);
|
||||
st.cap = gs.cap;
|
||||
st.join = gs.join;
|
||||
st.miter_limit = gs.miter;
|
||||
st.dash = gs.dash.clone().map(|mut d| {
|
||||
d.scale(k);
|
||||
d
|
||||
});
|
||||
st.overprint = gs.overprint_stroke;
|
||||
st
|
||||
}
|
||||
|
||||
pub(super) fn set_instance(&mut self, i: &Instance) {
|
||||
let mut to_doc = self.space();
|
||||
// In a pattern's definition a gradient's `Xm` and `Bm` are written y down about the canvas point of art space's
|
||||
|
||||
@@ -885,6 +885,7 @@ impl<'a> Reader<'a> {
|
||||
return;
|
||||
}
|
||||
let Some(p) = self.envelopes.pop() else { return };
|
||||
let scale = self.space_scale();
|
||||
let drawn = self.frames.last().filter(|f| f.children.len() == p.siblings + 1).and_then(|f| f.children.last());
|
||||
let Some(drawn) = drawn else {
|
||||
self.warn(crate::import::ai::envelope::drawn_note(p.typed));
|
||||
@@ -894,7 +895,7 @@ impl<'a> Reader<'a> {
|
||||
self.wait_for_type(p);
|
||||
return;
|
||||
}
|
||||
let live = (self.envelope_checks > 0).then(|| crate::import::ai::envelope::live(&p.obj, p.before, p.inner)).flatten();
|
||||
let live = (self.envelope_checks > 0).then(|| crate::import::ai::envelope::live(&p.obj, p.before, p.inner, scale)).flatten();
|
||||
let Some(kind) = live else {
|
||||
self.warn(crate::import::ai::envelope::DRAWN);
|
||||
return;
|
||||
@@ -982,8 +983,8 @@ impl Reader<'_> {
|
||||
self.warn(crate::import::ai::envelope::TYPE_DRAWN);
|
||||
return;
|
||||
}
|
||||
let drawn = drawn.id;
|
||||
self.typed_envelopes.push(crate::import::ai::envelope::TypedEnvelope { obj: p.obj, before: p.before, inner: p.inner, drawn });
|
||||
let (drawn, scale) = (drawn.id, self.space_scale());
|
||||
self.typed_envelopes.push(crate::import::ai::envelope::TypedEnvelope { obj: p.obj, before: p.before, inner: p.inner, drawn, scale });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -934,6 +934,13 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// How many times as long [`Self::space`] makes a length in art space: a Large Canvas copy's
|
||||
/// declared scale in the document, and 1 in a pattern's or a symbol's definition.
|
||||
pub(super) fn space_scale(&mut self) -> f64 {
|
||||
let k = self.space().determinant().abs().sqrt();
|
||||
if k.is_finite() && k > 0.0 { k } else { 1.0 }
|
||||
}
|
||||
|
||||
/// The space an image's matrix is in → where the art being read goes: [`Self::space`], and in a
|
||||
/// symbol's art (outside a pattern's definition) the canvas's space turned y up about art space's
|
||||
/// origin there, as an instance's matrix in it is; `None` there without a template box.
|
||||
|
||||
@@ -1797,6 +1797,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
SVG import keeps attributes in other applications' XML namespaces (`plotter:pen="2"`) on the objects and layers they belong to, as it keeps their `data-*` attributes: copies, duplicates and `.vectorcraft` files keep them, and SVG export writes them back with each namespace declared once on the root (the rest of #522; `crates/svg/tests/it/foreign_attributes.rs`, `tests/attributes.rs`).
|
||||
A PDF-compatible `.ai` saved with Include Editing Data for Other Apps defines every symbol in its editing copy with its art, registration point and place in the Symbols panel's order, and writes its instances as symbol instances, which VectorCraft's `.ai` reader opens as symbols and instances again (`symbols_and_their_instances_are_read_back` in `crates/eps/src/ai_editing/tests.rs`; [file-format-parity.md](file-format-parity.md) lists the instances written as their art).
|
||||
A PDF-compatible `.ai` saved with Include Editing Data for Other Apps keeps envelopes made with a warp, a mesh or a top object editable: its editing copy holds each envelope's contents, shape, Fidelity, Envelope Options and Edit Contents state in the form VectorCraft's `.ai` envelope reader reads, beside its distorted art, so the file opens with the same live envelope, Edit Contents still switching between the contents and the envelope ([Edit the contents of envelopes](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/edit-the-contents-of-envelopes.html)). Envelopes whose type is threaded, has text wrap options or is written as its outlines, envelopes in opacity masks, pattern tiles or another envelope's contents, and envelopes the reader would open with another shape or other settings (a Fidelity that isn't a whole number, bounds margins kept with Distort Appearance off), and envelopes after the first 256 envelopes and images with a Warp in a file are written as their distorted art, with a warning (`envelopes_are_read_back_live` and `envelopes_the_reader_cannot_open_live_are_written_as_their_art` in `crates/eps/src/ai_editing/tests.rs`).
|
||||
On a large canvas ([the help page](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/start-a-new-file/large-canvas-faq.html); VectorCraft writes one when the artboards together are wider or taller than 16,381 points, its own limit), that `.ai` keeps warp, mesh and top object envelopes editable too: the editing copy writes them live at 1/10 of their size with the rest of the art, and VectorCraft's `.ai` reader opens them at their size, from the editing data alone or beside the PDF part. Read from the editing data alone, an envelope's saved box size is compared with its contents at the same scale, so a bounds margin kept with Distort Appearance comes back, and every path's stroke weight, dashes and dash offset come back at their size, not at 1/10 (`large_canvas_envelope_kinds_round_trip_on_both_ai_routes`, `large_canvas_envelope_stroke_margin_round_trips_on_both_ai_routes` and `a_large_canvas_path_keeps_its_stroke_weight_and_dashes_read_alone` in `crates/eps/src/ai_editing/tests.rs`).
|
||||
An envelope whose contents hold type keeps the type editable in that `.ai`: the editing copy writes the type as type in the envelope's contents, in the form the `.ai` reader opens as a live envelope of type (`TypedEnvelope` in `crates/eps/src/import/ai/envelope.rs`), so the file opens with the type shown and editable in the envelope's contents, with Edit Contents off or on. An envelope of type in a symbol's art, and one whose type is threaded, has text wrap options or is written as its outlines (mirrored type, for example), is written as its distorted art, as before (`an_envelope_of_type_is_read_back_live_with_its_type`, `an_envelope_of_type_written_as_its_art_leaves_no_story` and `an_envelope_of_type_in_a_symbol_or_a_thread_is_written_as_its_art` in `crates/eps/src/ai_editing/tests.rs`).
|
||||
A top object whose top and bottom sides, or left and right sides, have different numbers of segments is also saved live: the side with fewer segments is split into as many as the side across from it has (each segment into equal spans of its curve, a straight one at even steps), up to the 50 a side the grid holds, so the file opens with the same corners and the same mapping of the contents, its outline holding the added anchors. Where the split side would share out the contents another way, as a side of two curves that aren't one curve can, or a side has more than 50 segments, the envelope is written as its distorted art, with the warning (`a_top_object_with_uneven_sides_is_read_back_live`, `a_top_object_split_to_the_grids_limit_is_read_back_live` and `a_top_object_whose_split_side_would_map_another_way_is_written_as_its_art` in `crates/eps/src/ai_editing/tests.rs`).
|
||||
A PDF-compatible `.ai` saved with Include Editing Data for Other Apps writes eligible paths, compound paths and groups with live effects with an art style when the writer supports their appearance and effects (not a filled path that uses the even-odd rule, and none on a large canvas), which VectorCraft's `.ai` reader opens as the same appearance with its effects live (`objects_with_live_effects_are_read_back` and `every_effect_setting_written_on_an_object_is_read_back` in `crates/eps/src/ai_editing/tests.rs`; [file-format-parity.md](file-format-parity.md) lists the objects written without one and the effects they lose).
|
||||
|
||||
Reference in New Issue
Block a user