@@ -513,9 +513,11 @@ extern {
513
513
//static kCTFontSampleTextNameKey: CFStringRef;
514
514
//static kCTFontPostScriptCIDNameKey: CFStringRef;
515
515
516
- //static kCTFontVariationAxisIdentifierKey: CFStringRef;
516
+ #[ cfg( test) ]
517
+ static kCTFontVariationAxisIdentifierKey: CFStringRef ;
517
518
//static kCTFontVariationAxisMinimumValueKey: CFStringRef;
518
- //static kCTFontVariationAxisMaximumValueKey: CFStringRef;
519
+ #[ cfg( test) ]
520
+ static kCTFontVariationAxisMaximumValueKey: CFStringRef ;
519
521
//static kCTFontVariationAxisDefaultValueKey: CFStringRef;
520
522
//static kCTFontVariationAxisNameKey: CFStringRef;
521
523
@@ -749,4 +751,49 @@ fn copy_system_font() {
749
751
assert ! ( matching. attributes( ) . find( CFString :: from_static_string( "NSFontSizeAttribute" ) ) . is_none( ) ) ;
750
752
751
753
assert_eq ! ( small. postscript_name( ) , cgfont. postscript_name( ) ) ;
754
+ }
755
+
756
+ // Tests what happens when variations have values not inbetween min and max
757
+ #[ test]
758
+ fn out_of_range_variations ( ) {
759
+ use crate :: * ;
760
+
761
+ let small = unsafe {
762
+ CTFont :: wrap_under_create_rule (
763
+ CTFontCreateUIFontForLanguage ( kCTFontSystemDetailFontType, 19. , std:: ptr:: null ( ) )
764
+ )
765
+ } ;
766
+
767
+ let axes = small. get_variation_axes ( ) ;
768
+ if macos_version ( ) < ( 10 , 12 , 0 ) {
769
+ assert ! ( axes. is_none( ) ) ;
770
+ return ;
771
+ }
772
+ let axes = axes. unwrap ( ) ;
773
+ let mut vals = Vec :: new ( ) ;
774
+ dbg ! ( & axes) ;
775
+ for axis in axes. iter ( ) {
776
+ let tag = axis. find ( unsafe { kCTFontVariationAxisIdentifierKey } )
777
+ . unwrap ( ) . downcast :: < CFNumber > ( ) . unwrap ( ) . to_i64 ( ) . unwrap ( ) ;
778
+ let max = axis. find ( unsafe { kCTFontVariationAxisMaximumValueKey } )
779
+ . unwrap ( ) . downcast :: < CFNumber > ( ) . unwrap ( ) . to_f64 ( ) . unwrap ( ) ;
780
+ vals. push ( ( CFNumber :: from ( tag) , CFNumber :: from ( max + 1. ) ) ) ;
781
+
782
+ }
783
+ let vals_dict = CFDictionary :: from_CFType_pairs ( & vals) ;
784
+ let variation_attribute = unsafe { CFString :: wrap_under_get_rule ( font_descriptor:: kCTFontVariationAttribute) } ;
785
+ let attrs_dict = CFDictionary :: from_CFType_pairs ( & [ ( variation_attribute. clone ( ) , vals_dict) ] ) ;
786
+ let ct_var_font_desc = small. copy_descriptor ( ) . create_copy_with_attributes ( attrs_dict. to_untyped ( ) ) . unwrap ( ) ;
787
+ let variation_font = crate :: font:: new_from_descriptor ( & ct_var_font_desc, 19. ) ;
788
+ let var_desc = variation_font. copy_descriptor ( ) ;
789
+ let var_attrs = var_desc. attributes ( ) ;
790
+ dbg ! ( & var_attrs) ;
791
+ // attributes greater than max are dropped
792
+ let var_attrs = var_attrs. find ( variation_attribute) ;
793
+ if macos_version ( ) >= ( 10 , 15 , 0 ) {
794
+ assert ! ( var_attrs. is_none( ) ) ;
795
+ } else {
796
+ let var_attrs = var_attrs. unwrap ( ) . downcast :: < CFDictionary > ( ) . unwrap ( ) ;
797
+ assert ! ( var_attrs. is_empty( ) ) ;
798
+ }
752
799
}
0 commit comments