]> git.wh0rd.org - fontconfig.git/blame - src/fcinit.c
Change files from ISO-Latin-1 to UTF-8
[fontconfig.git] / src / fcinit.c
CommitLineData
24330d27 1/*
4bd4418a 2 * $RCSId: xc/lib/fontconfig/src/fcinit.c,v 1.7 2002/08/22 07:36:44 keithp Exp $
24330d27 3 *
46b51147 4 * Copyright © 2001 Keith Packard
24330d27
KP
5 *
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 Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
15 *
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD 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.
23 */
24
25#include <stdlib.h>
26#include "fcint.h"
27
179c3995 28static FcConfig *
24330d27
KP
29FcInitFallbackConfig (void)
30{
31 FcConfig *config;
32
33 config = FcConfigCreate ();
34 if (!config)
35 goto bail0;
446bb9c9 36 if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
24330d27 37 goto bail1;
179c3995 38 return config;
24330d27
KP
39
40bail1:
41 FcConfigDestroy (config);
42bail0:
179c3995 43 return 0;
24330d27
KP
44}
45
48db40f6
KP
46int
47FcGetVersion (void)
48{
49 return FC_VERSION;
50}
51
24330d27 52/*
179c3995 53 * Load the configuration files
24330d27 54 */
179c3995
KP
55FcConfig *
56FcInitLoadConfig (void)
24330d27 57{
179c3995 58 FcConfig *config;
24330d27
KP
59
60 config = FcConfigCreate ();
61 if (!config)
62 return FcFalse;
63
64 if (!FcConfigParseAndLoad (config, 0, FcTrue))
65 {
66 FcConfigDestroy (config);
67 return FcInitFallbackConfig ();
68 }
179c3995
KP
69
70 return config;
71}
72
73/*
74 * Load the configuration files and scan for available fonts
75 */
76FcConfig *
77FcInitLoadConfigAndFonts (void)
78{
79 FcConfig *config = FcInitLoadConfig ();
80
81 if (!config)
82 return 0;
83 if (!FcConfigBuildFonts (config))
84 {
85 FcConfigDestroy (config);
86 return 0;
87 }
88 return config;
89}
90
91/*
92 * Initialize the default library configuration
93 */
94FcBool
95FcInit (void)
96{
97 FcConfig *config;
98
99 if (_fcConfig)
100 return FcTrue;
101 config = FcInitLoadConfigAndFonts ();
102 if (!config)
103 return FcTrue;
104 FcConfigSetCurrent (config);
d8d73958
KP
105 if (FcDebug() & FC_DBG_MEMORY)
106 FcMemReport ();
179c3995
KP
107 return FcTrue;
108}
109
34cd0514
CW
110/*
111 * Free all library-allocated data structures.
112 */
113void
114FcFini (void)
115{
116 if (_fcConfig)
117 FcConfigDestroy (_fcConfig);
118
119 FcPatternThawAll ();
120 FcCharSetThawAll ();
121}
122
179c3995
KP
123/*
124 * Reread the configuration and available font lists
125 */
126FcBool
127FcInitReinitialize (void)
128{
129 FcConfig *config;
130
131 config = FcInitLoadConfigAndFonts ();
132 if (!config)
133 return FcFalse;
24330d27
KP
134 FcConfigSetCurrent (config);
135 return FcTrue;
136}
137
138FcBool
179c3995 139FcInitBringUptoDate (void)
24330d27 140{
179c3995
KP
141 FcConfig *config = FcConfigGetCurrent ();
142 time_t now;
143
144 /*
145 * rescanInterval == 0 disables automatic up to date
146 */
147 if (config->rescanInterval == 0)
148 return FcTrue;
149 /*
150 * Check no more often than rescanInterval seconds
151 */
152 now = time (0);
153 if (config->rescanTime + config->rescanInterval - now > 0)
154 return FcTrue;
155 /*
156 * If up to date, don't reload configuration
157 */
158 if (FcConfigUptoDate (0))
159 return FcTrue;
160 return FcInitReinitialize ();
24330d27
KP
161}
162
163static struct {
164 char *name;
165 int alloc_count;
166 int alloc_mem;
167 int free_count;
168 int free_mem;
169} FcInUse[FC_MEM_NUM] = {
9dac3c59
KP
170 { "charset" },
171 { "charleaf" },
172 { "fontset" },
173 { "fontptr" },
174 { "objectset" },
175 { "objectptr" },
176 { "matrix" },
177 { "pattern" },
178 { "patelt" },
179 { "vallist" },
180 { "substate" },
181 { "string" },
182 { "listbuck" },
183 { "strset" },
184 { "strlist" },
185 { "config" },
186 { "langset" },
187 { "atomic" },
188 { "blanks" },
189 { "cache" },
190 { "strbuf" },
191 { "subst" },
192 { "objecttype" },
193 { "constant" },
194 { "test" },
195 { "expr" },
196 { "vstack" },
197 { "attr" },
198 { "pstack" },
24330d27
KP
199};
200
201static int FcAllocCount, FcAllocMem;
202static int FcFreeCount, FcFreeMem;
203
204static int FcMemNotice = 1*1024*1024;
205
206static int FcAllocNotify, FcFreeNotify;
207
d8d73958
KP
208void
209FcValueListReport (void);
210
24330d27
KP
211void
212FcMemReport (void)
213{
214 int i;
215 printf ("Fc Memory Usage:\n");
216 printf ("\t Which Alloc Free Active\n");
217 printf ("\t count bytes count bytes count bytes\n");
218 for (i = 0; i < FC_MEM_NUM; i++)
219 printf ("\t%8.8s%8d%8d%8d%8d%8d%8d\n",
220 FcInUse[i].name,
221 FcInUse[i].alloc_count, FcInUse[i].alloc_mem,
222 FcInUse[i].free_count, FcInUse[i].free_mem,
223 FcInUse[i].alloc_count - FcInUse[i].free_count,
224 FcInUse[i].alloc_mem - FcInUse[i].free_mem);
225 printf ("\t%8.8s%8d%8d%8d%8d%8d%8d\n",
226 "Total",
227 FcAllocCount, FcAllocMem,
228 FcFreeCount, FcFreeMem,
229 FcAllocCount - FcFreeCount,
230 FcAllocMem - FcFreeMem);
231 FcAllocNotify = 0;
232 FcFreeNotify = 0;
d8d73958 233 FcValueListReport ();
24330d27
KP
234}
235
236void
237FcMemAlloc (int kind, int size)
238{
239 if (FcDebug() & FC_DBG_MEMORY)
240 {
241 FcInUse[kind].alloc_count++;
242 FcInUse[kind].alloc_mem += size;
243 FcAllocCount++;
244 FcAllocMem += size;
245 FcAllocNotify += size;
246 if (FcAllocNotify > FcMemNotice)
247 FcMemReport ();
248 }
249}
250
251void
252FcMemFree (int kind, int size)
253{
254 if (FcDebug() & FC_DBG_MEMORY)
255 {
256 FcInUse[kind].free_count++;
257 FcInUse[kind].free_mem += size;
258 FcFreeCount++;
259 FcFreeMem += size;
260 FcFreeNotify += size;
261 if (FcFreeNotify > FcMemNotice)
262 FcMemReport ();
263 }
264}