Mercurial > emacs
comparison src/xfaces.c @ 49859:c6bacc76cfb6
* xterm.c (x_list_fonts): If maxnames is less than 0, get all font
names.
* xfaces.c (x_face_list_fonts): Allocate struct font_name here.
(sorted_font_list): Moved allocation of struct font_name to
x_face_list_fonts.
(Fx_font_family_list): Set font-list-limit to -1 to get all font names.
(Fx_list_fonts): Set maxnames to -1 to get all font names.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Tue, 18 Feb 2003 21:30:08 +0000 |
parents | 23a1cea22d13 |
children | 6d5c33f4dd05 |
comparison
equal
deleted
inserted
replaced
49858:f86aab6b2827 | 49859:c6bacc76cfb6 |
---|---|
472 static int may_use_scalable_font_p P_ ((const char *)); | 472 static int may_use_scalable_font_p P_ ((const char *)); |
473 static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); | 473 static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); |
474 static int better_font_p P_ ((int *, struct font_name *, struct font_name *, | 474 static int better_font_p P_ ((int *, struct font_name *, struct font_name *, |
475 int, int)); | 475 int, int)); |
476 static int x_face_list_fonts P_ ((struct frame *, char *, | 476 static int x_face_list_fonts P_ ((struct frame *, char *, |
477 struct font_name *, int, int)); | 477 struct font_name **, int, int)); |
478 static int font_scalable_p P_ ((struct font_name *)); | 478 static int font_scalable_p P_ ((struct font_name *)); |
479 static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); | 479 static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); |
480 static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); | 480 static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); |
481 static unsigned char *xstrlwr P_ ((unsigned char *)); | 481 static unsigned char *xstrlwr P_ ((unsigned char *)); |
482 static void signal_error P_ ((char *, Lisp_Object)); | 482 static void signal_error P_ ((char *, Lisp_Object)); |
2433 For all fonts found, set FONTS[i].name to the name of the font, | 2433 For all fonts found, set FONTS[i].name to the name of the font, |
2434 allocated via xmalloc, and split font names into fields. Ignore | 2434 allocated via xmalloc, and split font names into fields. Ignore |
2435 fonts that we can't parse. Value is the number of fonts found. */ | 2435 fonts that we can't parse. Value is the number of fonts found. */ |
2436 | 2436 |
2437 static int | 2437 static int |
2438 x_face_list_fonts (f, pattern, fonts, nfonts, try_alternatives_p) | 2438 x_face_list_fonts (f, pattern, pfonts, nfonts, try_alternatives_p) |
2439 struct frame *f; | 2439 struct frame *f; |
2440 char *pattern; | 2440 char *pattern; |
2441 struct font_name *fonts; | 2441 struct font_name **pfonts; |
2442 int nfonts, try_alternatives_p; | 2442 int nfonts, try_alternatives_p; |
2443 { | 2443 { |
2444 int n, nignored; | 2444 int n, nignored; |
2445 | 2445 |
2446 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be | 2446 /* NTEMACS_TODO : currently this uses w32_list_fonts, but it may be |
2447 better to do it the other way around. */ | 2447 better to do it the other way around. */ |
2448 Lisp_Object lfonts; | 2448 Lisp_Object lfonts; |
2449 Lisp_Object lpattern, tem; | 2449 Lisp_Object lpattern, tem; |
2450 | 2450 struct font_name *fonts = 0; |
2451 int num_fonts = nfonts; | |
2452 | |
2453 *pfonts = 0; | |
2451 lpattern = build_string (pattern); | 2454 lpattern = build_string (pattern); |
2452 | 2455 |
2453 /* Get the list of fonts matching PATTERN. */ | 2456 /* Get the list of fonts matching PATTERN. */ |
2454 #ifdef WINDOWSNT | 2457 #ifdef WINDOWSNT |
2455 BLOCK_INPUT; | 2458 BLOCK_INPUT; |
2457 UNBLOCK_INPUT; | 2460 UNBLOCK_INPUT; |
2458 #else | 2461 #else |
2459 lfonts = x_list_fonts (f, lpattern, -1, nfonts); | 2462 lfonts = x_list_fonts (f, lpattern, -1, nfonts); |
2460 #endif | 2463 #endif |
2461 | 2464 |
2465 if (nfonts < 0 && CONSP (lfonts)) | |
2466 num_fonts = Flength (lfonts); | |
2467 | |
2462 /* Make a copy of the font names we got from X, and | 2468 /* Make a copy of the font names we got from X, and |
2463 split them into fields. */ | 2469 split them into fields. */ |
2464 n = nignored = 0; | 2470 n = nignored = 0; |
2465 for (tem = lfonts; CONSP (tem) && n < nfonts; tem = XCDR (tem)) | 2471 for (tem = lfonts; CONSP (tem) && n < num_fonts; tem = XCDR (tem)) |
2466 { | 2472 { |
2467 Lisp_Object elt, tail; | 2473 Lisp_Object elt, tail; |
2468 const char *name = SDATA (XCAR (tem)); | 2474 const char *name = SDATA (XCAR (tem)); |
2469 | 2475 |
2470 /* Ignore fonts matching a pattern from face-ignored-fonts. */ | 2476 /* Ignore fonts matching a pattern from face-ignored-fonts. */ |
2479 { | 2485 { |
2480 ++nignored; | 2486 ++nignored; |
2481 continue; | 2487 continue; |
2482 } | 2488 } |
2483 | 2489 |
2490 if (! fonts) | |
2491 { | |
2492 *pfonts = (struct font_name *) xmalloc (num_fonts * sizeof **pfonts); | |
2493 fonts = *pfonts; | |
2494 } | |
2495 | |
2484 /* Make a copy of the font name. */ | 2496 /* Make a copy of the font name. */ |
2485 fonts[n].name = xstrdup (name); | 2497 fonts[n].name = xstrdup (name); |
2486 | 2498 |
2487 if (split_font_name (f, fonts + n, 1)) | 2499 if (split_font_name (f, fonts + n, 1)) |
2488 { | 2500 { |
2502 /* If no fonts found, try patterns from Valternate_fontname_alist. */ | 2514 /* If no fonts found, try patterns from Valternate_fontname_alist. */ |
2503 if (n == 0 && try_alternatives_p) | 2515 if (n == 0 && try_alternatives_p) |
2504 { | 2516 { |
2505 Lisp_Object list = Valternate_fontname_alist; | 2517 Lisp_Object list = Valternate_fontname_alist; |
2506 | 2518 |
2519 if (fonts) xfree (fonts); | |
2520 | |
2507 while (CONSP (list)) | 2521 while (CONSP (list)) |
2508 { | 2522 { |
2509 Lisp_Object entry = XCAR (list); | 2523 Lisp_Object entry = XCAR (list); |
2510 if (CONSP (entry) | 2524 if (CONSP (entry) |
2511 && STRINGP (XCAR (entry)) | 2525 && STRINGP (XCAR (entry)) |
2525 STRINGP (name)) | 2539 STRINGP (name)) |
2526 /* Ignore patterns equal to PATTERN because we tried that | 2540 /* Ignore patterns equal to PATTERN because we tried that |
2527 already with no success. */ | 2541 already with no success. */ |
2528 && (strcmp (SDATA (name), pattern) == 0 | 2542 && (strcmp (SDATA (name), pattern) == 0 |
2529 || (n = x_face_list_fonts (f, SDATA (name), | 2543 || (n = x_face_list_fonts (f, SDATA (name), |
2530 fonts, nfonts, 0), | 2544 pfonts, nfonts, 0), |
2531 n == 0))) | 2545 n == 0))) |
2532 patterns = XCDR (patterns); | 2546 patterns = XCDR (patterns); |
2533 } | 2547 } |
2534 } | 2548 } |
2535 | 2549 |
2554 { | 2568 { |
2555 int nfonts; | 2569 int nfonts; |
2556 | 2570 |
2557 /* Get the list of fonts matching pattern. 100 should suffice. */ | 2571 /* Get the list of fonts matching pattern. 100 should suffice. */ |
2558 nfonts = DEFAULT_FONT_LIST_LIMIT; | 2572 nfonts = DEFAULT_FONT_LIST_LIMIT; |
2559 if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0) | 2573 if (INTEGERP (Vfont_list_limit)) |
2560 nfonts = XFASTINT (Vfont_list_limit); | 2574 nfonts = XINT (Vfont_list_limit); |
2561 | 2575 |
2562 *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts); | 2576 *fonts = NULL; |
2563 nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1); | 2577 nfonts = x_face_list_fonts (f, pattern, fonts, nfonts, 1); |
2564 | 2578 |
2565 /* Sort the resulting array and return it in *FONTS. If no | 2579 /* Sort the resulting array and return it in *FONTS. If no |
2566 fonts were found, make sure to set *FONTS to null. */ | 2580 fonts were found, make sure to set *FONTS to null. */ |
2567 if (nfonts) | 2581 if (nfonts) |
2568 sort_fonts (f, *fonts, nfonts, cmpfn); | 2582 sort_fonts (f, *fonts, nfonts, cmpfn); |
2569 else | 2583 else if (*fonts) |
2570 { | 2584 { |
2571 xfree (*fonts); | 2585 xfree (*fonts); |
2572 *fonts = NULL; | 2586 *fonts = NULL; |
2573 } | 2587 } |
2574 | 2588 |
2832 int nfonts, i; | 2846 int nfonts, i; |
2833 struct font_name *fonts; | 2847 struct font_name *fonts; |
2834 Lisp_Object result; | 2848 Lisp_Object result; |
2835 struct gcpro gcpro1; | 2849 struct gcpro gcpro1; |
2836 int count = SPECPDL_INDEX (); | 2850 int count = SPECPDL_INDEX (); |
2837 int limit; | 2851 |
2838 | 2852 /* Let's consider all fonts. */ |
2839 /* Let's consider all fonts. Increase the limit for matching | 2853 specbind (intern ("font-list-limit"), make_number (-1)); |
2840 fonts until we have them all. */ | 2854 nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts); |
2841 for (limit = 500;;) | |
2842 { | |
2843 specbind (intern ("font-list-limit"), make_number (limit)); | |
2844 nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts); | |
2845 | |
2846 if (nfonts == limit) | |
2847 { | |
2848 free_font_names (fonts, nfonts); | |
2849 limit *= 2; | |
2850 } | |
2851 else | |
2852 break; | |
2853 } | |
2854 | 2855 |
2855 result = Qnil; | 2856 result = Qnil; |
2856 GCPRO1 (result); | 2857 GCPRO1 (result); |
2857 for (i = nfonts - 1; i >= 0; --i) | 2858 for (i = nfonts - 1; i >= 0; --i) |
2858 result = Fcons (Fcons (build_string (fonts[i].fields[XLFD_FAMILY]), | 2859 result = Fcons (Fcons (build_string (fonts[i].fields[XLFD_FAMILY]), |
2895 | 2896 |
2896 check_x (); | 2897 check_x (); |
2897 CHECK_STRING (pattern); | 2898 CHECK_STRING (pattern); |
2898 | 2899 |
2899 if (NILP (maximum)) | 2900 if (NILP (maximum)) |
2900 maxnames = 2000; | 2901 maxnames = -1; |
2901 else | 2902 else |
2902 { | 2903 { |
2903 CHECK_NATNUM (maximum); | 2904 CHECK_NATNUM (maximum); |
2904 maxnames = XINT (maximum); | 2905 maxnames = XINT (maximum); |
2905 } | 2906 } |