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

Add functions to get font tag information #104

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 21 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,6 +107,21 @@ impl CGFont {
CGFontGetUnitsPerEm(self.as_ptr())
}
}

pub fn copy_table_tags(&self) -> CFArray<u32> {
unsafe {
TCFType::wrap_under_create_rule(CGFontCopyTableTags(self.as_ptr()))
}
}

pub fn copy_table_for_tag(&self, tag: u32) -> Option<CFData> {
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")]
Expand Down Expand Up @@ -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;
}