From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Jan D." Newsgroups: gmane.emacs.devel Subject: Re: [d.love@dl.ac.uk: x-font-family-list gives incomplete results] Date: Sun, 16 Feb 2003 20:20:43 +0100 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <3E4FE48B.2030004@swipnet.se> References: <3E4FDADA.3040105@swipnet.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050609070901030209060705" X-Trace: main.gmane.org 1045423351 20431 80.91.224.249 (16 Feb 2003 19:22:31 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 16 Feb 2003 19:22:31 +0000 (UTC) Cc: d.love@dl.ac.uk Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18kUMv-0005JM-00 for ; Sun, 16 Feb 2003 20:22:29 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18kUay-00080q-00 for ; Sun, 16 Feb 2003 20:37:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18kUOu-0002aW-03 for emacs-devel@quimby.gnus.org; Sun, 16 Feb 2003 14:24:32 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18kUNy-0002J9-00 for emacs-devel@gnu.org; Sun, 16 Feb 2003 14:23:34 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18kUNt-0002BM-00 for emacs-devel@gnu.org; Sun, 16 Feb 2003 14:23:31 -0500 Original-Received: from stubby.bodenonline.com ([193.201.16.94]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18kULI-0000jW-00; Sun, 16 Feb 2003 14:20:48 -0500 Original-Received: from swipnet.se (accessno42.bodenonline.com [193.201.16.44]) h1GKES3B032706; Sun, 16 Feb 2003 21:14:29 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2a) Gecko/20020910 X-Accept-Language: en-us, en Original-To: emacs-devel@gnu.org Original-cc: rms@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:11686 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:11686 This is a multi-part message in MIME format. --------------050609070901030209060705 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Jan D. wrote: > One alternative solution would be to make maxnames passed to > x_list_fonts (xterm.c) mean "get all font names" if it is less than > zero. This also affects w32 and mac, since those ports also have a > function with this name. > > Making maxnames < 0 mean "all font names" should perhaps be propagated > into Fx_list_fonts? Now it uses an arbitrary limit of 2000 if maximum > is not given, which is too few on many machines. > Here is a proposed patch. Comments welcome. I can not do the mac and w32 parts, because I have no development environment on such systems. Jan D. --------------050609070901030209060705 Content-Type: text/plain; name="listfont.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="listfont.diff" Index: src/xfaces.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xfaces.c,v retrieving revision 1.267 diff -c -r1.267 xfaces.c *** src/xfaces.c 4 Feb 2003 14:03:17 -0000 1.267 --- src/xfaces.c 16 Feb 2003 19:17:34 -0000 *************** *** 474,480 **** static int better_font_p P_ ((int *, struct font_name *, struct font_name *, int, int)); static int x_face_list_fonts P_ ((struct frame *, char *, ! struct font_name *, int, int)); static int font_scalable_p P_ ((struct font_name *)); static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); --- 474,480 ---- static int better_font_p P_ ((int *, struct font_name *, struct font_name *, int, int)); static int x_face_list_fonts P_ ((struct frame *, char *, ! struct font_name **, int, int)); static int font_scalable_p P_ ((struct font_name *)); static int get_lface_attributes P_ ((struct frame *, Lisp_Object, Lisp_Object *, int)); static int load_pixmap P_ ((struct frame *, Lisp_Object, unsigned *, unsigned *)); *************** *** 2435,2444 **** fonts that we can't parse. Value is the number of fonts found. */ static int ! x_face_list_fonts (f, pattern, fonts, nfonts, try_alternatives_p) struct frame *f; char *pattern; ! struct font_name *fonts; int nfonts, try_alternatives_p; { int n, nignored; --- 2435,2444 ---- fonts that we can't parse. Value is the number of fonts found. */ static int ! x_face_list_fonts (f, pattern, pfonts, nfonts, try_alternatives_p) struct frame *f; char *pattern; ! struct font_name **pfonts; int nfonts, try_alternatives_p; { int n, nignored; *************** *** 2447,2452 **** --- 2447,2454 ---- better to do it the other way around. */ Lisp_Object lfonts; Lisp_Object lpattern, tem; + struct font_name *fonts = 0; + int num_fonts = nfonts; lpattern = build_string (pattern); *************** *** 2459,2468 **** lfonts = x_list_fonts (f, lpattern, -1, nfonts); #endif /* Make a copy of the font names we got from X, and split them into fields. */ n = nignored = 0; ! for (tem = lfonts; CONSP (tem) && n < nfonts; tem = XCDR (tem)) { Lisp_Object elt, tail; const char *name = SDATA (XCAR (tem)); --- 2461,2473 ---- lfonts = x_list_fonts (f, lpattern, -1, nfonts); #endif + if (nfonts < 0 && CONSP (lfonts)) + num_fonts = Flength (lfonts); + /* Make a copy of the font names we got from X, and split them into fields. */ n = nignored = 0; ! for (tem = lfonts; CONSP (tem) && n < num_fonts; tem = XCDR (tem)) { Lisp_Object elt, tail; const char *name = SDATA (XCAR (tem)); *************** *** 2481,2486 **** --- 2486,2497 ---- continue; } + if (! fonts) + { + *pfonts = (struct font_name *) xmalloc (num_fonts * sizeof **pfonts); + fonts = *pfonts; + } + /* Make a copy of the font name. */ fonts[n].name = xstrdup (name); *************** *** 2504,2509 **** --- 2515,2522 ---- { Lisp_Object list = Valternate_fontname_alist; + if (fonts) xfree (fonts); + while (CONSP (list)) { Lisp_Object entry = XCAR (list); *************** *** 2527,2533 **** already with no success. */ && (strcmp (SDATA (name), pattern) == 0 || (n = x_face_list_fonts (f, SDATA (name), ! fonts, nfonts, 0), n == 0))) patterns = XCDR (patterns); } --- 2540,2546 ---- already with no success. */ && (strcmp (SDATA (name), pattern) == 0 || (n = x_face_list_fonts (f, SDATA (name), ! pfonts, nfonts, 0), n == 0))) patterns = XCDR (patterns); } *************** *** 2556,2566 **** /* Get the list of fonts matching pattern. 100 should suffice. */ nfonts = DEFAULT_FONT_LIST_LIMIT; ! if (INTEGERP (Vfont_list_limit) && XINT (Vfont_list_limit) > 0) ! nfonts = XFASTINT (Vfont_list_limit); ! *fonts = (struct font_name *) xmalloc (nfonts * sizeof **fonts); ! nfonts = x_face_list_fonts (f, pattern, *fonts, nfonts, 1); /* Sort the resulting array and return it in *FONTS. If no fonts were found, make sure to set *FONTS to null. */ --- 2569,2578 ---- /* Get the list of fonts matching pattern. 100 should suffice. */ nfonts = DEFAULT_FONT_LIST_LIMIT; ! if (INTEGERP (Vfont_list_limit)) ! nfonts = XINT (Vfont_list_limit); ! nfonts = x_face_list_fonts (f, pattern, fonts, nfonts, 1); /* Sort the resulting array and return it in *FONTS. If no fonts were found, make sure to set *FONTS to null. */ *************** *** 2834,2856 **** Lisp_Object result; struct gcpro gcpro1; int count = SPECPDL_INDEX (); - int limit; - - /* Let's consider all fonts. Increase the limit for matching - fonts until we have them all. */ - for (limit = 500;;) - { - specbind (intern ("font-list-limit"), make_number (limit)); - nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts); ! if (nfonts == limit) ! { ! free_font_names (fonts, nfonts); ! limit *= 2; ! } ! else ! break; ! } result = Qnil; GCPRO1 (result); --- 2846,2855 ---- Lisp_Object result; struct gcpro gcpro1; int count = SPECPDL_INDEX (); ! /* Let's consider all fonts. */ ! specbind (intern ("font-list-limit"), make_number (-1)); ! nfonts = font_list (f, Qnil, Qnil, Qnil, &fonts); result = Qnil; GCPRO1 (result); *************** *** 2897,2903 **** CHECK_STRING (pattern); if (NILP (maximum)) ! maxnames = 2000; else { CHECK_NATNUM (maximum); --- 2896,2902 ---- CHECK_STRING (pattern); if (NILP (maximum)) ! maxnames = -1; else { CHECK_NATNUM (maximum); Index: src/xterm.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/xterm.c,v retrieving revision 1.772 diff -c -r1.772 xterm.c *** src/xterm.c 8 Feb 2003 11:18:32 -0000 1.772 --- src/xterm.c 16 Feb 2003 19:17:45 -0000 *************** *** 14536,14543 **** { /* We try at least 10 fonts because XListFonts will return auto-scaled fonts at the head. */ ! names = XListFonts (dpy, SDATA (pattern), max (maxnames, 10), ! &num_fonts); if (x_had_errors_p (dpy)) { /* This error is perhaps due to insufficient memory on X --- 14536,14563 ---- { /* We try at least 10 fonts because XListFonts will return auto-scaled fonts at the head. */ ! if (maxnames < 0) ! { ! int limit; ! ! for (limit = 500;;) ! { ! names = XListFonts (dpy, SDATA (pattern), limit, &num_fonts); ! if (num_fonts == limit) ! { ! BLOCK_INPUT; ! XFreeFontNames (names); ! UNBLOCK_INPUT; ! limit *= 2; ! } ! else ! break; ! } ! } ! else ! names = XListFonts (dpy, SDATA (pattern), max (maxnames, 10), ! &num_fonts); ! if (x_had_errors_p (dpy)) { /* This error is perhaps due to insufficient memory on X --------------050609070901030209060705 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel --------------050609070901030209060705--