Skip to content

Commit 0488869

Browse files
committed
Add a test for variation preservation.
1 parent 4bd0ff7 commit 0488869

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

core-text/src/font.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,29 @@ fn copy_system_font() {
741741
assert!(matching.attributes().find(CFString::from_static_string("NSFontSizeAttribute")).is_none());
742742

743743
assert_eq!(small.postscript_name(), cgfont.postscript_name());
744-
}
744+
}
745+
746+
#[test]
747+
fn variations() {
748+
let mut vals_str: Vec<(CFString, CFNumber)> = Vec::new();
749+
let system_font = unsafe {
750+
CTFont::wrap_under_create_rule(
751+
CTFontCreateUIFontForLanguage(kCTFontEmphasizedSystemDetailFontType, 19., std::ptr::null())
752+
)
753+
};
754+
let font = system_font.copy_to_CGFont();
755+
vals_str.push((CFString::new("Weight"), (700.).into()) );
756+
let vars = CFDictionary::from_CFType_pairs(&vals_str);
757+
let var_font = CGFont::create_copy_from_variations(&font, &vars).unwrap();
758+
// Check if new_from_CGFont will work on our CGFont with variations applied
759+
let ct_font = new_from_CGFont(&var_font.clone(), 19.);
760+
match macos_version() {
761+
(10, 15, 0) => assert_ne!(ct_font.family_name(), ".LastResort"),
762+
(10, 14, 0) => assert_eq!(ct_font.family_name(), ".LastResort"),
763+
(10, 13, 0) => assert_eq!(ct_font.family_name(), ".LastResort"),
764+
(10, 12, 0) => assert_eq!(ct_font.family_name(), ".LastResort"),
765+
(10, 11, 0) => assert_ne!(ct_font.family_name(), ".LastResort"),
766+
_ => assert_ne!(ct_font.family_name(), ".LastResort"),
767+
768+
}
769+
}

0 commit comments

Comments
 (0)