DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge origin/main into codex/eyedropper-text-format
moppeeer6bc1bbff8912
diff --cc ROADMAP.mdindex 56f77c5a7,d60a6bf49..4672e6368--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -132,7 -347,20 +347,21 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-15** · The Eyedropper with text selected picks up the formatting of the text it clicks (character style and overrides, paragraph style and overrides) and applies it to the selection, as InDesign's does; it copied the clicked frame's fill and stroke instead. No readiness percentage change.+ - **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.+ - **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.+ - **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.+ - **2026-10-14** · The Color panel's Tint field keeps what is typed while it has focus and applies it on Enter or when it loses focus, clamped to 0–100 %. Typing 60 over 100 % no longer snaps back to 100 after the first digit (10060), and a typed tint is no longer ignored. No readiness percentage change.+ - **2026-10-15** · IDML: ruler guides import and export (they were dropped). Each page's guides come in measured from the document's ruler origin (spread, page or spine), with Fit to Page, Locked and their layer, parent pages' included, and go out again under their pages. No readiness percentage change.+ - **2026-10-15** · Find Font no longer reports a style missing when it differs from the installed one only in spacing or case (InDesign files can name `Regular ` with a trailing space); the text was already drawn in the right face. No readiness percentage change.+ - **2026-10-15** · A line of text is set when its baseline fits in the frame, as in InDesign: descenders may hang below the frame's bottom. A frame sized to the cap height of a big heading (103 pt in a 2.77 cm frame, as Zero2Graphic's magazine tutorial draws them) no longer oversets. No readiness percentage change.+ - **2026-10-15** · A story that ends with a return is no longer overset when only its empty last paragraph doesn't fit, as in InDesign (Preflight said "Overset text: 0 characters" for a caption InDesign shows with no errors). No readiness percentage change.+ - **2026-10-15** · Flex Layout (InDesign 2026): Object › Flex Layout (Add to, Convert to, Remove) and a Flex Layout panel laid out as InDesign's, also in Properties. A container lays out its objects by direction, wrap, justification, the alignment grid, Fixed/Auto width and height, padding and spacing, after every edit; Add detects aligned objects (direction, Auto size, Space Between at their spacing); resizing a container reflows its objects instead of scaling them; dragging an object in one reorders it. Montilla Design's tutorial replays step for step. No readiness percentage change.+ - **2026-10-14** · Layout › Margins and Columns and Layout › Create Guides are laid out as InDesign's: Margins in Top/Bottom and Inside/Outside pairs with a link button that makes all four the same, Rows and Columns side by side, Fit Guides to Margins or Page, and a Preview checkbox that shows the change on the canvas before OK. A measurement field works out arithmetic when you leave it (`0.4375 in*2` becomes `0.875 in`). No readiness percentage change.+ - **2026-10-14** · The Pathfinder panel is laid out as InDesign's: Paths (Join, Open, Close, Reverse), Pathfinder, Convert Shape and Convert Point, each a row of icon buttons. Join Path closes an open path or joins two at their nearest ends (`path.join`), and Convert Point makes the selected points plain, corner, smooth or symmetrical (`path.convertPoints`). No readiness percentage change.+ - **2026-10-12** · Linked text files (#597): placed Word, RTF and text files can stay linked; the Links panel shows them OK / Modified / Missing, and Update imports the file again into the same frames with the saved style map (the Links panel asks before replacing edits made in the layout). No readiness percentage change.+ - **2026-10-15** · IDML: the CJK leading model InDesign writes on [No paragraph style] of every document (Aki Below) only applies when the document uses a Japanese composer, as in InDesign; a Western document's paragraphs after a size change no longer sit lower than in InDesign (Montilla Design's Flex Layout file: its captions came out overset). No readiness percentage change.+ - **2026-10-14** · Type › Fill with Placeholder Text fills a frame with paragraphs of a few sentences, as InDesign does, so one paragraph can be styled on its own (it was one long paragraph, and the filler ran sentences together, "interit.Ovid"). No readiness percentage change.- **2026-10-13** · Object › Fitting has InDesign's shortcuts: Fill Frame Proportionally ⌘⌥⇧C, Fit Content Proportionally ⌘⌥⇧E, Fit Frame to Content ⌘⌥C, Fit Content to Frame ⌘⌥E, Center Content ⌘⇧E. No readiness percentage change.- **2026-10-13** · Gradients between process colours blend as inks, as InDesign shows them: magenta to cyan passes through C 50 M 50 (a light lilac) on screen instead of the darker RGB mix, and a midpoint between CMYK or grey stops no longer turns the PDF shading RGB. No readiness percentage change.- **2026-10-14** · The Swatches panel has InDesign's header: a Fill/Stroke proxy, Formatting Affects Container/Text and the Tint of the colour in front (a tint alone keeps each object's own swatch). Clicking a swatch applies it to the fill or stroke in front (of the text, when formatting affects text), and the bottom row has New Color Group, New Swatch and Delete Swatch. No readiness percentage change.diff --cc crates/engine/src/cmd/text.rsindex 7625e36e1,432297f35..842f3a4c9--- a/crates/engine/src/cmd/text.rs+++ b/crates/engine/src/cmd/text.rs@@@ -2601,41 -2787,261 +2828,300 @@@ mod sentence_selection_tests}}+ #[cfg(test)]+ mod open_type_features_tests {+ use serde_json::{Value, json};++ use crate::Session;++ fn feature<'a>(v: &'a Value, tag: &str) -> &'a Value {+ v["features"].as_array().unwrap().iter().find(|f| f["tag"] == tag).unwrap_or(&Value::Null)+ }++ #[test]+ fn the_selected_fonts_features_are_listed_with_their_state() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello fi"})).unwrap();+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 8})).unwrap();+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();+ assert_eq!(v["fonts"][0]["family"], "Source Serif 4", "{v}");+ assert_eq!(feature(&v, "liga")["applied"], "all", "liga is on by default: {v}");+ assert_eq!(feature(&v, "kern")["available"], "all", "{v}");+ }++ #[test]+ fn a_feature_on_part_of_the_selection_is_some_and_on_all_of_it_is_all() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello world"})).unwrap();+ let story = r["story"].clone();+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();+ s.execute("type.feature", &json!({"features": {"lnum": true}})).unwrap();+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();+ assert_eq!(feature(&v, "lnum")["applied"], "some", "{v}");+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();+ assert_eq!(feature(&v, "lnum")["applied"], "all", "{v}");+ s.execute("type.feature", &json!({"features": {"lnum": false}})).unwrap();+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();+ assert_eq!(feature(&v, "lnum")["applied"], "none", "{v}");+ }+ }++ #[cfg(test)]+ mod gradient_text_tests {+ use serde_json::json;++ /// Mean red and blue of the ink (pixels whose green is low: red → blue has none) in columns+ /// `x0..x1`.+ fn ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);+ for x in x0..x1 {+ for y in 0..img.height {+ let p = img.pixel(x, y);+ if p[1] < 100 {+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);+ }+ }+ }+ assert!(n > 50.0, "no ink in {x0}..{x1}");+ (r / n, b / n)+ }++ /// Red ink at the frame's left, blue at its right.+ fn check(img: &designcraft_render::Rendered, what: &str) {+ let (lr, lb) = ink(img, 0, 60);+ let (rr, rb) = ink(img, 200, 300);+ assert!(lr > lb + 80.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");+ assert!(rb > rr + 80.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");+ }++ #[test]+ fn a_gradient_on_text_spans_its_frame_on_screen_and_in_pdf() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();+ // A gradient swatch (an off-page object's unnamed one), red → blue.+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))+ .unwrap();+ let id = designcraft_doc::ItemId(shape.as_u64().unwrap());+ let swatch = s.doc().unwrap().doc.item(id).unwrap().fill.swatch.clone();+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": "IIIIIIIIIIIIIIIIIIIIIIIIIIIIII"})).unwrap();+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 30})).unwrap();+ s.execute("type.char", &json!({"size": 60, "tracking": 0, "fill": swatch})).unwrap();+ let d = s.doc().unwrap().doc.clone();+ let mut rr = designcraft_render::Renderer::new();+ check(&rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap(), "screen");+ // The PDF, placed back and drawn: the same gradient.+ let pdf = designcraft_pdf::export_pdf(&d, &s.cache, &Default::default()).unwrap();+ let mut p = crate::Session::new();+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "text.pdf", "x": 0, "y": 0, "width": 300}))+ .unwrap();+ let d = p.doc().unwrap().doc.clone();+ check(&rr.render_page(&d, &p.cache, 0, 1.0, false, &Default::default()).unwrap(), "pdf");+ }++ /// The columns the red → blue ink spans (black table edges left out).+ fn ink_span(img: &designcraft_render::Rendered) -> (u32, u32) {+ let cols: Vec<u32> = (0..img.width)+ .filter(|&x| {+ (0..img.height).any(|y| {+ let p = img.pixel(x, y);+ p[1] < 100 && p[0].max(p[2]) > 100+ })+ })+ .collect();+ (*cols.first().unwrap(), *cols.last().unwrap())+ }++ /// Mean red and blue of the red → blue ink in columns `x0..x1`.+ fn coloured_ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);+ for x in x0..x1 {+ for y in 0..img.height {+ let p = img.pixel(x, y);+ if p[1] < 100 && p[0].max(p[2]) > 100 {+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);+ }+ }+ }+ assert!(n > 20.0, "no ink in {x0}..{x1}");+ (r / n, b / n)+ }++ #[test]+ fn a_gradient_on_table_cell_text_spans_the_cells_text_in_pdf_as_on_screen() {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();+ // A gradient swatch (an off-page object's unnamed one), red → blue.+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))+ .unwrap();+ let g = s.doc().unwrap().doc.item(designcraft_doc::ItemId(shape.as_u64().unwrap())).unwrap().fill.swatch.clone();+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": ""})).unwrap();+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 0})).unwrap();+ s.execute("table.insert", &json!({"rows": 1, "cols": 3})).unwrap();+ // A third of the frame's width: the cell's text, red → blue.+ let mut d: designcraft_doc::Document = (*s.doc().unwrap().doc).clone();+ let sid = d.stories.values().find(|st| !st.tables.is_empty()).unwrap().id;+ let t = std::sync::Arc::make_mut(d.story_mut(sid).unwrap().tables.values_mut().next().unwrap());+ let text = &mut t.cell_mut(0, 0).unwrap().text;+ text.insert(0, "HHHH");+ text.format_chars(0..4, |f| {+ f.over.fill = Some(g.clone());+ f.over.size = Some(24.0);+ });+ let mut rr = designcraft_render::Renderer::new();+ let cache = designcraft_compose::Cache::new();+ let screen = rr.render_page(&d, &cache, 0, 1.0, false, &Default::default()).unwrap();+ let pdf = designcraft_pdf::export_pdf(&d, &cache, &Default::default()).unwrap();+ let mut p = crate::Session::new();+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "cell.pdf", "x": 0, "y": 0, "width": 300}))+ .unwrap();+ let placed = rr.render_page(&p.doc().unwrap().doc.clone(), &p.cache, 0, 1.0, false, &Default::default()).unwrap();+ let (x0, x1) = ink_span(&screen);+ assert!(x1 < 120, "the text stays in the first column: {x0}..{x1}");+ let q = (x1 - x0) / 4;+ for (what, img) in [("screen", &screen), ("pdf", &placed)] {+ let (lr, lb) = coloured_ink(img, x0, x0 + q);+ let (rr, rb) = coloured_ink(img, x1 + 1 - q, x1 + 1);+ assert!(lr > lb + 50.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");+ assert!(rb > rr + 50.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");+ }+ }+ }++ #[cfg(test)]+ mod compose_tests {+ use serde_json::json;++ use crate::Session;++ /// A story "Ta" with the caret after "T" and 30 pt chosen for the next typing.+ fn session() -> (Session, u64) {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 500, 200], "content": "text", "text": "Ta"})).unwrap();+ let sid = r["story"].as_u64().unwrap();+ s.set_tool("type");+ s.execute("text.select", &json!({"story": sid, "anchor": 1})).unwrap();+ s.execute("type.char", &json!({"attrs": {"size": 30}})).unwrap();+ (s, sid)+ }++ fn text(s: &Session, sid: u64) -> String {+ s.doc().unwrap().doc.story(designcraft_doc::StoryId(sid)).unwrap().text.clone()+ }++ /// ⌥E shows the accent in the story, in the format it will be typed in, then I types "í":+ /// one undo step, and the accent was never part of the document.+ #[test]+ fn composed_text_shows_in_the_typing_format_until_it_is_typed() {+ let (mut s, sid) = session();+ let r = s.execute("text.compose", &json!({"text": "´"})).unwrap();+ assert_eq!(r["range"], json!([1, 3]));+ assert_eq!(text(&s, sid), "T´a");+ let size_at = |s: &Session, b| s.doc().unwrap().doc.story(designcraft_doc::StoryId(sid)).unwrap().char_format_at(b).over.size;+ assert_eq!(size_at(&s, 2), Some(30.0), "the accent is shown in the format chosen at the caret");+ assert_eq!(s.composition().map(|c| c.2), Some(1..3));+ s.execute("text.compose", &json!({"text": "¨"})).unwrap();+ assert_eq!(text(&s, sid), "T¨a", "a new composition replaces the last one");+ s.execute("text.compose", &json!({"text": ""})).unwrap();+ assert_eq!(text(&s, sid), "Ta");+ assert!(s.composition().is_none());+ s.execute("text.insert", &json!({"text": "í"})).unwrap();+ assert_eq!(text(&s, sid), "Tía");+ assert_eq!(size_at(&s, 2), Some(30.0), "the typing format survived the composition");+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(text(&s, sid), "Ta");+ }++ /// Anything else that edits, a tool change or a drag drops the uncommitted accent.+ #[test]+ fn other_edits_drop_the_composed_text() {+ for act in 0..3 {+ let (mut s, sid) = session();+ s.execute("text.compose", &json!({"text": "´"})).unwrap();+ match act {+ 0 => {+ s.execute("text.move", &json!({"dir": "right"})).unwrap();+ }+ 1 => s.set_tool("selection"),+ _ => s.begin_interaction("Move").unwrap(),+ }+ assert_eq!(text(&s, sid), "Ta", "case {act}");+ assert!(s.composition().is_none());+ }+ }+ }++ #[cfg(test)]+ mod placeholder_tests {+ use serde_json::json;++ use crate::Session;++ /// Fill with Placeholder Text gives paragraphs of a few sentences, as InDesign's does (it was one+ /// paragraph, and the filler ran sentences together: "interit.Ovid").+ #[test]+ fn placeholder_text_comes_in_paragraphs() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let r = s.execute("frame.create", &json!({"rect": [36, 36, 336, 736], "content": "text", "text": ""})).unwrap();+ s.execute("type.fillWithPlaceholder", &json!({"frame": r["id"]})).unwrap();+ let st = s.execute("story.get", &json!({"story": r["story"]})).unwrap();+ let text = st["text"].as_str().unwrap();+ let paragraphs: Vec<&str> = text.split('\n').collect();+ assert!(paragraphs.len() >= 4, "{} paragraphs", paragraphs.len());+ for p in ¶graphs {+ assert!(p.ends_with('.') && !p.starts_with(' '), "a paragraph of whole sentences: {p:?}");+ }+ assert!(!text.contains(".O") && !text.contains(".L"), "sentences are spaced: {text}");+ assert!(st["overset"].is_null(), "nothing overset: {}", st["overset"]);+ assert!(text.len() > 1500, "the frame is filled: {}", text.len());+ }+ }+++#[cfg(test)]+mod pick_up_format_tests {+ use designcraft_doc::ItemId;+ use serde_json::json;++ use crate::Session;++ /// Typefool's video (12:04): select body text, Eyedropper, click the third header: the body+ /// text takes the header's font, size and paragraph settings. DesignCraft copied the frame's+ /// fill and stroke instead.+ #[test]+ fn the_eyedropper_copies_text_formatting_to_selected_text() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let head = s.execute("frame.create", &json!({"rect": [36, 36, 400, 100], "content": "text", "text": "Innovative Design"})).unwrap();+ s.execute("text.select", &json!({"story": head["story"], "anchor": 0, "focus": 17})).unwrap();+ s.execute("type.char", &json!({"attrs": {"fontStyle": "Bold", "size": 18, "tracking": 20}})).unwrap();+ s.execute("type.para", &json!({"attrs": {"align": "center", "spaceAfter": 6}})).unwrap();+ let body = s.execute("frame.create", &json!({"rect": [36, 200, 400, 300], "content": "text", "text": "Body copy here.\nSecond."})).unwrap();+ s.execute("text.select", &json!({"story": body["story"], "anchor": 0, "focus": 4})).unwrap();+ // Click the header's middle (the frame's text starts at its top left).+ let r = s.execute("type.pickUpFormat", &json!({"frame": head["id"], "point": [100, 50]})).unwrap();+ assert!(r.is_object(), "{r}");+ s.execute("text.select", &json!({"story": body["story"], "anchor": 0, "focus": 4})).unwrap();+ let a = s.execute("type.selectionAttrs", &json!({})).unwrap();+ assert_eq!((&a["chars"]["fontStyle"], &a["chars"]["size"], &a["chars"]["tracking"]), (&json!("Bold"), &json!(18.0), &json!(20.0)), "{a}");+ assert_eq!((&a["para"]["align"], &a["para"]["spaceAfter"]), (&json!("center"), &json!(6.0)));+ // Only the selected characters change; the second paragraph keeps its own.+ s.execute("text.select", &json!({"story": body["story"], "anchor": 6, "focus": 10})).unwrap();+ assert_eq!(s.execute("type.selectionAttrs", &json!({})).unwrap()["chars"]["size"], json!(12.0));+ s.execute("text.select", &json!({"story": body["story"], "anchor": 17, "focus": 20})).unwrap();+ assert_eq!(s.execute("type.selectionAttrs", &json!({})).unwrap()["para"]["align"], json!("left"));+ // Not a text frame, or nothing selected: refused.+ let rect = s.execute("frame.create", &json!({"rect": [500, 500, 520, 520]})).unwrap()["id"].as_u64().unwrap();+ assert!(s.execute("type.pickUpFormat", &json!({"frame": rect, "point": [510, 510]})).is_err());+ let _ = ItemId(rect);+ }+}diff --cc crates/tools/src/tests.rsindex 9390dcbbb,aacfb8d3f..7e59759a0--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@@ -1168,19 -1214,103 +1214,120 @@@ fn eyedropper_samples_a_placed_image_anassert_eq!(a, vec![Action::Exec("object.matchAttributes".into(), serde_json::json!({"from": photo.0}))]);}+/// With text selected, the Eyedropper on a text frame picks up its text formatting instead of+/// copying the frame's fill and stroke onto the selection (InDesign's Eyedropper).+#[test]+fn eyedropper_with_text_selected_picks_up_text_formatting() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (head, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 300.0, 140.0), lid, "Header", ParaFormat::default()).unwrap();+ let (_, body) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 200.0, 300.0, 300.0), lid, "Body", ParaFormat::default()).unwrap();+ let s = Selection::text(designcraft_doc::TextSel { story: body, anchor: 0, focus: 4, frame: None, cell: None });+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let off = l.xf(SpreadRef::Doc(0)).translation();+ let cx = ctx(&d, &s, &c, &l);+ let mut t = create("eyedropper");+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 150.0 + off.x, 120.0 + off.y));+ assert_eq!(a, vec![Action::Exec("type.pickUpFormat".into(), serde_json::json!({"frame": head.0, "point": [150.0, 120.0]}))]);+}+++ #[test]+ fn eyedropper_ignores_inactive_states_of_a_multi_state_object() {+ use designcraft_doc::{Asset, AssetId, Content, Graphic};+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ d.assets.insert(+ AssetId(1),+ std::sync::Arc::new(Asset {+ id: AssetId(1),+ name: "photo.png".into(),+ mime: "image/png".into(),+ link: None,+ data: std::sync::Arc::new(vec![]),+ pixels: Some((100, 100)),+ page: 0,+ }),+ );+ let area = Rect::new(100.0, 100.0, 200.0, 200.0);+ let raster = {+ let mut it = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));+ it.content = Content::Graphic(Graphic {+ asset: AssetId(1),+ size: (100.0, 100.0),+ xf: designcraft_geom::Affine::translate((0.0, 0.0)),+ auto_fit: Default::default(),+ fit_align: 4,+ crop: [0.0; 4],+ });+ it+ };+ let mut vector = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));+ vector.fill.swatch = "[Black]".into();+ let target = add_rect(&mut d, Rect::new(400.0, 100.0, 450.0, 150.0));+ let s = Selection { items: vec![target], ..Default::default() };+ let sample = Action::Exec("color.sample".into(), serde_json::json!({"at": [120.0, 130.0], "spread": {"kind": "doc", "index": 0}}));+ // Children [vector, raster] with the raster on top: it samples only while it is the active state.+ for (active, samples) in [(1, true), (0, false)] {+ let mut group = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));+ group.content = Content::Group { items: vec![std::sync::Arc::new(vector.clone()), std::sync::Arc::new(raster.clone())] };+ group.states = vec!["a".into(), "b".into()];+ group.active_state = active;+ let mut d2 = d.clone();+ d2.insert_item(SpreadRef::Doc(0), group, None).unwrap();+ let (c, l) = (Cache::new(), CanvasLayout::new(&d2, false));+ let off = l.xf(SpreadRef::Doc(0)).translation();+ let cx = ctx(&d2, &s, &c, &l);+ let a = create("eyedropper").pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0 + off.x, 130.0 + off.y));+ assert_eq!(a.contains(&sample), samples, "active state {active}: {a:?}");+ }+ }++ #[test]+ fn pen_cursor_shows_add_delete_and_close() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (fid, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 200.0, 200.0), lid, "", ParaFormat::default()).unwrap();+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let selected = Selection::items(vec![fid]);+ let none = Selection::default();+ let off = l.xf(SpreadRef::Doc(0)).translation();+ let at = |x: f64, y: f64| Point::new(x + off.x, y + off.y);+ let mut t = create("pen");+ let m = Mods::default();++ let cx = ctx(&d, &selected, &c, &l);+ assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::PenDelete, "on a selected path's anchor");+ assert_eq!(t.cursor(&cx, at(150.0, 101.0), m), Cursor::PenAdd, "on a selected path's outline");+ assert_eq!(t.cursor(&cx, at(150.0, 150.0), m), Cursor::Pen, "inside, away from the outline");+ let click = |t: &mut Box<dyn Tool>, cx: &ToolContext, p: Point| {+ let down = t.pointer(cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));+ let up = t.pointer(cx, &PointerEvent::new(PointerKind::Up, p.x, p.y));+ (down, up)+ };+ let (down, up) = click(&mut t, &cx, at(200.0, 100.0));+ assert_eq!(down, vec![Action::Exec("path.deleteAnchor".into(), serde_json::json!({"id": fid.0, "subpath": 0, "anchor": 1}))]);+ assert!(up.is_empty() && !t.busy(), "deleting starts no path");+ let (down, _) = click(&mut t, &cx, at(150.0, 101.0));+ assert!(matches!(&down[..], [Action::Exec(cmd, p)] if cmd == "path.addAnchor" && p["id"] == fid.0), "{down:?}");++ // Unselected paths are drawn over; the first anchor of the path being drawn closes it.+ let cx = ctx(&d, &none, &c, &l);+ assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::Pen, "unselected path");+ click(&mut t, &cx, at(300.0, 300.0));+ assert_eq!(t.cursor(&cx, at(300.0, 300.0), m), Cursor::Pen, "one anchor cannot close yet");+ click(&mut t, &cx, at(400.0, 300.0));+ assert_eq!(t.cursor(&cx, at(301.0, 301.0), m), Cursor::PenClose, "on the first anchor");+ assert_eq!(t.cursor(&cx, at(350.0, 350.0), m), Cursor::Pen, "elsewhere while drawing");+ }++ #[test]+ fn anchor_tools_show_pen_state_cursors() {+ let d = Document::new(&NewDocument::default());+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let p = Point::new(10.0, 10.0);+ let cursor = |id: &str| create(id).cursor(&cx, p, Mods::default());+ assert_eq!(cursor("addAnchor"), Cursor::PenAdd);+ assert_eq!(cursor("deleteAnchor"), Cursor::PenDelete);+ assert_eq!(cursor("convertDirection"), Cursor::PenConvert);+ }diff --cc crates/tools/src/xform.rsindex f67c84386,d57596cf8..81c9e9b50--- a/crates/tools/src/xform.rs+++ b/crates/tools/src/xform.rs@@@ -299,9 -301,14 +301,14 @@@ impl Tool for EyedropperToollet selected = !cx.selection.items.is_empty() || cx.selection.text.is_some() || cx.selection.cells.is_some();// A placed image under the pointer is sampled (its layer may be locked: sampling changes nothing).if selected && let Some((sr, at)) = image_under(cx, ev.pos) {- return vec![Action::Exec("color.sample".into(), json!({"at": [at.x, at.y], "spread": sr}))];+ // To the fill or stroke in front in the toolbox, as in InDesign.+ let mut p = json!({"at": [at.x, at.y], "spread": sr});+ if cx.stroke_in_front {+ p["target"] = json!("stroke");+ }+ return vec![Action::Exec("color.sample".into(), p)];}- let Some((_, id)) = cx.hit(ev.pos) else { return vec![] };+ let Some((sr, id)) = cx.hit(ev.pos) else { return vec![] };if !selected {return vec![Action::Exec("selection.set".into(), json!({"ids": [id.0]}))];}