#741: font menu filters to variable fonts
Problem: After Effects 26.3's font menu can show only variable fonts.
EffectCraft's font menus (Character panel, Properties ▸ Text) had no such
filter, and text.fonts / MCP list_fonts didn't say which families are
variable.
Fix: the font scan marks a face variable when its table directory has an
fvar table declaring axes (header read only, no extra file loading). The
font menu gets a "Variable fonts only" checkbox above the results; it
combines with the typed search, keeps the keyboard in the search field and
stays set while the app runs. text.fonts reports `variable` per family and
takes `{variable: true}`; list_fonts passes it through. Catalog rows for
ja, zh-Hans, zh-Hant and uk.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a7d3e7699
commit
7afe723260
@@ -260,6 +260,63 @@ fn fonts_lists_bundled_and_installed_families() {
|
||||
assert_eq!(crate::font_styles("No Such Family").len(), 5);
|
||||
}
|
||||
|
||||
/// A font file of just `name` (the family, Regular) and an `fvar` table with one axis pinned at
|
||||
/// 400 (so the helpers that look for an installed font with a real axis range never pick it).
|
||||
fn pinned_variable_font(family: &str) -> Vec<u8> {
|
||||
let u16s = |v: &[u16]| -> Vec<u8> { v.iter().flat_map(|x| x.to_be_bytes()).collect() };
|
||||
let strings: Vec<Vec<u8>> = [family, "Regular"].iter().map(|s| s.encode_utf16().flat_map(|u| u.to_be_bytes()).collect()).collect();
|
||||
let mut name = u16s(&[0, 2, 30]);
|
||||
let mut off = 0;
|
||||
for (id, st) in strings.iter().enumerate() {
|
||||
name.extend(u16s(&[3, 1, 0x409, id as u16 + 1, st.len() as u16, off]));
|
||||
off += st.len() as u16;
|
||||
}
|
||||
strings.iter().for_each(|st| name.extend(st));
|
||||
let mut fvar = u16s(&[1, 0, 16, 2, 1, 20, 0, 8]);
|
||||
fvar.extend(b"wght".iter().copied().chain(u16s(&[0x190, 0, 0x190, 0, 0x190, 0, 0, 256])));
|
||||
let mut out = u16s(&[1, 0, 2, 0, 0, 0]);
|
||||
let mut body: Vec<u8> = vec![];
|
||||
for (tag, data) in [(b"fvar", fvar), (b"name", name)] {
|
||||
out.extend(tag);
|
||||
out.extend([0u8; 4]);
|
||||
out.extend(((12 + 32 + body.len()) as u32).to_be_bytes());
|
||||
out.extend((data.len() as u32).to_be_bytes());
|
||||
body.extend(data);
|
||||
}
|
||||
out.extend(body);
|
||||
out
|
||||
}
|
||||
|
||||
/// The font menu's Variable Fonts filter (After Effects 26.3): `text.fonts {variable: true}`
|
||||
/// lists only families with variation axes, every listing says which families are variable, and
|
||||
/// the font menu's rows carry the flag the filter uses.
|
||||
#[test]
|
||||
fn fonts_filter_variable_families() {
|
||||
const FAMILY: &str = "EffectCraft Variable Filter Test";
|
||||
assert_eq!(effectcraft_text::fonts::add_font_data(pinned_variable_font(FAMILY)).len(), 1);
|
||||
let mut s = Session::default();
|
||||
let all = s.execute("text.fonts", json!({})).unwrap();
|
||||
let fams = all["families"].as_array().unwrap();
|
||||
let flag = |name: &str| fams.iter().find(|f| f["family"] == name).map(|f| f["variable"].clone());
|
||||
assert_eq!(flag("Inter"), Some(json!(false)), "the bundled fonts are static");
|
||||
assert_eq!(flag(FAMILY), Some(json!(true)));
|
||||
let var = s.execute("text.fonts", json!({"variable": true})).unwrap();
|
||||
let listed = var["families"].as_array().unwrap();
|
||||
assert_eq!(var["count"].as_u64(), Some(listed.len() as u64));
|
||||
assert!(listed.iter().all(|f| f["variable"] == true), "{var}");
|
||||
assert!(listed.iter().any(|f| f["family"] == FAMILY), "{var}");
|
||||
assert!(listed.len() < fams.len(), "the filter drops the static families");
|
||||
// Combined with the name query.
|
||||
let both = s.execute("text.fonts", json!({"variable": true, "query": "variable filter"})).unwrap();
|
||||
assert_eq!(both["families"].as_array().map(Vec::len), Some(1), "{both}");
|
||||
let none = s.execute("text.fonts", json!({"variable": true, "query": "jetbrains mono"})).unwrap();
|
||||
assert!(!none["families"].as_array().unwrap().iter().any(|f| f["family"] == "JetBrains Mono"), "{none}");
|
||||
// The font menu's rows.
|
||||
let menu = crate::font_menu(&s.prefs);
|
||||
assert!(menu.iter().any(|r| r.family == FAMILY && r.variable));
|
||||
assert!(menu.iter().any(|r| r.family == "Inter" && !r.variable));
|
||||
}
|
||||
|
||||
/// `layer.setText`'s schema lists every OpenType key as optional, so checked execution (control
|
||||
/// channel, MCP) accepts them and requires none (#520).
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user