Mercurial > emacs
annotate src/xfont.c @ 91165:3f9bb85be0a4
(x-complement-fontset-spec): Use
font-spec.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 03 Dec 2007 13:42:35 +0000 |
parents | 4bcf0716ddf4 |
children | ca4dcecf8f88 |
rev | line source |
---|---|
90400 | 1 /* xfont.c -- X core font driver. |
2 Copyright (C) 2006 Free Software Foundation, Inc. | |
3 Copyright (C) 2006 | |
4 National Institute of Advanced Industrial Science and Technology (AIST) | |
5 Registration Number H13PRO009 | |
6 | |
7 This file is part of GNU Emacs. | |
8 | |
9 GNU Emacs is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2, or (at your option) | |
12 any later version. | |
13 | |
14 GNU Emacs is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with GNU Emacs; see the file COPYING. If not, write to | |
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 Boston, MA 02110-1301, USA. */ | |
23 | |
24 #include <config.h> | |
25 #include <stdio.h> | |
26 #include <X11/Xlib.h> | |
27 | |
28 #include "lisp.h" | |
29 #include "dispextern.h" | |
30 #include "xterm.h" | |
31 #include "frame.h" | |
32 #include "blockinput.h" | |
33 #include "character.h" | |
34 #include "charset.h" | |
35 #include "fontset.h" | |
36 #include "font.h" | |
37 | |
38 | |
39 /* X core font driver. */ | |
40 | |
41 Lisp_Object Qx; | |
42 | |
43 /* Prototypes of support functions. */ | |
44 extern void x_clear_errors P_ ((Display *)); | |
45 | |
46 static char *xfont_query_font P_ ((Display *, char *, Lisp_Object)); | |
47 static XCharStruct *xfont_get_pcm P_ ((XFontStruct *, XChar2b *)); | |
48 static int xfont_registry_charsets P_ ((Lisp_Object, struct charset **, | |
49 struct charset **)); | |
50 | |
51 static char * | |
52 xfont_query_font (display, name, spec) | |
53 Display *display; | |
54 char *name; | |
55 Lisp_Object spec; | |
56 { | |
57 XFontStruct *font; | |
58 | |
59 BLOCK_INPUT; | |
60 x_catch_errors (display); | |
61 font = XLoadQueryFont (display, name); | |
62 name = NULL; | |
63 if (x_had_errors_p (display)) | |
64 { | |
65 /* This error is perhaps due to insufficient memory on X | |
66 server. Let's just ignore it. */ | |
67 x_clear_errors (display); | |
68 } | |
69 else if (font) | |
70 { | |
71 unsigned long value; | |
72 | |
73 if (XGetFontProperty (font, XA_FONT, &value)) | |
74 { | |
75 char *n = (char *) XGetAtomName (display, (Atom) value); | |
76 | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
77 if (font_parse_xlfd (n, spec) >= 0) |
90400 | 78 name = n; |
79 else | |
80 XFree (n); | |
81 } | |
82 XFreeFont (display, font); | |
83 } | |
84 x_uncatch_errors (); | |
85 UNBLOCK_INPUT; | |
86 | |
87 return name; | |
88 } | |
89 | |
90 | |
91 /* Get metrics of character CHAR2B in XFONT. Value is null if CHAR2B | |
92 is not contained in the font. */ | |
93 | |
94 static XCharStruct * | |
95 xfont_get_pcm (xfont, char2b) | |
96 XFontStruct *xfont; | |
97 XChar2b *char2b; | |
98 { | |
99 /* The result metric information. */ | |
100 XCharStruct *pcm = NULL; | |
101 | |
102 xassert (xfont && char2b); | |
103 | |
104 if (xfont->per_char != NULL) | |
105 { | |
106 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0) | |
107 { | |
108 /* min_char_or_byte2 specifies the linear character index | |
109 corresponding to the first element of the per_char array, | |
110 max_char_or_byte2 is the index of the last character. A | |
111 character with non-zero CHAR2B->byte1 is not in the font. | |
112 A character with byte2 less than min_char_or_byte2 or | |
113 greater max_char_or_byte2 is not in the font. */ | |
114 if (char2b->byte1 == 0 | |
115 && char2b->byte2 >= xfont->min_char_or_byte2 | |
116 && char2b->byte2 <= xfont->max_char_or_byte2) | |
117 pcm = xfont->per_char + char2b->byte2 - xfont->min_char_or_byte2; | |
118 } | |
119 else | |
120 { | |
121 /* If either min_byte1 or max_byte1 are nonzero, both | |
122 min_char_or_byte2 and max_char_or_byte2 are less than | |
123 256, and the 2-byte character index values corresponding | |
124 to the per_char array element N (counting from 0) are: | |
125 | |
126 byte1 = N/D + min_byte1 | |
127 byte2 = N\D + min_char_or_byte2 | |
128 | |
129 where: | |
130 | |
131 D = max_char_or_byte2 - min_char_or_byte2 + 1 | |
132 / = integer division | |
133 \ = integer modulus */ | |
134 if (char2b->byte1 >= xfont->min_byte1 | |
135 && char2b->byte1 <= xfont->max_byte1 | |
136 && char2b->byte2 >= xfont->min_char_or_byte2 | |
137 && char2b->byte2 <= xfont->max_char_or_byte2) | |
138 pcm = (xfont->per_char | |
139 + ((xfont->max_char_or_byte2 - xfont->min_char_or_byte2 + 1) | |
140 * (char2b->byte1 - xfont->min_byte1)) | |
141 + (char2b->byte2 - xfont->min_char_or_byte2)); | |
142 } | |
143 } | |
144 else | |
145 { | |
146 /* If the per_char pointer is null, all glyphs between the first | |
147 and last character indexes inclusive have the same | |
148 information, as given by both min_bounds and max_bounds. */ | |
149 if (char2b->byte2 >= xfont->min_char_or_byte2 | |
150 && char2b->byte2 <= xfont->max_char_or_byte2) | |
151 pcm = &xfont->max_bounds; | |
152 } | |
153 | |
154 return ((pcm == NULL | |
155 || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)) | |
156 ? NULL : pcm); | |
157 } | |
158 | |
159 static Lisp_Object xfont_get_cache P_ ((Lisp_Object)); | |
160 static Lisp_Object xfont_list P_ ((Lisp_Object, Lisp_Object)); | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
161 static Lisp_Object xfont_match P_ ((Lisp_Object, Lisp_Object)); |
90400 | 162 static Lisp_Object xfont_list_family P_ ((Lisp_Object)); |
163 static struct font *xfont_open P_ ((FRAME_PTR, Lisp_Object, int)); | |
164 static void xfont_close P_ ((FRAME_PTR, struct font *)); | |
165 static int xfont_prepare_face P_ ((FRAME_PTR, struct face *)); | |
166 #if 0 | |
167 static void xfont_done_face P_ ((FRAME_PTR, struct face *)); | |
168 #endif | |
169 static int xfont_has_char P_ ((Lisp_Object, int)); | |
170 static unsigned xfont_encode_char P_ ((struct font *, int)); | |
171 static int xfont_text_extents P_ ((struct font *, unsigned *, int, | |
172 struct font_metrics *)); | |
173 static int xfont_draw P_ ((struct glyph_string *, int, int, int, int, int)); | |
174 | |
175 struct font_driver xfont_driver = | |
176 { | |
90698
a31984e21969
(xfont_driver): Initialize ftfont_driver.type by 0.
Kenichi Handa <handa@m17n.org>
parents:
90679
diff
changeset
|
177 0, /* Qx */ |
90400 | 178 xfont_get_cache, |
179 xfont_list, | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
180 xfont_match, |
90400 | 181 xfont_list_family, |
182 NULL, | |
183 xfont_open, | |
184 xfont_close, | |
185 xfont_prepare_face, | |
186 NULL /*xfont_done_face*/, | |
187 xfont_has_char, | |
188 xfont_encode_char, | |
189 xfont_text_extents, | |
190 xfont_draw, | |
191 }; | |
192 | |
193 extern Lisp_Object QCname; | |
194 | |
195 static Lisp_Object | |
196 xfont_get_cache (frame) | |
197 Lisp_Object frame; | |
198 { | |
199 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (frame)); | |
200 | |
201 return (dpyinfo->name_list_element); | |
202 } | |
203 | |
204 extern Lisp_Object Vface_alternative_font_registry_alist; | |
205 | |
206 static Lisp_Object | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
207 xfont_list_pattern (frame, display, pattern) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
208 Lisp_Object frame; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
209 Display *display; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
210 char *pattern; |
90400 | 211 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
212 Lisp_Object list = Qnil; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
213 int i, limit, num_fonts; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
214 char **names; |
90400 | 215 |
216 BLOCK_INPUT; | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
217 x_catch_errors (display); |
90400 | 218 |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
219 for (limit = 512; ; limit *= 2) |
90400 | 220 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
221 names = XListFonts (display, pattern, limit, &num_fonts); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
222 if (x_had_errors_p (display)) |
90400 | 223 { |
224 /* This error is perhaps due to insufficient memory on X | |
225 server. Let's just ignore it. */ | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
226 x_clear_errors (display); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
227 num_fonts = 0; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
228 break; |
90400 | 229 } |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
230 if (num_fonts < limit) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
231 break; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
232 XFreeFontNames (names); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
233 } |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
234 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
235 for (i = 0; i < num_fonts; i++) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
236 { |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
237 Lisp_Object entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
238 int result; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
239 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
240 ASET (entity, FONT_TYPE_INDEX, Qx); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
241 ASET (entity, FONT_FRAME_INDEX, frame); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
242 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
243 result = font_parse_xlfd (names[i], entity); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
244 if (result < 0) |
90400 | 245 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
246 /* This may be an alias name. Try to get the full XLFD name |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
247 from XA_FONT property of the font. */ |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
248 XFontStruct *font = XLoadQueryFont (display, names[i]); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
249 unsigned long value; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
250 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
251 if (! font) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
252 continue; |
90400 | 253 if (XGetFontProperty (font, XA_FONT, &value)) |
254 { | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
255 char *name = (char *) XGetAtomName (display, (Atom) value); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
256 int len = strlen (name); |
90400 | 257 |
258 /* If DXPC (a Differential X Protocol Compressor) | |
259 Ver.3.7 is running, XGetAtomName will return null | |
260 string. We must avoid such a name. */ | |
261 if (len > 0) | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
262 result = font_parse_xlfd (name, entity); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
263 XFree (name); |
90400 | 264 } |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
265 XFreeFont (display, font); |
90400 | 266 } |
267 | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
268 if (result == 0) |
90400 | 269 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
270 Lisp_Object val = AREF (entity, FONT_EXTRA_INDEX); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
271 char *p = (char *) SDATA (SYMBOL_NAME (val)); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
272 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
273 /* P == "RESX-RESY-SPACING-AVGWIDTH. We rejust this font if |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
274 it's an autoscaled one (i.e. RESX > 0 && AVGWIDTH == 0). */ |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
275 if (atoi (p) > 0) |
90400 | 276 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
277 p += SBYTES (SYMBOL_NAME (val)); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
278 while (p[-1] != '-') p--; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
279 if (atoi (p) == 0) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
280 continue; |
90400 | 281 } |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
282 list = Fcons (entity, list); |
90400 | 283 } |
284 } | |
285 | |
286 x_uncatch_errors (); | |
287 UNBLOCK_INPUT; | |
288 | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
289 return list; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
290 } |
90400 | 291 |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
292 static Lisp_Object |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
293 xfont_list (frame, spec) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
294 Lisp_Object frame, spec; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
295 { |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
296 FRAME_PTR f = XFRAME (frame); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
297 Display *display = FRAME_X_DISPLAY_INFO (f)->display; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
298 Lisp_Object list, val, extra, font_name; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
299 int len; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
300 char name[256]; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
301 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
302 extra = AREF (spec, FONT_EXTRA_INDEX); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
303 font_name = Qnil; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
304 if (CONSP (extra)) |
90400 | 305 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
306 val = assq_no_quit (QCotf, extra); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
307 if (! NILP (val)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
308 return null_vector; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
309 val = assq_no_quit (QCscript, extra); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
310 if (! NILP (val)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
311 return null_vector; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
312 val = assq_no_quit (QClanguage, extra); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
313 if (! NILP (val)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
314 return null_vector; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
315 val = assq_no_quit (QCname, extra); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
316 if (CONSP (val)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
317 font_name = XCDR (val); |
90400 | 318 } |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
319 |
90545
7536a4fa3a3b
(xfont_list): Don't try listing by :name property if the
Kenichi Handa <handa@m17n.org>
parents:
90501
diff
changeset
|
320 if (STRINGP (font_name) |
7536a4fa3a3b
(xfont_list): Don't try listing by :name property if the
Kenichi Handa <handa@m17n.org>
parents:
90501
diff
changeset
|
321 && ! strchr ((char *) SDATA (font_name), ':')) |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
322 list = xfont_list_pattern (frame, display, (char *) SDATA (font_name)); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
323 else if ((len = font_unparse_xlfd (spec, 0, name, 256)) < 0) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
324 return null_vector; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
325 else |
90400 | 326 { |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
327 list = xfont_list_pattern (frame, display, name); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
328 if (NILP (list)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
329 { |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
330 Lisp_Object registry = AREF (spec, FONT_REGISTRY_INDEX); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
331 Lisp_Object alter; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
332 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
333 if (! NILP (registry) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
334 && (alter = Fassoc (SYMBOL_NAME (registry), |
90698
a31984e21969
(xfont_driver): Initialize ftfont_driver.type by 0.
Kenichi Handa <handa@m17n.org>
parents:
90679
diff
changeset
|
335 Vface_alternative_font_registry_alist), |
a31984e21969
(xfont_driver): Initialize ftfont_driver.type by 0.
Kenichi Handa <handa@m17n.org>
parents:
90679
diff
changeset
|
336 CONSP (alter))) |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
337 { |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
338 /* Pointer to REGISTRY-ENCODING field. */ |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
339 char *r = name + len - SBYTES (SYMBOL_NAME (registry)); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
340 |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
341 for (alter = XCDR (alter); CONSP (alter); alter = XCDR (alter)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
342 if (STRINGP (XCAR (alter)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
343 && ((r - name) + SBYTES (XCAR (alter))) < 255) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
344 { |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
345 strcpy (r, (char *) SDATA (XCAR (alter))); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
346 list = xfont_list_pattern (frame, display, name); |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
347 if (! NILP (list)) |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
348 break; |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
349 } |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
350 } |
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
351 } |
90400 | 352 } |
353 | |
90501
2ef165ebcc7d
(xfont_query_font): Adjusted for the change of
Kenichi Handa <handa@m17n.org>
parents:
90461
diff
changeset
|
354 return (NILP (list) ? null_vector : Fvconcat (1, &list)); |
90400 | 355 } |
356 | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
357 static Lisp_Object |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
358 xfont_match (frame, spec) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
359 Lisp_Object frame, spec; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
360 { |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
361 FRAME_PTR f = XFRAME (frame); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
362 Display *display = FRAME_X_DISPLAY_INFO (f)->display; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
363 Lisp_Object extra, val, entity; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
364 char *name; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
365 XFontStruct *xfont; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
366 unsigned long value; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
367 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
368 extra = AREF (spec, FONT_EXTRA_INDEX); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
369 val = assq_no_quit (QCname, extra); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
370 if (! CONSP (val) || ! STRINGP (XCDR (val))) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
371 return Qnil; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
372 |
90569
0af2dbdeaeb3
(xfont_match): Block and unblock input while callin Xlib.
Kenichi Handa <handa@m17n.org>
parents:
90561
diff
changeset
|
373 BLOCK_INPUT; |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
374 entity = Qnil; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
375 name = (char *) SDATA (XCDR (val)); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
376 xfont = XLoadQueryFont (display, name); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
377 if (xfont) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
378 { |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
379 if (XGetFontProperty (xfont, XA_FONT, &value)) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
380 { |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
381 int len; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
382 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
383 name = (char *) XGetAtomName (display, (Atom) value); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
384 len = strlen (name); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
385 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
386 /* If DXPC (a Differential X Protocol Compressor) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
387 Ver.3.7 is running, XGetAtomName will return null |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
388 string. We must avoid such a name. */ |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
389 if (len > 0) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
390 { |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
391 entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
392 ASET (entity, FONT_TYPE_INDEX, Qx); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
393 ASET (entity, FONT_FRAME_INDEX, frame); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
394 if (font_parse_xlfd (name, entity) < 0) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
395 entity = Qnil; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
396 } |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
397 XFree (name); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
398 } |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
399 XFreeFont (display, xfont); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
400 } |
90569
0af2dbdeaeb3
(xfont_match): Block and unblock input while callin Xlib.
Kenichi Handa <handa@m17n.org>
parents:
90561
diff
changeset
|
401 UNBLOCK_INPUT; |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
402 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
403 return entity; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
404 } |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
405 |
90400 | 406 static int |
407 memq_no_quit (elt, list) | |
408 Lisp_Object elt, list; | |
409 { | |
410 while (CONSP (list) && ! EQ (XCAR (list), elt)) | |
411 list = XCDR (list); | |
412 return (CONSP (list)); | |
413 } | |
414 | |
415 static Lisp_Object | |
416 xfont_list_family (frame) | |
90443
57b847825c30
(xfont_list): If script is specified for a font, return
Kenichi Handa <handa@m17n.org>
parents:
90427
diff
changeset
|
417 Lisp_Object frame; |
90400 | 418 { |
419 FRAME_PTR f = XFRAME (frame); | |
420 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
421 char **names; | |
422 int num_fonts, i; | |
423 Lisp_Object list; | |
424 char *last_family; | |
425 int last_len; | |
426 | |
427 BLOCK_INPUT; | |
428 x_catch_errors (dpyinfo->display); | |
429 names = XListFonts (dpyinfo->display, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", | |
430 0x8000, &num_fonts); | |
431 if (x_had_errors_p (dpyinfo->display)) | |
432 { | |
433 /* This error is perhaps due to insufficient memory on X server. | |
434 Let's just ignore it. */ | |
435 x_clear_errors (dpyinfo->display); | |
436 num_fonts = 0; | |
437 } | |
438 | |
439 list = Qnil; | |
440 for (i = 0, last_len = 0; i < num_fonts; i++) | |
441 { | |
442 char *p0 = names[i], *p1; | |
443 Lisp_Object family; | |
444 | |
445 p0++; /* skip the leading '-' */ | |
446 while (*p0 && *p0 != '-') p0++; /* skip foundry */ | |
447 if (! *p0) | |
448 continue; | |
449 p1 = ++p0; | |
450 while (*p1 && *p1 != '-') p1++; /* find the end of family */ | |
451 if (! *p1 || p1 == p0) | |
452 continue; | |
453 if (last_len == p1 - p0 | |
454 && bcmp (last_family, p0, last_len) == 0) | |
455 continue; | |
456 last_len = p1 - p0; | |
457 last_family = p0; | |
458 family = intern_downcase (p0, last_len); | |
459 if (! memq_no_quit (family, list)) | |
460 list = Fcons (family, list); | |
461 } | |
462 | |
463 XFreeFontNames (names); | |
464 x_uncatch_errors (); | |
465 UNBLOCK_INPUT; | |
466 | |
467 return list; | |
468 } | |
469 | |
470 static struct font * | |
471 xfont_open (f, entity, pixel_size) | |
472 FRAME_PTR f; | |
473 Lisp_Object entity; | |
474 int pixel_size; | |
475 { | |
476 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
477 Display *display = dpyinfo->display; | |
478 char name[256]; | |
479 int len; | |
480 unsigned long value; | |
481 Lisp_Object registry; | |
482 struct charset *encoding, *repertory; | |
483 struct font *font; | |
484 XFontStruct *xfont; | |
485 | |
486 /* At first, check if we know how to encode characters for this | |
487 font. */ | |
488 registry = AREF (entity, FONT_REGISTRY_INDEX); | |
91142
4bcf0716ddf4
* xfont.c (x_font_charset_alist): Moved to font.c and renamed.
Kenichi Handa <handa@m17n.org>
parents:
90698
diff
changeset
|
489 if (font_registry_charsets (registry, &encoding, &repertory) < 0) |
90400 | 490 return NULL; |
491 | |
492 if (XINT (AREF (entity, FONT_SIZE_INDEX)) != 0) | |
493 pixel_size = XINT (AREF (entity, FONT_SIZE_INDEX)); | |
494 len = font_unparse_xlfd (entity, pixel_size, name, 256); | |
495 if (len <= 0) | |
496 return NULL; | |
497 | |
498 BLOCK_INPUT; | |
499 x_catch_errors (display); | |
500 xfont = XLoadQueryFont (display, name); | |
501 if (x_had_errors_p (display)) | |
502 { | |
503 /* This error is perhaps due to insufficient memory on X server. | |
504 Let's just ignore it. */ | |
505 x_clear_errors (display); | |
506 xfont = NULL; | |
507 } | |
508 x_uncatch_errors (); | |
509 UNBLOCK_INPUT; | |
510 | |
511 if (! xfont) | |
512 return NULL; | |
513 font = malloc (sizeof (struct font)); | |
90679 | 514 font->format = Qx; |
90400 | 515 font->font.font = xfont; |
516 font->entity = entity; | |
517 font->pixel_size = pixel_size; | |
518 font->driver = &xfont_driver; | |
519 font->font.name = malloc (len + 1); | |
520 if (! font->font.name) | |
521 { | |
522 XFreeFont (display, xfont); | |
523 free (font); | |
524 return NULL; | |
525 } | |
526 bcopy (name, font->font.name, len + 1); | |
527 font->font.charset = encoding->id; | |
528 font->encoding_charset = encoding->id; | |
90454
a8b745412821
(xfont_open, xfont_encode_char): Fix typo.
Kenichi Handa <handa@m17n.org>
parents:
90443
diff
changeset
|
529 font->repertory_charset = repertory ? repertory->id : -1; |
90400 | 530 font->ascent = xfont->ascent; |
531 font->descent = xfont->descent; | |
532 | |
533 if (xfont->min_bounds.width == xfont->max_bounds.width) | |
534 { | |
535 /* Fixed width font. */ | |
536 font->font.average_width = font->font.space_width | |
537 = xfont->min_bounds.width; | |
538 } | |
539 else | |
540 { | |
541 XChar2b char2b; | |
542 XCharStruct *pcm; | |
543 | |
544 char2b.byte1 = 0x00, char2b.byte2 = 0x20; | |
545 pcm = xfont_get_pcm (xfont, &char2b); | |
546 if (pcm) | |
547 font->font.space_width = pcm->width; | |
548 else | |
549 font->font.space_width = xfont->max_bounds.width; | |
550 | |
551 font->font.average_width | |
552 = (XGetFontProperty (xfont, dpyinfo->Xatom_AVERAGE_WIDTH, &value) | |
553 ? (long) value / 10 : 0); | |
554 if (font->font.average_width < 0) | |
555 font->font.average_width = - font->font.average_width; | |
556 if (font->font.average_width == 0) | |
557 { | |
558 if (pcm) | |
559 { | |
560 int width = pcm->width; | |
561 for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++) | |
562 if ((pcm = xfont_get_pcm (xfont, &char2b)) != NULL) | |
563 width += pcm->width; | |
564 font->font.average_width = width / 95; | |
565 } | |
566 else | |
567 font->font.average_width = xfont->max_bounds.width; | |
568 } | |
569 } | |
570 font->min_width = xfont->min_bounds.width; | |
571 if (font->min_width <= 0) | |
572 font->min_width = font->font.space_width; | |
573 | |
574 BLOCK_INPUT; | |
575 /* Try to get the full name of FONT. Put it in FULL_NAME. */ | |
576 if (XGetFontProperty (xfont, XA_FONT, &value)) | |
577 { | |
578 char *full_name = NULL, *p0, *p; | |
579 int dashes = 0; | |
580 | |
581 p0 = p = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value);; | |
582 /* Count the number of dashes in the "full name". | |
583 If it is too few, this isn't really the font's full name, | |
584 so don't use it. | |
585 In X11R4, the fonts did not come with their canonical names | |
586 stored in them. */ | |
587 while (*p) | |
588 { | |
589 if (*p == '-') | |
590 dashes++; | |
591 p++; | |
592 } | |
593 | |
594 if (dashes >= 13) | |
595 { | |
596 full_name = (char *) malloc (p - p0 + 1); | |
597 if (full_name) | |
598 bcopy (p0, full_name, p - p0 + 1); | |
599 } | |
600 XFree (p0); | |
601 | |
602 if (full_name) | |
603 font->font.full_name = full_name; | |
604 else | |
605 font->font.full_name = font->font.name; | |
606 } | |
607 font->file_name = NULL; | |
608 | |
609 font->font.size = xfont->max_bounds.width; | |
610 font->font.height = xfont->ascent + xfont->descent; | |
611 font->font.baseline_offset | |
612 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_BASELINE_OFFSET, &value) | |
613 ? (long) value : 0); | |
614 font->font.relative_compose | |
615 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_RELATIVE_COMPOSE, &value) | |
616 ? (long) value : 0); | |
617 font->font.default_ascent | |
618 = (XGetFontProperty (xfont, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value) | |
619 ? (long) value : 0); | |
620 font->font.vertical_centering | |
621 = (STRINGP (Vvertical_centering_font_regexp) | |
622 && (fast_c_string_match_ignore_case | |
623 (Vvertical_centering_font_regexp, font->font.full_name) >= 0)); | |
624 | |
625 UNBLOCK_INPUT; | |
626 | |
627 dpyinfo->n_fonts++; | |
628 | |
629 /* Set global flag fonts_changed_p to non-zero if the font loaded | |
630 has a character with a smaller width than any other character | |
631 before, or if the font loaded has a smaller height than any other | |
632 font loaded before. If this happens, it will make a glyph matrix | |
633 reallocation necessary. */ | |
634 if (dpyinfo->n_fonts == 1) | |
635 { | |
636 dpyinfo->smallest_font_height = font->font.height; | |
637 dpyinfo->smallest_char_width = font->min_width; | |
638 fonts_changed_p = 1; | |
639 } | |
640 else | |
641 { | |
642 if (dpyinfo->smallest_font_height > font->font.height) | |
643 dpyinfo->smallest_font_height = font->font.height, fonts_changed_p |= 1; | |
644 if (dpyinfo->smallest_char_width > font->min_width) | |
645 dpyinfo->smallest_char_width = font->min_width, fonts_changed_p |= 1; | |
646 } | |
647 | |
648 return font; | |
649 } | |
650 | |
651 static void | |
652 xfont_close (f, font) | |
653 FRAME_PTR f; | |
654 struct font *font; | |
655 { | |
656 BLOCK_INPUT; | |
657 XFreeFont (FRAME_X_DISPLAY (f), font->font.font); | |
658 UNBLOCK_INPUT; | |
659 | |
660 if (font->font.name != font->font.full_name) | |
661 free (font->font.full_name); | |
662 free (font->font.name); | |
663 free (font); | |
664 FRAME_X_DISPLAY_INFO (f)->n_fonts--; | |
665 } | |
666 | |
667 static int | |
668 xfont_prepare_face (f, face) | |
669 FRAME_PTR f; | |
670 struct face *face; | |
671 { | |
672 BLOCK_INPUT; | |
673 XSetFont (FRAME_X_DISPLAY (f), face->gc, face->font->fid); | |
674 UNBLOCK_INPUT; | |
675 | |
676 return 0; | |
677 } | |
678 | |
679 #if 0 | |
680 static void | |
681 xfont_done_face (f, face) | |
682 FRAME_PTR f; | |
683 struct face *face; | |
684 { | |
685 if (face->extra) | |
686 { | |
687 BLOCK_INPUT; | |
688 XFreeGC (FRAME_X_DISPLAY (f), (GC) face->extra); | |
689 UNBLOCK_INPUT; | |
690 face->extra = NULL; | |
691 } | |
692 } | |
693 #endif /* 0 */ | |
694 | |
695 static int | |
696 xfont_has_char (entity, c) | |
697 Lisp_Object entity; | |
698 int c; | |
699 { | |
700 Lisp_Object registry = AREF (entity, FONT_REGISTRY_INDEX); | |
701 struct charset *repertory; | |
702 | |
91142
4bcf0716ddf4
* xfont.c (x_font_charset_alist): Moved to font.c and renamed.
Kenichi Handa <handa@m17n.org>
parents:
90698
diff
changeset
|
703 if (font_registry_charsets (registry, NULL, &repertory) < 0) |
90400 | 704 return -1; |
705 if (! repertory) | |
706 return -1; | |
707 return (ENCODE_CHAR (repertory, c) != CHARSET_INVALID_CODE (repertory)); | |
708 } | |
709 | |
710 static unsigned | |
711 xfont_encode_char (font, c) | |
712 struct font *font; | |
713 int c; | |
714 { | |
715 struct charset *charset; | |
716 unsigned code; | |
717 XChar2b char2b; | |
718 | |
719 charset = CHARSET_FROM_ID (font->encoding_charset); | |
720 code = ENCODE_CHAR (charset, c); | |
721 if (code == CHARSET_INVALID_CODE (charset)) | |
722 return 0xFFFFFFFF; | |
90454
a8b745412821
(xfont_open, xfont_encode_char): Fix typo.
Kenichi Handa <handa@m17n.org>
parents:
90443
diff
changeset
|
723 if (font->repertory_charset >= 0) |
90400 | 724 { |
90454
a8b745412821
(xfont_open, xfont_encode_char): Fix typo.
Kenichi Handa <handa@m17n.org>
parents:
90443
diff
changeset
|
725 charset = CHARSET_FROM_ID (font->repertory_charset); |
90400 | 726 return (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset) |
727 ? code : 0xFFFFFFFF); | |
728 } | |
90425
5976e428d68e
(xfont_encode_char): Fix calculation of char2b.
Kenichi Handa <handa@m17n.org>
parents:
90400
diff
changeset
|
729 char2b.byte1 = code >> 8; |
5976e428d68e
(xfont_encode_char): Fix calculation of char2b.
Kenichi Handa <handa@m17n.org>
parents:
90400
diff
changeset
|
730 char2b.byte2 = code & 0xFF; |
90400 | 731 return (xfont_get_pcm (font->font.font, &char2b) ? code : 0xFFFFFFFF); |
732 } | |
733 | |
734 static int | |
735 xfont_text_extents (font, code, nglyphs, metrics) | |
736 struct font *font; | |
737 unsigned *code; | |
738 int nglyphs; | |
739 struct font_metrics *metrics; | |
740 { | |
741 int width = 0; | |
742 int i, x; | |
743 | |
744 if (metrics) | |
745 bzero (metrics, sizeof (struct font_metrics)); | |
746 for (i = 0, x = 0; i < nglyphs; i++) | |
747 { | |
748 XChar2b char2b; | |
749 static XCharStruct *pcm; | |
750 | |
751 if (code[i] >= 0x10000) | |
752 continue; | |
753 char2b.byte1 = code[i] >> 8, char2b.byte2 = code[i] & 0xFF; | |
754 pcm = xfont_get_pcm (font->font.font, &char2b); | |
755 if (! pcm) | |
756 continue; | |
757 if (metrics->lbearing > width + pcm->lbearing) | |
758 metrics->lbearing = width + pcm->lbearing; | |
759 if (metrics->rbearing < width + pcm->rbearing) | |
760 metrics->rbearing = width + pcm->rbearing; | |
761 if (metrics->ascent < pcm->ascent) | |
762 metrics->ascent = pcm->ascent; | |
763 if (metrics->descent < pcm->descent) | |
764 metrics->descent = pcm->descent; | |
765 width += pcm->width; | |
766 } | |
767 if (metrics) | |
768 metrics->width = width; | |
769 return width; | |
770 } | |
771 | |
772 static int | |
773 xfont_draw (s, from, to, x, y, with_background) | |
774 struct glyph_string *s; | |
775 int from, to, x, y, with_background; | |
776 { | |
777 XFontStruct *xfont = s->face->font; | |
778 int len = to - from; | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
779 GC gc = s->gc; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
780 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
781 if (gc != s->face->gc) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
782 { |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
783 XGCValues xgcv; |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
784 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (s->f); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
785 |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
786 XGetGCValues (s->display, gc, GCFont, &xgcv); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
787 if (xgcv.font != xfont->fid) |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
788 XSetFont (s->display, gc, xfont->fid); |
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
789 } |
90400 | 790 |
791 if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0) | |
792 { | |
793 char *str; | |
794 int i; | |
795 USE_SAFE_ALLOCA; | |
796 | |
797 SAFE_ALLOCA (str, char *, len); | |
798 for (i = 0; i < len ; i++) | |
799 str[i] = XCHAR2B_BYTE2 (s->char2b + from + i); | |
800 if (with_background > 0) | |
801 XDrawImageString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
802 gc, x, y, str, len); |
90400 | 803 else |
804 XDrawString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
805 gc, x, y, str, len); |
90400 | 806 SAFE_FREE (); |
807 return s->nchars; | |
808 } | |
809 | |
810 if (with_background > 0) | |
811 XDrawImageString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
812 gc, x, y, s->char2b + from, len); |
90400 | 813 else |
814 XDrawString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f), | |
90561
73750c4e078a
(xfont_match): New function.
Kenichi Handa <handa@m17n.org>
parents:
90545
diff
changeset
|
815 gc, x, y, s->char2b + from, len); |
90400 | 816 |
817 return len; | |
818 } | |
819 | |
820 | |
821 | |
822 void | |
823 syms_of_xfont () | |
824 { | |
825 DEFSYM (Qx, "x"); | |
826 xfont_driver.type = Qx; | |
827 register_font_driver (&xfont_driver, NULL); | |
828 } | |
90427 | 829 |
830 /* arch-tag: 23c5f366-a5ee-44b7-a3b7-90d6da7fd749 | |
831 (do not change this comment) */ |