Skip to content

Commit 20dcdc0

Browse files
authored
Auto merge of #420 - jrmuizel:round-trip, r=jdm
Make sure we can round trip data fonts through descriptors.
2 parents e000e13 + 5a9ab37 commit 20dcdc0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

core-text/src/font.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ impl CTFont {
162162
}
163163
}
164164

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+
165172
pub fn clone_with_font_size(&self, size: f64) -> CTFont {
166173
unsafe {
167174
let font_ref = CTFontCreateCopyWithAttributes(self.0,
@@ -545,7 +552,7 @@ extern {
545552
//fn CTFontCreateForString
546553

547554
/* Getting Font Data */
548-
//fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
555+
fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
549556
fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef;
550557
fn CTFontGetSize(font: CTFontRef) -> CGFloat;
551558
//fn CTFontGetMatrix
@@ -638,3 +645,18 @@ extern {
638645
fn CTFontGetTypeID() -> CFTypeID;
639646
}
640647

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

Comments
 (0)