Mercurial > hg > xemacs-beta
annotate src/fontcolor-xlike-inc.c @ 5197:ce8ffb95bbe3
finish up CHANGES-beta -- all changes thru Apr 9, 2010
-------------------- ChangeLog entries follow: --------------------
ChangeLog addition:
2010-04-09 Ben Wing <ben@xemacs.org>
* CHANGES-beta:
Update with my changes to the trunk since the release of 21.5.29
in 2009 up through April 9, 2010.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 09 Apr 2010 02:33:11 -0500 |
parents | b65692aa90d8 |
children | c87ec061e8cc |
rev | line source |
---|---|
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
1 /* Common code between X and GTK -- fonts and colors. |
3659 | 2 Copyright (C) 1991-5, 1997 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
4 Copyright (C) 1996, 2001, 2002, 2003, 2010 Ben Wing. |
3659 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Not in FSF. */ | |
24 | |
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
25 /* Before including this file, you need to define either THIS_IS_X or |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
26 THIS_IS_GTK. */ |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
27 |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
28 /* See comment at top of console-xlike-inc.h for an explanation of |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
29 how this file works. */ |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
30 |
3659 | 31 /* Pango is ready for prime-time now, as far as I understand it. The GTK |
32 people should be using that. Oh well. (Aidan Kehoe, Sat Nov 4 12:41:12 | |
33 CET 2006) */ | |
34 | |
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
35 #include "console-xlike-inc.h" |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
36 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
37 #define DEBUG_FONTS1(format, arg) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
38 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
39 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
40 debug_out (format, arg); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
41 } while (0) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
42 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
43 #define DEBUG_FONTS2(format, arg1, arg2) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
44 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
45 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
46 debug_out (format, arg1, arg2); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
47 } while (0) |
3659 | 48 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
49 #define DEBUG_FONTS3(format, arg1, arg2, arg3) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
50 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
51 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
52 debug_out (format, arg1, arg2, arg3); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
53 } while (0) |
3659 | 54 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
55 #define DEBUG_FONTS4(format, arg1, arg2, arg3, arg4) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
56 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
57 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
58 debug_out (format, arg1, arg2, arg3, arg4); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
59 } while (0) |
3659 | 60 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
61 #define DEBUG_FONTS_LISP1(format, arg) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
62 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
63 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
64 debug_out_lisp (format, 1, arg); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
65 } while (0) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
66 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
67 #define DEBUG_FONTS_LISP2(format, arg1, arg2) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
68 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
69 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
70 debug_out_lisp (format, 2, arg1, arg2); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
71 } while (0) |
3659 | 72 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
73 #define DEBUG_FONTS_LISP3(format, arg1, arg2, arg3) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
74 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
75 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
76 debug_out_lisp (format, 3, arg1, arg2, arg3); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
77 } while (0) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
78 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
79 #define DEBUG_FONTS_LISP4(format, arg1, arg2, arg3, arg4) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
80 do { \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
81 if (debug_x_fonts) \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
82 debug_out_lisp (format, 4, arg1, arg2, arg3, arg4); \ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
83 } while (0) |
3659 | 84 |
85 #ifdef MULE | |
86 | |
87 /* For some code it's reasonable to have only one copy and conditionalize | |
88 at run-time. For other code it isn't. */ | |
89 | |
90 static int | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
91 count_hyphens (const Ibyte *str, Bytecount length, Ibyte **last_hyphen) |
3659 | 92 { |
93 int hyphen_count = 0; | |
94 const Ibyte *hyphening = str; | |
95 const Ibyte *new_hyphening; | |
96 | |
97 for (hyphen_count = 0; | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
98 NULL != (new_hyphening = (Ibyte *) memchr ((const void *)hyphening, '-', length)); |
3659 | 99 hyphen_count++) |
100 { | |
101 ++new_hyphening; | |
102 length -= new_hyphening - hyphening; | |
103 hyphening = new_hyphening; | |
104 } | |
105 | |
106 if (NULL != last_hyphen) | |
107 { | |
108 *last_hyphen = (Ibyte *)hyphening; | |
109 } | |
110 | |
111 return hyphen_count; | |
112 } | |
113 | |
114 static int | |
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
115 XFUN (font_spec_matches_charset) (struct device * USED_IF_XFT (d), |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
116 Lisp_Object charset, |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
117 const Ibyte *nonreloc, Lisp_Object reloc, |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
118 Bytecount offset, Bytecount length, |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
119 enum font_specifier_matchspec_stages stage) |
3659 | 120 { |
121 Lisp_Object registries = Qnil; | |
122 long i, registries_len; | |
123 const Ibyte *the_nonreloc; | |
124 Bytecount the_length; | |
125 | |
126 the_nonreloc = nonreloc; | |
127 the_length = length; | |
128 | |
129 if (!the_nonreloc) | |
130 the_nonreloc = XSTRING_DATA (reloc); | |
131 fixup_internal_substring (nonreloc, reloc, offset, &the_length); | |
132 the_nonreloc += offset; | |
133 | |
134 #ifdef USE_XFT | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
135 if (stage == STAGE_FINAL) |
3659 | 136 { |
137 Display *dpy = DEVICE_X_DISPLAY (d); | |
138 Extbyte *extname; | |
139 XftFont *rf; | |
140 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
141 if (!NILP (reloc)) |
3659 | 142 { |
143 the_nonreloc = XSTRING_DATA (reloc); | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
144 extname = LISP_STRING_TO_EXTERNAL (reloc, Qx_font_name_encoding); |
3659 | 145 rf = xft_open_font_by_name (dpy, extname); |
146 return 0; /* #### maybe this will compile and run ;) */ | |
147 /* Jesus, Stephen, what the fuck? */ | |
148 } | |
149 } | |
150 #endif | |
151 | |
152 /* Hmm, this smells bad. */ | |
4353
4143b78d0df0
Merge an old patch of Ben's, involving font instantiation and charsets.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
153 if (NILP (charset)) |
3659 | 154 return 1; |
155 | |
156 /* Hack! Short font names don't have the registry in them, | |
157 so we just assume the user knows what they're doing in the | |
158 case of ASCII. For other charsets, you gotta give the | |
159 long form; sorry buster. | |
160 #### FMH: this screws fontconfig/Xft? | |
161 STRATEGY: use fontconfig's ability to hack languages and character | |
162 sets (lang and charset properties). | |
163 #### Maybe we can use the fontconfig model to eliminate the difference | |
164 between faces and fonts? No - it looks like that would be an abuse | |
165 (fontconfig doesn't know about colors, although Xft does). | |
166 */ | |
167 if (EQ (charset, Vcharset_ascii) && | |
168 (!memchr (the_nonreloc, '*', the_length)) | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
169 && (5 > (count_hyphens (the_nonreloc, the_length, NULL)))) |
3659 | 170 { |
171 return 1; | |
172 } | |
173 | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
174 if (STAGE_FINAL == stage) |
3659 | 175 { |
176 registries = Qunicode_registries; | |
177 } | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
178 else if (STAGE_INITIAL == stage) |
3659 | 179 { |
180 registries = XCHARSET_REGISTRIES (charset); | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
181 if (NILP (registries)) |
3659 | 182 { |
183 return 0; | |
184 } | |
185 } | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
186 else assert (0); |
3659 | 187 |
188 CHECK_VECTOR (registries); | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
189 registries_len = XVECTOR_LENGTH (registries); |
3659 | 190 |
191 for (i = 0; i < registries_len; ++i) | |
192 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
193 if (!(STRINGP (XVECTOR_DATA (registries)[i])) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
194 || (XSTRING_LENGTH (XVECTOR_DATA (registries)[i]) > the_length)) |
3659 | 195 { |
196 continue; | |
197 } | |
198 | |
199 /* Check if the font spec ends in the registry specified. X11 says | |
200 this comparison is case insensitive: XLFD, section 3.11: | |
201 | |
202 "Alphabetic case distinctions are allowed but are for human | |
203 readability concerns only. Conforming X servers will perform | |
204 matching on font name query or open requests independent of case." */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
205 if (0 == qxestrcasecmp (XSTRING_DATA (XVECTOR_DATA (registries)[i]), |
3659 | 206 the_nonreloc + (the_length - |
207 XSTRING_LENGTH | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
208 (XVECTOR_DATA (registries)[i])))) |
3659 | 209 { |
210 return 1; | |
211 } | |
212 } | |
213 return 0; | |
214 } | |
215 | |
216 static Lisp_Object | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
217 xlistfonts_checking_charset (Lisp_Object device, const Ibyte *xlfd, |
3659 | 218 Lisp_Object charset, |
219 enum font_specifier_matchspec_stages stage) | |
220 { | |
221 Extbyte **names; | |
222 Lisp_Object result = Qnil; | |
223 int count = 0, i; | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
224 DECLARE_EISTRING (ei_single_result); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
225 Extbyte *fontext; |
3659 | 226 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
227 DEBUG_FONTS2 ("xlistfonts_checking_charset called, XLFD %s stage %s", |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
228 xlfd, stage == STAGE_INITIAL ? "initial" : "final"); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
229 DEBUG_FONTS_LISP1 (" charset %s\n", charset); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
230 fontext = ITEXT_TO_EXTERNAL (xlfd, Qx_font_name_encoding); |
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
231 names = XListFonts (GET_XLIKE_DISPLAY (XDEVICE (device)), |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
232 fontext, MAX_FONT_COUNT, &count); |
3659 | 233 |
234 for (i = 0; i < count; ++i) | |
235 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
236 eireset (ei_single_result); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
237 eicpy_ext (ei_single_result, names[i], Qx_font_name_encoding); |
3659 | 238 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
239 if (DEVMETH_OR_GIVEN (XDEVICE (device), font_spec_matches_charset, |
3659 | 240 (XDEVICE (device), charset, |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
241 eidata (ei_single_result), Qnil, 0, |
3659 | 242 -1, stage), 0)) |
243 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
244 result = eimake_string (ei_single_result); |
3659 | 245 break; |
246 } | |
247 } | |
248 | |
249 if (names) | |
250 { | |
251 XFreeFontNames (names); | |
252 } | |
253 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
254 DEBUG_FONTS_LISP1 ("xlistfonts_checking_charset returns %s\n", result); |
3659 | 255 return result; |
256 } | |
257 | |
258 #ifdef USE_XFT | |
259 /* #### debug functions: find a better place for us */ | |
260 const char *FcResultToString (FcResult r); | |
261 const char * | |
262 FcResultToString (FcResult r) | |
263 { | |
264 static char buffer[256]; | |
265 switch (r) | |
266 { | |
267 case FcResultMatch: | |
268 return "FcResultMatch"; | |
269 case FcResultNoMatch: | |
270 return "FcResultNoMatch"; | |
271 case FcResultTypeMismatch: | |
272 return "FcResultTypeMismatch"; | |
273 case FcResultNoId: | |
274 return "FcResultNoId"; | |
275 default: | |
276 snprintf (buffer, 255, "FcResultUndocumentedValue (%d)", r); | |
277 return buffer; | |
278 } | |
279 } | |
280 | |
281 const char *FcTypeOfValueToString (FcValue v); | |
282 const char * | |
283 FcTypeOfValueToString (FcValue v) | |
284 { | |
285 static char buffer[256]; | |
286 switch (v.type) | |
287 { | |
288 case FcTypeMatrix: | |
289 return "FcTypeMatrix"; | |
290 case FcTypeString: | |
291 return "FcTypeString"; | |
292 case FcTypeVoid: | |
293 return "FcTypeVoid"; | |
294 case FcTypeDouble: | |
295 return "FcTypeDouble"; | |
296 case FcTypeInteger: | |
297 return "FcTypeInteger"; | |
298 case FcTypeBool: | |
299 return "FcTypeBool"; | |
300 case FcTypeCharSet: | |
301 return "FcTypeCharSet"; | |
302 case FcTypeLangSet: | |
303 return "FcTypeLangSet"; | |
304 /* #### There is no union member of this type, but there are void* and | |
305 FcPattern* members, as of fontconfig.h FC_VERSION 10002 */ | |
306 case FcTypeFTFace: | |
307 return "FcTypeFTFace"; | |
308 default: | |
309 snprintf (buffer, 255, "FcTypeUndocumentedType (%d)", v.type); | |
310 return buffer; | |
311 } | |
312 } | |
313 | |
314 static FcCharSet * | |
315 mule_to_fc_charset (Lisp_Object cs) | |
316 { | |
317 int ucode, i, j; | |
318 FcCharSet *fccs; | |
319 | |
320 CHECK_CHARSET (cs); | |
321 fccs = FcCharSetCreate (); | |
322 /* #### do we also need to deal with 94 vs. 96 charsets? | |
323 ie, how are SP and DEL treated in ASCII? non-graphic should return -1 */ | |
324 if (1 == XCHARSET_DIMENSION (cs)) | |
325 /* Unicode tables are indexed by offsets from ASCII SP, not by ASCII */ | |
326 for (i = 0; i < 96; i++) | |
327 { | |
328 ucode = ((int *) XCHARSET_TO_UNICODE_TABLE (cs))[i]; | |
329 if (ucode >= 0) | |
330 /* #### should check for allocation failure */ | |
331 FcCharSetAddChar (fccs, (FcChar32) ucode); | |
332 } | |
333 else if (2 == XCHARSET_DIMENSION (cs)) | |
334 /* Unicode tables are indexed by offsets from ASCII SP, not by ASCII */ | |
335 for (i = 0; i < 96; i++) | |
336 for (j = 0; j < 96; j++) | |
337 { | |
338 ucode = ((int **) XCHARSET_TO_UNICODE_TABLE (cs))[i][j]; | |
339 if (ucode >= 0) | |
340 /* #### should check for allocation failure */ | |
341 FcCharSetAddChar (fccs, (FcChar32) ucode); | |
342 } | |
343 else | |
344 { | |
345 FcCharSetDestroy (fccs); | |
346 fccs = NULL; | |
347 } | |
348 return fccs; | |
349 } | |
350 | |
351 struct charset_reporter { | |
352 Lisp_Object *charset; | |
353 /* This is a debug facility, require ASCII. */ | |
4932 | 354 const Ascbyte *language; /* ASCII, please */ |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
355 /* Technically this is FcChar8, but fsckin' GCC 4 bitches. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
356 RFC 3066 is a combination of ISO 639 and ISO 3166. */ |
4932 | 357 const Ascbyte *rfc3066; /* ASCII, please */ |
3659 | 358 }; |
359 | |
360 static struct charset_reporter charset_table[] = | |
361 { | |
362 /* #### It's my branch, my favorite charsets get checked first! | |
363 That's a joke, Son. | |
364 Ie, I don't know what I'm doing, so my charsets first is as good as | |
365 any other arbitrary order. If you have a better idea, speak up! */ | |
366 { &Vcharset_ascii, "English", "en" }, | |
367 { &Vcharset_japanese_jisx0208, "Japanese", "ja" }, | |
368 { &Vcharset_japanese_jisx0212, "Japanese", "ja" }, | |
369 { &Vcharset_katakana_jisx0201, "Japanese", "ja" }, | |
370 { &Vcharset_latin_jisx0201, "Japanese", "ja" }, | |
371 { &Vcharset_japanese_jisx0208_1978, "Japanese", "ja" }, | |
372 { &Vcharset_greek_iso8859_7, "Greek", "el" }, | |
373 /* #### all the Chinese need checking | |
374 Damn the blood-sucking ISO anyway. */ | |
4756
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
375 { &Vcharset_chinese_gb2312, "simplified Chinese", "zh-cn" }, |
3659 | 376 { &Vcharset_korean_ksc5601, "Korean", "ko" }, |
4756
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
377 { &Vcharset_chinese_cns11643_1, "traditional Chinese", "zh-tw" }, |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
378 { &Vcharset_chinese_cns11643_2, "traditional Chinese", "zh-tw" }, |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
379 /* #### not obvious how to handle these |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
380 We could (for experimental purposes) make the last element into |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
381 an array of ISO 639 codes, and check for all of them. If a font |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
382 provides some but not others, warn. */ |
3659 | 383 { &Vcharset_latin_iso8859_1, NULL, NULL }, |
384 { &Vcharset_latin_iso8859_2, NULL, NULL }, | |
385 { &Vcharset_latin_iso8859_3, NULL, NULL }, | |
386 { &Vcharset_latin_iso8859_4, NULL, NULL }, | |
387 { &Vcharset_latin_iso8859_9, NULL, NULL }, | |
388 { &Vcharset_latin_iso8859_15, NULL, NULL }, | |
4756
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
389 { &Vcharset_thai_tis620, "Thai", "th" }, |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
390 /* We don't have an arabic charset. bidi issues, I guess? */ |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
391 /* { &Vcharset_arabic_iso8859_6, "Arabic", "ar" }, */ |
3659 | 392 { &Vcharset_hebrew_iso8859_8, "Hebrew", "he" }, |
4756
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
393 /* #### probably close enough for Ukraine? */ |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
394 { &Vcharset_cyrillic_iso8859_5, "Russian", "ru" }, |
3659 | 395 /* #### these probably are not quite right */ |
4756
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
396 { &Vcharset_chinese_big5_1, "traditional Chinese", "zh-tw" }, |
5d67242595a8
Update charset_table used by Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4494
diff
changeset
|
397 { &Vcharset_chinese_big5_2, "traditional Chinese", "zh-tw" }, |
3659 | 398 { NULL, NULL, NULL } |
399 }; | |
400 | |
401 /* Choose appropriate font name for debug messages. | |
402 Use only in the top half of next function (enforced with #undef). */ | |
403 #define DECLARE_DEBUG_FONTNAME(__xemacs_name) \ | |
404 Eistring *__xemacs_name; \ | |
405 do \ | |
406 { \ | |
407 __xemacs_name = debug_xft > 2 ? eistr_fullname \ | |
408 : debug_xft > 1 ? eistr_longname \ | |
409 : eistr_shortname; \ | |
410 } while (0) | |
411 | |
412 static Lisp_Object | |
413 xft_find_charset_font (Lisp_Object font, Lisp_Object charset, | |
414 enum font_specifier_matchspec_stages stage) | |
415 { | |
416 const Extbyte *patternext; | |
417 Lisp_Object result = Qnil; | |
418 | |
419 /* #### with Xft need to handle second stage here -- sjt | |
420 Hm. Or maybe not. That would be cool. :-) */ | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
421 if (stage == STAGE_FINAL) |
3659 | 422 return Qnil; |
423 | |
424 /* Fontconfig converts all FreeType names to UTF-8 before passing them | |
425 back to callers---see fcfreetype.c (FcFreeTypeQuery). | |
426 I don't believe this is documented. */ | |
427 | |
428 DEBUG_XFT1 (1, "confirming charset for font instance %s\n", | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
429 XSTRING_DATA (font)); |
3659 | 430 |
431 /* #### this looks like a fair amount of work, but the basic design | |
432 has never been rethought, and it should be | |
433 | |
434 what really should happen here is that we use FcFontSort (FcFontList?) | |
435 to get a list of matching fonts, then pick the first (best) one that | |
436 gives language or repertoire coverage. | |
437 */ | |
438 | |
439 FcInit (); /* No-op if already initialized. | |
440 In fontconfig 2.3.2, this cannot return | |
441 failure, but that looks like a bug. We | |
442 check for it with FcGetCurrentConfig(), | |
443 which *can* fail. */ | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
444 if (!FcConfigGetCurrent()) |
3659 | 445 stderr_out ("Failed fontconfig initialization\n"); |
446 else | |
447 { | |
448 FcPattern *fontxft; /* long-lived, freed at end of this block */ | |
449 FcResult fcresult; | |
450 FcConfig *fcc; | |
4932 | 451 const Ascbyte *lang = "en"; |
3659 | 452 FcCharSet *fccs = NULL; |
453 DECLARE_EISTRING (eistr_shortname); /* user-friendly nickname */ | |
454 DECLARE_EISTRING (eistr_longname); /* omit FC_LANG and FC_CHARSET */ | |
455 DECLARE_EISTRING (eistr_fullname); /* everything */ | |
456 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
457 patternext = LISP_STRING_TO_EXTERNAL (font, Qfc_font_name_encoding); |
3659 | 458 fcc = FcConfigGetCurrent (); |
459 | |
460 /* parse the name, do the substitutions, and match the font */ | |
461 | |
462 { | |
463 FcPattern *p = FcNameParse ((FcChar8 *) patternext); | |
464 PRINT_XFT_PATTERN (3, "FcNameParse'ed name is %s\n", p); | |
465 /* #### Next two return FcBool, but what does the return mean? */ | |
466 /* The order is correct according the fontconfig docs. */ | |
467 FcConfigSubstitute (fcc, p, FcMatchPattern); | |
468 PRINT_XFT_PATTERN (2, "FcConfigSubstitute'ed name is %s\n", p); | |
469 FcDefaultSubstitute (p); | |
470 PRINT_XFT_PATTERN (3, "FcDefaultSubstitute'ed name is %s\n", p); | |
471 /* #### check fcresult of following match? */ | |
4809
0d3ccd5a2509
Initialize the result variable passed to FcFontMatch. See xemacs-patches
Jerry James <james@xemacs.org>
parents:
4758
diff
changeset
|
472 fcresult = FcResultMatch; |
3659 | 473 fontxft = FcFontMatch (fcc, p, &fcresult); |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
474 switch (fcresult) |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
475 { |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
476 /* case FcResultOutOfMemory: */ |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
477 case FcResultNoMatch: |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
478 case FcResultTypeMismatch: |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
479 case FcResultNoId: |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
480 break; |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
481 case FcResultMatch: |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
482 /* this prints the long fontconfig name */ |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
483 PRINT_XFT_PATTERN (1, "FcFontMatch'ed name is %s\n", fontxft); |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
484 break; |
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
485 } |
3659 | 486 FcPatternDestroy (p); |
487 } | |
488 | |
489 /* heuristic to give reasonable-length names for debug reports | |
490 | |
491 I considered #ifdef SUPPORT_FULL_FONTCONFIG_NAME etc but that's | |
492 pointless. We're just going to remove this code once the font/ | |
493 face refactoring is done, but until then it could be very useful. | |
494 */ | |
495 { | |
496 FcPattern *p = FcFontRenderPrepare (fcc, fontxft, fontxft); | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
497 Extbyte *name; |
3659 | 498 |
499 /* full name, including language coverage and repertoire */ | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
500 name = (Extbyte *) FcNameUnparse (p); |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
501 eicpy_ext (eistr_fullname, |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
502 (name ? name : "NOT FOUND"), |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
503 Qfc_font_name_encoding); |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
504 if (name) free (name); |
3659 | 505 |
506 /* long name, omitting coverage and repertoire, plus a number | |
507 of rarely useful properties */ | |
508 FcPatternDel (p, FC_CHARSET); | |
509 FcPatternDel (p, FC_LANG); | |
3841 | 510 #ifdef FC_WIDTH |
3659 | 511 FcPatternDel (p, FC_WIDTH); |
3841 | 512 #endif |
3659 | 513 FcPatternDel (p, FC_SPACING); |
514 FcPatternDel (p, FC_HINTING); | |
515 FcPatternDel (p, FC_VERTICAL_LAYOUT); | |
516 FcPatternDel (p, FC_AUTOHINT); | |
517 FcPatternDel (p, FC_GLOBAL_ADVANCE); | |
518 FcPatternDel (p, FC_INDEX); | |
519 FcPatternDel (p, FC_SCALE); | |
520 FcPatternDel (p, FC_FONTVERSION); | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
521 name = (Extbyte *) FcNameUnparse (p); |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
522 eicpy_ext (eistr_longname, |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
523 (name ? name : "NOT FOUND"), |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
524 Qfc_font_name_encoding); |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
525 if (name) free (name); |
3659 | 526 |
527 /* nickname, just family and size, but | |
528 "family" names usually have style, slant, and weight */ | |
529 FcPatternDel (p, FC_FOUNDRY); | |
530 FcPatternDel (p, FC_STYLE); | |
531 FcPatternDel (p, FC_SLANT); | |
532 FcPatternDel (p, FC_WEIGHT); | |
533 FcPatternDel (p, FC_PIXEL_SIZE); | |
534 FcPatternDel (p, FC_OUTLINE); | |
535 FcPatternDel (p, FC_SCALABLE); | |
536 FcPatternDel (p, FC_DPI); | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
537 name = (Extbyte *) FcNameUnparse (p); |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
538 eicpy_ext (eistr_shortname, |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
539 (name ? name : "NOT FOUND"), |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4756
diff
changeset
|
540 Qfc_font_name_encoding); |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
541 if (name) free (name); |
3659 | 542 |
543 FcPatternDestroy (p); | |
544 } | |
545 | |
546 /* The language approach may better in the long run, but we can't use | |
547 it based on Mule charsets; fontconfig doesn't provide a way to test | |
548 for unions of languages, etc. That will require support from the | |
549 text module. | |
550 | |
551 Optimization: cache the generated FcCharSet in the Mule charset. | |
552 Don't forget to destroy it if the Mule charset gets deallocated. */ | |
553 | |
554 { | |
555 /* This block possibly should be a function, but it generates | |
556 multiple values. I find the "pass an address to return the | |
557 value in" idiom opaque, so prefer a block. */ | |
558 struct charset_reporter *cr; | |
559 for (cr = charset_table; | |
560 cr->charset && !EQ (*(cr->charset), charset); | |
561 cr++) | |
562 ; | |
563 | |
564 if (cr->rfc3066) | |
565 { | |
566 DECLARE_DEBUG_FONTNAME (name); | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
567 CHECKING_LANG (0, eidata (name), cr->language); |
4932 | 568 lang = cr->rfc3066; |
3659 | 569 } |
570 else if (cr->charset) | |
571 { | |
572 /* what the hey, build 'em on the fly */ | |
573 /* #### in the case of error this could return NULL! */ | |
574 fccs = mule_to_fc_charset (charset); | |
4932 | 575 /* #### Bad idea here */ |
576 lang = (const Ascbyte *) XSTRING_DATA (XSYMBOL (XCHARSET_NAME | |
577 (charset))->name); | |
3659 | 578 } |
579 else | |
580 { | |
581 /* OK, we fell off the end of the table */ | |
582 warn_when_safe_lispobj (intern ("xft"), intern ("alert"), | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4932
diff
changeset
|
583 list2 (build_ascstring ("unchecked charset"), |
3659 | 584 charset)); |
585 /* default to "en" | |
586 #### THIS IS WRONG, WRONG, WRONG!! | |
587 It is why we never fall through to XLFD-checking. */ | |
588 } | |
589 | |
4932 | 590 ASSERT_ASCTEXT_ASCII (lang); |
3659 | 591 |
592 if (fccs) | |
593 { | |
594 /* check for character set coverage */ | |
595 int i = 0; | |
596 FcCharSet *v; | |
597 FcResult r = FcPatternGetCharSet (fontxft, FC_CHARSET, i, &v); | |
598 | |
599 if (r == FcResultTypeMismatch) | |
600 { | |
601 DEBUG_XFT0 (0, "Unexpected type return in charset value\n"); | |
602 result = Qnil; | |
603 } | |
604 else if (r == FcResultMatch && FcCharSetIsSubset (fccs, v)) | |
605 { | |
606 /* The full pattern with the bitmap coverage is massively | |
607 unwieldy, but the shorter names are just *wrong*. We | |
608 should have the full thing internally as truename, and | |
609 filter stuff the client doesn't want to see on output. | |
610 Should we just store it into the truename right here? */ | |
611 DECLARE_DEBUG_FONTNAME (name); | |
612 DEBUG_XFT2 (0, "Xft font %s supports %s\n", | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
613 eidata (name), lang); |
3659 | 614 #ifdef RETURN_LONG_FONTCONFIG_NAMES |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
615 result = eimake_string (eistr_fullname); |
3659 | 616 #else |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
617 result = eimake_string (eistr_longname); |
3659 | 618 #endif |
619 } | |
620 else | |
621 { | |
622 DECLARE_DEBUG_FONTNAME (name); | |
623 DEBUG_XFT2 (0, "Xft font %s doesn't support %s\n", | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
624 eidata (name), lang); |
3659 | 625 result = Qnil; |
626 } | |
627 | |
628 /* clean up */ | |
629 FcCharSetDestroy (fccs); | |
630 } | |
631 else | |
632 { | |
633 /* check for language coverage */ | |
634 int i = 0; | |
635 FcValue v; | |
636 /* the main event */ | |
637 FcResult r = FcPatternGet (fontxft, FC_LANG, i, &v); | |
638 | |
639 if (r == FcResultMatch) | |
640 { | |
641 if (v.type != FcTypeLangSet) /* excessive paranoia */ | |
642 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
643 ASSERT_ASCTEXT_ASCII (FcTypeOfValueToString (v)); |
3659 | 644 /* Urk! Fall back and punt to core font. */ |
645 DEBUG_XFT1 (0, "Unexpected type of lang value (%s)\n", | |
646 FcTypeOfValueToString (v)); | |
647 result = Qnil; | |
648 } | |
4932 | 649 else if (FcLangSetHasLang (v.u.l, (FcChar8 *) lang) |
650 != FcLangDifferentLang) | |
3659 | 651 { |
652 DECLARE_DEBUG_FONTNAME (name); | |
653 DEBUG_XFT2 (0, "Xft font %s supports %s\n", | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
654 eidata (name), lang); |
3659 | 655 #ifdef RETURN_LONG_FONTCONFIG_NAMES |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
656 result = eimake_string (eistr_fullname); |
3659 | 657 #else |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
658 result = eimake_string (eistr_longname); |
3659 | 659 #endif |
660 } | |
661 else | |
662 { | |
663 DECLARE_DEBUG_FONTNAME (name); | |
664 DEBUG_XFT2 (0, "Xft font %s doesn't support %s\n", | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
665 eidata (name), lang); |
3659 | 666 result = Qnil; |
667 } | |
668 } | |
669 else | |
670 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
671 ASSERT_ASCTEXT_ASCII (FcResultToString (r)); |
3659 | 672 DEBUG_XFT1 (0, "Getting lang: unexpected result=%s\n", |
673 FcResultToString (r)); | |
674 result = Qnil; | |
675 } | |
676 } | |
677 | |
678 /* clean up and maybe return */ | |
679 FcPatternDestroy (fontxft); | |
680 if (!UNBOUNDP (result)) | |
681 return result; | |
682 } | |
683 } | |
684 return Qnil; | |
685 } | |
686 #undef DECLARE_DEBUG_FONTNAME | |
687 | |
688 #endif /* USE_XFT */ | |
689 | |
690 /* find a font spec that matches font spec FONT and also matches | |
691 (the registry of) CHARSET. */ | |
692 static Lisp_Object | |
4908
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
693 XFUN (find_charset_font) (Lisp_Object device, Lisp_Object font, |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
694 Lisp_Object charset, |
b3ce27ca7647
various fixes related to gtk, redisplay-xlike-inc.c
Ben Wing <ben@xemacs.org>
parents:
4809
diff
changeset
|
695 enum font_specifier_matchspec_stages stage) |
3659 | 696 { |
697 Lisp_Object result = Qnil, registries = Qnil; | |
698 int j, hyphen_count, registries_len = 0; | |
699 Ibyte *hyphening, *new_hyphening; | |
700 Bytecount xlfd_length; | |
701 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
702 DECLARE_EISTRING (ei_xlfd_without_registry); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
703 DECLARE_EISTRING (ei_xlfd); |
3659 | 704 |
705 #ifdef USE_XFT | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
706 result = xft_find_charset_font (font, charset, stage); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
707 if (!NILP (result)) |
3659 | 708 { |
709 return result; | |
710 } | |
711 #endif | |
712 | |
713 switch (stage) | |
714 { | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
715 case STAGE_INITIAL: |
3659 | 716 { |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
717 if (!(NILP (XCHARSET_REGISTRIES (charset))) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
718 && VECTORP (XCHARSET_REGISTRIES (charset))) |
3659 | 719 { |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
720 registries_len = XVECTOR_LENGTH (XCHARSET_REGISTRIES (charset)); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
721 registries = XCHARSET_REGISTRIES (charset); |
3659 | 722 } |
723 break; | |
724 } | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
725 case STAGE_FINAL: |
3659 | 726 { |
727 registries_len = 1; | |
728 registries = Qunicode_registries; | |
729 break; | |
730 } | |
731 default: | |
732 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
733 assert (0); |
3659 | 734 break; |
735 } | |
736 } | |
737 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
738 eicpy_lstr (ei_xlfd, font); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
739 hyphening = eidata (ei_xlfd); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
740 xlfd_length = eilen (ei_xlfd); |
3659 | 741 |
742 /* Count the hyphens in the string, moving new_hyphening to just after the | |
743 last one. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
744 hyphen_count = count_hyphens (hyphening, xlfd_length, &new_hyphening); |
3659 | 745 |
746 if (0 == registries_len || (5 > hyphen_count && | |
747 !(1 == xlfd_length && '*' == *hyphening))) | |
748 { | |
749 /* No proper XLFD specified, or we can't modify the pattern to change | |
750 the registry and encoding to match what we want, or we have no | |
751 information on the registry needed. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
752 result = xlistfonts_checking_charset (device, eidata (ei_xlfd), |
3659 | 753 charset, stage); |
754 /* No need to loop through the available registries; return | |
755 immediately. */ | |
756 return result; | |
757 } | |
758 else if (1 == xlfd_length && '*' == *hyphening) | |
759 { | |
760 /* It's a single asterisk. We can add the registry directly to the | |
761 end. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
762 eicpy_ch (ei_xlfd_without_registry, '*'); |
3659 | 763 } |
764 else | |
765 { | |
766 /* It's a fully-specified XLFD. Work out where the registry and | |
767 encoding are, and initialise ei_xlfd_without_registry to the string | |
768 without them. */ | |
769 | |
770 /* count_hyphens has set new_hyphening to just after the last | |
771 hyphen. Move back to just after the hyphen before it. */ | |
772 | |
773 for (new_hyphening -= 2; new_hyphening > hyphening | |
774 && '-' != *new_hyphening; --new_hyphening) | |
775 ; | |
776 ++new_hyphening; | |
777 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
778 eicpy_ei (ei_xlfd_without_registry, ei_xlfd); |
3659 | 779 |
780 /* Manipulate ei_xlfd_without_registry, using the information about | |
781 ei_xlfd, to which it's identical. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
782 eidel (ei_xlfd_without_registry, new_hyphening - hyphening, -1, |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
783 eilen (ei_xlfd) - (new_hyphening - hyphening), -1); |
3659 | 784 |
785 } | |
786 | |
787 /* Now, loop through the registries and encodings defined for this | |
788 charset, doing an XListFonts each time with the pattern modified to | |
789 specify the regisry and encoding. This avoids huge amounts of IPC and | |
790 duplicated searching; now we use the searching the X server was doing | |
791 anyway, where before the X server did its search, transferred huge | |
792 amounts of data, and then we proceeded to do a regexp search on that | |
793 data. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
794 for (j = 0; j < registries_len && NILP (result); ++j) |
3659 | 795 { |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
796 eireset (ei_xlfd); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
797 eicpy_ei (ei_xlfd, ei_xlfd_without_registry); |
3659 | 798 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
799 eicat_lstr (ei_xlfd, XVECTOR_DATA (registries)[j]); |
3659 | 800 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
801 result = xlistfonts_checking_charset (device, eidata (ei_xlfd), |
3659 | 802 charset, stage); |
803 } | |
804 | |
3676 | 805 /* In the event that the charset is ASCII and we haven't matched |
806 anything up to now, even with a pattern of "*", add "iso8859-1" | |
807 to the charset's registry and try again. Not returning a result | |
808 for ASCII means our frame geometry calculations are | |
809 inconsistent, and that we may crash. */ | |
810 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
811 if (1 == xlfd_length && EQ (charset, Vcharset_ascii) && NILP (result) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
812 && ('*' == eigetch (ei_xlfd_without_registry, 0))) |
3676 | 813 |
814 { | |
815 int have_latin1 = 0; | |
816 | |
817 /* Set this to, for example, is08859-1 if you want to see the | |
818 error behaviour. */ | |
819 | |
820 #define FALLBACK_ASCII_REGISTRY "iso8859-1" | |
821 | |
822 for (j = 0; j < registries_len; ++j) | |
823 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
824 if (0 == qxestrcasecmp (XSTRING_DATA (XVECTOR_DATA (registries)[j]), |
4124 | 825 (Ibyte *) FALLBACK_ASCII_REGISTRY)) |
3676 | 826 { |
827 have_latin1 = 1; | |
828 break; | |
829 } | |
830 } | |
831 | |
832 if (!have_latin1) | |
833 { | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
834 Lisp_Object new_registries = make_vector (registries_len + 1, Qnil); |
3676 | 835 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
836 XVECTOR_DATA (new_registries)[0] |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
837 = build_ascstring (FALLBACK_ASCII_REGISTRY); |
3676 | 838 |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
839 memcpy (XVECTOR_DATA (new_registries) + 1, |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
840 XVECTOR_DATA (registries), |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
841 sizeof XVECTOR_DATA (registries)[0] * |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
842 XVECTOR_LENGTH (registries)); |
3676 | 843 |
844 /* Calling set_charset_registries instead of overwriting the | |
845 value directly, to allow the charset font caches to be | |
846 invalidated and a change to the default face to be | |
847 noted. */ | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
848 set_charset_registries (charset, new_registries); |
3676 | 849 |
3680 | 850 warn_when_safe (Qface, Qwarning, |
851 "Your ASCII charset registries contain nothing " | |
852 "sensible. Adding `" FALLBACK_ASCII_REGISTRY "'."); | |
853 | |
3676 | 854 /* And recurse. */ |
855 result = | |
856 DEVMETH_OR_GIVEN (XDEVICE (device), find_charset_font, | |
857 (device, font, charset, stage), | |
858 result); | |
859 } | |
860 else | |
861 { | |
862 DECLARE_EISTRING (ei_connection_name); | |
863 | |
864 /* We preserve a copy of the connection name for the error message | |
865 after the device is deleted. */ | |
866 eicpy_lstr (ei_connection_name, | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5176
diff
changeset
|
867 DEVICE_CONNECTION (XDEVICE (device))); |
3676 | 868 |
869 stderr_out ("Cannot find a font for ASCII, deleting device on %s\n", | |
870 eidata (ei_connection_name)); | |
871 | |
872 io_error_delete_device (device); | |
873 | |
874 /* Do a normal warning in the event that we have other, non-X | |
875 frames available. (If we don't, io_error_delete_device will | |
876 have exited.) */ | |
877 warn_when_safe | |
878 (Qface, Qerror, | |
879 "Cannot find a font for ASCII, deleting device on %s.\n" | |
880 "\n" | |
881 "Your X server fonts appear to be inconsistent; fix them, or\n" | |
882 "the next frame you create on that DISPLAY will crash this\n" | |
883 "XEmacs. At a minimum, provide one font with an XLFD ending\n" | |
884 "in `" FALLBACK_ASCII_REGISTRY "', so we can work out what size\n" | |
885 "a frame should be. ", | |
886 eidata (ei_connection_name)); | |
887 } | |
888 | |
889 } | |
890 | |
3659 | 891 /* This function used to return the font spec, in the case where a font |
892 didn't exist on the X server but it did match the charset. We're not | |
893 doing that any more, because none of the other platform code does, and | |
894 the old behaviour was badly-judged in other respects, so I don't trust | |
895 the original author to have had a good reason for it. */ | |
896 | |
897 return result; | |
898 } | |
899 | |
900 #endif /* MULE */ |