17052
|
1 /* Fontset handler.
|
|
2 Ver.1.0
|
|
3 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
5
|
17071
|
6 This file is part of GNU Emacs.
|
|
7
|
|
8 GNU Emacs is free software; you can redistribute it and/or modify
|
|
9 it under the terms of the GNU General Public License as published by
|
|
10 the Free Software Foundation; either version 2, or (at your option)
|
|
11 any later version.
|
17052
|
12
|
17071
|
13 GNU Emacs is distributed in the hope that it will be useful,
|
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 GNU General Public License for more details.
|
17052
|
17
|
17071
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with GNU Emacs; 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. */
|
17052
|
22
|
|
23 #include <config.h>
|
|
24 #if HAVE_ALLOCA_H
|
|
25 #include <alloca.h>
|
|
26 #endif /* HAVE_ALLOCA_H */
|
|
27 #include "lisp.h"
|
|
28 #include "charset.h"
|
|
29 #include "ccl.h"
|
|
30 #include "fontset.h"
|
|
31 #include "frame.h"
|
|
32
|
|
33 Lisp_Object Vglobal_fontset_alist;
|
|
34
|
|
35 Lisp_Object Vfont_encoding_alist;
|
|
36
|
|
37 /* We had better have our own strcasecmp function because some system
|
|
38 doesn't have it. */
|
|
39 static char my_strcasetbl[256];
|
|
40
|
|
41 /* Compare two strings S0 and S1 while ignoring differences in case.
|
|
42 Return 1 if they differ, else return 0. */
|
|
43 static int
|
|
44 my_strcasecmp (s0, s1)
|
|
45 unsigned char *s0, *s1;
|
|
46 {
|
|
47 while (*s0)
|
|
48 if (my_strcasetbl[*s0++] != my_strcasetbl[*s1++]) return 1;
|
|
49 return (int) *s1;
|
|
50 }
|
|
51
|
|
52 /* The following six are window system dependent functions. See
|
|
53 the comments in src/fontset.h for more detail. */
|
|
54
|
|
55 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
|
|
56 struct font_info *(*get_font_info_func) (/* FRAME_PTR f; int font_idx */);
|
|
57
|
|
58 /* Return a list of font names which matches PATTERN. See the document of
|
|
59 `x-list-fonts' for more detail. */
|
|
60 Lisp_Object (*list_fonts_func) (/* Lisp_Object pattern, face, frame, width */);
|
|
61
|
|
62 /* Load a font named NAME for frame F and return a pointer to the
|
|
63 information of the loaded font. If loading is failed, return 0. */
|
|
64 struct font_info *(*load_font_func) (/* FRAME_PTR f; char *name */);
|
|
65
|
|
66 /* Return a pointer to struct font_info of a font named NAME for frame F. */
|
|
67 struct font_info *(*query_font_func) (/* FRAME_PTR f; char *name */);
|
|
68
|
|
69 /* Additional function for setting fontset or changing fontset
|
|
70 contents of frame F. */
|
|
71 void (*set_frame_fontset_func) (/* FRAME_PTR f; Lisp_Object arg, oldval */);
|
|
72
|
|
73 /* Check if any window system is used now. */
|
|
74 void (*check_window_system_func) ();
|
|
75
|
|
76 struct fontset_data *
|
|
77 alloc_fontset_data ()
|
|
78 {
|
|
79 struct fontset_data *fontset_data
|
|
80 = (struct fontset_data *) xmalloc (sizeof (struct fontset_data));
|
|
81
|
|
82 bzero (fontset_data, sizeof (struct fontset_data));
|
|
83
|
|
84 return fontset_data;
|
|
85 }
|
|
86
|
|
87 void
|
|
88 free_fontset_data (fontset_data)
|
|
89 struct fontset_data *fontset_data;
|
|
90 {
|
|
91 int i;
|
|
92
|
|
93 for (i = 0; i < fontset_data->n_fontsets; i++)
|
|
94 {
|
|
95 int j;
|
|
96
|
|
97 xfree (fontset_data->fontset_table[i]->name);
|
|
98 for (j = 0; j < MAX_CHARSET; j++)
|
|
99 if (fontset_data->fontset_table[i]->fontname[j])
|
|
100 xfree (fontset_data->fontset_table[i]->fontname[j]);
|
|
101 xfree (fontset_data->fontset_table[i]);
|
|
102 }
|
|
103 xfree (fontset_data->fontset_table);
|
|
104
|
|
105 xfree (fontset_data);
|
|
106 }
|
|
107
|
|
108 /* Load a font named FONTNAME for displaying CHARSET on frame F.
|
|
109 All fonts for frame F is stored in a table pointed by FONT_TABLE.
|
|
110 Return a pointer to the struct font_info of the loaded font.
|
|
111 If loading fails, return 0;
|
|
112 If FONTNAME is NULL, the name is taken from the information of FONTSET.
|
|
113 If FONTSET is given, try to load a font whose size matches that of
|
|
114 FONTSET, and, the font index is stored in the table for FONTSET. */
|
|
115
|
|
116 struct font_info *
|
|
117 fs_load_font (f, font_table, charset, fontname, fontset)
|
|
118 FRAME_PTR f;
|
|
119 struct font_info *font_table;
|
|
120 int charset, fontset;
|
|
121 char *fontname;
|
|
122 {
|
|
123 Lisp_Object font_list;
|
|
124 Lisp_Object list, elt;
|
|
125 int font_idx;
|
|
126 int size = 0;
|
|
127 struct fontset_info *fontsetp = 0;
|
|
128 struct font_info *fontp;
|
|
129
|
|
130 if (fontset >= 0 && fontset < FRAME_FONTSET_DATA (f)->n_fontsets)
|
|
131 {
|
|
132 fontsetp = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
|
|
133 font_idx = fontsetp->font_indexes[charset];
|
|
134 if (font_idx >= 0)
|
|
135 /* We have already loaded a font. */
|
|
136 return font_table + font_idx;
|
|
137 else if (font_idx == FONT_NOT_FOUND)
|
|
138 /* We have already tried loading a font and failed. */
|
|
139 return 0;
|
|
140 if (!fontname)
|
|
141 fontname = fontsetp->fontname[charset];
|
|
142 }
|
|
143
|
|
144 if (!fontname)
|
|
145 /* No way to get fontname. */
|
|
146 return 0;
|
|
147
|
|
148 /* If a fontset is specified and we have already loaded some fonts
|
|
149 in the fontset, we need a font of appropriate size to be used
|
|
150 with the fonts. */
|
|
151 if (fontsetp && fontsetp->size)
|
|
152 size = fontsetp->size * CHARSET_WIDTH (charset);
|
|
153
|
|
154 fontp = (*load_font_func) (f, fontname, size);
|
|
155
|
|
156 if (!fontp)
|
|
157 {
|
|
158 if (fontsetp)
|
|
159 fontsetp->font_indexes[charset] = FONT_NOT_FOUND;
|
|
160 return 0;
|
|
161 }
|
|
162
|
|
163 /* Fill in fields (CHARSET, ENCODING, and FONT_ENCODER) which are
|
|
164 not set by (*load_font_func). */
|
|
165 fontp->charset = charset;
|
|
166
|
|
167 if (fontp->encoding[1] >= 0)
|
|
168 {
|
|
169 /* The font itself tells which code points to be used. Use this
|
|
170 encoding for all other charsets. */
|
|
171 int i;
|
|
172
|
|
173 fontp->encoding[0] = fontp->encoding[1];
|
|
174 for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i < MAX_CHARSET; i++)
|
|
175 fontp->encoding[i] = fontp->encoding[1];
|
|
176 }
|
|
177 else
|
|
178 {
|
|
179 /* The font itself doesn't tell which code points to be used. */
|
|
180 int i;
|
|
181
|
|
182 /* At first, set 1 (means 0xA0..0xFF) as the default. */
|
|
183 fontp->encoding[0] = 1;
|
|
184 for (i = MIN_CHARSET_OFFICIAL_DIMENSION1; i < MAX_CHARSET; i++)
|
|
185 fontp->encoding[i] = 1;
|
|
186 /* Then override them by a specification in Vfont_encoding_alist. */
|
|
187 for (list = Vfont_encoding_alist; CONSP (list); list = XCONS (list)->cdr)
|
|
188 {
|
|
189 elt = XCONS (list)->car;
|
|
190 if (CONSP (elt)
|
|
191 && STRINGP (XCONS (elt)->car) && CONSP (XCONS (elt)->cdr)
|
|
192 && (fast_string_match_ignore_case (XCONS (elt)->car, fontname)
|
|
193 >= 0))
|
|
194 {
|
|
195 Lisp_Object tmp;
|
|
196
|
|
197 for (tmp = XCONS (elt)->cdr; CONSP (tmp); tmp = XCONS (tmp)->cdr)
|
|
198 if (CONSP (XCONS (tmp)->car)
|
|
199 && INTEGERP (XCONS (XCONS (tmp)->car)->car)
|
|
200 && ((i = get_charset_id (XCONS (XCONS (tmp)->car)->car))
|
|
201 >= 0)
|
|
202 && INTEGERP (XCONS (XCONS (tmp)->car)->cdr)
|
|
203 && XFASTINT (XCONS (XCONS (tmp)->car)->cdr) < 4)
|
|
204 fontp->encoding[i]
|
|
205 = XFASTINT (XCONS (XCONS (tmp)->car)->cdr);
|
|
206 }
|
|
207 }
|
|
208 }
|
|
209
|
|
210 fontp->font_encoder = (struct ccl_program *) 0;
|
|
211 for (list = Vfont_ccl_encoder_alist; CONSP (list); list = XCONS (list)->cdr)
|
|
212 {
|
|
213 elt = XCONS (list)->car;
|
|
214 if (CONSP (elt)
|
|
215 && STRINGP (XCONS (elt)->car) && VECTORP (XCONS (elt)->cdr)
|
|
216 && fast_string_match_ignore_case (XCONS (elt)->car, fontname) >= 0)
|
|
217 {
|
|
218 fontp->font_encoder
|
|
219 = (struct ccl_program *) xmalloc (sizeof (struct ccl_program));
|
|
220 setup_ccl_program (fontp->font_encoder, XCONS (elt)->cdr);
|
|
221 break;
|
|
222 }
|
|
223 }
|
|
224
|
|
225 if (fontsetp)
|
|
226 {
|
|
227 fontsetp->font_indexes[charset] = fontp->font_idx;
|
|
228 if (fontsetp->size == 0)
|
|
229 fontsetp->size = fontp->size / CHARSET_WIDTH (charset);
|
|
230
|
|
231 if (charset == CHARSET_ASCII
|
|
232 && fontsetp->size != fontp->size)
|
|
233 {
|
|
234 /* When loading ASCII font of the different size from the
|
|
235 size of FONTSET, we have to update the size of FONTSET.
|
|
236 Since changing the size of FONTSET may make some fonts
|
|
237 already loaded inappropriate to be used in FONTSET, we
|
|
238 must delete the record of such fonts. In that case, we
|
|
239 also have to calculate the height of FONTSET from the
|
|
240 remaining fonts. */
|
|
241 int i;
|
|
242
|
|
243 fontsetp->size = fontp->size;
|
|
244 fontsetp->height = fontp->height;
|
|
245 for (i = CHARSET_ASCII + 1; i < MAX_CHARSET; i++)
|
|
246 {
|
|
247 font_idx = fontsetp->font_indexes[i];
|
|
248 if (font_idx >= 0)
|
|
249 {
|
|
250 struct font_info *fontp2 = font_table + font_idx;
|
|
251
|
|
252 if (fontp2->size != fontp->size * CHARSET_WIDTH (i))
|
|
253 fontsetp->font_indexes[i] = FONT_NOT_OPENED;
|
|
254 else if (fontsetp->height < fontp->height)
|
|
255 fontsetp->height = fontp->height;
|
|
256 }
|
|
257 }
|
|
258 }
|
|
259 else if (fontsetp->height < fontp->height)
|
|
260 fontsetp->height = fontp->height;
|
|
261 }
|
|
262
|
|
263 return fontp;
|
|
264 }
|
|
265
|
|
266 /* Return ID of the fontset named NAME on frame F. */
|
|
267
|
|
268 int
|
|
269 fs_query_fontset (f, name)
|
|
270 FRAME_PTR f;
|
|
271 char *name;
|
|
272 {
|
|
273 struct fontset_data *fontset_data = FRAME_FONTSET_DATA (f);
|
|
274 int i;
|
|
275
|
|
276 for (i = 0; i < fontset_data->n_fontsets; i++)
|
|
277 if (!my_strcasecmp(name, fontset_data->fontset_table[i]->name))
|
|
278 return i;
|
|
279 return -1;
|
|
280 }
|
|
281
|
|
282 /* Register a fontset specified by FONTSET_INFO for frame FRAME.
|
|
283 Return the fontset ID if successfully registered, else return -1.
|
|
284 FONTSET_INFO is a cons of name of the fontset and FONTLIST, where
|
|
285 FONTLIST is an alist of charsets vs fontnames. */
|
|
286
|
|
287 int
|
|
288 fs_register_fontset (f, fontset_info)
|
|
289 FRAME_PTR f;
|
|
290 Lisp_Object fontset_info;
|
|
291 {
|
|
292 struct fontset_data *fontset_data = FRAME_FONTSET_DATA (f);
|
|
293 Lisp_Object name, fontlist;
|
|
294 int fontset;
|
|
295 struct fontset_info *fontsetp;
|
|
296 int i;
|
|
297
|
|
298 if (!CONSP (fontset_info)
|
|
299 || !STRINGP (XCONS (fontset_info)->car)
|
|
300 || !CONSP (XCONS (fontset_info)->cdr))
|
|
301 /* Invalid data in FONTSET_INFO. */
|
|
302 return -1;
|
|
303
|
|
304 name = XCONS (fontset_info)->car;
|
|
305 if ((fontset = fs_query_fontset (f, XSTRING (name)->data)) >= 0)
|
|
306 /* This fontset already exists on frame F. */
|
|
307 return fontset;
|
|
308
|
|
309 fontsetp = (struct fontset_info *) xmalloc (sizeof (struct fontset_info));
|
|
310
|
|
311 fontsetp->name = (char *) xmalloc (XSTRING (name)->size + 1);
|
|
312 bcopy(XSTRING (name)->data, fontsetp->name, XSTRING (name)->size + 1);
|
|
313
|
|
314 fontsetp->size = fontsetp->height = 0;
|
|
315
|
|
316 for (i = 0; i < MAX_CHARSET; i++)
|
|
317 {
|
|
318 fontsetp->fontname[i] = (char *) 0;
|
|
319 fontsetp->font_indexes[i] = FONT_NOT_OPENED;
|
|
320 }
|
|
321
|
|
322 for (fontlist = XCONS (fontset_info)->cdr; CONSP (fontlist);
|
|
323 fontlist = XCONS (fontlist)->cdr)
|
|
324 {
|
|
325 Lisp_Object tem = Fcar (fontlist);
|
|
326 int charset;
|
|
327
|
|
328 if (CONSP (tem)
|
|
329 && (charset = get_charset_id (XCONS (tem)->car)) >= 0
|
|
330 && STRINGP (XCONS (tem)->cdr))
|
|
331 {
|
|
332 fontsetp->fontname[charset]
|
|
333 = (char *) xmalloc (XSTRING (XCONS (tem)->cdr)->size + 1);
|
|
334 bcopy (XSTRING (XCONS (tem)->cdr)->data,
|
|
335 fontsetp->fontname[charset],
|
|
336 XSTRING (XCONS (tem)->cdr)->size + 1);
|
|
337 }
|
|
338 else
|
|
339 /* Broken or invalid data structure. */
|
|
340 return -1;
|
|
341 }
|
|
342
|
|
343 /* Do we need to create the table? */
|
|
344 if (fontset_data->fontset_table_size == 0)
|
|
345 {
|
|
346 fontset_data->fontset_table_size = 8;
|
|
347 fontset_data->fontset_table
|
|
348 = (struct fontset_info **) xmalloc (fontset_data->fontset_table_size
|
|
349 * sizeof (struct fontset_info *));
|
|
350 }
|
|
351 /* Do we need to grow the table? */
|
|
352 else if (fontset_data->n_fontsets >= fontset_data->fontset_table_size)
|
|
353 {
|
|
354 fontset_data->fontset_table_size += 8;
|
|
355 fontset_data->fontset_table
|
|
356 = (struct fontset_info **) xrealloc (fontset_data->fontset_table,
|
|
357 fontset_data->fontset_table_size
|
|
358 * sizeof (struct fontset_info *));
|
|
359 }
|
|
360 fontset = fontset_data->n_fontsets++;
|
|
361 fontset_data->fontset_table[fontset] = fontsetp;
|
|
362
|
|
363 return fontset;
|
|
364 }
|
|
365
|
|
366 /* Cache data used by fontset_pattern_regexp. The car part is a
|
|
367 pattern string containing at least one wild card, the cdr part is
|
|
368 the corresponding regular expression. */
|
|
369 static Lisp_Object Vcached_fontset_data;
|
|
370
|
|
371 #define CACHED_FONTSET_NAME (XSTRING (XCONS (Vcached_fontset_data)->car)->data)
|
|
372 #define CACHED_FONTSET_REGEX (XCONS (Vcached_fontset_data)->cdr)
|
|
373
|
|
374 /* If fontset name PATTERN contains any wild card, return regular
|
|
375 expression corresponding to PATTERN. */
|
|
376
|
|
377 Lisp_Object
|
|
378 fontset_pattern_regexp (pattern)
|
|
379 Lisp_Object pattern;
|
|
380 {
|
|
381 int nickname = 0;
|
|
382
|
|
383 if (!index (XSTRING (pattern)->data, '*')
|
|
384 && !index (XSTRING (pattern)->data, '?'))
|
|
385 /* PATTERN does not contain any wild cards. */
|
|
386 {
|
|
387 if (XSTRING (pattern)->size > 8
|
|
388 && ! bcmp (XSTRING (pattern)->data, "fontset-", 8))
|
|
389 /* Just a nickname of a fontset is specified. */
|
|
390 nickname = 1;
|
|
391 else
|
|
392 return Qnil;
|
|
393 }
|
|
394
|
|
395 if (!CONSP (Vcached_fontset_data)
|
|
396 || strcmp (XSTRING (pattern)->data, CACHED_FONTSET_NAME))
|
|
397 {
|
|
398 /* We must at first update the cached data. */
|
|
399 char *regex = (char *) alloca (XSTRING (pattern)->size * 2 + 3);
|
|
400 char *p0, *p1 = regex;
|
|
401
|
|
402 if (nickname)
|
|
403 {
|
|
404 /* Just prepend ".*-" to PATTERN. */
|
|
405 *p1++= '.'; *p1++= '*', *p1++= '-';
|
|
406 bcopy (XSTRING (pattern)->data, p1, XSTRING (pattern)->size);
|
|
407 p1 += XSTRING (pattern)->size;
|
|
408 }
|
|
409 else
|
|
410 {
|
|
411 /* Convert "*" to ".*", "?" to ".". */
|
|
412 *p1++ = '^';
|
|
413 for (p0 = XSTRING (pattern)->data; *p0; p0++)
|
|
414 {
|
|
415 if (*p0 == '*')
|
|
416 {
|
|
417 *p1++ = '.';
|
|
418 *p1++ = '*';
|
|
419 }
|
|
420 else if (*p0 == '?')
|
|
421 *p1++ == '.';
|
|
422 else
|
|
423 *p1++ = *p0;
|
|
424 }
|
|
425 }
|
|
426 *p1++ = '$';
|
|
427 *p1++ = 0;
|
|
428
|
|
429 Vcached_fontset_data = Fcons (build_string (XSTRING (pattern)->data),
|
|
430 build_string (regex));
|
|
431 }
|
|
432
|
|
433 return CACHED_FONTSET_REGEX;
|
|
434 }
|
|
435
|
|
436 DEFUN ("query-fontset", Fquery_fontset, Squery_fontset, 1, 1, 0,
|
|
437 "Return a fontset name which matches PATTERN, nil if no matching fontset.\n\
|
|
438 PATTERN can contain `*' or `?' as a wild card\n\
|
|
439 just like X's font name matching algorithm allows.")
|
|
440 (pattern)
|
|
441 Lisp_Object pattern;
|
|
442 {
|
|
443 Lisp_Object regexp, tem;
|
|
444
|
|
445 (*check_window_system_func) ();
|
|
446
|
|
447 CHECK_STRING (pattern, 0);
|
|
448
|
|
449 if (XSTRING (pattern)->size == 0)
|
|
450 return Qnil;
|
|
451
|
|
452 regexp = fontset_pattern_regexp (pattern);
|
|
453
|
|
454 for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCONS (tem)->cdr)
|
|
455 {
|
|
456 Lisp_Object fontset_name = XCONS (XCONS (tem)->car)->car;
|
|
457 if (!NILP (regexp))
|
|
458 {
|
|
459 if (fast_string_match_ignore_case (regexp,
|
|
460 XSTRING (fontset_name)->data)
|
|
461 >= 0)
|
|
462 return fontset_name;
|
|
463 }
|
|
464 else
|
|
465 {
|
|
466 if (!my_strcasecmp (XSTRING (pattern)->data,
|
|
467 XSTRING (fontset_name)->data))
|
|
468 return fontset_name;
|
|
469 }
|
|
470 }
|
|
471
|
|
472 return Qnil;
|
|
473 }
|
|
474
|
|
475 Lisp_Object Fframe_char_width ();
|
|
476
|
|
477 /* Return a list of names of available fontsets matching PATTERN on
|
|
478 frame F. If SIZE is not 0, it is the size (maximum bound width) of
|
|
479 fontsets to be listed. */
|
|
480
|
|
481 Lisp_Object
|
|
482 list_fontsets (f, pattern, size)
|
|
483 FRAME_PTR f;
|
|
484 Lisp_Object pattern;
|
|
485 int size;
|
|
486 {
|
|
487 int i;
|
|
488 Lisp_Object regexp, val;
|
|
489
|
|
490 regexp = fontset_pattern_regexp (pattern);
|
|
491
|
|
492 val = Qnil;
|
|
493 for (i = 0; i < FRAME_FONTSET_DATA (f)->n_fontsets; i++)
|
|
494 {
|
|
495 struct fontset_info *fontsetp = FRAME_FONTSET_DATA (f)->fontset_table[i];
|
|
496 int name_matched = 0;
|
|
497 int size_matched = 0;
|
|
498
|
|
499 if (!NILP (regexp))
|
|
500 {
|
|
501 if (fast_string_match_ignore_case (regexp, fontsetp->name) >= 0)
|
|
502 name_matched = 1;
|
|
503 }
|
|
504 else
|
|
505 {
|
|
506 if (!my_strcasecmp (XSTRING (pattern)->data, fontsetp->name))
|
|
507 name_matched = 1;
|
|
508 }
|
|
509
|
|
510 if (name_matched)
|
|
511 {
|
|
512 if (!size || fontsetp->size == size)
|
|
513 size_matched = 1;
|
|
514 else if (fontsetp->size == 0)
|
|
515 {
|
|
516 /* No font of this fontset has loaded yet. Try loading
|
|
517 one with SIZE. */
|
|
518 int j;
|
|
519
|
|
520 for (j = 0; j < MAX_CHARSET; j++)
|
|
521 if (fontsetp->fontname[j])
|
|
522 {
|
|
523 if ((*load_font_func) (f, fontsetp->fontname[j], size))
|
|
524 size_matched = 1;
|
|
525 break;
|
|
526 }
|
|
527 }
|
|
528
|
|
529 if (size_matched)
|
|
530 val = Fcons (build_string (fontsetp->name), val);
|
|
531 }
|
|
532 }
|
|
533
|
|
534 return val;
|
|
535 }
|
|
536
|
|
537 DEFUN ("new-fontset", Fnew_fontset, Snew_fontset, 2, 2, 0,
|
|
538 "Create a new fontset NAME which contains fonts in FONTLIST.\n\
|
|
539 FONTLIST is an alist of charsets vs corresponding font names.")
|
|
540 (name, fontlist)
|
|
541 Lisp_Object name, fontlist;
|
|
542 {
|
|
543 Lisp_Object fullname, fontset_info;
|
|
544 Lisp_Object tail;
|
|
545
|
|
546 (*check_window_system_func) ();
|
|
547
|
|
548 CHECK_STRING (name, 0);
|
|
549 CHECK_LIST (fontlist, 1);
|
|
550
|
|
551 fullname = Fquery_fontset (name);
|
|
552 if (!NILP (fullname))
|
|
553 error ("Fontset \"%s\" matches the existing fontset \"%s\"",
|
|
554 XSTRING (name)->data, XSTRING (fullname)->data);
|
|
555
|
|
556 /* Check the validity of FONTLIST. */
|
|
557 for (tail = fontlist; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
558 {
|
|
559 Lisp_Object tem = XCONS (tail)->car;
|
|
560 int charset;
|
|
561
|
|
562 if (!CONSP (tem)
|
|
563 || (charset = get_charset_id (XCONS (tem)->car)) < 0
|
|
564 || !STRINGP (XCONS (tem)->cdr))
|
|
565 error ("Elements of fontlist must be a cons of charset and font name");
|
|
566 }
|
|
567
|
|
568 fontset_info = Fcons (name, fontlist);
|
|
569 Vglobal_fontset_alist = Fcons (fontset_info, Vglobal_fontset_alist);
|
|
570
|
|
571 /* Register this fontset for all existing frames. */
|
|
572 {
|
|
573 Lisp_Object framelist, frame;
|
|
574
|
|
575 FOR_EACH_FRAME (framelist, frame)
|
|
576 if (!FRAME_TERMCAP_P (XFRAME (frame)))
|
|
577 fs_register_fontset (XFRAME (frame), fontset_info);
|
|
578 }
|
|
579
|
|
580 return Qnil;
|
|
581 }
|
|
582
|
|
583 extern Lisp_Object Fframe_parameters ();
|
|
584 extern Lisp_Object Qfont;
|
|
585 Lisp_Object Qfontset;
|
|
586
|
|
587 DEFUN ("set-fontset-font", Fset_fontset_font, Sset_fontset_font, 3, 4, 0,
|
|
588 "Set FONTNAME for a font of CHARSET in fontset NAME on frame FRAME.\n\
|
|
589 If FRAME is omitted or nil, all frames are affected.")
|
|
590 (name, charset_symbol, fontname, frame)
|
|
591 Lisp_Object name, charset_symbol, fontname, frame;
|
|
592 {
|
|
593 int charset;
|
|
594 Lisp_Object fullname, fontlist;
|
|
595
|
|
596 (*check_window_system_func) ();
|
|
597
|
|
598 CHECK_STRING (name, 0);
|
|
599 CHECK_SYMBOL (charset_symbol, 1);
|
|
600 CHECK_STRING (fontname, 2);
|
|
601 if (!NILP (frame))
|
|
602 CHECK_LIVE_FRAME (frame, 3);
|
|
603
|
|
604 if ((charset = get_charset_id (charset_symbol)) < 0)
|
|
605 error ("Invalid charset: %s", XSYMBOL (charset_symbol)->name->data);
|
|
606
|
|
607 fullname = Fquery_fontset (name);
|
|
608 if (NILP (fullname))
|
|
609 error ("Fontset \"%s\" does not exist", XSTRING (name)->data);
|
|
610
|
|
611 /* If FRAME is not specified, we must, at first, update contents of
|
|
612 `global-fontset-alist' for a frame created in the future. */
|
|
613 if (NILP (frame))
|
|
614 {
|
|
615 Lisp_Object fontset_info = Fassoc (fullname, Vglobal_fontset_alist);
|
|
616 Lisp_Object tem = Fassq (charset, XCONS (fontset_info)->cdr);
|
|
617
|
|
618 if (NILP (tem))
|
|
619 XCONS (fontset_info)->cdr
|
|
620 = Fcons (Fcons (charset, fontname), XCONS (fontset_info)->cdr);
|
|
621 else
|
|
622 XCONS (tem)->cdr = fontname;
|
|
623 }
|
|
624
|
|
625 /* Then, update information in the specified frame or all existing
|
|
626 frames. */
|
|
627 {
|
|
628 Lisp_Object framelist, tem;
|
|
629
|
|
630 FOR_EACH_FRAME (framelist, tem)
|
|
631 if (!FRAME_TERMCAP_P (XFRAME (tem))
|
|
632 && (NILP (frame) || EQ (frame, tem)))
|
|
633 {
|
|
634 FRAME_PTR f = XFRAME (tem);
|
|
635 int fontset = fs_query_fontset (f, XSTRING (fullname)->data);
|
|
636 struct fontset_info *fontsetp
|
|
637 = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
|
|
638
|
|
639 if (fontsetp->fontname[XINT (charset)])
|
|
640 xfree (fontsetp->fontname[XINT (charset)]);
|
|
641 fontsetp->fontname[XINT (charset)]
|
|
642 = (char *) xmalloc (XSTRING (fontname)->size + 1);
|
|
643 bcopy (XSTRING (fontname)->data, fontsetp->fontname[XINT (charset)],
|
|
644 XSTRING (fontname)->size + 1);
|
|
645 fontsetp->font_indexes[XINT (charset)] = FONT_NOT_OPENED;
|
|
646
|
|
647 if (charset == CHARSET_ASCII)
|
|
648 {
|
|
649 Lisp_Object font_param = Fassq (Qfont, Fframe_parameters (tem));
|
|
650
|
|
651 if (set_frame_fontset_func
|
|
652 && !NILP (font_param)
|
|
653 && !strcmp (XSTRING (fullname)->data,
|
|
654 XSTRING (XCONS (font_param)->cdr)->data))
|
|
655 /* This fontset is the default fontset on frame TEM.
|
|
656 We may have to resize this frame because of new
|
|
657 ASCII font. */
|
|
658 (*set_frame_fontset_func) (f, fullname, Qnil);
|
|
659 }
|
|
660 }
|
|
661 }
|
|
662
|
|
663 return Qnil;
|
|
664 }
|
|
665
|
|
666 DEFUN ("font-info", Ffont_info, Sfont_info, 1, 2, 0,
|
|
667 "Return information about a font named NAME on frame FRAME.\n\
|
|
668 If FRAME is omitted or nil, use the selected frame.\n\
|
|
669 The returned value is a vector of OPENED-NAME, FULL-NAME, CHARSET, SIZE,\n\
|
|
670 HEIGHT, BASELINE-OFFSET, and RELATIVE-COMPOSE,\n\
|
|
671 where\n\
|
|
672 OPENED-NAME is the name used for opening the font,\n\
|
|
673 FULL-NAME is the full name of the font,\n\
|
|
674 CHARSET is the charset displayed by the font,\n\
|
|
675 SIZE is the minimum bound width of the font,\n\
|
|
676 HEIGHT is the height of the font,\n\
|
|
677 BASELINE-OFFSET is the upward offset pixels from ASCII baseline,\n\
|
|
678 RELATIVE-COMPOSE is the number controlling how to compose characters.\n\
|
|
679 If the named font is not yet loaded, return nil.")
|
|
680 (name, frame)
|
|
681 Lisp_Object name, frame;
|
|
682 {
|
|
683 FRAME_PTR f;
|
|
684 struct font_info *fontp;
|
|
685 Lisp_Object info;
|
|
686
|
|
687 (*check_window_system_func) ();
|
|
688
|
|
689 CHECK_STRING (name, 0);
|
|
690 if (NILP (frame))
|
|
691 f = selected_frame;
|
|
692 else
|
|
693 {
|
|
694 CHECK_LIVE_FRAME (frame, 1);
|
|
695 f = XFRAME (frame);
|
|
696 }
|
|
697
|
|
698 if (!query_font_func)
|
|
699 error ("Font query function is not supported");
|
|
700
|
|
701 fontp = (*query_font_func) (f, XSTRING (name)->data);
|
|
702 if (!fontp)
|
|
703 return Qnil;
|
|
704
|
|
705 info = Fmake_vector (make_number (6), Qnil);
|
|
706
|
|
707 XVECTOR (info)->contents[0] = build_string (fontp->name);
|
|
708 XVECTOR (info)->contents[1] = build_string (fontp->full_name);
|
|
709 XVECTOR (info)->contents[2] = CHARSET_SYMBOL (fontp->charset);
|
|
710 XVECTOR (info)->contents[3] = make_number (fontp->size);
|
|
711 XVECTOR (info)->contents[4] = make_number (fontp->height);
|
|
712 XVECTOR (info)->contents[5] = make_number (fontp->baseline_offset);
|
|
713 XVECTOR (info)->contents[6] = make_number (fontp->relative_compose);
|
|
714
|
|
715 return info;
|
|
716 }
|
|
717
|
|
718 DEFUN ("fontset-info", Ffontset_info, Sfontset_info, 1, 2, 0,
|
|
719 "Return information about a fontset named NAME on frame FRAME.\n\
|
|
720 If FRAME is omitted or nil, use the selected frame.\n\
|
|
721 The returned value is a vector of SIZE, HEIGHT, and FONT-LIST,\n\
|
|
722 where\n\
|
|
723 SIZE is the minimum bound width of ASCII font of the fontset,\n\
|
|
724 HEIGHT is the height of the tallest font in the fontset, and\n\
|
|
725 FONT-LIST is an alist of the format:\n\
|
|
726 (CHARSET REQUESTED-FONT-NAME LOADED-FONT-NAME).\n\
|
|
727 LOADED-FONT-NAME t means the font is not yet loaded, nil means the\n\
|
|
728 loading failed.")
|
|
729 (name, frame)
|
|
730 Lisp_Object name, frame;
|
|
731 {
|
|
732 FRAME_PTR f;
|
|
733 int fontset;
|
|
734 struct fontset_info *fontsetp;
|
|
735 Lisp_Object info, val;
|
|
736 int i;
|
|
737
|
|
738 (*check_window_system_func) ();
|
|
739
|
|
740 CHECK_STRING(name, 0);
|
|
741 if (NILP (frame))
|
|
742 f = selected_frame;
|
|
743 else
|
|
744 {
|
|
745 CHECK_LIVE_FRAME (frame, 1);
|
|
746 f = XFRAME (frame);
|
|
747 }
|
|
748
|
|
749 fontset = fs_query_fontset (f, XSTRING (name)->data);
|
|
750 if (fontset < 0)
|
|
751 error ("Fontset \"%s\" does not exist", XSTRING (name)->data);
|
|
752
|
|
753 info = Fmake_vector (make_number (3), Qnil);
|
|
754
|
|
755 fontsetp = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
|
|
756
|
|
757 XVECTOR (info)->contents[0] = make_number (fontsetp->size);
|
|
758 XVECTOR (info)->contents[1] = make_number (fontsetp->height);
|
|
759 val = Qnil;
|
|
760 for (i = 0; i < MAX_CHARSET; i++)
|
|
761 if (fontsetp->fontname[i])
|
|
762 {
|
|
763 int font_idx = fontsetp->font_indexes[i];
|
|
764 Lisp_Object loaded;
|
|
765
|
|
766 if (font_idx == FONT_NOT_OPENED)
|
|
767 loaded = Qt;
|
|
768 else if (font_idx == FONT_NOT_FOUND)
|
|
769 loaded = Qnil;
|
|
770 else
|
|
771 loaded
|
|
772 = build_string ((*get_font_info_func) (f, font_idx)->full_name);
|
|
773 val = Fcons (Fcons (CHARSET_SYMBOL (i),
|
|
774 Fcons (build_string (fontsetp->fontname[i]),
|
|
775 Fcons (loaded, Qnil))),
|
|
776 val);
|
|
777 }
|
|
778 XVECTOR (info)->contents[2] = val;
|
|
779 return info;
|
|
780 }
|
|
781
|
|
782 syms_of_fontset ()
|
|
783 {
|
|
784 int i;
|
|
785
|
|
786 for (i = 0; i < 256; i++)
|
|
787 my_strcasetbl[i] = (i >= 'A' && i <= 'Z') ? i + 'a' - 'A' : i;
|
|
788
|
|
789 if (!load_font_func)
|
|
790 /* Window system initializer should have set proper functions. */
|
|
791 abort ();
|
|
792
|
|
793 staticpro (&Qfontset);
|
|
794
|
|
795 Vcached_fontset_data = Qnil;
|
|
796 staticpro (&Vcached_fontset_data);
|
|
797
|
|
798 DEFVAR_LISP ("global-fontset-alist", &Vglobal_fontset_alist,
|
|
799 "Internal data for fontset. Not for external use.\n\
|
|
800 This is an alist associating fontset names with the lists of fonts\n\
|
|
801 contained in them.\n\
|
|
802 Newly created frames make their own fontset database from here.");
|
|
803 Vglobal_fontset_alist = Qnil;
|
|
804
|
|
805 DEFVAR_LISP ("font-encoding-alist", &Vfont_encoding_alist,
|
|
806 "Alist of fontname patterns vs corresponding encoding info.\n\
|
|
807 Each element looks like (REGEXP . ENCODING-INFO),\n\
|
|
808 where ENCODING-INFO is an alist of CHARSET vs ENCODING.\n\
|
|
809 ENCODING is one of the following integer values:\n\
|
|
810 0: code points 0x20..0x7F or 0x2020..0x7F7F are used,\n\
|
|
811 1: code points 0xA0..0xFF or 0xA0A0..0xFFFF are used,\n\
|
|
812 2: code points 0x20A0..0x7FFF are used,\n\
|
|
813 3: code points 0xA020..0xFF7F are used.");
|
|
814 Vfont_encoding_alist = Qnil;
|
|
815
|
|
816 defsubr (&Squery_fontset);
|
|
817 defsubr (&Snew_fontset);
|
|
818 defsubr (&Sset_fontset_font);
|
|
819 defsubr (&Sfont_info);
|
|
820 defsubr (&Sfontset_info);
|
|
821 }
|