summaryrefslogtreecommitdiffstats
path: root/third_party/rust/core-text/src/font_manager.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/core-text/src/font_manager.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/core-text/src/font_manager.rs')
-rw-r--r--third_party/rust/core-text/src/font_manager.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/third_party/rust/core-text/src/font_manager.rs b/third_party/rust/core-text/src/font_manager.rs
new file mode 100644
index 0000000000..dff0f8d0fb
--- /dev/null
+++ b/third_party/rust/core-text/src/font_manager.rs
@@ -0,0 +1,76 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use crate::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
+use core_foundation::array::{CFArray, CFArrayRef};
+use core_foundation::base::TCFType;
+use core_foundation::data::{CFData, CFDataRef};
+use core_foundation::string::CFString;
+use core_foundation::url::CFURLRef;
+
+pub fn copy_available_font_family_names() -> CFArray<CFString> {
+ unsafe { TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) }
+}
+
+pub fn create_font_descriptor(buffer: &[u8]) -> Result<CTFontDescriptor, ()> {
+ let cf_data = CFData::from_buffer(buffer);
+ unsafe {
+ let ct_font_descriptor_ref =
+ CTFontManagerCreateFontDescriptorFromData(cf_data.as_concrete_TypeRef());
+ if ct_font_descriptor_ref.is_null() {
+ return Err(());
+ }
+ Ok(CTFontDescriptor::wrap_under_create_rule(
+ ct_font_descriptor_ref,
+ ))
+ }
+}
+
+pub fn create_font_descriptor_with_data(data: CFData) -> Result<CTFontDescriptor, ()> {
+ unsafe {
+ let ct_font_descriptor_ref =
+ CTFontManagerCreateFontDescriptorFromData(data.as_concrete_TypeRef());
+ if ct_font_descriptor_ref.is_null() {
+ return Err(());
+ }
+ Ok(CTFontDescriptor::wrap_under_create_rule(
+ ct_font_descriptor_ref,
+ ))
+ }
+}
+
+extern "C" {
+ /*
+ * CTFontManager.h
+ */
+
+ // Incomplete function bindings are mostly related to CoreText font matching, which
+ // we implement in a platform-independent manner using FontMatcher.
+
+ //pub fn CTFontManagerCompareFontFamilyNames
+ pub fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef;
+ pub fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef;
+ pub fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef;
+ pub fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef;
+ pub fn CTFontManagerCreateFontDescriptorFromData(data: CFDataRef) -> CTFontDescriptorRef;
+ //pub fn CTFontManagerCreateFontRequestRunLoopSource
+ //pub fn CTFontManagerEnableFontDescriptors
+ //pub fn CTFontManagerGetAutoActivationSetting
+ //pub fn CTFontManagerGetScopeForURL
+ //pub fn CTFontManagerGetAutoActivationSetting
+ //pub fn CTFontManagerGetScopeForURL
+ pub fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool;
+ //pub fn CTFontManagerRegisterFontsForURL
+ //pub fn CTFontManagerRegisterFontsForURLs
+ //pub fn CTFontManagerRegisterGraphicsFont
+ //pub fn CTFontManagerSetAutoActivationSetting
+ //pub fn CTFontManagerUnregisterFontsForURL
+ //pub fn CTFontManagerUnregisterFontsForURLs
+ //pub fn CTFontManagerUnregisterGraphicsFont
+}