1 module fontconfig; 2 3 public import fontconfig.fctypes; 4 public import fontconfig.functions; 5 6 import bindbc.loader; 7 8 enum FCSupport { 9 noLibrary, 10 badLibrary, 11 // TODO: real versions and stuff 12 fc100 = 100, 13 } 14 15 private { 16 SharedLib lib; 17 FCSupport loadedVersion; 18 } 19 20 21 @nogc nothrow: 22 void unloadFC() 23 { 24 if(lib != invalidHandle) { 25 lib.unload(); 26 } 27 } 28 29 30 FCSupport loadedFCVersion() { return loadedVersion; } 31 32 bool isFCLoaded() 33 { 34 return lib != invalidHandle; 35 } 36 37 38 FCSupport loadFC() 39 { 40 // #1778 prevents from using static arrays here :( 41 version(Windows) { 42 const(char)[][1] libNames = [ "libfontconfig-1.dll"]; 43 } 44 else version(OSX) { 45 const(char)[][1] libNames = [ 46 "/usr/local/lib/libfontconfig.dylib" 47 ]; 48 } 49 else version(Posix) { 50 const(char)[][2] libNames = [ 51 "libfontconfig.so.1", 52 "libfontconfig.so" 53 ]; 54 } 55 else static assert(0, "bindbc-fc is not yet supported on this platform."); 56 57 FCSupport ret; 58 foreach(name; libNames) { 59 ret = loadFC(name.ptr); 60 if(ret != FCSupport.noLibrary) break; 61 } 62 return ret; 63 } 64 65 FCSupport loadFC(const(char)* libName) 66 { 67 lib = load(libName); 68 if(lib == invalidHandle) { 69 return FCSupport.noLibrary; 70 } 71 72 auto errCount = errorCount(); 73 loadedVersion = FCSupport.badLibrary; 74 75 lib.bindSymbol( cast( void** )&FcObjectSetBuild, "FcObjectSetBuild" ); 76 lib.bindSymbol( cast( void** )&FcPatternCreate, "FcPatternCreate" ); 77 lib.bindSymbol( cast( void** )&FcPatternAddBool, "FcPatternAddBool" ); 78 lib.bindSymbol( cast( void** )&FcFontList, "FcFontList" ); 79 lib.bindSymbol( cast( void** )&FcPatternDestroy, "FcPatternDestroy" ); 80 lib.bindSymbol( cast( void** )&FcObjectSetDestroy, "FcObjectSetDestroy" ); 81 lib.bindSymbol( cast( void** )&FcPatternGetString, "FcPatternGetString" ); 82 lib.bindSymbol( cast( void** )&FcPatternGetInteger, "FcPatternGetInteger" ); 83 lib.bindSymbol( cast( void** )&FcPatternGetBool, "FcPatternGetBool" ); 84 lib.bindSymbol( cast( void** )&FcFontSetDestroy, "FcFontSetDestroy" ); 85 86 if(errorCount() != errCount) return FCSupport.badLibrary; 87 else loadedVersion = FCSupport.fc100; 88 89 return loadedVersion; 90 }