]> git.pld-linux.org Git - packages/XFree86.git/blame - XFree86-xfsftfontdir.patch
- outdated
[packages/XFree86.git] / XFree86-xfsftfontdir.patch
CommitLineData
54286d6c 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
3@@ -111,6 +111,7 @@
4 #include <X11/X.h>
5 #include <X11/Xproto.h>
6 #include "fntfilst.h"
7+#include "fontenc.h"
8
9 #include <errno.h>
10 #ifdef X_NOT_STDC_ENV
11@@ -122,16 +123,67 @@
12 #include <X11/keysymdef.h>
13
14 char *progName;
15+char *prefix = "";
16+Bool relative = FALSE;
17+
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"};
22+#else
23+#define NUMENCODINGEXTENSIONS 1
24+char *encodingExtensions[]={".Z"};
25+#endif
26+
27+typedef struct _nameBucket {
28+ struct _nameBucket *next;
29+ char *name;
30+ FontRendererPtr renderer;
31+} NameBucketRec, *NameBucketPtr;
32+
33+typedef struct _encodingBucket {
34+ struct _encodingBucket *next;
35+ char *name;
36+ char *fileName;
37+ int priority;
38+} EncodingBucketRec, *EncodingBucketPtr;
39+
40+#define HASH_SIZE 1024
41+/* should be a divisor of HASH_SIZE */
42+#define ENCODING_HASH_SIZE 256
43+
44+
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 );
63
64 static Bool
65-WriteFontTable(dirName, table)
66+WriteFontTable(dirName, table, encodings, count)
67 char *dirName;
68 FontTablePtr table;
69+ EncodingBucketPtr *encodings;
70+ int count;
71 {
72 int i;
73 FILE *file;
74 char full_name[PATH_MAX];
75 FontEntryPtr entry;
76+ EncodingBucketPtr encoding;
77
78 sprintf (full_name, "%s/%s", dirName, FontDirFile);
79
80@@ -155,6 +207,30 @@
81 fprintf (file, "%s %s\n", entry->u.bitmap.fileName, entry->name.name);
82 }
83 fclose (file);
84+
85+
86+ /* Write out encodings directory */
87+
88+ sprintf (full_name, "%s/%s", dirName, "encodings.dir");
89+ if (unlink(full_name) < 0 && errno != ENOENT)
90+ {
91+ fprintf(stderr, "%s: warning: cannot unlink %s\n", progName, full_name);
92+ return TRUE; /* non fatal error */
93+ }
94+ if(!count) return TRUE;
95+ file = fopen (full_name, "w");
96+ if (!file)
97+ {
98+ fprintf (stderr, "%s: can't create directory %s\n", progName, full_name);
99+ return TRUE;
100+ }
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);
106+ fclose(file);
107+
108 return TRUE;
109 }
110
111@@ -215,6 +291,7 @@
112 return 0;
113 }
114
115+int
116 AddEntry (table, fontName, fileName)
117 FontTablePtr table;
118 char *fontName, *fileName;
119@@ -249,7 +326,7 @@
120
121 CopyISOLatin1Lowered (font_name, font_name, strlen(font_name));
122
123- if (existing = FontNameExists (table, font_name))
124+ if ((existing = FontNameExists (table, font_name)) != 0)
125 {
126 fprintf (stderr, "%s: Duplicate font names %s\n", progName, font_name);
127 fprintf (stderr, "\t%s %s\n", existing, fileName);
128@@ -259,6 +336,7 @@
129 }
130
131 static
132+void
133 Estrip(ext,name)
134 char *ext;
135 char *name;
136@@ -268,16 +346,8 @@
137
138 /***====================================================================***/
139
140-typedef struct _nameBucket {
141- struct _nameBucket *next;
142- char *name;
143- FontRendererPtr renderer;
144-} NameBucketRec, *NameBucketPtr;
145-
146 #define New(type,count) ((type *) malloc (count * sizeof (type)))
147
148-#define HASH_SIZE 1024
149-
150 char *
151 MakeName(name)
152 char *name;
153@@ -297,7 +367,7 @@
154 char c;
155
156 i = 0;
157- while (c = *name++)
158+ while ((c = *name++) != 0)
159 i = (i << 1) ^ c;
160 return i & (HASH_SIZE - 1);
161 }
162@@ -319,7 +389,6 @@
163 int hash;
164 char *extension;
165 NameBucketPtr *hashTable, bucket, *prev, next;
166- Bool status;
167
168 #ifdef WIN32
169 if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
170@@ -435,8 +504,141 @@
171 }
172
173 static Bool
174-DoDirectory(dirName)
175+CompareEncodingFiles(char *name1, char *name2)
176+{
177+ int len, len1, len2, p1, p2, i;
178+ char *extension;
179+
180+ len1=strlen(name1);
181+ len2=strlen(name2);
182+ p1=p2=-1;
183+
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))
189+ p1=i;
190+ if(p2<0 && len2>=len && !strcmp(name2+len2-len, extension))
191+ p2=i;
192+ }
193+
194+ if(p1<0)
195+ return FALSE;
196+ else if(p2<0)
197+ return TRUE;
198+ else
199+ return(p1<p2);
200+}
201+
202+static Bool
203+InsertEncoding(EncodingBucketPtr *encodings,
204+ char *name, char *fileName, int priority)
205+{
206+ int bucket;
207+ EncodingBucketPtr encoding;
208+
209+ bucket=Hash(name)%ENCODING_HASH_SIZE;
210+
211+ for(encoding=encodings[bucket]; encoding; encoding=encoding->next) {
212+ if(!strcmp(name, encoding->name)) {
213+ if(encoding->priority<priority)
214+ return TRUE;
215+ else if(encoding->priority>priority)
216+ break;
217+ else if(CompareEncodingFiles(fileName, encoding->fileName))
218+ break;
219+ else
220+ return TRUE;
221+
222+ }
223+ }
224+
225+ if(!encoding) {
226+ /* Need to insert new bucket */
227+ if((encoding=New(EncodingBucketRec, 1))==NULL)
228+ return FALSE;
229+ encoding->next=encodings[bucket];
230+ encodings[bucket]=encoding;
231+ }
232+
233+ /* Now encoding points to a bucket to fill in */
234+ encoding->name=name;
235+ encoding->fileName=fileName;
236+ encoding->priority=priority;
237+ return TRUE;
238+}
239+
240+Bool
241+LoadEncodings(EncodingBucketPtr *encodings, char *dirName, int priority)
242+{
243+ EncodingBucketPtr new;
244+ char *filename;
245+ char **names;
246+ char **name;
247+ char fullname[MAXFONTFILENAMELEN];
248+ int len;
249+#ifdef WIN32
250+ HANDLE dirh;
251+ WIN32_FIND_DATA file;
252+#else
253+ DIR *dirp;
254+ struct dirent *file;
255+#endif
256+
257+ if (strcmp(dirName, ".") == 0) {
258+ len=0;
259+ } else {
260+ len=strlen(dirName);
261+ strcpy(fullname, dirName);
262+ if(fullname[len-1]!='/')
263+ fullname[len++]='/';
264+ }
265+
266+
267+#ifdef WIN32
268+ if ((dirh = FindFirstFile("*.*", &file)) == INVALID_HANDLE_VALUE)
269+ return FALSE;
270+#else
271+ if ((dirp = opendir (dirName)) == NULL)
272+ return FALSE;
273+#endif
274+#ifdef WIN32
275+ do {
276+#else
277+ while ((file = readdir (dirp)) != NULL) {
278+#endif
279+ if(len+strlen(FileName(file))>=MAXFONTFILENAMELEN) {
280+ fprintf(stderr, "%s: warning: filename `%s/%s' too long, ignored\n",
281+ progName, dirName, FileName(file));
282+ continue;
283+ }
284+ strcpy(fullname+len, FileName(file));
285+ names=identifyEncodingFile(fullname);
286+ if(names) {
287+ if((filename=New(char, strlen(fullname)+1))==NULL) {
288+ fprintf(stderr, "%s: warning: out of memory.\n", progName);
289+ break;
290+ }
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 */
296+ free(names);
297+ }
298+ }
299+#ifdef WIN32
300+ while (FindNextFile(dirh, &file));
301+#endif
302+ return TRUE;
303+}
304+
305+static Bool
306+DoDirectory(dirName, encodings, count)
307 char *dirName;
308+ EncodingBucketPtr *encodings;
309+ int count;
310 {
311 FontTableRec table;
312 Bool status;
313@@ -455,42 +657,113 @@
314 }
315 status = TRUE;
316 if (table.used >= 0)
317- status = WriteFontTable (dirName, &table);
318+ status = WriteFontTable (dirName, &table, encodings, count);
319 FontFileFreeTable (&table);
320 return status;
321 }
322
323-GetDefaultPointSize ()
324+int
325+GetDefaultPointSize (void)
326 {
327 return 120;
328 }
329
330-FontResolutionPtr GetClientResolutions ()
331+FontResolutionPtr GetClientResolutions (num)
332+ int *num;
333 {
334 return 0;
335 }
336
337-RegisterFPEFunctions ()
338+void
339+RegisterFPEFunctions (void)
340 {
341 }
342
343-ErrorF ()
344+void
345+ErrorF (void)
346 {
347 }
348
349 /***====================================================================***/
350
351+int
352 main (argc, argv)
353 int argc;
354 char **argv;
355 {
356- int i;
357+ int argn, i, count;
358+ char *dirname, fulldirname[MAXFONTFILENAMELEN];
359+ EncodingBucketPtr *encodings, encoding;
360+ char **name;
361
362 BitmapRegisterFontFileFunctions ();
363 progName = argv[0];
364- if (argc == 1)
365+ if((encodings=New(EncodingBucketPtr, ENCODING_HASH_SIZE))==NULL) {
366+ fprintf(stderr, "%s: out of memory\n", progName);
367+ exit(2);
368+ }
369+ for(i=0; i<ENCODING_HASH_SIZE; i++)
370+ encodings[i]=NULL;
371+
372+ for(argn=1; argn<argc; argn++) {
373+ if(argv[argn][0]=='\0' || argv[argn][0]!='-')
374+ break;
375+ if(argv[argn][1]=='-') {
376+ argn++;
377+ break;
378+ } else if(argv[argn][1]=='e') {
379+ if(argv[argn][2]=='\0') {
380+ argn++;
381+ if (argn < argc)
382+ dirname=argv[argn];
383+ else {
384+ fprintf(stderr, "%s: -e requires an argument\n", progName);
385+ break;
386+ }
387+ } else
388+ dirname=argv[argn]+2;
389+ if(dirname[0]=='/' || relative)
390+ LoadEncodings(encodings, dirname, argn);
391+ else {
392+ if(getcwd(fulldirname, MAXFONTFILENAMELEN)==NULL) {
393+ fprintf(stderr, "%s: failed to get cwd\n", progName);
394+ break;
395+ }
396+ i=strlen(fulldirname);
397+ if(i+1+strlen(dirname)>=MAXFONTFILENAMELEN-1) {
398+ fprintf(stderr, "%s: directory name `%s' too long\n", progName,
399+ dirname);
400+ break;
401+ }
402+ fulldirname[i++]='/';
403+ strcpy(fulldirname+i, dirname);
404+ LoadEncodings(encodings, fulldirname, argn);
405+ }
406+ } else if(argv[argn][1]=='p') {
407+ if(argv[argn][2]=='\0') {
408+ argn++;
409+ prefix=argv[argn];
410+ } else
411+ prefix=argv[argn]+2;
412+ } else if(argv[argn][1]=='r') {
413+ if(argv[argn][2]=='\0')
414+ relative=TRUE;
415+ else {
416+ fprintf(stderr, "%s: unknown option `%s'\n", progName, argv[argn]);
417+ continue;
418+ }
419+ } else
420+ fprintf(stderr, "%s: unknown option `%s'\n", progName, argv[argn]);
421+ }
422+
423+ count=0;
424+ for(i=0; i<ENCODING_HASH_SIZE; i++)
425+ for(encoding=encodings[i]; encoding; encoding=encoding->next)
426+ count++;
427+
428+ if (argc == argc)
429 {
430- if (!DoDirectory("."))
431+ if (!DoDirectory(".", encodings, count))
432 {
433 fprintf (stderr, "%s: failed to create directory in %s\n",
434 progName, ".");
435@@ -498,11 +771,11 @@
436 }
437 }
438 else
439- for (i = 1; i < argc; i++) {
440- if (!DoDirectory(argv[i]))
441+ for (; argn < argc; argn++) {
442+ if (!DoDirectory(argv[argn], encodings, count))
443 {
444 fprintf (stderr, "%s: failed to create directory in %s\n",
445- progName, argv[i]);
446+ progName, argv[argn]);
447 exit (1);
448 }
449 }
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
452@@ -26,12 +26,22 @@
453 .\" from the X Consortium.
454 .TH MKFONTDIR 1 "Release 6.3" "X Version 11"
455 .SH NAME
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
458 .SH SYNOPSIS
459 .B "mkfontdir"
460-[\fIdirectory-name\fP .\|.\|. ]
461+.RB [ \-r ]
462+.RB [ \-p
463+.IR prefix ]
464+.RB [ \-e
465+.IR encoding-directory-name ]
466+\|.\|.\|.
467+.RB [ \-\- ]
468+.RI [ directory-name
469+\|.\|.\|. ]
470 .SH DESCRIPTION
471-For each directory argument, \fImkfontdir\fP reads all of the font files in the
472+For each directory argument,
473+.Imkfontdir
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,
478@@ -39,7 +49,9 @@
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.
481 .PP
482-The kinds of font files read by \fImkfontdir\fP depend on configuration
483+The kinds of font files read by
484+.Imkfontdir
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,
488 .I mkfontdir
489@@ -53,7 +65,8 @@
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
492 directory.
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
495+.Imkfontdir .
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
499@@ -83,6 +96,48 @@
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
502 that font.
503+.SH ENCODING FILES
504+The option
505+.B -e
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
510+information.
511+.PP
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.
516+.SH OPTIONS
517+The following options are supported:
518+.TP
519+.B \-e
520+Specify a directory containing encoding files. The
521+.B \-e
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.
527+.TP
528+.B \-p
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.
533+.TP
534+.B \-r
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
540+.B \-e
541+options.
542+.TP
543+.B \-\-
544+End options.
545 .SH FILES
546 .TP 15
547 .B fonts.dir
548@@ -98,5 +153,10 @@
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)).
552+.TP 15
553+.B encodings.dir
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.
557 .SH "SEE ALSO"
558 X(1), Xserver(1), xfs(1), xset(1)
This page took 0.150516 seconds and 4 git commands to generate.