Skip to content

Add a test for variation preservation. #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion core-text/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,29 @@ fn copy_system_font() {
assert!(matching.attributes().find(CFString::from_static_string("NSFontSizeAttribute")).is_none());

assert_eq!(small.postscript_name(), cgfont.postscript_name());
}
}

#[test]
fn variations() {
let mut vals_str: Vec<(CFString, CFNumber)> = Vec::new();
let system_font = unsafe {
CTFont::wrap_under_create_rule(
CTFontCreateUIFontForLanguage(kCTFontEmphasizedSystemDetailFontType, 19., std::ptr::null())
)
};
let font = system_font.copy_to_CGFont();
vals_str.push((CFString::new("Weight"), (700.).into()) );
let vars = CFDictionary::from_CFType_pairs(&vals_str);
let var_font = CGFont::create_copy_from_variations(&font, &vars).unwrap();
// Check if new_from_CGFont will work on our CGFont with variations applied
let ct_font = new_from_CGFont(&var_font.clone(), 19.);
match macos_version() {
(10, 15, _) => assert_ne!(ct_font.family_name(), ".LastResort"),
(10, 14, _) => assert_eq!(ct_font.family_name(), ".LastResort"),
(10, 13, _) => assert_eq!(ct_font.family_name(), ".LastResort"),
(10, 12, _) => assert_eq!(ct_font.family_name(), ".LastResort"),
(10, 11, _) => assert_ne!(ct_font.family_name(), ".LastResort"),
_ => assert_ne!(ct_font.family_name(), ".LastResort"),

}
}