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 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EZbgszHyuEuWAzxaamteuU
This commit is contained in:
DingusMcRinkyDinkyandClaude Opus 5.5 committed 2026-11-03 08:24:33 +01:00
1 parent c6af3dcb98
commit 80e32f8ef7
32 files changed
+220 -12

No files matched your search

+11 -1
View File
@@ -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<CommandSpec> {
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",
+44 -10
View File
@@ -424,16 +424,7 @@ pub(super) fn shape_create(s: &mut Session, p: &Value) -> Result<Value> {
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<Value> {
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<Fill>, Option<photocraft_doc::ShapeStroke>)> {
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<Value> {
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<Value> {
const CMD: &str = "shape.edit";
let id = layer_id(s, p)?;
@@ -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);
+1
View File
@@ -2290,6 +2290,7 @@
Punctuation علامات الترقيم
Make Work Path إنشاء مسار عمل
Make Selection إنشاء تحديد
Make Shape إنشاء شكل
Fill Path تعبئة المسار
Stroke Path رسم حدود للمسار
Delete Path حذف المسار
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -2781,6 +2781,7 @@
Make Κατασκευαστής
Make Default Ορισμός ως προεπιλογής
Make Selection Δημιουργία επιλογής
Make Shape Δημιουργία σχήματος
Make Work Path Δημιουργία διαδρομής εργασίας
Marker Size Μέγεθος δείκτη
Master Κύριο
Can't render this file because it contains an unexpected character in line 47 and column 53.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 79 and column 53.
+1
View File
@@ -3024,6 +3024,7 @@ fontWeight Italic 斜体
Magnetic Lasso マグネット投げ縄
Make 作成
Make Selection 選択範囲を作成
Make Shape シェイプを作成
Make Work Path 作業用パスを作成
Match Color カラーを一致
Mezzotint メゾティント
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -3564,6 +3564,7 @@ curves Smooth 매끄럽게
Edit Selected Guides 선택한 안내선 편집
Clear Selected Guides 선택한 안내선 지우기
Make Selection 선택 영역 만들기
Make Shape 모양 만들기
Bicubic Automatic 쌍입방 자동
Bicubic Smoother 쌍입방 더 부드럽게
Bicubic Sharper 쌍입방 더 선명하게
Can't render this file because it contains an unexpected character in line 63 and column 53.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 8 and column 34.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1341,6 +1341,7 @@
Path to Illustrator… Контур в Illustrator…
Make Work Path Создать рабочий контур
Make Selection Создать выделение
Make Shape Создать фигуру
Fill Path Залить контур
Stroke Path Обвести контур
Clipping Path Обтравочный контур
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 8 and column 34.
+1
View File
@@ -1308,6 +1308,7 @@
Path to Illustrator… Контур до Illustrator…
Make Work Path Створити робочий контур
Make Selection Створити виділення
Make Shape Створити фігуру
Fill Path Залити контур
Stroke Path Обвести контур
Clipping Path Відсічний контур
Can't render this file because it contains an unexpected character in line 152 and column 53.
+1
View File
@@ -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
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -3015,6 +3015,7 @@ curves Smooth 平滑
Edit Selected Guides 编辑所选参考线
Clear Selected Guides 清除所选参考线
Make Selection 建立选区
Make Shape 建立形状
Bicubic Automatic 双三次(自动)
Bicubic Smoother 双三次(较平滑)
Bicubic Sharper 双三次(较锐利)
Can't render this file because it contains an unexpected character in line 63 and column 53.
+1
View File
@@ -2976,6 +2976,7 @@ curves Smooth 平滑
Edit Selected Guides 編輯所選參考線
Clear Selected Guides 清除所選參考線
Make Selection 建立選取範圍
Make Shape 建立形狀
Bicubic Automatic 雙三次 (自動)
Bicubic Smoother 雙三次 (較平滑)
Bicubic Sharper 雙三次 (較銳利)
Can't render this file because it contains an unexpected character in line 6 and column 47.
+3 -1
View File
@@ -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,
};
@@ -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;
}
@@ -73,6 +73,25 @@ pub fn path_to_selection(app: &mut PhotocraftApp, params: Value) -> Result<Value
Ok(r)
}
/// The Pen options bar's Make Shape (Path mode, #10934): a new shape layer from the path being
/// drawn (committed first) or the active path, with the shape tools' fill and stroke. The Work Path
/// becomes the shape's path, so it is no longer selected in the Paths panel.
pub fn make_shape(app: &mut PhotocraftApp) -> Result<Value, String> {
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
@@ -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);
}