Skip to content

Commit

Permalink
Test the creation of variable CTFonts from CGFonts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmuizel committed Feb 10, 2021
1 parent 987123d commit 9be2a05
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion core-text/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,40 @@ 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_dict() {
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();
match macos_version() {
(10, 11, _) => {
assert!(font.copy_variation_axis().is_none());
return;
}
_ => {}
}

// create a ct_font
let vars = var_font.copy_variations().unwrap();
let ct_font = new_from_CGFont_with_variations(&var_font.clone(), 19., &vars);

// check if our variations worked
let var = ct_font.copy_descriptor().attributes().find(CFString::from_static_string("NSCTFontVariationAttribute"))
.unwrap()
.downcast::<CFDictionary>()
.unwrap();
let var: CFDictionary<CFNumber, CFNumber> = unsafe { std::mem::transmute(var) };
match macos_version() {
// (10, 12, _) => assert!(var.find(CFNumber::from(0x77676874)).is_none()), // XXX: I'm not sure why this is
_ => assert!(var.find(CFNumber::from(0x77676874)).is_some()),
}
}

0 comments on commit 9be2a05

Please sign in to comment.