fix(type): clear retained wght variation when resolving exact face

This commit is contained in:
Gabrieljr42 committed 2026-10-20 21:01:11 -03:00
1 parent 99a234d2e2
commit 797c7852f9
2 files changed
+32

No files matched your search

+1
View File
@@ -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;
@@ -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));
}