Outline view: linked images and placed documents show their box with an X

In Outline mode, with File > Document Setup > Show Images in Outline Mode
off, a linked image's frame is crossed from corner to corner, following
the corners of a turned or distorted image. A placed document shows its
box crossed, and its file's art no longer draws in Outline mode unless
the option is on. Embedded images keep a plain frame, and so do the
pieces that an envelope cuts an image into.

A placed document with raster effects or color adjustments stays
crossed. One with an effect that changes geometry, its own or its
group's, still draws its file's art reshaped and is not crossed yet.

With the option on, images show their pixels in gray and placed
documents show their art. The art inside a placed document now follows
the option of the document it is placed in rather than the placed
file's own setting.

Linked files showing as a box with an X in Outline mode is described at
https://helpx.adobe.com/illustrator/using/viewing-artwork.html; the
other rules are VectorCraft's own.

Docs: docs/ui-parity.md, docs/mcp.md; document.setup params text for
outlineImages.
This commit is contained in:
dotCooCoo
2026-11-22 19:49:08 -08:00
parent 5af36bae87
commit 97ac3c8c8b
12 changed files with 350 additions and 18 deletions
+17
View File
@@ -481,6 +481,23 @@ impl Renderer {
/// What [`Self::draw_object_fx`] draws inside the object's transparency group.
fn draw_object_fx_art(&mut self, ctx: &mut RenderContext, f: &Frame, a: &Arc<Node>, cache: bool) {
// 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.
if let NodeKind::PlacedDocument(p) = &a.kind
&& self.crosses_placed(f)
&& !effects::has_geometry(&a.appearance.effects)
&& !effects::has_revolve(a)
&& !effects::has_solid(a)
&& !effects::has_pathfinder(a)
&& !effects::has_crop_marks(a)
&& !effects::addons::halftone::has_halftone(a)
{
return self.draw_crossed_placed(ctx, f, p);
}
if !self.charge_fx_instance(f.symbols, a) {
return;
}
+8
View File
@@ -245,6 +245,14 @@ pub struct Renderer {
/// Layer Options → Dim Images to, of the layer being drawn (screen views only): images show
/// faded to this opacity over white.
dim_images: Option<f32>,
/// Document Setup → Show Images in Outline Mode of the document whose placed documents are
/// being drawn ([`Self::shows_outline_images`]): the art inside them follows it, not the
/// placed files' own setup.
host_outline_images: Option<bool>,
/// Drawing the image a piece of a mesh-warped image clips in Outline mode
/// ([`vectorcraft_doc::Node::warp_piece_image`]): a copy of the whole image, which is not crossed
/// ([`Self::cross_linked_image`]).
in_warp_piece: bool,
/// Inline graphics being drawn inside inline graphics (a symbol whose art holds text showing
/// it): drawing stops at [`MAX_INLINE_DEPTH`].
inline_depth: u32,
+40 -11
View File
@@ -16,7 +16,8 @@
//! ([`crate::placed_area`]). Bitmaps drawn since a frame began are not dropped to make room for
//! the ones it asks for, up to [`MAX_BYTES`], and a bitmap that can't be made is not asked for
//! again. Past [`MAX_SIDE`] pixels, past [`MAX_BYTES`], and in outline, proofing and ink frames,
//! it is drawn exactly.
//! it is drawn exactly. An outline frame draws only its box, crossed from corner to corner, unless
//! Document Setup → Show Images in Outline Mode is on.
//!
//! A document opened with only its placed documents' previews ([`ImageBlob::is_proxy`]) shows them
//! up to their resolution; past it the file is read again in the background
@@ -390,28 +391,37 @@ fn schedule(job: Job) {
run(&mut Renderer::new(), job);
}
/// The file `p` shows (its bytes `blob`) read as art, and kept for
/// [`vectorcraft_doc::placed_document::read_cached`]: from its bytes stored, read again already,
/// or (inside another placed document, while not too deep) read again now.
fn read_placed(p: &PlacedDocument, blob: &ImageBlob) -> Option<Arc<vectorcraft_doc::placed_document::ReadDocument>> {
let full = match depth() {
0 => vectorcraft_doc::placed_document::full_bytes_cached(p, blob),
d if d < MAX_DEPTH => vectorcraft_doc::placed_document::full_bytes(p, blob),
_ => None,
};
full.and_then(|bytes| vectorcraft_doc::placed_document::read(p, &bytes))
}
/// The mean scale of `a`.
fn mean_scale(a: Affine) -> f64 {
a.determinant().abs().sqrt()
}
impl Renderer {
/// Draw placed document `p` in frame `f`: from a cached bitmap on screen, else exactly.
/// Draw placed document `p` in frame `f`: from a cached bitmap on screen, else exactly; in
/// Outline mode without Document Setup → Show Images in Outline Mode, its box crossed from
/// corner to corner ([`Self::draw_crossed_box`]) and none of its art.
pub(crate) fn draw_placed(&mut self, ctx: &mut RenderContext, f: &Frame, p: &PlacedDocument) {
if self.crosses_placed(f) {
return self.draw_crossed_placed(ctx, f, p);
}
let plain = f.ink == Ink::Display && !f.opts.outline && f.opts.proof.is_none() && !f.opts.overprint_preview;
if f.opts.progressive_placed && plain && depth() == 0 && self.draw_placed_bitmap(ctx, f, p) {
return;
}
let Some(blob) = f.doc.images.get(&p.key) else { return };
// The file's bytes: stored, read again already, or (inside another placed document, while
// not too deep) read again now.
let full = match depth() {
0 => vectorcraft_doc::placed_document::full_bytes_cached(p, blob),
d if d < MAX_DEPTH => vectorcraft_doc::placed_document::full_bytes(p, blob),
_ => None,
};
let read = full.and_then(|bytes| vectorcraft_doc::placed_document::read(p, &bytes));
let Some(e) = read else {
let Some(e) = read_placed(p, blob) else {
// Only the preview: drawn scaled into the box.
if blob.is_proxy()
&& let Some(im) = p.preview_image(&blob.bytes)
@@ -432,7 +442,26 @@ impl Renderer {
let visible = m.inverse().transform_rect_bbox(f.visible);
let inner = Frame { doc: &e.doc, symbols: &symbols, view: f.view * m, visible, px: f.px / k, output: f.output * m, ..*f };
let _inside = Inside::enter();
// Its art follows this document's Show Images in Outline Mode, not the file's.
let host = self.host_outline_images.replace(self.shows_outline_images(f));
self.draw_arc(ctx, &inner, &e.art);
self.host_outline_images = host;
}
/// 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.
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);
}
self.draw_crossed_box(ctx, f, p.corners());
}
/// Whether `f` draws a placed document as its box crossed from corner to corner and none of
/// its art: in Outline mode without Show Images in Outline Mode ([`Self::shows_outline_images`]).
pub(crate) fn crosses_placed(&self, f: &Frame) -> bool {
f.opts.outline && !self.shows_outline_images(f)
}
/// Draw `p` from its bitmap at this zoom step, or (while that is made, or when it can't be)
+2
View File
@@ -98,6 +98,8 @@ impl Renderer {
moved_slices: PtrMap::default(),
adjusts: HashMap::new(),
dim_images: None,
host_outline_images: None,
in_warp_piece: false,
inline_depth: 0,
raster: vello_cpu::RasterizerSettings::default(),
isolation: None,
+49 -5
View File
@@ -2,6 +2,7 @@ use super::{
Affine, Arc, BezPath, Document, FillRule, Frame, HashMap, Ink, Node, NodeKind, Pixmap, Rect, RenderContext, Renderer, Shape, blob_key,
blob_pixmap, fill_rule, image_mip, ink, lookup, mip_level, peniko, proof, vello_cpu,
};
use vectorcraft_geom::Point;
use vello_cpu::peniko::{BlendMode, Compose, Mix};
use crate::images;
@@ -21,6 +22,46 @@ pub(super) fn image_tint(doc: &Document, n: &Node, ink: Ink) -> Option<[u8; 3]>
}
impl Renderer {
/// Document Setup → Show Images in Outline Mode for the art `f` draws: the setting of the
/// document whose placed documents are being drawn, else of `f`'s document.
pub(crate) fn shows_outline_images(&self, f: &Frame) -> bool {
self.host_outline_images.unwrap_or(f.doc.setup.outline_images)
}
/// Cross image node `n` from corner to corner of its frame ([`Node::image_cross`]) as a
/// hairline when it is linked and `f` draws in Outline mode without Show Images in Outline Mode
/// ([`Self::shows_outline_images`]). An embedded image shows its frame alone, and so does a
/// piece of a mesh-warped image's copy of the image ([`vectorcraft_doc::NodeExtras::warp_piece`]).
pub(crate) fn cross_linked_image(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node) {
if let NodeKind::Image(im) = &n.kind
&& im.link.is_some()
&& !self.in_warp_piece
&& !n.extras().warp_piece
&& f.opts.outline
&& !self.shows_outline_images(f)
&& let Some(cross) = n.image_cross()
{
self.hairline(ctx, f, &cross, [0, 0, 0, 255]);
}
}
/// Draw the box with corners `q` (top left, top right, bottom right, bottom left) crossed from
/// corner to corner, as a hairline: a placed document in Outline mode without Show Images in
/// Outline Mode.
pub(crate) fn draw_crossed_box(&mut self, ctx: &mut RenderContext, f: &Frame, q: [Point; 4]) {
let mut bp = BezPath::new();
bp.move_to(q[0]);
for p in &q[1..] {
bp.line_to(*p);
}
bp.close_path();
bp.move_to(q[0]);
bp.line_to(q[2]);
bp.move_to(q[1]);
bp.line_to(q[3]);
self.hairline(ctx, f, &bp, [0, 0, 0, 255]);
}
/// Draw an image, colorized with `tint` when given ([`image_tint`]).
pub(crate) fn draw_image(&mut self, ctx: &mut RenderContext, f: &Frame, im: &vectorcraft_doc::ImageObject, tint: Option<[u8; 3]>) {
self.draw_image_in(ctx, f, im, None, tint, false);
@@ -28,13 +69,15 @@ impl Renderer {
/// Distorted image `n` in outline mode: with Document Setup's Show Images in Outline Mode its
/// pixels, each piece of its mesh at the view's scale ([`Self::distorted_art`]) painted into
/// its triangle inside its corners, then its frame through its corners as a hairline. The
/// its triangle inside its corners, then its frame through its corners as a hairline, crossed
/// from corner to corner when it is linked and its pixels are not shown
/// ([`Self::cross_linked_image`]). The
/// pieces knock out as the mesh's knockout group does ([`Self::draw_knockout`]): each first
/// erases the pieces below it inside its triangle, so a partly transparent image paints once
/// where pieces overlap.
pub(crate) fn draw_distorted_frame(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Arc<Node>, cache: bool) {
let frame = n.image_frame();
if f.doc.setup.outline_images
if self.shows_outline_images(f)
&& let Some(edge) = &frame
&& let Some(art) = self.distorted_art(n, f.view, cache)
{
@@ -65,6 +108,7 @@ impl Renderer {
if let Some(bp) = &frame {
self.hairline(ctx, f, bp, [0, 0, 0, 255]);
}
self.cross_linked_image(ctx, f, n);
}
/// Draw an image, or with `area` (a region in the document inside the image's frame, see
@@ -81,7 +125,7 @@ impl Renderer {
) {
let rect = Rect::new(0.0, 0.0, im.width as f64, im.height as f64);
// Outline mode draws the image's frame, and with Document Setup → Show Images in Outline
// Mode its pixels in greyscale under the frame.
// Mode ([`Self::shows_outline_images`]) its pixels in grayscale under the frame.
let outline = f.opts.outline;
// With mips the full pixels are only looked at (not marked used) until they're drawn, and
// a mip the store holds is drawn without them: they may have been dropped (#2820). A
@@ -93,7 +137,7 @@ impl Renderer {
// With `kept_images_only`, an image still to be decoded: it draws as a light box, not as
// an undecoded image.
let mut pending = false;
let shown = if outline && !f.doc.setup.outline_images {
let shown = if outline && !self.shows_outline_images(f) {
None
} else if f.opts.kept_images_only {
let kept = self.nearest_kept(f, &im.key, im.pixels.as_deref(), outline, tint, unit);
@@ -174,7 +218,7 @@ impl Renderer {
}
}
}
} else if f.opts.mark_undecoded_images && !pending && (!outline || f.doc.setup.outline_images) {
} else if f.opts.mark_undecoded_images && !pending && (!outline || self.shows_outline_images(f)) {
self.draw_undecoded_mark(ctx, f, im, area);
} else if !pending && !outline {
self.image_left_out = self.image_left_out.map(|_| true);
+8 -1
View File
@@ -510,8 +510,13 @@ impl Renderer {
self.draw_children(ctx, f, children, knockout)
}
NodeKind::Group { children, clip: true } | NodeKind::Layer { children, clip: true, .. } if f.opts.outline => {
// A piece of a mesh-warped image: the copy of the image it clips is not crossed.
let piece = n.warp_piece_image();
for c in children {
let outer = self.in_warp_piece;
self.in_warp_piece = piece.is_some_and(|image| std::ptr::eq(image, &**c));
self.draw_outline_member(ctx, f, c);
self.in_warp_piece = outer;
}
}
NodeKind::Group { children, clip: true } | NodeKind::Layer { children, clip: true, .. } => {
@@ -581,7 +586,9 @@ impl Renderer {
}
NodeKind::Text(t) => self.draw_text(ctx, f, n, t),
NodeKind::Image(im) if !n.is_distorted_image() => {
self.draw_image_in(ctx, f, &f.doc.shown_image(n, im), None, images::image_tint(f.doc, n, f.ink), n.extras().pixelated)
self.draw_image_in(ctx, f, &f.doc.shown_image(n, im), None, images::image_tint(f.doc, n, f.ink), n.extras().pixelated);
// Crossed by the node's own link: a color mask's copy of the image has none.
self.cross_linked_image(ctx, f, n);
}
NodeKind::SymbolInstance { symbol, xf } => {
if let Some(sym) = f.symbols.symbol(symbol) {
@@ -129,6 +129,83 @@ fn a_placed_document_draws_exactly_with_its_own_art() {
assert_eq!(&r.pixel(95, 95)[..3], &[255, 255, 255], "nothing outside");
}
#[test]
fn outline_mode_draws_a_placed_document_as_its_box_crossed_unless_the_setup_shows_images() {
let outline = |d: &Document| {
let opts = RenderOptions { background: Some([255, 255, 255, 255]), outline: true, ..Default::default() };
Renderer::new().render(d, 100, 100, Affine::IDENTITY, &opts)
};
let inked = |r: &Rendered, x: u32, y: u32| r.pixel(x, y)[0] < 200;
// The box is (10, 10)–(90, 50): (20, 15) is on its diagonal from the top left. The file places
// itself again in the box (30, 20)–(70, 40), whose top edge passes (50, 20) and whose diagonal
// from the top left passes (35, 22).
let mut d = doc_with("outline-cross-1", b"loop");
let r = outline(&d);
assert!(inked(&r, 20, 15), "the box is crossed from corner to corner");
assert!(!inked(&r, 50, 20), "none of the file's art is drawn");
// The file's own setup has Show Images in Outline Mode off; this document's setting applies
// to the art inside it.
d.setup.outline_images = true;
let r = outline(&d);
assert!(!inked(&r, 20, 15), "with Show Images in Outline Mode it is not crossed");
assert!(inked(&r, 50, 20), "and its art is drawn in outline");
assert!(!inked(&r, 35, 22), "nor is the file it places");
// A drop shadow does not change what Outline mode shows.
let mut d = doc_with("outline-cross-2", b"loop");
let params = serde_json::json!({"x": 4, "y": 4, "blur": 1, "opacity": 100});
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect { id: "stylize.dropShadow".into(), params, visible: true });
let r = outline(&d);
assert!(inked(&r, 20, 15), "a placed document with a drop shadow is crossed");
assert!(!inked(&r, 50, 20), "and none of the file's art is drawn");
// The same in a clip group, whose members Outline mode draws one by one.
let placed = d.remove(NodeId(50)).unwrap();
let mut clip = Node::path(NodeId(71), shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)), Appearance::default());
if let NodeKind::Path { clipping, .. } = &mut clip.kind {
*clipping = true;
}
let group = Node::new(NodeId(70), NodeKind::Group { children: vec![Arc::new(clip), placed], clip: true });
let l = d.layers[0].id;
d.insert(Some(l), 0, group).unwrap();
let r = outline(&d);
assert!(inked(&r, 20, 15), "a clipped placed document with a drop shadow is crossed");
assert!(!inked(&r, 50, 20), "and none of its file's art is drawn");
// A color adjustment changes no geometry either.
let mut d = doc_with("outline-cross-3", b"loop");
let params = serde_json::json!({"brightness": 50});
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect {
id: "adjust.brightnessContrast".into(),
params,
visible: true,
});
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.
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, 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");
let shadow = serde_json::json!({"x": 4, "y": 4, "blur": 1, "opacity": 100});
d.node_mut(NodeId(50)).unwrap().appearance.effects.push(vectorcraft_doc::Effect {
id: "stylize.dropShadow".into(),
params: shadow,
visible: true,
});
assert!(inked(&outline(&d), 20, 15), "first drawn crossed with a drop shadow");
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");
}
#[test]
fn an_enveloped_placed_document_shows_its_file_once_read() {
let mut d = doc("enveloped-1");
+129
View File
@@ -63,3 +63,132 @@ fn outline_mode_draws_images_in_grey_only_when_the_setup_asks() {
// Preview mode keeps the colours.
assert_eq!(Renderer::new().render(&d, 40, 40, Affine::IDENTITY, &RenderOptions::default()).pixel(20, 20), [255, 0, 0, 255]);
}
/// A 60×60 document holding the red 40×40 image of [`doc_with_red_image`] placed by `xf`, linked
/// to a file when `linked`, and with its corners moved to `corners` when given.
fn doc_with_image(linked: bool, xf: Affine, corners: Option<[(f64, f64); 4]>) -> Document {
let red = doc_with_red_image().images["red"].clone();
let mut d = Document::new(60.0, 60.0);
d.images.insert("red".into(), red);
let link = linked.then(|| vectorcraft_doc::LinkInfo::new("/art/red.png"));
let im = ImageObject { key: "red".into(), width: 40, height: 40, xf, link, placement: Default::default(), pixels: None };
let mut n = Node::new(d.alloc_id(), NodeKind::Image(Box::new(im)));
if let Some(q) = corners {
n.set_image_corners(q.map(vectorcraft_geom::Point::from)).unwrap();
}
d.insert(Some(d.layers[0].id), 0, n).unwrap();
d
}
/// The alpha of each of `pixels` of `d` drawn 60×60 in outline mode.
fn outline_alphas(d: &Document, pixels: &[(u32, u32)]) -> Vec<u8> {
let r = Renderer::new().render(d, 60, 60, Affine::IDENTITY, &RenderOptions { outline: true, ..Default::default() });
pixels.iter().map(|&(x, y)| r.pixel(x, y)[3]).collect()
}
#[test]
fn outline_mode_crosses_a_linked_images_frame_unless_the_setup_shows_images() {
// (20, 20) is where the diagonals cross, (25, 10) is on neither of them.
let at = [(20, 20), (25, 10)];
let mut linked = doc_with_image(true, Affine::IDENTITY, None);
let [cross, off] = outline_alphas(&linked, &at)[..] else { panic!("two pixels") };
assert!(cross > 0, "a linked image is crossed from corner to corner");
assert_eq!(off, 0, "and filled with nothing else");
let embedded = doc_with_image(false, Affine::IDENTITY, None);
assert_eq!(outline_alphas(&embedded, &at), vec![0, 0], "an embedded image shows its frame alone");
linked.setup.outline_images = true;
let r = Renderer::new().render(&linked, 60, 60, Affine::IDENTITY, &RenderOptions { outline: true, ..Default::default() });
let [red, green, blue, alpha] = r.pixel(20, 20);
assert!(alpha == 255 && red == green && green == blue && (50..=58).contains(&red), "the image's gray pixels, not crossed: {:?}", r.pixel(20, 20));
let preview = Renderer::new().render(&linked, 60, 60, Affine::IDENTITY, &RenderOptions::default());
assert_eq!(preview.pixel(20, 20), [255, 0, 0, 255], "preview and output draw the pixels uncrossed");
}
#[test]
fn outline_mode_crosses_a_linked_image_with_a_color_mask() {
use vectorcraft_doc::color_mask::{ColorMask, MaskBackground, MaskMatch};
let mut d = doc_with_image(true, Affine::IDENTITY, None);
let red = d.images["red"].clone();
d.images.insert("red-masked".into(), red);
let id = d.layers[0].children().unwrap()[0].id;
let mask = ColorMask {
key: "red-masked".into(),
from: "red".into(),
background: MaskBackground::Colors,
colors: vec![[255, 255, 255]],
contiguous: false,
measure: MaskMatch::Distance,
tolerance: 10.0,
softness: 0.0,
};
d.node_mut(id).unwrap().extras_mut().color_mask = Some(Box::new(mask));
let NodeKind::Image(im) = &d.layers[0].children().unwrap()[0].kind else { panic!("an image") };
assert!(d.shown_image(&d.layers[0].children().unwrap()[0], im).link.is_none(), "the masked copy drawn has no link");
assert!(outline_alphas(&d, &[(20, 20)])[0] > 0, "the image is crossed as linked");
}
/// The pieces an envelope cuts a linked image into are each a copy of the whole image; Outline mode
/// does not cross them, so the envelope draws as it does for an embedded image.
#[test]
fn outline_mode_does_not_cross_the_pieces_of_an_enveloped_linked_image() {
let drawn = |linked: bool| {
let mut d = doc_with_image(linked, Affine::translate((10.0, 10.0)), None);
let id = d.layers[0].children().unwrap()[0].id;
let image = d.remove(id).unwrap();
let kind = vectorcraft_doc::EnvelopeKind::Warp { style: "arc".into(), bend: 30.0, h: 0.0, v: 0.0, horizontal: true, version: 0 };
let envelope = NodeKind::Envelope {
content: vec![image],
kind: Box::new(kind),
fidelity: 50.0,
editing: false,
options: Default::default(),
frame: Box::new(Affine::IDENTITY),
};
let envelope = Node::new(d.alloc_id(), envelope);
d.insert(Some(d.layers[0].id), 0, envelope).unwrap();
Renderer::new().render(&d, 60, 60, Affine::IDENTITY, &RenderOptions { outline: true, ..Default::default() }).pixels
};
let embedded = drawn(false);
assert!(embedded.iter().any(|v| *v > 0), "the envelope draws in outline mode");
assert!(drawn(true) == embedded, "a linked image's pieces are not crossed");
}
/// A linked image moved into a piece of an expanded envelope is not the piece's copy of its image,
/// and is crossed.
#[test]
fn outline_mode_crosses_a_linked_image_moved_into_a_warp_piece() {
let mut d = doc_with_image(true, Affine::IDENTITY, None);
let id = d.layers[0].children().unwrap()[0].id;
let mine = d.remove(id).unwrap();
let copy = Arc::new(Node::new(d.alloc_id(), mine.kind.clone()));
let mut clip = Node::path(d.alloc_id(), vectorcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 60.0, 60.0)), Default::default());
if let NodeKind::Path { clipping, .. } = &mut clip.kind {
*clipping = true;
}
let NodeKind::Image(im) = &mine.kind else { panic!("an image") };
let moved = ImageObject { xf: Affine::translate((10.0, 0.0)), ..(**im).clone() };
let moved = Node::new(mine.id, NodeKind::Image(Box::new(moved)));
let mut piece = Node::new(d.alloc_id(), NodeKind::Group { children: vec![Arc::new(clip), copy, Arc::new(moved)], clip: true });
piece.extras_mut().warp_piece = true;
d.insert(Some(d.layers[0].id), 0, piece).unwrap();
// The copy's diagonals cross at (20, 20), the moved image's at (30, 20).
let [copy_cross, moved_cross] = outline_alphas(&d, &[(20, 20), (30, 20)])[..] else { panic!("two pixels") };
assert_eq!(copy_cross, 0, "the piece's own image is not crossed");
assert!(moved_cross > 0, "the image moved into it is");
}
#[test]
fn outline_mode_crosses_a_turned_or_distorted_linked_image_through_its_corners() {
// Turned 0.5 radians about (30, 30): the points three quarters of the way along each diagonal.
let xf = Affine::translate((30.0, 30.0)) * Affine::rotate(0.5) * Affine::translate((-20.0, -20.0));
let on = [xf * vectorcraft_geom::Point::new(30.0, 30.0), xf * vectorcraft_geom::Point::new(10.0, 30.0)];
let at: Vec<(u32, u32)> = on.iter().map(|p| (p.x.floor() as u32, p.y.floor() as u32)).collect();
assert!(outline_alphas(&doc_with_image(true, xf, None), &at).iter().all(|a| *a > 0), "{at:?} on the turned diagonals");
assert_eq!(outline_alphas(&doc_with_image(false, xf, None), &at), vec![0, 0], "an embedded image is not crossed");
// Distorted to (10, 5), (50, 5), (55, 55), (5, 50): (43.75, 42.5) is on one diagonal, (38.75, 16.25)
// on the other.
let q = Some([(10.0, 5.0), (50.0, 5.0), (55.0, 55.0), (5.0, 50.0)]);
let at = [(43, 42), (38, 16)];
assert!(outline_alphas(&doc_with_image(true, Affine::IDENTITY, q), &at).iter().all(|a| *a > 0), "on the distorted diagonals");
assert_eq!(outline_alphas(&doc_with_image(false, Affine::IDENTITY, q), &at), vec![0, 0], "a distorted embedded image is not crossed");
}