test(text): hostile parameters on text paths, embeds and change events; regenerate the command reference (M5)

This commit is contained in:
Tanish Manku committed 2026-11-20 15:07:51 -07:00
1 parent 019a1b1e5a
commit 1a7394def6
5 files changed
+63 -9

No files matched your search

+54
View File
@@ -272,3 +272,57 @@ fn line_breaks_set_further_lines_parallel_to_the_path() {
assert!(t5.on_path.is_none() && t5.text == "First\nFloor" && t5.box_height > lh * 1.8);
}
/// Hostile parameters on the new surfaces (ADR 0107) return errors, never panic, and leave a
/// document that still evaluates and saves.
#[test]
fn hostile_point_edits_embeds_and_change_events_never_panic() {
if !fonts() {
return;
}
let (mut s, text, line) = text_and_line();
run(&mut s, "element.select", json!({"ids": [text.0]}));
run(&mut s, "text.edit", json!({"text": "a\n\n\nb\n".repeat(40)}));
run(&mut s, "element.select", json!({"ids": [text.0, line.0]}));
run(&mut s, "text.attach_path", json!({}));
let id = text.0;
let wild = [json!(null), json!(-1), json!(1e308), json!(u64::MAX), json!("x"), json!([]), json!({}), json!(f64::MIN_POSITIVE)];
let mut tried = 0;
for a in &wild {
for b in &wild {
for p in [
json!({"id": id, "points": [[a, b]], "dx": b, "dy": a}),
json!({"id": id, "points": [[1, 0]], "dx": a, "dy": b}),
json!({"id": id, "points": a, "dx": 1, "dy": 1, "smooth": b}),
] {
let _ = s.execute("path.move_points", &p);
tried += 1;
}
let _ = s.execute("path.add_point", &json!({"id": id, "x": a, "y": b, "slop": a}));
let _ = s.execute("path.delete_points", &json!({"id": id, "cmds": [a, b]}));
let _ = s.execute("path.convert_point", &json!({"id": id, "cmd": a, "smooth": b}));
let _ = s.execute("text.path", &json!({"offset": a, "flip": b}));
let _ = s.execute("text.field", &json!({"embed": a, "type": b}));
let _ = s.execute("actions.set", &json!({"element": id, "event": "change", "actions": a}));
let _ = s.execute("actions.clear", &json!({"element": a, "event": "change"}));
}
}
assert!(tried > 100);
// Far moves that stay in range, a path folded onto itself, many lines: still text on a path.
for (dx, dy) in [(1e5, -1e5), (-1e5, 1e5), (-399.0, 0.0), (0.5, 0.5)] {
let _ = s.execute("path.move_points", &json!({"id": id, "points": [[1, 0]], "dx": dx, "dy": dy}));
}
let (_, t) = text_of(&s, text);
assert!(t.on_path.is_some());
assert!(t.outline.cmds.iter().all(|c| match c {
anicraft_geom::PathCmd::MoveTo(p) | anicraft_geom::PathCmd::LineTo(p) => p.is_finite(),
_ => true,
}));
let saved = crate::format::to_json(&s.doc).unwrap();
assert_eq!(crate::format::from_json(&saved).unwrap(), s.doc);
assert!(anicraft_render::render_frame(&s.doc, 0, 0.25).is_ok());
// Plug-ins may call what artists can: the namespaces already have their policy.
for cmd in ["path.move_points", "text.field", "text.path", "actions.set"] {
let _ = crate::cmds_plugin::plugin_may_call(cmd);
}
}
+1 -1
View File
@@ -362,7 +362,7 @@ fn fields_embed_glyph_outlines_in_the_html_export() {
// The usual case: the outlines are in the page, and the report counts them.
"embedded" => {
let n = rows[0]["glyphs"].as_u64().unwrap();
assert!(n >= 10 && n <= 17, "{v}");
assert!((10..=17).contains(&n), "{v}");
assert!(html.contains("\"fonts\":[{"), "the page carries the face");
assert!(v["notes"].as_object().unwrap().iter().any(|(k, c)| k.starts_with("glyph outlines embedded") && c.as_u64() == Some(n)), "{v}");
assert!(html.len() > before["bytes"].as_u64().unwrap() as usize, "the glyphs add to the page");
+1 -1
View File
@@ -1086,7 +1086,7 @@ fn the_js_player_runs_html_text_change_events_and_limits_like_the_rust_player()
"Script on frame 5 of the main timeline stopped: line 1: the main timeline isn't a text field".to_string(),
"Script on frame 6 of the main timeline stopped: line 1: `htmlText` is set to text, not null".to_string(),
] {
assert!(lines.iter().any(|l| *l == want), "the movie never wrote {want:?}: {lines:#?}");
assert!(lines.contains(&want), "the movie never wrote {want:?}: {lines:#?}");
}
// The hostile markup left nothing behind in what the field reads back.
let html = lines.iter().find(|l| l.starts_with("<p align=\"right\">")).expect("htmlText read back");
+4 -4
View File
@@ -178,7 +178,7 @@ impl Parallel {
/// The distance along the parallel curve under distance `s` along the path (past the
/// path's ends it carries on at the path's own pace).
fn from_path(&self, s: f32) -> f32 {
fn along_at(&self, s: f32) -> f32 {
let n = self.along.len().saturating_sub(1).max(1);
if s <= 0.0 {
return s;
@@ -193,7 +193,7 @@ impl Parallel {
}
/// The distance along the path over distance `t` along the parallel curve (in range).
fn to_path(&self, t: f32) -> f32 {
fn path_at(&self, t: f32) -> f32 {
let n = self.along.len().saturating_sub(1).max(1);
let i = self.along.partition_point(|l| *l <= t).clamp(1, n);
let (a, b) = (self.along.get(i - 1).copied().unwrap_or(0.0), self.along.get(i).copied().unwrap_or(0.0));
@@ -271,7 +271,7 @@ pub fn on_path(glyphs: &[PlacedGlyph], path: &Path, how: PathPlacement) -> Optio
// Where the glyph's middle is along its line, and how long that line is.
let (anchor, total) = match parallel {
None => (offset, length),
Some((_, par)) => (par.from_path(if closed { offset.rem_euclid(length) } else { offset }), par.total()),
Some((_, par)) => (par.along_at(if closed { offset.rem_euclid(length) } else { offset }), par.total()),
};
let mid = anchor - back + g.x + g.advance * 0.5;
// A parallel curve squeezed to (almost) nothing, as at a circle's centre, holds no text.
@@ -290,7 +290,7 @@ pub fn on_path(glyphs: &[PlacedGlyph], path: &Path, how: PathPlacement) -> Optio
let (p, dir) = match parallel {
None => at(t),
Some((d, par)) => {
let (p, dir) = at(par.to_path(t));
let (p, dir) = at(par.path_at(t));
(p + Vec2::new(-dir.y, dir.x) * *d, dir)
}
};
+3 -3
View File
@@ -608,7 +608,7 @@ These commands have no menu item: the panels, the stage and the timeline use the
- **Pencil Stroke** `draw.freehand` · changes the document
Parameters: `{points: [[x, y], ..], mode?: "smooth"|"straighten"|"ink", tolerance? (stage units), closed?, stroke?, stroke_width?, object?}`
- **Move Points** `path.move_points` · changes the document
Parameters: `{id, points: [[cmd, slot], ..], dx, dy, smooth?: bool} (a handle moved alone at a smooth anchor turns the other one with it, keeping its length, unless smooth is false: Alt breaks the pair)`
Parameters: `{id (a shape, or text on a path: the path it follows, ADR 0107), points: [[cmd, slot], ..], dx, dy, smooth?: bool} (a handle moved alone at a smooth anchor turns the other one with it, keeping its length, unless smooth is false: Alt breaks the pair)`
- **Add Anchor Point** `path.add_point` · changes the document
Parameters: `{id, x, y, slop?}`
- **Delete Anchor Points** `path.delete_points` · changes the document
@@ -760,7 +760,7 @@ These commands have no menu item: the panels, the stage and the timeline use the
- **Text on Path** `text.path` · changes the document
Parameters: `{offset? (px along the path), flip?: bool (along the path backwards, on its other side), release?: bool (back to lines of text where it starts)} on the selected text on a path (ADR 0070)`
- **Text Type** `text.field` · changes the document
Parameters: `{type?: static|dynamic|input, lines?: single|multiline|multiline_no_wrap|password (input only), width?, height? (the field's box, px), selectable?, border?, background?, border_color?, background_color?, max_chars? (input; 0: no limit), variable? (kept, not run)} on the selected text; dynamic and input fields are named with instance.set_name and scripted in Test Movie and the HTML export (ADR 0066)`
Parameters: `{type?: static|dynamic|input, lines?: single|multiline|multiline_no_wrap|password (input only), width?, height? (the field's box, px), selectable?, border?, background?, border_color?, background_color?, max_chars? (input; 0: no limit), variable? (kept, not run), embed?: characters whose glyph outlines the HTML export carries for this field's font, so text a script sets is drawn in it where the font's licence allows ("": none; ADR 0107)} on the selected text; dynamic and input fields are named with instance.set_name and scripted in Test Movie and the HTML export (ADR 0066)`
- **Width Profile** `stroke.set_profile` · changes the document
Parameters: `{profile: uniform|taper_both|taper_start|taper_end|bulge|pinch | [[t, left, right], ..], id? (default: the selected shapes)}`
- **Width** `stroke.set_width_point` · changes the document
@@ -798,7 +798,7 @@ These commands have no menu item: the panels, the stage and the timeline use the
- **Reference Video** `layer.set_video` · changes the document
Parameters: `{layer?, path? (relink: another file, or the same one where it moved), start? (the timeline frame, from 0, where the video begins), offset? (seconds into the video shown there), remove? (true: the layer keeps its artwork and loses the video), ffmpeg?} changes a layer's reference video (ADR 0116) → {layer, video}`
- **Set Actions** `actions.set` · changes the document
Parameters: `{actions: [{op: stop|play|goto_and_play|goto_and_stop|next_frame|prev_frame|next_scene|prev_scene|trace|set_property, target?, frame?, scene?, message?, property?, value?}] | plugin: id, entry?, symbol?: id (a movie clip's timeline), layer?, frame?} sets what the keyframe at the frame runs; or {element, event: click|press|release|over|out, actions} sets an instance's event handler. An empty list clears it`
Parameters: `{actions: [{op: stop|play|goto_and_play|goto_and_stop|next_frame|prev_frame|next_scene|prev_scene|trace|set_property, target?, frame?, scene?, message?, property?, value?}] | plugin: id, entry?, symbol?: id (a movie clip's timeline), layer?, frame?} sets what the keyframe at the frame runs; or {element, event: click|press|release|over|out, actions} (or event: change on an input text field: what it does when the viewer changes its text, ADR 0107) sets an instance's event handler. An empty list clears it`
- **Clear Actions** `actions.clear` · changes the document
Parameters: `{symbol?, layer?, frame?} clears the keyframe's actions; {element, event?} clears an instance's handlers (one event, or all)`
- **List Actions** `actions.list`