M13.5: Animate Text > Variable Font Axes

Text: text.animatorFontAxes (replaces the stub) lists the layer font's
variation axes (skrifa) or adds an animator property that offsets one axis
(weighted by the selectors, from the axis default); the renderer redraws each
character's outline at its design-space position (cached per location). The
Timeline's Animate: menu lists the font's axes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 00:24:05 -04:00
co-authored by Claude Opus 5.5
parent 5b4e936e9d
commit 7537eea85c
7 changed files with 310 additions and 5 deletions
-1
View File
@@ -46,7 +46,6 @@ pub fn specs() -> Vec<CommandSpec> {
// Keyframes / text / tracking.
stub!("keys.audioToKeyframes", "Convert Audio to Keyframes", ["Animation", "Keyframe Assistant"], "{}"),
stub!("keys.rpfCameraImport", "RPF Camera Import", ["Animation", "Keyframe Assistant"], "{}"),
stub!("text.animatorFontAxes", "Variable Font Axes", ["Animation", "Animate Text"], "{}"),
stub!("track.camera", "Track Camera", ["Animation"], "{}"),
// Workspaces and panels that don't exist yet.
stub!("window.unavailablePanel", "Panel", [], "{panel}"),
+63
View File
@@ -372,6 +372,60 @@ fn list_presets(_: &mut Session, _: &Value) -> Result<Value> {
Ok(Value::Array(presets().iter().map(|p| json!({"id": p.get("id"), "name": p.get("name"), "description": p.get("description")})).collect()))
}
/// Animation ▸ Animate Text ▸ Variable Font Axes: the axes of the layer's font, or (with `axis`)
/// a new animator — or a property on `animator` — that offsets that axis (user units, weighted
/// by the selectors, added to the axis default).
fn font_axes(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "text.animatorFontAxes";
let (cid, lid) = layer_p(s, p, C)?;
let layer = s.project.comp(cid).and_then(|c| c.layer(lid)).cloned().ok_or_else(|| bad(C, "no layer"))?;
let Some(KV::Text(doc)) = layer.props.prop("text/sourceText").map(|pr| pr.value_at(layer.layer_time(s.time()))) else {
return Err(bad(C, "not a text layer"));
};
let face = effectcraft_text::layout_doc(&doc).glyphs.first().map(|g| g.face).unwrap_or_else(|| effectcraft_text::resolve(&doc.font, &doc.style).face);
let axes = effectcraft_text::variable::font_axes(face);
let list = || json!(axes.iter().map(|a| json!({"tag": a.tag, "name": a.name, "min": a.min, "default": a.default, "max": a.max})).collect::<Vec<_>>());
let Some(want) = str_p(p, "axis") else { return Ok(json!({"font": doc.font, "axes": list()})) };
if axes.is_empty() {
return Err(bad(C, format!("{} {} has no variation axes (not a variable font)", doc.font, doc.style)));
}
let axis = axes
.iter()
.find(|a| a.tag == want || a.name.eq_ignore_ascii_case(want))
.ok_or_else(|| bad(C, format!("no axis `{want}`; the font has {}", list())))?
.clone();
let target = match p.get("animator") {
Some(_) => Some(animator_uid(s, &layer, p, C)?),
None => None,
};
let uid = s.edit("Add Variable Font Axis", None, |proj, _| {
let mut next = proj.next_id;
let mut ids = Ids(&mut next);
let prop = ids
.prop(&format!("{}{}", effectcraft_render::text::AXIS_PREFIX, axis.tag.trim_end()), &axis.name, KV::Scalar(0.0))
.with_ui(effectcraft_project::ParamUi::Number);
let l = layer_mut(proj, cid, lid)?;
let uid = match target {
Some(a) => {
let g = l.props.find_group_mut(a).and_then(|g| g.sub_mut("properties")).ok_or_else(|| bad(C, "no such animator"))?;
g.children.push(prop.into());
a
}
None => {
let anims = l.props.group_mut("text/animators").ok_or_else(|| bad(C, "not a text layer"))?;
let name = format!("Animator {}", anims.children.len() + 1);
let g = build::text_animator(&mut ids, &name, vec![prop]);
let uid = g.uid;
anims.children.push(g.into());
uid
}
};
proj.next_id = next;
Ok(uid)
})?;
Ok(json!({"animator": uid, "axis": axis.tag}))
}
fn list_kinds(_: &mut Session, _: &Value) -> Result<Value> {
Ok(Value::Array(build::TEXT_ANIMATOR_KINDS.iter().filter(|(k, _)| *k != "-").map(|(k, l)| json!({"property": k, "label": l})).collect()))
}
@@ -415,6 +469,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_text_layer,
apply_preset
),
cmd!(
"text.animatorFontAxes",
"Variable Font Axes",
["Animation", "Animate Text"],
None,
"{layer?, axis?: tag|name (omit to list the font's axes), animator?: uid|index}",
has_text_layer,
font_axes
),
query!("text.presets", "Text Animation Presets", "{}", list_presets),
query!("text.animatorProperties", "Text Animator Properties", "{}", list_kinds),
]
+43
View File
@@ -283,6 +283,49 @@ fn tate_chu_yoko_via_set_text_with_undo_and_serde() {
assert!(crate::commands::text_edit::layer_doc(&s, LayerId(t)).unwrap().vertical_roman_upright);
}
#[test]
fn variable_font_axes_animator() {
let mut s = comp(400, 200);
let t = s.execute("layer.newText", json!({"text": "HH", "size": 60})).unwrap()["layer"].as_u64().unwrap();
s.execute("layer.select", json!({"layers": [t]})).unwrap();
assert!(s.is_enabled("text.animatorFontAxes"));
// Inter (bundled) is static.
assert_eq!(s.execute("text.animatorFontAxes", json!({})).unwrap()["axes"], json!([]));
assert!(s.execute("text.animatorFontAxes", json!({"axis": "wght"})).is_err());
let Some((face, axes)) = effectcraft_text::variable::find_variable_face() else {
eprintln!("no variable font installed: animation check skipped");
return;
};
let info = effectcraft_text::fonts::face(face).info.clone();
s.execute("layer.setText", json!({"layer": t, "font": info.family, "style": info.style})).unwrap();
let axis = axes.iter().find(|a| a.max > a.min).unwrap().clone();
let listed = s.execute("text.animatorFontAxes", json!({})).unwrap();
if listed["axes"].as_array().is_none_or(|a| a.is_empty()) {
eprintln!("the variable face isn't reachable by family/style: skipped");
return;
}
let tag = listed["axes"][0]["tag"].as_str().unwrap().to_string();
let r = s.execute("text.animatorFontAxes", json!({"axis": tag})).unwrap();
let anim = r["animator"].as_u64().unwrap();
let area = |s: &Session| {
let cid = s.active_comp_id().unwrap();
let comp = s.project.comp(cid).unwrap();
let ctx = effectcraft_render::EvalCtx::new(&s.project, cid, comp, s.time());
let l = comp.layer(LayerId(t)).unwrap();
effectcraft_render::text::glyph_paths(&ctx, l).iter().map(|(p, _)| effectcraft_text::kurbo::Shape::area(p).abs()).sum::<f64>()
};
let before = area(&s);
let l = s.active_comp().unwrap().layer(LayerId(t)).unwrap().clone();
let pg = l.props.find_group(anim).unwrap().sub("properties").unwrap().props().next().unwrap().uid;
let range = (axis.max - axis.min) as f64;
s.execute("prop.set", json!({"layer": t, "prop": pg, "value": range})).unwrap();
let after = area(&s);
assert!((after - before).abs() > 1.0, "{} axis moved the outline: {before} → {after}", axis.tag);
s.execute("edit.undo", json!({})).unwrap();
assert!((area(&s) - before).abs() < 1e-6);
let _ = info;
}
#[test]
fn camera_focus_commands_undo_and_serde() {
let mut s = comp(400, 300);