@@ -741,4 +741,40 @@ fn copy_system_font() {
741
741
assert ! ( matching. attributes( ) . find( CFString :: from_static_string( "NSFontSizeAttribute" ) ) . is_none( ) ) ;
742
742
743
743
assert_eq ! ( small. postscript_name( ) , cgfont. postscript_name( ) ) ;
744
- }
744
+ }
745
+
746
+ #[ test]
747
+ fn variations_dict ( ) {
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
+ match macos_version ( ) {
759
+ ( 10 , 11 , _) => {
760
+ assert ! ( font. copy_variation_axis( ) . is_none( ) ) ;
761
+ return ;
762
+ }
763
+ _ => { }
764
+ }
765
+
766
+ // create a ct_font
767
+ let vars = var_font. copy_variations ( ) . unwrap ( ) ;
768
+ let ct_font = new_from_CGFont_with_variations ( & var_font. clone ( ) , 19. , & vars) ;
769
+
770
+ // check if our variations worked
771
+ let var = ct_font. copy_descriptor ( ) . attributes ( ) . find ( CFString :: from_static_string ( "NSCTFontVariationAttribute" ) )
772
+ . unwrap ( )
773
+ . downcast :: < CFDictionary > ( )
774
+ . unwrap ( ) ;
775
+ let var: CFDictionary < CFNumber , CFNumber > = unsafe { std:: mem:: transmute ( var) } ;
776
+ match macos_version ( ) {
777
+ // (10, 12, _) => assert!(var.find(CFNumber::from(0x77676874)).is_none()), // XXX: I'm not sure why this is
778
+ _ => assert ! ( var. find( CFNumber :: from( 0x77676874 ) ) . is_some( ) ) ,
779
+ }
780
+ }
0 commit comments