From 80e32f8ef7e7d437586a4e72f54703e87dcc89ba Mon Sep 17 00:00:00 2001 From: DingusMcRinkyDinky <127614779+DingusMcRinkyDinky@users.noreply.github.com> Date: Tue, 3 Nov 2026 08:24:33 +0100 Subject: [PATCH] Pen: Make Shape turns the path into a shape layer (#10934) The Pen options bar in Path mode only offered Make Selection, so a drawn path could not become a shape layer. Make Shape now does that, next to Make Selection, with the shape tools' fill and stroke, as one History step. A path still being drawn is finished first. The Work Path becomes the shape's path and is removed; a saved path stays. New engine command path.toShape, so scripts and agents can do the same. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EZbgszHyuEuWAzxaamteuU --- crates/engine/src/cmd/vector_cmds.rs | 12 +++- crates/engine/src/cmd/vector_cmds/shape.rs | 54 +++++++++++++---- crates/engine/src/cmd/vector_cmds/tests.rs | 52 ++++++++++++++++ crates/ui-egui/src/i18n/ar.tsv | 1 + crates/ui-egui/src/i18n/cs.tsv | 1 + crates/ui-egui/src/i18n/da.tsv | 1 + crates/ui-egui/src/i18n/de.tsv | 1 + crates/ui-egui/src/i18n/el.tsv | 1 + crates/ui-egui/src/i18n/es.tsv | 1 + crates/ui-egui/src/i18n/fi.tsv | 1 + crates/ui-egui/src/i18n/fr.tsv | 1 + crates/ui-egui/src/i18n/hu.tsv | 1 + crates/ui-egui/src/i18n/id.tsv | 1 + crates/ui-egui/src/i18n/it.tsv | 1 + crates/ui-egui/src/i18n/ja.tsv | 1 + crates/ui-egui/src/i18n/ko.tsv | 1 + crates/ui-egui/src/i18n/nb.tsv | 1 + crates/ui-egui/src/i18n/nl.tsv | 1 + crates/ui-egui/src/i18n/pl.tsv | 1 + crates/ui-egui/src/i18n/pt-br.tsv | 1 + crates/ui-egui/src/i18n/ru.tsv | 1 + crates/ui-egui/src/i18n/sr.tsv | 1 + crates/ui-egui/src/i18n/sv.tsv | 1 + crates/ui-egui/src/i18n/tr.tsv | 1 + crates/ui-egui/src/i18n/uk.tsv | 1 + crates/ui-egui/src/i18n/vi.tsv | 1 + crates/ui-egui/src/i18n/zh-hans.tsv | 1 + crates/ui-egui/src/i18n/zh-hant.tsv | 1 + crates/ui-egui/src/tools/vector_ui.rs | 4 +- crates/ui-egui/src/tools/vector_ui/options.rs | 7 +++ .../ui-egui/src/tools/vector_ui/path_ops.rs | 19 ++++++ .../src/tools/vector_ui/pen_path_ops_tests.rs | 59 +++++++++++++++++++ 32 files changed, 220 insertions(+), 12 deletions(-) diff --git a/crates/engine/src/cmd/vector_cmds.rs b/crates/engine/src/cmd/vector_cmds.rs index f331a303353..21bfbfddbaf 100644 --- a/crates/engine/src/cmd/vector_cmds.rs +++ b/crates/engine/src/cmd/vector_cmds.rs @@ -80,7 +80,7 @@ pub(crate) use paths::{is_work, path_mut}; pub(crate) use shape::{bake_path, map_path, map_shape, shift_shape, with_shape}; use shape::{ can_paste_shape_fill, can_paste_shape_stroke, combine_shapes, copy_shape_fill, copy_shape_stroke, has_shape_fill, has_shape_stroke, merge_components, - paste_shape_fill, paste_shape_stroke, selection_to_shape, shape_create, shape_edit, shape_info, shape_rasterize, + paste_shape_fill, paste_shape_stroke, path_to_shape, selection_to_shape, shape_create, shape_edit, shape_info, shape_rasterize, }; pub use shape::{preview_shape_stroke, refresh_shape, shape_path, transform_shape, translate_vectors}; use vector_mask::{toggle_vector_mask, vector_mask_add, vector_mask_delete, vector_mask_edit, vector_mask_info, vector_mask_rasterize, with}; @@ -230,6 +230,16 @@ pub fn specs() -> Vec { run: |s, p| path_to_selection_with_mode(s, p, "subtract"), journal: true, }, + spec!( + "path.toShape", + "Make Shape from Path", + [], + leak(format!( + r##"{{"name":str|"work"|"layer"="work" (the Work Path becomes the shape's path; a saved path stays),{fill}=foreground,{stroke}=none,"layerName":str?}} → shape.info"## + )), + has_doc, + path_to_shape + ), spec!("select.toWorkPath", "Make Work Path", [], r##"{"tolerance":0.5..10 px=2} → {subpaths,knots}"##, has_selection, select_to_work_path), spec!( "path.fill", diff --git a/crates/engine/src/cmd/vector_cmds/shape.rs b/crates/engine/src/cmd/vector_cmds/shape.rs index 33e1bfe3cfa..432b8b47f2d 100644 --- a/crates/engine/src/cmd/vector_cmds/shape.rs +++ b/crates/engine/src/cmd/vector_cmds/shape.rs @@ -424,16 +424,7 @@ pub(super) fn shape_create(s: &mut Session, p: &Value) -> Result { let l = live_from_params(CMD, kind, p, None)?; (vector::shapes::live_path(&l), Some(l)) }; - let fg = s.tools.foreground; - let fgc = Color::rgba(fg[0], fg[1], fg[2], fg[3]); - let fill = match p.get("fill") { - Some(v) => parse_fill(v).map_err(|e| bad(CMD, e))?, - None => Some(Fill::Solid(fgc)), - }; - let stroke = match p.get("stroke") { - Some(v) => parse_stroke(v, None, fgc).map_err(|e| bad(CMD, e))?, - None => None, - }; + let (fill, stroke) = new_fill_stroke(s, CMD, p)?; vector::flatten::validate_shape(&path, stroke.as_ref()).map_err(|e| bad(CMD, e))?; // Add to an existing shape layer with a path operation (Shape tool in combine/subtract… mode). if let Some(target) = p.get("addTo").and_then(Value::as_u64) { @@ -463,6 +454,49 @@ pub(super) fn shape_create(s: &mut Session, p: &Value) -> Result { shape_info(s, id) } +/// A new shape layer's `fill` (default the foreground colour) and `stroke` (default none). +fn new_fill_stroke(s: &Session, cmd: &str, p: &Value) -> Result<(Option, Option)> { + let fg = s.tools.foreground; + let fgc = Color::rgba(fg[0], fg[1], fg[2], fg[3]); + let fill = match p.get("fill") { + Some(v) => parse_fill(v).map_err(|e| bad(cmd, e))?, + None => Some(Fill::Solid(fgc)), + }; + let stroke = match p.get("stroke") { + Some(v) => parse_stroke(v, None, fgc).map_err(|e| bad(cmd, e))?, + None => None, + }; + Ok((fill, stroke)) +} + +/// The Pen options bar's Make: Shape: a new shape layer from the work path or a saved path, as one +/// History step. The Work Path becomes the shape's path, so it is gone afterwards; a saved path +/// stays. With no work path, `"work"` takes the active layer's path, as the other path commands do. +pub(super) fn path_to_shape(s: &mut Session, p: &Value) -> Result { + const CMD: &str = "path.toShape"; + let name = p.get("name").and_then(Value::as_str); + let path = super::resolve_path(s, name)?; + if path.subpaths.iter().all(|sp| sp.knots.is_empty()) { + return Err(bad(CMD, "the path is empty")); + } + let (fill, stroke) = new_fill_stroke(s, CMD, p)?; + vector::flatten::validate_shape(&path, stroke.as_ref()).map_err(|e| bad(CMD, e))?; + let layer_name = p.get("layerName").and_then(Value::as_str).map(str::to_string); + let consume_work = super::is_work(name); + let mut sh = ShapeLayer { path, fill, stroke, ..Default::default() }; + let id = s.edit("New Shape Layer", |doc, active| { + refresh_shape(doc, &mut sh); + let name = layer_name.unwrap_or_else(|| doc.next_layer_name(default_name("path"))); + let id = crate::layer_place::insert_new(doc, *active, Layer::new(name, LayerContent::Shape(sh)), crate::layer_place::Place::AutoEditable); + if consume_work { + doc.work_path = None; + } + *active = Some(id); + Ok(id) + })?; + shape_info(s, id) +} + pub(super) fn shape_edit(s: &mut Session, p: &Value) -> Result { const CMD: &str = "shape.edit"; let id = layer_id(s, p)?; diff --git a/crates/engine/src/cmd/vector_cmds/tests.rs b/crates/engine/src/cmd/vector_cmds/tests.rs index b659cbd656d..ef48efe5a8c 100644 --- a/crates/engine/src/cmd/vector_cmds/tests.rs +++ b/crates/engine/src/cmd/vector_cmds/tests.rs @@ -403,6 +403,58 @@ fn path_to_selection_matches_analytic_shape() { assert!(m[100 * 200 + 160] > 0.2 && m[100 * 200 + 160] < 0.8); } +#[test] +fn path_to_shape_makes_a_shape_layer_from_the_work_path_in_one_step() { + let mut s = session(80, 80, 8); + let square = json!({"subpaths": [{"knots": [[10, 10], [50, 10], [50, 50], [10, 50]]}]}); + s.execute("path.set", json!({"path": square})).unwrap(); + let history = s.active().unwrap().history.past_len(); + let info = s.execute("path.toShape", json!({"fill": "#ff0000"})).unwrap(); + let id = LayerId(info["layer"].as_u64().unwrap()); + let d = doc(&s); + let LayerContent::Shape(sh) = &d.layer(id).unwrap().content else { panic!("not a shape layer") }; + assert_eq!(sh.path.subpaths[0].knots.len(), 4); + assert_eq!(sh.fill, Some(Fill::Solid(Color::rgba(1.0, 0.0, 0.0, 1.0)))); + // The Work Path became the shape's path. + assert!(d.work_path.is_none()); + assert_eq!(s.active().unwrap().active_layer, Some(id)); + assert_eq!(s.active().unwrap().history.past_len(), history + 1); + s.undo(); + assert!(doc(&s).layer(id).is_none()); + assert!(doc(&s).work_path.is_some()); +} + +#[test] +fn path_to_shape_keeps_a_saved_path() { + let mut s = session(80, 80, 8); + let tri = json!({"subpaths": [{"knots": [[10, 10], [50, 10], [30, 50]]}]}); + s.execute("path.set", json!({"name": "Tri", "path": tri})).unwrap(); + let info = s.execute("path.toShape", json!({"name": "Tri", "layerName": "Roof"})).unwrap(); + assert_eq!(info["name"], "Roof"); + assert_eq!(doc(&s).paths[0].name, "Tri"); +} + +#[test] +fn path_to_shape_rejects_bad_input_without_changing_history() { + let mut s = session(80, 80, 8); + assert!(s.execute("path.toShape", json!({})).is_err(), "no path"); + s.execute("path.set", json!({"path": {"subpaths": [{"knots": [[12, 12], [60, 12], [60, 60]]}]}})).unwrap(); + let before = doc(&s).clone(); + let history = s.active().unwrap().history.past_len(); + for p in [ + json!({"name": "missing"}), + json!({"fill": "not a colour"}), + json!({"fill": 42}), + json!({"stroke": {"width": -1}}), + json!({"stroke": {"width": 1e100}}), + json!({"stroke": true}), + ] { + assert!(s.execute("path.toShape", p.clone()).is_err(), "accepted {p}"); + assert_eq!(*doc(&s), before, "{p} modified the document"); + assert_eq!(s.active().unwrap().history.past_len(), history, "{p} changed history"); + } +} + #[test] fn path_make_selection_rejects_invalid_options_without_changing_history() { let mut s = session(80, 80, 8); diff --git a/crates/ui-egui/src/i18n/ar.tsv b/crates/ui-egui/src/i18n/ar.tsv index 0b09aae6e11..bb1e223191d 100644 --- a/crates/ui-egui/src/i18n/ar.tsv +++ b/crates/ui-egui/src/i18n/ar.tsv @@ -2290,6 +2290,7 @@ Punctuation علامات الترقيم Make Work Path إنشاء مسار عمل Make Selection إنشاء تحديد + Make Shape إنشاء شكل Fill Path تعبئة المسار Stroke Path رسم حدود للمسار Delete Path حذف المسار diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 6b84a31cbf3..3d4f24dcf86 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -3224,6 +3224,7 @@ cameraData Lens Objektiv Magnetic Lasso Magnetické laso Make Výrobce Make Selection Vytvořit výběr + Make Shape Vytvořit tvar Make Work Path Vytvořit pracovní cestu Manual Ručně Map Document Dokument mapy diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 00cfb09d840..72538cd966c 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -1209,6 +1209,7 @@ Path to Illustrator… Sti til Illustrator… Make Work Path Opret arbejdssti Make Selection Opret markering + Make Shape Opret form Fill Path Udfyld sti Stroke Path Lav kontur på sti Clipping Path Udklipningssti diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index c68e8e098db..e79622fc4a1 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -2364,6 +2364,7 @@ Punctuation Zeichensetzung Make Work Path Arbeitspfad erzeugen Make Selection Auswahl erzeugen + Make Shape Form erzeugen Fill Path Pfad füllen Stroke Path Pfad nachziehen Delete Path Pfad löschen diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index e40e24e130a..d0fef9fbc0c 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -2781,6 +2781,7 @@ Make Κατασκευαστής Make Default Ορισμός ως προεπιλογής Make Selection Δημιουργία επιλογής + Make Shape Δημιουργία σχήματος Make Work Path Δημιουργία διαδρομής εργασίας Marker Size Μέγεθος δείκτη Master Κύριο diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 4b039176f41..5346fff77ff 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -2339,6 +2339,7 @@ Punctuation Puntuación Make Work Path Crear trazado de trabajo Make Selection Crear selección + Make Shape Crear forma Fill Path Rellenar trazado Stroke Path Contornear trazado Delete Path Eliminar trazado diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 1cacf9ffeae..924e0d13f1e 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -1210,6 +1210,7 @@ Path to Illustrator… Polku Illustratoriin… Make Work Path Luo työpolku Make Selection Luo valinta + Make Shape Luo muoto Fill Path Täytä polku Stroke Path Piirrä polun reunaviiva Clipping Path Leikkauspolku diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index c9e3bf5d3d5..79efc2cc04f 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -2479,6 +2479,7 @@ Path to Illustrator… Tracé vers Illustrator… Make Work Path Créer un tracé de travail Make Selection Créer une sélection + Make Shape Créer une forme Fill Path Remplir le tracé Stroke Path Contourner le tracé Clipping Path Tracé de détourage diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 37e07e1690f..a2b7e0bb2a5 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -3431,6 +3431,7 @@ cameraRaw Yellow Sárga Magnetic Lasso Mágneses lasszó Magnetic Lasso Tool Mágneses lasszó Make Selection Kijelölés készítése + Make Shape Alakzat készítése Make work path from selection Munkaútvonal készítése a kijelölésből Manual Kézi manual kézi diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 5d1a13dcc83..7fc324ecf54 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -2484,6 +2484,7 @@ Path to Illustrator… Path ke Illustrator… Make Work Path Buat Work Path Make Selection Buat Seleksi + Make Shape Buat Bentuk Fill Path Isi Path Stroke Path Stroke Path Clipping Path Clipping Path diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 6c2d6c18cd3..332da8afed5 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -2386,6 +2386,7 @@ Punctuation Punteggiatura Make Work Path Crea tracciato di lavoro Make Selection Crea selezione + Make Shape Crea forma Fill Path Riempi tracciato Stroke Path Traccia tracciato Delete Path Elimina tracciato diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 0d3714c9e2e..27b46962954 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -3024,6 +3024,7 @@ fontWeight Italic 斜体 Magnetic Lasso マグネット投げ縄 Make 作成 Make Selection 選択範囲を作成 + Make Shape シェイプを作成 Make Work Path 作業用パスを作成 Match Color カラーを一致 Mezzotint メゾティント diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index c52d0c31ca9..c4f301a7a94 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -3564,6 +3564,7 @@ curves Smooth 매끄럽게 Edit Selected Guides 선택한 안내선 편집 Clear Selected Guides 선택한 안내선 지우기 Make Selection 선택 영역 만들기 + Make Shape 모양 만들기 Bicubic Automatic 쌍입방 자동 Bicubic Smoother 쌍입방 더 부드럽게 Bicubic Sharper 쌍입방 더 선명하게 diff --git a/crates/ui-egui/src/i18n/nb.tsv b/crates/ui-egui/src/i18n/nb.tsv index 85f9a0441a5..cfd0dec77c5 100644 --- a/crates/ui-egui/src/i18n/nb.tsv +++ b/crates/ui-egui/src/i18n/nb.tsv @@ -1209,6 +1209,7 @@ Path to Illustrator… Bane til Illustrator… Make Work Path Opprett arbeidsbane Make Selection Opprett utvalg + Make Shape Opprett form Fill Path Fyll bane Stroke Path Strek opp bane Clipping Path Klippebane diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index c80142366a6..cc7bb15a569 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -2307,6 +2307,7 @@ Punctuation Interpunctie Make Work Path Werkpad maken Make Selection Selectie maken + Make Shape Vorm maken Fill Path Pad vullen Stroke Path Pad omlijnen Delete Path Pad verwijderen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 1b5c9e68788..f908d78aabf 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -2508,6 +2508,7 @@ Path to Illustrator… Ścieżka do Illustratora… Make Work Path Utwórz ścieżkę roboczą Make Selection Utwórz zaznaczenie + Make Shape Utwórz kształt Fill Path Wypełnij ścieżkę Stroke Path Obrysuj ścieżkę Clipping Path Ścieżka przycinająca diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 7b50d472fe0..ace1b8fea00 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -2473,6 +2473,7 @@ Path to Illustrator… Demarcador para o Illustrator… Make Work Path Criar demarcador de trabalho Make Selection Fazer seleção + Make Shape Fazer forma Fill Path Preencher demarcador Stroke Path Traçar demarcador Clipping Path Demarcador de corte diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 487a6fc0660..582b98556c8 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -1341,6 +1341,7 @@ Path to Illustrator… Контур в Illustrator… Make Work Path Создать рабочий контур Make Selection Создать выделение + Make Shape Создать фигуру Fill Path Залить контур Stroke Path Обвести контур Clipping Path Обтравочный контур diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv index 0152204d905..742d4cb6e90 100644 --- a/crates/ui-egui/src/i18n/sr.tsv +++ b/crates/ui-egui/src/i18n/sr.tsv @@ -2494,6 +2494,7 @@ Path to Illustrator… Putanja u Illustrator… Make Work Path Napravi radnu putanju Make Selection Napravi selekciju + Make Shape Napravi oblik Fill Path Popuni putanju Stroke Path Ocrtaj putanju Clipping Path Putanja isecanja diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 64191012c41..ba789d05dc7 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -1207,6 +1207,7 @@ Path to Illustrator… Bana till Illustrator… Make Work Path Skapa arbetsbana Make Selection Skapa markering + Make Shape Skapa form Fill Path Fyll bana Stroke Path Linje på bana Clipping Path Urklippsbana diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index a45309f6b29..e9601ea02be 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -2260,6 +2260,7 @@ Punctuation Noktalama işaretleri Make Work Path Çalışma Yolu Oluştur Make Selection Seçim Yap + Make Shape Şekil Yap Fill Path Yolu Doldur Stroke Path Kontur Yolu Delete Path Yolu Sil diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index eec0b45c31c..3459064c16e 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -1308,6 +1308,7 @@ Path to Illustrator… Контур до Illustrator… Make Work Path Створити робочий контур Make Selection Створити виділення + Make Shape Створити фігуру Fill Path Залити контур Stroke Path Обвести контур Clipping Path Відсічний контур diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 768d1dd2adb..570e33cb628 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -1388,6 +1388,7 @@ ✓ Color Indicates Selected Areas ✓ Màu chỉ vùng được chọn Work Path Đường dẫn làm việc Make Selection Tạo vùng chọn + Make Shape Tạo hình Fill Path Tô đường dẫn Stroke Path Đi nét đường dẫn Save Path Lưu đường dẫn diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 2a203c08c12..e158ad8bf75 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -3015,6 +3015,7 @@ curves Smooth 平滑 Edit Selected Guides 编辑所选参考线 Clear Selected Guides 清除所选参考线 Make Selection 建立选区 + Make Shape 建立形状 Bicubic Automatic 双三次(自动) Bicubic Smoother 双三次(较平滑) Bicubic Sharper 双三次(较锐利) diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 6452c838bd0..b92581c0b21 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -2976,6 +2976,7 @@ curves Smooth 平滑 Edit Selected Guides 編輯所選參考線 Clear Selected Guides 清除所選參考線 Make Selection 建立選取範圍 + Make Shape 建立形狀 Bicubic Automatic 雙三次 (自動) Bicubic Smoother 雙三次 (較平滑) Bicubic Sharper 雙三次 (較銳利) diff --git a/crates/ui-egui/src/tools/vector_ui.rs b/crates/ui-egui/src/tools/vector_ui.rs index 0749b874340..aef9749948d 100644 --- a/crates/ui-egui/src/tools/vector_ui.rs +++ b/crates/ui-egui/src/tools/vector_ui.rs @@ -41,7 +41,9 @@ pub(crate) use overlay::{curve_points, path_lines, selected_saved_path, shows_an pub(crate) use overlay::{draw_anchor, draw_handle, draw_outline}; #[cfg(test)] use path_ops::target_path; -pub use path_ops::{active_path_name, path_selection_finish, path_to_selection, pick_shape_at, selected_document_path, takes_path_mask, with_active_path}; +pub use path_ops::{ + active_path_name, make_shape, path_selection_finish, path_to_selection, pick_shape_at, selected_document_path, takes_path_mask, with_active_path, +}; pub(crate) use path_ops::{ active_shape_path, active_type_path, delete_key_deletes_work_path, deselect_loaded_path, free_transform_path, targeted_vector_mask, work_path_shown, }; diff --git a/crates/ui-egui/src/tools/vector_ui/options.rs b/crates/ui-egui/src/tools/vector_ui/options.rs index cd68a6bcb64..fb2528a65f4 100644 --- a/crates/ui-egui/src/tools/vector_ui/options.rs +++ b/crates/ui-egui/src/tools/vector_ui/options.rs @@ -108,6 +108,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo app.ui.status = e; app.ui.status_error = true; } + // Make: Shape turns the path into a shape layer with the shape fill and stroke (#10934). + if ui.add_enabled(has_path, egui::Button::new(tl!("Make Shape"))).clicked() + && let Err(e) = super::make_shape(app) + { + app.ui.status = e; + app.ui.status_error = true; + } } return true; } diff --git a/crates/ui-egui/src/tools/vector_ui/path_ops.rs b/crates/ui-egui/src/tools/vector_ui/path_ops.rs index e6c3a1a6ccf..f4847251922 100644 --- a/crates/ui-egui/src/tools/vector_ui/path_ops.rs +++ b/crates/ui-egui/src/tools/vector_ui/path_ops.rs @@ -73,6 +73,25 @@ pub fn path_to_selection(app: &mut PhotocraftApp, params: Value) -> Result Result { + let pending = app.ui.pen.as_ref().is_some_and(|p| p.knots.len() >= 2); + // A path being drawn into a targeted vector mask is that layer's path afterwards. + let pending_layer = pending && super::targeted_vector_mask(app).is_some(); + if pending && !pen_commit(app, false) { + return Err(app.ui.status.clone()); + } + let name = if pending_layer { Some("layer".to_string()) } else { active_path_name(app) } + .ok_or_else(|| tl!("No path to make a shape from: draw one with the Pen tool or select one in the Paths panel.").to_string())?; + let r = app.run("path.toShape", json!({"name": name, "fill": super::shapes::fill_param(app), "stroke": super::shapes::stroke_param(app)}))?; + if name == "work" && app.ui.selected_path.as_deref() == Some("work") { + app.ui.selected_path = None; + } + Ok(r) +} + /// After the Pen or Path Selection tool made a selection from the path `name` (⌘↩, the canvas /// menu's Make Selection…), Photoshop deselects it in the Paths panel and stops drawing it; the /// path itself stays (#6079). The Work Path is hidden too when a saved path was loaded, so no diff --git a/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs index 25ae41650b0..8e713c098ad 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_path_ops_tests.rs @@ -348,3 +348,62 @@ fn freeform_refuses_a_locked_shape_before_starting_a_stroke() { assert!(app.drag.is_some(), "{lock}: unlocked stroke can start"); } } + +/// #10934: the options bar's Make Shape (Path mode) turns the Work Path into a shape layer filled +/// with the foreground colour, as one History step; the Work Path is the shape's path afterwards. +/// A path still being drawn is finished first. With no path the button is disabled. +#[test] +fn make_shape_turns_the_work_path_into_a_shape_layer() { + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 400.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + ui.horizontal(|ui| super::options_bar(app, ui, Tool::Pen)); + } + }, + app(), + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio); + h.run_steps(4); + assert!(h.get_by_label("Make Shape").accesskit_node().is_disabled(), "no path yet"); + square(h.state_mut(), 20.0, 20.0, 100.0); + let drawn = work(h.state()); + let (count, steps) = (layers(h.state()), h.state().session.active().unwrap().history.past_len()); + h.run_steps(2); + h.get_by_label("Make Shape").click(); + h.run_steps(3); + let app = h.state(); + assert_eq!(layers(app), count + 1); + assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1, "one History step"); + let (id, path) = shape_path(app); + assert_eq!(path, drawn); + let st = app.session.active().unwrap(); + assert!(st.doc.work_path.is_none()); + let LayerContent::Shape(sh) = &st.doc.layer(id).unwrap().content else { panic!("not a shape layer") }; + let fg = app.session.tools.foreground; + assert_eq!(sh.fill, Some(photocraft_doc::Fill::Solid(photocraft_color::Color::rgba(fg[0], fg[1], fg[2], fg[3])))); + // An open path still being drawn is finished into the Work Path, then made a shape. + for (x, y) in [(10.0, 150.0), (60.0, 150.0), (60.0, 190.0)] { + pen_down(h.state_mut(), x, y, false); + pen_up(h.state_mut()); + } + h.run_steps(2); + h.get_by_label("Make Shape").click(); + h.run_steps(3); + let app = h.state(); + assert!(app.ui.pen.is_none()); + assert_eq!(layers(app), count + 2); + assert_eq!(shape_path(app).1.subpaths[0].knots.len(), 3); +} + +/// Make Shape on a saved path selected in the Paths panel keeps that path. +#[test] +fn make_shape_keeps_a_saved_path() { + let mut app = app(); + square(&mut app, 20.0, 20.0, 50.0); + app.run("path.rename", json!({"name": "work", "to": "Box"})).unwrap(); + app.ui.selected_path = Some("Box".into()); + super::make_shape(&mut app).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.paths.first().map(|p| p.name.as_str()), Some("Box")); + assert_eq!(shape_path(&app).1, st.doc.paths[0].path); +}