From bada19954f634ad06df2256af73b007bc18341c6 Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 14 Feb 2022 16:29:32 -0600 Subject: [PATCH] add dlopen Cargo feature using dlib to load fontconfig at runtime Fixes https://github.com/yeslogic/fontconfig-rs/issues/11 --- .travis.yml | 2 +- fontconfig-sys/Cargo.toml | 7 +- fontconfig-sys/build.rs | 1 + fontconfig-sys/src/fontconfig.rs | 747 ++++++++++++++++--------------- fontconfig-sys/src/lib.rs | 9 +- fontconfig/Cargo.toml | 5 + fontconfig/src/lib.rs | 59 ++- 7 files changed, 436 insertions(+), 394 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85772a3..b804753 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ rust: - nightly - beta - stable - - 1.38.0 + - 1.43.0 jobs: allow_failures: diff --git a/fontconfig-sys/Cargo.toml b/fontconfig-sys/Cargo.toml index db21df3..73f1d84 100644 --- a/fontconfig-sys/Cargo.toml +++ b/fontconfig-sys/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "yeslogic-fontconfig-sys" version = "2.11.2" +edition = "2018" authors = [ "Austin Bonander ", "The Servo Project Developers", @@ -16,7 +17,6 @@ homepage = "https://github.com/yeslogic/fontconfig-rs" documentation = "https://docs.rs/crate/yeslogic-fontconfig-sys" repository = "https://github.com/yeslogic/fontconfig-rs" -build = "build.rs" links = "fontconfig" [badges] @@ -27,6 +27,11 @@ name = "fontconfig_sys" [dependencies] const-cstr = "0.3" +dlib = "0.5.0" +lazy_static = { verison = "1.4.0", optional = true } + +[features] +dlopen = [ "lazy_static" ] [build-dependencies] pkg-config = "0.3" diff --git a/fontconfig-sys/build.rs b/fontconfig-sys/build.rs index 2dd4282..f07a959 100644 --- a/fontconfig-sys/build.rs +++ b/fontconfig-sys/build.rs @@ -1,5 +1,6 @@ extern crate pkg_config; fn main() { + #[cfg(not(feature = "dlopen"))] pkg_config::find_library("fontconfig").unwrap(); } diff --git a/fontconfig-sys/src/fontconfig.rs b/fontconfig-sys/src/fontconfig.rs index 150dd61..3ffd165 100644 --- a/fontconfig-sys/src/fontconfig.rs +++ b/fontconfig-sys/src/fontconfig.rs @@ -9,6 +9,24 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +#[cfg(feature = "dlopen")] +static SONAME: &str = if cfg!(windows) { + "libfontconfig.dll" +} else if cfg!(target_vendor = "apple") { + "libfontconfig.dylib.1" +} else { + "libfontconfig.so.1" +}; + +#[cfg(feature = "dlopen")] +lazy_static::lazy_static! { + pub static ref LIB: &'static Fc = LIB_RESULT.as_ref().unwrap(); + + pub static ref LIB_RESULT: Result = + unsafe { Fc::open(SONAME) }; +} use std::os::raw::{c_char, c_double, c_int, c_uchar, c_uint, c_ushort, c_void}; @@ -286,550 +304,549 @@ pub type FcCache = struct__FcCache; pub type union_unnamed1 = c_void; -extern "C" { - - pub fn FcBlanksCreate() -> *mut FcBlanks; - - pub fn FcBlanksDestroy(b: *mut FcBlanks); +dlib::external_library!(Fc, "fontconfig", + functions: + fn FcBlanksCreate() -> *mut FcBlanks, - pub fn FcBlanksAdd(b: *mut FcBlanks, ucs4: FcChar32) -> FcBool; + fn FcBlanksDestroy(*mut FcBlanks) -> (), - pub fn FcBlanksIsMember(b: *mut FcBlanks, ucs4: FcChar32) -> FcBool; + fn FcBlanksAdd(*mut FcBlanks, FcChar32) -> FcBool, - pub fn FcCacheDir(c: *mut FcCache) -> *const FcChar8; + fn FcBlanksIsMember(*mut FcBlanks, FcChar32) -> FcBool, - pub fn FcCacheCopySet(c: *const FcCache) -> *mut FcFontSet; + fn FcCacheDir(*mut FcCache) -> *const FcChar8, - pub fn FcCacheSubdir(c: *const FcCache, i: c_int) -> *const FcChar8; + fn FcCacheCopySet(*const FcCache) -> *mut FcFontSet, - pub fn FcCacheNumSubdir(c: *const FcCache) -> c_int; + fn FcCacheSubdir(*const FcCache, c_int) -> *const FcChar8, - pub fn FcCacheNumFont(c: *const FcCache) -> c_int; + fn FcCacheNumSubdir(*const FcCache) -> c_int, - pub fn FcDirCacheUnlink(dir: *const FcChar8, config: *mut FcConfig) -> FcBool; + fn FcCacheNumFont(*const FcCache) -> c_int, - pub fn FcDirCacheValid(cache_file: *const FcChar8) -> FcBool; + fn FcDirCacheUnlink(*const FcChar8, *mut FcConfig) -> FcBool, - pub fn FcConfigHome() -> *mut FcChar8; + fn FcDirCacheValid(*const FcChar8) -> FcBool, - pub fn FcConfigEnableHome(enable: FcBool) -> FcBool; + fn FcConfigHome() -> *mut FcChar8, - pub fn FcConfigFilename(url: *const FcChar8) -> *mut FcChar8; + fn FcConfigEnableHome(FcBool) -> FcBool, - pub fn FcConfigCreate() -> *mut FcConfig; + fn FcConfigFilename(*const FcChar8) -> *mut FcChar8, - pub fn FcConfigReference(config: *mut FcConfig) -> *mut FcConfig; + fn FcConfigCreate() -> *mut FcConfig, - pub fn FcConfigDestroy(config: *mut FcConfig); + fn FcConfigReference(*mut FcConfig) -> *mut FcConfig, - pub fn FcConfigSetCurrent(config: *mut FcConfig) -> FcBool; + fn FcConfigDestroy(*mut FcConfig) -> (), - pub fn FcConfigGetCurrent() -> *mut FcConfig; + fn FcConfigSetCurrent(*mut FcConfig) -> FcBool, - pub fn FcConfigUptoDate(config: *mut FcConfig) -> FcBool; + fn FcConfigGetCurrent() -> *mut FcConfig, - pub fn FcConfigBuildFonts(config: *mut FcConfig) -> FcBool; + fn FcConfigUptoDate(*mut FcConfig) -> FcBool, - pub fn FcConfigGetFontDirs(config: *mut FcConfig) -> *mut FcStrList; + fn FcConfigBuildFonts(*mut FcConfig) -> FcBool, - pub fn FcConfigGetConfigDirs(config: *mut FcConfig) -> *mut FcStrList; + fn FcConfigGetFontDirs(*mut FcConfig) -> *mut FcStrList, - pub fn FcConfigGetConfigFiles(config: *mut FcConfig) -> *mut FcStrList; + fn FcConfigGetConfigDirs(*mut FcConfig) -> *mut FcStrList, - pub fn FcConfigGetCache(config: *mut FcConfig) -> *mut FcChar8; + fn FcConfigGetConfigFiles(*mut FcConfig) -> *mut FcStrList, - pub fn FcConfigGetBlanks(config: *mut FcConfig) -> *mut FcBlanks; + fn FcConfigGetCache(*mut FcConfig) -> *mut FcChar8, - pub fn FcConfigGetCacheDirs(config: *const FcConfig) -> *mut FcStrList; + fn FcConfigGetBlanks(*mut FcConfig) -> *mut FcBlanks, - pub fn FcConfigGetRescanInterval(config: *mut FcConfig) -> c_int; + fn FcConfigGetCacheDirs(*const FcConfig) -> *mut FcStrList, - pub fn FcConfigSetRescanInterval(config: *mut FcConfig, rescanInterval: c_int) -> FcBool; + fn FcConfigGetRescanInterval(*mut FcConfig) -> c_int, - pub fn FcConfigGetFonts(config: *mut FcConfig, set: FcSetName) -> *mut FcFontSet; + fn FcConfigSetRescanInterval(*mut FcConfig, c_int) -> FcBool, - pub fn FcConfigAppFontAddFile(config: *mut FcConfig, file: *const FcChar8) -> FcBool; + fn FcConfigGetFonts(*mut FcConfig, FcSetName) -> *mut FcFontSet, - pub fn FcConfigAppFontAddDir(config: *mut FcConfig, dir: *const FcChar8) -> FcBool; + fn FcConfigAppFontAddFile(*mut FcConfig, *const FcChar8) -> FcBool, - pub fn FcConfigAppFontClear(config: *mut FcConfig); + fn FcConfigAppFontAddDir(*mut FcConfig, *const FcChar8) -> FcBool, - pub fn FcConfigSubstituteWithPat( - config: *mut FcConfig, - p: *mut FcPattern, - p_pat: *mut FcPattern, - kind: FcMatchKind, - ) -> FcBool; + fn FcConfigAppFontClear(*mut FcConfig) -> (), - pub fn FcConfigSubstitute( - config: *mut FcConfig, - p: *mut FcPattern, - kind: FcMatchKind, - ) -> FcBool; + fn FcConfigSubstituteWithPat( + *mut FcConfig, + *mut FcPattern, + *mut FcPattern, + FcMatchKind + ) -> FcBool, - pub fn FcCharSetCreate() -> *mut FcCharSet; + fn FcConfigSubstitute( + *mut FcConfig, + *mut FcPattern, + FcMatchKind + ) -> FcBool, - pub fn FcCharSetNew() -> *mut FcCharSet; + fn FcCharSetCreate() -> *mut FcCharSet, - pub fn FcCharSetDestroy(fcs: *mut FcCharSet); + fn FcCharSetNew() -> *mut FcCharSet, - pub fn FcCharSetAddChar(fcs: *mut FcCharSet, ucs4: FcChar32) -> FcBool; + fn FcCharSetDestroy(*mut FcCharSet) -> (), - pub fn FcCharSetCopy(src: *mut FcCharSet) -> *mut FcCharSet; + fn FcCharSetAddChar(*mut FcCharSet, FcChar32) -> FcBool, - pub fn FcCharSetEqual(a: *const FcCharSet, b: *const FcCharSet) -> FcBool; + fn FcCharSetCopy(*mut FcCharSet) -> *mut FcCharSet, - pub fn FcCharSetIntersect(a: *const FcCharSet, b: *const FcCharSet) -> *mut FcCharSet; + fn FcCharSetEqual(*const FcCharSet, *const FcCharSet) -> FcBool, - pub fn FcCharSetUnion(a: *const FcCharSet, b: *const FcCharSet) -> *mut FcCharSet; + fn FcCharSetIntersect(*const FcCharSet, *const FcCharSet) -> *mut FcCharSet, - pub fn FcCharSetSubtract(a: *const FcCharSet, b: *const FcCharSet) -> *mut FcCharSet; + fn FcCharSetUnion(*const FcCharSet, *const FcCharSet) -> *mut FcCharSet, - pub fn FcCharSetMerge(a: *mut FcCharSet, b: *const FcCharSet, changed: *mut FcBool) -> FcBool; + fn FcCharSetSubtract(*const FcCharSet, *const FcCharSet) -> *mut FcCharSet, - pub fn FcCharSetHasChar(fcs: *const FcCharSet, ucs4: FcChar32) -> FcBool; + fn FcCharSetMerge(*mut FcCharSet, *const FcCharSet, *mut FcBool) -> FcBool, - pub fn FcCharSetCount(a: *const FcCharSet) -> FcChar32; + fn FcCharSetHasChar(*const FcCharSet, FcChar32) -> FcBool, - pub fn FcCharSetIntersectCount(a: *const FcCharSet, b: *const FcCharSet) -> FcChar32; + fn FcCharSetCount(*const FcCharSet) -> FcChar32, - pub fn FcCharSetSubtractCount(a: *const FcCharSet, b: *const FcCharSet) -> FcChar32; + fn FcCharSetIntersectCount(*const FcCharSet, *const FcCharSet) -> FcChar32, - pub fn FcCharSetIsSubset(a: *const FcCharSet, bi: *const FcCharSet) -> FcBool; + fn FcCharSetSubtractCount(*const FcCharSet, *const FcCharSet) -> FcChar32, - pub fn FcCharSetFirstPage( - a: *const FcCharSet, - map: *mut FcChar32, - next: *mut FcChar32, - ) -> FcChar32; + fn FcCharSetIsSubset(*const FcCharSet, *const FcCharSet) -> FcBool, - pub fn FcCharSetNextPage( - a: *const FcCharSet, - map: *mut FcChar32, - next: *mut FcChar32, - ) -> FcChar32; + fn FcCharSetFirstPage( + *const FcCharSet, + *mut FcChar32, + *mut FcChar32 + ) -> FcChar32, - pub fn FcCharSetCoverage( - a: *const FcCharSet, - page: FcChar32, - result: *mut FcChar32, - ) -> FcChar32; + fn FcCharSetNextPage( + *const FcCharSet, + *mut FcChar32, + *mut FcChar32 + ) -> FcChar32, - pub fn FcValuePrint(v: FcValue); + fn FcCharSetCoverage( + *const FcCharSet, + FcChar32, + *mut FcChar32 + ) -> FcChar32, - pub fn FcPatternPrint(p: *const FcPattern); + fn FcValuePrint(FcValue) -> (), - pub fn FcFontSetPrint(s: *mut FcFontSet); + fn FcPatternPrint(*const FcPattern) -> (), - pub fn FcDefaultSubstitute(pattern: *mut FcPattern); + fn FcFontSetPrint(*mut FcFontSet) -> (), - pub fn FcFileIsDir(file: *const FcChar8) -> FcBool; + fn FcDefaultSubstitute(*mut FcPattern) -> (), - pub fn FcFileScan( - set: *mut FcFontSet, - dirs: *mut FcStrSet, - cache: *mut FcFileCache, - blanks: *mut FcBlanks, - file: *const FcChar8, - force: FcBool, - ) -> FcBool; + fn FcFileIsDir(*const FcChar8) -> FcBool, - pub fn FcDirScan( - set: *mut FcFontSet, - dirs: *mut FcStrSet, - cache: *mut FcFileCache, - blanks: *mut FcBlanks, - dir: *const FcChar8, - force: FcBool, - ) -> FcBool; + fn FcFileScan( + *mut FcFontSet, + *mut FcStrSet, + *mut FcFileCache, + *mut FcBlanks, + *const FcChar8, + FcBool + ) -> FcBool, - pub fn FcDirSave(set: *mut FcFontSet, dirs: *const FcStrSet, dir: *mut FcChar8) -> FcBool; + fn FcDirScan( + *mut FcFontSet, + *mut FcStrSet, + *mut FcFileCache, + *mut FcBlanks, + *const FcChar8, + FcBool + ) -> FcBool, - pub fn FcDirCacheLoad( - dir: *const FcChar8, - config: *mut FcConfig, - cache_file: *mut *mut FcChar8, - ) -> *mut FcCache; + fn FcDirSave(*mut FcFontSet, *const FcStrSet, *mut FcChar8) -> FcBool, - pub fn FcDirCacheRead( - dir: *const FcChar8, - force: FcBool, - config: *mut FcConfig, - ) -> *mut FcCache; + fn FcDirCacheLoad( + *const FcChar8, + *mut FcConfig, + *mut *mut FcChar8 + ) -> *mut FcCache, - //pub fn FcDirCacheLoadFile(cache_file: *mut FcChar8, file_stat: *mut struct_stat) -> *mut FcCache; + fn FcDirCacheRead( + *const FcChar8, + FcBool, + *mut FcConfig + ) -> *mut FcCache, - pub fn FcDirCacheUnload(cache: *mut FcCache); + // fn FcDirCacheLoadFile(*mut FcChar8, *mut struct_stat) -> *mut FcCache, - pub fn FcFreeTypeQuery( - file: *const FcChar8, - id: c_int, - blanks: *mut FcBlanks, - count: *mut c_int, - ) -> *mut FcPattern; + fn FcDirCacheUnload(*mut FcCache) -> (), - pub fn FcFontSetCreate() -> *mut FcFontSet; + fn FcFreeTypeQuery( + *const FcChar8, + c_int, + *mut FcBlanks, + *mut c_int + ) -> *mut FcPattern, - pub fn FcFontSetDestroy(s: *mut FcFontSet); + fn FcFontSetCreate() -> *mut FcFontSet, - pub fn FcFontSetAdd(s: *mut FcFontSet, font: *mut FcPattern) -> FcBool; + fn FcFontSetDestroy(*mut FcFontSet) -> (), - pub fn FcInitLoadConfig() -> *mut FcConfig; + fn FcFontSetAdd(*mut FcFontSet, *mut FcPattern) -> FcBool, - pub fn FcInitLoadConfigAndFonts() -> *mut FcConfig; + fn FcInitLoadConfig() -> *mut FcConfig, - pub fn FcInit() -> FcBool; + fn FcInitLoadConfigAndFonts() -> *mut FcConfig, - pub fn FcFini(); + fn FcInit() -> FcBool, - pub fn FcGetVersion() -> c_int; + fn FcFini() -> (), - pub fn FcInitReinitialize() -> FcBool; + fn FcGetVersion() -> c_int, - pub fn FcInitBringUptoDate() -> FcBool; + fn FcInitReinitialize() -> FcBool, - pub fn FcGetLangs() -> *mut FcStrSet; + fn FcInitBringUptoDate() -> FcBool, - pub fn FcLangGetCharSet(lang: *const FcChar8) -> *mut FcCharSet; + fn FcGetLangs() -> *mut FcStrSet, - pub fn FcLangSetCreate() -> *mut FcLangSet; + fn FcLangGetCharSet(*const FcChar8) -> *mut FcCharSet, - pub fn FcLangSetDestroy(ls: *mut FcLangSet); + fn FcLangSetCreate() -> *mut FcLangSet, - pub fn FcLangSetCopy(ls: *const FcLangSet) -> *mut FcLangSet; + fn FcLangSetDestroy(*mut FcLangSet) -> (), - pub fn FcLangSetAdd(ls: *mut FcLangSet, lang: *const FcChar8) -> FcBool; + fn FcLangSetCopy(*const FcLangSet) -> *mut FcLangSet, - pub fn FcLangSetHasLang(ls: *const FcLangSet, lang: *const FcChar8) -> FcLangResult; + fn FcLangSetAdd(*mut FcLangSet, *const FcChar8) -> FcBool, - pub fn FcLangSetCompare(lsa: *const FcLangSet, lsb: *const FcLangSet) -> FcLangResult; + fn FcLangSetHasLang(*const FcLangSet, *const FcChar8) -> FcLangResult, - pub fn FcLangSetContains(lsa: *const FcLangSet, lsb: *const FcLangSet) -> FcBool; + fn FcLangSetCompare(*const FcLangSet, *const FcLangSet) -> FcLangResult, - pub fn FcLangSetEqual(lsa: *const FcLangSet, lsb: *const FcLangSet) -> FcBool; + fn FcLangSetContains(*const FcLangSet, *const FcLangSet) -> FcBool, - pub fn FcLangSetHash(ls: *const FcLangSet) -> FcChar32; + fn FcLangSetEqual(*const FcLangSet, *const FcLangSet) -> FcBool, - pub fn FcLangSetGetLangs(ls: *const FcLangSet) -> *mut FcStrSet; + fn FcLangSetHash(*const FcLangSet) -> FcChar32, - pub fn FcObjectSetCreate() -> *mut FcObjectSet; + fn FcLangSetGetLangs(*const FcLangSet) -> *mut FcStrSet, - pub fn FcObjectSetAdd(os: *mut FcObjectSet, object: *const c_char) -> FcBool; + fn FcObjectSetCreate() -> *mut FcObjectSet, - pub fn FcObjectSetDestroy(os: *mut FcObjectSet); + fn FcObjectSetAdd(*mut FcObjectSet, *const c_char) -> FcBool, - //pub fn FcObjectSetVaBuild(first: *mut c_char, va: *mut __va_list_tag) -> *mut FcObjectSet; + fn FcObjectSetDestroy(*mut FcObjectSet) -> (), - pub fn FcObjectSetBuild(first: *mut c_char, ...) -> *mut FcObjectSet; + // fn FcObjectSetVaBuild(*mut c_char, *mut __va_list_tag) -> *mut FcObjectSet, - pub fn FcFontSetList( - config: *mut FcConfig, - sets: *mut *mut FcFontSet, - nsets: c_int, - p: *mut FcPattern, - os: *mut FcObjectSet, - ) -> *mut FcFontSet; + fn FcFontSetList( + *mut FcConfig, + *mut *mut FcFontSet, + c_int, + *mut FcPattern, + *mut FcObjectSet + ) -> *mut FcFontSet, - pub fn FcFontList( - config: *mut FcConfig, - p: *mut FcPattern, - os: *mut FcObjectSet, - ) -> *mut FcFontSet; + fn FcFontList( + *mut FcConfig, + *mut FcPattern, + *mut FcObjectSet + ) -> *mut FcFontSet, - pub fn FcAtomicCreate(file: *const FcChar8) -> *mut FcAtomic; + fn FcAtomicCreate(*const FcChar8) -> *mut FcAtomic, - pub fn FcAtomicLock(atomic: *mut FcAtomic) -> FcBool; + fn FcAtomicLock(*mut FcAtomic) -> FcBool, - pub fn FcAtomicNewFile(atomic: *mut FcAtomic) -> *mut FcChar8; + fn FcAtomicNewFile(*mut FcAtomic) -> *mut FcChar8, - pub fn FcAtomicOrigFile(atomic: *mut FcAtomic) -> *mut FcChar8; + fn FcAtomicOrigFile(*mut FcAtomic) -> *mut FcChar8, - pub fn FcAtomicReplaceOrig(atomic: *mut FcAtomic) -> FcBool; + fn FcAtomicReplaceOrig(*mut FcAtomic) -> FcBool, - pub fn FcAtomicDeleteNew(atomic: *mut FcAtomic); + fn FcAtomicDeleteNew(*mut FcAtomic) -> (), - pub fn FcAtomicUnlock(atomic: *mut FcAtomic); + fn FcAtomicUnlock(*mut FcAtomic) -> (), - pub fn FcAtomicDestroy(atomic: *mut FcAtomic); + fn FcAtomicDestroy(*mut FcAtomic) -> (), - pub fn FcFontSetMatch( - config: *mut FcConfig, - sets: *mut *mut FcFontSet, - nsets: c_int, - p: *mut FcPattern, - result: *mut FcResult, - ) -> *mut FcPattern; + fn FcFontSetMatch( + *mut FcConfig, + *mut *mut FcFontSet, + c_int, + *mut FcPattern, + *mut FcResult + ) -> *mut FcPattern, - pub fn FcFontMatch( - config: *mut FcConfig, - p: *mut FcPattern, - result: *mut FcResult, - ) -> *mut FcPattern; + fn FcFontMatch( + *mut FcConfig, + *mut FcPattern, + *mut FcResult + ) -> *mut FcPattern, - pub fn FcFontRenderPrepare( - config: *mut FcConfig, - pat: *mut FcPattern, - font: *mut FcPattern, - ) -> *mut FcPattern; + fn FcFontRenderPrepare( + *mut FcConfig, + *mut FcPattern, + *mut FcPattern + ) -> *mut FcPattern, - pub fn FcFontSetSort( - config: *mut FcConfig, - sets: *mut *mut FcFontSet, - nsets: c_int, - p: *mut FcPattern, - trim: FcBool, - csp: *mut *mut FcCharSet, - result: *mut FcResult, - ) -> *mut FcFontSet; + fn FcFontSetSort( + *mut FcConfig, + *mut *mut FcFontSet, + c_int, + *mut FcPattern, + FcBool, + *mut *mut FcCharSet, + *mut FcResult + ) -> *mut FcFontSet, - pub fn FcFontSort( - config: *mut FcConfig, - p: *mut FcPattern, - trim: FcBool, - csp: *mut *mut FcCharSet, - result: *mut FcResult, - ) -> *mut FcFontSet; + fn FcFontSort( + *mut FcConfig, + *mut FcPattern, + FcBool, + *mut *mut FcCharSet, + *mut FcResult + ) -> *mut FcFontSet, - pub fn FcFontSetSortDestroy(fs: *mut FcFontSet); + fn FcFontSetSortDestroy(*mut FcFontSet) -> (), - pub fn FcMatrixCopy(mat: *const FcMatrix) -> *mut FcMatrix; + fn FcMatrixCopy(*const FcMatrix) -> *mut FcMatrix, - pub fn FcMatrixEqual(mat1: *const FcMatrix, mat2: *const FcMatrix) -> FcBool; + fn FcMatrixEqual(*const FcMatrix, *const FcMatrix) -> FcBool, - pub fn FcMatrixMultiply(result: *mut FcMatrix, a: *const FcMatrix, b: *const FcMatrix); + fn FcMatrixMultiply(*mut FcMatrix, *const FcMatrix, *const FcMatrix) -> (), - pub fn FcMatrixRotate(m: *mut FcMatrix, c: c_double, s: c_double); + fn FcMatrixRotate(*mut FcMatrix, c_double, c_double) -> (), - pub fn FcMatrixScale(m: *mut FcMatrix, sx: c_double, sy: c_double); + fn FcMatrixScale(*mut FcMatrix, c_double, c_double) -> (), - pub fn FcMatrixShear(m: *mut FcMatrix, sh: c_double, sv: c_double); + fn FcMatrixShear(*mut FcMatrix, c_double, c_double) -> (), - pub fn FcNameRegisterObjectTypes(types: *const FcObjectType, ntype: c_int) -> FcBool; + fn FcNameRegisterObjectTypes(*const FcObjectType, c_int) -> FcBool, - pub fn FcNameUnregisterObjectTypes(types: *const FcObjectType, ntype: c_int) -> FcBool; + fn FcNameUnregisterObjectTypes(*const FcObjectType, c_int) -> FcBool, - pub fn FcNameGetObjectType(object: *const c_char) -> *const FcObjectType; + fn FcNameGetObjectType(*const c_char) -> *const FcObjectType, - pub fn FcNameRegisterConstants(consts: *const FcConstant, nconsts: c_int) -> FcBool; + fn FcNameRegisterConstants(*const FcConstant, c_int) -> FcBool, - pub fn FcNameUnregisterConstants(consts: *const FcConstant, nconsts: c_int) -> FcBool; + fn FcNameUnregisterConstants(*const FcConstant, c_int) -> FcBool, - pub fn FcNameGetConstant(string: *mut FcChar8) -> *const FcConstant; + fn FcNameGetConstant(*mut FcChar8) -> *const FcConstant, - pub fn FcNameConstant(string: *mut FcChar8, result: *mut c_int) -> FcBool; + fn FcNameConstant(*mut FcChar8, *mut c_int) -> FcBool, - pub fn FcNameParse(name: *const FcChar8) -> *mut FcPattern; + fn FcNameParse(*const FcChar8) -> *mut FcPattern, - pub fn FcNameUnparse(pat: *mut FcPattern) -> *mut FcChar8; + fn FcNameUnparse(*mut FcPattern) -> *mut FcChar8, - pub fn FcPatternCreate() -> *mut FcPattern; + fn FcPatternCreate() -> *mut FcPattern, - pub fn FcPatternDuplicate(p: *const FcPattern) -> *mut FcPattern; + fn FcPatternDuplicate(*const FcPattern) -> *mut FcPattern, - pub fn FcPatternReference(p: *mut FcPattern); + fn FcPatternReference(*mut FcPattern) -> (), - pub fn FcPatternFilter(p: *mut FcPattern, os: *const FcObjectSet) -> *mut FcPattern; + fn FcPatternFilter(*mut FcPattern, *const FcObjectSet) -> *mut FcPattern, - pub fn FcValueDestroy(v: FcValue); + fn FcValueDestroy(FcValue) -> (), - pub fn FcValueEqual(va: FcValue, vb: FcValue) -> FcBool; + fn FcValueEqual(FcValue, FcValue) -> FcBool, - pub fn FcValueSave(v: FcValue) -> FcValue; + fn FcValueSave(FcValue) -> FcValue, - pub fn FcPatternDestroy(p: *mut FcPattern); + fn FcPatternDestroy(*mut FcPattern) -> (), - pub fn FcPatternEqual(pa: *const FcPattern, pb: *const FcPattern) -> FcBool; + fn FcPatternEqual(*const FcPattern, *const FcPattern) -> FcBool, - pub fn FcPatternEqualSubset( - pa: *const FcPattern, - pb: *const FcPattern, - os: *const FcObjectSet, - ) -> FcBool; + fn FcPatternEqualSubset( + *const FcPattern, + *const FcPattern, + *const FcObjectSet + ) -> FcBool, - pub fn FcPatternHash(p: *const FcPattern) -> FcChar32; + fn FcPatternHash(*const FcPattern) -> FcChar32, - pub fn FcPatternAdd( - p: *mut FcPattern, - object: *const c_char, - value: FcValue, - append: FcBool, - ) -> FcBool; + fn FcPatternAdd( + *mut FcPattern, + *const c_char, + FcValue, + FcBool + ) -> FcBool, - pub fn FcPatternAddWeak( - p: *mut FcPattern, - object: *const c_char, - value: FcValue, - append: FcBool, - ) -> FcBool; + fn FcPatternAddWeak( + *mut FcPattern, + *const c_char, + FcValue, + FcBool + ) -> FcBool, - pub fn FcPatternGet( - p: *mut FcPattern, - object: *const c_char, - id: c_int, - v: *mut FcValue, - ) -> FcResult; + fn FcPatternGet( + *mut FcPattern, + *const c_char, + c_int, + *mut FcValue + ) -> FcResult, - pub fn FcPatternDel(p: *mut FcPattern, object: *const c_char) -> FcBool; + fn FcPatternDel(*mut FcPattern, *const c_char) -> FcBool, - pub fn FcPatternRemove(p: *mut FcPattern, object: *const c_char, id: c_int) -> FcBool; + fn FcPatternRemove(*mut FcPattern, *const c_char, c_int) -> FcBool, - pub fn FcPatternAddInteger(p: *mut FcPattern, object: *const c_char, i: c_int) -> FcBool; + fn FcPatternAddInteger(*mut FcPattern, *const c_char, c_int) -> FcBool, - pub fn FcPatternAddDouble(p: *mut FcPattern, object: *const c_char, d: c_double) -> FcBool; + fn FcPatternAddDouble(*mut FcPattern, *const c_char, c_double) -> FcBool, - pub fn FcPatternAddString( - p: *mut FcPattern, - object: *const c_char, - s: *const FcChar8, - ) -> FcBool; + fn FcPatternAddString( + *mut FcPattern, + *const c_char, + *const FcChar8 + ) -> FcBool, - pub fn FcPatternAddMatrix( - p: *mut FcPattern, - object: *const c_char, - s: *const FcMatrix, - ) -> FcBool; + fn FcPatternAddMatrix( + *mut FcPattern, + *const c_char, + *const FcMatrix + ) -> FcBool, - pub fn FcPatternAddCharSet( - p: *mut FcPattern, - object: *const c_char, - c: *const FcCharSet, - ) -> FcBool; + fn FcPatternAddCharSet( + *mut FcPattern, + *const c_char, + *const FcCharSet + ) -> FcBool, - pub fn FcPatternAddBool(p: *mut FcPattern, object: *const c_char, b: FcBool) -> FcBool; + fn FcPatternAddBool(*mut FcPattern, *const c_char, FcBool) -> FcBool, - pub fn FcPatternAddLangSet( - p: *mut FcPattern, - object: *const c_char, - ls: *const FcLangSet, - ) -> FcBool; + fn FcPatternAddLangSet( + *mut FcPattern, + *const c_char, + *const FcLangSet + ) -> FcBool, - pub fn FcPatternGetInteger( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - i: *mut c_int, - ) -> FcResult; + fn FcPatternGetInteger( + *mut FcPattern, + *const c_char, + c_int, + *mut c_int + ) -> FcResult, - pub fn FcPatternGetDouble( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - d: *mut c_double, - ) -> FcResult; + fn FcPatternGetDouble( + *mut FcPattern, + *const c_char, + c_int, + *mut c_double + ) -> FcResult, - pub fn FcPatternGetString( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - s: *mut *mut FcChar8, - ) -> FcResult; + fn FcPatternGetString( + *mut FcPattern, + *const c_char, + c_int, + *mut *mut FcChar8 + ) -> FcResult, - pub fn FcPatternGetMatrix( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - s: *mut *mut FcMatrix, - ) -> FcResult; + fn FcPatternGetMatrix( + *mut FcPattern, + *const c_char, + c_int, + *mut *mut FcMatrix + ) -> FcResult, - pub fn FcPatternGetCharSet( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - c: *mut *mut FcCharSet, - ) -> FcResult; + fn FcPatternGetCharSet( + *mut FcPattern, + *const c_char, + c_int, + *mut *mut FcCharSet + ) -> FcResult, - pub fn FcPatternGetBool( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - b: *mut FcBool, - ) -> FcResult; + fn FcPatternGetBool( + *mut FcPattern, + *const c_char, + c_int, + *mut FcBool + ) -> FcResult, - pub fn FcPatternGetLangSet( - p: *mut FcPattern, - object: *const c_char, - n: c_int, - ls: *mut *mut FcLangSet, - ) -> FcResult; + fn FcPatternGetLangSet( + *mut FcPattern, + *const c_char, + c_int, + *mut *mut FcLangSet + ) -> FcResult, - //pub fn FcPatternVaBuild(p: *mut FcPattern, va: *mut __va_list_tag) -> *mut FcPattern; + // fn FcPatternVaBuild(*mut FcPattern, *mut __va_list_tag) -> *mut FcPattern, - pub fn FcPatternBuild(p: *mut FcPattern, ...) -> *mut FcPattern; + fn FcPatternFormat(*mut FcPattern, *const FcChar8) -> *mut FcChar8, - pub fn FcPatternFormat(pat: *mut FcPattern, format: *const FcChar8) -> *mut FcChar8; + fn FcStrCopy(*const FcChar8) -> *mut FcChar8, - pub fn FcStrCopy(s: *const FcChar8) -> *mut FcChar8; + fn FcStrCopyFilename(*const FcChar8) -> *mut FcChar8, - pub fn FcStrCopyFilename(s: *const FcChar8) -> *mut FcChar8; + fn FcStrPlus(*const FcChar8, *const FcChar8) -> *mut FcChar8, - pub fn FcStrPlus(s1: *const FcChar8, s2: *const FcChar8) -> *mut FcChar8; + fn FcStrFree(*mut FcChar8) -> (), - pub fn FcStrFree(s: *mut FcChar8); + fn FcStrDowncase(*const FcChar8) -> *mut FcChar8, - pub fn FcStrDowncase(s: *const FcChar8) -> *mut FcChar8; + fn FcStrCmpIgnoreCase(*const FcChar8, *const FcChar8) -> c_int, - pub fn FcStrCmpIgnoreCase(s1: *const FcChar8, s2: *const FcChar8) -> c_int; + fn FcStrCmp(*const FcChar8, *const FcChar8) -> c_int, - pub fn FcStrCmp(s1: *const FcChar8, s2: *const FcChar8) -> c_int; + fn FcStrStrIgnoreCase(*const FcChar8, *const FcChar8) -> *mut FcChar8, - pub fn FcStrStrIgnoreCase(s1: *const FcChar8, s2: *const FcChar8) -> *mut FcChar8; + fn FcStrStr(*const FcChar8, *const FcChar8) -> *mut FcChar8, - pub fn FcStrStr(s1: *const FcChar8, s2: *const FcChar8) -> *mut FcChar8; + fn FcUtf8ToUcs4(*mut FcChar8, *mut FcChar32, c_int) -> c_int, - pub fn FcUtf8ToUcs4(src_orig: *mut FcChar8, dst: *mut FcChar32, len: c_int) -> c_int; + fn FcUtf8Len( + *mut FcChar8, + c_int, + *mut c_int, + *mut c_int + ) -> FcBool, - pub fn FcUtf8Len( - string: *mut FcChar8, - len: c_int, - nchar: *mut c_int, - wchar: *mut c_int, - ) -> FcBool; + fn FcUcs4ToUtf8(FcChar32, *mut FcChar8) -> c_int, - pub fn FcUcs4ToUtf8(ucs4: FcChar32, dest: *mut FcChar8) -> c_int; + fn FcUtf16ToUcs4( + *mut FcChar8, + FcEndian, + *mut FcChar32, + c_int + ) -> c_int, - pub fn FcUtf16ToUcs4( - src_orig: *mut FcChar8, - endian: FcEndian, - dst: *mut FcChar32, - len: c_int, - ) -> c_int; + fn FcUtf16Len( + *mut FcChar8, + FcEndian, + c_int, + *mut c_int, + *mut c_int + ) -> FcBool, - pub fn FcUtf16Len( - string: *mut FcChar8, - endian: FcEndian, - len: c_int, - nchar: *mut c_int, - wchar: *mut c_int, - ) -> FcBool; + fn FcStrDirname(*const FcChar8) -> *mut FcChar8, - pub fn FcStrDirname(file: *const FcChar8) -> *mut FcChar8; + fn FcStrBasename(*const FcChar8) -> *mut FcChar8, - pub fn FcStrBasename(file: *const FcChar8) -> *mut FcChar8; + fn FcStrSetCreate() -> *mut FcStrSet, - pub fn FcStrSetCreate() -> *mut FcStrSet; + fn FcStrSetMember(*mut FcStrSet, *const FcChar8) -> FcBool, - pub fn FcStrSetMember(set: *mut FcStrSet, s: *const FcChar8) -> FcBool; + fn FcStrSetEqual(*mut FcStrSet, *mut FcStrSet) -> FcBool, - pub fn FcStrSetEqual(sa: *mut FcStrSet, sb: *mut FcStrSet) -> FcBool; + fn FcStrSetAdd(*mut FcStrSet, *const FcChar8) -> FcBool, - pub fn FcStrSetAdd(set: *mut FcStrSet, s: *const FcChar8) -> FcBool; + fn FcStrSetAddFilename(*mut FcStrSet, *const FcChar8) -> FcBool, - pub fn FcStrSetAddFilename(set: *mut FcStrSet, s: *const FcChar8) -> FcBool; + fn FcStrSetDel(*mut FcStrSet, *const FcChar8) -> FcBool, - pub fn FcStrSetDel(set: *mut FcStrSet, s: *const FcChar8) -> FcBool; + fn FcStrSetDestroy(*mut FcStrSet) -> (), - pub fn FcStrSetDestroy(set: *mut FcStrSet); + fn FcStrListCreate(*mut FcStrSet) -> *mut FcStrList, - pub fn FcStrListCreate(set: *mut FcStrSet) -> *mut FcStrList; + fn FcStrListNext(*mut FcStrList) -> *mut FcChar8, - pub fn FcStrListNext(list: *mut FcStrList) -> *mut FcChar8; + fn FcStrListDone(*mut FcStrList) -> (), - pub fn FcStrListDone(list: *mut FcStrList); + fn FcConfigParseAndLoad( + *mut FcConfig, + *const FcChar8, + FcBool + ) -> FcBool, - pub fn FcConfigParseAndLoad( - config: *mut FcConfig, - file: *const FcChar8, - complain: FcBool, - ) -> FcBool; - -} + varargs: + fn FcPatternBuild(*mut FcPattern) -> *mut FcPattern, + fn FcObjectSetBuild(*mut c_char) -> *mut FcObjectSet, +); diff --git a/fontconfig-sys/src/lib.rs b/fontconfig-sys/src/lib.rs index 532699e..6ba1240 100644 --- a/fontconfig-sys/src/lib.rs +++ b/fontconfig-sys/src/lib.rs @@ -7,11 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_type = "lib"] -#![crate_type = "dylib"] -#![crate_type = "rlib"] - #[macro_use] extern crate const_cstr; pub mod fontconfig; + +#[cfg(feature = "dlopen")] +pub use fontconfig::{LIB, LIB_RESULT}; + +pub use dlib::ffi_dispatch; diff --git a/fontconfig/Cargo.toml b/fontconfig/Cargo.toml index c4cf994..cd118b8 100644 --- a/fontconfig/Cargo.toml +++ b/fontconfig/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "fontconfig" version = "0.2.1" +edition = "2018" +rust-version = "1.43" authors = [ "Austin Bonander ", "Manuel Reinhardt ", @@ -23,3 +25,6 @@ travis-ci = { repository = "yeslogic/fontconfig-rs" } [dependencies.yeslogic-fontconfig-sys] version = "2.11.2" path = "../fontconfig-sys" + +[features] +dlopen = [ "yeslogic-fontconfig-sys/dlopen" ] diff --git a/fontconfig/src/lib.rs b/fontconfig/src/lib.rs index 1b90b43..4c472d3 100644 --- a/fontconfig/src/lib.rs +++ b/fontconfig/src/lib.rs @@ -1,6 +1,9 @@ #![deny(missing_docs)] -//! A wrapper around [freedesktop.org's Fontconfig library][homepage], for locating fonts on a UNIX like systems such as Linux and FreeBSD. Requires Fontconfig to be installed. +//! A wrapper around [freedesktop.org's Fontconfig library][homepage], for locating fonts on a UNIX +//! like systems such as Linux and FreeBSD. Requires Fontconfig to be installed, or alternatively +//! enable the `dlopen` Cargo feature to load the library at runtime rather than link at build time +//! (useful for cross compiling). //! //! See the [Fontconfig developer reference][1] for more information. //! @@ -34,6 +37,12 @@ extern crate fontconfig_sys; use crate::fontconfig_sys::fontconfig as sys; +use crate::fontconfig_sys::ffi_dispatch; + +#[cfg(feature = "dlopen")] +use sys::{LIB, LIB_RESULT}; +#[cfg(not(feature = "dlopen"))] +use sys::*; use std::ffi::{CStr, CString}; use std::mem; @@ -81,7 +90,11 @@ impl Fontconfig { /// /// If Fontconfig fails to initialise, returns `None`. pub fn new() -> Option { - if unsafe { sys::FcInit() == FcTrue } { + #[cfg(feature = "dlopen")] + if LIB_RESULT.is_err() { + return None; + } + if unsafe { ffi_dispatch!(LIB, FcInit,) == FcTrue } { Some(Fontconfig { _initialised: () }) } else { None @@ -150,7 +163,7 @@ pub struct Pattern<'fc> { impl<'fc> Pattern<'fc> { /// Create a new `Pattern`. pub fn new(fc: &Fontconfig) -> Pattern { - let pat = unsafe { sys::FcPatternCreate() }; + let pat = unsafe { ffi_dispatch!(LIB, FcPatternCreate,) }; assert!(!pat.is_null()); Pattern { pat, fc } @@ -159,7 +172,7 @@ impl<'fc> Pattern<'fc> { /// Create a `Pattern` from a raw fontconfig FcPattern pointer. The pattern is referenced. pub fn from_pattern(fc: &Fontconfig, pat: *mut FcPattern) -> Pattern { unsafe { - sys::FcPatternReference(pat); + ffi_dispatch!(LIB, FcPatternReference, pat); } Pattern { pat, fc } @@ -172,7 +185,7 @@ impl<'fc> Pattern<'fc> { /// [1]: http://www.freedesktop.org/software/fontconfig/fontconfig-devel/x19.html pub fn add_string(&mut self, name: &CStr, val: &CStr) { unsafe { - sys::FcPatternAddString(self.pat, name.as_ptr(), val.as_ptr() as *const u8); + ffi_dispatch!(LIB, FcPatternAddString, self.pat, name.as_ptr(), val.as_ptr() as *const u8); } } @@ -180,7 +193,7 @@ impl<'fc> Pattern<'fc> { pub fn get_string<'a>(&'a self, name: &'a CStr) -> Option<&'a str> { unsafe { let mut ret: *mut sys::FcChar8 = ptr::null_mut(); - if sys::FcPatternGetString(self.pat, name.as_ptr(), 0, &mut ret as *mut _) + if ffi_dispatch!(LIB, FcPatternGetString, self.pat, name.as_ptr(), 0, &mut ret as *mut _) == sys::FcResultMatch { let cstr = CStr::from_ptr(ret as *const c_char); @@ -195,7 +208,7 @@ impl<'fc> Pattern<'fc> { pub fn get_int(&self, name: &CStr) -> Option { unsafe { let mut ret: i32 = 0; - if sys::FcPatternGetInteger(self.pat, name.as_ptr(), 0, &mut ret as *mut i32) + if ffi_dispatch!(LIB, FcPatternGetInteger, self.pat, name.as_ptr(), 0, &mut ret as *mut i32) == sys::FcResultMatch { Some(ret) @@ -208,19 +221,19 @@ impl<'fc> Pattern<'fc> { /// Print this pattern to stdout with all its values. pub fn print(&self) { unsafe { - sys::FcPatternPrint(&*self.pat); + ffi_dispatch!(LIB, FcPatternPrint, &*self.pat); } } fn default_substitute(&mut self) { unsafe { - sys::FcDefaultSubstitute(self.pat); + ffi_dispatch!(LIB, FcDefaultSubstitute, self.pat); } } fn config_substitute(&mut self) { unsafe { - sys::FcConfigSubstitute(ptr::null_mut(), self.pat, sys::FcMatchPattern); + ffi_dispatch!(LIB, FcConfigSubstitute, ptr::null_mut(), self.pat, sys::FcMatchPattern); } } @@ -233,7 +246,7 @@ impl<'fc> Pattern<'fc> { let mut res = sys::FcResultNoMatch; Pattern::from_pattern( self.fc, - sys::FcFontMatch(ptr::null_mut(), self.pat, &mut res), + ffi_dispatch!(LIB, FcFontMatch, ptr::null_mut(), self.pat, &mut res), ) } } @@ -278,17 +291,17 @@ impl<'fc> Pattern<'fc> { impl<'fc> std::fmt::Debug for Pattern<'fc> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let fcstr = unsafe { sys::FcNameUnparse(self.pat) }; + let fcstr = unsafe { ffi_dispatch!(LIB, FcNameUnparse, self.pat) }; let fcstr = unsafe { CStr::from_ptr(fcstr as *const c_char) }; let result = write!(f, "{:?}", fcstr); - unsafe { sys::FcStrFree(fcstr.as_ptr() as *mut u8) }; + unsafe { ffi_dispatch!(LIB, FcStrFree, fcstr.as_ptr() as *mut u8) }; result } } impl<'fc> Clone for Pattern<'fc> { fn clone(&self) -> Self { - let clone = unsafe { sys::FcPatternDuplicate(self.pat) }; + let clone = unsafe { ffi_dispatch!(LIB, FcPatternDuplicate, self.pat) }; Pattern { pat: clone, fc: self.fc, @@ -299,7 +312,7 @@ impl<'fc> Clone for Pattern<'fc> { impl<'fc> Drop for Pattern<'fc> { fn drop(&mut self) { unsafe { - sys::FcPatternDestroy(self.pat); + ffi_dispatch!(LIB, FcPatternDestroy, self.pat); } } } @@ -313,7 +326,7 @@ pub struct FontSet<'fc> { impl<'fc> FontSet<'fc> { /// Create a new, empty `FontSet`. pub fn new(fc: &Fontconfig) -> FontSet { - let fcset = unsafe { sys::FcFontSetCreate() }; + let fcset = unsafe { ffi_dispatch!(LIB, FcFontSetCreate,) }; FontSet { fcset, fc } } @@ -327,14 +340,14 @@ impl<'fc> FontSet<'fc> { /// Add a `Pattern` to this `FontSet`. pub fn add_pattern(&mut self, pat: Pattern) { unsafe { - sys::FcFontSetAdd(self.fcset, pat.pat); + ffi_dispatch!(LIB, FcFontSetAdd, self.fcset, pat.pat); mem::forget(pat); } } /// Print this `FontSet` to stdout. pub fn print(&self) { - unsafe { sys::FcFontSetPrint(self.fcset) }; + unsafe { ffi_dispatch!(LIB, FcFontSetPrint, self.fcset) }; } /// Iterate the fonts (as `Patterns`) in this `FontSet`. @@ -351,14 +364,14 @@ impl<'fc> FontSet<'fc> { impl<'fc> Drop for FontSet<'fc> { fn drop(&mut self) { - unsafe { sys::FcFontSetDestroy(self.fcset) } + unsafe { ffi_dispatch!(LIB, FcFontSetDestroy, self.fcset) } } } /// Return a `FontSet` containing Fonts that match the supplied `pattern` and `objects`. pub fn list_fonts<'fc>(pattern: &Pattern<'fc>, objects: Option<&ObjectSet>) -> FontSet<'fc> { let os = objects.map(|o| o.fcset).unwrap_or(ptr::null_mut()); - let ptr = unsafe { sys::FcFontList(ptr::null_mut(), pattern.pat, os) }; + let ptr = unsafe { ffi_dispatch!(LIB, FcFontList, ptr::null_mut(), pattern.pat, os) }; FontSet::from_raw(pattern.fc, ptr) } @@ -370,7 +383,7 @@ pub struct ObjectSet { impl ObjectSet { /// Create a new, empty `ObjectSet`. pub fn new(_: &Fontconfig) -> ObjectSet { - let fcset = unsafe { sys::FcObjectSetCreate() }; + let fcset = unsafe { ffi_dispatch!(LIB, FcObjectSetCreate,) }; assert!(!fcset.is_null()); ObjectSet { fcset } @@ -386,14 +399,14 @@ impl ObjectSet { /// Add a string to the `ObjectSet`. pub fn add(&mut self, name: &CStr) { - let res = unsafe { sys::FcObjectSetAdd(self.fcset, name.as_ptr()) }; + let res = unsafe { ffi_dispatch!(LIB, FcObjectSetAdd, self.fcset, name.as_ptr()) }; assert_eq!(res, FcTrue); } } impl Drop for ObjectSet { fn drop(&mut self) { - unsafe { sys::FcObjectSetDestroy(self.fcset) } + unsafe { ffi_dispatch!(LIB, FcObjectSetDestroy, self.fcset) } } }