mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 09:54:09 +01:00
Gradient: an aspect for a Live Paint group without faces is an error
A fill edit of a selected Live Paint group with edges and no faces edits no object, yet paint.editGradient accepted an aspect there and returned no ids, and the Aspect Ratio field stayed enabled. - paint.editGradient refuses an aspect when the Live Paint filter leaves no object. Graph design art alone still changes nothing without an error, as for the other params. - Session::gradient_edit_has_objects reads the same filtered targets, so the field is dimmed in that case. - Params text and docs/mcp.md name the case.
This commit is contained in:
1 parent
d5ab3f8654
commit
8d7eaf36bb
3 files changed
+21
-8
No files matched your search
@@ -24,7 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Gradient",
|
||||
["Window", "Gradient"],
|
||||
None,
|
||||
"{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds; an error when no object is edited, as with nothing selected or the Live Paint Bucket's gradient: the default gradient fits each new object and keeps no aspect), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. Without `item`, a Live Paint group's faces take a fill edit and its edges take a stroke edit. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket is the active tool and no ids, id or item are given (a null ids or id counts as none), o
Line truncated
|
||||
"{stroke?: bool (default: the targeted item's kind, else the active proxy), kind?: linear|radial|conic|diamond|freeform (conic, also accepted as angle or conical, sweeps the stops once around the center, clockwise from the vector, with a seam where the last stop meets the first; diamond runs the stops from the center out to a square with a corner at the end of the vector; freeform places points on each object, coloured along the stops), mode?: points|lines (freeform: how the Gradient tool adds points), method?: classic|perceptual|hue-clockwise|hue-counterclockwise (how the colours between the stops mix: in display RGB, perceptually (OKLab) so the steps look even, or around the hue wheel: hue, saturation and brightness each change evenly from one stop to the next, the hue angle falling with hue-clockwise (red, magenta, blue, cyan, green, yellow) and rising with hue-counterclockwise; two stops whose hues are less than half a color level apart keep that hue; a stop whose RGB numbers are less than half a color level apart is gray and takes the hue of the stop it mixes with, and black that stop's saturation too; these two methods are VectorCraft's own, and SVG and PDF exports draw their gradients as RGB images, CMYK and spot color stops included; SVG exports draw a Perceptual gradient as an image, and PDF exports do too unless it is linear, radial, conic or diamond, has spot color stops, every other stop is paper white or written in CMYK or gray (an export that converts colors to a CMYK destination profile writes RGB and Lab stops in CMYK, and so does a CMYK document unless the export converts colors to an RGB destination profile), it is not a dithered fill and its curve does not have too many stops: then PDF writes tints of one spot ink as a Separation shading in that ink, and spot inks mixed with other spot, CMYK or gray inks as a DeviceN shading; freeform gradients mix their own way), spread?: pad|repeat|reflect (linear, radial, conic and diamond: what the gradient paints past the ends of its stops: pad carries the end colors on; repeat and reflect run the stops `repeats` times along the vector (around the circle, for a conic) and on past both ends, reflect mirroring every other run; an error on a freeform gradient), repeats?: 1..100 (a whole number: how many times repeat and reflect run the stops along the vector; VectorCraft's own limit; pad keeps it unused), stops?: [{offset 0..1, color? (needed without swatch; #rrggbbaa and #rgba are refused), opacity? 0..1 (or 0..100), midpoint? 0.13..0.87, swatch?: colour swatch name (a global or spot colour or tint swatch links the stop, so swatch edits recolour it and a spot stop prints on its plate; a process colour just gives its colour), tint?: 0..100 (% of the linked swatch; default 100, or a tint swatch's own)}] (at least 2; a freeform gradient's points are recoloured along them), keepModel?: bool (as paint.setFill; a stop color the gradient already has keeps its model), angle?: deg counter-clockwise (0: the gradient runs left to right; radial, conic and diamond: the vector turns about the center), aspect?: % (radial, conic and diamond; a negative one mirrors a conic's sweep and is an error for the other kinds; an error when no object is edited, as with nothing selected, the Live Paint Bucket's gradient, or a fill edit of a Live Paint group without faces: the default gradient fits each new object and keeps no aspect), reverse?: bool (the same ramp the other way round: the stops in reverse order, and a hue method turned the other way unless `method` is given too), dither?: bool (fills only: a linear, radial, conic or diamond gradient fill is drawn with fine noise that hides banding, and as pixels in SVG and PDF exports), item?: fill/stroke item index|null (omitted: the Appearance panel's active item when it is of the edited kind), aligned?: bool (as paint.setFill; without stroke, the kind of the row edited), ids?|id?, strokeMode?: within|along|across (strokes only: the gradient lies on the page and shows through the stroke, runs from the start of each subpath to its end, or runs from the stroke's left edge to its right all along it; with nothing selected, for the next object drawn; type characters' own strokes always paint within), target?: \"object\"|\"contents\"} edit the gradient in place (keeps its placement); solid/none paints become the default gradient. Without `item`, a Live Paint group's faces take a fill edit and its edges take a stroke edit. On a path directly in a graph series, the graph also stores the gradient when it is on the topmost visible fill or stroke (docs/mcp.md); on a graph label's row, or on a graph's axis line, tick mark or radar ring, the graph stores that object's topmost visible fill and stroke rows for every label or line of its kind (a line's gradient without its placement), and on its characters their gradient without its placement, fitted to each label. While the Live Paint Bucket is the active tool and no ids, id or i
Line truncated
|
||||
has_doc,
|
||||
edit_gradient
|
||||
),
|
||||
@@ -118,13 +118,14 @@ impl StopOwner {
|
||||
|
||||
impl Session {
|
||||
/// Does `paint.editGradient` without `ids` edit objects on the fill (or the stroke, `stroke`)? It does not
|
||||
/// while the Live Paint Bucket is active or when nothing it can paint is selected: it then edits only the
|
||||
/// default gradient, which takes no `aspect`.
|
||||
/// while the Live Paint Bucket is active or when nothing it can paint is selected (a Live Paint group stands
|
||||
/// only for its faces in a fill edit and its edges in a stroke edit): it then edits no object and takes no
|
||||
/// `aspect`.
|
||||
pub fn gradient_edit_has_objects(&self, stroke: bool) -> bool {
|
||||
let p = json!({ "stroke": stroke });
|
||||
!super::paint::for_bucket(self, &p)
|
||||
&& item_target(self, &p, "paint.editGradient")
|
||||
.is_ok_and(|item| item.of_kind(self, !stroke).targets(self, &p).is_ok_and(|ids| !ids.is_empty()))
|
||||
.is_ok_and(|item| item.of_kind(self, !stroke).targets_for(self, &p, !stroke).is_ok_and(|ids| !ids.is_empty()))
|
||||
}
|
||||
|
||||
/// The selected gradient stop (`gradient.selectStop`), while the gradient it was selected on
|
||||
@@ -557,8 +558,10 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// Objects were given or selected, even when all of them are graph design art left out below, or Live Paint group parts
|
||||
// of the other kind left out above: the stroke mode is then not one for new art.
|
||||
let selected = !ids.is_empty() || skipped;
|
||||
// The default gradient for new art (and the bucket's) is fitted to each object, so it has no aspect of its own.
|
||||
if !selected && p.get("aspect").is_some() {
|
||||
// The default gradient for new art (and the bucket's) is fitted to each object, so it has no aspect of its own. A
|
||||
// Live Paint group with no part of the edited kind gives no object either. Graph design art is left out below
|
||||
// without an error, as for every other param.
|
||||
if ids.is_empty() && p.get("aspect").is_some() {
|
||||
return Err(bad(C, "`aspect` needs objects to place the gradient on: give ids or select objects"));
|
||||
}
|
||||
let ids = super::appearance::drop_design_art_rows(s, ids, item, !stroke, C)?;
|
||||
|
||||
@@ -3332,7 +3332,7 @@ fn live_paint_bucket_paint_and_stroke_commands_leave_the_selection_unpainted() {
|
||||
}
|
||||
|
||||
/// `paint.editGradient` with an `aspect` and no object to edit (the Live Paint Bucket's gradient,
|
||||
/// or nothing selected) is an error that leaves the default gradient as it was, since a gradient
|
||||
/// nothing selected, or a fill edit of a Live Paint group without faces) is an error that leaves the default gradient as it was, since a gradient
|
||||
/// fitted to each object has no aspect of its own. Named objects still take the aspect.
|
||||
#[test]
|
||||
fn edit_gradient_aspect_without_objects_is_an_error() {
|
||||
@@ -3376,6 +3376,16 @@ fn edit_gradient_aspect_without_objects_is_an_error() {
|
||||
s.execute("select.set", &json!({"ids": [empty.0]})).unwrap();
|
||||
assert!(!s.gradient_edit_has_objects(false), "an empty group");
|
||||
assert!(s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 50})).is_err());
|
||||
// A fill edit of a Live Paint group with edges and no faces edits no object; a stroke edit edits its edges.
|
||||
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 100, "y2": 0})).unwrap()["id"].as_u64().unwrap());
|
||||
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": [edges_only.0]})).unwrap();
|
||||
let (fill, group, steps) = (s.paint.fill.clone(), node(&s, edges_only), s.doc().unwrap().history.undo.len());
|
||||
assert!(!s.gradient_edit_has_objects(false), "a Live Paint group without faces");
|
||||
assert!(s.gradient_edit_has_objects(true), "its edges take a stroke edit");
|
||||
assert!(s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 50})).is_err());
|
||||
assert_eq!((&s.paint.fill, node(&s, edges_only)), (&fill, group), "the default and the group stay");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "no undo step");
|
||||
// A selected object takes it.
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
assert!(s.gradient_edit_has_objects(false) && s.gradient_edit_has_objects(true));
|
||||
|
||||
+1
-1
@@ -1651,7 +1651,7 @@ for a conic gradient is an error. A negative `aspect` mirrors the sweep (counter
|
||||
does; for the other kinds a negative `aspect` is an error. The Gradient panel's Aspect Ratio field and the aspect dot
|
||||
keep a mirrored sweep mirrored. The default gradient for new art, and the Live Paint Bucket's, fits each object it
|
||||
paints and keeps no aspect, so `paint.editGradient` with an `aspect` is an error when it edits no object (nothing
|
||||
selected, or the bucket's gradient without `ids`) and leaves the default as it was. Dither and Method apply as they do to a linear gradient. PDF export writes it as a
|
||||
selected, the bucket's gradient without `ids`, or a fill edit of a Live Paint group without faces) and leaves the default as it was. Dither and Method apply as they do to a linear gradient. PDF export writes it as a
|
||||
function-based shading (type 1) whose calculator function turns the angle into the ramp, and PDF import reads a
|
||||
function-based shading whose color turns around the origin of its space back as a conic gradient, with its stops'
|
||||
opacity, also when the origin lies outside the painted area; in a PDF/A file, or with more than 97 stops on its
|
||||
|
||||
Reference in new issue
Block a user