mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 23:58:03 +00:00
Expand: type reports a gradient only when Fill expands one of its outlines
object.expand.info reported a gradient (and a fill) to expand for any type whose characters have a gradient fill. Expand outlines type first, and each outline then holds the run's gradient on its own box, so a gradient that repeats or reflects in more than 256 runs across every outline stays a gradient: the dialog enabled options that changed nothing. - The query now measures the paths type.createOutlines makes of the glyphs, ruby glyphs and underline and strikethrough bars, each with its run's paint, and reports a gradient when one of them expands. It lays the text out only when a run has a gradient fill, stops at the first outline that expands, and does not change the document. Type in symbol art, blends and repeats goes through the same check. - docs/mcp.md says when gradient is false; docs/target-app-parity.md gets an evidence line.
This commit is contained in:
@@ -629,6 +629,89 @@ fn a_spread_gradient_with_more_runs_than_written_stays_a_gradient() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selected type "Hi" at 48 pt, its characters filled with a gradient that repeats 100 times along
|
||||
/// a vector `len` pt long.
|
||||
fn spread_gradient_type(s: &mut Session, len: f64) -> u64 {
|
||||
let t = run(s, "text.create", json!({"x": 50, "y": 100, "text": "Hi", "size": 48}))["id"].as_u64().unwrap();
|
||||
run(s, "select.set", json!({"ids": [t]}));
|
||||
run(
|
||||
s,
|
||||
"paint.setFill",
|
||||
json!({"gradient": {"kind": "linear", "spread": "repeat", "repeats": 100, "start": [50, 100], "end": [50.0 + len, 100],
|
||||
"stops": [{"offset": 0, "color": "#ffff00"}, {"offset": 1, "color": "#004080"}]}}),
|
||||
);
|
||||
t
|
||||
}
|
||||
|
||||
/// How many objects in the document have a gradient fill, and how many are type.
|
||||
fn gradients_and_type(s: &Session) -> (usize, usize) {
|
||||
let (mut gradients, mut texts) = (0, 0);
|
||||
s.doc().unwrap().doc.walk(|n| {
|
||||
gradients += usize::from(matches!(n.appearance.fill_paint(), Paint::Gradient(_)));
|
||||
texts += usize::from(matches!(n.kind, NodeKind::Text(_)));
|
||||
});
|
||||
(gradients, texts)
|
||||
}
|
||||
|
||||
/// Type is outlined before its fills expand, and each glyph's gradient fits that glyph's own box:
|
||||
/// `object.expand.info` reports a gradient (and a fill) only when a glyph's box needs no more runs
|
||||
/// than are written, so Expand turns it into art. Both Expand Gradient To options leave the
|
||||
/// glyphs whose gradient needs more runs with their gradient, and Object still outlines the type.
|
||||
/// The query leaves the document and its history as they are.
|
||||
#[test]
|
||||
fn type_whose_gradient_needs_more_runs_than_written_reports_no_gradient() {
|
||||
// 0.2 pt runs (100 repeats over 20 pt) across glyphs about 30 pt wide: under the limit.
|
||||
// 0.02 pt runs (over 2 pt): far over it.
|
||||
for (len, expands) in [(20.0, true), (2.0, false)] {
|
||||
let mut s = session();
|
||||
spread_gradient_type(&mut s, len);
|
||||
let before = (s.doc().unwrap().revision, s.doc().unwrap().history.undo.len(), s.doc().unwrap().doc.layers.clone());
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!((info["gradient"].clone(), info["fill"].clone(), info["object"].clone()), (json!(expands), json!(expands), json!(true)), "{len}");
|
||||
assert!(
|
||||
before == (s.doc().unwrap().revision, s.doc().unwrap().history.undo.len(), s.doc().unwrap().doc.layers.clone()),
|
||||
"{len}: the query changed the document"
|
||||
);
|
||||
for to in [json!({}), json!({"gradient": "mesh"})] {
|
||||
let mut s = session();
|
||||
spread_gradient_type(&mut s, len);
|
||||
run(&mut s, "object.expand", to.clone());
|
||||
let (gradients, texts) = gradients_and_type(&s);
|
||||
assert_eq!(texts, 0, "{len} {to}: outlined");
|
||||
assert_eq!(gradients == 0, expands, "{len} {to}: {gradients} gradient fills left");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One glyph whose box needs more runs than are written does not hide another that Expand turns
|
||||
/// into art: the 200 pt "H" keeps its gradient, the 48 pt "i" expands, and the query reports it.
|
||||
#[test]
|
||||
fn type_reports_a_gradient_when_any_glyph_expands() {
|
||||
let mut s = session();
|
||||
let t = spread_gradient_type(&mut s, 20.0);
|
||||
run(&mut s, "text.setRangeStyle", json!({"id": t, "start": 0, "end": 1, "size": 200}));
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!((info["gradient"].clone(), info["fill"].clone()), (json!(true), json!(true)));
|
||||
run(&mut s, "object.expand", json!({}));
|
||||
assert_eq!(gradients_and_type(&s), (1, 0), "the large glyph keeps its gradient");
|
||||
}
|
||||
|
||||
/// The same rule for type in the art of a symbol instance that Object expands. The symbol's art
|
||||
/// is the type scaled down (its "i" about 2.5 pt wide), so its glyphs need more runs than are
|
||||
/// written with 0.002 pt runs (over a 0.2 pt vector).
|
||||
#[test]
|
||||
fn type_in_symbol_art_reports_a_gradient_only_when_it_expands() {
|
||||
for (len, expands) in [(20.0, true), (0.2, false)] {
|
||||
let mut s = session();
|
||||
spread_gradient_type(&mut s, len);
|
||||
let inst = run(&mut s, "symbol.new", json!({"name": "Hi"}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [inst]}));
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!(info["gradient"], json!(expands), "{len}");
|
||||
assert_eq!((info["symbolArt"]["gradient"].clone(), info["symbolArt"]["fill"].clone()), (json!(expands), json!(expands)), "{len}: {info}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_mesh_option_makes_a_mesh_that_paints_the_gradient() {
|
||||
for gradient in [
|
||||
|
||||
Reference in New Issue
Block a user