mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
Merge pull request #9806 from dotCooCoo/fix/outline-placed-geometry-effects
Outline view: effects reshape a placed document's crossed box
This commit is contained in:
11 files changed
+329
-31
No files matched your search
@@ -17,15 +17,16 @@
|
||||
//! other stop there, showing their previews).
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::{Arc, Mutex, MutexGuard, OnceLock, PoisonError};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vectorcraft_geom::{Affine, Rect};
|
||||
use vectorcraft_geom::{Affine, PathData, Rect, SubPath};
|
||||
|
||||
use vectorcraft_color::Paint;
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
|
||||
use crate::{AppearanceItem, Document, ImageBlob, ImageObject, LinkInfo, Node, NodeKind, PatternDef, PlacementOptions, Symbol};
|
||||
use crate::{Appearance, AppearanceItem, Document, ImageBlob, ImageObject, LinkInfo, Node, NodeKind, PatternDef, PlacementOptions, Symbol};
|
||||
|
||||
/// A placed document: an artboard of another VectorCraft file, a page of a PDF or `.ai` file, or
|
||||
/// an EPS file's art, shown as one locked object.
|
||||
@@ -123,12 +124,27 @@ impl PlacedDocument {
|
||||
}
|
||||
|
||||
/// The art the object shows, as plain objects with `n`'s id: one group, its resources named
|
||||
/// as [`Document::with_placed_art`] adds them (nothing until that has read it).
|
||||
/// as [`Document::with_placed_art`] adds them (nothing until that has read it). While
|
||||
/// [`Crossed`] is on for this thread, its box crossed from corner to corner instead
|
||||
/// ([`Self::crossed_art`]).
|
||||
pub fn art(&self, n: &Node) -> Vec<Node> {
|
||||
if crossed() {
|
||||
return vec![self.crossed_art(n)];
|
||||
}
|
||||
let prefix = prefix(&self.key);
|
||||
read_cached(self).and_then(|e| self.art_node(n, &e, &prefix)).into_iter().collect()
|
||||
}
|
||||
|
||||
/// The object's box crossed from corner to corner, as one group with `n`'s id: a path of the
|
||||
/// box's outline and its two diagonals with a black 1 pt stroke. Outline mode without Document
|
||||
/// Setup → Show Images in Outline Mode shows the object so, and its effects reshape this art.
|
||||
pub fn crossed_art(&self, n: &Node) -> Node {
|
||||
let q = self.corners();
|
||||
let path = PathData::new(vec![SubPath::polyline(&q, true), SubPath::polyline(&[q[0], q[2]], false), SubPath::polyline(&[q[1], q[3]], false)]);
|
||||
let stroke = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
|
||||
Node::group(n.id, vec![Arc::new(Node::path(art_id(), path, stroke))])
|
||||
}
|
||||
|
||||
/// Read `e`'s art placed as this object `n` shows it (`n`'s id), its resources renamed with
|
||||
/// `prefix`.
|
||||
fn art_node(&self, n: &Node, e: &ReadDocument, prefix: &str) -> Option<Node> {
|
||||
@@ -470,6 +486,36 @@ fn read_preview(p: &PlacedDocument, bytes: &Arc<Vec<u8>>) -> Option<Arc<ReadDocu
|
||||
Some(e)
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// Whether [`PlacedDocument::art`] gives the crossed box on this thread ([`Crossed`]).
|
||||
static CROSSED: Cell<bool> = const { Cell::new(false) };
|
||||
}
|
||||
|
||||
/// While alive, [`PlacedDocument::art`] on this thread gives each placed document's box crossed
|
||||
/// from corner to corner ([`PlacedDocument::crossed_art`]) when it was made with `true`, and the
|
||||
/// file's art when made with `false`; once dropped, the setting before it applies again. A
|
||||
/// renderer holds one while it draws or measures Outline mode without Document Setup → Show Images
|
||||
/// in Outline Mode, so that effects and live objects make their art from the crossed box.
|
||||
#[must_use]
|
||||
pub struct Crossed(bool);
|
||||
|
||||
impl Crossed {
|
||||
pub fn set(on: bool) -> Self {
|
||||
Self(CROSSED.with(|c| c.replace(on)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Crossed {
|
||||
fn drop(&mut self) {
|
||||
CROSSED.with(|c| c.set(self.0));
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether [`PlacedDocument::art`] gives the crossed box on this thread ([`Crossed`]).
|
||||
pub fn crossed() -> bool {
|
||||
CROSSED.with(Cell::get)
|
||||
}
|
||||
|
||||
/// `p`'s file as read already (else its preview's), without reading it.
|
||||
pub fn read_cached(p: &PlacedDocument) -> Option<Arc<ReadDocument>> {
|
||||
let mut c = cache();
|
||||
|
||||
@@ -7,6 +7,8 @@ use std::sync::Arc;
|
||||
use vectorcraft_doc::{Document, Node, NodeId, NodeKind, SymbolBoxes};
|
||||
use vectorcraft_geom::{Affine, Rect};
|
||||
|
||||
use crate::placed_document::{LayerMode, enter_layer};
|
||||
|
||||
/// What may draw differently in a document than in its version before an edit ([`changed`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Changed {
|
||||
@@ -129,6 +131,8 @@ fn changed_with(old: &Document, new: &Document, renderer: Option<&mut crate::Ren
|
||||
return Changed::Everything;
|
||||
}
|
||||
let mut diff = Diff { old: old.symbol_boxes(), new: new.symbol_boxes(), area: None, renderer, opts, sources: (None, None) };
|
||||
// Measured as the frames with `opts` draw ([`crate::Renderer::cross_placed`]).
|
||||
let _mode = LayerMode { options: opts.dim_templates && !opts.skip_templates, outline: opts.outline, images: new.setup.outline_images }.enter();
|
||||
diff.children(&old.layers, &new.layers);
|
||||
diff.area.map_or(Changed::Nothing, Changed::Area)
|
||||
}
|
||||
@@ -179,11 +183,20 @@ impl Diff<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Self::node_in`], the members of a layer that draws in the same mode in both versions
|
||||
/// measured in that mode ([`LayerMode::inside`]). The two versions of a layer that draw in
|
||||
/// different modes are each measured in their own ([`Self::bounds`]).
|
||||
fn node(&mut self, old: &Arc<Node>, new: &Arc<Node>) {
|
||||
let modes = LayerMode::now().map(|m| (m.inside(old), m.inside(new)));
|
||||
let _mode = modes.and_then(|(a, b)| if a == b { b } else { None }).map(LayerMode::enter);
|
||||
self.node_in(old, new);
|
||||
}
|
||||
|
||||
/// A group or layer that only its members changed in, without a clipping mask or effects of
|
||||
/// its own that draw from all of them, changed where they did. A path or compound path that
|
||||
/// only had anchors moved changed around them ([`moved_anchors`]). Any other object that
|
||||
/// changed counts whole, before and after.
|
||||
fn node(&mut self, old: &Arc<Node>, new: &Arc<Node>) {
|
||||
fn node_in(&mut self, old: &Arc<Node>, new: &Arc<Node>) {
|
||||
if Arc::ptr_eq(old, new) || self.unseen(Side::Old, old) && self.unseen(Side::New, new) {
|
||||
return;
|
||||
}
|
||||
@@ -228,6 +241,8 @@ impl Diff<'_, '_> {
|
||||
if self.unseen(side, n) {
|
||||
return None;
|
||||
}
|
||||
// A layer is measured in the mode its Layer Options draw it in.
|
||||
let _mode = enter_layer(n);
|
||||
let Diff { old, new, renderer, .. } = self;
|
||||
let symbols = match side {
|
||||
Side::Old => old,
|
||||
|
||||
@@ -68,11 +68,13 @@ pub(super) fn evaluates_live(n: &Node) -> bool {
|
||||
/// dots sampled from everything it draws), one with a live-effect plug-in that paints its pieces
|
||||
/// (drawn only while the swatches and patterns they name are in the document), or an image with a
|
||||
/// fill or stroke that follows the outline of its pixels ([`effects::follows_image_pixels`]: the
|
||||
/// document's pixels for it can change), in it or in the opacity masks of the objects in it.
|
||||
/// document's pixels for it can change), or a placed document (its file read, or in some Outline
|
||||
/// frames its crossed box, [`vectorcraft_doc::placed_document::Crossed`]), in it or in the opacity
|
||||
/// masks of the objects in it.
|
||||
pub(super) fn reads_outside(n: &Node) -> bool {
|
||||
let mut reads = false;
|
||||
n.walk(&mut |c| {
|
||||
reads |= matches!(c.kind, NodeKind::Text(_) | NodeKind::SymbolInstance { .. })
|
||||
reads |= matches!(c.kind, NodeKind::Text(_) | NodeKind::SymbolInstance { .. } | NodeKind::PlacedDocument(_))
|
||||
|| effects::follows_image_pixels(c)
|
||||
|| effects::has_revolve(c)
|
||||
|| effects::has_solid(c)
|
||||
|
||||
@@ -488,9 +488,9 @@ impl Renderer {
|
||||
// A placed document whose effects make no art of their own (raster effects and color
|
||||
// adjustments, which Outline mode does not draw) shows its box crossed as without effects
|
||||
// ([`Self::draw_placed`]). Effects that change geometry (plug-in effects among them,
|
||||
// [`effects::is_geometry`]), 3D and Pathfinder make art from
|
||||
// the file's art, which is drawn; Crop Marks and Vector Halftone draw the placed document
|
||||
// itself among their art.
|
||||
// [`effects::is_geometry`]), 3D and Pathfinder make art from the crossed box, which the
|
||||
// frame gives as the placed document's art ([`Self::cross_placed`]), and that art is drawn;
|
||||
// Crop Marks and Vector Halftone draw the placed document itself among their art.
|
||||
if let NodeKind::PlacedDocument(p) = &a.kind
|
||||
&& self.crosses_placed(f)
|
||||
&& !effects::has_geometry(&a.appearance.effects)
|
||||
|
||||
@@ -176,7 +176,8 @@ struct Shown {
|
||||
/// tilings ([`crate::pattern::hash_tiling`]) of the patterns in the fills and strokes of its
|
||||
/// objects and of type's characters, the address of each symbol instance's art, and the address of
|
||||
/// the read of each placed file that [`vectorcraft_doc::PlacedDocument::art`] shows (none before
|
||||
/// the file is read), and the address of the document's pixels for each image whose
|
||||
/// the file is read) with whether that art is the crossed box
|
||||
/// ([`vectorcraft_doc::placed_document::Crossed`]), and the address of the document's pixels for each image whose
|
||||
/// own fills or strokes follow them ([`crate::effects::follows_image_pixels`]). It walks `n` and
|
||||
/// then, one at a time from a list, the opacity-mask, pattern and symbol art it finds, each pattern
|
||||
/// and each symbol's art once ([`first_seen`]). `shown` records the type, placed files, reads,
|
||||
@@ -214,6 +215,8 @@ fn hash_resources<'a>(symbols: &SymbolBoxes<'a>, n: &'a Node, shown: &mut Shown,
|
||||
NodeKind::PlacedDocument(p) => {
|
||||
let read = vectorcraft_doc::placed_document::read_cached(p);
|
||||
read.as_ref().map(|r| Arc::as_ptr(r) as usize).hash(h);
|
||||
// The art is the crossed box instead in some Outline frames.
|
||||
vectorcraft_doc::placed_document::crossed().hash(h);
|
||||
shown.reads.extend(read.as_ref().map(Arc::downgrade));
|
||||
shown.text = true;
|
||||
shown.placed = true;
|
||||
|
||||
@@ -297,6 +297,74 @@ fn depth() -> usize {
|
||||
DEPTH.with(Cell::get)
|
||||
}
|
||||
|
||||
/// How a frame draws art ([`Renderer::layer_mode`]): whether Layer Options apply (on screen;
|
||||
/// exports and thumbnails ignore them), whether the art draws in Outline mode, and whether Show
|
||||
/// Images in Outline Mode is on for it ([`Renderer::shows_outline_images`]). Layers are measured
|
||||
/// in the mode they draw in, and placed documents are their crossed box in Outline mode without
|
||||
/// Show Images in Outline Mode ([`vectorcraft_doc::placed_document::Crossed`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) struct LayerMode {
|
||||
pub(crate) options: bool,
|
||||
pub(crate) outline: bool,
|
||||
pub(crate) images: bool,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// The mode of the frame being drawn or measured on this thread ([`LayerMode::enter`]).
|
||||
static MODE: Cell<Option<LayerMode>> = const { Cell::new(None) };
|
||||
}
|
||||
|
||||
impl LayerMode {
|
||||
/// The mode layer `n` draws its art in when its Layer Options change it: a template layer stays
|
||||
/// in Preview in Outline mode (#1486), and a layer whose Preview is off draws in outline.
|
||||
/// `None` for other objects and for a layer that draws in this mode.
|
||||
pub(crate) fn inside(self, n: &Node) -> Option<Self> {
|
||||
let vectorcraft_doc::NodeKind::Layer { preview, template, .. } = &n.kind else { return None };
|
||||
if !self.options {
|
||||
return None;
|
||||
}
|
||||
let outline = if *template && self.outline {
|
||||
false
|
||||
} else if !preview && !template && !self.outline {
|
||||
true
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
Some(Self { outline, ..self })
|
||||
}
|
||||
|
||||
/// The mode of the frame being drawn or measured on this thread, if any.
|
||||
pub(crate) fn now() -> Option<Self> {
|
||||
MODE.with(Cell::get)
|
||||
}
|
||||
|
||||
/// Draw and measure in this mode on this thread until the guard returned is dropped.
|
||||
pub(crate) fn enter(self) -> InMode {
|
||||
let crossed = vectorcraft_doc::placed_document::Crossed::set(self.outline && !self.images);
|
||||
InMode { was: MODE.with(|m| m.replace(Some(self))), _crossed: crossed }
|
||||
}
|
||||
}
|
||||
|
||||
/// While alive: art on this thread is drawn and measured in a [`LayerMode`]; once dropped, in the
|
||||
/// mode before it.
|
||||
#[must_use]
|
||||
pub(crate) struct InMode {
|
||||
was: Option<LayerMode>,
|
||||
_crossed: vectorcraft_doc::placed_document::Crossed,
|
||||
}
|
||||
|
||||
impl Drop for InMode {
|
||||
fn drop(&mut self) {
|
||||
MODE.with(|m| m.set(self.was));
|
||||
}
|
||||
}
|
||||
|
||||
/// Measure layer `n` in the mode its Layer Options draw it in, inside the mode on this thread
|
||||
/// ([`LayerMode::inside`]), until the guard returned is dropped; `None` when that is the same mode.
|
||||
pub(crate) fn enter_layer(n: &Node) -> Option<InMode> {
|
||||
LayerMode::now()?.inside(n).map(LayerMode::enter)
|
||||
}
|
||||
|
||||
/// Render `art` of a placed document's file (`doc`, its resources) into `w`×`h` transparent
|
||||
/// pixels through `view`, the placed documents inside it one level deeper.
|
||||
pub fn render_inside(r: &mut Renderer, doc: &vectorcraft_doc::Document, art: &Arc<Node>, w: u16, h: u16, view: Affine) -> Option<crate::Rendered> {
|
||||
@@ -489,8 +557,8 @@ impl Renderer {
|
||||
}
|
||||
|
||||
/// Draw placed document `p` as its box crossed from corner to corner ([`Self::crosses_placed`]).
|
||||
/// Its file is still read, as when its art is drawn: the art its effects and its group's effects
|
||||
/// make comes from the read kept.
|
||||
/// Its file is still read, as when its art is drawn: once the frame shows images again, the art
|
||||
/// its effects and its group's effects make comes from the read kept.
|
||||
pub(crate) fn draw_crossed_placed(&mut self, ctx: &mut RenderContext, f: &Frame, p: &PlacedDocument) {
|
||||
if let Some(blob) = f.doc.images.get(&p.key) {
|
||||
let _ = read_placed(p, blob);
|
||||
|
||||
@@ -198,6 +198,7 @@ impl Renderer {
|
||||
let output = Affine::scale(1.0 / f64::from(cell.max(1))) * view;
|
||||
let plates = proof::plate_lut(opts, doc);
|
||||
let frame = Frame { mt: threads > 0, patch, doc, symbols: &symbols, view, visible, px, opts, ink: screen, output, plates: plates.as_deref() };
|
||||
let _crossed = self.cross_placed(&frame);
|
||||
self.begin_frame();
|
||||
// View Opacity Mask: the mask's coverage in greyscale instead of the artwork.
|
||||
if let Some(m) = opts.mask_view.and_then(|id| doc.node(id)).and_then(|n| n.extras().mask.as_deref()) {
|
||||
@@ -484,6 +485,7 @@ impl Renderer {
|
||||
let output = Affine::scale(1.0 / f64::from(cell.max(1))) * view;
|
||||
let frame = Frame { mt: false, patch: None, doc, symbols: &symbols, view, visible, px, opts, ink: Ink::Display, output, plates: None };
|
||||
let raster = std::mem::replace(&mut self.raster, raster_settings(opts));
|
||||
let _crossed = self.cross_placed(&frame);
|
||||
self.begin_frame();
|
||||
(self.knockout, self.nested, self.backdrop, self.picture) = (false, 0, None, None);
|
||||
self.clip_paths.clear();
|
||||
|
||||
@@ -6,6 +6,27 @@ use super::{
|
||||
};
|
||||
use crate::kept_paths::{self, KeptPath};
|
||||
use crate::node_checks::{holds_measured_three_d, measures_three_d};
|
||||
use crate::placed_document::{InMode, LayerMode, enter_layer};
|
||||
use vectorcraft_doc::placed_document::crossed;
|
||||
|
||||
/// The key of `a`'s cull bounds in [`Renderer::geom`]: its address, and in its lowest bits what the
|
||||
/// bounds depend on besides `a`. For a layer that is the mode its sublayers are measured in
|
||||
/// ([`LayerMode`], [`enter_layer`]); for an object other than a path, whether placed documents are
|
||||
/// crossed ([`vectorcraft_doc::placed_document::Crossed`]), since the art its effects make from a
|
||||
/// placed document in it is the crossed box then. A node's address is aligned to 8 bytes, so no
|
||||
/// other node has that key.
|
||||
fn geom_key(a: &Node) -> usize {
|
||||
let at = std::ptr::from_ref(a) as usize;
|
||||
match a.kind {
|
||||
NodeKind::Path { .. } | NodeKind::Compound { .. } => at,
|
||||
NodeKind::Layer { .. } => {
|
||||
at | LayerMode::now().map_or(0, |m| usize::from(m.options) | usize::from(m.outline) << 1 | usize::from(m.images) << 2)
|
||||
}
|
||||
_ => at | usize::from(crossed()),
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = assert!(std::mem::align_of::<Node>() >= 8, "geom_key keeps three bits below a node's address");
|
||||
|
||||
fn needs_three_d_bounds(symbols: &SymbolBoxes, node: &Node) -> bool {
|
||||
measures_three_d(node)
|
||||
@@ -34,7 +55,7 @@ impl Renderer {
|
||||
if patch.is_some_and(Frame::patch_rejected) {
|
||||
return None;
|
||||
}
|
||||
let key = Arc::as_ptr(a) as usize;
|
||||
let key = geom_key(a);
|
||||
if let Some(e) = self.geom.get_mut(&key)
|
||||
&& Arc::ptr_eq(&e.node, a)
|
||||
{
|
||||
@@ -53,6 +74,7 @@ impl Renderer {
|
||||
let source = a.extras().trace.is_some().then(|| children.first()).flatten();
|
||||
for c in children {
|
||||
if c.visible || source.is_some_and(|s| Arc::ptr_eq(s, c)) {
|
||||
let _mode = enter_layer(c);
|
||||
acc = vectorcraft_geom::union_opt(acc, self.bounds_with_patch(symbols, c, patch));
|
||||
if patch.is_some_and(Frame::patch_rejected) {
|
||||
return None;
|
||||
@@ -158,6 +180,19 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/// How frame `f` draws art ([`LayerMode`]).
|
||||
pub(crate) fn layer_mode(&self, f: &Frame) -> LayerMode {
|
||||
LayerMode { options: f.opts.dim_templates && !f.opts.skip_templates, outline: f.opts.outline, images: self.shows_outline_images(f) }
|
||||
}
|
||||
|
||||
/// Draw and measure art in frame `f`'s mode ([`Self::layer_mode`]) until the guard returned is
|
||||
/// dropped: placed documents' art ([`vectorcraft_doc::PlacedDocument::art`]) is their box
|
||||
/// crossed from corner to corner in Outline mode without Document Setup → Show Images in
|
||||
/// Outline Mode ([`Self::crosses_placed`]), else their file's art.
|
||||
pub(crate) fn cross_placed(&self, f: &Frame) -> InMode {
|
||||
self.layer_mode(f).enter()
|
||||
}
|
||||
|
||||
/// When a plug-in has been installed or removed since the last check
|
||||
/// ([`effects::plugin_revision`]), drop what the caches keep from plug-in effects: the effect
|
||||
/// geometry of paths with a plug-in effect, the cull bounds of objects that have one or hold one,
|
||||
@@ -266,6 +301,8 @@ impl Renderer {
|
||||
if crate::node_checks::left_out(f.opts, f.doc, a) {
|
||||
return true;
|
||||
}
|
||||
// A layer is measured in the mode its Layer Options draw it in ([`Self::draw_node`]).
|
||||
let _mode = self.layer_mode(f).inside(a).map(LayerMode::enter);
|
||||
let bounds = self.frame_bounds_of(f, a);
|
||||
if f.patch_rejected() {
|
||||
return true;
|
||||
@@ -377,6 +414,13 @@ impl Renderer {
|
||||
|
||||
/// Everything [`Self::draw_arc`] does after culling.
|
||||
fn draw_arc_body(&mut self, ctx: &mut RenderContext, f: &Frame, a: &Arc<Node>) {
|
||||
// A layer with effects of its own draws them in the mode its Layer Options give it, as
|
||||
// `draw_node` draws any other layer.
|
||||
if let Some(mode) = self.layer_mode(f).inside(a) {
|
||||
let opts = RenderOptions { outline: mode.outline, ..f.opts.clone() };
|
||||
let _mode = mode.enter();
|
||||
return self.draw_arc_body(ctx, &Frame { opts: &opts, ..*f }, a);
|
||||
}
|
||||
// Fast path for plain paths: cached geometry, opacity folded into the paint.
|
||||
// A blend mode on a single plain fill applies per draw (exact for one paint operation);
|
||||
// a blend layer would composite the whole viewport.
|
||||
@@ -459,18 +503,15 @@ impl Renderer {
|
||||
// Layer Options on screen: a layer whose Preview is off draws in outline, and Dim Images
|
||||
// fades its images, a template's too (exports and thumbnails, which leave templates out,
|
||||
// ignore both).
|
||||
if let NodeKind::Layer { preview, dim_images, template, .. } = &n.kind
|
||||
if let NodeKind::Layer { dim_images, .. } = &n.kind
|
||||
&& f.opts.dim_templates
|
||||
&& !f.opts.skip_templates
|
||||
{
|
||||
// A template layer stays in Preview while the view is in Outline (and whatever its own
|
||||
// Preview option says): its picture is there to be traced (#1486).
|
||||
if *template && f.opts.outline {
|
||||
let opts = RenderOptions { outline: false, ..f.opts.clone() };
|
||||
return self.draw_node(ctx, &Frame { opts: &opts, ..*f }, n, force);
|
||||
}
|
||||
if !preview && !template && !f.opts.outline {
|
||||
let opts = RenderOptions { outline: true, ..f.opts.clone() };
|
||||
if let Some(mode) = self.layer_mode(f).inside(n) {
|
||||
let opts = RenderOptions { outline: mode.outline, ..f.opts.clone() };
|
||||
let _mode = mode.enter();
|
||||
return self.draw_node(ctx, &Frame { opts: &opts, ..*f }, n, force);
|
||||
}
|
||||
if let Some(p) = *dim_images {
|
||||
@@ -763,6 +804,7 @@ impl Renderer {
|
||||
if view.shows_outlines() {
|
||||
let opts = RenderOptions { outline: true, ..f.opts.clone() };
|
||||
let frame = Frame { opts: &opts, ..*f };
|
||||
let _crossed = self.cross_placed(&frame);
|
||||
// An Abutting trace's seam fills hold no traced outline: a clip group of paths that are
|
||||
// each stroked without a fill or (on a stretched image, the strokes' outlines) filled
|
||||
// without a stroke, named "Seam Fills" or, renamed, still the lowest shape, where the
|
||||
@@ -843,7 +885,7 @@ impl Renderer {
|
||||
/// Cull bounds of `n` (symbol instances measured by their art box from `symbols`): cached when
|
||||
/// it is a node of the tree being drawn.
|
||||
fn node_bounds(&mut self, symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
|
||||
match self.geom.get(&(n as *const Node as usize)) {
|
||||
match self.geom.get(&geom_key(n)) {
|
||||
// The entry keeps its node alive, so the address is that node's.
|
||||
Some(e) if std::ptr::eq(Arc::as_ptr(&e.node), n) => e.bounds,
|
||||
_ => fx::cull_bounds(symbols, n),
|
||||
|
||||
@@ -206,16 +206,18 @@ fn outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_show
|
||||
let r = outline(&d);
|
||||
assert!(inked(&r, 20, 15), "a placed document with a color adjustment is crossed");
|
||||
assert!(!inked(&r, 50, 20), "and none of its file's art is drawn");
|
||||
// A Transform effect reshapes the file's art, read when the crossed box was drawn: its rectangle
|
||||
// is drawn moved 40 points down to (10, 50)–(90, 90), its bottom edge at y = 90, with no cross
|
||||
// through it ((20, 55) is on its diagonal) or where the box was.
|
||||
// A Transform effect reshapes the crossed box: it is drawn moved 40 points down to
|
||||
// (10, 50)–(90, 90), its bottom edge at y = 90 and crossed ((20, 55) is on its diagonal), with
|
||||
// nothing where the box was and none of the file's art ((50, 60) is the top edge of the box the
|
||||
// file places in itself, moved).
|
||||
let mut d = doc_with("outline-cross-4", b"loop");
|
||||
assert!(inked(&outline(&d), 20, 15), "first drawn crossed");
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
let r = outline(&d);
|
||||
assert!(inked(&r, 50, 89) || inked(&r, 50, 90), "the file's art is drawn moved");
|
||||
assert!(!inked(&r, 20, 55), "uncrossed");
|
||||
assert!(inked(&r, 50, 89) || inked(&r, 50, 90), "the box is drawn moved");
|
||||
assert!(inked(&r, 20, 55), "crossed");
|
||||
assert!(!inked(&r, 50, 60), "without the file's art");
|
||||
assert!(!inked(&r, 20, 15), "and nothing is drawn where the box was");
|
||||
// The same when the box was first drawn crossed with a drop shadow.
|
||||
let mut d = doc_with("outline-cross-5", b"loop");
|
||||
@@ -229,7 +231,125 @@ fn outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_show
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
let r = outline(&d);
|
||||
assert!(inked(&r, 50, 89) || inked(&r, 50, 90), "the file's art is drawn moved after a drop shadow");
|
||||
assert!(inked(&r, 50, 89) || inked(&r, 50, 90), "the box is drawn moved after a drop shadow");
|
||||
assert!(inked(&r, 20, 55), "and crossed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outline_mode_reshapes_the_crossed_box_of_a_placed_document_by_its_groups_effects() {
|
||||
let outline = |r: &mut Renderer, d: &Document| {
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), outline: true, ..Default::default() };
|
||||
r.render(d, 100, 100, Affine::IDENTITY, &opts)
|
||||
};
|
||||
let inked = |r: &Rendered, x: u32, y: u32| r.pixel(x, y)[0] < 200;
|
||||
// The box (10, 10)–(90, 50) in a group whose Transform effect moves it 40 points down: crossed at
|
||||
// (10, 50)–(90, 90), whose diagonal from the top left passes (20, 55). The file places itself in
|
||||
// its middle: moved, the top edge of that box passes (50, 60).
|
||||
let mut d = doc_with("outline-group-1", b"loop");
|
||||
let placed = d.remove(NodeId(50)).unwrap();
|
||||
let mut group = Node::group(NodeId(80), vec![placed]);
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
group.appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, group).unwrap();
|
||||
// Exporting the document as PDF, SVG or EPS reads the file.
|
||||
d.with_placed_art();
|
||||
let mut r = Renderer::new();
|
||||
let crossed = outline(&mut r, &d);
|
||||
assert!(inked(&crossed, 20, 55), "the moved box is crossed");
|
||||
assert!(!inked(&crossed, 50, 60), "without the file's art");
|
||||
assert!(!inked(&crossed, 20, 15), "and nothing is drawn where the box was");
|
||||
// With Show Images in Outline Mode the same renderer draws the file's art moved, not the art it
|
||||
// kept for the crossed box, and back again without it.
|
||||
d.setup.outline_images = true;
|
||||
let shown = outline(&mut r, &d);
|
||||
assert!(!inked(&shown, 20, 55), "with Show Images in Outline Mode the box is not crossed");
|
||||
assert!(inked(&shown, 50, 60), "and the file's art is drawn moved");
|
||||
assert!(shown.pixels == outline(&mut Renderer::new(), &d).pixels, "as a new renderer draws it");
|
||||
d.setup.outline_images = false;
|
||||
assert!(outline(&mut r, &d).pixels == crossed.pixels, "crossed again as at first");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_template_layer_in_outline_mode_draws_a_placed_documents_art_its_effects_reshape() {
|
||||
// A template layer stays in Preview in Outline mode: the file's blue art moved 40 points down
|
||||
// by a Transform effect fills (10, 50)–(90, 90), and is not crossed.
|
||||
let mut d = doc_with("outline-template-1", b"blue");
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
if let NodeKind::Layer { template, .. } = &mut Arc::make_mut(&mut d.layers[0]).kind {
|
||||
*template = true;
|
||||
}
|
||||
// Exporting the document as PDF, SVG or EPS reads the file.
|
||||
d.with_placed_art();
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), outline: true, ..Default::default() };
|
||||
let r = Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &opts);
|
||||
let [red, _, blue, _] = r.pixel(50, 80);
|
||||
assert!(blue > red, "the file's art fills the moved box: {:?}", r.pixel(50, 80));
|
||||
// The same with the Transform effect on the template layer itself.
|
||||
let effect = d.node_mut(NodeId(50)).unwrap().appearance.effects.pop().unwrap();
|
||||
Arc::make_mut(&mut d.layers[0]).appearance.effects.push(effect);
|
||||
let r = Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &opts);
|
||||
let [red, _, blue, _] = r.pixel(50, 80);
|
||||
assert!(blue > red, "the layer's effect moves the file's art: {:?}", r.pixel(50, 80));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outline_mode_draws_the_crossed_box_its_effects_move_into_view_after_a_preview_frame() {
|
||||
// A file that can't be read, in the box (10, 10)–(90, 50), moved 40 points down by a Transform
|
||||
// effect: crossed at (10, 50)–(90, 90). The view shows the document from y = 55 down, below
|
||||
// where the box is without the effect; the moved box's diagonal from the top left passes
|
||||
// (30, 60), the pixel (30, 5).
|
||||
let mut d = doc_with("outline-cull-1", b"bad");
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
let view = Affine::translate((0.0, -55.0));
|
||||
let preview = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
|
||||
let outline = RenderOptions { outline: true, ..preview.clone() };
|
||||
let mut r = Renderer::new();
|
||||
r.render(&d, 100, 100, view, &preview);
|
||||
let crossed = r.render(&d, 100, 100, view, &outline);
|
||||
assert!(crossed.pixel(30, 5)[0] < 200, "the moved box is drawn crossed after a frame in Preview");
|
||||
assert!(crossed.pixels == Renderer::new().render(&d, 100, 100, view, &outline).pixels, "as a new renderer draws it");
|
||||
// In Preview, a layer whose Preview is off draws in outline: the same.
|
||||
if let NodeKind::Layer { preview, .. } = &mut Arc::make_mut(&mut d.layers[0]).kind {
|
||||
*preview = false;
|
||||
}
|
||||
let r = Renderer::new().render(&d, 100, 100, view, &preview);
|
||||
assert!(r.pixel(30, 5)[0] < 200, "the moved box is drawn crossed in a layer whose Preview is off");
|
||||
// And in a sublayer whose Preview is off, in a layer whose Preview is on.
|
||||
if let NodeKind::Layer { preview, .. } = &mut Arc::make_mut(&mut d.layers[0]).kind {
|
||||
*preview = true;
|
||||
}
|
||||
let placed = d.remove(NodeId(50)).unwrap();
|
||||
let mut sub = Node::layer(NodeId(90), "Sublayer", vectorcraft_doc::LayerColor::Preset(1));
|
||||
if let NodeKind::Layer { children, preview, .. } = &mut sub.kind {
|
||||
children.push(placed);
|
||||
*preview = false;
|
||||
}
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, sub).unwrap();
|
||||
let mut r = Renderer::new();
|
||||
r.render(&d, 100, 100, view, &outline);
|
||||
let r = r.render(&d, 100, 100, view, &preview);
|
||||
assert!(r.pixel(30, 5)[0] < 200, "the moved box is drawn crossed in a sublayer whose Preview is off");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_in_outline_mode_redraws_where_the_effects_move_the_crossed_box() {
|
||||
// A file that can't be read, in the box (10, 10)–(90, 50): a Transform effect added to it moves
|
||||
// the crossed box 40 points down, to (10, 50)–(90, 90).
|
||||
let old = doc_with("outline-changed-1", b"bad");
|
||||
let mut new = old.clone();
|
||||
let params = serde_json::json!({"moveV": 40});
|
||||
new.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "distort.transform".into(), params, visible: true });
|
||||
let opts = RenderOptions { background: Some([255, 255, 255, 255]), outline: true, ..Default::default() };
|
||||
let mut r = Renderer::new();
|
||||
r.render(&old, 100, 100, Affine::IDENTITY, &opts);
|
||||
match r.changed(&old, &new, &opts) {
|
||||
crate::changed::Changed::Area(a) => assert!(a.y1 >= 89.0, "the area reaches the moved box: {a:?}"),
|
||||
other => panic!("an area, not {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+2
-2
@@ -9645,8 +9645,8 @@ and small caps proportions, SVG text export), the background contents (white: ra
|
||||
art) and Align New Objects to Pixel Grid (see [Align New Objects to Pixel Grid](#align-new-objects-to-pixel-grid)).
|
||||
`outlineImages` is Show Images in Outline Mode. While it is off, Outline mode draws a linked image's frame crossed
|
||||
from corner to corner, and a placed document as its box crossed the same way without its art; an embedded image
|
||||
shows its frame alone. Not yet: a placed document with an effect that changes geometry, its own or its group's, is
|
||||
not crossed and draws its file's art reshaped by the effect. While it is on, images show their pixels in gray and
|
||||
shows its frame alone. Effects that change geometry, a placed document's own or its group's, reshape the crossed box
|
||||
instead of the file's art. While it is on, images show their pixels in gray and
|
||||
placed documents show their art.
|
||||
Pass any of these keys to change them in one undo step; `document.setUnits` stays as an alias for `units`.
|
||||
A file whose bleed (0 to 72 pt a side), superscript and subscript sizes (1 to 500%) and positions (-500 to 500%) or
|
||||
|
||||
+1
-1
@@ -556,7 +556,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| Outline view draws on a white canvas, the artboards as their edges | done | Outline shows only the paths ([Outline mode](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/preview-artwork-as-outlines.html)). VectorCraft's own rule for the canvas: in every interface brightness and Canvas Color the whole canvas is white, pasteboard included; the artboards draw no paper (no Simulate Colored Paper or artboard color, and no paper with Hide Artboards); the artboard names and the ruler origin's crosshair are dark gray; split views and floating windows follow their own view. Tests `outline_draws_on_a_white_canvas_with_artboards_as_edges`, `outline_draws_no_colored_paper`, `a_pane_draws_its_own_views_outline`, `the_ruler_origin_crosshair_shows_on_the_outline_canvas` |
|
||||
| Overprint Preview draws a white canvas around the artboards, with no artboard shadows | done | VectorCraft's own rule, in Overprint Preview and in Separations Preview, which turns it on: while the artboards show, the canvas outside the artboards is white in every interface brightness and Canvas Color, and the artboards keep their paper and edges and draw no shadows. With a display profile, translucent art around the artboards is blended with the white canvas. Turning the preview off brings back the pasteboard color and the shadows. Tests `overprint_preview_draws_a_white_canvas_without_shadows`, `translucent_art_around_the_artboards_is_blended_with_overprint_previews_white_canvas`, `translucent_pixels_around_the_artboards_are_blended_with_the_white_canvas` |
|
||||
| Outline view: a click selects by the outlines drawn, so it reaches a path behind an image (picked on its frame, unless Show Images in Outline Mode draws its pixels) or a gradient mesh (picked on its mesh lines) | done | #6437; in Outline mode the path is selected directly ([Object selection methods and preferences](https://helpx.adobe.com/illustrator/desktop/manage-objects/select-objects/object-selection-methods-and-preferences.html), Object Selection by Path Only). Type, symbol instances, blends, envelopes and placed documents are still picked within their bounds. Tests `outline_mode_picks_paths_through_images_and_meshes`, `outline_view_click_through_an_image_selects_the_path_behind` |
|
||||
| Outline view draws a linked image or placed document as its box with an X inside, unless Show Images in Outline Mode is on | partial | A linked file draws in Outline mode as a box with an X in it, and its contents show only after the Document Setup option Show Images in Outline Mode is turned on ([View artwork](https://helpx.adobe.com/illustrator/using/viewing-artwork.html)). The rest are VectorCraft's own rules. A linked image's frame is crossed from corner to corner, following the corners of a turned or distorted image. An embedded image, and each piece that an envelope cuts an image into, shows its frame alone. A click selects a linked image on its frame, as before, and not on the lines. A placed document shows its box crossed and none of its art, also with raster effects such as a drop shadow and with color adjustments. Not yet: a placed document with an effect that changes geometry, its own or its group's, still shows its file's art reshaped by the effect, without the X. With the option on, images show their pixels in gray and placed documents show their art in outline, uncrossed, and the art inside a placed document follows the option of the document it is placed in. Preview mode and output draw them as before. Tests `outline_mode_crosses_a_linked_images_frame_unless_the_setup_shows_images`, `outline_mode_crosses_a_linked_image_with_a_color_mask`, `outline_mode_does_not_cross_the_pieces_of_an_enveloped_linked_image`, `outline_mode_crosses_a_linked_image_moved_into_a_warp_piece`, `outline_mode_crosses_a_turned_or_distorted_linked_image_through_its_corners`, `outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_shows_images` |
|
||||
| Outline view draws a linked image or placed document as its box with an X inside, unless Show Images in Outline Mode is on | done | A linked file draws in Outline mode as a box with an X in it, and its contents show only after the Document Setup option Show Images in Outline Mode is turned on ([View artwork](https://helpx.adobe.com/illustrator/using/viewing-artwork.html)). The rest are VectorCraft's own rules. A linked image's frame is crossed from corner to corner, following the corners of a turned or distorted image. An embedded image, and each piece that an envelope cuts an image into, shows its frame alone. A click selects a linked image on its frame, as before, and not on the lines. A placed document shows its box crossed and none of its art, also with raster effects such as a drop shadow and with color adjustments. Effects that change geometry, its own or its group's, reshape the crossed box instead of the file's art. With the option on, images show their pixels in gray and placed documents show their art in outline, uncrossed, and the art inside a placed document follows the option of the document it is placed in. Preview mode and output draw them as before. Tests `outline_mode_crosses_a_linked_images_frame_unless_the_setup_shows_images`, `outline_mode_crosses_a_linked_image_with_a_color_mask`, `outline_mode_does_not_cross_the_pieces_of_an_enveloped_linked_image`, `outline_mode_crosses_a_linked_image_moved_into_a_warp_piece`, `outline_mode_crosses_a_turned_or_distorted_linked_image_through_its_corners`, `outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_shows_images`, `outline_mode_reshapes_the_crossed_box_of_a_placed_document_by_its_groups_effects`, `outline_mode_draws_the_crossed_box_its_effects_move_into_view_after_a_preview_frame` |
|
||||
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools runs Arrange in Grid… (grid by row, one row or one column; columns, H and V spacing, Center on Artboard; Preview), Swap Objects, Swap Objects and Sizes, Replace with Top Object… (Actual Size, Bounds or Bounds (Fit Proportionally); Keep Original; Scale Strokes & Effects; Preview), Set Size of Each… (Width and Height each ticked on or off, Constrain Width and Height Proportions with one side, the reference point, Scale Strokes & Effects; Preview) and Zoom to Selection, each one undo step | done | `addon.arrange.*`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Group Overlapping Objects groups the selected objects whose visual bounds overlap or touch (chains included, within one layer or group), each group at its frontmost member's stacking place, one undo step | done | #4928; `addon.arrange.groupOverlapping`, `crates/engine/src/cmd/addons/arrange.rs` and its tests; not a feature of the reference app, so it is not scored |
|
||||
| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Randomize Opacity… gives each selected object its own opacity at random between Minimum and Maximum (%), with a Seed that repeats it and Preview, one undo step | done | #4925; `addon.arrange.randomizeOpacity`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
|
||||
Reference in new issue
Block a user