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.
29 FcInitFallbackConfig (void)
33 config = FcConfigCreate ();
36 if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
38 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
43 FcConfigDestroy (config);
55 * Load the configuration files
58 FcInitLoadConfig (void)
63 config = FcConfigCreate ();
67 if (!FcConfigParseAndLoad (config, 0, FcTrue))
69 FcConfigDestroy (config);
70 return FcInitFallbackConfig ();
73 if (config->cacheDirs && config->cacheDirs->num == 0)
79 "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
81 "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
83 prefix = FcConfigXdgCacheHome ();
86 plen = strlen ((const char *)prefix);
87 p = realloc (prefix, plen + 12);
91 memcpy (&prefix[plen], FC_DIR_SEPARATOR_S "fontconfig", 11);
92 prefix[plen + 11] = 0;
94 "Fontconfig warning: adding <cachedir prefix=\"xdg\">fontconfig</cachedir>\n");
96 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
97 !FcConfigAddCacheDir (config, (FcChar8 *) prefix))
101 "Fontconfig error: out of memory");
104 FcConfigDestroy (config);
105 return FcInitFallbackConfig ();
114 * Load the configuration files and scan for available fonts
117 FcInitLoadConfigAndFonts (void)
119 FcConfig *config = FcInitLoadConfig ();
124 if (!FcConfigBuildFonts (config))
126 FcConfigDestroy (config);
133 * Initialize the default library configuration
138 return FcConfigInit ();
142 * Free all library-allocated data structures.
153 * Reread the configuration and available font lists
156 FcInitReinitialize (void)
160 config = FcInitLoadConfigAndFonts ();
163 return FcConfigSetCurrent (config);
167 FcInitBringUptoDate (void)
169 FcConfig *config = FcConfigGetCurrent ();
173 * rescanInterval == 0 disables automatic up to date
175 if (config->rescanInterval == 0)
178 * Check no more often than rescanInterval seconds
181 if (config->rescanTime + config->rescanInterval - now > 0)
184 * If up to date, don't reload configuration
186 if (FcConfigUptoDate (0))
188 return FcInitReinitialize ();
192 #include "fcaliastail.h"