Engine split step 8: the vector crate (install, incomplete-docs list, layer comp recorded step, top wiring, corpus feature, core items vector uses made public, tooling)

This commit is contained in:
aiongg committed 2026-11-24 02:41:56 +00:00
1 parent eb982b0c82
commit 6d73dcee09
42 files changed
+313 -91

No files matched your search

Generated
+30
View File
@@ -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"
+5 -1
View File
@@ -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]
-2
View File
@@ -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 = []
+7 -3
View File
@@ -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};
+1 -1
View File
@@ -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<R>(s: &mut Session, label: &str, f: impl FnOnce(&mut Session) -> Result<R>) -> Result<R> {
pub fn compound<R>(s: &mut Session, label: &str, f: impl FnOnce(&mut Session) -> Result<R>) -> Result<R> {
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());
+1 -1
View File
@@ -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.
+4 -4
View File
@@ -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<bool> {
pub fn rasterize_one(s: &mut Session, id: LayerId, only: Option<&str>, key: &str) -> Result<bool> {
let vector_mask = has_vector_mask(s, id, only);
let content = rasterize_content(s, id, only, key)?;
if vector_mask {
+9 -4
View File
@@ -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}\"") })
}
@@ -176,7 +176,7 @@ pub fn template_name(s: &Session, path: &str) -> Option<String> {
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) }
+3 -3
View File
@@ -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<f64>,
/// 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<Self> {
pub fn from_params(s: &Session, p: &Value, cmd: &str) -> Result<Self> {
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<SaveOpts>) -> 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<SaveOpts>) -> Result<Vec<String>> {
pub fn save_doc(doc: &Document, path: &str, save: impl Into<SaveOpts>) -> Result<Vec<String>> {
let (bytes, warnings) = encode(doc, path, save)?;
write_file(path, &bytes)?;
Ok(warnings)
@@ -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};
@@ -14,7 +14,7 @@ pub fn selected(s: &Session) -> Vec<LayerId> {
/// 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<Vec<LayerId>> {
pub fn targets(s: &Session, p: &serde_json::Value) -> Result<Vec<LayerId>> {
if p.get("layer").is_some() {
return Ok(vec![crate::commands::layer_param(s, p)?]);
}
@@ -220,7 +220,7 @@ pub(super) fn merge_layers(s: &mut Session) -> Result<Value> {
/// 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<LayerId> {
pub fn deletion_neighbours(doc: &Document, target: LayerId) -> Vec<LayerId> {
let rows = |expand_all: bool| {
let mut stack: Vec<&Layer> = doc.layers.iter().collect();
let mut order = Vec::new();
+1 -1
View File
@@ -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<Option<LayerId>> {
pub fn explicit_layer(s: &Session, p: &Value) -> Result<Option<LayerId>> {
let named = |name: &str| {
let d = s.active().ok_or(EngineError::NoDocument)?;
let layers = d.doc.walk();
+1 -1
View File
@@ -156,7 +156,7 @@ fn mask_destination(s: &Session, p: &Value) -> Result<LayerId> {
/// 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);
}
+2 -2
View File
@@ -25,12 +25,12 @@ pub(crate) fn int_i32(cmd: &str, p: &Value, key: &str) -> Result<Option<i32>> {
/// 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<u32> {
pub fn u32_id(cmd: &str, key: &str, v: &Value) -> Result<u32> {
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<Option<u32>> {
pub fn u32_id_param(cmd: &str, p: &Value, key: &str) -> Result<Option<u32>> {
p.get(key).map(|v| u32_id(cmd, key, v)).transpose()
}
+9 -9
View File
@@ -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<usize>, geometric: bool, focal35: Option<f64>) -> Option<Alignment> {
pub fn register(images: &[(&Surface, Rect)], layout: Layout, reference: Option<usize>, geometric: bool, focal35: Option<f64>) -> Option<Alignment> {
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<panorama::PreparedImage> = 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<Alignment, String> {
pub fn register_direct(images: &[(&Surface, Rect)], layout: Layout, reference: usize) -> std::result::Result<Alignment, String> {
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<f64> {
/// 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<Surface> {
pub fn warp_placed(surf: &Surface, rect: Rect, origin: (f64, f64), pl: &Placement, offset: (f64, f64), interp: Interp) -> Result<Surface> {
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<Homography> {
pub fn plane_matrix(pl: &Placement, origin: (f64, f64)) -> Option<Homography> {
(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<Vec<f32>>,
@@ -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<BlendGeometry<'a>>,
@@ -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<Surface>,
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<usize> {
pub fn seam_order(warped: &[Surface], reference: usize) -> Vec<usize> {
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)
+6 -3
View File
@@ -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"];
@@ -128,7 +128,7 @@ pub(super) fn reset_transform(s: &mut Session, p: &Value) -> Result<Value> {
/// 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;
}
@@ -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<bool>,
entries: VecDeque<WarningSource>,
@@ -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<Surface>, Vec<String>)> {
pub fn render_with_warnings_using(sm: &SmartObject, sources: &mut WarningRenderSources<'_>) -> Result<(Option<Surface>, Vec<String>)> {
let doc = sources.document;
if sm.vector_preview.is_some() || sm.stack_mode.is_some() {
return render(doc, sm).map(|surface| (surface, Vec::new()));
@@ -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() {
+1 -1
View File
@@ -909,7 +909,7 @@ fn info(s: &Session, p: &Value) -> Result<Value> {
/// 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<TextLayer> {
pub fn new_text_layer(s: &Session, p: &Value, cmd: &str) -> Result<TextLayer> {
crate::commands::check_f32_values(cmd, p)?;
let orientation = match p.get("orientation") {
None => Orientation::Horizontal,
@@ -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<R>(s: &mut Session, p: &Value, label: &str, f: impl FnOnce(&mut TextLayer, f32) -> Result<R>) -> Result<R> {
pub fn with_text<R>(s: &mut Session, p: &Value, label: &str, f: impl FnOnce(&mut TextLayer, f32) -> Result<R>) -> Result<R> {
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<Path> {
/// 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())) };
+12 -6
View File
@@ -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<String>) -> EngineError {
pub fn bad(cmd: &str, msg: impl Into<String>) -> 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())
}
@@ -3,7 +3,7 @@ use super::{
Value, bad, json,
};
pub(crate) fn layer_id(s: &Session, p: &Value) -> Result<LayerId> {
pub fn layer_id(s: &Session, p: &Value) -> Result<LayerId> {
crate::commands::layer_param(s, p)
}
@@ -11,7 +11,7 @@ pub(super) fn f64p(p: &Value, k: &str) -> Option<f64> {
p.get(k).and_then(Value::as_f64)
}
pub(crate) fn pt(v: &Value) -> Option<Point> {
pub fn pt(v: &Value) -> Option<Point> {
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<Point> {
}
}
pub(crate) fn nums<const N: usize>(p: &Value, k: &str) -> Option<[f64; N]> {
pub fn nums<const N: usize>(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<PathOp> {
pub fn op_from(s: &str) -> Option<PathOp> {
Some(match s.to_ascii_lowercase().as_str() {
"combine" | "add" | "union" => PathOp::Combine,
"subtract" | "minus" => PathOp::Subtract,
@@ -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<Path> {
/// 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<LayerId>) -> Result<&'a mut Path> {
pub fn path_mut<'a>(doc: &'a mut Document, name: &str, layer: Option<LayerId>) -> 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()));
@@ -397,7 +397,7 @@ pub(super) fn shape_info(s: &Session, id: LayerId) -> Result<Value> {
}))
}
pub(crate) fn with_shape<R>(s: &mut Session, id: LayerId, label: &str, f: impl FnOnce(&mut ShapeLayer, &mut Layer) -> Result<R>) -> Result<R> {
pub fn with_shape<R>(s: &mut Session, id: LayerId, label: &str, f: impl FnOnce(&mut ShapeLayer, &mut Layer) -> Result<R>) -> Result<R> {
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<Path> {
pub fn bake_path(path: &Path, tol: f64) -> Result<Path> {
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()));
}
+1 -1
View File
@@ -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 } => {
-16
View File
@@ -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.
+2 -2
View File
@@ -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<String>,
pub coalesce_request: Option<String>,
/// The outer action's original document/history states, independent of command transactions.
action_history: Option<action_history::ActionHistory>,
/// Weak leases expire when every copy of a suspended continuation is abandoned.
-1
View File
@@ -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",
+45
View File
@@ -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 = []
+17
View File
@@ -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;
+84
View File
@@ -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<Result<()>> = 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");
}
}
+35
View File
@@ -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};
+2 -1
View File
@@ -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]
+3
View File
@@ -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;
+3 -2
View File
@@ -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()
+1 -1
View File
@@ -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 == '_'
+1 -1
View File
@@ -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/<area>_cmds.rs`, or `crates/engine-<crate>/src/cmd/<area>_cmds.rs` for a crate cut out of core, such as `engine-paint`) exposing `specs()`, registered by adding `("<module>", crate::<module>::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/<owner>/<menu>.rs` of its crate instead. Fill in:
3. **Command** goes in an engine module (`crates/engine-core/src/<area>_cmds.rs`, or `crates/engine-<crate>/src/cmd/<area>_cmds.rs` for a crate cut out of core, such as `engine-paint` or `engine-vector`) exposing `specs()`, registered by adding `("<module>", crate::<module>::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/<owner>/<menu>.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),
+1 -1
View File
@@ -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"];
+2 -1
View File
@@ -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));