1 --- XFree86-3.3.5/xc/programs/mkfontdir/mkfontdir.c.xfsftfontdir Fri Nov 13 09:17:34 1998
2 +++ XFree86-3.3.5/xc/programs/mkfontdir/mkfontdir.c Thu Aug 19 10:01:45 1999
5 #include <X11/Xproto.h>
12 #include <X11/keysymdef.h>
16 +Bool relative = FALSE;
18 +/* The possible extensions for encoding files, in decreasing priority */
19 +#ifdef X_GZIP_FONT_COMPRESSION
20 +#define NUMENCODINGEXTENSIONS 2
21 +char *encodingExtensions[]={".gz", ".Z"};
23 +#define NUMENCODINGEXTENSIONS 1
24 +char *encodingExtensions[]={".Z"};
27 +typedef struct _nameBucket {
28 + struct _nameBucket *next;
30 + FontRendererPtr renderer;
31 +} NameBucketRec, *NameBucketPtr;
33 +typedef struct _encodingBucket {
34 + struct _encodingBucket *next;
38 +} EncodingBucketRec, *EncodingBucketPtr;
40 +#define HASH_SIZE 1024
41 +/* should be a divisor of HASH_SIZE */
42 +#define ENCODING_HASH_SIZE 256
45 +static Bool WriteFontTable ( char *dirName, FontTablePtr table,
46 + EncodingBucketPtr *encodings, int count);
47 +static char * NameForAtomOrNone ( Atom a );
48 +static Bool GetFontName ( char *file_name, char *font_name );
49 +static char * FontNameExists ( FontTablePtr table, char *font_name );
50 +int AddEntry ( FontTablePtr table, char *fontName, char *fileName );
51 +static Bool ProcessFile ( char *dirName, char *fileName, FontTablePtr table );
52 +static void Estrip ( char *ext, char *name );
53 +char * MakeName ( char *name );
54 +int Hash ( char *name );
55 +Bool LoadEncodings(EncodingBucketPtr *encodings, char *dirName, int priority);
56 +static Bool LoadDirectory ( char *dirName, FontTablePtr table );
57 +int LoadScalable ( char *dirName, FontTablePtr table );
58 +static Bool DoDirectory(char *dirName,
59 + EncodingBucketPtr *encodings, int count);
60 +int GetDefaultPointSize ( void );
61 +void RegisterFPEFunctions ( void );
62 +void ErrorF ( void );
65 -WriteFontTable(dirName, table)
66 +WriteFontTable(dirName, table, encodings, count)
69 + EncodingBucketPtr *encodings;
74 char full_name[PATH_MAX];
76 + EncodingBucketPtr encoding;
78 sprintf (full_name, "%s/%s", dirName, FontDirFile);
81 fprintf (file, "%s %s\n", entry->u.bitmap.fileName, entry->name.name);
86 + /* Write out encodings directory */
88 + sprintf (full_name, "%s/%s", dirName, "encodings.dir");
89 + if (unlink(full_name) < 0 && errno != ENOENT)
91 + fprintf(stderr, "%s: warning: cannot unlink %s\n", progName, full_name);
92 + return TRUE; /* non fatal error */
94 + if(!count) return TRUE;
95 + file = fopen (full_name, "w");
98 + fprintf (stderr, "%s: can't create directory %s\n", progName, full_name);
101 + fprintf(file, "%d\n", count);
102 + for(i=0; i<ENCODING_HASH_SIZE; i++)
103 + for(encoding=encodings[i]; encoding; encoding=encoding->next)
104 + fprintf(file, "%s %s%s\n",
105 + encoding->name, prefix, encoding->fileName);
116 AddEntry (table, fontName, fileName)
118 char *fontName, *fileName;
121 CopyISOLatin1Lowered (font_name, font_name, strlen(font_name));
123 - if (existing = FontNameExists (table, font_name))
124 + if ((existing = FontNameExists (table, font_name)) != 0)
126 fprintf (stderr, "%s: Duplicate font names %s\n", progName, font_name);
127 fprintf (stderr, "\t%s %s\n", existing, fileName);
138 /***====================================================================***/
140 -typedef struct _nameBucket {
141 - struct _nameBucket *next;
143 - FontRendererPtr renderer;
144 -} NameBucketRec, *NameBucketPtr;
146 #define New(type,count) ((type *) malloc (count * sizeof (type)))
148 -#define HASH_SIZE 1024
157 - while (c = *name++)
158 + while ((c = *name++) != 0)
160 return i & (HASH_SIZE - 1);
165 NameBucketPtr *hashTable, bucket, *prev, next;
169 if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
170 @@ -435,8 +504,141 @@
174 -DoDirectory(dirName)
175 +CompareEncodingFiles(char *name1, char *name2)
177 + int len, len1, len2, p1, p2, i;
180 + len1=strlen(name1);
181 + len2=strlen(name2);
184 + for(extension=encodingExtensions[0], i=0;
185 + i<NUMENCODINGEXTENSIONS;
186 + extension++, i++) {
187 + len=strlen(extension);
188 + if(p1<0 && len1>=len && !strcmp(name1+len1-len, extension))
190 + if(p2<0 && len2>=len && !strcmp(name2+len2-len, extension))
203 +InsertEncoding(EncodingBucketPtr *encodings,
204 + char *name, char *fileName, int priority)
207 + EncodingBucketPtr encoding;
209 + bucket=Hash(name)%ENCODING_HASH_SIZE;
211 + for(encoding=encodings[bucket]; encoding; encoding=encoding->next) {
212 + if(!strcmp(name, encoding->name)) {
213 + if(encoding->priority<priority)
215 + else if(encoding->priority>priority)
217 + else if(CompareEncodingFiles(fileName, encoding->fileName))
226 + /* Need to insert new bucket */
227 + if((encoding=New(EncodingBucketRec, 1))==NULL)
229 + encoding->next=encodings[bucket];
230 + encodings[bucket]=encoding;
233 + /* Now encoding points to a bucket to fill in */
234 + encoding->name=name;
235 + encoding->fileName=fileName;
236 + encoding->priority=priority;
241 +LoadEncodings(EncodingBucketPtr *encodings, char *dirName, int priority)
243 + EncodingBucketPtr new;
247 + char fullname[MAXFONTFILENAMELEN];
251 + WIN32_FIND_DATA file;
254 + struct dirent *file;
257 + if (strcmp(dirName, ".") == 0) {
260 + len=strlen(dirName);
261 + strcpy(fullname, dirName);
262 + if(fullname[len-1]!='/')
263 + fullname[len++]='/';
268 + if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
271 + if ((dirp = opendir (dirName)) == NULL)
277 + while ((file = readdir (dirp)) != NULL) {
279 + if(len+strlen(FileName(file))>=MAXFONTFILENAMELEN) {
280 + fprintf(stderr, "%s: warning: filename `%s/%s' too long, ignored\n",
281 + progName, dirName, FileName(file));
284 + strcpy(fullname+len, FileName(file));
285 + names=identifyEncodingFile(fullname);
287 + if((filename=New(char, strlen(fullname)+1))==NULL) {
288 + fprintf(stderr, "%s: warning: out of memory.\n", progName);
291 + strcpy(filename, fullname);
292 + for(name=names; *name; name++)
293 + if(!InsertEncoding(encodings, *name, filename, priority))
294 + fprintf(stderr, "%s: warning: failed to insert encoding %s\n", *name);
295 + /* Only free the spine -- the names themselves may be used */
300 + while (FindNextFile(dirh, &file));
306 +DoDirectory(dirName, encodings, count)
308 + EncodingBucketPtr *encodings;
313 @@ -455,42 +657,113 @@
317 - status = WriteFontTable (dirName, &table);
318 + status = WriteFontTable (dirName, &table, encodings, count);
319 FontFileFreeTable (&table);
323 -GetDefaultPointSize ()
325 +GetDefaultPointSize (void)
330 -FontResolutionPtr GetClientResolutions ()
331 +FontResolutionPtr GetClientResolutions (num)
337 -RegisterFPEFunctions ()
339 +RegisterFPEFunctions (void)
349 /***====================================================================***/
357 + int argn, i, count;
358 + char *dirname, fulldirname[MAXFONTFILENAMELEN];
359 + EncodingBucketPtr *encodings, encoding;
362 BitmapRegisterFontFileFunctions ();
365 + if((encodings=New(EncodingBucketPtr, ENCODING_HASH_SIZE))==NULL) {
366 + fprintf(stderr, "%s: out of memory\n", progName);
369 + for(i=0; i<ENCODING_HASH_SIZE; i++)
372 + for(argn=1; argn<argc; argn++) {
373 + if(argv[argn][0]=='\0' || argv[argn][0]!='-')
375 + if(argv[argn][1]=='-') {
378 + } else if(argv[argn][1]=='e') {
379 + if(argv[argn][2]=='\0') {
382 + dirname=argv[argn];
384 + fprintf(stderr, "%s: -e requires an argument\n", progName);
388 + dirname=argv[argn]+2;
389 + if(dirname[0]=='/' || relative)
390 + LoadEncodings(encodings, dirname, argn);
392 + if(getcwd(fulldirname, MAXFONTFILENAMELEN)==NULL) {
393 + fprintf(stderr, "%s: failed to get cwd\n", progName);
396 + i=strlen(fulldirname);
397 + if(i+1+strlen(dirname)>=MAXFONTFILENAMELEN-1) {
398 + fprintf(stderr, "%s: directory name `%s' too long\n", progName,
402 + fulldirname[i++]='/';
403 + strcpy(fulldirname+i, dirname);
404 + LoadEncodings(encodings, fulldirname, argn);
406 + } else if(argv[argn][1]=='p') {
407 + if(argv[argn][2]=='\0') {
411 + prefix=argv[argn]+2;
412 + } else if(argv[argn][1]=='r') {
413 + if(argv[argn][2]=='\0')
416 + fprintf(stderr, "%s: unknown option `%s'\n", progName, argv[argn]);
420 + fprintf(stderr, "%s: unknown option `%s'\n", progName, argv[argn]);
424 + for(i=0; i<ENCODING_HASH_SIZE; i++)
425 + for(encoding=encodings[i]; encoding; encoding=encoding->next)
430 - if (!DoDirectory("."))
431 + if (!DoDirectory(".", encodings, count))
433 fprintf (stderr, "%s: failed to create directory in %s\n",
435 @@ -498,11 +771,11 @@
439 - for (i = 1; i < argc; i++) {
440 - if (!DoDirectory(argv[i]))
441 + for (; argn < argc; argn++) {
442 + if (!DoDirectory(argv[argn], encodings, count))
444 fprintf (stderr, "%s: failed to create directory in %s\n",
445 - progName, argv[i]);
446 + progName, argv[argn]);
450 --- XFree86-3.3.5/xc/programs/mkfontdir/mkfontdir.man.xfsftfontdir Sat Dec 21 23:11:23 1996
451 +++ XFree86-3.3.5/xc/programs/mkfontdir/mkfontdir.man Wed Aug 18 17:23:04 1999
453 .\" from the X Consortium.
454 .TH MKFONTDIR 1 "Release 6.3" "X Version 11"
456 -mkfontdir, fonts.dir, fonts.scale, fonts.alias \- create an index of X font files in a directory
457 +mkfontdir, fonts.dir, fonts.scale, fonts.alias, encodings.dir \- create an index of X font files in a directory
460 -[\fIdirectory-name\fP .\|.\|. ]
465 +.IR encoding-directory-name ]
468 +.RI [ directory-name
471 -For each directory argument, \fImkfontdir\fP reads all of the font files in the
472 +For each directory argument,
474 +reads all of the font files in the
475 directory searching for properties named "FONT", or (failing that) the name
476 of the file stripped of its suffix. These are converted to lower case and
477 used as font names, and,
479 written out to the file "fonts.dir" in the directory.
480 The X server and font server use "fonts.dir" to find font files.
482 -The kinds of font files read by \fImkfontdir\fP depend on configuration
483 +The kinds of font files read by
485 +depend on configuration
486 parameters, but typically include PCF (suffix ".pcf"), SNF (suffix ".snf")
487 and BDF (suffix ".bdf"). If a font exists in multiple formats,
490 Because scalable font files do not usually include the X font name, the
491 file "fonts.scale" can be used to name the scalable fonts in the
493 -The fonts listed in it are copied to fonts.dir by \fImkfontdir\fP.
494 +The fonts listed in it are copied to fonts.dir by
496 "fonts.scale" has the same format as the "fonts.dir" file.
497 .SH "FONT NAME ALIASES"
498 The file "fonts.alias", which can be put in any directory of the font-path, is
500 If the string "FILE_NAMES_ALIASES" stands alone on a line, each file-name
501 in the directory (stripped of its suffix) will be used as an alias for
506 +can be used to specify a directory with encoding files. Every such
507 +directory is scanned for encoding files, the list of which is then
508 +written to an "encodings.dir" file in every font directory. The
509 +"encodings.dir" file is used by the server to find encoding
512 +The "encodings.dir" file has the same format as "fonts.dir".
513 +It maps encoding names (strings of the form
514 +.BI CHARSET_REGISTRY \- CHARSET_ENCODING
515 +) to encoding file names.
517 +The following options are supported:
520 +Specify a directory containing encoding files. The
522 +option may be specified multiple times, and all the specified
523 +directories will be read. The order of the entries is significant, as
524 +encodings found in earlier directories override those in later ones;
525 +encoding files in the same directory are discriminated by preferring
526 +compressed versions.
529 +Specify a prefix that is prepended to the encoding file path names
530 +when the are written to the "encodings.dir" file. The prefix is
531 +prepended as-is. If a `/' is required between the prefix and the path
532 +names, it must be supplied explicitly as part of the prefix.
535 +Keep non-absolute encoding directories in their relative form when
536 +writing the "encodings.dir" file. The default is to convert relative
537 +encoding directories to absolute directories by prepending the current
538 +directory. The positioning of this options is significant, as this
539 +option only applies to subsequent
549 List of font name aliases.
550 Read by the X server and font server each
551 time the font path is set (see xset(1)).
554 +List of known encodings and the files they are stored in.
555 +Created by \fImkfontdir\fP. Read by the X server and font server each
556 +time a font with an unknown charset is opened.
558 X(1), Xserver(1), xfs(1), xset(1)