From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.bugs Subject: bug#2667: Still seeing inconsistent fonts Date: Mon, 11 May 2009 21:21:45 +0900 Message-ID: References: <87zldo8dnb.fsf@cyd.mit.edu> Reply-To: Kenichi Handa , 2667@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1242045187 11699 80.91.229.12 (11 May 2009 12:33:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 11 May 2009 12:33:07 +0000 (UTC) Cc: cyd@stupidchicken.com, 2667@emacsbugs.donarmstrong.com To: Stefan Monnier , 2667@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 11 14:32:57 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M3Uga-0000QQ-De for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 May 2009 14:32:50 +0200 Original-Received: from localhost ([127.0.0.1]:44208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M3UgZ-0006Gs-Mv for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 May 2009 08:32:47 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M3Ufs-0005hO-B1 for bug-gnu-emacs@gnu.org; Mon, 11 May 2009 08:32:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M3Ufn-0005f8-Dq for bug-gnu-emacs@gnu.org; Mon, 11 May 2009 08:32:03 -0400 Original-Received: from [199.232.76.173] (port=54945 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M3Ufm-0005es-Hr for bug-gnu-emacs@gnu.org; Mon, 11 May 2009 08:31:59 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:60081) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M3Ufl-0003Yv-Kw for bug-gnu-emacs@gnu.org; Mon, 11 May 2009 08:31:58 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n4BCVsbW002485; Mon, 11 May 2009 05:31:55 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id n4BCP5sw032425; Mon, 11 May 2009 05:25:05 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Kenichi Handa Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Mon, 11 May 2009 12:25:05 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 2667 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 2667-submit@emacsbugs.donarmstrong.com id=B2667.124204451532088 (code B ref 2667); Mon, 11 May 2009 12:25:05 +0000 Original-Received: (at 2667) by emacsbugs.donarmstrong.com; 11 May 2009 12:21:55 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mx1.aist.go.jp (mx1.aist.go.jp [150.29.246.133]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n4BCLlTt032072 for <2667@emacsbugs.donarmstrong.com>; Mon, 11 May 2009 05:21:49 -0700 Original-Received: from rqsmtp1.aist.go.jp (rqsmtp1.aist.go.jp [150.29.254.115]) by mx1.aist.go.jp with ESMTP id n4BCLhC1019369; Mon, 11 May 2009 21:21:43 +0900 (JST) env-from (handa@m17n.org) Original-Received: from smtp3.aist.go.jp by rqsmtp1.aist.go.jp with ESMTP id n4BCLhuH018990; Mon, 11 May 2009 21:21:43 +0900 (JST) env-from (handa@m17n.org) Original-Received: by smtp3.aist.go.jp with ESMTP id n4BCLfm8005511; Mon, 11 May 2009 21:21:41 +0900 (JST) env-from (handa@m17n.org) Original-Received: from handa by etlken with local (Exim 4.69) (envelope-from ) id 1M3UVt-0000EV-8d; Mon, 11 May 2009 21:21:45 +0900 In-reply-to: (message from Stefan Monnier on Fri, 08 May 2009 15:58:31 -0400) X-MIME-Autoconverted: from 8bit to quoted-printable by rzlab.ucr.edu id n4BCVsbW002485 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Mon, 11 May 2009 08:32:03 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:27824 Archived-At: Sorry for the late response on this matter. In article , Stefan Monn= ier writes: > > I can't reproduce this. Could you provide a self-contained testcase? > Sure: > xrdb -remove > rm ~/.Xdefaults > src/emacs -Q --eval '(set-face-font (quote default) \ > "-misc-fixed-medium-r-semicondensed--13-*-*-*-*-*-*-*")' > C-u C-\ TeX RET > a > \ ' e > \ ' r > \ f o r a l l > "a=C3=A9=C5=95" use misc-fixed-semicondensed (the first two with iso885= 9-1 and > the last with iso8859-2), but "=E2=88=80" is displayed with > xft:-unknown-DejaVu Sans-normal-normal-semi-condensed-*-13-*-*-*-*-0-is= o10646-1 =E2=88=80 belongs to `symbol' script, but the xfont backend didn't support :script font property. That is because I was afraid that it made the font listing extremely slow (we must open all iso10646-1 fonts to check if it supports the requested characters). Actually my trial implementation of :script property supports took more than 1 minute to display HELLO file. But, if we can use this heuristic: X fonts that have the same property values except for size related properties supports the same set of characters on all display. For example, all these fonts=20 -adobe-courier-medium-r-normal--8-80-75-75-m-50-iso10646-1 -adobe-courier-medium-r-normal--10-100-75-75-m-60-iso10646-1 -adobe-courier-medium-r-normal--11-80-100-100-m-60-iso10646-1 -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso10646-1 -adobe-courier-medium-r-normal--14-100-100-100-m-90-iso10646-1 -adobe-courier-medium-r-normal--14-140-75-75-m-90-iso10646-1 -adobe-courier-medium-r-normal--17-120-100-100-m-100-iso10646-1 -adobe-courier-medium-r-normal--18-180-75-75-m-110-iso10646-1 -adobe-courier-medium-r-normal--20-140-100-100-m-110-iso10646-1 -adobe-courier-medium-r-normal--24-240-75-75-m-150-iso10646-1 -adobe-courier-medium-r-normal--25-180-100-100-m-150-iso10646-1 -adobe-courier-medium-r-normal--34-240-100-100-m-200-iso10646-1 suports the same set of characters. we can list fonts in a realistic time. Attached is the patch to try it. Could you please test it? As the change is not simple, I have not yet installed it. --- Kenichi Handa handa@m17n.org Index: xfont.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/src/xfont.c,v retrieving revision 1.28 diff -u -r1.28 xfont.c --- xfont.c 8 May 2009 06:22:40 -0000 1.28 +++ xfont.c 11 May 2009 12:03:16 -0000 @@ -256,20 +256,172 @@ return len; } =20 -static Lisp_Object xfont_list_pattern P_ ((Lisp_Object, Display *, char = *)); +static int xfont_chars_supported P_ ((Lisp_Object, XFontStruct *, + struct charset *, struct charset *)); + +/* Check if CHARS (cons or vector) is supported by XFONT whose + encoding charset is ENCODING (XFONT is NULL) or by a font whose + registry corresponds to ENCODING and REPERTORY. + Return 1 if supported, return 0 otherwise. */ + +static int +xfont_chars_supported (chars, xfont, encoding, repertory) + Lisp_Object chars; + XFontStruct *xfont; + struct charset *encoding, *repertory; +{ + struct charset *charset =3D repertory ? repertory : encoding; + + if (CONSP (chars)) + { + for (; CONSP (chars); chars =3D XCDR (chars)) + { + int c =3D XINT (XCAR (chars)); + unsigned code =3D ENCODE_CHAR (charset, c); + XChar2b char2b; + + if (code =3D=3D CHARSET_INVALID_CODE (charset)) + break; + if (! xfont) + continue; + if (code >=3D 0x10000) + break; + char2b.byte1 =3D code >> 8; + char2b.byte2 =3D code & 0xFF; + if (! xfont_get_pcm (xfont, &char2b)) + break; + } + return (NILP (chars)); + } + else if (VECTORP (chars)) + { + int i; + + for (i =3D ASIZE (chars) - 1; i >=3D 0; i--) + { + int c =3D XINT (AREF (chars, i)); + unsigned code =3D ENCODE_CHAR (charset, c); + XChar2b char2b; + + if (code =3D=3D CHARSET_INVALID_CODE (charset)) + continue; + if (! xfont) + break; + if (code >=3D 0x10000) + continue; + char2b.byte1 =3D code >> 8; + char2b.byte2 =3D code & 0xFF; + if (xfont_get_pcm (xfont, &char2b)) + break; + } + return (i >=3D 0); + } + return 0; +} + +/* A hash table recoding which font supports which scritps. Each key + is a vector of characteristic font propertis FOUNDRY to WIDTH and + ADDSTYLE, and each value is a list of script symbols. + + We assume that fonts that have the same value in the above + properties supports the same set of characters on all displays. */ + +static Lisp_Object xfont_scripts_cache; + +/* Return a list of scripts supported by the font of FONTNAME whose + characteristic properties are in PROPS and whose encoding charset + is ENCODING. A caller must call BLOCK_INPUT in advance. */ =20 static Lisp_Object -xfont_list_pattern (frame, display, pattern) - Lisp_Object frame; +xfont_supported_scripts (display, fontname, props, encoding) + Display *display; + char *fontname; + Lisp_Object props; + struct charset *encoding; +{ + Lisp_Object scripts; + + /* Two special cases to avoid opening rather big fonts. */ + if (AREF (props, 2), Qja) + return Fcons (intern ("kana"), Fcons (intern ("han"), Qnil)); + if (AREF (props, 2), Qko) + return Fcons (intern ("hangul"), Qnil); + scripts =3D Fgethash (props, xfont_scripts_cache, Qt); + if (EQ (scripts, Qt)) + { + XFontStruct *xfont; + Lisp_Object val; + + scripts =3D Qnil; + xfont =3D XLoadQueryFont (display, fontname); + if (xfont) + { + if (xfont->per_char) + { + for (val =3D Vscript_representative_chars; CONSP (val); + val =3D XCDR (val)) + if (CONSP (XCAR (val)) && SYMBOLP (XCAR (XCAR (val)))) + { + Lisp_Object script =3D XCAR (XCAR (val)); + Lisp_Object chars =3D XCDR (XCAR (val)); + + if (xfont_chars_supported (chars, xfont, encoding, NULL)) + scripts =3D Fcons (script, scripts); + } + } + XFreeFont (display, xfont); + } + Fputhash (Fcopy_sequence (props), scripts, xfont_scripts_cache); + } + return scripts; +} + +extern Lisp_Object Vscalable_fonts_allowed; + +static Lisp_Object xfont_list_pattern P_ ((Display *, char *,=20 + Lisp_Object, Lisp_Object)); + +static Lisp_Object +xfont_list_pattern (display, pattern, registry, script) Display *display; char *pattern; + Lisp_Object registry, script; { Lisp_Object list =3D Qnil; + Lisp_Object chars =3D Qnil; + struct charset *encoding, *repertory =3D NULL; int i, limit, num_fonts; char **names; /* Large enough to decode the longest XLFD (255 bytes). */ char buf[512]; =20 + if (! NILP (registry) + && font_registry_charsets (registry, &encoding, &repertory) < 0) + /* Unknown REGISTRY, not supported. */ + return Qnil; + if (! NILP (script)) + { + chars =3D assq_no_quit (script, Vscript_representative_chars); + if (NILP (chars)) + /* We can't tell whether or not a font supports SCRIPT. */ + return Qnil; + chars =3D XCDR (chars); + if (repertory) + { + if (! xfont_chars_supported (chars, NULL, encoding, repertory)) + return Qnil; + script =3D Qnil; + } + } + if (! repertory && NILP (xfont_scripts_cache)) + { + Lisp_Object args[2]; + + args[0] =3D QCtest; + args[1] =3D Qequal; + xfont_scripts_cache =3D Fmake_hash_table (2, args); + } + =20 BLOCK_INPUT; x_catch_errors (display); =20 @@ -292,6 +444,8 @@ if (num_fonts > 0) { char **indices =3D alloca (sizeof (char *) * num_fonts); + Lisp_Object props =3D Fmake_vector (make_number (9), Qnil); + Lisp_Object scripts =3D Qnil; =20 for (i =3D 0; i < num_fonts; i++) indices[i] =3D names[i]; @@ -300,47 +454,68 @@ for (i =3D 0; i < num_fonts; i++) { Lisp_Object entity; - int result; - char *p; =20 if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) =3D=3D 0) continue; - entity =3D font_make_entity (); - ASET (entity, FONT_TYPE_INDEX, Qx); xfont_decode_coding_xlfd (indices[i], -1, buf); - result =3D font_parse_xlfd (buf, entity); - if (result < 0) + font_parse_xlfd (buf, entity); + ASET (entity, FONT_TYPE_INDEX, Qx); + /* Avoid auto-scaled fonts. */ + if (XINT (AREF (entity, FONT_DPI_INDEX)) !=3D 0 + && XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) =3D=3D 0) + continue; + /* Avoid not-allowed scalable fonts. */ + if (NILP (Vscalable_fonts_allowed)) { - /* This may be an alias name. Try to get the full XLFD name - from XA_FONT property of the font. */ - XFontStruct *font =3D XLoadQueryFont (display, indices[i]); - unsigned long value; - - if (! font) + if (XINT (AREF (entity, FONT_SIZE_INDEX)) =3D=3D 0) continue; - if (XGetFontProperty (font, XA_FONT, &value)) - { - char *name =3D (char *) XGetAtomName (display, (Atom) value); - int len =3D strlen (name); + } + else if (CONSP (Vscalable_fonts_allowed)) + { + Lisp_Object tail, elt; =20 - /* If DXPC (a Differential X Protocol Compressor) - Ver.3.7 is running, XGetAtomName will return null - string. We must avoid such a name. */ - if (len > 0) - { - xfont_decode_coding_xlfd (indices[i], -1, buf); - result =3D font_parse_xlfd (buf, entity); - } - XFree (name); + for (tail =3D Vscalable_fonts_allowed; CONSP (tail); + tail =3D XCDR (tail)) + { + elt =3D XCAR (tail); + if (STRINGP (elt) + && fast_c_string_match_ignore_case (elt, indices[i]) >=3D 0) + break; } - XFreeFont (display, font); + if (! CONSP (tail)) + continue; } =20 - if (result =3D=3D 0 - /* Avoid auto-scaled fonts. */ - && (XINT (AREF (entity, FONT_DPI_INDEX)) =3D=3D 0 - || XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) > 0)) + /* Update encoding and repertory if necessary. */ + if (! EQ (registry, AREF (entity, FONT_REGISTRY_INDEX))) + { + registry =3D AREF (entity, FONT_REGISTRY_INDEX); + if (font_registry_charsets (registry, &encoding, &repertory) < 0) + encoding =3D NULL; + } + if (! encoding) + /* Unknown REGISTRY, not supported. */ + continue; + if (repertory) + { + if (NILP (script) + || xfont_chars_supported (chars, NULL, encoding, repertory)) + list =3D Fcons (entity, list); + continue; + } + if (memcmp (&(AREF (props, 0)), &(AREF (entity, FONT_FOUNDRY_INDEX)), + sizeof (Lisp_Object) * 7) + || ! EQ (AREF (entity, FONT_SPACING_INDEX), AREF (props, 8))) + { + memcpy (&(AREF (props, 0)), &(AREF (entity, FONT_FOUNDRY_INDEX)), + sizeof (Lisp_Object) * 7); + ASET (props, 8, AREF (entity, FONT_SPACING_INDEX)); + scripts =3D xfont_supported_scripts (display, indices[i], + props, encoding); + } + if (NILP (script) + || ! NILP (Fmemq (script, scripts))) list =3D Fcons (entity, list); } XFreeFontNames (names); @@ -359,7 +534,7 @@ { FRAME_PTR f =3D XFRAME (frame); Display *display =3D FRAME_X_DISPLAY_INFO (f)->display; - Lisp_Object registry, list, val, extra; + Lisp_Object registry, list, val, extra, script; int len; /* Large enough to contain the longest XLFD (255 bytes) in UTF-8. */ char name[512]; @@ -370,9 +545,6 @@ val =3D assq_no_quit (QCotf, extra); if (! NILP (val)) return Qnil; - val =3D assq_no_quit (QCscript, extra); - if (! NILP (val)) - return Qnil; val =3D assq_no_quit (QClang, extra); if (! NILP (val)) return Qnil; @@ -382,8 +554,13 @@ len =3D font_unparse_xlfd (spec, 0, name, 512); if (len < 0 || (len =3D xfont_encode_coding_xlfd (name)) < 0) return Qnil; - ASET (spec, FONT_REGISTRY_INDEX, registry); - list =3D xfont_list_pattern (frame, display, name); + + val =3D assq_no_quit (QCscript, extra); + if (NILP (val)) + script =3D Qnil; + else + script =3D XCDR (val); + list =3D xfont_list_pattern (display, name, registry, script); if (NILP (list) && NILP (registry)) { /* Try iso10646-1 */ @@ -392,7 +569,7 @@ if (r - name + 10 < 256) /* 10 =3D=3D strlen (iso10646-1) */ { strcpy (r, "iso10646-1"); - list =3D xfont_list_pattern (frame, display, name); + list =3D xfont_list_pattern (display, name, Qiso10646_1, script); } } if (NILP (list) && ! NILP (registry)) @@ -412,7 +589,7 @@ && ((r - name) + SBYTES (XCAR (alter))) < 256) { strcpy (r, (char *) SDATA (XCAR (alter))); - list =3D xfont_list_pattern (frame, display, name); + list =3D xfont_list_pattern (display, name, registry, script); if (! NILP (list)) break; } @@ -427,7 +604,7 @@ bcopy (SDATA (XCDR (val)), name, SBYTES (XCDR (val)) + 1); if (xfont_encode_coding_xlfd (name) < 0) return Qnil; - list =3D xfont_list_pattern (frame, display, name); + list =3D xfont_list_pattern (display, name, registry, script); } } =20 @@ -996,6 +1173,8 @@ void syms_of_xfont () { + staticpro (&xfont_scripts_cache); + xfont_scripts_cache =3D Qnil; xfont_driver.type =3D Qx; register_font_driver (&xfont_driver, NULL); }