mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Plug-ins: returned Curves points take pairs, Transform counts whole numbers
A returned Curves effect's `points` is now also taken as [[x, y], ...], the form the effect draws, each entry a pair of numbers. A returned Transform effect's `copies` and `reference` must be whole numbers; 1.5 copies drew one copy before.
This commit is contained in:
1 parent
1e644a8251
commit
ff68f3553c
3 files changed
+27
-7
No files matched your search
@@ -155,9 +155,12 @@ pub fn check_returned_effect(e: &Effect, row: bool) -> Result<(), String> {
|
||||
let kind = |v: &Value| std::mem::discriminant(v);
|
||||
// A `color` is checked as a color, in any form the effect draws ([`is_color`]).
|
||||
let color = key == "color" && default.is_some_and(Value::is_string);
|
||||
// Curves' `points` is also taken as [[x, y], …], as the effect draws it.
|
||||
let curve = e.id == "adjust.curves" && key == "points" && v.is_array();
|
||||
if let Some(d) = default
|
||||
&& !d.is_null()
|
||||
&& !color
|
||||
&& !curve
|
||||
&& kind(d) != kind(v)
|
||||
{
|
||||
return Err(format!("`{key}` must be of the type its default {d} has"));
|
||||
@@ -184,7 +187,8 @@ pub fn check_returned_effect(e: &Effect, row: bool) -> Result<(), String> {
|
||||
|
||||
/// The values in `given`, the parameters of built-in effect `id` that a painted live-effect plug-in
|
||||
/// returned, that are checked further: an SVG filter's XML, `scale`, `origin`, `axes` and
|
||||
/// `name`; a Free Distort's four `corners`; a Warp's `version`; a `color` the effect can draw; a
|
||||
/// `name`; a Free Distort's four `corners`; Curves' `points` as pairs; a Transform's whole
|
||||
/// `copies` and `reference`; a Warp's `version`; a `color` the effect can draw; a
|
||||
/// shadow's or glow's blend `mode`; a Levels or Curves `channel`; a Radial
|
||||
/// Blur's center; and the type of each parameter without a default.
|
||||
fn check_returned_values(id: &str, given: &Map<String, Value>) -> Result<(), String> {
|
||||
@@ -214,6 +218,14 @@ fn check_returned_values(id: &str, given: &Map<String, Value>) -> Result<(), Str
|
||||
if id == "distort.freeDistort" && given.get("corners").is_some_and(|c| !c.as_array().is_some_and(|c| c.len() == 4 && c.iter().all(pair))) {
|
||||
return Err("`corners` must be four [x, y] pairs of numbers".into());
|
||||
}
|
||||
if id == "adjust.curves" && given.get("points").and_then(Value::as_array).is_some_and(|p| !p.iter().all(pair)) {
|
||||
return Err("`points` must be \"x,y x,y …\" or [[x, y], …] pairs of numbers".into());
|
||||
}
|
||||
if id == "distort.transform"
|
||||
&& let Some(key) = ["copies", "reference"].into_iter().find(|k| given.get(*k).and_then(Value::as_f64).is_some_and(|x| x.fract() != 0.0))
|
||||
{
|
||||
return Err(format!("`{key}` must be a whole number"));
|
||||
}
|
||||
if id.starts_with("warp.") && given.get("version").is_some_and(|v| crate::warp_version(v).is_none()) {
|
||||
return Err(format!("`version` must be 0 or {}", crate::WARP_NET));
|
||||
}
|
||||
|
||||
@@ -300,6 +300,9 @@ fn returned_effects_are_built_in_effects_with_their_own_parameters() {
|
||||
("stylize.outerGlow", json!({"color": {"model": "gray", "k": 0.5}})),
|
||||
("stylize.innerGlow", json!({"color": {"model": "cmyk", "c": 0, "m": 1, "y": 0, "k": 0}})),
|
||||
("stylize.innerGlow", json!({"color": {"model": "lab", "l": 100, "a": -128, "b": 127}})),
|
||||
// Curves' `points` is also taken as [[x, y], …], and a Transform's whole numbers as such.
|
||||
("adjust.curves", json!({"points": [[0, 255], [255, 0]]})),
|
||||
("distort.transform", json!({"copies": 2, "reference": 0.0})),
|
||||
] {
|
||||
assert_eq!(check(&e(id, params.clone()), false), Ok(()), "{id} {params}");
|
||||
}
|
||||
@@ -343,6 +346,10 @@ fn returned_effects_are_built_in_effects_with_their_own_parameters() {
|
||||
("stylize.outerGlow", json!({"color": {"model": "rgb", "r": 2.0, "g": 0.0, "b": 0.0}}), "color"),
|
||||
("stylize.innerGlow", json!({"color": {"model": "gray", "k": -0.5}}), "color"),
|
||||
("stylize.innerGlow", json!({"color": {"model": "lab", "l": 101, "a": 0, "b": 0}}), "color"),
|
||||
("adjust.curves", json!({"points": [[0, 255], [255]]}), "points"),
|
||||
("adjust.curves", json!({"points": ["0,0", "255,255"]}), "points"),
|
||||
("distort.transform", json!({"copies": 1.5}), "copies"),
|
||||
("distort.transform", json!({"reference": 4.5}), "reference"),
|
||||
("adjust.levels", json!({"channel": "cyan"}), "channel"),
|
||||
("blur.radial", json!({"centerX": 1.5}), "centerX"),
|
||||
("blur.gaussian", json!({"linear": 1}), "linear"),
|
||||
|
||||
+7
-6
@@ -876,12 +876,13 @@ fill and stroke the piece returns, three more keys:
|
||||
- An effect record names a built-in effect that `effect.list` lists, other than a 3D effect or a Pathfinder effect
|
||||
(`pathfinder.*`, which has nothing to combine on a piece's one path), with parameters that effect takes, each of the
|
||||
type of its default, within the range `effect.list` gives for it, where it gives one, and one of the choices it
|
||||
lists for it, where it lists them (Roughen's `points` is `"smooth"` or `"corner"`). The values `effect.apply`
|
||||
checks for one effect are checked the same way: an SVG filter's `xml`, `scale`, `origin`, `axes` and `name`, a
|
||||
Warp's `version`, a `color` (`"#rrggbb"`, `[r, g, b]` with each component from 0 to 1, or a color object with
|
||||
components from 0 to 1 and a Lab lightness from 0 to 100), a Levels or Curves `channel` and a Radial Blur's center. A Drop Shadow's, Inner
|
||||
Glow's or Outer Glow's `mode` must name a blend mode (`"multiply"`, `"color-burn"`). Omitted parameters take the
|
||||
effect's defaults. On a fill or stroke only raster effects are taken, and only from an effect in the object's stack:
|
||||
lists for it, where it lists them (Roughen's `points` is `"smooth"` or `"corner"`). Curves' `points` may also be
|
||||
`[[x, y], …]`, each a pair of numbers, and a Transform's `copies` and `reference` are whole numbers. The values
|
||||
`effect.apply` checks for one effect are checked the same way: an SVG filter's `xml`, `scale`, `origin`, `axes` and
|
||||
`name`, a Warp's `version`, a `color` (`"#rrggbb"`, `[r, g, b]` with each component from 0 to 1, or a color object
|
||||
with components from 0 to 1 and a Lab lightness from 0 to 100), a Levels or Curves `channel` and a Radial Blur's
|
||||
center. A Drop Shadow's, Inner Glow's or Outer Glow's `mode` must name a blend mode (`"multiply"`, `"color-burn"`).
|
||||
Omitted parameters take the effect's defaults. On a fill or stroke only raster effects are taken, and only from an effect in the object's stack:
|
||||
the fills or strokes that an effect on a fill or a stroke returns take `opacity` and `blend` but no `effects` (its
|
||||
pieces still take them). A plug-in effect (`plugin.<id>`), this effect's own included, is refused, so the effects a
|
||||
piece carries never run a plug-in.
|
||||
|
||||
Reference in new issue
Block a user