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)
76 "Fontconfig warning: no <cachedir> elements found. Check configuration.\n");
78 "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
81 "Fontconfig warning: adding <cachedir>~/.fontconfig</cachedir>\n");
82 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR) ||
83 !FcConfigAddCacheDir (config, (FcChar8 *) "~/.fontconfig"))
86 "Fontconfig error: out of memory");
87 FcConfigDestroy (config);
88 return FcInitFallbackConfig ();
96 * Load the configuration files and scan for available fonts
99 FcInitLoadConfigAndFonts (void)
101 FcConfig *config = FcInitLoadConfig ();
106 if (!FcConfigBuildFonts (config))
108 FcConfigDestroy (config);
115 * Initialize the default library configuration
124 config = FcInitLoadConfigAndFonts ();
127 FcConfigSetCurrent (config);
128 if (FcDebug() & FC_DBG_MEMORY)
134 * Free all library-allocated data structures.
140 FcConfigDestroy (_fcConfig);
144 if (FcDebug() & FC_DBG_MEMORY)
149 * Reread the configuration and available font lists
152 FcInitReinitialize (void)
156 config = FcInitLoadConfigAndFonts ();
159 FcConfigSetCurrent (config);
164 FcInitBringUptoDate (void)
166 FcConfig *config = FcConfigGetCurrent ();
170 * rescanInterval == 0 disables automatic up to date
172 if (config->rescanInterval == 0)
175 * Check no more often than rescanInterval seconds
178 if (config->rescanTime + config->rescanInterval - now > 0)
181 * If up to date, don't reload configuration
183 if (FcConfigUptoDate (0))
185 return FcInitReinitialize ();
194 } FcInUse[FC_MEM_NUM] = {
227 static int FcAllocCount, FcAllocMem;
228 static int FcFreeCount, FcFreeMem;
230 static int FcMemNotice = 1*1024*1024;
232 static int FcAllocNotify, FcFreeNotify;
238 printf ("Fc Memory Usage:\n");
239 printf ("\t Which Alloc Free Active\n");
240 printf ("\t count bytes count bytes count bytes\n");
241 for (i = 0; i < FC_MEM_NUM; i++)
242 printf ("%16.16s%8d%8d%8d%8d%8d%8d\n",
244 FcInUse[i].alloc_count, FcInUse[i].alloc_mem,
245 FcInUse[i].free_count, FcInUse[i].free_mem,
246 FcInUse[i].alloc_count - FcInUse[i].free_count,
247 FcInUse[i].alloc_mem - FcInUse[i].free_mem);
248 printf ("%16.16s%8d%8d%8d%8d%8d%8d\n",
250 FcAllocCount, FcAllocMem,
251 FcFreeCount, FcFreeMem,
252 FcAllocCount - FcFreeCount,
253 FcAllocMem - FcFreeMem);
259 FcMemAlloc (int kind, int size)
261 if (FcDebug() & FC_DBG_MEMORY)
263 FcInUse[kind].alloc_count++;
264 FcInUse[kind].alloc_mem += size;
267 FcAllocNotify += size;
268 if (FcAllocNotify > FcMemNotice)
274 FcMemFree (int kind, int size)
276 if (FcDebug() & FC_DBG_MEMORY)
278 FcInUse[kind].free_count++;
279 FcInUse[kind].free_mem += size;
282 FcFreeNotify += size;
283 if (FcFreeNotify > FcMemNotice)
288 #include "fcaliastail.h"