2 * $RCSId: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 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 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.
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.
29 FcFileIsDir (const FcChar8 *file)
33 if (stat ((const char *) file, &statb) != 0)
35 return S_ISDIR(statb.st_mode);
39 FcFileScanConfig (FcFontSet *set,
52 if (config && !FcConfigAcceptFilename (config, file))
55 if (FcFileIsDir (file))
56 return FcStrSetAdd (dirs, file);
66 * Nothing in the cache, scan the file
68 if (FcDebug () & FC_DBG_SCAN)
70 printf ("\tScanning file %s...", file);
73 font = FcFreeTypeQuery (file, id, blanks, &count);
74 if (FcDebug () & FC_DBG_SCAN)
79 if (font && (!config || FcConfigAcceptFont (config, font)))
81 if (!FcFontSetAdd (set, font))
83 FcPatternDestroy (font);
89 FcPatternDestroy (font);
91 } while (font && ret && id < count);
96 FcFileScan (FcFontSet *set,
103 return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0);
107 * Scan 'dir', adding font files to 'set' and
108 * subdirectories to 'dirs'
112 FcDirScanConfig (FcFontSet *set,
114 FcGlobalCache *cache,
123 const FcChar8 *d_can = 0;
129 if (config && !FcConfigAcceptFilename (config, dir))
133 d_can = FcConfigNormalizeFontDir (config, dir);
140 * Check ~/.fonts.cache-<version> file
142 if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
145 if (FcDirCacheValid (dir) &&
146 FcDirCacheHasCurrentArch (dir) &&
147 FcDirCacheRead (set, dirs, dir, config))
152 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
156 strcpy ((char *) file, (char *) dir);
157 strcat ((char *) file, "/");
158 base = file + strlen ((char *) file);
160 if (FcDebug () & FC_DBG_SCAN)
161 printf ("\tScanning dir %s\n", dir);
163 d = opendir ((char *) dir);
167 /* Don't complain about missing directories */
173 tmpSet = FcFontSetCreate();
180 while (ret && (e = readdir (d)))
182 if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
184 strcpy ((char *) base, (char *) e->d_name);
185 ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
191 * Now that the directory has been scanned,
192 * add the cache entry
195 FcGlobalCacheUpdate (cache, dirs, (char *)dir, tmpSet, config);
197 for (i = 0; i < tmpSet->nfont; i++)
198 FcFontSetAdd (set, tmpSet->fonts[i]);
202 FcMemFree (FC_MEM_FONTPTR, tmpSet->sfont * sizeof (FcPattern *));
203 free (tmpSet->fonts);
205 FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
212 FcDirScan (FcFontSet *set,
214 FcGlobalCache *cache,
219 return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0);
223 FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
225 return FcDirCacheWrite (set, dirs, dir);