Merge pull request #7979 from dotCooCoo/fix/flatten-kept-roots-walked-once

Flatten: look at each node of art without transparency once
This commit is contained in:
BFlat
2026-11-16 08:11:11 +07:00
committed by GitHub
6 changed files with 400 additions and 64 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ use vectorcraft_render::effects;
use super::edit::roots_of;
use super::menucmds::{MAX_PIXELS, isolated_doc, unique_key};
use super::pathops::{node_path, outline_strokes, outline_strokes_under, separate, shape_node};
use super::pathops::{leaves, node_path, outline_strokes, separate, shape_node};
use super::{CommandSpec, EngineError, Result, Session, always, bad, bool_or, cmd, has_doc, str_param, targets, unique_name};
mod analysis;
+390 -50
View File
@@ -1,9 +1,11 @@
use std::collections::HashSet;
use super::analysis::{Scratch, finite, flatten_groups, has_effects, masked, outlined_text, overlapping, painted, reach};
use super::compose::{Builder, CLEAR, Composer, Elem, Fill, Kind, Px, WHITE};
use super::options::FlattenOptions;
use super::{
Affine, Appearance, AppearanceItem, Arc, BlendMode, Color, ColorMode, Document, EngineError, FillLayer, FillRule, ImageBlob, ImageObject, Inks,
MAX_PIXELS, Node, NodeId, NodeKind, Paint, PathData, Rect, Result, composite, effects, isolated_doc, outline_strokes_under, planes_cmyk, po,
MAX_PIXELS, Node, NodeId, NodeKind, Paint, PathData, Rect, Result, composite, effects, isolated_doc, leaves, outline_strokes, planes_cmyk, po,
separate, shape_node, shapes, unique_key,
};
@@ -14,6 +16,8 @@ pub(super) struct Plan {
pub(super) flat: Vec<Flat>,
/// Objects without transparency (they stay, but for the outline options).
pub(super) kept: Vec<NodeId>,
/// What the outline and overprint options do to each of `kept`, in its order.
pub(super) work: Vec<Kept>,
/// The objects with transparency of their own.
pub(super) transparent: Vec<NodeId>,
}
@@ -112,7 +116,12 @@ pub(super) fn plan(src: &Document, roots: &[NodeId], o: &FlattenOptions, render:
let reaches: Vec<Option<Rect>> = plain.iter().zip(&clipped).map(|(n, c)| reach(n).zip(reach(c)).map(|(a, b)| a.intersect(b))).collect();
let see_through: Vec<bool> = plain.iter().map(|n| o.shows_transparency(&baked, n) || o.draws_see_through_image(n)).collect();
let cmyk = src.color_mode == ColorMode::Cmyk;
let mut out = Plan { flat: vec![], kept: vec![], transparent: roots.iter().zip(&see_through).filter(|(_, t)| **t).map(|(id, _)| *id).collect() };
let mut out = Plan {
flat: vec![],
kept: vec![],
work: vec![],
transparent: roots.iter().zip(&see_through).filter(|(_, t)| **t).map(|(id, _)| *id).collect(),
};
// Baking above stopped early when cancelled; each group is a place to stop (a plan changes nothing).
vectorcraft_doc::cancel::check()?;
let mut queue = groups(src, roots, &plain, &reaches, &see_through, o)?;
@@ -193,9 +202,101 @@ pub(super) fn plan(src: &Document, roots: &[NodeId], o: &FlattenOptions, render:
};
out.flat.push(Flat { roots: ids, regions, area, raster, lines });
}
out.work = out.kept.iter().map(|id| Kept::of(src, *id, o)).collect();
Ok(out)
}
/// What the outline and overprint options do to one object without transparency, found in one
/// walk of it.
pub(super) struct Kept {
pub(super) id: NodeId,
/// Whether the options change it.
pub(super) changes: bool,
/// The type the text option outlines and the stroked paths the stroke option outlines, those
/// that show and are not pieces of a compound path: what the Flattener Preview highlights.
pub(super) shown_text: Vec<NodeId>,
pub(super) shown_strokes: Vec<NodeId>,
/// In paint order: the type the text option outlines and the leaf shapes ([`leaves`]) other
/// than type that the stroke option outlines.
steps: Vec<Step>,
/// The objects with overprints, each with the type or leaf shape that holds it (itself
/// included) when a step replaces that.
overprinted: Vec<(NodeId, Option<NodeId>)>,
}
/// One object [`apply`] outlines.
enum Step {
/// Type; `leaf`: only groups and layers hold it, so its outlines are leaf shapes for the
/// stroke option.
Text { id: NodeId, leaf: bool },
/// A leaf shape other than type.
Leaf(NodeId),
}
/// Where [`Kept::visit`] is in the object it walks.
#[derive(Clone, Copy)]
struct At {
/// Neither the node nor what holds it is hidden, and it is not a piece of a compound path.
shown: bool,
/// Only groups and layers hold the node.
leaf: bool,
/// The type or leaf shape holding the node that a step replaces.
holder: Option<NodeId>,
}
impl Kept {
/// What the options `o` do to `root` of `d`: nothing when `d` doesn't hold it.
fn of(d: &Document, root: NodeId, o: &FlattenOptions) -> Kept {
let mut k = Kept { id: root, changes: false, shown_text: vec![], shown_strokes: vec![], steps: vec![], overprinted: vec![] };
if let Some(n) = d.node(root) {
k.visit(n, o, At { shown: true, leaf: true, holder: None });
}
k
}
/// Note what the options `o` do to `n` and to everything under it.
fn visit(&mut self, n: &Node, o: &FlattenOptions, at: At) {
kept_seen(n);
let shown = at.shown && n.visible;
let mut holder = at.holder;
if matches!(n.kind, NodeKind::Text(_)) {
if o.text_to_outlines {
self.changes = true;
if shown {
self.shown_text.push(n.id);
}
self.steps.push(Step::Text { id: n.id, leaf: at.leaf });
holder = Some(n.id);
}
} else {
if o.strokes_to_outlines && stroked(n) {
self.changes = true;
if shown {
self.shown_strokes.push(n.id);
}
}
if o.strokes_to_outlines && at.leaf && matches!(n.kind, NodeKind::Path { guide: false, clipping: false, .. } | NodeKind::Compound { .. })
{
self.steps.push(Step::Leaf(n.id));
holder = Some(n.id);
}
}
if !o.preserve_overprints && overprints(n) {
self.changes = true;
self.overprinted.push((n.id, holder));
}
let Some(children) = n.children() else { return };
let inside = At {
shown: shown && !matches!(n.kind, NodeKind::Compound { .. }),
leaf: at.leaf && matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }),
holder,
};
for c in children {
self.visit(c, o, inside);
}
}
}
/// `roots` of `src` (`plain`: as plain art; `reaches`: where each can paint, clipped) in the
/// groups that flatten together ([`flatten_groups`]), each in paint order, by their first object.
/// Objects that overlap (as [`overlapping`] groups them) stay in one group when one of them is
@@ -668,7 +769,7 @@ pub(crate) fn flatten_expanded(doc: &Document, o: &FlattenOptions) -> Result<Opt
roots.extend(children.iter().skip(usize::from(l.clips())).filter(|c| c.visible && !c.is_ruler_guide()).map(|c| c.id));
}
let plan = plan(doc, &roots, o, true)?;
if plan.flat.is_empty() && !plan.kept.iter().any(|id| doc.node(*id).is_some_and(|n| kept_work(n, o))) {
if plan.flat.is_empty() && !plan.work.iter().any(|k| k.changes) {
return Ok(None);
}
let mut d = doc.clone();
@@ -753,19 +854,8 @@ pub(super) fn apply(d: &mut Document, sel: &mut vectorcraft_doc::Selection, plan
d.insert(Some(layer), usize::MAX, guide)?;
}
let brushes = if o.strokes_to_outlines { vectorcraft_brush::library(d) } else { vec![] };
for mut id in plan.kept {
if o.text_to_outlines {
id = outline_texts_under(d, id)?;
}
if o.strokes_to_outlines {
id = outline_strokes_under(d, &brushes, id)?.0;
}
if !o.preserve_overprints
&& let Some(n) = d.node_mut(id)
{
drop_overprints(n);
}
ids.push(id);
for k in plan.work {
ids.push(outline_kept(d, &brushes, k, o)?);
}
ids.sort_by_key(|id| d.index_path(*id));
sel.set(ids.iter().copied());
@@ -838,6 +928,21 @@ fn guide_seen(n: &Node) {
#[cfg(not(test))]
fn guide_seen(_: &Node) {}
#[cfg(test)]
thread_local! {
/// The nodes that [`Kept::of`] has looked at on this thread, in order.
static KEPT_SEEN: std::cell::RefCell<Vec<NodeId>> = const { std::cell::RefCell::new(Vec::new()) };
}
/// Note that [`Kept::of`] looked at `n`.
#[cfg(test)]
fn kept_seen(n: &Node) {
KEPT_SEEN.with(|s| s.borrow_mut().push(n.id));
}
#[cfg(not(test))]
fn kept_seen(_: &Node) {}
/// An image of `r` (in a clip group when it is clipped).
fn raster_node(d: &mut Document, r: Raster) -> Node {
let key = unique_key(d, "flattened");
@@ -858,38 +963,65 @@ fn raster_node(d: &mut Document, r: Raster) -> Node {
crate::cmd::rasterfx::clip_group(d, path, FillRule::NonZero, image)
}
/// Replace the type under `root` by its outlines: → the id now standing for `root`.
fn outline_texts_under(d: &mut Document, root: NodeId) -> Result<NodeId> {
let mut texts = vec![];
if let Some(n) = d.node(root) {
n.walk(&mut |c| {
if matches!(c.kind, NodeKind::Text(_)) {
texts.push(c.clone());
/// Do what [`Kept`] `k` found to its object of `d` (`brushes`: the document's brushes, for the
/// stroke option): its type outlined, then the strokes of its leaf shapes, the outlines of its
/// type included, then its overprints dropped. → the id now standing for the object.
fn outline_kept(d: &mut Document, brushes: &[vectorcraft_brush::Brush], k: Kept, o: &FlattenOptions) -> Result<NodeId> {
let mut root = k.id;
let mut replaced = HashSet::new();
let dropping = !o.preserve_overprints;
// Each replacement loses its overprints before it goes in: no new object is looked up.
let mut put = |d: &mut Document, old: NodeId, mut new: Node, root: &mut NodeId| -> Result<()> {
if dropping {
drop_overprints(&mut new);
}
let nid = new.id;
*d.node_mut(old).ok_or(EngineError::NoNode(old))? = new;
replaced.insert(old);
if old == *root {
*root = nid;
}
Ok(())
};
// The leaf shapes of each outlined type that only groups and layers hold, by step.
let mut outlined: Vec<Vec<Node>> = Vec::with_capacity(k.steps.len());
for step in &k.steps {
let mut lv = vec![];
if let Step::Text { id, leaf } = *step
&& let Some(out) = d.node(id).and_then(outlined_text)
{
let out = d.reid(&out);
if leaf && o.strokes_to_outlines {
leaves(&out, &mut lv);
}
});
put(d, id, out, &mut root)?;
}
outlined.push(lv);
}
let mut out = root;
for t in texts {
let Some(o) = outlined_text(&t) else { continue };
let o = d.reid(&o);
let nid = o.id;
*d.node_mut(t.id).ok_or(EngineError::NoNode(t.id))? = o;
if t.id == root {
out = nid;
if o.strokes_to_outlines {
for (step, lv) in k.steps.iter().zip(outlined) {
let shapes = match *step {
Step::Leaf(id) => d.node(id).cloned().into_iter().collect(),
Step::Text { .. } => lv,
};
for l in shapes.iter().filter(|l| !matches!(l.kind, NodeKind::Text(_))) {
if let Some(new) = outline_strokes(d, brushes, l) {
put(d, l.id, new, &mut root)?;
}
}
}
}
Ok(out)
}
/// Whether the outline and overprint options change `n`, an object without transparency.
pub(super) fn kept_work(n: &Node, o: &FlattenOptions) -> bool {
let mut any = false;
n.walk(&mut |c| {
any |= (o.text_to_outlines && matches!(c.kind, NodeKind::Text(_)))
|| (o.strokes_to_outlines && stroked(c))
|| (!o.preserve_overprints && overprints(c));
});
any
if dropping {
for (id, holder) in k.overprinted {
if holder.is_some_and(|h| replaced.contains(&h)) {
continue;
}
if let Some(n) = d.node_mut(id) {
drop_own_overprints(n);
}
}
}
Ok(root)
}
/// Whether `n` is a path with a visible stroke (outlining turns it into a fill).
@@ -898,12 +1030,8 @@ pub(super) fn stroked(n: &Node) -> bool {
&& n.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(s) if s.visible && !s.paint.is_none() && s.width > 0.0))
}
fn overprints(n: &Node) -> bool {
n.appearance.items.iter().any(AppearanceItem::overprint)
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(|r| r.style.overprint_fill || r.style.overprint_stroke))
}
fn drop_overprints(n: &mut Node) {
/// Drop the overprints of `n` itself.
fn drop_own_overprints(n: &mut Node) {
if overprints(n) {
for i in &mut n.appearance.items {
*i.overprint_mut() = false;
@@ -914,6 +1042,16 @@ fn drop_overprints(n: &mut Node) {
}
}
}
}
fn overprints(n: &Node) -> bool {
n.appearance.items.iter().any(AppearanceItem::overprint)
|| matches!(&n.kind, NodeKind::Text(t) if t.runs.iter().any(|r| r.style.overprint_fill || r.style.overprint_stroke))
}
/// Drop the overprints of `n` and of everything under it.
fn drop_overprints(n: &mut Node) {
drop_own_overprints(n);
if let Some(ch) = n.children_mut() {
for c in ch {
drop_overprints(Arc::make_mut(c));
@@ -994,6 +1132,208 @@ mod tests {
assert_eq!(run(&[deep, deep]).0, vec![(sub, g2), (sub, g2)]);
}
/// The objects [`kept_session`] makes.
struct KeptArt {
/// Each group with its stroked rectangle (its fill overprints) and its stroked type.
groups: Vec<(NodeId, NodeId, NodeId)>,
/// A stroked rectangle and stroked type with an overprint, on their own.
rect: NodeId,
text: NodeId,
/// A stroked compound path and its pieces.
compound: NodeId,
pieces: Vec<NodeId>,
/// A group holding an unstroked rectangle and a hidden stroked rectangle.
hidden_group: NodeId,
hidden: NodeId,
/// An unstroked rectangle.
plain: NodeId,
}
/// A document without transparency: `n` groups, then the other objects of [`KeptArt`].
fn kept_session(n: usize) -> (Session, KeptArt) {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
let id = |v: serde_json::Value| NodeId(v["id"].as_u64().unwrap());
let rect = |s: &mut Session, x: f64| id(s.execute("shape.rectangle", &json!({"x": x, "y": 10, "width": 20, "height": 20})).unwrap());
let text = |s: &mut Session, x: f64| {
let t = id(s.execute("text.create", &json!({"x": x, "y": 80, "text": "Hi", "size": 24})).unwrap());
s.execute("paint.setStroke", &json!({"color": "#000000", "ids": [t.0]})).unwrap();
t
};
let select = |s: &mut Session, ids: &[NodeId]| {
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
};
let overprint = |s: &mut Session, on: NodeId| {
s.execute("attributes.set", &json!({"ids": [on.0], "overprintFill": true})).unwrap();
};
let unstroked = |s: &mut Session, on: NodeId| {
s.execute("paint.setStroke", &json!({"none": true, "ids": [on.0]})).unwrap();
};
let mut groups = vec![];
for i in 0..n {
let x = (i % 10) as f64 * 30.0;
let (r, t) = (rect(&mut s, x), text(&mut s, x));
overprint(&mut s, r);
select(&mut s, &[r, t]);
groups.push((id(s.execute("object.group", &json!({})).unwrap()), r, t));
}
let (r, t) = (rect(&mut s, 0.0), text(&mut s, 100.0));
overprint(&mut s, t);
let (a, b) = (rect(&mut s, 200.0), rect(&mut s, 210.0));
select(&mut s, &[a, b]);
let compound = id(s.execute("object.compoundPath.make", &json!({})).unwrap());
s.execute("paint.setStroke", &json!({"color": "#000000", "ids": [compound.0]})).unwrap();
let pieces = s.doc().unwrap().doc.node(compound).unwrap().children().unwrap().iter().map(|c| c.id).collect();
let (shown, hidden) = (rect(&mut s, 300.0), rect(&mut s, 310.0));
unstroked(&mut s, shown);
select(&mut s, &[shown, hidden]);
let hidden_group = id(s.execute("object.group", &json!({})).unwrap());
s.execute("object.hide", &json!({"ids": [hidden.0]})).unwrap();
let plain = rect(&mut s, 350.0);
unstroked(&mut s, plain);
(s, KeptArt { groups, rect: r, text: t, compound, pieces, hidden_group, hidden, plain })
}
/// Every option on: type and strokes outlined, overprints dropped.
fn outlining() -> FlattenOptions {
FlattenOptions { text_to_outlines: true, strokes_to_outlines: true, preserve_overprints: false, ..FlattenOptions::default() }
}
/// The top-level objects of `d`'s first layer, in paint order.
fn top_level(d: &Document) -> Vec<NodeId> {
d.layers[0].children().unwrap().iter().map(|c| c.id).collect()
}
fn sorted(mut ids: Vec<NodeId>) -> Vec<NodeId> {
ids.sort();
ids
}
/// The nodes [`Kept::of`] looked at while `f` ran, sorted.
fn kept_seen_by(f: impl FnOnce()) -> Vec<NodeId> {
KEPT_SEEN.with(|v| v.borrow_mut().clear());
f();
sorted(KEPT_SEEN.with(|v| v.take()))
}
/// The Flattener Preview, `object.flattenTransparency` and flattening a whole document each look
/// at every node of the objects without transparency once, with type and strokes outlined and
/// overprints dropped, an object they leave as it is included.
#[test]
fn kept_objects_are_looked_at_once() {
let (mut s, _) = kept_session(100);
let o = outlining();
let doc = s.doc().unwrap().doc.clone();
let roots = top_level(&doc);
let mut nodes = vec![];
for r in &roots {
doc.node(*r).unwrap().walk(&mut |c| nodes.push(c.id));
}
nodes.sort();
assert_eq!(nodes.len(), 309);
let preview = kept_seen_by(|| drop(super::super::report::report(&doc, &roots, &o).unwrap()));
assert!(preview == nodes, "the preview looked at {} nodes of {}", preview.len(), nodes.len());
let whole = kept_seen_by(|| drop(flatten_document(&doc, &o).unwrap().unwrap()));
assert!(whole == nodes, "flattening the document looked at {} nodes of {}", whole.len(), nodes.len());
let ids: Vec<u64> = roots.iter().map(|r| r.0).collect();
let command = kept_seen_by(|| {
s.execute(
"object.flattenTransparency",
&json!({"ids": ids, "textToOutlines": true, "strokesToOutlines": true, "preserveOverprints": false}),
)
.unwrap();
});
assert!(command == nodes, "object.flattenTransparency looked at {} nodes of {}", command.len(), nodes.len());
}
/// [`apply`]'s outlining of `kept` (objects of `d` without transparency) with `o`, done as a
/// walk of each object for each option: → the ids standing for them, in paint order.
fn outlined_walk_by_walk(d: &mut Document, kept: &[NodeId], o: &FlattenOptions) -> Vec<NodeId> {
let brushes = if o.strokes_to_outlines { vectorcraft_brush::library(d) } else { vec![] };
let mut ids = vec![];
for &root in kept {
let mut id = root;
if o.text_to_outlines {
let mut texts = vec![];
d.node(id).unwrap().walk(&mut |c| {
if matches!(c.kind, NodeKind::Text(_)) {
texts.push(c.clone());
}
});
for t in texts {
let Some(out) = outlined_text(&t) else { continue };
let out = d.reid(&out);
if t.id == root {
id = out.id;
}
*d.node_mut(t.id).unwrap() = out;
}
}
if o.strokes_to_outlines {
id = crate::cmd::pathops::outline_strokes_under(d, &brushes, id).unwrap().0;
}
if !o.preserve_overprints {
drop_overprints(d.node_mut(id).unwrap());
}
ids.push(id);
}
ids.sort_by_key(|id| d.index_path(*id));
ids
}
/// With each mix of the text, stroke and overprint options, the objects without transparency
/// end as a walk of each of them for each option leaves them: the same art, ids and selection.
#[test]
fn kept_objects_change_as_a_walk_per_option_changes_them() {
let (s, _) = kept_session(3);
let doc = Document::clone(&s.doc().unwrap().doc);
let roots = top_level(&doc);
for bits in 0..8u8 {
let o = FlattenOptions {
text_to_outlines: bits & 1 != 0,
strokes_to_outlines: bits & 2 != 0,
preserve_overprints: bits & 4 != 0,
..FlattenOptions::default()
};
let p = plan(&doc, &roots, &o, true).unwrap();
assert!(p.flat.is_empty(), "{o:?}");
// In the order the plan's groups come in.
let kept = p.kept.clone();
assert_eq!(sorted(kept.clone()), sorted(roots.clone()), "{o:?}");
let mut once = doc.clone();
let mut sel = vectorcraft_doc::Selection::default();
let (ids, ..) = apply(&mut once, &mut sel, p, &o).unwrap();
let mut walked = doc.clone();
let want = outlined_walk_by_walk(&mut walked, &kept, &o);
assert_eq!(ids, want, "{o:?}");
assert!(once == walked, "{o:?}");
assert_eq!(once == doc, bits == 4, "{o:?}: only with every option off does nothing change");
}
}
/// The Flattener Preview lists the kept objects the options change, and of those the type and
/// the stroked paths that show and are not pieces of a compound path.
#[test]
fn the_preview_lists_what_the_options_change_in_kept_objects() {
let (s, a) = kept_session(2);
let doc = &s.doc().unwrap().doc;
let roots = top_level(doc);
let r = super::super::report::report(doc, &roots, &outlining()).unwrap();
let (g, rects, texts): (Vec<_>, Vec<_>, Vec<_>) =
(a.groups.iter().map(|g| g.0).collect(), a.groups.iter().map(|g| g.1).collect(), a.groups.iter().map(|g| g.2).collect());
assert_eq!(r.affected, [g.clone(), vec![a.rect, a.text, a.compound, a.hidden_group]].concat());
// Both lists come in the order the plan's groups do.
assert_eq!(sorted(r.text.clone()), sorted([texts, vec![a.text]].concat()));
assert_eq!(sorted(r.strokes.clone()), sorted([rects, vec![a.rect, a.compound]].concat()));
assert!(!r.strokes.contains(&a.hidden) && !r.strokes.iter().any(|id| a.pieces.contains(id)) && !r.affected.contains(&a.plain));
// Dropping overprints alone changes the objects that overprint.
let o = FlattenOptions { preserve_overprints: false, ..FlattenOptions::default() };
let r = super::super::report::report(doc, &roots, &o).unwrap();
assert_eq!((r.affected, r.text, r.strokes), ([g, vec![a.text]].concat(), vec![], vec![]));
// With every option off, nothing.
assert!(super::super::report::report(doc, &roots, &FlattenOptions::default()).unwrap().affected.is_empty());
}
/// In a file without transparency with Clip Complex Regions on, art under a group's opaque
/// image within one of its pixels joins the group, also where a long image is made at a lower
/// resolution and its pixels are wider than at the preset's.
+2 -2
View File
@@ -1,5 +1,5 @@
use super::analysis::draws_image;
use super::apply::{apply, kept_work, plan};
use super::apply::{apply, plan};
use super::presets::{FlattenerPreset, saved_preset};
use super::report::target_roots;
use super::{BTreeSet, Deserialize, Document, EngineError, Node, NodeKind, Paint, Result, Serialize, Session, Value, bad, json, str_param};
@@ -194,7 +194,7 @@ pub(super) fn flatten(s: &mut Session, p: &Value) -> Result<Value> {
let plan = plan(&src, &roots, &o, true)?;
let warning = crate::cmd::rasterfx::undecoded_warning(failed);
let options = serde_json::to_value(&o).unwrap_or_default();
if plan.flat.is_empty() && !plan.kept.iter().any(|id| src.node(*id).is_some_and(|n| kept_work(n, &o))) {
if plan.flat.is_empty() && !plan.work.iter().any(|k| k.changes) {
return Ok(json!({ "ids": roots.iter().map(|i| i.0).collect::<Vec<_>>(), "rasterized": 0, "vector": 0, "options": options }));
}
let (ids, vector, rasterized) = s.edit("Flatten Transparency", |d, sel| {
+5 -10
View File
@@ -1,4 +1,4 @@
use super::apply::{kept_work, opaque, plan, stroked};
use super::apply::{opaque, plan, stroked};
use super::options::FlattenOptions;
use super::{
Appearance, Color, Deserialize, Document, Node, NodeId, NodeKind, Paint, PathData, Rect, Result, Serialize, Session, Value, bad, isolated_doc,
@@ -263,15 +263,10 @@ pub fn report(doc: &Document, roots: &[NodeId], o: &FlattenOptions) -> Result<Fl
r.rasterized.push(a.outline());
}
}
for root in plan.kept.iter().filter_map(|id| doc.node(*id)).filter(|n| kept_work(n, o)) {
r.affected.push(root.id);
visit(root, &mut |n| {
if o.text_to_outlines && matches!(n.kind, NodeKind::Text(_)) {
r.text.push(n.id);
} else if o.strokes_to_outlines && stroked(n) {
r.strokes.push(n.id);
}
});
for k in plan.work.iter().filter(|k| k.changes) {
r.affected.push(k.id);
r.text.extend(&k.shown_text);
r.strokes.extend(&k.shown_strokes);
}
r.affected.sort_by_key(|id| doc.index_path(*id));
Ok(r)
+1 -1
View File
@@ -318,7 +318,7 @@ pub(crate) fn style_of(n: &Node) -> Style {
/// Leaf shapes (paths, compound paths, text) of a subtree in paint order; guides and clipping
/// paths are skipped.
fn leaves(n: &Node, out: &mut Vec<Node>) {
pub(crate) fn leaves(n: &Node, out: &mut Vec<Node>) {
each_leaf(n, &mut |l| out.push(l.clone()));
}
+1
View File
@@ -1465,6 +1465,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Select › Object › All on Same Layers takes the layers only of the selected objects that can be selected: an object that is hidden or locked, on a template layer, on a locked artboard while nothing is isolated, or outside the isolated group adds no layer. This is VectorCraft's own behavior.
Object › Flatten Transparency takes a frame of threaded text out of the thread in the same way when Convert All Text to Outlines outlines it or when the frame becomes flat regions or an image, and the other frames keep the text they hold.
Object › Flatten Transparency, the Flattener Preview, and EPS, PDF and print output that flatten transparency stop building a group's flat regions at the first region past the raster/vector balance's limit (10^(balance/20), rounded down) and rasterize the whole group without building the remaining regions. Building every region gives the same flattened art and the same files. With Clip Complex Regions on, a group builds every region and its image is clipped to them.
Object › Flatten Transparency, the Flattener Preview, and EPS, PDF and print output that flatten transparency look at each node of an object without transparency once to list the type, strokes and overprints that Convert All Text to Outlines, Convert All Strokes to Outlines and dropping overprints change, and then change what the list holds. On 100 groups of a stroked rectangle and a line of stroked type and five other objects, with both options on and overprints dropped, the Flattener Preview looks at the 309 nodes 309 times where it looked 615 times, and Flatten Transparency looks at them 309 times where its walks made 2,352 visits, the outlines they made included. The flattened art, its ids and the preview's lists stay the same (`cmd::flatten::apply::tests::kept_objects_are_looked_at_once`, `kept_objects_change_as_a_walk_per_option_changes_them`).
Object › Flatten Transparency, the Flattener Preview, and EPS, PDF and print output that flatten transparency leave art without transparency as it is when it overlaps only other art without transparency, unless it overlaps a member of a see-through object's group and lies above that member and below the group's topmost object. Such art joins the group, and the group takes the place of its topmost object, so the stacking order stays the same. In files without transparency with Clip Complex Regions on, art under the group within one image pixel of a member joins it too. The 1 pt antialiasing margin goes around a group's art once, however deeply its groups nest. On a grid of 3,000 rectangles with a 0.5 pt stroke, 60 of them with a drop shadow, the Flattener Preview counts 180 affected objects where it counted 3,000, and Flatten Transparency with the Medium preset makes 240 flat regions and 2 images where it made one image of the whole grid. These rules are VectorCraft's own (`tests::flatten::opaque_art_that_touches_only_opaque_art_stays`, `tests::flatten::opaque_art_the_group_would_move_under_joins_it`).
When they group art for flattening, Object › Flatten Transparency, the Flattener Preview, and EPS, PDF and print output that flatten transparency compare the box of an object without transparency only with the boxes of see-through objects in the pass that splits art by transparency. In both passes, a box that lies inside an earlier box that ends no further right and joins everything it overlaps is not compared with later boxes. With one see-through object inside 512 nested objects without transparency, the grouping compares 1,024 pairs of boxes where it compared 262,145, and the groups stay the same (`cmd::flatten::analysis::tests::nested_opaque_boxes_meet_only_the_see_through_box`, `a_shrinking_nest_meets_only_its_outermost_box`). When a later box that joins everything it overlaps covers an earlier box to the right and below, the grouping compares the earlier box with still later boxes only above the later box's top: 512 boxes, each 1 pt right of and below the one before, compare 511 pairs where they compared 130,816, with and without transparency, and the groups stay the same (`cmd::flatten::analysis::tests::staggered_boxes_meet_only_the_box_before`, `staggered_boxes_group_as_comparing_every_pair`). When such a later box covers an earlier box to the right and above, the grouping compares the earlier box with still later boxes only below the later box's bottom: 512 boxes, each 1 pt right of and above the one before, or left of and below it, compare 511 pairs where they compared 130,816, with and without transparency, and the groups stay the same (`cmd::flatten::analysis::tests::boxes_staggered_up_meet_only_the_box_before`, `boxes_stepping_up_and_down_group_as_comparing_every_pair`).
New Symbol and Redefine Symbol on a frame of threaded text take it out of the thread with the text it shows, which the symbol's art holds, and the other frames keep the text they hold. When the last frame goes into the symbol, the text it has no room for goes after the text of the last frame that stays. When every frame of a thread goes into the symbol, the copy of the last frame keeps all its text.