From 8380931660052d024a23f2b01cc45dd555e8832a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 30 Sep 2015 17:50:30 -0700 Subject: [PATCH] Allow the URL of the Core Text font to be fetched. This allows FreeType to load Core Text fonts, which is necessary for WebRender (unless we want a Quartz backend for WebRender). --- src/font.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/font.rs b/src/font.rs index b93c639..80ce3f0 100644 --- a/src/font.rs +++ b/src/font.rs @@ -16,6 +16,7 @@ use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFRetai use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; +use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; @@ -293,6 +294,17 @@ impl CTFont { } } } + + pub fn url(&self) -> Option { + unsafe { + let result = CTFontCopyAttribute(self.obj, kCTFontURLAttribute); + if result.is_null() { + None + } else { + Some(TCFType::wrap_under_create_rule(result as CFURLRef)) + } + } + } } // Helper methods @@ -376,6 +388,8 @@ extern { //static kCTFontFeatureSelectorDefaultKey: CFStringRef; //static kCTFontFeatureSelectorSettingKey: CFStringRef; + static kCTFontURLAttribute: CFStringRef; + // N.B. Unlike most Cocoa bindings, this extern block is organized according // to the documentation's Functions By Task listing, because there so many functions. @@ -394,7 +408,7 @@ extern { /* Getting Font Data */ //fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; - //fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; + fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; fn CTFontGetSize(font: CTFontRef) -> CGFloat; //fn CTFontGetMatrix fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits;