Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit d3dec43

Browse files
committed
Add functions to get font tag information
1 parent de898c8 commit d3dec43

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/font.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
use std::ptr;
1011
use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType};
12+
use core_foundation::array::{CFArray, CFArrayRef};
13+
use core_foundation::data::{CFData, CFDataRef};
1114
use core_foundation::string::{CFString, CFStringRef};
1215
use data_provider::CGDataProvider;
1316
use geometry::CGRect;
@@ -91,6 +94,21 @@ impl CGFont {
9194
CGFontGetUnitsPerEm(self.as_ptr())
9295
}
9396
}
97+
98+
pub fn copy_table_tags(&self) -> CFArray<u32> {
99+
unsafe {
100+
TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr()))
101+
}
102+
}
103+
104+
pub fn copy_table_for_tag(&self, tag: u32) -> Option<CFData> {
105+
let data_ref = unsafe { CGFontCopyTableForTag(self.as_ptr(), tag) };
106+
if data_ref != ptr::null() {
107+
Some(unsafe { TCFType::wrap_under_create_rule(data_ref) })
108+
} else {
109+
None
110+
}
111+
}
94112
}
95113

96114
#[link(name = "CoreGraphics", kind = "framework")]
@@ -118,4 +136,7 @@ extern {
118136
advances: *mut c_int)
119137
-> bool;
120138
fn CGFontGetUnitsPerEm(font: ::sys::CGFontRef) -> c_int;
139+
140+
fn CGFontCopyTableTags(font: ::sys::CGFontRef) -> CFArrayRef;
141+
fn CGFontCopyTableForTag(font: ::sys::CGFontRef, tag: u32) -> CFDataRef;
121142
}

0 commit comments

Comments
 (0)