Skip to content

Commit

Permalink
Auto merge of servo#420 - jrmuizel:round-trip, r=jdm
Browse files Browse the repository at this point in the history
Make sure we can round trip data fonts through descriptors.
  • Loading branch information
bors-servo committed Oct 26, 2020
2 parents e000e13 + 5a9ab37 commit 20dcdc0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion core-text/src/font.rs
Expand Up @@ -162,6 +162,13 @@ impl CTFont {
}
}

pub fn copy_descriptor(&self) -> CTFontDescriptor {
unsafe {
let desc = CTFontCopyFontDescriptor(self.0);
CTFontDescriptor::wrap_under_create_rule(desc)
}
}

pub fn clone_with_font_size(&self, size: f64) -> CTFont {
unsafe {
let font_ref = CTFontCreateCopyWithAttributes(self.0,
Expand Down Expand Up @@ -545,7 +552,7 @@ extern {
//fn CTFontCreateForString

/* Getting Font Data */
//fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef;
fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef;
fn CTFontGetSize(font: CTFontRef) -> CGFloat;
//fn CTFontGetMatrix
Expand Down Expand Up @@ -638,3 +645,18 @@ extern {
fn CTFontGetTypeID() -> CFTypeID;
}

#[test]
fn copy_font() {
use std::io::Read;
let mut f = std::fs::File::open("/System/Library/Fonts/ZapfDingbats.ttf").unwrap();
let mut font_data = Vec::new();
f.read_to_end(&mut font_data).unwrap();
let desc = crate::font_manager::create_font_descriptor(&font_data).unwrap();
let font = new_from_descriptor(&desc, 12.);
drop(desc);
let desc = font.copy_descriptor();
drop(font);
let font = new_from_descriptor(&desc, 14.);
assert_eq!(font.family_name(), "Zapf Dingbats");
}

0 comments on commit 20dcdc0

Please sign in to comment.