]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
0b7c8d8c9290401dd4149fe05e9abc6ac897c8f0
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 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
)
67 if (font
&& (!config
|| FcConfigAcceptFont (config
, font
)))
69 if (!FcFontSetAdd (set
, font
))
71 FcPatternDestroy (font
);
77 FcPatternDestroy (font
);
79 } while (font
&& ret
&& id
< count
);
84 FcFileScanConfig (FcFontSet
*set
,
90 if (FcFileIsDir (file
))
91 return FcStrSetAdd (dirs
, file
);
93 return FcFileScanFontConfig (set
, blanks
, file
, config
);
97 FcFileScan (FcFontSet
*set
,
99 FcFileCache
*cache
, /* XXX unused */
104 return FcFileScanConfig (set
, dirs
, blanks
, file
, NULL
);
108 * Strcmp helper that takes pointers to pointers, copied from qsort(3) manpage
111 cmpstringp(const void *p1
, const void *p2
)
113 return strcmp(* (char **) p1
, * (char **) p2
);
117 * Scan the specified directory and construct a cache of its contents
120 FcDirCacheScan (const FcChar8
*dir
, FcConfig
*config
)
131 FcBlanks
*blanks
= FcConfigGetBlanks (config
);
132 FcCache
*cache
= NULL
;
134 if (FcDebug () & FC_DBG_FONTSET
)
135 printf ("cache scan dir %s\n", dir
);
138 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
144 strcpy ((char *) file
, (char *) dir
);
145 strcat ((char *) file
, "/");
146 base
= file
+ strlen ((char *) file
);
148 if (FcDebug () & FC_DBG_SCAN
)
149 printf ("\tScanning dir %s\n", dir
);
151 d
= opendir ((char *) dir
);
154 /* Don't complain about missing directories */
162 set
= FcFontSetCreate();
169 files
= FcStrSetCreate ();
175 while ((e
= readdir (d
)))
177 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
179 strcpy ((char *) base
, (char *) e
->d_name
);
180 if (!FcStrSetAdd (files
, file
)) {
188 * Sort files to make things prettier
190 qsort(files
->strs
, files
->num
, sizeof(FcChar8
*), cmpstringp
);
192 dirs
= FcStrSetCreate ();
197 * Scan file files to build font patterns
199 for (i
= 0; i
< files
->num
; i
++)
200 FcFileScanConfig (set
, dirs
, blanks
, files
->strs
[i
], config
);
203 * Build the cache object
205 cache
= FcDirCacheBuild (set
, dir
, dirs
);
210 * Write out the cache file, ignoring any troubles
212 FcDirCacheWrite (cache
, config
);
215 FcStrSetDestroy (dirs
);
217 FcStrSetDestroy (files
);
219 FcFontSetDestroy (set
);
231 * Read (or construct) the cache for a directory
234 FcDirCacheRead (const FcChar8
*dir
, FcBool force
, FcConfig
*config
)
236 FcCache
*cache
= NULL
;
239 canon_dir
= FcStrCanonFilename (dir
);
240 if (!canon_dir
) canon_dir
= (FcChar8
*) dir
;
242 if (config
&& !FcConfigAcceptFilename (config
, canon_dir
)) {
246 /* Try to use existing cache file */
248 cache
= FcDirCacheLoad (canon_dir
, config
, NULL
);
250 /* Not using existing cache file, construct new cache */
252 cache
= FcDirCacheScan (canon_dir
, config
);
255 if (canon_dir
!= dir
)
262 FcDirScanConfig (FcFontSet
*set
,
269 return FcFalse
; /* XXX fixme */
273 FcDirScan (FcFontSet
*set
,
275 FcFileCache
*cache
, /* XXX unused */
280 return FcDirScanConfig (set
, dirs
, blanks
, dir
, force
, NULL
);
284 FcDirSave (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
)
286 return FcFalse
; /* XXX deprecated */