@@ -162,6 +162,13 @@ impl CTFont {
162
162
}
163
163
}
164
164
165
+ pub fn copy_descriptor ( & self ) -> CTFontDescriptor {
166
+ unsafe {
167
+ let desc = CTFontCopyFontDescriptor ( self . 0 ) ;
168
+ CTFontDescriptor :: wrap_under_create_rule ( desc)
169
+ }
170
+ }
171
+
165
172
pub fn clone_with_font_size ( & self , size : f64 ) -> CTFont {
166
173
unsafe {
167
174
let font_ref = CTFontCreateCopyWithAttributes ( self . 0 ,
@@ -545,7 +552,7 @@ extern {
545
552
//fn CTFontCreateForString
546
553
547
554
/* Getting Font Data */
548
- // fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
555
+ fn CTFontCopyFontDescriptor ( font : CTFontRef ) -> CTFontDescriptorRef ;
549
556
fn CTFontCopyAttribute ( font : CTFontRef , attribute : CFStringRef ) -> CFTypeRef ;
550
557
fn CTFontGetSize ( font : CTFontRef ) -> CGFloat ;
551
558
//fn CTFontGetMatrix
@@ -638,3 +645,18 @@ extern {
638
645
fn CTFontGetTypeID ( ) -> CFTypeID ;
639
646
}
640
647
648
+ #[ test]
649
+ fn copy_font ( ) {
650
+ use std:: io:: Read ;
651
+ let mut f = std:: fs:: File :: open ( "/System/Library/Fonts/ZapfDingbats.ttf" ) . unwrap ( ) ;
652
+ let mut font_data = Vec :: new ( ) ;
653
+ f. read_to_end ( & mut font_data) . unwrap ( ) ;
654
+ let desc = crate :: font_manager:: create_font_descriptor ( & font_data) . unwrap ( ) ;
655
+ let font = new_from_descriptor ( & desc, 12. ) ;
656
+ drop ( desc) ;
657
+ let desc = font. copy_descriptor ( ) ;
658
+ drop ( font) ;
659
+ let font = new_from_descriptor ( & desc, 14. ) ;
660
+ assert_eq ! ( font. family_name( ) , "Zapf Dingbats" ) ;
661
+ }
662
+
0 commit comments