From d6217cc6bcce0768ce1e01c077e90967ff91db5a Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Fri, 7 Apr 2006 04:42:32 +0000 Subject: [PATCH] Patrick Lam Make fontconfig compile under MinGW: 1) remove unneeded #includes; 2) make use of mmap and sysconf conditional; 3) replace rand_r by srand/rand if needed; 4) use chsize instead of ftruncate; and 5) update libtool exports file --- ChangeLog | 18 ++ configure.in | 3 +- fc-cache/fc-cache.c | 7 + fc-cat/fc-cat.c | 1 - src/fccache.c | 74 ++++++++- src/fcfreetype.c | 3 +- src/fontconfig.def.in | 370 +++++++++++++++++++++++++++++------------- 7 files changed, 353 insertions(+), 123 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a5deb1..1b1fc46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2006-04-07 Dominic Lachowicz + Patrick Lam + * configure.in: + * fc-cache/fc-cache.c: + * fc-cat/fc-cat.c: + * src/fccache.c (FcGlobalCacheSave, FcCacheNextOffset, + FcDirCacheConsume, FcDirCacheProduce, + FcDirCacheWrite, FcCacheMachineSignature): + * src/fcfreetype.c (FcFreeTypeQuery): + * src/fontconfig.def.in: + + Make fontconfig compile under MinGW: + 1) remove unneeded #includes; + 2) make use of mmap and sysconf conditional; + 3) replace rand_r by srand/rand if needed; + 4) use chsize instead of ftruncate; and + 5) update libtool exports file + 2006-04-07 Patrick Lam * src/fcdir.c (FcDirScanConfig): diff --git a/configure.in b/configure.in index 26fd05b..4ec7abd 100644 --- a/configure.in +++ b/configure.in @@ -143,7 +143,8 @@ AC_TYPE_PID_T # Checks for library functions. AC_FUNC_VPRINTF -AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long iconv]) +AC_FUNC_MMAP +AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long iconv sysconf ftruncate chsize rand_r]) # # Checks for FreeType diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index ba1ba2b..ce6b567 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -38,6 +38,13 @@ #define HAVE_GETOPT 1 #endif +#if defined (_WIN32) +#define STRICT +#include +#define sleep(x) Sleep((x) * 1000) +#undef STRICT +#endif + #ifndef HAVE_GETOPT #define HAVE_GETOPT 0 #endif diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 24f8a44..80c381c 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/fccache.c b/src/fccache.c index 5aa0df8..248c6d1 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -26,15 +26,19 @@ #include #include #include -#include -#include #include #include #include "fcint.h" #include +#if defined(HAVE_MMAP) || defined(__CYGWIN__) +# include +# include +#endif #define ENDIAN_TEST 0x12345678 #define MACHINE_SIGNATURE_SIZE (9 + 5*20 + 1) +/* for when we don't have sysconf: */ +#define FC_HARDCODED_PAGESIZE 8192 #ifndef O_BINARY #define O_BINARY 0 @@ -458,8 +462,17 @@ FcGlobalCacheSave (FcGlobalCache *cache, goto bail3; current_arch_start = lseek(fd, 0, SEEK_CUR); +#if defined (HAVE_FTRUNCATE) if (ftruncate (fd, current_arch_start) == -1) goto bail3; +#else +#if defined (HAVE_CHSIZE) + if (chsize (fd, current_arch_start) == -1) + goto bail3; +#else + goto bail3; +#endif +#endif header = malloc (10 + strlen (current_arch_machine_name)); if (!header) @@ -602,7 +615,11 @@ FcCacheNextOffset(off_t w) { static long pagesize = -1; if (pagesize == -1) +#if defined (HAVE_SYSCONF) pagesize = sysconf(_SC_PAGESIZE); +#else + pagesize = FC_HARDCODED_PAGESIZE; +#endif if (w % pagesize == 0) return w; else @@ -1160,20 +1177,35 @@ FcDirCacheConsume (int fd, const char * dir, FcFontSet *set, FcConfig *config) } pos = FcCacheNextOffset (lseek(fd, 0, SEEK_CUR)); +#if defined(HAVE_MMAP) || defined(__CYGWIN__) current_dir_block = mmap (0, metadata.count, PROT_READ, MAP_SHARED, fd, pos); - lseek (fd, pos+metadata.count, SEEK_SET); if (current_dir_block == MAP_FAILED) return FcFalse; +#else + current_dir_block = malloc (metadata.count); + if (!current_dir_block) + return FcFalse; + + /* could also use CreateMappedViewOfFile under MinGW... */ + if (read (fd, current_dir_block, metadata.count) != metadata.count) + goto bail; +#endif + lseek (fd, pos+metadata.count, SEEK_SET); FcCacheAddBankDir (metadata.bank, dir); if (config) FcConfigAddFontDir (config, (FcChar8 *)dir); if (!FcFontSetUnserialize (&metadata, set, current_dir_block)) - return FcFalse; + goto bail; return FcTrue; + bail: +#if !(defined(HAVE_MMAP) || defined(__CYGWIN__)) + free (current_dir_block); +#endif + return FcFalse; } static void * @@ -1183,12 +1215,24 @@ FcDirCacheProduce (FcFontSet *set, FcCache *metadata) static unsigned int rand_state = 0; int bank, needed_bytes_no_align; +#if defined (HAVE_RAND_R) if (!rand_state) rand_state = time(0L); bank = rand_r(&rand_state); while (FcCacheHaveBank(bank)) bank = rand_r(&rand_state); +#else + if (!rand_state) + { + rand_state = 1; + srand (time (0L)); + } + bank = rand(); + + while (FcCacheHaveBank(bank)) + bank = rand(); +#endif memset (metadata, 0, sizeof(FcCache)); FcFontSetNewBank(); @@ -1336,8 +1380,17 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) close (fd_orig); current_arch_start = lseek(fd, 0, SEEK_CUR); +#if defined (HAVE_FTRUNCATE) if (ftruncate (fd, current_arch_start) == -1) goto bail4; +#else +#if defined (HAVE_CHSIZE) + if (chsize (fd, current_arch_start) == -1) + goto bail4; +#else + goto bail4; +#endif +#endif /* allocate space for subdir names in this block */ dirs_count = 0; @@ -1377,8 +1430,17 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) } /* this actually serves to pad out the cache file, if needed */ +#if defined (HAVE_FTRUNCATE) if (ftruncate (fd, current_arch_start + truncate_to) == -1) goto bail5; +#else +#if defined (HAVE_CHSIZE) + if (chsize (fd, current_arch_start + truncate_to) == -1) + goto bail5; +#else + goto bail5; +#endif +#endif free (header); close(fd); @@ -1439,7 +1501,11 @@ FcCacheMachineSignature () (unsigned int)sizeof (FcCharLeaf), (unsigned int)sizeof (FcChar32), (unsigned int)sizeof (FcCache), +#if defined (HAVE_SYSCONF) (unsigned int)sysconf(_SC_PAGESIZE)); +#else + (unsigned int)FC_HARDCODED_PAGESIZE); +#endif return buf; } diff --git a/src/fcfreetype.c b/src/fcfreetype.c index 6bdd733..2689b9f 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -47,7 +47,6 @@ #include #include #include -#include #include "fcint.h" #include #include FT_FREETYPE_H @@ -1281,7 +1280,7 @@ FcFreeTypeQuery (const FcChar8 *file, } file2 = FcStrCopy (file); - if (!FcPatternAddString (pat, FC_FILE, (FcChar8 *)basename((char *)file2))) + if (!FcPatternAddString (pat, FC_FILE, FcStrBasename(file2))) { FcStrFree (file2); goto bail1; diff --git a/src/fontconfig.def.in b/src/fontconfig.def.in index 83dac95..0bccef5 100755 --- a/src/fontconfig.def.in +++ b/src/fontconfig.def.in @@ -1,163 +1,303 @@ EXPORTS - FcAtomicCreate - FcAtomicDeleteNew - FcAtomicDestroy - FcAtomicLock - FcAtomicNewFile - FcAtomicOrigFile - FcAtomicReplaceOrig - FcAtomicUnlock - FcBlanksAdd + FcDirCacheValid + FcDirCacheHasCurrentArch + FcDirCacheUnlink FcBlanksCreate FcBlanksDestroy + FcBlanksAdd FcBlanksIsMember - FcCharSetAddChar - FcCharSetCopy - FcCharSetCount - FcCharSetCreate - FcCharSetDestroy - FcCharSetEqual - FcCharSetFirstPage - FcCharSetHasChar - FcCharSetIntersect - FcCharSetIntersectCount - FcCharSetIsSubset - FcCharSetNextPage - FcCharSetSubtract - FcCharSetSubtractCount - FcCharSetUnion - FcConfigAppFontAddDir - FcConfigAppFontAddFile - FcConfigAppFontClear - FcConfigBuildFonts - FcConfigCreate - FcConfigDestroy + FcConfigHome FcConfigEnableHome FcConfigFilename - FcConfigGetBlanks - FcConfigGetCache - FcConfigGetConfigDirs - FcConfigGetConfigFiles + FcConfigCreate + FcConfigDestroy + FcConfigSetCurrent FcConfigGetCurrent + FcConfigUptoDate + FcConfigBuildFonts FcConfigGetFontDirs - FcConfigGetFonts + FcConfigNormalizeFontDir + FcConfigGetConfigDirs + FcConfigGetConfigFiles + FcConfigGetCache + FcConfigGetBlanks FcConfigGetRescanInverval - FcConfigParseAndLoad - FcConfigSetCurrent FcConfigSetRescanInverval - FcConfigSubstitute + FcConfigGetFonts + FcConfigAppFontAddFile + FcConfigAppFontAddDir + FcConfigAppFontClear FcConfigSubstituteWithPat - FcConfigUptoDate + FcConfigSubstitute + FcCharSetCreate + FcCharSetDestroy + FcCharSetAddChar + FcCharSetCopy + FcCharSetEqual + FcCharSetIntersect + FcCharSetUnion + FcCharSetSubtract + FcCharSetHasChar + FcCharSetCount + FcCharSetIntersectCount + FcCharSetSubtractCount + FcCharSetIsSubset + FcCharSetFirstPage + FcCharSetNextPage + FcValuePrint + FcPatternPrint + FcFontSetPrint + FcDebugVal + FcFontSetUnserialize FcDefaultSubstitute - FcDirCacheValid - FcDirSave - FcDirScan FcFileScan - FcFini - FcFontList - FcFontMatch - FcFontRenderPrepare - FcFontSetAdd + FcDirScan + FcDirSave + FcFreeTypeQuery FcFontSetCreate FcFontSetDestroy - FcFontSetList - FcFontSetMatch - FcFontSetPrint - FcFontSetSort - FcFontSetSortDestroy - FcFontSort - FcFreeTypeCharIndex - FcFreeTypeCharSet - FcFreeTypeQuery - FcGetVersion - FcInit - FcInitBringUptoDate + FcFontSetAdd FcInitLoadConfig FcInitLoadConfigAndFonts + FcInit + FcFini + FcGetVersion FcInitReinitialize - FcLangSetAdd - FcLangSetCompare - FcLangSetCopy + FcInitBringUptoDate FcLangSetCreate FcLangSetDestroy - FcLangSetEqual + FcLangSetCopy + FcLangSetAdd FcLangSetHasLang + FcLangSetCompare + FcLangSetContains + FcLangSetEqual FcLangSetHash + FcObjectSetCreate + FcObjectSetAdd + FcObjectSetDestroy + FcObjectSetVaBuild + FcObjectSetBuild + FcFontSetList + FcFontList + FcAtomicCreate + FcAtomicLock + FcAtomicNewFile + FcAtomicOrigFile + FcAtomicReplaceOrig + FcAtomicDeleteNew + FcAtomicUnlock + FcAtomicDestroy + FcFontSetMatch + FcFontMatch + FcFontRenderPrepare + FcFontSetSort + FcFontSort + FcFontSetSortDestroy FcMatrixCopy FcMatrixEqual FcMatrixMultiply FcMatrixRotate FcMatrixScale FcMatrixShear - FcNameConstant - FcNameGetConstant + FcNameRegisterObjectTypes + FcNameUnregisterObjectTypes FcNameGetObjectType - FcNameParse FcNameRegisterConstants - FcNameRegisterObjectTypes - FcNameUnparse FcNameUnregisterConstants - FcNameUnregisterObjectTypes - FcObjectSetAdd - FcObjectSetBuild - FcObjectSetCreate - FcObjectSetDestroy - FcObjectSetVaBuild - FcPatternAdd - FcPatternAddBool - FcPatternAddCharSet - FcPatternAddDouble - FcPatternAddFTFace - FcPatternAddInteger - FcPatternAddLangSet - FcPatternAddMatrix - FcPatternAddString - FcPatternAddWeak - FcPatternBuild + FcNameGetConstant + FcNameConstant + FcNameParse + FcNameUnparse + FcNameUnparseEscaped FcPatternCreate - FcPatternDel - FcPatternDestroy FcPatternDuplicate + FcPatternReference + FcValueDestroy + FcValueEqual + FcValueSave + FcPatternDestroy FcPatternEqual FcPatternEqualSubset + FcPatternHash + FcPatternAdd + FcPatternAddWeak FcPatternGet - FcPatternGetBool - FcPatternGetCharSet - FcPatternGetDouble - FcPatternGetFTFace + FcPatternDel + FcPatternRemove + FcPatternAddInteger + FcPatternAddDouble + FcPatternAddString + FcPatternAddMatrix + FcPatternAddCharSet + FcPatternAddBool + FcPatternAddLangSet FcPatternGetInteger - FcPatternGetLangSet - FcPatternGetMatrix + FcPatternGetDouble FcPatternGetString - FcPatternHash - FcPatternPrint - FcPatternReference + FcPatternGetMatrix + FcPatternGetCharSet + FcPatternGetBool + FcPatternGetLangSet FcPatternVaBuild - FcStrBasename - FcStrCmp - FcStrCmp - FcStrCmpIgnoreCase + FcPatternBuild FcStrCopy FcStrCopyFilename + FcStrDowncase + FcStrCmpIgnoreCase + FcStrCmp + FcStrStrIgnoreCase + FcStrStr + FcUtf8ToUcs4 + FcUtf8Len + FcUcs4ToUtf8 + FcUtf16ToUcs4 + FcUtf16Len FcStrDirname - FcStrListCreate - FcStrListDone - FcStrListNext + FcStrBasename + FcStrSetCreate + FcStrSetMember + FcStrSetEqual FcStrSetAdd FcStrSetAddFilename - FcStrSetCreate FcStrSetDel FcStrSetDestroy - FcStrSetEqual - FcStrSetMember - FcUcs4ToUtf8 - FcUtf16Len - FcUtf16ToUcs4 - FcUtf8Len - FcUtf8ToUcs4 - FcValueDestroy - FcValueEqual - FcValuePrint - FcValueSave + FcStrListCreate + FcStrListNext + FcStrListDone + FcConfigParseAndLoad + FcFreeTypeCharIndex + FcFreeTypeCharSetAndSpacing + FcFreeTypeCharSet + FcPatternGetFTFace + FcPatternAddFTFace + FcGlobalCacheCreate + FcGlobalCacheDestroy + FcGlobalCacheReadDir + FcGlobalCacheLoad + FcGlobalCacheUpdate + FcGlobalCacheSave + FcCacheRead + FcDirCacheWrite + FcDirCacheRead + FcCacheBankToIndexMTF + FcCacheFindBankDir + FcConfigAddConfigDir + FcConfigAddFontDir + FcConfigAddDir + FcConfigAddConfigFile + FcConfigSetCache + FcConfigAddBlank + FcConfigAddEdit + FcConfigSetFonts + FcConfigCompareValue + FcConfigGlobAdd + FcConfigAcceptFilename + FcConfigPatternsAdd + FcConfigAcceptFont + FcConfigModifiedTime + FcLangCharSetPopulate + FcCharSetFreeze + FcCharSetThawAll + FcNameUnparseCharSet + FcNameParseCharSet + FcCharSetFindLeafCreate + FcCharSetNewBank + FcCharSetNeededBytes + FcCharSetNeededBytesAlign + FcCharSetDistributeBytes + FcCharSetUnserialize + FcValueListPrint + FcLangSetPrint + FcOpPrint + FcTestPrint + FcExprPrint + FcEditPrint + FcSubstPrint + FcInitDebug + FcGetDefaultLang + FcFileIsDir + FcFileScanConfig + FcDirScanConfig + FcFreeTypeIsExclusiveLang + FcFreeTypeUcs4ToPrivate + FcFreeTypePrivateToUcs4 + FcFreeTypeGetPrivateMap + FcFontSetNewBank + FcFontSetNeededBytes + FcFontSetNeededBytesAlign + FcFontSetDistributeBytes + FcFontSetSerialize + FcConfigSaveField + FcTestDestroy + FcExprCreateInteger + FcExprCreateDouble + FcExprCreateString + FcExprCreateMatrix + FcExprCreateBool + FcExprCreateNil + FcExprCreateField + FcExprCreateConst + FcExprCreateOp + FcExprDestroy + FcEditDestroy + FcMemReport + FcMemAlloc + FcMemFree + FcFreeTypeLangSet + FcLangCompare + FcCharSetForLang + FcLangSetPromote + FcNameParseLangSet + FcNameUnparseLangSet + FcLangSetNewBank + FcLangSetNeededBytes + FcLangSetNeededBytesAlign + FcLangSetDistributeBytes + FcLangSetSerialize + FcLangSetUnserialize + FcListPatternMatchAny + FcNameBool + FcObjectDistributeBytes + FcObjectToPtr + FcObjectNeededBytes + FcObjectNeededBytesAlign + FcObjectUnserialize + FcObjectSerialize + FcObjectPtrU + FcObjectStaticNameFini + FcValueCanonicalize + FcValueListDestroy + FcPatternFindElt + FcPatternInsertElt + FcPatternAddWithBinding + FcPatternFreeze + FcPatternFini + FcPatternAppend + FcPatternAddFullFname + FcPatternTransferFullFname + FcStrStaticName + FcStringHash + FcPatternNewBank + FcPatternNeededBytes + FcPatternNeededBytesAlign + FcPatternDistributeBytes + FcPatternSerialize + FcPatternUnserialize + FcMatrixFree + FcStrPlus + FcStrFree + FcStrBufInit + FcStrBufDestroy + FcStrBufDone + FcStrBufChar + FcStrBufString + FcStrBufData + FcStrCmpIgnoreBlanksAndCase + FcStrContainsIgnoreBlanksAndCase + FcStrContainsIgnoreCase + FcStrUsesHome + FcStrLastSlash + FcStrHashIgnoreCase LIBRARY libfontconfig-@LT_CURRENT_MINUS_AGE@.dll VERSION @LT_CURRENT@.@LT_REVISION@ -- 2.39.5