mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
crates/engine keeps the package photocraft-engine: src/facade.rs re-exports photocraft-engine-core, and its Session wraps core's and installs every engine command. Core's Session::new() installs nothing; core gets install() and session(). The command registry keeps main's behaviour (empty before an install). The top crate's dev-dependencies cover tests/ and examples/, including craft-develop-model (camera raw baseline test) and photocraft-testkit (the corpus-gated Photoshop oracle test). Dependents that need the core type or borrowed two fields through the wrapper are fixed at the call site, and tests that reach the registry before any session install first. Tooling follows the package: workspace dependency, cl selection, xtask layers, i18n report, scorecard and corpus paths, nextest overrides, ci-test-times rows, display-names roots, prefs_usage paths, the engine split scripts, docs, and the two release-perf steps in ci.yml. Corpus .atn paths, the layer_menu registry read and the craft-develop-model dev-dependency are FredApps' fixes from #16431. Part of #15710
218 lines
6.6 KiB
Rust
218 lines
6.6 KiB
Rust
//! The engine's commands and the helpers they share. Ids follow Photoshop's menu structure (see
|
|
//! the parity checklist).
|
|
|
|
use photocraft_color::{Color, ColorMode, SampleType};
|
|
use photocraft_doc::{Adjustment, Document, Fill, Layer, LayerContent, LayerId, LayerMask, Size};
|
|
use photocraft_geom::{Rect, TILE_SIZE};
|
|
use photocraft_raster::Surface;
|
|
use serde_json::{Value, json};
|
|
|
|
use crate::{EngineError, Result, Session, inspect, pixels};
|
|
|
|
macro_rules! cmd {
|
|
($id:literal, $label:literal, [$($m:literal),*], $sc:expr, $params:literal, $en:expr, $run:expr) => {
|
|
CommandSpec { id: $id, label: $label, menu: &[$($m),*], shortcut: $sc, params: $params, enabled: $en, run: $run, journal: true }
|
|
};
|
|
}
|
|
|
|
pub mod actions_cmds;
|
|
pub mod actions_edit_cmds;
|
|
pub mod adjust_cmds;
|
|
mod adjust_params;
|
|
pub mod adjustment_brush_cmds;
|
|
#[cfg(test)]
|
|
mod adjustment_brush_cmds_tests;
|
|
pub mod align_cmds;
|
|
pub mod analysis_cmds;
|
|
pub mod artboard_cmds;
|
|
pub mod atn_cmds;
|
|
pub mod automate_cmds;
|
|
pub mod background_cmds;
|
|
pub mod brush_cmds;
|
|
pub mod brush_key_cmds;
|
|
pub mod brush_preset_cmds;
|
|
pub mod channel_cmds;
|
|
pub mod color_cmds;
|
|
pub mod color_to_alpha_cmds;
|
|
pub mod comps_cmds;
|
|
pub mod contour_lib_cmds;
|
|
#[cfg(test)]
|
|
mod count_delete_group_tests;
|
|
#[cfg(test)]
|
|
mod count_history_names_tests;
|
|
#[cfg(test)]
|
|
mod count_record_label_tests;
|
|
#[cfg(test)]
|
|
mod count_resize_tests;
|
|
pub mod cutout_cmds;
|
|
pub mod distort_cmds;
|
|
pub mod document_preset_cmds;
|
|
pub mod edit_cmds;
|
|
pub mod edit_menu_cmds;
|
|
mod enabled;
|
|
pub mod eraser_cmds;
|
|
pub mod export_preset_cmds;
|
|
pub mod exr_cmds;
|
|
pub mod extra_cmds;
|
|
pub mod face_cmds;
|
|
pub mod file_cmds;
|
|
pub mod fill_cmds;
|
|
pub mod fill_key_cmds;
|
|
pub mod float_cmds;
|
|
pub mod font_library_cmds;
|
|
pub mod frame_cmds;
|
|
pub mod fx_view_cmds;
|
|
pub mod fx_visibility_cmds;
|
|
pub mod gallery_cmds;
|
|
#[cfg(test)]
|
|
mod gradient_alpha_method_tests;
|
|
pub mod gradient_fill_cmds;
|
|
pub mod group_view_cmds;
|
|
pub mod history_cmds;
|
|
pub mod history_menu_cmds;
|
|
pub mod history_options_cmds;
|
|
pub mod history_select_cmds;
|
|
pub mod history_source_cmds;
|
|
pub mod image_cmds;
|
|
pub mod layer_copy_cmds;
|
|
pub mod layer_css_cmds;
|
|
#[cfg(test)]
|
|
mod layer_from_background_name_tests;
|
|
pub mod layer_label_cmds;
|
|
pub mod layer_list_cmds;
|
|
pub mod layer_mask_props_cmds;
|
|
pub mod layer_menu_cmds;
|
|
pub mod layer_multi_cmds;
|
|
pub mod layer_nav_cmds;
|
|
mod layer_params;
|
|
mod layer_references;
|
|
pub mod layer_xmp_cmds;
|
|
pub mod lens_cmds;
|
|
pub mod magnetic_cmds;
|
|
pub mod mask_view_cmds;
|
|
pub mod migrate_cmds;
|
|
pub mod mode_cmds;
|
|
pub mod multichannel_cmds;
|
|
#[cfg(test)]
|
|
mod new_document_history_name_tests;
|
|
pub mod notes_cmds;
|
|
#[cfg(test)]
|
|
mod notes_stored_values_tests;
|
|
mod ops;
|
|
pub mod paint_cmds;
|
|
mod params;
|
|
pub mod path_edit_cmds;
|
|
pub mod pattern_cmds;
|
|
pub mod pattern_fill_cmds;
|
|
pub mod perspective_crop_cmds;
|
|
#[cfg(test)]
|
|
mod perspective_crop_refuse_tests;
|
|
pub mod photo_cmds;
|
|
pub mod pick_cmds;
|
|
pub mod plugin_cmds;
|
|
pub mod preset_import_cmds;
|
|
pub mod print_cmds;
|
|
pub mod rasterize_style_cmds;
|
|
pub mod redeye_cmds;
|
|
pub mod render_cmds;
|
|
pub mod retouch_cmds;
|
|
#[cfg(test)]
|
|
mod rotate_canvas_bitmap_tests;
|
|
|
|
#[cfg(test)]
|
|
mod rotate_canvas_guides_tests;
|
|
pub mod sample_cmds;
|
|
#[cfg(test)]
|
|
mod sample_zoom_box_tests;
|
|
pub mod sampler_cmds;
|
|
pub mod select_extra_cmds;
|
|
pub mod selection_cmds;
|
|
pub mod slice_cmds;
|
|
pub mod smart_cmds;
|
|
pub mod smart_svg_cmds;
|
|
pub mod smartselect_cmds;
|
|
pub mod solid_fill_cmds;
|
|
pub mod stamp_cmds;
|
|
pub mod style_asl_cmds;
|
|
pub mod swatch_cmds;
|
|
pub mod symmetry_cmds;
|
|
pub mod table;
|
|
pub mod timeline_cmds;
|
|
pub mod transform_cmds;
|
|
pub mod trap_cmds;
|
|
pub mod type_area_cmds;
|
|
pub mod type_caret_cmds;
|
|
pub mod type_cmds;
|
|
pub mod type_extra_cmds;
|
|
#[cfg(test)]
|
|
mod type_indexed_mode_tests;
|
|
pub mod type_mask_cmds;
|
|
pub mod type_spell_cmds;
|
|
pub mod type_styles_cmds;
|
|
pub mod variables_cmds;
|
|
mod vector_clipboard;
|
|
pub mod vector_cmds;
|
|
pub mod video_cmds;
|
|
pub mod vp_cmds;
|
|
pub mod warp_cmds;
|
|
pub mod web_cmds;
|
|
pub mod wia_cmds;
|
|
|
|
pub(crate) use adjust_params::inject_kind;
|
|
use adjust_params::{adjust_mode, destructive_adjust, doc_mode, new_adjustment};
|
|
pub use adjust_params::{adjustment_from_params, adjustment_kind};
|
|
pub(crate) use enabled::{always, check_all_unlocked, check_pixels_unlocked, has_paintable, is_mask_target, paint_surface};
|
|
use enabled::{can_redo, can_undo, has_doc, has_layer, has_pixel_or_channel, has_selection};
|
|
pub(crate) use layer_params::{NEW_LAYER_PATH, explicit_layer, layer_listing, layer_panel_option, layer_param, mask_at_depth, mask_new_layer, selection_mask};
|
|
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};
|
|
use params::{bad, set_clipped};
|
|
pub(crate) use params::{check_f32_values, cmyk_param, color_param, int, int_i32, parse_hex, u32_id, u32_id_param};
|
|
pub use photocraft_color::blend::parse_blend;
|
|
|
|
pub use crate::registry::{CommandSpec, list_entry, list_entry_matches, search_keywords};
|
|
pub use crate::registry::{command_specs, find};
|
|
|
|
#[cfg(test)]
|
|
mod set_props_tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn opacity_and_fill_outside_zero_to_one_are_refused_not_clamped() {
|
|
// #5242: `55` (a percentage, as the Layer Style commands take) used to become 100 %.
|
|
let mut s = crate::session();
|
|
s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
|
|
s.execute("layer.new.layer", json!({})).unwrap();
|
|
s.execute("layer.setProps", json!({"opacity": 0.55, "fill": 0.4})).unwrap();
|
|
let layer = |s: &Session| {
|
|
let d = s.active().unwrap();
|
|
let l = d.doc.layer(d.active_layer.unwrap()).unwrap();
|
|
(l.opacity, l.fill_opacity)
|
|
};
|
|
assert_eq!(layer(&s), (0.55, 0.4));
|
|
for bad in [json!({"opacity": 55}), json!({"opacity": -0.1}), json!({"fill": 1.5}), json!({"opacity": "50%"}), json!({"opacity": 0.5, "fill": 40})] {
|
|
let e = s.execute("layer.setProps", bad.clone()).unwrap_err().to_string();
|
|
assert!(e.contains("0..1"), "{bad}: {e}");
|
|
assert_eq!(layer(&s), (0.55, 0.4), "{bad} left the layer alone");
|
|
}
|
|
s.execute("layer.setProps", json!({"opacity": 0, "fill": 1})).unwrap();
|
|
assert_eq!(layer(&s), (0.0, 1.0));
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod parse_hex_tests {
|
|
use super::parse_hex;
|
|
|
|
#[test]
|
|
fn signs_and_other_non_hex_characters_are_rejected() {
|
|
for bad in ["#+f+f+f", "+f+f+f+f", "#-f0000", "#gg0000", "#0f0f+f"] {
|
|
assert_eq!(parse_hex(bad), None, "{bad:?} is not hex digits");
|
|
}
|
|
let g = 15.0 / 255.0;
|
|
assert_eq!(parse_hex("#0f0f0f"), Some([g, g, g, 1.0]));
|
|
assert_eq!(parse_hex("#0f0f0fff"), Some([g, g, g, 1.0]));
|
|
}
|
|
}
|