mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 19:56:47 +00:00
Export: live effects in symbol art apply in EMF, WMF and SVG
EMF, WMF and SVG wrote a symbol instance from its symbol's art as stored, so live effects inside that art were missing: a square moved 100 pt by a Transform effect stayed in place in the file while the canvas drew it moved. Art whose own place is off the artboard was left out even when the effect moved it onto it. These exports now call bake_document_placing_symbols, as PDF, print, EPS and DXF do: each instance of a symbol whose art needs baking is written as that art placed by the instance and then baked, so an instance that scales or turns its art does not scale what its effects do. EMF and SVG clip 9-slice cells and WMF does not, as each places other instances. In SVG those instances are written as groups; instances of symbols without such effects still share one <symbol>. Preserve Editing still embeds the document with its live effects. WrittenLayers gains hidden_objects. SVG sets it with Hidden Layers on, since it then writes hidden objects too, so a hidden instance is written hidden with its effects applied. The other exporters leave it off. An SVG instance nested in another instance's art was shared through <use> when the def allowed its own transform, while the <use> writes that transform after the outer instances'. A stroked symbol nested in a scaled instance then drew its stroke at double weight. The check now uses the transform the <use> writes.
This commit is contained in:
+14
-10
@@ -162,7 +162,7 @@ struct Placing {
|
||||
layers: WrittenLayers,
|
||||
}
|
||||
|
||||
/// The layers an exporter writes besides the shown, printing ones
|
||||
/// The layers and objects an exporter writes besides the shown, printing ones
|
||||
/// ([`bake_document_placing_symbols`]). Template layers are never written.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct WrittenLayers {
|
||||
@@ -170,16 +170,19 @@ pub struct WrittenLayers {
|
||||
pub hidden: bool,
|
||||
/// Layers that do not print.
|
||||
pub non_printing: bool,
|
||||
/// Hidden objects other than layers (written hidden, as SVG writes them when it keeps hidden
|
||||
/// layers).
|
||||
pub hidden_objects: bool,
|
||||
}
|
||||
|
||||
/// Does the export leave `n` and everything in it out, while [`bake_document_placing_symbols`]
|
||||
/// bakes? A hidden object other than a layer, a template layer, and a hidden layer or a layer
|
||||
/// bakes? A template layer, and a hidden object other than a layer, a hidden layer or a layer
|
||||
/// that does not print when the export leaves those out ([`WrittenLayers`]).
|
||||
fn unwritten(n: &Node) -> bool {
|
||||
PLACING.with(|p| {
|
||||
p.borrow().as_ref().is_some_and(|p| match n.kind {
|
||||
NodeKind::Layer { template, printable, .. } => template || !(printable || p.layers.non_printing) || !(n.visible || p.layers.hidden),
|
||||
_ => !n.visible,
|
||||
_ => !(n.visible || p.layers.hidden_objects),
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1014,13 +1017,14 @@ pub fn bake_document(doc: &Document) -> Option<Document> {
|
||||
/// (live geometry effects, color adjustments and the rest [`needs_bake`] counts, in its own art or
|
||||
/// in the art of the symbols it places) replaced by that art as the instance places it, baked
|
||||
/// ([`placed_symbol_art`]), so the art draws as on the canvas wherever the instance is. For
|
||||
/// exporters that write each instance's art in its place (PDF, print, EPS, DXF), rather than
|
||||
/// writing each symbol once. `clip_slices`: whether 9-slice cells are clipped
|
||||
/// ([`Document::place_symbol_art`]) or not ([`Document::place_symbol_art_unclipped`]), as the
|
||||
/// exporter places other instances. `layers`: the hidden layers and layers that do not print
|
||||
/// that the exporter writes. Instances the export does not write (hidden ones, those in hidden
|
||||
/// objects, on template layers, and on the layers `layers` leaves out) stay as they are. The
|
||||
/// symbols' own art is left as it is.
|
||||
/// exporters that write each instance's art in its place (PDF, print, EPS, DXF, EMF, WMF), and
|
||||
/// for SVG, which writes the instances of other symbols as one shared definition. `clip_slices`:
|
||||
/// whether 9-slice cells are clipped ([`Document::place_symbol_art`]) or not
|
||||
/// ([`Document::place_symbol_art_unclipped`]), as the exporter places other instances. `layers`:
|
||||
/// the hidden layers, layers that do not print and hidden objects that the exporter writes.
|
||||
/// Instances the export does not write (template layers, and the hidden objects and layers
|
||||
/// `layers` leaves out, with what is in them) stay as they are. The symbols' own art is left as
|
||||
/// it is.
|
||||
pub fn bake_document_placing_symbols(doc: &Document, clip_slices: bool, layers: WrittenLayers) -> Option<Document> {
|
||||
bake(doc, Some((clip_slices, vectorcraft_doc::MAX_SYMBOL_NODES, layers)))
|
||||
}
|
||||
|
||||
@@ -1328,7 +1328,7 @@ fn placing_symbols_keeps_the_instances_stain() {
|
||||
}
|
||||
|
||||
/// Every layer written, as DXF writes them (template layers are never written).
|
||||
const ALL: WrittenLayers = WrittenLayers { hidden: true, non_printing: true };
|
||||
const ALL: WrittenLayers = WrittenLayers { hidden: true, non_printing: true, hidden_objects: false };
|
||||
|
||||
fn is_instance(d: &Document, id: u64) -> bool {
|
||||
d.node(NodeId(id)).is_some_and(|n| matches!(n.kind, NodeKind::SymbolInstance { .. }))
|
||||
@@ -1455,10 +1455,20 @@ fn placing_symbols_skips_instances_the_export_leaves_out() {
|
||||
}
|
||||
// An export that writes the layers that do not print, or the hidden layers, places that
|
||||
// layer's instance first; the template layer's instance is never placed.
|
||||
for (layers, first) in [(WrittenLayers { non_printing: true, hidden: false }, 921), (WrittenLayers { non_printing: false, hidden: true }, 931)] {
|
||||
for (layers, first) in
|
||||
[(WrittenLayers { non_printing: true, ..WrittenLayers::default() }, 921), (WrittenLayers { hidden: true, ..WrittenLayers::default() }, 931)]
|
||||
{
|
||||
let out = bake(&d, Some((true, each, layers))).unwrap();
|
||||
assert!(!is_instance(&out, first) && is_instance(&out, 900) && is_instance(&out, 911), "{layers:?}");
|
||||
}
|
||||
// An export that writes hidden objects (SVG keeping hidden layers) places the hidden instance
|
||||
// first, and the instance in the hidden group would come next; the hidden layer's instance
|
||||
// stays, since that layer is still left out.
|
||||
let out = bake(&d, Some((true, each, WrittenLayers { hidden_objects: true, ..WrittenLayers::default() }))).unwrap();
|
||||
assert!(!is_instance(&out, 901), "the hidden instance is placed");
|
||||
for id in [900, 903, 911, 921, 931] {
|
||||
assert!(is_instance(&out, id), "{id} stays as it is");
|
||||
}
|
||||
}
|
||||
|
||||
/// `leaf` in `levels` groups, with ids from `id` up.
|
||||
|
||||
Reference in New Issue
Block a user