Debian Codegraph @

third_party/rust/core-text/src/font_manager.rs

raw
1 // Copyright 2013 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 use crate::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
11 use core_foundation::array::{CFArray, CFArrayRef};
12 use core_foundation::base::TCFType;
13 use core_foundation::data::{CFData, CFDataRef};
14 use core_foundation::string::CFString;
15 use core_foundation::url::CFURLRef;
16
17 pub fn copy_available_font_family_names() -> CFArray<CFString> {
18 unsafe { TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) }
19 }
20
21 pub fn create_font_descriptor(buffer: &[u8]) -> Result<CTFontDescriptor, ()> {
22 let cf_data = CFData::from_buffer(buffer);
23 unsafe {
24 let ct_font_descriptor_ref =
25 CTFontManagerCreateFontDescriptorFromData(cf_data.as_concrete_TypeRef());
26 if ct_font_descriptor_ref.is_null() {
27 return Err(());
28 }
29 Ok(CTFontDescriptor::wrap_under_create_rule(
30 ct_font_descriptor_ref,
31 ))
32 }
33 }
34
35 pub fn create_font_descriptor_with_data(data: CFData) -> Result<CTFontDescriptor, ()> {
36 unsafe {
37 let ct_font_descriptor_ref =
38 CTFontManagerCreateFontDescriptorFromData(data.as_concrete_TypeRef());
39 if ct_font_descriptor_ref.is_null() {
40 return Err(());
41 }
42 Ok(CTFontDescriptor::wrap_under_create_rule(
43 ct_font_descriptor_ref,
44 ))
45 }
46 }
47
48 extern "C" {
49 /*
50 * CTFontManager.h
51 */
52
53 // Incomplete function bindings are mostly related to CoreText font matching, which
54 // we implement in a platform-independent manner using FontMatcher.
55
56 //pub fn CTFontManagerCompareFontFamilyNames
57 pub fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef;
58 pub fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef;
59 pub fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef;
60 pub fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef;
61 pub fn CTFontManagerCreateFontDescriptorFromData(data: CFDataRef) -> CTFontDescriptorRef;
62 //pub fn CTFontManagerCreateFontRequestRunLoopSource
63 //pub fn CTFontManagerEnableFontDescriptors
64 //pub fn CTFontManagerGetAutoActivationSetting
65 //pub fn CTFontManagerGetScopeForURL
66 //pub fn CTFontManagerGetAutoActivationSetting
67 //pub fn CTFontManagerGetScopeForURL
68 pub fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool;
69 //pub fn CTFontManagerRegisterFontsForURL
70 //pub fn CTFontManagerRegisterFontsForURLs
71 //pub fn CTFontManagerRegisterGraphicsFont
72 //pub fn CTFontManagerSetAutoActivationSetting
73 //pub fn CTFontManagerUnregisterFontsForURL
74 //pub fn CTFontManagerUnregisterFontsForURLs
75 //pub fn CTFontManagerUnregisterGraphicsFont
76 }