Merge remote-tracking branch 'upstream/main' into footage-cache-3271

# Conflicts:
#	crates/effects/src/lib.rs
This commit is contained in:
vangel76 committed 2026-11-08 16:16:21 +01:00
commit cbaa68321c
48 files changed
+1816 -99

No files matched your search

+12 -4
View File
@@ -49,7 +49,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Text",
["Layer", "New"],
Some("Cmd+Alt+Shift+T"),
"{text?, name? (layer name; default the text), position? [x,y], box? [x,y,w,h] (paragraph text, comp space), vertical?, edit? (start editing), font?, style?, size?, fill?, stroke?, applyFill?, applyStroke?, strokeWidth?, tracking?, leading?, baselineShift?, hScale?, vScale?, tsume?, fauxBold?, fauxItalic?, allCaps?, smallCaps?, baseline?, superscript?, subscript?, kerning?, ligatures?, justify?, indentLeft?, indentRight?, indentFirst?, spaceBefore?, spaceAfter?, direction?, composer?, hangingPunctuation?, strokeOverFill?, lineJoin?} (attributes as layer.setText)",
"{text?, name? (layer name; default the text, which the name then follows; a given name stays), position? [x,y], box? [x,y,w,h] (paragraph text, comp space), vertical?, edit? (start editing), font?, style?, size?, fill?, stroke?, applyFill?, applyStroke?, strokeWidth?, tracking?, leading?, baselineShift?, hScale?, vScale?, tsume?, fauxBold?, fauxItalic?, allCaps?, smallCaps?, baseline?, superscript?, subscript?, kerning?, ligatures?, justify?, indentLeft?, indentRight?, indentFirst?, spaceBefore?, spaceAfter?, direction?, composer?, hangingPunctuation?, strokeOverFill?, lineJoin?} (attributes as layer.setText)",
has_comp,
new_text
),
@@ -70,7 +70,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Layer Settings...",
["Layer"],
Some("Cmd+Shift+Y"),
"{layer?, name?, color?, width?, height?, pixelAspect?, affectAll?: bool (default true; false gives this layer its own copy of a solid other layers use)} → {layer, solid?}",
"{layer?, name? (an empty name makes a text layer's name follow its text again), color?, width?, height?, pixelAspect?, affectAll?: bool (default true; false gives this layer its own copy of a solid other layers use)} → {layer, solid?}",
has_layer_settings,
layer_settings
),
@@ -114,7 +114,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_layers,
set_switch
),
cmd!("layer.rename", "Rename", [], Some("Enter"), "{layer?, name}", has_layers, rename),
cmd!(
"layer.rename",
"Rename",
[],
Some("Enter"),
"{layer?, name} — a text layer's name follows its text until renamed; an empty name follows it again",
has_layers,
rename
),
cmd!("layer.setComment", "Layer Comment", [], None, "{layers?, comment}", has_layers, set_comment),
cmd!("layer.setBlendMode", "Blending Mode", [], None, "{layers?, mode?: Normal|Multiply|Screen|…, step?: ±1}", has_layers, blend),
cmd!(
@@ -210,7 +218,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Edit Text",
[],
None,
"{layer?, range?: [start, end] (characters; default all), text?, font?, style?, size?, fill?, stroke?, applyFill?, applyStroke?, strokeWidth?, tracking?, leading?: px|\"auto\", baselineShift? px, hScale? %, vScale? %, tsume? %, fauxBold?, fauxItalic?, allCaps?, smallCaps?, baseline?: normal|superscript|subscript, superscript?, subscript?, kerning?: metrics|optical|number, ligatures?, discretionaryLigatures? (OpenType), contextualAlternates?, stylisticAlternates?, stylisticSets?: [1–20], ss01?, ss02?, ss03?, ss04?, ss05?, ss06?, ss07?, ss08?, ss09?, ss10?, ss11?, ss12?, ss13?, ss14?, ss15?, ss16?, ss17?, ss18?, ss19?, ss20?, swash?, titling?, ordinals?, fractions?, allSmallCaps?, figureStyle?: default|lining|oldStyle, figureWidth?: default|proportional|tabular, figures?, variations?: {tag: value} (variable font axes; null resets), justify?: left|center|right|justifyLeft|justifyCenter|justifyRight|justifyAll, indentLeft?, indentRight?, indentFirst?, spaceBefore?, spaceAfter?, direction?: ltr|rtl, composer?: everyLine|singleLine, hangingPunctuation?, strokeOverFill?, lineJoin?: miter|round|bevel, box?: [x,y,w,h]|null (layer space), vertical?}",
"{layer?, range?: [start, end] (characters; default all), text? (also renames a text layer whose name still follows its text), font?, style?, size?, fill?, stroke?, applyFill?, applyStroke?, strokeWidth?, tracking?, leading?: px|\"auto\", baselineShift? px, hScale? %, vScale? %, tsume? %, fauxBold?, fauxItalic?, allCaps?, smallCaps?, baseline?: normal|superscript|subscript, superscript?, subscript?, kerning?: metrics|optical|number, ligatures?, discretionaryLigatures? (OpenType), contextualAlternates?, stylisticAlternates?, stylisticSets?: [1–20], ss01?, ss02?, ss03?, ss04?, ss05?, ss06?, ss07?, ss08?, ss09?, ss10?, ss11?, ss12?, ss13?, ss14?, ss15?, ss16?, ss17?, ss18?, ss19?, ss20?, swash?, titling?, ordinals?, fractions?, allSmallCaps?, figureStyle?: default|lining|oldStyle, figureWidth?: default|proportional|tabular, figures?, variations?: {tag: value} (variable font axes; null resets), justify?: left|center|right|justifyLeft|justifyCenter|justifyRight|justifyAll, indentLeft?, indentRight?, indentFirst?, spaceBefore?, spaceAfter?, direction?: ltr|rtl, composer?: everyLine|singleLine, hangingPunctuation?, strokeOverFill?, lineJoin?: miter|round|bevel, box?: [x,y,w,h]|null (layer space), vertical?}",
has_layers,
set_text
),
+6 -6
View File
@@ -207,14 +207,14 @@ pub(super) fn set_text(s: &mut Session, p: &Value) -> Result<Value> {
KV::Str(t) => TextDoc::plain(&t),
_ => TextDoc::default(),
};
let before = effectcraft_project::text_layer_name(&doc.text);
apply_text_params("layer.setText", p, &mut doc, range.clone())?;
pr.set_value_at(lt, KV::Text(Box::new(doc.clone())));
if let Some(first) = doc.text.lines().next()
&& str_p(p, "text").is_some()
&& !first.is_empty()
&& (l.name.starts_with("Text") || l.name.is_empty())
{
l.name = first.chars().take(40).collect();
// Text layers are named after their text until renamed (#3233).
let after = effectcraft_project::text_layer_name(&doc.text);
if str_p(p, "text").is_some() && !after.is_empty() && l.name_follows_text(&before) {
l.name = after;
l.name_follows_text = Some(true);
}
Ok(())
})?;
+3 -1
View File
@@ -187,8 +187,10 @@ pub(super) fn new_text(s: &mut Session, p: &Value) -> Result<Value> {
}
let edit = b_p(p, "edit").unwrap_or(false);
let id = s.edit("New Text Layer", None, |proj, st| {
let name: String = layer_name.clone().unwrap_or_else(|| doc.text.lines().next().unwrap_or("").chars().take(40).collect());
let name: String = layer_name.clone().unwrap_or_else(|| effectcraft_project::text_layer_name(&doc.text));
let mut l = build::layer(proj, &comp, if name.is_empty() { "Text" } else { &name }, LayerSource::Text, (comp.width, comp.height), None);
// Named after its text, the name follows the text until renamed; a given name does not.
l.name_follows_text = Some(layer_name.as_deref().is_none_or(str::is_empty));
if let Some(pr) = l.props.prop_mut("text/sourceText") {
pr.value = KV::Text(Box::new(doc.clone()));
}
+25 -1
View File
@@ -139,13 +139,37 @@ fn drop_3d_values(l: &mut Layer) {
pub(super) fn rename(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, lid) = layer_p(s, p, "layer.rename")?;
let name = str_p(p, "name").ok_or_else(|| bad("layer.rename", "missing `name`"))?.to_string();
let t = s.time();
s.edit("Rename Layer", None, |proj, _| {
layer_mut(proj, cid, lid)?.name = name.clone();
set_layer_name(layer_mut(proj, cid, lid)?, &name, t);
Ok(())
})?;
Ok(Value::Null)
}
/// Give layer `l` the name `name` the user typed (comp time `t` picks the text). A text layer's
/// name follows its text until the user renames it; an empty name makes it follow the text again
/// (After Effects, #3233). Committing the unchanged name changes nothing.
pub(super) fn set_layer_name(l: &mut Layer, name: &str, t: effectcraft_time::Tick) {
let text_name =
l.props.prop("text/sourceText").filter(|_| matches!(l.source, effectcraft_project::LayerSource::Text)).map(|pr| match pr.value_at(l.layer_time(t)) {
KV::Text(d) => effectcraft_project::text_layer_name(&d.text),
KV::Str(txt) => effectcraft_project::text_layer_name(&txt),
_ => String::new(),
});
match text_name {
Some(first) if name.trim().is_empty() => {
l.name = if first.is_empty() { "Text".to_string() } else { first };
l.name_follows_text = Some(true);
}
Some(_) if name != l.name => {
l.name = name.to_string();
l.name_follows_text = Some(false);
}
_ => l.name = name.to_string(),
}
}
/// The Timeline's Comment column.
pub(super) fn set_comment(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, ids) = layers_p(s, p)?;
+9 -2
View File
@@ -157,7 +157,7 @@ pub(super) fn transform_op(s: &mut Session, p: &Value) -> Result<Value> {
/// layers, which are solids) edit their Solid Settings. With `affectAll: false`, a solid other
/// layers also use is copied into a new solid for this layer instead of being changed for all of
/// them (After Effects' "Affect all layers that use this solid"). `name` renames the layer and
/// its solid.
/// its solid; an empty one makes a text layer's name follow its text again.
pub(super) fn layer_settings(s: &mut Session, p: &Value) -> Result<Value> {
let (cid, lid) = layer_p(s, p, "layer.settings")?;
// Cameras and lights open their own settings (Camera Settings / Light Settings).
@@ -171,11 +171,18 @@ pub(super) fn layer_settings(s: &mut Session, p: &Value) -> Result<Value> {
let h = p.get("height").and_then(Value::as_u64).map(limits::size);
let pixel_aspect = pixel_aspect_p(p)?;
let name = str_p(p, "name").map(str::trim).filter(|n| !n.is_empty()).map(str::to_string);
// An empty name gives a text layer its text's name again, as `layer.rename` does (#3233);
// other layers keep theirs.
let follow_text = str_p(p, "name").is_some_and(|n| n.trim().is_empty());
let affect_all = p.get("affectAll").and_then(Value::as_bool).unwrap_or(true);
let t = s.time();
let solid = s.edit("Layer Settings", None, |proj, _| {
let src = layer_mut(proj, cid, lid)?.source.clone();
if let Some(n) = &name {
layer_mut(proj, cid, lid)?.name = n.clone();
// A user name: a text layer's name stops following its text (#3233).
super::switches::set_layer_name(layer_mut(proj, cid, lid)?, n, t);
} else if follow_text && matches!(src, LayerSource::Text) {
super::switches::set_layer_name(layer_mut(proj, cid, lid)?, "", t);
}
let LayerSource::Solid { item } = src else { return Ok(None) };
let shared = proj.comps().flat_map(|(_, c)| &c.layers).filter(|l| l.source == src).count() > 1;
+7
View File
@@ -59,9 +59,16 @@ fn time_stretch(s: &mut Session, p: &Value) -> Result<Value> {
(None, Some(d)) if span > 0.0 => old * d / span,
_ => old,
};
if !new.is_finite() {
return Err(bad("layer.timeStretch", "the stretch factor must be a number"));
}
if new.abs() < 1.0 {
return Err(bad("layer.timeStretch", "the stretch factor must be at least 1 %"));
}
// After Effects' largest stretch; a project file holds no more either (#3247).
if new.abs() > effectcraft_project::limits::MAX_STRETCH {
return Err(bad("layer.timeStretch", "the stretch factor must be at most 9900 %"));
}
// The hold point keeps showing the same layer time.
let h = match hold {
"current" => cti,
+6 -9
View File
@@ -6,7 +6,7 @@
//! Positions are character indices. The selection is `anchor..caret` (either order).
use effectcraft_keyframe::{CharStyle, TextDoc, Value as KV};
use effectcraft_project::{ItemId, LayerId, LayerSource};
use effectcraft_project::{ItemId, LayerId, LayerSource, text_layer_name};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
@@ -288,10 +288,6 @@ fn session_on(s: &mut Session, lid: LayerId) -> TextEdit {
}
}
fn first_line_name(text: &str) -> String {
text.lines().next().unwrap_or("").chars().take(40).collect()
}
/// Edit a layer's Source Text at the CTI (one undo step, or merged by `merge`), then set the
/// session's selection.
pub(crate) fn edit_doc(
@@ -319,12 +315,13 @@ pub(crate) fn edit_doc(
// already has) must not turn a static Str into Text or add a keyframe at the CTI: that
// would change the project and record an empty undo step.
if doc != original {
let before = first_line_name(&original.text);
let after = first_line_name(&doc.text);
let before = text_layer_name(&original.text);
let after = text_layer_name(&doc.text);
pr.set_value_at(lt, KV::Text(Box::new(doc)));
// Text layers are named after their text until renamed.
if before != after && !after.is_empty() && (l.name == before || l.name.starts_with("Text") || l.name.is_empty()) {
// Text layers are named after their text until renamed (#3233).
if before != after && !after.is_empty() && l.name_follows_text(&before) {
l.name = after;
l.name_follows_text = Some(true);
}
}
Ok(())
+18
View File
@@ -103,6 +103,24 @@ fn commands_cap_sizes_at_30000_px() {
assert_eq!((f.width, f.height, f.frame_rate), (limits::MAX_SIZE, 8, FrameRate::FPS_29_97));
}
/// Time Stretch takes After Effects' range, ±1 % to ±9900 %: before, 1e300 % was set, and a
/// project file holding it opened at 9900 % (#3247).
#[test]
fn time_stretch_refuses_more_than_9900_percent() {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "Main", "width": 64, "height": 32, "frameRate": 30, "duration": 2})).unwrap();
let layer = s.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap();
let stretch = |s: &Session| s.active_comp().unwrap().layers.iter().find(|l| l.id.0 == layer).unwrap().stretch;
for pct in [1e300, -1e300, 9900.5] {
assert!(s.execute("layer.timeStretch", json!({"layers": [layer], "percent": pct})).is_err(), "{pct}");
assert_eq!(stretch(&s), 100.0, "{pct}");
}
for pct in [limits::MAX_STRETCH, -limits::MAX_STRETCH] {
s.execute("layer.timeStretch", json!({"layers": [layer], "percent": pct})).unwrap();
assert_eq!(stretch(&s), pct);
}
}
#[test]
fn a_project_with_a_precomp_cycle_opens_adds_and_renders_without_running_out_of_stack() {
// Comps A and B nest each other (a damaged file); C is unrelated. Checking whether A
+104
View File
@@ -1417,3 +1417,107 @@ fn duplicate_of_an_empty_type_tool_layer_ends_the_edit_and_copies_it() {
assert_eq!(layer_count(&s), before + 1, "the empty layer is kept, as text.endEdit keeps it, and copied");
assert_eq!(s.state.selected_layers, vec![LayerId(copy)], "and the copy is selected");
}
fn layer_name(s: &Session, t: u64) -> String {
s.active_comp().unwrap().layer(effectcraft_project::LayerId(t)).unwrap().name.clone()
}
/// Replace the text with `text` in the on-canvas editor (everything selected, typed, committed).
fn retype(s: &mut Session, t: u64, text: &str) {
begin_edit(s, t);
s.execute("text.insert", json!({"text": text})).unwrap();
s.execute("text.endEdit", json!({})).unwrap();
}
/// #3233: a text layer's name follows its Source Text, edited on canvas or by `layer.setText`,
/// until the user renames it (After Effects). A user name stays, even one that starts with
/// "Text", and so does a copy's; renaming to an empty name follows the text again.
#[test]
fn a_text_layer_name_follows_its_text_until_renamed() {
let (mut s, t) = session("Hello");
assert_eq!(layer_name(&s, t), "Hello");
retype(&mut s, t, "World");
assert_eq!(layer_name(&s, t), "World", "a new text layer follows its text");
s.execute("layer.setText", json!({"layer": t, "text": "Again"})).unwrap();
assert_eq!(layer_name(&s, t), "Again");
s.execute("layer.rename", json!({"layer": t, "name": "Text Title"})).unwrap();
s.execute("layer.setText", json!({"layer": t, "text": "Changed"})).unwrap();
assert_eq!(layer_name(&s, t), "Text Title", "layer.setText keeps the user's name");
retype(&mut s, t, "Typed");
assert_eq!(layer_name(&s, t), "Text Title", "typing keeps the user's name");
s.execute("layer.select", json!({"layers": [t]})).unwrap();
let copy = s.execute("edit.duplicate", json!({})).unwrap()[0].as_u64().unwrap();
let copy_name = layer_name(&s, copy);
s.execute("layer.setText", json!({"layer": copy, "text": "Copied"})).unwrap();
assert_eq!(layer_name(&s, copy), copy_name, "a copy keeps the user's name too");
// Renaming to an empty name: the name is the text's again, and follows it.
s.execute("layer.rename", json!({"layer": t, "name": ""})).unwrap();
assert_eq!(layer_name(&s, t), "Typed", "an empty name shows the text");
retype(&mut s, t, "Followed");
assert_eq!(layer_name(&s, t), "Followed", "and follows it again");
// Committing the unchanged name (Enter, Enter) does not stop the following.
s.execute("layer.rename", json!({"layer": t, "name": "Followed"})).unwrap();
s.execute("layer.setText", json!({"layer": t, "text": "Still"})).unwrap();
assert_eq!(layer_name(&s, t), "Still");
// A name given in Layer Settings is the user's too. The UI offers Layer Settings only for
// solids, nulls, cameras and lights (as After Effects does); this guards the command, which
// agents can call on any layer.
s.execute("layer.settings", json!({"layer": t, "name": "Settings Name"})).unwrap();
s.execute("layer.setText", json!({"layer": t, "text": "Later"})).unwrap();
assert_eq!(layer_name(&s, t), "Settings Name", "Layer Settings names it for good");
// An empty Layer Settings name follows the text again, as `layer.rename` does.
s.execute("layer.settings", json!({"layer": t, "name": ""})).unwrap();
assert_eq!(layer_name(&s, t), "Later", "an empty Layer Settings name shows the text");
s.execute("layer.setText", json!({"layer": t, "text": "Follows"})).unwrap();
assert_eq!(layer_name(&s, t), "Follows", "and follows it again");
// A layer given a name when it is made does not follow.
let named = s.execute("layer.newText", json!({"text": "Body", "name": "Caption"})).unwrap()["layer"].as_u64().unwrap();
s.execute("layer.setText", json!({"layer": named, "text": "Other"})).unwrap();
assert_eq!(layer_name(&s, named), "Caption");
}
/// #3233: After Effects breaks paragraphs with a bare carriage return; the name is the first
/// paragraph, without the break, and an older layer named after it counts as following.
#[test]
fn a_text_layer_name_ends_at_a_bare_carriage_return() {
let (mut s, t) = session("A\rB");
assert_eq!(layer_name(&s, t), "A");
s.execute("layer.setText", json!({"layer": t, "text": "C\rD"})).unwrap();
assert_eq!(layer_name(&s, t), "C");
retype(&mut s, t, "E\rF");
assert_eq!(layer_name(&s, t), "E");
let cid = s.active_comp_id().unwrap();
let l = std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(t)).unwrap();
l.name = "Para1".into();
l.name_follows_text = None;
l.props.prop_mut("text/sourceText").unwrap().value = effectcraft_keyframe::Value::Text(Box::new(TextDoc::plain("Para1\rPara2")));
s.execute("layer.setText", json!({"layer": t, "text": "Next\rLine"})).unwrap();
assert_eq!(layer_name(&s, t), "Next", "an older layer named after its first paragraph follows");
}
/// #3233: projects saved before the state was recorded load without it; there a name that is
/// the text's, empty, or the default "Text"/"Text 2"… follows the text, any other name stays.
#[test]
fn older_text_layers_without_the_name_state_follow_as_before() {
let (mut s, t) = session("Hello");
let mut v = serde_json::to_value(s.active_comp().unwrap().layer(effectcraft_project::LayerId(t)).unwrap()).unwrap();
v.as_object_mut().unwrap().remove("name_follows_text");
let old: effectcraft_project::Layer = serde_json::from_value(v).unwrap();
assert_eq!(old.name_follows_text, None, "an older project has no state");
for (name, follows) in [("Hello", true), ("", true), ("Text", true), ("Text 3", true), ("Text Title", false), ("Text 3b", false), ("Title", false)] {
let l = effectcraft_project::Layer { name: name.into(), ..old.clone() };
assert_eq!(l.name_follows_text("Hello"), follows, "{name:?}");
}
let legacy = |s: &mut Session, name: &str| {
let cid = s.active_comp_id().unwrap();
let l = std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(t)).unwrap();
l.name = name.into();
l.name_follows_text = None;
};
legacy(&mut s, "Hello");
s.execute("layer.setText", json!({"layer": t, "text": "World"})).unwrap();
assert_eq!(layer_name(&s, t), "World", "a name equal to the text follows it");
legacy(&mut s, "Title");
retype(&mut s, t, "Typed");
assert_eq!(layer_name(&s, t), "Title", "another name stays");
}