comparison src/xterm.c @ 22503:104e277d77d3

(x_list_fonts): If SIZE is zero and MAXNAMES is 1, use XLoadQueryFont instead of XListFonts. (x_load_fonts): Call x_list_fonts with MAXNAMES 1.
author Kenichi Handa <handa@m17n.org>
date Tue, 16 Jun 1998 07:32:05 +0000
parents 8fbe6f509385
children f56d8440c0a4
comparison
equal deleted inserted replaced
22502:627b13315f04 22503:104e277d77d3
6421 int size; 6421 int size;
6422 int maxnames; 6422 int maxnames;
6423 { 6423 {
6424 Lisp_Object list = Qnil, patterns, newlist = Qnil, key, tem, second_best; 6424 Lisp_Object list = Qnil, patterns, newlist = Qnil, key, tem, second_best;
6425 Display *dpy = f != NULL ? FRAME_X_DISPLAY (f) : x_display_list->display; 6425 Display *dpy = f != NULL ? FRAME_X_DISPLAY (f) : x_display_list->display;
6426 int try_XLoadQueryFont = 0;
6426 6427
6427 patterns = Fassoc (pattern, Valternate_fontname_alist); 6428 patterns = Fassoc (pattern, Valternate_fontname_alist);
6428 if (NILP (patterns)) 6429 if (NILP (patterns))
6429 patterns = Fcons (pattern, Qnil); 6430 patterns = Fcons (pattern, Qnil);
6430 6431
6431 /* We try at least 10 fonts because X server will return auto-scaled 6432 if (maxnames == 1 && !size)
6432 fonts at the head. */ 6433 /* We can return any single font matching PATTERN. */
6433 if (maxnames < 10) maxnames = 10; 6434 try_XLoadQueryFont = 1;
6435 else
6436 {
6437 /* We try at least 10 fonts because XListFonts will return
6438 auto-scaled fonts at the head. */
6439 if (maxnames < 10) maxnames = 10;
6440 }
6434 6441
6435 for (; CONSP (patterns); patterns = XCONS (patterns)->cdr) 6442 for (; CONSP (patterns); patterns = XCONS (patterns)->cdr)
6436 { 6443 {
6437 int num_fonts; 6444 int num_fonts;
6438 char **names; 6445 char **names;
6450 /* We have a cashed list. Don't have to get the list again. */ 6457 /* We have a cashed list. Don't have to get the list again. */
6451 goto label_cached; 6458 goto label_cached;
6452 } 6459 }
6453 6460
6454 /* At first, put PATTERN in the cache. */ 6461 /* At first, put PATTERN in the cache. */
6462
6455 BLOCK_INPUT; 6463 BLOCK_INPUT;
6456 names = XListFonts (dpy, XSTRING (pattern)->data, maxnames, &num_fonts); 6464 if (try_XLoadQueryFont)
6465 {
6466 XFontStruct *font;
6467 unsigned long value;
6468
6469 font = XLoadQueryFont (dpy, XSTRING (pattern)->data);
6470 if (font
6471 && XGetFontProperty (font, XA_FONT, &value))
6472 {
6473 char *name = (char *) XGetAtomName (dpy, (Atom) value);
6474 int len = strlen (name);
6475
6476 num_fonts = 1;
6477 names = alloca (sizeof (char *));
6478 names[0] = alloca (len + 1);
6479 bcopy (name, names[0], len + 1);
6480 XFree (name);
6481 }
6482 else
6483 try_XLoadQueryFont = 0;
6484 }
6485
6486 if (!try_XLoadQueryFont)
6487 names = XListFonts (dpy, XSTRING (pattern)->data, maxnames,
6488 &num_fonts);
6457 UNBLOCK_INPUT; 6489 UNBLOCK_INPUT;
6458 6490
6459 if (names) 6491 if (names)
6460 { 6492 {
6461 int i; 6493 int i;
6497 /* For the moment, width is not known. */ 6529 /* For the moment, width is not known. */
6498 list = Fcons (Fcons (tem, Qnil), list); 6530 list = Fcons (Fcons (tem, Qnil), list);
6499 } 6531 }
6500 } 6532 }
6501 } 6533 }
6502 XFreeFontNames (names); 6534 if (!try_XLoadQueryFont)
6535 XFreeFontNames (names);
6503 } 6536 }
6504 6537
6505 /* Now store the result in the cache. */ 6538 /* Now store the result in the cache. */
6506 if (f != NULL) 6539 if (f != NULL)
6507 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr 6540 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr
6601 Lisp_Object font_names; 6634 Lisp_Object font_names;
6602 6635
6603 /* Get a list of all the fonts that match this name. Once we 6636 /* Get a list of all the fonts that match this name. Once we
6604 have a list of matching fonts, we compare them against the fonts 6637 have a list of matching fonts, we compare them against the fonts
6605 we already have by comparing names. */ 6638 we already have by comparing names. */
6606 font_names = x_list_fonts (f, build_string (fontname), size, 256); 6639 font_names = x_list_fonts (f, build_string (fontname), size, 1);
6607 6640
6608 if (!NILP (font_names)) 6641 if (!NILP (font_names))
6609 { 6642 {
6610 Lisp_Object tail; 6643 Lisp_Object tail;
6611 int i; 6644 int i;