]>
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 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 (FcStat ((const char *) 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
&& !FcConfigSubstituteWithPat (config
, font
, NULL
, FcMatchScan
))
70 FcPatternDestroy (font
);
78 if (font
&& (!config
|| FcConfigAcceptFont (config
, 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
, NULL
);
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 */
155 blanks
= FcConfigGetBlanks (config
);
158 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
164 strcpy ((char *) file
, (char *) dir
);
165 strcat ((char *) file
, "/");
166 base
= file
+ strlen ((char *) file
);
168 if (FcDebug () & FC_DBG_SCAN
)
169 printf ("\tScanning dir %s\n", dir
);
171 d
= opendir ((char *) dir
);
174 /* Don't complain about missing directories */
180 files
= FcStrSetCreate ();
186 while ((e
= readdir (d
)))
188 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
190 strcpy ((char *) base
, (char *) e
->d_name
);
191 if (!FcStrSetAdd (files
, file
)) {
199 * Sort files to make things prettier
201 qsort(files
->strs
, files
->num
, sizeof(FcChar8
*), cmpstringp
);
204 * Scan file files to build font patterns
206 for (i
= 0; i
< files
->num
; i
++)
207 FcFileScanConfig (set
, dirs
, blanks
, files
->strs
[i
], config
);
210 FcStrSetDestroy (files
);
218 FcDirScan (FcFontSet
*set
,
220 FcFileCache
*cache
, /* XXX unused */
223 FcBool force
/* XXX unused */)
228 return FcDirScanConfig (set
, dirs
, blanks
, dir
, force
, NULL
);
232 * Scan the specified directory and construct a cache of its contents
235 FcDirCacheScan (const FcChar8
*dir
, FcConfig
*config
)
240 FcCache
*cache
= NULL
;
241 struct stat dir_stat
;
243 if (FcDebug () & FC_DBG_FONTSET
)
244 printf ("cache scan dir %s\n", dir
);
246 if (FcStat ((char *) dir
, &dir_stat
) < 0)
253 set
= FcFontSetCreate();
260 dirs
= FcStrSetCreate ();
270 if (!FcDirScanConfig (set
, dirs
, NULL
, dir
, FcTrue
, config
))
277 * Build the cache object
279 cache
= FcDirCacheBuild (set
, dir
, &dir_stat
, dirs
);
287 * Write out the cache file, ignoring any troubles
289 FcDirCacheWrite (cache
, config
);
292 FcStrSetDestroy (dirs
);
294 FcFontSetDestroy (set
);
300 * Read (or construct) the cache for a directory
303 FcDirCacheRead (const FcChar8
*dir
, FcBool force
, FcConfig
*config
)
305 FcCache
*cache
= NULL
;
307 if (config
&& !FcConfigAcceptFilename (config
, dir
))
310 /* Try to use existing cache file */
312 cache
= FcDirCacheLoad (dir
, config
, NULL
);
314 /* Not using existing cache file, construct new cache */
316 cache
= FcDirCacheScan (dir
, config
);
322 FcDirSave (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
)
324 return FcFalse
; /* XXX deprecated */
327 #include "fcaliastail.h"