diff --git a/Cargo.toml b/Cargo.toml index 1842c3684e4..410231e9ee7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,16 +10,16 @@ members = [ 'api/rs/slint', 'api/wasm-interpreter', 'docs/tutorial/rust/src', - 'examples/7gui', - 'examples/gallery', - 'examples/imagefilter', - 'examples/memory', - 'examples/opengl_underlay', - 'examples/plotter', - 'examples/printerdemo_old/rust', - 'examples/printerdemo/rust', - 'examples/slide_puzzle', - 'examples/todo/rust', + #'examples/7gui', + #'examples/gallery', + #'examples/imagefilter', + #'examples/memory', + #'examples/opengl_underlay', + #'examples/plotter', + #'examples/printerdemo_old/rust', + #'examples/printerdemo/rust', + #'examples/slide_puzzle', + #'examples/todo/rust', 'helper_crates/const-field-offset', 'helper_crates/vtable', 'helper_crates/vtable/macro', @@ -52,12 +52,12 @@ default-members = [ 'api/node/native', 'api/rs/build', 'api/rs/slint', - 'examples/gallery', - 'examples/memory', - 'examples/printerdemo_old/rust', - 'examples/printerdemo/rust', - 'examples/slide_puzzle', - 'examples/todo/rust', + #'examples/gallery', + #'examples/memory', + #'examples/printerdemo_old/rust', + #'examples/printerdemo/rust', + #'examples/slide_puzzle', + #'examples/todo/rust', 'internal/backends/gl', 'internal/backends/qt', 'internal/backends/selector', diff --git a/internal/backends/gl/Cargo.toml b/internal/backends/gl/Cargo.toml index 758a97f7f42..afae93afe5a 100644 --- a/internal/backends/gl/Cargo.toml +++ b/internal/backends/gl/Cargo.toml @@ -20,6 +20,10 @@ path = "lib.rs" svg = ["resvg", "usvg", "tiny-skia"] wayland = ["winit/wayland", "glutin/wayland", "copypasta/wayland"] x11 = ["winit/x11", "glutin/x11", "copypasta/x11"] +# dlopen fontconfig at runtime rather than link at build time. +# useful for cross compiling +# Using a vendored fontconfig C library does not work well, refer to Issue #88. +fontconfig-dlopen = [ "yeslogic-fontconfig-sys/dlopen" ] default = ["svg"] @@ -62,13 +66,11 @@ glutin = { version = "0.28", default-features = false } usvg = { version= "0.20", optional = true, default-features = false, features = ["text", "memmap-fonts"] } [target.'cfg(target_family = "windows")'.dependencies] -font-kit = { version = "0.10", features = [] } +#font-kit = { version = "0.10", features = [] } [target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies] libc = { version = "0.2" } -# Require font-config from the system on Linux. Issue #88 indicates that the copy provided by servo-fontconfig may be incompatible -# with distros at times. -servo-fontconfig = { version = "0.5", features = [ "force_system_lib" ] } +yeslogic-fontconfig-sys = { git = "https://github.com/Be-ing/fontconfig-rs.git", branch = "dlopen" } [target.'cfg(target_os = "macos")'.dependencies] cocoa = { version = "0.24.0" } diff --git a/internal/backends/gl/fonts/fontconfig.rs b/internal/backends/gl/fonts/fontconfig.rs index b5086c09918..143dd68fb72 100644 --- a/internal/backends/gl/fonts/fontconfig.rs +++ b/internal/backends/gl/fonts/fontconfig.rs @@ -1,28 +1,57 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial -use fontconfig::fontconfig; +use fontconfig_sys::ffi_dispatch; +use fontconfig_sys::fontconfig as ffi; + +#[cfg(not(feature = "fontconfig-dlopen"))] +use ffi::*; +#[cfg(feature = "fontconfig-dlopen")] +use ffi::LIB; pub fn find_families(requested_family: &str) -> Vec { unsafe { - let config = fontconfig::FcInitLoadConfigAndFonts(); + let config = ffi_dispatch!(feature = "fontconfig-dlopen", LIB, FcInitLoadConfigAndFonts,); let family_cstr = std::ffi::CString::new(requested_family).unwrap(); - let pattern = fontconfig::FcNameParse(family_cstr.as_ptr() as *mut libc::c_uchar); - fontconfig::FcConfigSubstitute(std::ptr::null_mut(), pattern, fontconfig::FcMatchPattern); - fontconfig::FcDefaultSubstitute(pattern); - let mut sort_result = fontconfig::FcResultMatch; - let result_set = - fontconfig::FcFontSort(config, pattern, 1, std::ptr::null_mut(), &mut sort_result); + let pattern = ffi_dispatch!( + feature = "fontconfig-dlopen", + LIB, + FcNameParse, + family_cstr.as_ptr() as *mut libc::c_uchar + ); + ffi_dispatch!( + feature = "fontconfig-dlopen", + LIB, + FcConfigSubstitute, + std::ptr::null_mut(), + pattern, + ffi::FcMatchPattern + ); + ffi_dispatch!(feature = "fontconfig-dlopen", LIB, FcDefaultSubstitute, pattern); + let mut sort_result = ffi::FcResultMatch; + let result_set = ffi_dispatch!( + feature = "fontconfig-dlopen", + LIB, + FcFontSort, + config, + pattern, + 1, + std::ptr::null_mut(), + &mut sort_result + ); let mut families = Vec::new(); for idx in 0..(*result_set).nfont { let mut raw_family_name = std::ptr::null_mut(); - if fontconfig::FcPatternGetString( + if ffi_dispatch!( + feature = "fontconfig-dlopen", + LIB, + FcPatternGetString, *(*result_set).fonts.offset(idx as isize), b"family\0".as_ptr() as *const libc::c_char, 0, - &mut raw_family_name, - ) != fontconfig::FcResultMatch + &mut raw_family_name + ) != ffi::FcResultMatch { continue; } @@ -40,9 +69,9 @@ pub fn find_families(requested_family: &str) -> Vec { } } - fontconfig::FcFontSetDestroy(result_set); - fontconfig::FcPatternDestroy(pattern); - fontconfig::FcConfigDestroy(config); + ffi_dispatch!(feature = "fontconfig-dlopen", LIB, FcFontSetDestroy, result_set); + ffi_dispatch!(feature = "fontconfig-dlopen", LIB, FcPatternDestroy, pattern); + ffi_dispatch!(feature = "fontconfig-dlopen", LIB, FcConfigDestroy, config); families } }