forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to yeslogic-fontconfig-sys from servo-fontconfig
This allows setting the RUST_FONTCONFIG_DLOPEN environment variable to dlopen fontconfig at runtime rather than linking it at build time. This is helpful for cross compiling to Linux, particularly because fontconfig has lots of C dependencies. Building a vendored copy of fontconfig does not work as expected: slint-ui#88
- Loading branch information
Showing
7 changed files
with
127 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright © SixtyFPS GmbH <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN"); | ||
let dlopen = std::env::var("RUST_FONTCONFIG_DLOPEN").is_ok(); | ||
if dlopen { | ||
println!("cargo:rustc-cfg=feature=\"fontconfig-dlopen\""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,58 @@ | ||
// Copyright © SixtyFPS GmbH <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial | ||
|
||
use fontconfig::fontconfig; | ||
use fontconfig_sys as ffi; | ||
use fontconfig_sys::ffi_dispatch; | ||
|
||
#[cfg(feature = "fontconfig-dlopen")] | ||
use ffi::statics::LIB; | ||
#[cfg(not(feature = "fontconfig-dlopen"))] | ||
use ffi::*; | ||
|
||
// This is duplicated in the slint-compiler's glyph embedding code | ||
pub fn find_families(requested_family: &str) -> Vec<String> { | ||
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; | ||
} | ||
|
@@ -41,9 +70,9 @@ pub fn find_families(requested_family: &str) -> Vec<String> { | |
} | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,59 @@ | ||
// Copyright © SixtyFPS GmbH <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial | ||
|
||
use fontconfig::fontconfig; | ||
use fontconfig_sys as ffi; | ||
use fontconfig_sys::ffi_dispatch; | ||
|
||
// This is duplicated from the GL backend | ||
#[cfg(feature = "fontconfig-dlopen")] | ||
use ffi::statics::LIB; | ||
#[cfg(not(feature = "fontconfig-dlopen"))] | ||
use ffi::*; | ||
|
||
// This is duplicated in the slint-compiler's glyph embedding code | ||
pub fn find_families(requested_family: &str) -> Vec<String> { | ||
#[allow(unsafe_code)] | ||
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; | ||
} | ||
|
@@ -42,9 +71,9 @@ pub fn find_families(requested_family: &str) -> Vec<String> { | |
} | ||
} | ||
|
||
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 | ||
} | ||
} |