Mercurial > hg > aim92
comparison tools/x11fonts.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 List font names in font style. | |
3 | |
4 Usage: x11fonts [options] name_pattern | |
5 | |
6 To enter name_patterns with wildcards, use forward quote, | |
7 (eg. x11fonts 'vt*' finds all font names beginning with vt). | |
8 | |
9 Option -l = list font names | |
10 Default option = display font names (X11). | |
11 | |
12 The display format is: "i/n fontname" | |
13 where the displayed name is the i'th out of n names which match the | |
14 given name_pattern. | |
15 The name is displayed at the current cursor position. | |
16 | |
17 The centre mouse button gets the next fontname in the list. | |
18 The left button exits. | |
19 The right button clears the display screen. | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <math.h> | |
24 #include "x11coord.h" | |
25 | |
26 #define FONTNAME_SIZE 256 | |
27 | |
28 char printlist=0; | |
29 char printcount=0; | |
30 char printpath=0; | |
31 | |
32 char **list = (char **)0 ; | |
33 char **pattern = (char **)0 ; | |
34 int num_patterns ; | |
35 | |
36 int prompt_height ; | |
37 int Y0 = 0 ; | |
38 int Y = 0 ; | |
39 | |
40 char prompt[FONTNAME_SIZE] ; | |
41 | |
42 main(argc, argv) | |
43 int argc ; | |
44 char *argv[] ; | |
45 { | |
46 Window w; | |
47 int i, j, n; | |
48 | |
49 /* Search args list while args are single chars to prevent fontnames */ | |
50 /* which start with a `-' from being interpreted as args */ | |
51 | |
52 while ( --argc > 0 && **++argv == '-' && strlen( *argv ) < 3 ) | |
53 switch (*++*argv) { | |
54 case 'l': ++printlist; break; | |
55 case 'n': ++printcount; break; | |
56 case 'P': ++printpath; break; | |
57 case 'h': | |
58 case 'H': help(); | |
59 } | |
60 | |
61 if ( argc == 0 ) num_patterns = 1 ; | |
62 else num_patterns = argc ; | |
63 | |
64 pattern = (char **)malloc( num_patterns * sizeof(char *) ) ; | |
65 for ( i=0 ; i < num_patterns ; i++ ) | |
66 pattern[i] = (char *)malloc( FONTNAME_SIZE * sizeof(char) ) ; | |
67 | |
68 if ( argc == 0 ) | |
69 sprintf( pattern[0], "*\0" ); | |
70 else | |
71 for ( i=0 ; i < num_patterns ; i++ ) | |
72 sprintf( pattern[i], "%s\0", *argv++ ) ; | |
73 | |
74 | |
75 set_window_parameters(BOXXORG,BOXYORG, BOXWIDTH,BOXHEIGHT); | |
76 xopen(); | |
77 | |
78 if ( printpath ) { | |
79 list = XGetFontPath( theDisplay, &n ) ; | |
80 for ( j=0 ; j < n ; j++ ) | |
81 printf("%s\n", list[j]); | |
82 XFreeFontPath( list ) ; | |
83 exit( 0 ) ; | |
84 } | |
85 | |
86 if ( printcount || printlist ) { | |
87 for ( i=0 ; i < num_patterns ; i++ ) { | |
88 list = XListFonts(theDisplay, pattern[i], 1000, &n); | |
89 if (n>0) { | |
90 if ( printcount ) | |
91 printf("%d of %s\n", n, pattern[i]); | |
92 else if ( printlist ) | |
93 for ( j=0 ; j < n ; j++ ) | |
94 printf("%3d %s\n", j+1, list[j]); | |
95 } | |
96 else | |
97 fprintf(stderr, "no font names found to match pattern = %s\n", pattern[i] ) ; | |
98 | |
99 XFreeFontNames(list); | |
100 } | |
101 exit( 0 ) ; | |
102 } | |
103 | |
104 if ( setFont( theFontString ) == NULL ) { | |
105 fprintf( stderr,"x11fonts: no prompts as can't load default font \"%s\"\n", theFontString ) ; | |
106 prompt_height = 0 ; | |
107 } | |
108 else | |
109 prompt_height = line(1) ; | |
110 | |
111 w = xcreate("fonts", ButtonPressMask | ExposureMask); | |
112 xevent_monitor(w); | |
113 | |
114 if ( list != (char **)0 ) XFreeFontNames(list); | |
115 XCloseDisplay( theDisplay ) ; | |
116 } | |
117 | |
118 | |
119 xevent_monitor(w) | |
120 Window w; | |
121 { | |
122 XEvent event; | |
123 int n, i = 0, j = 0 ; | |
124 | |
125 for ( ; ; ) { | |
126 XNextEvent(theDisplay,&event); switch (event.type) { | |
127 case ButtonPress: | |
128 switch(event.xbutton.button) { | |
129 case Button1: /* Left */ | |
130 Y = Y0 ; | |
131 if ( j < n ) { | |
132 XClearArea( theDisplay, w, 0, Y+2*prompt_height, BOXWIDTH, BOXHEIGHT-Y, 0 ) ; | |
133 print_alphabet(w, list, j++, n); | |
134 } | |
135 break ; | |
136 case Button2: /* Middle */ | |
137 Y0 = Y ; | |
138 if (j<n) print_alphabet(w, list, j++, n); | |
139 break; | |
140 case Button3: /* Right */ | |
141 if ( ++i >= num_patterns ) return ; | |
142 j = 0 ; | |
143 if ( list != (char **)0 ) XFreeFontNames(list); | |
144 list = XListFonts(theDisplay, pattern[i], 1000, &n); | |
145 if ( prompt_height ) { | |
146 setFont( theFontString ) ; | |
147 XClearArea( theDisplay, w, 0, 0, BOXWIDTH, 2*prompt_height, 0 ) ; | |
148 if ( n > 0 ) { | |
149 sprintf( prompt, "pattern = %s", pattern[i]); | |
150 topline(w,prompt); | |
151 } | |
152 else { | |
153 sprintf( prompt, "no font names found to match pattern = %s", pattern[i] ) ; | |
154 topline(w,prompt); | |
155 } | |
156 } | |
157 break; | |
158 default: | |
159 fprintf(stderr,"button %d not used\n", event.xbutton.button); | |
160 } | |
161 break; | |
162 case Expose: | |
163 if ( event.xexpose.count == 0 ) { | |
164 list = XListFonts(theDisplay, pattern[i], 1000, &n); | |
165 if ( prompt_height ) { | |
166 setFont( theFontString ) ; | |
167 if (n>0) { | |
168 sprintf( prompt, "pattern = %s", pattern[i]); | |
169 topline(w,prompt); | |
170 } | |
171 else { | |
172 sprintf( prompt, "no font names found to match pattern = %s", pattern[i] ) ; | |
173 topline(w,prompt); | |
174 } | |
175 } | |
176 if ( n > 0 ) { | |
177 Y = Y0 ; | |
178 print_alphabet(w, list, j++, n); | |
179 } | |
180 } | |
181 break; | |
182 default: | |
183 fprintf(stderr,"event type %d not found\n", event.type); | |
184 } | |
185 } | |
186 } | |
187 | |
188 | |
189 | |
190 char alphabet[] = "abcdefghijklmnopqrstuvwxyz\ | |
191 ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | |
192 | |
193 print_alphabet(w, fontlist, m, n) | |
194 Window w; | |
195 char **fontlist; | |
196 int m,n; | |
197 { | |
198 int i,j,k, x,y; | |
199 char str[128]; | |
200 | |
201 if ( prompt_height ) { | |
202 | |
203 setFont( theFontString ) ; | |
204 sprintf(str, "[%d/%d] %s", m+1, n, fontlist[m]); | |
205 | |
206 Y += line(3) ; | |
207 XDrawString(theDisplay,w,theGC,0,Y,str,strlen(str)) ; | |
208 | |
209 y = line(2); | |
210 } | |
211 else y = 0 ; | |
212 | |
213 setFont( fontlist[m] ); | |
214 if (y < line(2)) Y += line(2); /* set to start of larger font */ | |
215 else Y += y ; | |
216 | |
217 y = Y ; | |
218 for (i=0, k=0 ; i<nlines() && k<62; i++) { | |
219 x = leftmargin(); | |
220 for (j=0 ; j<(ncols())-1 && k<62; j++) { | |
221 XDrawString(theDisplay, w, theGC, x,y, &alphabet[k++], 1); | |
222 x += colwidth(); | |
223 } | |
224 y += lineheight(); | |
225 } | |
226 Y = y ; | |
227 | |
228 | |
229 if ( Y > BOXHEIGHT ) { | |
230 Y = Y0 = 0 ; | |
231 XClearArea( theDisplay, w, 0, 2*prompt_height, BOXWIDTH, BOXHEIGHT-prompt_height, 0 ) ; | |
232 print_alphabet(w, fontlist, m, n) ; | |
233 } | |
234 } | |
235 | |
236 | |
237 help() | |
238 { | |
239 fprintf(stderr,"Usage: x11fonts [options] [name_patterns]\n"); | |
240 fprintf(stderr,"(name_patterns containing wild-cards must be quoted. Default = \"*\") \n"); | |
241 fprintf(stderr,"options: \n"); | |
242 fprintf(stderr," -n = print count of matching font names found in search path\n"); | |
243 fprintf(stderr," -l = list matching font names \n"); | |
244 fprintf(stderr," -P = print the current font search path\n"); | |
245 exit(1); | |
246 } |