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