2 * fontconfig/src/fcinit.c
4 * Copyright © 2001 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
28 #if defined(FC_ATOMIC_INT_NIL)
29 #pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe.")
31 #if defined(FC_MUTEX_IMPL_NIL)
32 #pragma message("Could not find any system to define mutex macros, library may NOT be thread-safe.")
34 #if defined(FC_ATOMIC_INT_NIL) || defined(FC_MUTEX_IMPL_NIL)
35 #pragma message("To suppress these warnings, define FC_NO_MT.")
39 FcInitFallbackConfig (const FcChar8 *sysroot)
43 config = FcConfigCreate ();
46 FcConfigSetSysRoot (config, sysroot);
47 if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
49 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
54 FcConfigDestroy (config);
66 * Load the configuration files
69 FcInitLoadOwnConfig (FcConfig *config)
73 config = FcConfigCreate ();
80 if (!FcConfigParseAndLoad (config, 0, FcTrue))
82 const FcChar8 *sysroot = FcConfigGetSysRoot (config);
83 FcConfig *fallback = FcInitFallbackConfig (sysroot);
85 FcConfigDestroy (config);
90 if (config->cacheDirs && config->cacheDirs->num == 0)
94 FcBool have_own = FcFalse;
95 char *env_file, *env_path;
97 env_file = getenv ("FONTCONFIG_FILE");
98 env_path = getenv ("FONTCONFIG_PATH");
99 if ((env_file != NULL && env_file[0] != 0) ||
100 (env_path != NULL && env_path[0] != 0))
106 "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
108 "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
111 prefix = FcConfigXdgCacheHome ();
114 plen = strlen ((const char *)prefix);
115 p = realloc (prefix, plen + 12);
119 memcpy (&prefix[plen], FC_DIR_SEPARATOR_S "fontconfig", 11);
120 prefix[plen + 11] = 0;
123 "Fontconfig warning: adding <cachedir prefix=\"xdg\">fontconfig</cachedir>\n");
125 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
126 !FcConfigAddCacheDir (config, (FcChar8 *) prefix))
129 const FcChar8 *sysroot;
132 sysroot = FcConfigGetSysRoot (config);
134 "Fontconfig error: out of memory");
137 fallback = FcInitFallbackConfig (sysroot);
138 FcConfigDestroy (config);
149 FcInitLoadConfig (void)
151 return FcInitLoadOwnConfig (NULL);
155 * Load the configuration files and scan for available fonts
158 FcInitLoadOwnConfigAndFonts (FcConfig *config)
160 config = FcInitLoadOwnConfig (config);
163 if (!FcConfigBuildFonts (config))
165 FcConfigDestroy (config);
172 FcInitLoadConfigAndFonts (void)
174 return FcInitLoadOwnConfigAndFonts (NULL);
178 * Initialize the default library configuration
183 return FcConfigInit ();
187 * Free all library-allocated data structures.
200 * Reread the configuration and available font lists
203 FcInitReinitialize (void)
208 config = FcInitLoadConfigAndFonts ();
211 ret = FcConfigSetCurrent (config);
212 /* FcConfigSetCurrent() increases the refcount.
213 * decrease it here to avoid the memory leak.
215 FcConfigDestroy (config);
221 FcInitBringUptoDate (void)
223 FcConfig *config = FcConfigGetCurrent ();
229 * rescanInterval == 0 disables automatic up to date
231 if (config->rescanInterval == 0)
234 * Check no more often than rescanInterval seconds
237 if (config->rescanTime + config->rescanInterval - now > 0)
240 * If up to date, don't reload configuration
242 if (FcConfigUptoDate (0))
244 return FcInitReinitialize ();
248 #include "fcaliastail.h"