From 9be2a056d14c05ed20801ea531897980f5a2723c Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Tue, 9 Feb 2021 15:28:25 -0500 Subject: [PATCH 1/2] Test the creation of variable CTFonts from CGFonts --- core-text/src/font.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/core-text/src/font.rs b/core-text/src/font.rs index ebe6d580f..5cee3347d 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -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()); -} \ No newline at end of file +} + +#[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::() + .unwrap(); + let var: CFDictionary = 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()), + } +} From e4d2fe6be258e81006085bca70b16cec5a6cd627 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 10 Feb 2021 12:32:38 -0500 Subject: [PATCH 2/2] Check the preservation of variable fonts --- core-text/src/font.rs | 26 +++++++++++++++++++++++++- core-text/variabletest_box.ttf | Bin 0 -> 4032 bytes 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 core-text/variabletest_box.ttf diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 5cee3347d..da06e5db9 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -757,7 +757,7 @@ fn variations_dict() { let var_font = CGFont::create_copy_from_variations(&font, &vars).unwrap(); match macos_version() { (10, 11, _) => { - assert!(font.copy_variation_axis().is_none()); + assert!(font.copy_variation_axes().is_none()); return; } _ => {} @@ -778,3 +778,27 @@ fn variations_dict() { _ => assert!(var.find(CFNumber::from(0x77676874)).is_some()), } } + +#[test] +fn variations_copy() { + use std::io::Read; + let mut f = std::fs::File::open("variabletest_box.ttf").unwrap(); + let mut buffer = Vec::new(); + // read the whole file + f.read_to_end(&mut buffer).unwrap(); + + let font = new_from_buffer(&buffer).unwrap(); + dbg!(&font); + let cg_font = font.copy_to_CGFont(); + dbg!(cg_font.copy_variation_axes()); + let mut vals_str: Vec<(CFString, CFNumber)> = Vec::new(); + vals_str.push((CFString::new("Optical Sizing"), (100.).into())); + vals_str.push((CFString::new("Upward"), (350).into())); + let vars = CFDictionary::from_CFType_pairs(&vals_str); + let var_font = CGFont::create_copy_from_variations(&cg_font, &vars).unwrap(); + let var_ct_font = new_from_CGFont(&var_font, 19.); + dbg!(&var_ct_font); + dbg!(var_ct_font.copy_descriptor().attributes().find(CFString::from_static_string("NSCTFontVariationAttribute"))); + dbg!(var_ct_font.copy_to_CGFont().copy_variations()); + assert!(false); +} diff --git a/core-text/variabletest_box.ttf b/core-text/variabletest_box.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0d5bf3e267fc663bc87835226000ac2a45867fd7 GIT binary patch literal 4032 zcmb7HYitzP6+U-n*M^Pl;Kmjxq0y`#Kz4~|##{3UMfjDa2opo>g+vPMj=h6-!+LkU zyLNz7*o{e*2Z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