diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index 51711fa2a..f2c9bd3f7 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -152,7 +152,6 @@ struct MyStruct { pub use sixtyfps_macros::sixtyfps; -pub use sixtyfps_corelib::graphics::register_application_font_from_memory; pub use sixtyfps_corelib::model::{ Model, ModelHandle, ModelNotify, ModelPeer, StandardListViewItem, VecModel, }; @@ -160,6 +159,7 @@ pub use sixtyfps_corelib::sharedvector::SharedVector; pub use sixtyfps_corelib::string::SharedString; pub use sixtyfps_corelib::timers::{Timer, TimerMode}; pub use sixtyfps_corelib::{Color, RgbaColor}; +pub use sixtyfps_rendering_backend_default::register_application_font_from_memory; // FIXME: this should not be in this namespace // but the name is `sixtyfps::StateInfo` in builtin.60 diff --git a/sixtyfps_runtime/corelib/Cargo.toml b/sixtyfps_runtime/corelib/Cargo.toml index 3314cb4bb..b79377992 100644 --- a/sixtyfps_runtime/corelib/Cargo.toml +++ b/sixtyfps_runtime/corelib/Cargo.toml @@ -43,7 +43,6 @@ auto_enums = "0.7" stretch = "0.3.2" weak-table = "0.3" femtovg = { git = "https://github.com/femtovg/femtovg", branch = "master", optional = true } -fontdb = "0.5.1" [target.'cfg(target_arch = "wasm32")'.dependencies] instant = { version = "0.1", features = [ "wasm-bindgen", "now" ] } diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index 1c8c50e7d..a41c6d5d6 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -28,7 +28,7 @@ use crate::{Callback, SharedString}; use auto_enums::auto_enum; use const_field_offset::FieldOffsets; use sixtyfps_corelib_macros::*; -use std::{cell::RefCell, rc::Rc}; +use std::rc::Rc; /// 2D Rectangle pub type Rect = euclid::default::Rect; @@ -687,18 +687,3 @@ pub(crate) mod ffi { core::ptr::write(out_coordinates as *mut crate::SharedVector, coordinates.clone()); } } - -thread_local! { - /// Database used to keep track of fonts added by the application - pub static APPLICATION_FONTS: RefCell = RefCell::new(fontdb::Database::new()) -} - -/// This function can be used to register a custom TrueType font with SixtyFPS, -/// for use with the `font-family` property. The provided slice must be a valid TrueType -/// font. -pub fn register_application_font_from_memory( - data: &'static [u8], -) -> Result<(), Box> { - APPLICATION_FONTS.with(|fontdb| fontdb.borrow_mut().load_font_data(data.into())); - Ok(()) -} diff --git a/sixtyfps_runtime/rendering_backends/default/lib.rs b/sixtyfps_runtime/rendering_backends/default/lib.rs index 8009c313e..4507bd966 100644 --- a/sixtyfps_runtime/rendering_backends/default/lib.rs +++ b/sixtyfps_runtime/rendering_backends/default/lib.rs @@ -45,7 +45,10 @@ pub fn create_window() -> ComponentWindow { default_backend::create_window() } -pub use default_backend::{native_widgets, NativeGlobals, NativeWidgets, HAS_NATIVE_STYLE}; +pub use default_backend::{ + native_widgets, register_application_font_from_memory, NativeGlobals, NativeWidgets, + HAS_NATIVE_STYLE, +}; #[doc(hidden)] #[cold] diff --git a/sixtyfps_runtime/rendering_backends/gl/lib.rs b/sixtyfps_runtime/rendering_backends/gl/lib.rs index de7d00d11..ed1c3871f 100644 --- a/sixtyfps_runtime/rendering_backends/gl/lib.rs +++ b/sixtyfps_runtime/rendering_backends/gl/lib.rs @@ -58,6 +58,21 @@ impl Default for FontDatabase { } } +thread_local! { + /// Database used to keep track of fonts added by the application + pub static APPLICATION_FONTS: RefCell = RefCell::new(fontdb::Database::new()) +} + +/// This function can be used to register a custom TrueType font with SixtyFPS, +/// for use with the `font-family` property. The provided slice must be a valid TrueType +/// font. +pub fn register_application_font_from_memory( + data: &'static [u8], +) -> Result<(), Box> { + APPLICATION_FONTS.with(|fontdb| fontdb.borrow_mut().load_font_data(data.into())); + Ok(()) +} + fn try_load_app_font(canvas: &CanvasRc, request: &FontRequest) -> Option { let family = if request.family.is_empty() { fontdb::Family::SansSerif @@ -69,7 +84,7 @@ fn try_load_app_font(canvas: &CanvasRc, request: &FontRequest) -> Option weight: fontdb::Weight(request.weight as u16), ..Default::default() }; - sixtyfps_corelib::graphics::APPLICATION_FONTS.with(|font_db| { + APPLICATION_FONTS.with(|font_db| { let font_db = font_db.borrow(); font_db.query(&query).and_then(|id| font_db.face_source(id)).map(|(source, _index)| { GLFont {