aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/xterm.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 5ddeeb0e100..565e9205ca7 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -6423,14 +6423,21 @@ x_list_fonts (f, pattern, size, 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 {
@@ -6452,8 +6459,33 @@ x_list_fonts (f, pattern, size, maxnames)
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)
@@ -6499,7 +6531,8 @@ x_list_fonts (f, pattern, size, maxnames)
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. */
@@ -6603,7 +6636,7 @@ x_load_font (f, fontname, size)
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 {