diff --git a/Cargo.lock b/Cargo.lock index f5b1b75ef5..483376c3b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6626,6 +6626,7 @@ dependencies = [ "photocraft-doc", "photocraft-engine-core", "photocraft-engine-paint", + "photocraft-engine-vector", "photocraft-format", "photocraft-geom", "photocraft-io", @@ -6708,6 +6709,35 @@ dependencies = [ "serde_json", ] +[[package]] +name = "photocraft-engine-vector" +version = "0.23.1" +dependencies = [ + "base64 0.22.1", + "blake3", + "chrono", + "craft-cms 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5c5e0d52c387c0a4ae2908a07e476d7584f60362)", + "craft-image-codecs", + "craft-xml", + "flate2", + "photocraft-algo", + "photocraft-color", + "photocraft-compose", + "photocraft-doc", + "photocraft-engine-core", + "photocraft-format", + "photocraft-geom", + "photocraft-io", + "photocraft-paint", + "photocraft-raster", + "photocraft-testkit", + "photocraft-text", + "photocraft-vector", + "rayon", + "serde", + "serde_json", +] + [[package]] name = "photocraft-format" version = "0.23.1" diff --git a/Cargo.toml b/Cargo.toml index 03def19e82..5b55c2a247 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ photocraft-plugins = { path = "crates/plugins" } photocraft-engine = { path = "crates/engine" } photocraft-engine-core = { path = "crates/engine-core" } photocraft-engine-paint = { path = "crates/engine-paint" } +photocraft-engine-vector = { path = "crates/engine-vector" } photocraft-ui-egui = { path = "crates/ui-egui" } photocraft-testkit = { path = "crates/testkit" } photocraft-tablet = { path = "crates/tablet" } @@ -122,7 +123,7 @@ todo = "warn" # Every cl command selects these packages: each brings features the others lack, so a command that drops one # builds a second copy of egui, photocraft-io or craft-affinity and of everything above them. selection = [ - "photocraft-ui-egui", "photocraft-engine", "photocraft-engine-core", "photocraft-engine-paint", "photocraft", "photocraft-algo", "photocraft-automation", + "photocraft-ui-egui", "photocraft-engine", "photocraft-engine-core", "photocraft-engine-paint", "photocraft-engine-vector", "photocraft", "photocraft-algo", "photocraft-automation", "photocraft-text", "photocraft-tablet", "photocraft-cli", "photocraft-paint", "photocraft-io", "photocraft-gpu", ] # Crates whose new builds cl names after a command, besides the framework's. @@ -153,6 +154,7 @@ craft-imaging = ["default", "screen-testing", "ui"] "photocraft-ui-egui/it" = 221.0 "photocraft-engine-core/photocraft_engine_core" = 62.0 "photocraft-engine-paint/photocraft_engine_paint" = 35.0 +"photocraft-engine-vector/photocraft_engine_vector" = 6.0 # Dependencies carry no debug info: their frames in a backtrace lose file:line, and the target dir # and link times shrink. The test profile inherits both settings. @@ -186,6 +188,8 @@ opt-level = 0 opt-level = 0 [profile.test.package.photocraft-engine-paint] opt-level = 0 +[profile.test.package.photocraft-engine-vector] +opt-level = 0 # Only the exhaustive rounding proof needs maximum optimization; algo stays at its usual level. [profile.test.package.photocraft-oil-round-proof] diff --git a/crates/engine-core/Cargo.toml b/crates/engine-core/Cargo.toml index e91fa8af21..5f89823ff4 100644 --- a/crates/engine-core/Cargo.toml +++ b/crates/engine-core/Cargo.toml @@ -8,8 +8,6 @@ license.workspace = true workspace = true [features] -# Real-file corpus tests (opt-in; `cargo xtask test-corpus`). Fail when the corpus is missing. -corpus = [] # Exposes the allocation failpoints (`allocation::fail_next_for_test`) to other engine crates' tests; only dev-dependencies turn it on. failpoints = [] diff --git a/crates/engine-core/src/cmd.rs b/crates/engine-core/src/cmd.rs index 60ba76d83d..8ed8b442d5 100644 --- a/crates/engine-core/src/cmd.rs +++ b/crates/engine-core/src/cmd.rs @@ -147,14 +147,18 @@ use enabled::{can_redo, can_undo, has_doc, has_layer, has_selection}; pub use layer_params::layer_param; pub use layer_params::mask_at_depth; pub use layer_params::selection_mask; -pub(crate) use layer_params::{NEW_LAYER_PATH, explicit_layer, layer_listing, layer_panel_option, mask_new_layer}; +pub(crate) use layer_params::{NEW_LAYER_PATH, layer_listing, layer_panel_option, mask_new_layer}; +pub use layer_params::explicit_layer; pub(crate) use layer_references::{recorded_drop, recorded_layer}; use ops::{arrange, merge_group, move_mask, set_mask, set_mask_and_deselect}; -pub(crate) use ops::{layer_copy, translate_layer, translate_layer_wrapped}; +pub(crate) use ops::{layer_copy, translate_layer_wrapped}; +pub use ops::translate_layer; pub use params::color_param; pub use params::parse_hex; use params::{bad, set_clipped}; -pub(crate) use params::{check_f32_values, cmyk_param, int, int_i32, u32_id, u32_id_param}; +pub(crate) use params::{check_f32_values, cmyk_param, int, int_i32}; +pub use params::u32_id; +pub use params::u32_id_param; pub use photocraft_color::blend::parse_blend; pub use crate::registry::{CommandSpec, list_entry, list_entry_matches, search_keywords}; diff --git a/crates/engine-core/src/cmd/analysis_cmds.rs b/crates/engine-core/src/cmd/analysis_cmds.rs index 295cc4b9be..5e6de123bd 100644 --- a/crates/engine-core/src/cmd/analysis_cmds.rs +++ b/crates/engine-core/src/cmd/analysis_cmds.rs @@ -170,7 +170,7 @@ fn set_quiet(s: &mut Session, f: impl FnOnce(&mut Document)) -> Result<()> { /// Run several commands as one history step labelled `label`. On failure the document goes back /// as it was and the journal forgets the commands `f` ran, so an action being recorded does not /// replay an edit that was taken back. -pub(crate) fn compound(s: &mut Session, label: &str, f: impl FnOnce(&mut Session) -> Result) -> Result { +pub fn compound(s: &mut Session, label: &str, f: impl FnOnce(&mut Session) -> Result) -> Result { crate::actions_cmds::before_action_edit(s); let st = s.active().ok_or(EngineError::NoDocument)?; let (before, history, prior) = (st.doc.clone(), st.history.clone(), st.layer_target()); diff --git a/crates/engine-core/src/cmd/edit_menu_cmds.rs b/crates/engine-core/src/cmd/edit_menu_cmds.rs index 9c296824ac..ff3b98f2df 100644 --- a/crates/engine-core/src/cmd/edit_menu_cmds.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds.rs @@ -1,6 +1,6 @@ //! The rest of Photoshop's Edit menu: Fade, Purge, Content-Aware Fill and Scale, Define Brush //! Preset / Custom Shape, Find and Replace Text, the Preset Manager and preset export/import. -//! Auto-Align and Auto-Blend Layers live in [`crate::align_cmds`]. +//! Auto-Align and Auto-Blend Layers live in the vector crate's `align_cmds`. //! //! Check Spelling is not implemented: it needs a word list per language, and no permissively //! licensed dictionary small enough to bundle (or a pure-Rust checker with one) was available. diff --git a/crates/engine-core/src/cmd/extra_cmds.rs b/crates/engine-core/src/cmd/extra_cmds.rs index d9d03286af..44920b0cd6 100644 --- a/crates/engine-core/src/cmd/extra_cmds.rs +++ b/crates/engine-core/src/cmd/extra_cmds.rs @@ -64,7 +64,7 @@ pub(crate) fn style_targets(s: &Session, p: &Value, fits: impl Fn(&Layer) -> boo } /// A key that makes the sub-commands of one command share a single history step. -pub(crate) fn step_key(s: &Session, what: &str) -> String { +pub fn step_key(s: &Session, what: &str) -> String { format!("{what}#{}", s.active().map_or(0, |d| d.revision)) } @@ -531,7 +531,7 @@ pub(crate) fn unlock_background(l: &mut Layer) { /// Before `id` gets a layer mask: the Background can't have one, so it becomes a normal layer /// first ("Layer 0"), as when adding a mask to it in Photoshop. Other layers are left alone. -pub(crate) fn background_to_layer_for_mask(doc: &mut photocraft_doc::Document, id: photocraft_doc::LayerId) { +pub fn background_to_layer_for_mask(doc: &mut photocraft_doc::Document, id: photocraft_doc::LayerId) { background_to_layer(doc, id); } @@ -757,7 +757,7 @@ fn content_pixels(doc: &Document, l: &Layer) -> photocraft_raster::Surface { s } -pub(crate) fn kind_of(s: &Session, id: LayerId) -> Option<&'static str> { +pub fn kind_of(s: &Session, id: LayerId) -> Option<&'static str> { let d = s.active()?; Some(match &d.doc.layer(id)?.content { LayerContent::Text(_) => "type", @@ -780,7 +780,7 @@ fn has_rasterize_work(s: &Session, id: LayerId, only: Option<&str>) -> bool { /// Rasterize one layer; `only` restricts it to one kind. Without `only` (Rasterize › Layer / All /// Layers: "all vector data") a vector mask becomes a pixel mask too; layer effects stay live, as /// in Photoshop (Rasterize › Layer Style bakes them). Returns false when there was nothing to do. -pub(crate) fn rasterize_one(s: &mut Session, id: LayerId, only: Option<&str>, key: &str) -> Result { +pub fn rasterize_one(s: &mut Session, id: LayerId, only: Option<&str>, key: &str) -> Result { let vector_mask = has_vector_mask(s, id, only); let content = rasterize_content(s, id, only, key)?; if vector_mask { diff --git a/crates/engine-core/src/cmd/file_cmds.rs b/crates/engine-core/src/cmd/file_cmds.rs index 169f234f78..460ab21325 100644 --- a/crates/engine-core/src/cmd/file_cmds.rs +++ b/crates/engine-core/src/cmd/file_cmds.rs @@ -60,11 +60,16 @@ pub use paths::{ extension, holds, holds_at, is_template, layered_extension, list_images, losses_at, portable_device_name, same_destination, same_file, saves_in_place, template_name, untitled_name, }; -pub(crate) use paths::{file_name, forward_slashes, is_windows_device_name, join, read_file, read_file_limited, sanitize, stem, write_file}; +pub(crate) use paths::{file_name, forward_slashes, is_windows_device_name, read_file, read_file_limited, write_file}; +pub use paths::join; +pub use paths::sanitize; +pub use paths::stem; pub(crate) use place_steps::PlaceSteps; use processing::{conditional_mode_change, fit_image, flatten_all_effects, flatten_all_masks, image_processor, load_files_into_stack}; use save::save_a_copy; -pub(crate) use save::{SaveOpts, encode, save_doc}; +pub(crate) use save::{encode}; +pub use save::SaveOpts; +pub use save::save_doc; pub use save::{ dds_param, dpx_bits_param, jpeg_format_param, jpeg_quality, maximize_compatibility_param, pcraft_full_composite_param, pdf_spot_plates_param, tga_bits_param, tiff_bool_param, tiff_compression_param, tiff_would_write_layers, @@ -88,7 +93,7 @@ fn always(_: &Session) -> std::result::Result<(), String> { Ok(()) } -pub(crate) fn native_doc(s: &Session) -> std::result::Result<(), String> { +pub fn native_doc(s: &Session) -> std::result::Result<(), String> { native(s)?; has_doc(s) } @@ -140,7 +145,7 @@ impl crate::DocState { } } -pub(crate) fn str_param<'a>(p: &'a Value, key: &str, cmd: &str) -> Result<&'a str> { +pub fn str_param<'a>(p: &'a Value, key: &str, cmd: &str) -> Result<&'a str> { p.get(key).and_then(Value::as_str).filter(|v| !v.is_empty()).ok_or_else(|| EngineError::BadParams { cmd: cmd.into(), msg: format!("missing \"{key}\"") }) } diff --git a/crates/engine-core/src/cmd/file_cmds/paths.rs b/crates/engine-core/src/cmd/file_cmds/paths.rs index 079417b031..e11e0e0e57 100644 --- a/crates/engine-core/src/cmd/file_cmds/paths.rs +++ b/crates/engine-core/src/cmd/file_cmds/paths.rs @@ -176,7 +176,7 @@ pub fn template_name(s: &Session, path: &str) -> Option { is_template(path).then(|| untitled_name("Untitled", |n| s.documents().iter().any(|d| d.doc.name == n))) } -pub(crate) fn stem(path: &str) -> String { +pub fn stem(path: &str) -> String { let n = file_name(path); match n.rfind('.') { Some(i) if i > 0 => n[..i].to_string(), @@ -313,7 +313,7 @@ pub(crate) fn forward_slashes(path: String) -> String { if path.starts_with(r"\\") { path } else { path.replace('\\', "/") } } -pub(crate) fn join(dir: &str, name: &str) -> String { +pub fn join(dir: &str, name: &str) -> String { if dir.is_empty() { name.to_string() } else if dir.ends_with('/') || dir.ends_with('\\') { @@ -325,7 +325,7 @@ pub(crate) fn join(dir: &str, name: &str) -> String { /// A file-name-safe version of a layer name. A Windows device name (`nul`, `con.v2`) gets a `_` /// before its first dot, so the file or folder is usable on Windows, wherever it was written. -pub(crate) fn sanitize(name: &str) -> String { +pub fn sanitize(name: &str) -> String { let s: String = name.chars().map(|c| if c.is_alphanumeric() || matches!(c, '-' | '_' | ' ' | '.') { c } else { '_' }).collect(); let s = s.trim().trim_matches('.').to_string(); if s.is_empty() { "layer".into() } else { portable_device_name(s) } diff --git a/crates/engine-core/src/cmd/file_cmds/save.rs b/crates/engine-core/src/cmd/file_cmds/save.rs index 2a41eb52ba..e1d8101a74 100644 --- a/crates/engine-core/src/cmd/file_cmds/save.rs +++ b/crates/engine-core/src/cmd/file_cmds/save.rs @@ -12,7 +12,7 @@ pub fn tiff_would_write_layers(doc: &Document) -> bool { /// bits, DPX bits, DDS compression and mipmaps, PSD previews, the PSD merged image and the /// `.pcraft` full-size composite. #[derive(Debug, Clone, Copy)] -pub(crate) struct SaveOpts { +pub struct SaveOpts { /// Photoshop's 0–12 JPEG scale. pub quality: Option, /// JPEG Options › Format Options (`"jpegFormat"`); unset, Baseline ("Standard"). @@ -91,7 +91,7 @@ impl SaveOpts { /// Maximize Compatibility checkbox both start on); `maximizeCompatibility` decides the merged /// image for this save instead. The `.pcraft` full-size composite comes from /// `pcraftFullComposite`, or without it from the File Handling preference. - pub(crate) fn from_params(s: &Session, p: &Value, cmd: &str) -> Result { + pub fn from_params(s: &Session, p: &Value, cmd: &str) -> Result { let file_handling = &s.prefs().file_handling; Ok(SaveOpts { quality: f64_param(p, "quality"), @@ -304,7 +304,7 @@ pub(crate) fn encode(doc: &Document, path: &str, save: impl Into) -> R photocraft_io::export(doc, path, &opts).map(|r| (r.bytes, r.warnings)).map_err(|e| EngineError::Other(format!("{path}: {e}"))) } -pub(crate) fn save_doc(doc: &Document, path: &str, save: impl Into) -> Result> { +pub fn save_doc(doc: &Document, path: &str, save: impl Into) -> Result> { let (bytes, warnings) = encode(doc, path, save)?; write_file(path, &bytes)?; Ok(warnings) diff --git a/crates/engine-core/src/cmd/layer_multi_cmds.rs b/crates/engine-core/src/cmd/layer_multi_cmds.rs index 9bf29398e1..792ecd2a5d 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds.rs @@ -28,9 +28,11 @@ pub use moves::{move_targets, move_to, moved, moved_target, moved_wrapping, move pub(crate) use moves::{wrap_path, wrap_surface, wraps_linked_masks}; pub use selection::top_level; use selection::{doc_state, find_layers, select_all_layers, select_linked}; -pub(crate) use selection::{mask_targets, recorded_step, reselect, targets}; +pub(crate) use selection::{mask_targets, recorded_step, reselect}; +pub use selection::targets; pub use selection::{select, selected, set_selection}; -pub(crate) use structure::{check_group_depth, deletion_neighbours, relink_copies}; +pub(crate) use structure::{check_group_depth, relink_copies}; +pub use structure::deletion_neighbours; pub use structure::{delete_selected, duplicate_selected, group_layers, set_visible_selected}; use structure::{link_layers, lock_layers, merge_layers, rename_layer, reverse}; diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/selection.rs b/crates/engine-core/src/cmd/layer_multi_cmds/selection.rs index 845bd85031..38505f8b8d 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/selection.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/selection.rs @@ -14,7 +14,7 @@ pub fn selected(s: &Session) -> Vec { /// The layers a layer command acts on: the `layer` param when given, else every selected layer /// (bottom-to-top), else the active layer. A single layer behaves exactly as before. -pub(crate) fn targets(s: &Session, p: &serde_json::Value) -> Result> { +pub fn targets(s: &Session, p: &serde_json::Value) -> Result> { if p.get("layer").is_some() { return Ok(vec![crate::commands::layer_param(s, p)?]); } diff --git a/crates/engine-core/src/cmd/layer_multi_cmds/structure.rs b/crates/engine-core/src/cmd/layer_multi_cmds/structure.rs index 7e2ac72b12..967fff2f55 100644 --- a/crates/engine-core/src/cmd/layer_multi_cmds/structure.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/structure.rs @@ -220,7 +220,7 @@ pub(super) fn merge_layers(s: &mut Session) -> Result { /// Next visible layer row below the deleted target, then rows above in reverse order. /// Group headers precede their children in the UI, unlike Document::walk's storage order. -pub(crate) fn deletion_neighbours(doc: &Document, target: LayerId) -> Vec { +pub fn deletion_neighbours(doc: &Document, target: LayerId) -> Vec { let rows = |expand_all: bool| { let mut stack: Vec<&Layer> = doc.layers.iter().collect(); let mut order = Vec::new(); diff --git a/crates/engine-core/src/cmd/layer_params.rs b/crates/engine-core/src/cmd/layer_params.rs index f901da1289..84dda6e1e0 100644 --- a/crates/engine-core/src/cmd/layer_params.rs +++ b/crates/engine-core/src/cmd/layer_params.rs @@ -7,7 +7,7 @@ use super::{Document, EngineError, Layer, LayerId, LayerMask, Result, SampleType /// `"background"` finds that name). A recorded `{"name":"Layer"}` uses the same lookup. /// `{"background":true}` targets the actual Background, independently of its name. `None` /// when the param is absent. -pub(crate) fn explicit_layer(s: &Session, p: &Value) -> Result> { +pub fn explicit_layer(s: &Session, p: &Value) -> Result> { let named = |name: &str| { let d = s.active().ok_or(EngineError::NoDocument)?; let layers = d.doc.walk(); diff --git a/crates/engine-core/src/cmd/ops.rs b/crates/engine-core/src/cmd/ops.rs index c300028e72..7e08493d68 100644 --- a/crates/engine-core/src/cmd/ops.rs +++ b/crates/engine-core/src/cmd/ops.rs @@ -156,7 +156,7 @@ fn mask_destination(s: &Session, p: &Value) -> Result { /// Move a layer's pixels, linked mask and type by whole pixels (vectors move via /// `vector_cmds::translate_vectors`). -pub(crate) fn translate_layer(doc: &Document, l: &mut Layer, dx: i32, dy: i32) { +pub fn translate_layer(doc: &Document, l: &mut Layer, dx: i32, dy: i32) { translate_layer_wrapped(doc, l, dx, dy, None); } diff --git a/crates/engine-core/src/cmd/params.rs b/crates/engine-core/src/cmd/params.rs index 62397642ce..dfc3b14eb6 100644 --- a/crates/engine-core/src/cmd/params.rs +++ b/crates/engine-core/src/cmd/params.rs @@ -25,12 +25,12 @@ pub(crate) fn int_i32(cmd: &str, p: &Value, key: &str) -> Result> { /// An id (layer comp, slice, style…) from a JSON value: a bad-params error unless it is a whole /// number in `u32` range. `as u32` would wrap `2^32 + 1` to `1` and target a real item. -pub(crate) fn u32_id(cmd: &str, key: &str, v: &Value) -> Result { +pub fn u32_id(cmd: &str, key: &str, v: &Value) -> Result { v.as_u64().and_then(|n| u32::try_from(n).ok()).ok_or_else(|| bad(cmd, format!("`{key}` = {v} is not a valid id (0..={})", u32::MAX))) } /// [`u32_id`] of `p[key]`: `None` when absent. -pub(crate) fn u32_id_param(cmd: &str, p: &Value, key: &str) -> Result> { +pub fn u32_id_param(cmd: &str, p: &Value, key: &str) -> Result> { p.get(key).map(|v| u32_id(cmd, key, v)).transpose() } diff --git a/crates/engine-core/src/cmd/photo_cmds.rs b/crates/engine-core/src/cmd/photo_cmds.rs index c10d0bf5a6..866f6ea8a2 100644 --- a/crates/engine-core/src/cmd/photo_cmds.rs +++ b/crates/engine-core/src/cmd/photo_cmds.rs @@ -356,7 +356,7 @@ pub(crate) fn luma_alpha(surf: &Surface, area: Rect, k: usize) -> (usize, usize, /// Registers `images` (surface, content area) and returns full-resolution placements. /// `focal35` is the 35 mm-equivalent focal length when known (EXIF). -pub(crate) fn register(images: &[(&Surface, Rect)], layout: Layout, reference: Option, geometric: bool, focal35: Option) -> Option { +pub fn register(images: &[(&Surface, Rect)], layout: Layout, reference: Option, geometric: bool, focal35: Option) -> Option { let side = images.iter().map(|(_, r)| r.width().max(r.height()) as usize).max().unwrap_or(1); let k = side.div_ceil(REGISTER_SIDE).max(1); let prepared: Vec = images @@ -387,7 +387,7 @@ const DIRECT_MIN_OVERLAP: f64 = 0.25; const DIRECT_MIN_CORRELATION: f64 = 0.5; /// The error of either registration when the layers have no detail in common. -pub(crate) const NO_DETAIL: &str = "Auto-Align couldn't find enough matching detail between the layers"; +pub const NO_DETAIL: &str = "Auto-Align couldn't find enough matching detail between the layers"; /// Registers `images` (surface, content area, all of one size) by intensity /// ([`photocraft_algo::direct`]), for layers that nearly coincide (a focus or exposure bracket, @@ -396,7 +396,7 @@ pub(crate) const NO_DETAIL: &str = "Auto-Align couldn't find enough matching det /// nothing full-resolution is held or warped. A layer whose best pose overlaps its neighbour /// too little or explains too little of it is no fit, and fails with [`NO_DETAIL`]. Planar /// layouts only; Auto means a similarity (Collage). -pub(crate) fn register_direct(images: &[(&Surface, Rect)], layout: Layout, reference: usize) -> std::result::Result { +pub fn register_direct(images: &[(&Surface, Rect)], layout: Layout, reference: usize) -> std::result::Result { use photocraft_algo::direct::{self, Plane, Pose}; use photocraft_algo::transform::Homography; let (motion, layout) = match layout { @@ -471,7 +471,7 @@ fn exif_focal(srcs: &[Source]) -> Option { /// Warps the content of `surf` inside `rect` by a placement shifted by `offset`; image /// coordinates are surface coordinates minus `origin`. -pub(crate) fn warp_placed(surf: &Surface, rect: Rect, origin: (f64, f64), pl: &Placement, offset: (f64, f64), interp: Interp) -> Result { +pub fn warp_placed(surf: &Surface, rect: Rect, origin: (f64, f64), pl: &Placement, offset: (f64, f64), interp: Interp) -> Result { let pl = pl.translated(offset.0, offset.1); if let Some(h) = plane_matrix(&pl, origin) { return Ok(warp_surface(surf, rect, &h, interp)?); @@ -480,7 +480,7 @@ pub(crate) fn warp_placed(surf: &Surface, rect: Rect, origin: (f64, f64), pl: &P } /// The projective matrix of a planar, distortion-free placement (surface px → panorama px). -pub(crate) fn plane_matrix(pl: &Placement, origin: (f64, f64)) -> Option { +pub fn plane_matrix(pl: &Placement, origin: (f64, f64)) -> Option { (pl.projection == panorama::Projection::Plane && pl.k1 == 0.0).then(|| { let t = Homography([1.0, 0.0, -pl.center[0] - origin.0, 0.0, 1.0, -pl.center[1] - origin.1, 0.0, 0.0, 1.0]); pl.h.mul(&t) @@ -591,7 +591,7 @@ pub(crate) type BlendGeometry<'a> = (&'a [Placement], &'a [(usize, usize)], (f64 /// Result of [`seam_blend`]: per input, the pixels to keep (blended inside its seam region) /// and its mask; plus the blended composite. -pub(crate) struct Blended { +pub struct Blended { pub layers: Vec<(Surface, Surface)>, pub composite: Surface, pub gains: Vec>, @@ -602,7 +602,7 @@ pub(crate) struct Blended { /// exposure and colour, `geometry` enables vignette removal. `budget` is the bytes of bands built /// at a time and the cap on any single band (an error beyond it); `None` is 5 GiB batches with /// no cap. -pub(crate) struct BlendOptions<'a> { +pub struct BlendOptions<'a> { pub seamless: bool, pub gains: bool, pub geometry: Option>, @@ -797,7 +797,7 @@ fn build_layers( /// Gain compensation (+ optional vignetting), seams in `order`, multi-band blending. Inputs are /// surfaces already in panorama coordinates with alpha. `geometry` enables vignette removal. -pub(crate) fn seam_blend( +pub fn seam_blend( warped: Vec, canvas: Rect, order: &[usize], @@ -850,7 +850,7 @@ fn data_clamp(v: f32, fmt: PixelFormat) -> f32 { } /// Seam order: the reference first, then by distance of each image's centre from it. -pub(crate) fn seam_order(warped: &[Surface], reference: usize) -> Vec { +pub fn seam_order(warped: &[Surface], reference: usize) -> Vec { let centre = |s: &Surface| { let b = s.content_bounds(); ((b.x0 + b.x1) as f64 / 2.0, (b.y0 + b.y1) as f64 / 2.0) diff --git a/crates/engine-core/src/cmd/smart_cmds.rs b/crates/engine-core/src/cmd/smart_cmds.rs index add6248c27..9362c77882 100644 --- a/crates/engine-core/src/cmd/smart_cmds.rs +++ b/crates/engine-core/src/cmd/smart_cmds.rs @@ -191,7 +191,7 @@ use contents::{edit_contents, export_contents, is_smart_child, path_param, repla use filters::smart_mut; pub(crate) use filters::{add_smart_filter, add_smart_filter_in, filter_mask_paintable, filter_mask_surface, refresh_after_filter_mask_edit}; use filters::{blending_options, delete_filter, edit_filters, move_filter, set_filter_params, set_filter_visible, smart, transfer_filters}; -pub(crate) use placing::detach_psd; +pub use placing::detach_psd; pub(crate) use placing::{affine_homography, set_placement, shift_smart, transform_placement}; use placing::{convert, reset_transform, shift_layer, via_copy}; pub use placing::{layer_to_smart, layers_to_smart, placement}; @@ -199,13 +199,16 @@ use rendering::refresh_or_fail; #[cfg(test)] use rendering::{NativeDigests, blend_surfaces, place, render_in}; pub use rendering::{SourceCacheStatistics, source_cache_statistics}; -pub(crate) use rendering::{WarningRenderSources, render_with_warnings, render_with_warnings_using, source_box}; +pub(crate) use rendering::{render_with_warnings, source_box}; +pub use rendering::WarningRenderSources; +pub use rendering::render_with_warnings_using; pub use rendering::{apply_smart_filters, purge_stack_cache, refresh, refresh_layer, render, render_below_filter, stack_cache_bytes, stack_image}; #[cfg(test)] use source::svg_source_image_in; pub use source::{SourceImage, purge_source_cache, source_bytes, source_cache_bytes, source_decode_count, source_image, svg_source_image}; use source::{authorize_source, authorized_source_bytes}; -pub(crate) use source::{restore_unrendered, take_caches, vector_scale}; +pub(crate) use source::{restore_unrendered, take_caches}; +pub use source::vector_scale; const SO: &[&str] = &["Layer", "Smart Objects"]; const SF: &[&str] = &["Layer", "Smart Filter"]; diff --git a/crates/engine-core/src/cmd/smart_cmds/placing.rs b/crates/engine-core/src/cmd/smart_cmds/placing.rs index fa0f9cf459..f08d35a7b7 100644 --- a/crates/engine-core/src/cmd/smart_cmds/placing.rs +++ b/crates/engine-core/src/cmd/smart_cmds/placing.rs @@ -128,7 +128,7 @@ pub(super) fn reset_transform(s: &mut Session, p: &Value) -> Result { /// Forget PSD placed-layer data that no longer describes the smart object (its source changed): /// PSD export then writes fresh placed-layer blocks and embeds the new source. -pub(crate) fn detach_psd(l: &mut Layer) { +pub fn detach_psd(l: &mut Layer) { if let LayerContent::Smart(sm) = &mut l.content { sm.psd_raw = None; } diff --git a/crates/engine-core/src/cmd/smart_cmds/rendering.rs b/crates/engine-core/src/cmd/smart_cmds/rendering.rs index 3c7fa52d2f..92dff91564 100644 --- a/crates/engine-core/src/cmd/smart_cmds/rendering.rs +++ b/crates/engine-core/src/cmd/smart_cmds/rendering.rs @@ -384,7 +384,7 @@ struct WarningSource { /// One command's bounded source-space renders. Placement, warp, filters and masks /// are instance-specific and must never be cached here. Weak identity pins only the /// allocation header; the borrowed document owns encoded bytes throughout the command. -pub(crate) struct WarningRenderSources<'a> { +pub struct WarningRenderSources<'a> { document: &'a Document, srgb: Option, entries: VecDeque, @@ -394,7 +394,7 @@ pub(crate) struct WarningRenderSources<'a> { } impl<'a> WarningRenderSources<'a> { - pub(crate) fn new(document: &'a Document) -> Self { + pub fn new(document: &'a Document) -> Self { Self { document, srgb: None, entries: VecDeque::new(), budget: if cfg!(target_arch = "wasm32") { 128 << 20 } else { 384 << 20 }, limit: 32, bytes: 0 } } @@ -474,7 +474,7 @@ impl<'a> WarningRenderSources<'a> { } /// Reuse only warning-aware source pixels during one shared-content update. -pub(crate) fn render_with_warnings_using(sm: &SmartObject, sources: &mut WarningRenderSources<'_>) -> Result<(Option, Vec)> { +pub fn render_with_warnings_using(sm: &SmartObject, sources: &mut WarningRenderSources<'_>) -> Result<(Option, Vec)> { let doc = sources.document; if sm.vector_preview.is_some() || sm.stack_mode.is_some() { return render(doc, sm).map(|surface| (surface, Vec::new())); diff --git a/crates/engine-core/src/cmd/smart_cmds/source.rs b/crates/engine-core/src/cmd/smart_cmds/source.rs index 3a4d65e0a4..95cc008850 100644 --- a/crates/engine-core/src/cmd/smart_cmds/source.rs +++ b/crates/engine-core/src/cmd/smart_cmds/source.rs @@ -358,7 +358,7 @@ pub(super) fn convert_svg_source(source: SourceImage, doc: &Document) -> Result< /// The scale a vector source is rasterised at for its placement: the larger axis scale of the /// transform in 1/16 steps (so nudges reuse the cache), between 1/16 and 64. -pub(crate) fn vector_scale(sm: &SmartObject) -> f64 { +pub fn vector_scale(sm: &SmartObject) -> f64 { let [a, b, c, d, ..] = sm.transform.m; let k = (a * a + b * b).sqrt().max((c * c + d * d).sqrt()); if !k.is_finite() { diff --git a/crates/engine-core/src/cmd/type_cmds.rs b/crates/engine-core/src/cmd/type_cmds.rs index ff27c026c7..b5bf1f9345 100644 --- a/crates/engine-core/src/cmd/type_cmds.rs +++ b/crates/engine-core/src/cmd/type_cmds.rs @@ -909,7 +909,7 @@ fn info(s: &Session, p: &Value) -> Result { /// A type layer (not yet rendered or added) from `type.create`'s params: text, point `x`/`y` or /// paragraph `box`, `orientation`, character and paragraph keys, starting from the default type /// styles in the foreground colour. Shared with the Type Mask tools' `type.createSelection`. -pub(crate) fn new_text_layer(s: &Session, p: &Value, cmd: &str) -> Result { +pub fn new_text_layer(s: &Session, p: &Value, cmd: &str) -> Result { crate::commands::check_f32_values(cmd, p)?; let orientation = match p.get("orientation") { None => Orientation::Horizontal, diff --git a/crates/engine-core/src/cmd/type_extra_cmds.rs b/crates/engine-core/src/cmd/type_extra_cmds.rs index cbc9514804..051667b358 100644 --- a/crates/engine-core/src/cmd/type_extra_cmds.rs +++ b/crates/engine-core/src/cmd/type_extra_cmds.rs @@ -73,7 +73,7 @@ fn has_defaults(s: &Session) -> std::result::Result<(), String> { /// Edits a type layer as one history step and re-renders it. `f` gets the document's resolution /// (dpi). -pub(crate) fn with_text(s: &mut Session, p: &Value, label: &str, f: impl FnOnce(&mut TextLayer, f32) -> Result) -> Result { +pub fn with_text(s: &mut Session, p: &Value, label: &str, f: impl FnOnce(&mut TextLayer, f32) -> Result) -> Result { let id = layer_param(s, p)?; check_text_unlocked(&s.active().ok_or(EngineError::NoDocument)?.doc, id)?; let typed = typed_name(s, id); @@ -431,7 +431,7 @@ pub fn type_path(t: &TextLayer) -> Option { /// Puts an edited [`type_path`] back into `t` (its text space), keeping where the type starts and /// which side it runs on. It must still be one subpath with two or more points. -pub(crate) fn set_type_path(t: &mut TextLayer, edited: &Path) -> Result<()> { +pub fn set_type_path(t: &mut TextLayer, edited: &Path) -> Result<()> { let TextShape::Path { start, end, flip, .. } = &t.shape else { return Err(EngineError::Other("the type layer is not on a path".into())) }; let (start, end, flip) = (*start, *end, *flip); let [sub] = edited.subpaths.as_slice() else { return Err(EngineError::Other("type on a path follows one path".into())) }; diff --git a/crates/engine-core/src/cmd/vector_cmds.rs b/crates/engine-core/src/cmd/vector_cmds.rs index 29af7a082b..1bbbbd3f57 100644 --- a/crates/engine-core/src/cmd/vector_cmds.rs +++ b/crates/engine-core/src/cmd/vector_cmds.rs @@ -32,11 +32,11 @@ use crate::{EngineError, Result, Session}; /// Keys PSD uses for a shape layer's vector data; dropped when a shape is rasterized. pub(crate) const SHAPE_BLOCKS: [&[u8; 4]; 8] = [b"vmsk", b"vsms", b"vogk", b"vstk", b"vscg", b"SoCo", b"GdFl", b"PtFl"]; -pub(crate) fn bad(cmd: &str, msg: impl Into) -> EngineError { +pub fn bad(cmd: &str, msg: impl Into) -> EngineError { EngineError::BadParams { cmd: cmd.into(), msg: msg.into() } } -pub(crate) fn has_doc(s: &Session) -> std::result::Result<(), String> { +pub fn has_doc(s: &Session) -> std::result::Result<(), String> { s.active().map(|_| ()).ok_or_else(|| "no document open".into()) } @@ -69,15 +69,21 @@ mod paths; mod shape; mod vector_mask; -pub(crate) use params::{layer_id, nums, op_from, pt}; +pub use params::{layer_id}; +pub use params::nums; +pub use params::op_from; +pub use params::pt; pub use params::{parse_path, parse_stroke, path_json}; pub use paths::STROKE_PATH_TOOLS; use paths::{ clipping_path_clear, clipping_path_set, path_delete, path_fill, path_rename, path_set, path_stroke, path_to_selection, path_to_selection_with_mode, path_transform, paths_list, resolve_path, select_to_work_path, }; -pub(crate) use paths::{is_work, path_mut}; -pub(crate) use shape::{bake_path, map_path, map_shape, shift_shape, translate_vectors_wrapped, with_shape}; +pub use paths::{is_work}; +pub use paths::path_mut; +pub(crate) use shape::{map_path, map_shape, shift_shape, translate_vectors_wrapped}; +pub use shape::bake_path; +pub use 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, path_to_shape, selection_to_shape, shape_create, shape_edit, shape_info, shape_rasterize, @@ -85,7 +91,7 @@ use shape::{ 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}; -pub(crate) fn leak(s: String) -> &'static str { +pub fn leak(s: String) -> &'static str { Box::leak(s.into_boxed_str()) } diff --git a/crates/engine-core/src/cmd/vector_cmds/params.rs b/crates/engine-core/src/cmd/vector_cmds/params.rs index ea52a43bc9..825274984c 100644 --- a/crates/engine-core/src/cmd/vector_cmds/params.rs +++ b/crates/engine-core/src/cmd/vector_cmds/params.rs @@ -3,7 +3,7 @@ use super::{ Value, bad, json, }; -pub(crate) fn layer_id(s: &Session, p: &Value) -> Result { +pub fn layer_id(s: &Session, p: &Value) -> Result { crate::commands::layer_param(s, p) } @@ -11,7 +11,7 @@ pub(super) fn f64p(p: &Value, k: &str) -> Option { p.get(k).and_then(Value::as_f64) } -pub(crate) fn pt(v: &Value) -> Option { +pub fn pt(v: &Value) -> Option { match v { Value::Array(a) if a.len() >= 2 => Some(Point::new(a[0].as_f64()?, a[1].as_f64()?)), Value::Object(_) => Some(Point::new(v.get("x")?.as_f64()?, v.get("y")?.as_f64()?)), @@ -19,7 +19,7 @@ pub(crate) fn pt(v: &Value) -> Option { } } -pub(crate) fn nums(p: &Value, k: &str) -> Option<[f64; N]> { +pub fn nums(p: &Value, k: &str) -> Option<[f64; N]> { let a = p.get(k)?.as_array()?; if a.len() < N { return None; @@ -69,7 +69,7 @@ fn hex(c: &Color) -> String { if c.alpha < 1.0 { format!("#{:02x}{:02x}{:02x}{:02x}", q(r), q(g), q(b), q(c.alpha)) } else { format!("#{:02x}{:02x}{:02x}", q(r), q(g), q(b)) } } -pub(crate) fn op_from(s: &str) -> Option { +pub fn op_from(s: &str) -> Option { Some(match s.to_ascii_lowercase().as_str() { "combine" | "add" | "union" => PathOp::Combine, "subtract" | "minus" => PathOp::Subtract, diff --git a/crates/engine-core/src/cmd/vector_cmds/paths.rs b/crates/engine-core/src/cmd/vector_cmds/paths.rs index fd1c3cfe84..f53f836956 100644 --- a/crates/engine-core/src/cmd/vector_cmds/paths.rs +++ b/crates/engine-core/src/cmd/vector_cmds/paths.rs @@ -9,7 +9,7 @@ use super::{ // Document paths // --------------------------------------------------------------------------- -pub(crate) fn is_work(name: Option<&str>) -> bool { +pub fn is_work(name: Option<&str>) -> bool { name.is_none_or(|n| n.is_empty() || n.eq_ignore_ascii_case("work") || n == "Work Path") } @@ -37,7 +37,7 @@ pub(super) fn resolve_path(s: &Session, name: Option<&str>) -> Result { /// The path an edit targets, except a shape layer's (edit those with [`with_shape`], which /// re-renders them): `layer`'s vector mask when given, else the work path or a saved path. -pub(crate) fn path_mut<'a>(doc: &'a mut Document, name: &str, layer: Option) -> Result<&'a mut Path> { +pub fn path_mut<'a>(doc: &'a mut Document, name: &str, layer: Option) -> Result<&'a mut Path> { if let Some(id) = layer { let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?; return l.vector_mask.as_mut().map(|vm| &mut vm.path).ok_or_else(|| EngineError::Other("active layer has no shape path or vector mask".into())); diff --git a/crates/engine-core/src/cmd/vector_cmds/shape.rs b/crates/engine-core/src/cmd/vector_cmds/shape.rs index 9d59ac44c5..a2724b55a7 100644 --- a/crates/engine-core/src/cmd/vector_cmds/shape.rs +++ b/crates/engine-core/src/cmd/vector_cmds/shape.rs @@ -397,7 +397,7 @@ pub(super) fn shape_info(s: &Session, id: LayerId) -> Result { })) } -pub(crate) fn with_shape(s: &mut Session, id: LayerId, label: &str, f: impl FnOnce(&mut ShapeLayer, &mut Layer) -> Result) -> Result { +pub fn with_shape(s: &mut Session, id: LayerId, label: &str, f: impl FnOnce(&mut ShapeLayer, &mut Layer) -> Result) -> Result { if let Some(st) = s.active() { let locks = st.doc.effective_locks(id); if locks.all || locks.pixels { @@ -699,7 +699,7 @@ fn bake_components(sh: &mut ShapeLayer, tol: f64) -> Result<()> { /// inverted path (a vector mask's) stays inverted around the merged area. An open subpath is /// refused: tracing its fill would close it, or drop a straight one or a lone anchor (a dot under /// a round or square cap), losing the stroked geometry. -pub(crate) fn bake_path(path: &Path, tol: f64) -> Result { +pub fn bake_path(path: &Path, tol: f64) -> Result { if path.subpaths.iter().any(|sp| !sp.closed && !sp.knots.is_empty()) { return Err(EngineError::Other("Merge Shape Components needs closed paths: close or delete the open subpaths first".into())); } diff --git a/crates/engine-core/src/error.rs b/crates/engine-core/src/error.rs index 0c482afd93..406d872d08 100644 --- a/crates/engine-core/src/error.rs +++ b/crates/engine-core/src/error.rs @@ -140,7 +140,7 @@ impl EngineError { /// Maps an io open/import failure to the engine's typed errors, preserving the memory fields the /// UI, control channel and agents need to answer or explain it. -pub(crate) fn io_open_error(name: &str, error: photocraft_io::IoError) -> EngineError { +pub fn io_open_error(name: &str, error: photocraft_io::IoError) -> EngineError { use photocraft_io::IoError; match error { IoError::PsdApprovalRequired { required, soft_limit, hard_limit, available_ram } => { diff --git a/crates/engine-core/src/install.rs b/crates/engine-core/src/install.rs index 706a7f577f..56544361a4 100644 --- a/crates/engine-core/src/install.rs +++ b/crates/engine-core/src/install.rs @@ -40,16 +40,13 @@ const TABLES: &[Table] = &[ ("solid_fill_cmds", crate::solid_fill_cmds::specs), ("pattern_fill_cmds", crate::pattern_fill_cmds::specs), ("type_cmds", crate::type_cmds::specs), - ("type_mask_cmds", crate::type_mask_cmds::specs), ("transform_cmds", crate::transform_cmds::specs), ("float_cmds", crate::float_cmds::specs), ("vector_cmds", crate::vector_cmds::specs), - ("path_edit_cmds", crate::path_edit_cmds::specs), ("smartselect_cmds", crate::smartselect_cmds::specs), ("cutout_cmds", crate::cutout_cmds::specs), ("symmetry_cmds", crate::symmetry_cmds::specs), ("edit_cmds", crate::edit_cmds::specs), - ("smart_svg_cmds", crate::smart_svg_cmds::specs), ("color_cmds", crate::color_cmds::specs), ("brush_preset_cmds", crate::brush_preset_cmds::specs), ("preset_import_cmds", crate::preset_import_cmds::specs), @@ -67,17 +64,13 @@ const TABLES: &[Table] = &[ ("file_cmds", crate::file_cmds::specs), ("exr_cmds", crate::exr_cmds::specs), ("type_extra_cmds", crate::type_extra_cmds::specs), - ("type_area_cmds", crate::type_area_cmds::specs), - ("type_styles_cmds", crate::type_styles_cmds::specs), ("type_spell_cmds", crate::type_spell_cmds::specs), - ("type_caret_cmds", crate::type_caret_cmds::specs), ("smart_cmds", crate::smart_cmds::specs), ("layer_multi_cmds", crate::layer_multi_cmds::specs), ("layer_copy_cmds", crate::layer_copy_cmds::specs), ("prefs", crate::prefs::specs), ("edit_menu_cmds", crate::edit_menu_cmds::specs), ("sample_cmds", crate::sample_cmds::specs), - ("align_cmds", crate::align_cmds::specs), ("photo_cmds", crate::photo_cmds::specs), ("lens_cmds", crate::lens_cmds::specs), ("vp_cmds", crate::vp_cmds::specs), @@ -85,17 +78,13 @@ const TABLES: &[Table] = &[ ("adjust_cmds", crate::adjust_cmds::specs), ("layer_menu_cmds", crate::layer_menu_cmds::specs), ("layer_label_cmds", crate::layer_label_cmds::specs), - ("layer_css_cmds", crate::layer_css_cmds::specs), - ("layer_xmp_cmds", crate::layer_xmp_cmds::specs), ("mode_cmds", crate::mode_cmds::specs), ("multichannel_cmds", crate::multichannel_cmds::specs), ("pattern_cmds", crate::pattern_cmds::specs), ("warp_cmds", crate::warp_cmds::specs), - ("comps_cmds", crate::comps_cmds::specs), ("artboard_cmds", crate::artboard_cmds::specs), ("distort_cmds", crate::distort_cmds::specs), ("analysis_cmds", crate::analysis_cmds::specs), - ("notes_cmds", crate::notes_cmds::specs), ("font_library_cmds", crate::font_library_cmds::specs), ("history_cmds", crate::history_cmds::specs), ("history_options_cmds", crate::history_options_cmds::specs), @@ -115,12 +104,10 @@ const TABLES: &[Table] = &[ ("layer_nav_cmds", crate::layer_nav_cmds::specs), ("frame_cmds", crate::frame_cmds::specs), ("migrate_cmds", crate::migrate_cmds::specs), - ("trap_cmds", crate::trap_cmds::specs), ("timeline_cmds", crate::timeline_cmds::specs), ("video_cmds", crate::video_cmds::specs), ("jobs", crate::jobs::specs), ("wia_cmds", crate::wia_cmds::specs), - ("rasterize_style_cmds", crate::rasterize_style_cmds::specs), ("variables_cmds", crate::variables_cmds::specs), ("plugin_cmds", crate::plugin_cmds::specs), ("group_view_cmds", crate::group_view_cmds::specs), @@ -175,10 +162,7 @@ pub fn register(install: &mut Install) { Some(crate::artboard_cmds::recorded_duplicate(s, crate::layer_multi_cmds::recorded_step(s, id, p.clone(), pre_selected))) })); hooks.recorded_step = Some(crate::layer_multi_cmds::recorded_step); - - // vector hooks.before_command.push(crate::float_cmds::before_dispatch); - hooks.recorded_steps.push(("layerComp.apply", |s, _, p, _| Some(crate::comps_cmds::recorded_apply(s, p.clone())))); hooks.recorded_steps.push(("edit.checkSpelling", |_, _, p, _| crate::type_spell_cmds::records(p).then(|| crate::type_spell_cmds::recorded_step(p)))); hooks.prefs_applied.push(|s| crate::transform_cmds::set_budget(u64::from(s.prefs().performance.effective_memory_usage_mb()) << 20)); // An edited Edit Contents document updates its parent as it closes. diff --git a/crates/engine-core/src/lib.rs b/crates/engine-core/src/lib.rs index 5bb6eba78a..cbdd00e00d 100644 --- a/crates/engine-core/src/lib.rs +++ b/crates/engine-core/src/lib.rs @@ -71,7 +71,7 @@ pub use photocraft_paint::BrushSettings; pub mod cmd; mod doc_state; -mod error; +pub mod error; mod install; pub mod registry; mod session; @@ -224,7 +224,7 @@ pub struct Session { /// Text layer changed by the last journal entry, for folding Type tool keystrokes. typed_layer: Option<(photocraft_doc::DocId, LayerId)>, /// Coalescing key of the command being executed. - coalesce_request: Option, + pub coalesce_request: Option, /// The outer action's original document/history states, independent of command transactions. action_history: Option, /// Weak leases expire when every copy of a suspended continuation is abandoned. diff --git a/crates/engine-core/src/param_check.rs b/crates/engine-core/src/param_check.rs index 447046cc4d..c8f6dce2f7 100644 --- a/crates/engine-core/src/param_check.rs +++ b/crates/engine-core/src/param_check.rs @@ -72,7 +72,6 @@ pub(crate) const INCOMPLETE: &[&str] = &[ "layer.videoLayers.newVideoLayerFromFile", "layer.videoLayers.replaceFootage", "measurementLog.delete", - "notes.delete", "path.addToSelection", "path.intersectWithSelection", "path.set", diff --git a/crates/engine-vector/Cargo.toml b/crates/engine-vector/Cargo.toml new file mode 100644 index 0000000000..8a54de2a12 --- /dev/null +++ b/crates/engine-vector/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "photocraft-engine-vector" +version.workspace = true +edition.workspace = true +license.workspace = true + +[lints] +workspace = true + +# The vector-area commands of the engine (photocraft#15710): align, layer comps, layer CSS and XMP, +# notes, path editing, rasterize style, smart-object SVG, traps and the type commands for areas, +# carets, masks and styles. Built on photocraft-engine-core. +[dependencies] +photocraft-engine-core = { workspace = true } +craft-cms = { workspace = true } +craft-xml = { workspace = true } +photocraft-algo = { workspace = true } +photocraft-codecs = { workspace = true } +photocraft-color = { workspace = true } +photocraft-compose = { workspace = true } +photocraft-doc = { workspace = true } +photocraft-format = { workspace = true } +photocraft-geom = { workspace = true } +photocraft-io = { workspace = true } +photocraft-paint = { workspace = true } +photocraft-raster = { workspace = true } +photocraft-text = { workspace = true } +photocraft-vector = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +rayon = { workspace = true } +chrono = { workspace = true } +base64 = "0.22" +blake3 = { version = "1.8", default-features = false, features = ["pure"] } +flate2 = { workspace = true } + +# Core's allocation failpoints, which the notes import and Type Mask tests arm. +[dev-dependencies] +photocraft-engine-core = { workspace = true, features = ["failpoints"] } +photocraft-io = { workspace = true, features = ["testgen"] } +photocraft-testkit = { workspace = true } + +[features] +# Real-file corpus tests (opt-in; `cargo xtask test-corpus`). Fail when the corpus is missing. +corpus = [] diff --git a/crates/engine-vector/src/cmd.rs b/crates/engine-vector/src/cmd.rs new file mode 100644 index 0000000000..2f567ccaa3 --- /dev/null +++ b/crates/engine-vector/src/cmd.rs @@ -0,0 +1,17 @@ +//! The vector-area commands, one module per area. + +pub mod align_cmds; +pub mod comps_cmds; +pub mod layer_css_cmds; +pub mod layer_xmp_cmds; +pub mod notes_cmds; +#[cfg(test)] +mod notes_stored_values_tests; +pub mod path_edit_cmds; +pub mod rasterize_style_cmds; +pub mod smart_svg_cmds; +pub mod trap_cmds; +pub mod type_area_cmds; +pub mod type_caret_cmds; +pub mod type_mask_cmds; +pub mod type_styles_cmds; diff --git a/crates/engine-vector/src/install.rs b/crates/engine-vector/src/install.rs new file mode 100644 index 0000000000..2a9c56062a --- /dev/null +++ b/crates/engine-vector/src/install.rs @@ -0,0 +1,84 @@ +//! This crate's command tables and hooks, and the install for a process that uses this crate +//! and core (this crate's own tests). `photocraft_engine::install()` installs them with every +//! other engine crate's. + +use std::sync::OnceLock; + +use photocraft_engine_core::registry::{self, Install, Table}; + +use crate::{Result, Session}; + +/// This crate's command tables with their names, in the app's registry order +/// (`crates/engine/src/install/command_ids.txt`). +const TABLES: &[Table] = &[ + ("type_mask_cmds", crate::type_mask_cmds::specs), + ("path_edit_cmds", crate::path_edit_cmds::specs), + ("smart_svg_cmds", crate::smart_svg_cmds::specs), + ("type_area_cmds", crate::type_area_cmds::specs), + ("type_styles_cmds", crate::type_styles_cmds::specs), + ("type_caret_cmds", crate::type_caret_cmds::specs), + ("align_cmds", crate::align_cmds::specs), + ("layer_css_cmds", crate::layer_css_cmds::specs), + ("layer_xmp_cmds", crate::layer_xmp_cmds::specs), + ("comps_cmds", crate::comps_cmds::specs), + ("notes_cmds", crate::notes_cmds::specs), + ("trap_cmds", crate::trap_cmds::specs), + ("rasterize_style_cmds", crate::rasterize_style_cmds::specs), +]; + +/// This crate's commands whose doc does not yet name every key they read (the engine's own tests +/// pass them more): not checked until their doc is completed. The list may only shrink. +const INCOMPLETE: &[&str] = &["notes.delete"]; + +/// This crate's command tables. +pub fn command_tables() -> &'static [Table] { + TABLES +} + +/// This crate's pipeline hooks. Its recorded step is looked up by command id, so the order the +/// engine crates' `register`s run in doesn't change what it does. +pub fn register(install: &mut Install) { + install.incomplete.push(INCOMPLETE); + let hooks = &mut install.hooks; + hooks.recorded_steps.push(("layerComp.apply", |s, _, p, _| Some(crate::comps_cmds::recorded_apply(s, p.clone())))); +} + +/// Install core's commands and this crate's for the process. Later calls return the first call's result. +pub fn install() -> Result<()> { + static INSTALLED: OnceLock> = OnceLock::new(); + INSTALLED + .get_or_init(|| { + let mut install = Install::default(); + install.commands.extend_from_slice(photocraft_engine_core::command_tables()); + install.commands.extend_from_slice(TABLES); + photocraft_engine_core::register(&mut install); + register(&mut install); + registry::install(install) + }) + .clone() +} + +/// A session with core's commands and this crate's installed: what this crate's tests start from. +pub fn session() -> Session { + // A conflicting install reports itself at the session's first command. + let _ = install(); + Session::new() +} + +#[cfg(test)] +mod tests { + use photocraft_engine_core::param_schema; + + use super::{INCOMPLETE, install}; + + #[test] + fn incomplete_docs_are_registered_closed_docs() { + install().unwrap(); + for id in INCOMPLETE { + let spec = photocraft_engine_core::commands::find(id).unwrap_or_else(|| panic!("{id} is not registered")); + assert!(param_schema::of(spec).is_some_and(|p| !p.open()), "{id}: open or unparsed docs are not checked anyway"); + assert!(photocraft_engine_core::is_incomplete(id), "{id} is on the installed list"); + } + assert!(INCOMPLETE.windows(2).all(|w| w[0] < w[1]), "sorted, no duplicates"); + } +} diff --git a/crates/engine-vector/src/lib.rs b/crates/engine-vector/src/lib.rs new file mode 100644 index 0000000000..b546a3f833 --- /dev/null +++ b/crates/engine-vector/src/lib.rs @@ -0,0 +1,35 @@ +//! The PhotoCraft engine's vector-area commands: alignment, layer comps, layer CSS and XMP, notes, +//! path editing, rasterized layer styles, smart-object SVG, traps and the type area, caret, mask +//! and style commands. +//! +//! Built on [`photocraft_engine_core`]; [`install`] installs core's commands and this crate's, and +//! [`session`] makes a session after it. Apps use `photocraft-engine`, which installs every engine crate. +#![forbid(unsafe_code)] +#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] + +// The core items this crate's code names as `crate::x`, so the code reads as it did inside core +// (photocraft#15710). +use photocraft_engine_core::{ + EngineError, Result, Session, active_layer_of, allocation, analysis_cmds, channel_cmds, commands, error, extra_cmds, file_cmds, layer_multi_cmds, + layer_place, photo_cmds, smart_cmds, transform_cmds, type_cmds, type_extra_cmds, vector_cmds, +}; +#[cfg(test)] +use photocraft_engine_core::{actions_cmds, command_specs, inspect}; + +pub mod cmd; +mod install; + +pub use cmd::align_cmds; +pub use cmd::comps_cmds; +pub use cmd::layer_css_cmds; +pub use cmd::layer_xmp_cmds; +pub use cmd::notes_cmds; +pub use cmd::path_edit_cmds; +pub use cmd::rasterize_style_cmds; +pub use cmd::smart_svg_cmds; +pub use cmd::trap_cmds; +pub use cmd::type_area_cmds; +pub use cmd::type_caret_cmds; +pub use cmd::type_mask_cmds; +pub use cmd::type_styles_cmds; +pub use install::{command_tables, install, register, session}; diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 1a5b7db9c0..e11d9f9c40 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -14,12 +14,13 @@ path = "src/facade.rs" [features] # Real-file corpus tests (opt-in; `cargo xtask test-corpus`). Fail when the corpus is missing. -corpus = ["photocraft-engine-core/corpus"] +corpus = ["photocraft-engine-vector/corpus"] # The engine's code and dependencies live in the engine crates; this crate re-exports them. [dependencies] photocraft-engine-core = { workspace = true } photocraft-engine-paint = { workspace = true } +photocraft-engine-vector = { workspace = true } # What tests/ and examples/ use. [dev-dependencies] diff --git a/crates/engine/src/facade.rs b/crates/engine/src/facade.rs index 68643541bf..7178655aef 100644 --- a/crates/engine/src/facade.rs +++ b/crates/engine/src/facade.rs @@ -19,6 +19,8 @@ pub use photocraft_engine_paint::{ adjustment_brush_cmds, brush_cmds, brush_key_cmds, eraser_cmds, face_cmds, fill_cmds, fill_key_cmds, paint_cmds, pick_cmds, redeye_cmds, retouch_cmds, sampler_cmds, stamp_cmds, }; +// The vector-area commands' modules, likewise. +pub use photocraft_engine_vector::{align_cmds, comps_cmds, layer_css_cmds, layer_xmp_cmds, notes_cmds, path_edit_cmds, rasterize_style_cmds, smart_svg_cmds, trap_cmds, type_area_cmds, type_caret_cmds, type_mask_cmds, type_styles_cmds}; mod install; @@ -33,6 +35,7 @@ pub mod commands { adjustment_brush_cmds, brush_cmds, brush_key_cmds, eraser_cmds, face_cmds, fill_cmds, fill_key_cmds, paint_cmds, pick_cmds, redeye_cmds, retouch_cmds, sampler_cmds, stamp_cmds, }; + pub use photocraft_engine_vector::cmd::{align_cmds, comps_cmds, layer_css_cmds, layer_xmp_cmds, notes_cmds, path_edit_cmds, rasterize_style_cmds, smart_svg_cmds, trap_cmds, type_area_cmds, type_caret_cmds, type_mask_cmds, type_styles_cmds}; } pub use commands as cmd; diff --git a/crates/engine/src/install.rs b/crates/engine/src/install.rs index a5ae8740c6..f60d94bf84 100644 --- a/crates/engine/src/install.rs +++ b/crates/engine/src/install.rs @@ -11,8 +11,8 @@ use crate::Result; const ORDER: &str = include_str!("install/command_ids.txt"); /// Every engine crate's command tables, core first, then the crates above it. -fn crate_tables() -> [&'static [Table]; 2] { - [photocraft_engine_core::command_tables(), photocraft_engine_paint::command_tables()] +fn crate_tables() -> [&'static [Table]; 3] { + [photocraft_engine_core::command_tables(), photocraft_engine_paint::command_tables(), photocraft_engine_vector::command_tables()] } /// Install every engine command for this process. Later calls return the first call's result. @@ -28,6 +28,7 @@ pub fn install() -> Result<()> { // Each stage runs its hooks in this order; core's own list keeps today's after-command order. photocraft_engine_core::register(&mut install); photocraft_engine_paint::register(&mut install); + photocraft_engine_vector::register(&mut install); registry::install(install) }) .clone() diff --git a/crates/ui-egui/tests/it/display_names.rs b/crates/ui-egui/tests/it/display_names.rs index c65c1b58f5..9ded75a3cc 100644 --- a/crates/ui-egui/tests/it/display_names.rs +++ b/crates/ui-egui/tests/it/display_names.rs @@ -21,7 +21,7 @@ const ALLOWED: &[&str] = &[ ]; // The only catalog rows that may say "Camera Raw": their English text names Photoshop's .xmp files. const ALLOWED_KEYS: &[&str] = &["Save these settings as a Camera Raw .xmp file", "Load settings from a Camera Raw .xmp file"]; -const ROOTS: &[&str] = &["src", "../engine/src", "../engine-core/src", "../engine-paint/src"]; +const ROOTS: &[&str] = &["src", "../engine/src", "../engine-core/src", "../engine-paint/src", "../engine-vector/src"]; fn is_word(c: char) -> bool { c.is_alphanumeric() || c == '_' diff --git a/docs/contributing.md b/docs/contributing.md index c02b60d0a3..0f41eaebb5 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -15,7 +15,7 @@ 1. **Find the id.** Search `crates/ui-egui/src/menu_catalog.rs` for the Photoshop menu item. Using its id makes the menu item live with no UI work. Commands without a Photoshop menu entry use a descriptive id in the same style (`layer.smartFilter.delete`) and an empty menu path. 2. **Algorithm** goes in the lowest crate that fits (`algo` for imaging, `paint`, `vector`, `text`; colour management is `craft-cms` in craft-libs), with unit tests. It takes depth-agnostic surfaces (`photocraft-raster`), works per tile, and is deterministic (seeded randomness). -3. **Command** goes in an engine module (`crates/engine-core/src/_cmds.rs`, or `crates/engine-/src/cmd/_cmds.rs` for a crate cut out of core, such as `engine-paint`) exposing `specs()`, registered by adding `("", crate::::specs)` to `TABLES` in that crate's `install.rs`, and its ids to `crates/engine/src/install/command_ids.txt` after the command it follows in the menus: that file sets the registry order (the top crate's order test says how). A command in a core menu goes in the owner fragment `cmd/table//.rs` of its crate instead. Fill in: +3. **Command** goes in an engine module (`crates/engine-core/src/_cmds.rs`, or `crates/engine-/src/cmd/_cmds.rs` for a crate cut out of core, such as `engine-paint` or `engine-vector`) exposing `specs()`, registered by adding `("", crate::::specs)` to `TABLES` in that crate's `install.rs`, and its ids to `crates/engine/src/install/command_ids.txt` after the command it follows in the menus: that file sets the registry order (the top crate's order test says how). A command in a core menu goes in the owner fragment `cmd/table//.rs` of its crate instead. Fill in: - `id`, `label`, `menu` path and Photoshop's default `shortcut`, - a params doc string such as `{"radius":px=4,"mode":"a|b"="a"}` (this is what agents read through `commands` / `command_list`), - an `enabled` predicate (greys the menu item out), diff --git a/xtask/src/corpus.rs b/xtask/src/corpus.rs index 29510b6e05..2138e59045 100644 --- a/xtask/src/corpus.rs +++ b/xtask/src/corpus.rs @@ -15,7 +15,7 @@ use crate::pinned::{PinnedCorpus, USER_AGENT}; use crate::{cargo, root, run}; /// Crates with corpus tests (behind their `corpus` feature). -pub const CORPUS_CRATES: &[&str] = &["photocraft-io", "photocraft-engine-core", "photocraft-engine"]; +pub const CORPUS_CRATES: &[&str] = &["photocraft-io", "photocraft-engine-vector", "photocraft-engine"]; /// Opt-in corpus crates: fetched and tested only with `test-corpus --pixls`. pub const PIXLS_CRATES: &[&str] = &["photocraft-raw"]; diff --git a/xtask/src/layers.rs b/xtask/src/layers.rs index dd5e40023b..ab99aa9e8b 100644 --- a/xtask/src/layers.rs +++ b/xtask/src/layers.rs @@ -61,6 +61,7 @@ pub const TABLE: &[(&str, Class)] = &[ ("plugins", Class::Layer(4)), ("engine-core", Class::Layer(5)), ("engine-paint", Class::Layer(5)), + ("engine-vector", Class::Layer(5)), ("engine", Class::Layer(5)), ("ui-egui", Class::Layer(6)), ("automation", Class::Layer(6)), @@ -80,7 +81,7 @@ pub const TABLE: &[(&str, Class)] = &[ /// `geom`, which the §3 diagram draws on one line. The GPU backend (`gpu`) /// reuses the CPU reference (`compose`) for LUTs and parity tests. The engine's crates form one /// chain per leaf crate, from `engine-core` to the top crate `engine` (photocraft#15710). -pub const INTRA_LAYER_ORDER: &[&[&str]] = &[&["geom", "color", "raster"], &["compose", "gpu"], &["engine-core", "engine-paint", "engine"]]; +pub const INTRA_LAYER_ORDER: &[&[&str]] = &[&["geom", "color", "raster"], &["compose", "gpu"], &["engine-core", "engine-paint", "engine"], &["engine-core", "engine-vector", "engine"]]; fn intra_layer_allowed(from: &str, to: &str) -> bool { let (from, to) = (short_name(from), short_name(to));