Commit daeed6e0 authored by Tor Lillqvist's avatar Tor Lillqvist

Changes for Windows:

On Windows with gcc (a.k.a. mingw) build as a DLL.
We don't want to hardcode the fonts.conf file location in the DLL, so we
    look up the DLL location at run-time in a DllMain() function. The
    fonts.conf location is deduced from that.
The colon can't be used as path separator on Windows, semicolon is used
    instead. File path components can be separated with either slash or
    backslash. Absolute paths can also begin with a drive letter.
Add internal function FcStrLastSlash that strrchr's the last slash, or
    backslash on Windows.
There is no link() on Windows. For atomicity checks, mkdir a lock directory
    instead.
In addition to HOME, also look for USERPROFILE.
Recognize the special font directory token WINDOWSFONTDIR, to use the
    system's font directory.
Remove the fontconfig-def.cpp that was obsolete. Add fontconfig.def(.in),
    without internal functions.
Add a fontconfig-zip(.in) script, used to build a binary distribution.
parent cc9dd098
2003-03-22 Tor Lillqvist <tml@iki.fi>
Changes for Windows:
+ On Windows with gcc (a.k.a. mingw) build as a DLL.
+ We don't want to hardcode the fonts.conf file location in the
DLL, so we look up the DLL location at run-time in a DllMain()
function. The fonts.conf location is deduced from that.
+ The colon can't be used as path separator on Windows,
semicolon is used instead. File path components can be separated
with either slash or backslash. Absolute paths can also begin
with a drive letter.
+ Add internal function FcStrLastSlash that strrchr's the last
slash, or backslash on Windows.
+ There is no link() on Windows. For atomicity checks, mkdir a
lock directory instead.
+ In addition to HOME, also look for USERPROFILE.
+ Recognize the special font directory token WINDOWSFONTDIR, to
use the system's font directory.
+ Remove the fontconfig-def.cpp that was obsolete. Add
fontconfig.def(.in), without internal functions.
+ Add a fontconfig-zip(.in) script, used to build a binary
distribution.
Fri Mar 7 07:55:00 EST 2003 Mike A. Harris <mharris@redhat.com>
+ RPM specfile cleanups for 2.1.92: Removed man1/* and added man5/*
to main package and man3/* to devel package
......
......@@ -29,7 +29,8 @@ EXTRA_DIST = \
fonts.dtd \
local.conf \
fontconfig.spec.in \
fontconfig.spec
fontconfig.spec \
fontconfig-zip.in
pkgconfigdir=$(libdir)/pkgconfig
pkgconfig_DATA = fontconfig.pc
......
......@@ -39,11 +39,16 @@ dnl libtool versioning
LT_CURRENT=1
LT_REVISION=4
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
LT_AGE=0
LT_VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
AC_SUBST(LT_VERSION_INFO)
LT_CURRENT_MINUS_AGE=`expr $LT_CURRENT - $LT_AGE`
AC_SUBST(LT_CURRENT_MINUS_AGE)
dnl ==========================================================================
AM_CONFIG_HEADER(config.h)
......@@ -51,9 +56,28 @@ AM_CONFIG_HEADER(config.h)
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_MAKE_SET
dnl ==========================================================================
case "$host" in
*-*-mingw*)
os_win32=yes
;;
*)
os_win32=no
esac
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
if test "$os_win32" = "yes"; then
AC_CHECK_PROG(ms_librarian, lib.exe, yes, no)
fi
AM_CONDITIONAL(MS_LIB_AVAILABLE, test x$ms_librarian = xyes)
dnl ==========================================================================
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
......@@ -65,7 +89,7 @@ AC_TYPE_PID_T
# Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([memmove memset strchr strrchr strtol getopt getopt_long])
AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr strtol getopt getopt_long])
#
# Checks for FreeType
......@@ -334,6 +358,7 @@ Makefile
fontconfig/Makefile
fc-lang/Makefile
src/Makefile
src/fontconfig.def
fc-cache/Makefile
fc-list/Makefile
doc/Makefile
......@@ -342,4 +367,5 @@ test/Makefile
fontconfig.spec
fontconfig.pc
fonts.conf
fontconfig-zip
])
......@@ -24,18 +24,18 @@
.\"
.TH FC-LANG 1 __vendorversion__
.SH NAME
fc-lang, fclang.c \- create an database of language orthographies
fc-lang, fclang.h \- create an database of language orthographies
.SH SYNOPSIS
.B "fc-lang"
.RI [ language-coverage
\|.\|.\|. ]
.SH DESCRIPTION
.I Fc-lang
builds the fclang.c file used in the fontconfig library to automatically
builds the fclang.h file used in the fontconfig library to automatically
determine language coverage for fonts which don't contain this information.
.SH FILES
.TP 15
.B fclang.tmpl.c
.B fclang.tmpl.h
The template file in which the tables are inserted
.SH "SEE ALSO"
fontconfig(3)
if OS_WIN32
no_undefined = -no-undefined
export_symbols = -export-symbols fontconfig.def
# gcc import library install/uninstall
install-libtool-import-lib:
$(INSTALL) .libs/libfontconfig.dll.a $(DESTDIR)$(libdir)
$(INSTALL) fontconfig.def $(DESTDIR)$(libdir)/glib-2.0.def
uninstall-libtool-import-lib:
-rm $(DESTDIR)$(libdir)/libfontconfig.dll.a $(DESTDIR)$(libdir)/fontconfig.def
else
install-libtool-import-lib:
uninstall-libtool-import-lib:
endif
if MS_LIB_AVAILABLE
# Microsoft import library install/uninstall
noinst_DATA = fontconfig.lib
fontconfig.lib : libfontconfig.la
lib -name:libfontconfig-$(lt_current_minus_age).dll -def:fontconfig.def -out:$@
install-ms-import-lib:
$(INSTALL) fontconfig.lib $(DESTDIR)$(libdir)
uninstall-ms-import-lib:
-rm $(DESTDIR)$(libdir)/fontconfig.lib
else
install-ms-lib:
uninstall-ms-lib:
endif
INCLUDES = \
$(FREETYPE_CFLAGS) \
$(EXPAT_CFLAGS) \
-I$(top_srcdir) \
-I$(top_srcdir)/src
EXTRA_DIST = fontconfig.def.in
noinst_HEADERS=fcint.h
libfontconfig_la_SOURCES = \
......@@ -26,11 +71,15 @@ libfontconfig_la_SOURCES = \
fcpat.c \
fcstr.c \
fcxml.c
lib_LTLIBRARIES = libfontconfig.la
libfontconfig_la_LDFLAGS = \
-version-info @LT_VERSION_INFO@
-version-info @LT_VERSION_INFO@ $(no_undefined) $(export_symbols)
libfontconfig_la_LIBADD = $(FREETYPE_LIBS) $(EXPAT_LIBS)
install-data-local: install-ms-import-lib install-libtool-import-lib
uninstall-local: uninstall-ms-import-lib uninstall-libtool-import-lib
......@@ -30,7 +30,7 @@
* Uses only regular filesystem calls so it should
* work even in the absense of functioning file locking
*
* Four files:
* On Unix, four files are used:
* file - the data file accessed by other apps.
* new - a new version of the data file while it's being written
* lck - the lock file
......@@ -41,6 +41,10 @@
* Attempt to link it to 'lck'
* Unlink 'tmp'
* If the link succeeded, the lock is held
*
* On Windows, where there are no links, no tmp file is used, and lck
* is a directory that's mkdir'ed. If the mkdir succeeds, the lock is
* held.
*/
#include "fcint.h"
......@@ -51,6 +55,10 @@
#include <stdlib.h>
#include <time.h>
#ifdef _WIN32
#define mkdir(path,mode) _mkdir(path)
#endif
#define NEW_NAME ".NEW"
#define LCK_NAME ".LCK"
#define TMP_NAME ".TMP-XXXXXX"
......@@ -96,6 +104,7 @@ FcAtomicLock (FcAtomic *atomic)
int ret;
struct stat lck_stat;
#ifdef HAVE_LINK
strcpy ((char *) atomic->tmp, (char *) atomic->file);
strcat ((char *) atomic->tmp, TMP_NAME);
fd = mkstemp ((char *) atomic->tmp);
......@@ -122,6 +131,9 @@ FcAtomicLock (FcAtomic *atomic)
}
ret = link ((char *) atomic->tmp, (char *) atomic->lck);
(void) unlink ((char *) atomic->tmp);
#else
ret = mkdir ((char *) atomic->lck, 0600);
#endif
if (ret < 0)
{
/*
......@@ -135,8 +147,13 @@ FcAtomicLock (FcAtomic *atomic)
time_t now = time (0);
if ((long int) (now - lck_stat.st_mtime) > 10 * 60)
{
#ifdef HAVE_LINK
if (unlink ((char *) atomic->lck) == 0)
return FcAtomicLock (atomic);
#else
if (rmdir ((char *) atomic->lck) == 0)
return FcAtomicLock (atomic);
#endif
}
}
return FcFalse;
......@@ -174,7 +191,11 @@ FcAtomicDeleteNew (FcAtomic *atomic)
void
FcAtomicUnlock (FcAtomic *atomic)
{
#ifdef HAVE_LINK
unlink ((char *) atomic->lck);
#else
rmdir ((char *) atomic->lck);
#endif
}
void
......
......@@ -188,9 +188,19 @@ FcCacheWritePath (FILE *f, const FcChar8 *dir, const FcChar8 *file)
if (dir)
if (!FcCacheWriteChars (f, dir))
return FcFalse;
#ifdef _WIN32
if (dir &&
dir[strlen((const char *) dir) - 1] != '/' &&
dir[strlen((const char *) dir) - 1] != '\\')
{
if (!FcCacheWriteChars (f, "\\"))
return FcFalse;
}
#else
if (dir && dir[strlen((const char *) dir) - 1] != '/')
if (PUTC ('/', f) == EOF)
return FcFalse;
#endif
if (!FcCacheWriteChars (f, file))
return FcFalse;
if (PUTC ('"', f) == EOF)
......@@ -258,8 +268,13 @@ FcCacheFontSetAdd (FcFontSet *set,
return FcFalse;
}
strncpy ((char *) path, (const char *) dir, dir_len);
#ifdef _WIN32
if (dir[dir_len - 1] != '/' && dir[dir_len - 1] != '\\' )
path[dir_len++] = '\\';
#else
if (dir[dir_len - 1] != '/')
path[dir_len++] = '/';
#endif
strcpy ((char *) path + dir_len, (const char *) file);
if (!FcStrCmp (name, FC_FONT_FILE_DIR))
{
......@@ -361,7 +376,7 @@ FcFilePathInfoGet (const FcChar8 *path)
FcFilePathInfo i;
FcChar8 *slash;
slash = (FcChar8 *) strrchr ((const char *) path, '/');
slash = FcStrLastSlash (path);
if (slash)
{
i.dir = path;
......@@ -840,9 +855,11 @@ FcGlobalCacheSave (FcGlobalCache *cache,
if (cache->broken)
return FcFalse;
#if defined (HAVE_GETUID) && defined (HAVE_GETEUID)
/* Set-UID programs can't safely update the cache */
if (getuid () != geteuid ())
return FcFalse;
#endif
atomic = FcAtomicCreate (cache_file);
if (!atomic)
......@@ -1033,7 +1050,7 @@ FcFileBaseName (const FcChar8 *cache, const FcChar8 *file)
{
const FcChar8 *cache_slash;
cache_slash = (const FcChar8 *) strrchr ((const char *) cache, '/');
cache_slash = FcStrLastSlash (cache);
if (cache_slash && !strncmp ((const char *) cache, (const char *) file,
(cache_slash + 1) - cache))
return file + ((cache_slash + 1) - cache);
......
......@@ -24,6 +24,12 @@
#include "fcint.h"
#if defined (_WIN32) && defined (PIC)
#define STRICT
#include <windows.h>
#undef STRICT
#endif
FcConfig *_fcConfig;
FcConfig *
......@@ -1267,10 +1273,58 @@ FcConfigSubstitute (FcConfig *config,
return FcConfigSubstituteWithPat (config, p, 0, kind);
}
#if defined (_WIN32) && defined (PIC)
static FcChar8 fontconfig_path[1000] = "";
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
FcChar8 *p;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
if (!GetModuleFileName ((HMODULE) hinstDLL, fontconfig_path,
sizeof (fontconfig_path)))
break;
/* If the fontconfig DLL is in a "bin" or "lib" subfolder,
* assume it's a Unix-style installation tree, and use
* "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
* folder where the DLL is as FONTCONFIG_PATH.
*/
p = strrchr (fontconfig_path, '\\');
if (p)
{
*p = '\0';
p = strrchr (fontconfig_path, '\\');
if (p && (FcStrCmpIgnoreCase (p + 1, "bin") == 0 ||
FcStrCmpIgnoreCase (p + 1, "lib") == 0))
*p = '\0';
strcat (fontconfig_path, "\\etc\\fonts");
}
else
fontconfig_path[0] = '\0';
break;
}
return TRUE;
}
#undef FONTCONFIG_PATH
#define FONTCONFIG_PATH fontconfig_path
#else /* !(_WIN32 && PIC) */
#ifndef FONTCONFIG_PATH
#define FONTCONFIG_PATH "/etc/fonts"
#endif
#endif /* !(_WIN32 && PIC) */
#ifndef FONTCONFIG_FILE
#define FONTCONFIG_FILE "fonts.conf"
#endif
......@@ -1287,9 +1341,16 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
return 0;
strcpy ((char *) path, (const char *) dir);
/* make sure there's a single separating / */
/* make sure there's a single separator */
#ifdef _WIN32
if ((!path[0] || (path[strlen((char *) path)-1] != '/' &&
path[strlen((char *) path)-1] != '\\')) &&
(file[0] != '/' && file[0] != '\\'))
strcat ((char *) path, "\\");
#else
if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
strcat ((char *) path, "/");
#endif
strcat ((char *) path, (char *) file);
FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1);
......@@ -1316,7 +1377,7 @@ FcConfigGetPath (void)
e = env;
npath++;
while (*e)
if (*e++ == ':')
if (*e++ == FC_SEARCH_PATH_SEPARATOR)
npath++;
}
path = calloc (npath, sizeof (FcChar8 *));
......@@ -1329,7 +1390,7 @@ FcConfigGetPath (void)
e = env;
while (*e)
{
colon = (FcChar8 *) strchr ((char *) e, ':');
colon = (FcChar8 *) strchr ((char *) e, FC_SEARCH_PATH_SEPARATOR);
if (!colon)
colon = e + strlen ((char *) e);
path[i] = malloc (colon - e + 1);
......@@ -1376,7 +1437,16 @@ FcChar8 *
FcConfigHome (void)
{
if (_FcConfigHomeEnabled)
return getenv ("HOME");
{
char *home = getenv ("HOME");
#ifdef _WIN32
if (home == NULL)
home = getenv ("USERPROFILE");
#endif
return home;
}
return 0;
}
......@@ -1400,6 +1470,14 @@ FcConfigFilename (const FcChar8 *url)
url = (FcChar8 *) FONTCONFIG_FILE;
}
file = 0;
#ifdef _WIN32
if (isalpha (*url) &&
url[1] == ':' &&
(url[2] == '/' || url[2] == '\\'))
goto absolute_path;
#endif
switch (*url) {
case '~':
dir = FcConfigHome ();
......@@ -1408,6 +1486,10 @@ FcConfigFilename (const FcChar8 *url)
else
file = 0;
break;
#ifdef _WIN32
case '\\':
absolute_path:
#endif
case '/':
file = FcConfigFileExists (0, url);
break;
......
......@@ -53,6 +53,12 @@ typedef struct _FcSymbolic {
#define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
#define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
#ifdef _WIN32
#define FC_SEARCH_PATH_SEPARATOR ';'
#else
#define FC_SEARCH_PATH_SEPARATOR ':'
#endif
#define FC_DBG_MATCH 1
#define FC_DBG_MATCHV 2
#define FC_DBG_EDIT 4
......@@ -649,4 +655,7 @@ FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
FcBool
FcStrUsesHome (const FcChar8 *s);
FcChar8 *
FcStrLastSlash (const FcChar8 *path);
#endif /* _FC_INT_H_ */
......@@ -447,13 +447,32 @@ FcStrCopyFilename (const FcChar8 *s)
return new;
}
FcChar8 *
FcStrLastSlash (const FcChar8 *path)
{
FcChar8 *slash;
slash = (FcChar8 *) strrchr ((const char *) path, '/');
#ifdef _WIN32
{
FcChar8 *backslash;
backslash = (FcChar8 *) strrchr ((const char *) path, '\\');
if (!slash || (backslash && backslash > slash))
slash = backslash;
}
#endif
return slash;
}
FcChar8 *
FcStrDirname (const FcChar8 *file)
{
FcChar8 *slash;
FcChar8 *dir;
slash = (FcChar8 *) strrchr ((char *) file, '/');
slash = FcStrLastSlash (file);
if (!slash)
return FcStrCopy ((FcChar8 *) ".");
dir = malloc ((slash - file) + 1);
......@@ -470,7 +489,7 @@ FcStrBasename (const FcChar8 *file)
{
FcChar8 *slash;
slash = (FcChar8 *) strrchr ((char *) file, '/');
slash = FcStrLastSlash (file);
if (!slash)
return FcStrCopy (file);
return FcStrCopy (slash + 1);
......
......@@ -35,6 +35,12 @@
#include <expat.h>
#endif
#ifdef _WIN32
#define STRICT
#include <windows.h>
#undef STRICT
#endif
FcTest *
FcTestCreate (FcMatchKind kind,
FcQual qual,
......@@ -1600,6 +1606,30 @@ FcEndElement(void *userData, const XML_Char *name)
FcConfigMessage (parse, FcSevereError, "out of memory");
break;
}
#ifdef _WIN32
if (strcmp (data, "WINDOWSFONTDIR") == 0)
{
int rc;
FcStrFree (data);
data = malloc (1000);
if (!data)
{
FcConfigMessage (parse, FcSevereError, "out of memory");
break;
}
FcMemAlloc (FC_MEM_STRING, 1000);
rc = GetWindowsDirectory (data, 800);
if (rc == 0 || rc > 800)
{
FcConfigMessage (parse, FcSevereError, "GetWindowsDirectory failed");
FcStrFree (data);
break;
}
if (data [strlen (data) - 1] != '\\')
strcat (data, "\\");
strcat (data, "fonts");
}
#endif
if (!FcStrUsesHome (data) || FcConfigHome ())
{
if (!FcConfigAddDir (parse->config, data))
......
LIBRARY fontconfig
VERSION LIBRARY_VERSION
EXPORTS
FcAtomicCreate
FcAtomicDeleteNew
FcAtomicDestroy
FcAtomicLock
FcAtomicNewFile
FcAtomicOrigFile
FcAtomicReplaceOrig
FcAtomicUnlock
FcAvlDelete
FcAvlInsert
FcBlanksAdd
FcBlanksCreate
FcBlanksDestroy
FcBlanksIsMember
FcFileCacheCreate
FcFileCacheDestroy
FcFileCacheFind
FcFileCacheLoad
FcFileCacheReadDir
FcFileCacheSave
FcFileCacheUpdate
FcFileCacheWriteDir
FcConfigAddBlank
FcConfigAddConfigFile
FcConfigAddDir
FcConfigAddEdit
FcConfigAppFontAddDir
FcConfigAppFontAddFile
FcConfigAppFontClear
FcConfigBuildFonts
FcConfigCompareValue
FcConfigCreate
FcConfigDestroy
FcConfigFilename
FcConfigGetBlanks
FcConfigGetCache
FcConfigGetConfigFiles
FcConfigGetCurrent
FcConfigGetDirs
FcConfigGetFonts
FcConfigSetCache
FcConfigSetCurrent
FcConfigSetFonts
FcConfigSubstitute
FcCharSetAddChar
FcCharSetCopy
FcCharSetCount
FcCharSetCoverage
FcCharSetCreate
FcCharSetDestroy
FcCharSetEqual
FcCharSetHasChar
FcCharSetIntersect
FcCharSetIntersectCount
FcCharSetNew
FcCharSetSubtract
FcCharSetSubtractCount
FcCharSetUnion
FcFreeTypeCharIndex
FcFreeTypeCharSet
FcNameParseCharSet
FcNameUnparseCharSet
FcDebug
FcEditPrint
FcExprPrint
FcFontSetPrint
FcOpPrint
FcPatternPrint