From 66bb295237433eb1e4a6d72eb88e574ba05a913c Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Thu, 16 Nov 2017 22:05:47 -0500 Subject: [PATCH] Add functions to get font tag information --- Cargo.toml | 2 +- src/font.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 91231b8..c2bdb8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,6 @@ elcapitan = [] [dependencies] bitflags = "1.0" -core-foundation = "0.4" +core-foundation = "0.4.5" foreign-types = "0.3.0" libc = "0.2" diff --git a/src/font.rs b/src/font.rs index 73265a7..96e9f33 100644 --- a/src/font.rs +++ b/src/font.rs @@ -7,7 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::ptr; use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType}; +use core_foundation::array::{CFArray, CFArrayRef}; +use core_foundation::data::{CFData, CFDataRef}; use core_foundation::string::{CFString, CFStringRef}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use data_provider::CGDataProvider; @@ -104,6 +107,21 @@ impl CGFont { CGFontGetUnitsPerEm(self.as_ptr()) } } + + pub fn copy_table_tags(&self) -> CFArray { + unsafe { + TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr())) + } + } + + pub fn copy_table_for_tag(&self, tag: u32) -> Option { + let data_ref = unsafe { CGFontCopyTableForTag(self.as_ptr(), tag) }; + if data_ref != ptr::null() { + Some(unsafe { TCFType::wrap_under_create_rule(data_ref) }) + } else { + None + } + } } #[link(name = "CoreGraphics", kind = "framework")] @@ -132,4 +150,7 @@ extern { advances: *mut c_int) -> bool; fn CGFontGetUnitsPerEm(font: ::sys::CGFontRef) -> c_int; + + fn CGFontCopyTableTags(font: ::sys::CGFontRef) -> CFArrayRef; + fn CGFontCopyTableForTag(font: ::sys::CGFontRef, tag: u32) -> CFDataRef; }