diff --git a/crates/engine/src/type_cmds.rs b/crates/engine/src/type_cmds.rs index fd44f874ce..85abca0c3b 100644 --- a/crates/engine/src/type_cmds.rs +++ b/crates/engine/src/type_cmds.rs @@ -249,6 +249,7 @@ pub fn apply_char_props(s: &mut CharStyle, p: &Value) -> bool { if !text.fonts.has_family(v) { let resolved = text.fonts.resolve_postscript(v); if resolved.exact { + s.variations.retain(|f| f.axis != "wght"); s.font_family = resolved.family; s.weight = resolved.weight; s.italic = resolved.italic; diff --git a/crates/engine/tests/type_postscript_font.rs b/crates/engine/tests/type_postscript_font.rs index 0a5bf82c6d..06171d7d84 100644 --- a/crates/engine/tests/type_postscript_font.rs +++ b/crates/engine/tests/type_postscript_font.rs @@ -61,3 +61,34 @@ fn type_create_resolves_exact_postscript_font_names() { let missing = session.execute("type.create", json!({"text": "Test", "font": "No Such Family 123"})).unwrap(); assert_eq!(missing["warnings"], json!(["font 'No Such Family 123' is not installed; text may render using a fallback face"])); } + +#[test] +fn exact_postscript_face_clears_retained_weight_variation() { + let ps = "PhotoCraft-Black-Test-Var"; + photocraft_text::shared() + .lock() + .unwrap_or_else(|e| e.into_inner()) + .fonts + .register_font_data(font_with_postscript_name(photocraft_text::fonts::INTER_REGULAR.as_slice(), ps)); + + let mut session = Session::new(); + session.execute("file.new", json!({"width": 200, "height": 100, "background": "transparent"})).unwrap(); + let response = session.execute("type.create", json!({"text": "Test", "font": "Inter", "variations": {"wght": 300}})).unwrap(); + let id = LayerId(response["layer"].as_u64().unwrap()); + + // Setting an exact PostScript face should clear the previously retained wght variation + session.execute("type.setStyle", json!({"layer": id.0, "font": ps})).unwrap(); + let LayerContent::Text(text) = &session.active().unwrap().doc.layer(id).unwrap().content else { panic!("not a text layer") }; + let style = &text.char_runs()[0].style; + assert_eq!(style.font_family, "PhotoCraft Black Test"); + assert_eq!(style.weight, 900); + assert!(!style.variations.iter().any(|v| v.axis == "wght")); + + // Supplying a variations.wght in the same call should apply after clearing + session.execute("type.setStyle", json!({"layer": id.0, "font": ps, "variations": {"wght": 700}})).unwrap(); + let LayerContent::Text(text2) = &session.active().unwrap().doc.layer(id).unwrap().content else { panic!("not a text layer") }; + let style2 = &text2.char_runs()[0].style; + assert_eq!(style2.font_family, "PhotoCraft Black Test"); + assert_eq!(style2.weight, 900); + assert_eq!(style2.variations.iter().find(|v| v.axis == "wght").map(|v| v.value), Some(700.0)); +}