]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
2 * fontconfig/src/fcdir.c
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 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 FcFileIsDir (const FcChar8
*file
)
33 if (FcStat (file
, &statb
) != 0)
35 return S_ISDIR(statb
.st_mode
);
39 FcFileScanFontConfig (FcFontSet
*set
,
54 * Nothing in the cache, scan the file
56 if (FcDebug () & FC_DBG_SCAN
)
58 printf ("\tScanning file %s...", file
);
61 font
= FcFreeTypeQuery (file
, id
, blanks
, &count
);
62 if (FcDebug () & FC_DBG_SCAN
)
66 * Edit pattern with user-defined rules
68 if (font
&& config
&& !FcConfigSubstitute (config
, font
, FcMatchScan
))
70 FcPatternDestroy (font
);
80 if (FcDebug() & FC_DBG_SCANV
)
82 printf ("Final font pattern:\n");
83 FcPatternPrint (font
);
85 if (!FcFontSetAdd (set
, font
))
87 FcPatternDestroy (font
);
93 FcPatternDestroy (font
);
95 } while (font
&& ret
&& id
< count
);
100 FcFileScanConfig (FcFontSet
*set
,
106 if (FcFileIsDir (file
))
107 return FcStrSetAdd (dirs
, file
);
109 return FcFileScanFontConfig (set
, blanks
, file
, config
);
113 FcFileScan (FcFontSet
*set
,
115 FcFileCache
*cache
, /* XXX unused */
120 return FcFileScanConfig (set
, dirs
, blanks
, file
, FcConfigGetCurrent ());
124 * Strcmp helper that takes pointers to pointers, copied from qsort(3) manpage
127 cmpstringp(const void *p1
, const void *p2
)
129 return strcmp(* (char **) p1
, * (char **) p2
);
133 FcDirScanConfig (FcFontSet
*set
,
137 FcBool force
, /* XXX unused */
145 const FcChar8
*scanDir
;
157 blanks
= FcConfigGetBlanks (config
);
160 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
166 strcpy ((char *) file
, (char *) dir
);
167 strcat ((char *) file
, "/");
168 base
= file
+ strlen ((char *) file
);
170 if (FcDebug () & FC_DBG_SCAN
)
171 printf ("\tScanning dir %s\n", dir
);
173 fullDir
= FcConfigGetRootPlus (dir
);
178 d
= opendir ((char *) scanDir
);
183 /* Don't complain about missing directories */
189 files
= FcStrSetCreate ();
195 while ((e
= readdir (d
)))
197 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
199 strcpy ((char *) base
, (char *) e
->d_name
);
200 if (!FcStrSetAdd (files
, file
)) {
208 * Sort files to make things prettier
210 qsort(files
->strs
, files
->num
, sizeof(FcChar8
*), cmpstringp
);
213 * Scan file files to build font patterns
215 for (i
= 0; i
< files
->num
; i
++)
216 FcFileScanConfig (set
, dirs
, blanks
, files
->strs
[i
], config
);
219 FcStrSetDestroy (files
);
227 FcDirScan (FcFontSet
*set
,
229 FcFileCache
*cache
, /* XXX unused */
232 FcBool force
/* XXX unused */)
237 return FcDirScanConfig (set
, dirs
, blanks
, dir
, force
, FcConfigGetCurrent ());
241 * Scan the specified directory and construct a cache of its contents
244 FcDirCacheScan (const FcChar8
*dir
, FcConfig
*config
)
248 FcCache
*cache
= NULL
;
249 struct stat dir_stat
;
251 if (FcDebug () & FC_DBG_FONTSET
)
252 printf ("cache scan dir %s\n", dir
);
254 if (FcStat (dir
, &dir_stat
) < 0)
257 set
= FcFontSetCreate();
261 dirs
= FcStrSetCreate ();
268 if (!FcDirScanConfig (set
, dirs
, NULL
, dir
, FcTrue
, config
))
272 * Build the cache object
274 cache
= FcDirCacheBuild (set
, dir
, &dir_stat
, dirs
);
279 * Write out the cache file, ignoring any troubles
281 FcDirCacheWrite (cache
, config
);
284 FcStrSetDestroy (dirs
);
286 FcFontSetDestroy (set
);
292 * Read (or construct) the cache for a directory
295 FcDirCacheRead (const FcChar8
*dir
, FcBool force
, FcConfig
*config
)
297 FcCache
*cache
= NULL
;
299 /* Try to use existing cache file */
301 cache
= FcDirCacheLoad (dir
, config
, NULL
);
303 /* Not using existing cache file, construct new cache */
305 cache
= FcDirCacheScan (dir
, config
);
311 FcDirSave (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
)
313 return FcFalse
; /* XXX deprecated */
316 #include "fcaliastail.h"