tomwalters@0: /* tomwalters@0: List font names in font style. tomwalters@0: tomwalters@0: Usage: x11fonts [options] name_pattern tomwalters@0: tomwalters@0: To enter name_patterns with wildcards, use forward quote, tomwalters@0: (eg. x11fonts 'vt*' finds all font names beginning with vt). tomwalters@0: tomwalters@0: Option -l = list font names tomwalters@0: Default option = display font names (X11). tomwalters@0: tomwalters@0: The display format is: "i/n fontname" tomwalters@0: where the displayed name is the i'th out of n names which match the tomwalters@0: given name_pattern. tomwalters@0: The name is displayed at the current cursor position. tomwalters@0: tomwalters@0: The centre mouse button gets the next fontname in the list. tomwalters@0: The left button exits. tomwalters@0: The right button clears the display screen. tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "x11coord.h" tomwalters@0: tomwalters@0: #define FONTNAME_SIZE 256 tomwalters@0: tomwalters@0: char printlist=0; tomwalters@0: char printcount=0; tomwalters@0: char printpath=0; tomwalters@0: tomwalters@0: char **list = (char **)0 ; tomwalters@0: char **pattern = (char **)0 ; tomwalters@0: int num_patterns ; tomwalters@0: tomwalters@0: int prompt_height ; tomwalters@0: int Y0 = 0 ; tomwalters@0: int Y = 0 ; tomwalters@0: tomwalters@0: char prompt[FONTNAME_SIZE] ; tomwalters@0: tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: Window w; tomwalters@0: int i, j, n; tomwalters@0: tomwalters@0: /* Search args list while args are single chars to prevent fontnames */ tomwalters@0: /* which start with a `-' from being interpreted as args */ tomwalters@0: tomwalters@0: while ( --argc > 0 && **++argv == '-' && strlen( *argv ) < 3 ) tomwalters@0: switch (*++*argv) { tomwalters@0: case 'l': ++printlist; break; tomwalters@0: case 'n': ++printcount; break; tomwalters@0: case 'P': ++printpath; break; tomwalters@0: case 'h': tomwalters@0: case 'H': help(); tomwalters@0: } tomwalters@0: tomwalters@0: if ( argc == 0 ) num_patterns = 1 ; tomwalters@0: else num_patterns = argc ; tomwalters@0: tomwalters@0: pattern = (char **)malloc( num_patterns * sizeof(char *) ) ; tomwalters@0: for ( i=0 ; i < num_patterns ; i++ ) tomwalters@0: pattern[i] = (char *)malloc( FONTNAME_SIZE * sizeof(char) ) ; tomwalters@0: tomwalters@0: if ( argc == 0 ) tomwalters@0: sprintf( pattern[0], "*\0" ); tomwalters@0: else tomwalters@0: for ( i=0 ; i < num_patterns ; i++ ) tomwalters@0: sprintf( pattern[i], "%s\0", *argv++ ) ; tomwalters@0: tomwalters@0: tomwalters@0: set_window_parameters(BOXXORG,BOXYORG, BOXWIDTH,BOXHEIGHT); tomwalters@0: xopen(); tomwalters@0: tomwalters@0: if ( printpath ) { tomwalters@0: list = XGetFontPath( theDisplay, &n ) ; tomwalters@0: for ( j=0 ; j < n ; j++ ) tomwalters@0: printf("%s\n", list[j]); tomwalters@0: XFreeFontPath( list ) ; tomwalters@0: exit( 0 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( printcount || printlist ) { tomwalters@0: for ( i=0 ; i < num_patterns ; i++ ) { tomwalters@0: list = XListFonts(theDisplay, pattern[i], 1000, &n); tomwalters@0: if (n>0) { tomwalters@0: if ( printcount ) tomwalters@0: printf("%d of %s\n", n, pattern[i]); tomwalters@0: else if ( printlist ) tomwalters@0: for ( j=0 ; j < n ; j++ ) tomwalters@0: printf("%3d %s\n", j+1, list[j]); tomwalters@0: } tomwalters@0: else tomwalters@0: fprintf(stderr, "no font names found to match pattern = %s\n", pattern[i] ) ; tomwalters@0: tomwalters@0: XFreeFontNames(list); tomwalters@0: } tomwalters@0: exit( 0 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( setFont( theFontString ) == NULL ) { tomwalters@0: fprintf( stderr,"x11fonts: no prompts as can't load default font \"%s\"\n", theFontString ) ; tomwalters@0: prompt_height = 0 ; tomwalters@0: } tomwalters@0: else tomwalters@0: prompt_height = line(1) ; tomwalters@0: tomwalters@0: w = xcreate("fonts", ButtonPressMask | ExposureMask); tomwalters@0: xevent_monitor(w); tomwalters@0: tomwalters@0: if ( list != (char **)0 ) XFreeFontNames(list); tomwalters@0: XCloseDisplay( theDisplay ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: xevent_monitor(w) tomwalters@0: Window w; tomwalters@0: { tomwalters@0: XEvent event; tomwalters@0: int n, i = 0, j = 0 ; tomwalters@0: tomwalters@0: for ( ; ; ) { tomwalters@0: XNextEvent(theDisplay,&event); switch (event.type) { tomwalters@0: case ButtonPress: tomwalters@0: switch(event.xbutton.button) { tomwalters@0: case Button1: /* Left */ tomwalters@0: Y = Y0 ; tomwalters@0: if ( j < n ) { tomwalters@0: XClearArea( theDisplay, w, 0, Y+2*prompt_height, BOXWIDTH, BOXHEIGHT-Y, 0 ) ; tomwalters@0: print_alphabet(w, list, j++, n); tomwalters@0: } tomwalters@0: break ; tomwalters@0: case Button2: /* Middle */ tomwalters@0: Y0 = Y ; tomwalters@0: if (j= num_patterns ) return ; tomwalters@0: j = 0 ; tomwalters@0: if ( list != (char **)0 ) XFreeFontNames(list); tomwalters@0: list = XListFonts(theDisplay, pattern[i], 1000, &n); tomwalters@0: if ( prompt_height ) { tomwalters@0: setFont( theFontString ) ; tomwalters@0: XClearArea( theDisplay, w, 0, 0, BOXWIDTH, 2*prompt_height, 0 ) ; tomwalters@0: if ( n > 0 ) { tomwalters@0: sprintf( prompt, "pattern = %s", pattern[i]); tomwalters@0: topline(w,prompt); tomwalters@0: } tomwalters@0: else { tomwalters@0: sprintf( prompt, "no font names found to match pattern = %s", pattern[i] ) ; tomwalters@0: topline(w,prompt); tomwalters@0: } tomwalters@0: } tomwalters@0: break; tomwalters@0: default: tomwalters@0: fprintf(stderr,"button %d not used\n", event.xbutton.button); tomwalters@0: } tomwalters@0: break; tomwalters@0: case Expose: tomwalters@0: if ( event.xexpose.count == 0 ) { tomwalters@0: list = XListFonts(theDisplay, pattern[i], 1000, &n); tomwalters@0: if ( prompt_height ) { tomwalters@0: setFont( theFontString ) ; tomwalters@0: if (n>0) { tomwalters@0: sprintf( prompt, "pattern = %s", pattern[i]); tomwalters@0: topline(w,prompt); tomwalters@0: } tomwalters@0: else { tomwalters@0: sprintf( prompt, "no font names found to match pattern = %s", pattern[i] ) ; tomwalters@0: topline(w,prompt); tomwalters@0: } tomwalters@0: } tomwalters@0: if ( n > 0 ) { tomwalters@0: Y = Y0 ; tomwalters@0: print_alphabet(w, list, j++, n); tomwalters@0: } tomwalters@0: } tomwalters@0: break; tomwalters@0: default: tomwalters@0: fprintf(stderr,"event type %d not found\n", event.type); tomwalters@0: } tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: char alphabet[] = "abcdefghijklmnopqrstuvwxyz\ tomwalters@0: ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; tomwalters@0: tomwalters@0: print_alphabet(w, fontlist, m, n) tomwalters@0: Window w; tomwalters@0: char **fontlist; tomwalters@0: int m,n; tomwalters@0: { tomwalters@0: int i,j,k, x,y; tomwalters@0: char str[128]; tomwalters@0: tomwalters@0: if ( prompt_height ) { tomwalters@0: tomwalters@0: setFont( theFontString ) ; tomwalters@0: sprintf(str, "[%d/%d] %s", m+1, n, fontlist[m]); tomwalters@0: tomwalters@0: Y += line(3) ; tomwalters@0: XDrawString(theDisplay,w,theGC,0,Y,str,strlen(str)) ; tomwalters@0: tomwalters@0: y = line(2); tomwalters@0: } tomwalters@0: else y = 0 ; tomwalters@0: tomwalters@0: setFont( fontlist[m] ); tomwalters@0: if (y < line(2)) Y += line(2); /* set to start of larger font */ tomwalters@0: else Y += y ; tomwalters@0: tomwalters@0: y = Y ; tomwalters@0: for (i=0, k=0 ; i BOXHEIGHT ) { tomwalters@0: Y = Y0 = 0 ; tomwalters@0: XClearArea( theDisplay, w, 0, 2*prompt_height, BOXWIDTH, BOXHEIGHT-prompt_height, 0 ) ; tomwalters@0: print_alphabet(w, fontlist, m, n) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: help() tomwalters@0: { tomwalters@0: fprintf(stderr,"Usage: x11fonts [options] [name_patterns]\n"); tomwalters@0: fprintf(stderr,"(name_patterns containing wild-cards must be quoted. Default = \"*\") \n"); tomwalters@0: fprintf(stderr,"options: \n"); tomwalters@0: fprintf(stderr," -n = print count of matching font names found in search path\n"); tomwalters@0: fprintf(stderr," -l = list matching font names \n"); tomwalters@0: fprintf(stderr," -P = print the current font search path\n"); tomwalters@0: exit(1); tomwalters@0: }