462
|
1 /* X-specific Lisp objects.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Tinker Systems.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
|
25 /* Synched up with: Not in FSF. */
|
|
26
|
|
27 /* Authors: Jamie Zawinski, Chuck Thompson, Ben Wing */
|
|
28 /* Gtk version by William Perry */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "console-gtk.h"
|
|
34 #include "objects-gtk.h"
|
|
35
|
|
36 #include "buffer.h"
|
|
37 #include "device.h"
|
|
38 #include "insdel.h"
|
|
39
|
|
40 /* sigh */
|
|
41 #include <gdk/gdkx.h>
|
|
42
|
|
43
|
|
44 /************************************************************************/
|
|
45 /* color instances */
|
|
46 /************************************************************************/
|
|
47
|
|
48 /* Replacement for XAllocColor() that tries to return the nearest
|
|
49 available color if the colormap is full. Original was from FSFmacs,
|
|
50 but rewritten by Jareth Hein <jareth@camelot-soft.com> 97/11/25
|
|
51 Modified by Lee Kindness <lkindness@csl.co.uk> 31/08/99 to handle previous
|
|
52 total failure which was due to a read/write colorcell being the nearest
|
|
53 match - tries the next nearest...
|
|
54
|
|
55 Gdk takes care of all this behind the scenes, so we don't need to
|
|
56 worry about it.
|
|
57
|
|
58 Return value is 1 for normal success, 2 for nearest color success,
|
|
59 3 for Non-deallocable sucess. */
|
|
60 int
|
|
61 allocate_nearest_color (GdkColormap *colormap, GdkVisual *visual,
|
|
62 GdkColor *color_def)
|
|
63 {
|
|
64 int rc;
|
|
65
|
|
66 rc = gdk_colormap_alloc_color (colormap, color_def, FALSE, TRUE);
|
|
67
|
|
68 if (rc == TRUE)
|
|
69 return (1);
|
|
70
|
|
71 return (0);
|
|
72 }
|
|
73
|
|
74 int
|
867
|
75 gtk_parse_nearest_color (struct device *d, GdkColor *color, Ibyte *name,
|
578
|
76 Bytecount len, Error_Behavior errb)
|
462
|
77 {
|
|
78 GdkColormap *cmap;
|
|
79 GdkVisual *visual;
|
|
80 int result;
|
|
81
|
|
82 cmap = DEVICE_GTK_COLORMAP(d);
|
|
83 visual = DEVICE_GTK_VISUAL (d);
|
|
84
|
|
85 xzero (*color);
|
|
86 {
|
|
87 const Extbyte *extname;
|
665
|
88 Bytecount extnamelen;
|
462
|
89
|
|
90 TO_EXTERNAL_FORMAT (DATA, (name, len), ALLOCA, (extname, extnamelen), Qbinary);
|
|
91
|
|
92 result = gdk_color_parse (extname, color);
|
|
93 }
|
|
94
|
|
95 if (result == FALSE)
|
|
96 {
|
563
|
97 maybe_invalid_argument ("unrecognized color", make_string (name, len),
|
|
98 Qcolor, errb);
|
462
|
99 return 0;
|
|
100 }
|
|
101 result = allocate_nearest_color (cmap, visual, color);
|
|
102 if (!result)
|
|
103 {
|
563
|
104 maybe_signal_error (Qgui_error, "couldn't allocate color",
|
|
105 make_string (name, len), Qcolor, errb);
|
462
|
106 return 0;
|
|
107 }
|
|
108
|
|
109 return result;
|
|
110 }
|
|
111
|
|
112 static int
|
|
113 gtk_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
|
578
|
114 Lisp_Object device, Error_Behavior errb)
|
462
|
115 {
|
|
116 GdkColor color;
|
|
117 int result;
|
|
118
|
|
119 result = gtk_parse_nearest_color (XDEVICE (device), &color,
|
|
120 XSTRING_DATA (name),
|
|
121 XSTRING_LENGTH (name),
|
|
122 errb);
|
|
123
|
|
124 if (!result)
|
|
125 return 0;
|
|
126
|
|
127 /* Don't allocate the data until we're sure that we will succeed,
|
|
128 or the finalize method may get fucked. */
|
|
129 c->data = xnew (struct gtk_color_instance_data);
|
|
130 if (result == 3)
|
|
131 COLOR_INSTANCE_GTK_DEALLOC (c) = 0;
|
|
132 else
|
|
133 COLOR_INSTANCE_GTK_DEALLOC (c) = 1;
|
|
134 COLOR_INSTANCE_GTK_COLOR (c) = gdk_color_copy (&color);
|
|
135 return 1;
|
|
136 }
|
|
137
|
|
138 static void
|
|
139 gtk_print_color_instance (struct Lisp_Color_Instance *c,
|
|
140 Lisp_Object printcharfun,
|
|
141 int escapeflag)
|
|
142 {
|
|
143 GdkColor *color = COLOR_INSTANCE_GTK_COLOR (c);
|
800
|
144 write_fmt_string (printcharfun, " %ld=(%X,%X,%X)",
|
|
145 color->pixel, color->red, color->green, color->blue);
|
462
|
146 }
|
|
147
|
|
148 static void
|
|
149 gtk_finalize_color_instance (struct Lisp_Color_Instance *c)
|
|
150 {
|
|
151 if (c->data)
|
|
152 {
|
|
153 if (DEVICE_LIVE_P (XDEVICE (c->device)))
|
|
154 {
|
|
155 if (COLOR_INSTANCE_GTK_DEALLOC (c))
|
|
156 {
|
|
157 gdk_colormap_free_colors (DEVICE_GTK_COLORMAP (XDEVICE (c->device)),
|
|
158 COLOR_INSTANCE_GTK_COLOR (c), 1);
|
|
159 }
|
|
160 gdk_color_free (COLOR_INSTANCE_GTK_COLOR (c));
|
|
161 }
|
|
162 xfree (c->data);
|
|
163 c->data = 0;
|
|
164 }
|
|
165 }
|
|
166
|
|
167 /* Color instances are equal if they resolve to the same color on the
|
|
168 screen (have the same RGB values). I imagine that
|
|
169 "same RGB values" == "same cell in the colormap." Arguably we should
|
|
170 be comparing their names or pixel values instead. */
|
|
171
|
|
172 static int
|
|
173 gtk_color_instance_equal (struct Lisp_Color_Instance *c1,
|
|
174 struct Lisp_Color_Instance *c2,
|
|
175 int depth)
|
|
176 {
|
|
177 return (gdk_color_equal (COLOR_INSTANCE_GTK_COLOR (c1),
|
|
178 COLOR_INSTANCE_GTK_COLOR (c2)));
|
|
179 }
|
|
180
|
|
181 static unsigned long
|
|
182 gtk_color_instance_hash (struct Lisp_Color_Instance *c, int depth)
|
|
183 {
|
|
184 return (gdk_color_hash (COLOR_INSTANCE_GTK_COLOR (c), NULL));
|
|
185 }
|
|
186
|
|
187 static Lisp_Object
|
|
188 gtk_color_instance_rgb_components (struct Lisp_Color_Instance *c)
|
|
189 {
|
|
190 GdkColor *color = COLOR_INSTANCE_GTK_COLOR (c);
|
|
191 return (list3 (make_int (color->red),
|
|
192 make_int (color->green),
|
|
193 make_int (color->blue)));
|
|
194 }
|
|
195
|
|
196 static int
|
|
197 gtk_valid_color_name_p (struct device *d, Lisp_Object color)
|
|
198 {
|
|
199 GdkColor c;
|
|
200 const char *extname;
|
|
201
|
|
202 TO_EXTERNAL_FORMAT (LISP_STRING, color, C_STRING_ALLOCA, extname, Qctext);
|
|
203
|
|
204 if (gdk_color_parse (extname, &c) != TRUE)
|
|
205 return(0);
|
|
206 return (1);
|
|
207 }
|
|
208
|
|
209
|
|
210 /************************************************************************/
|
|
211 /* font instances */
|
|
212 /************************************************************************/
|
|
213
|
|
214 static int
|
|
215 gtk_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
|
578
|
216 Lisp_Object device, Error_Behavior errb)
|
462
|
217 {
|
|
218 GdkFont *gf;
|
|
219 XFontStruct *xf;
|
|
220 const char *extname;
|
|
221
|
|
222 TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, extname, Qctext);
|
|
223
|
|
224 gf = gdk_font_load (extname);
|
|
225
|
|
226 if (!gf)
|
|
227 {
|
563
|
228 maybe_signal_error (Qgui_error, "couldn't load font", f->name,
|
|
229 Qfont, errb);
|
462
|
230 return 0;
|
|
231 }
|
|
232
|
|
233 xf = GDK_FONT_XFONT (gf);
|
|
234
|
|
235 /* Don't allocate the data until we're sure that we will succeed,
|
|
236 or the finalize method may get fucked. */
|
|
237 f->data = xnew (struct gtk_font_instance_data);
|
|
238 FONT_INSTANCE_GTK_TRUENAME (f) = Qnil;
|
|
239 FONT_INSTANCE_GTK_FONT (f) = gf;
|
|
240 f->ascent = gf->ascent;
|
|
241 f->descent = gf->descent;
|
|
242 f->height = gf->ascent + gf->descent;
|
|
243
|
|
244 /* Now lets figure out the width of the font */
|
|
245 {
|
|
246 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */
|
|
247 unsigned int def_char = 'n'; /*xf->default_char;*/
|
|
248 unsigned int byte1, byte2;
|
|
249
|
|
250 once_more:
|
|
251 byte1 = def_char >> 8;
|
|
252 byte2 = def_char & 0xFF;
|
|
253
|
|
254 if (xf->per_char)
|
|
255 {
|
|
256 /* Old versions of the R5 font server have garbage (>63k) as
|
|
257 def_char. 'n' might not be a valid character. */
|
|
258 if (byte1 < xf->min_byte1 ||
|
|
259 byte1 > xf->max_byte1 ||
|
|
260 byte2 < xf->min_char_or_byte2 ||
|
|
261 byte2 > xf->max_char_or_byte2)
|
|
262 f->width = 0;
|
|
263 else
|
|
264 f->width = xf->per_char[(byte1 - xf->min_byte1) *
|
|
265 (xf->max_char_or_byte2 -
|
|
266 xf->min_char_or_byte2 + 1) +
|
|
267 (byte2 - xf->min_char_or_byte2)].width;
|
|
268 }
|
|
269 else
|
|
270 f->width = xf->max_bounds.width;
|
|
271
|
|
272 /* Some fonts have a default char whose width is 0. This is no good.
|
|
273 If that's the case, first try 'n' as the default char, and if n has
|
|
274 0 width too (unlikely) then just use the max width. */
|
|
275 if (f->width == 0)
|
|
276 {
|
|
277 if (def_char == xf->default_char)
|
|
278 f->width = xf->max_bounds.width;
|
|
279 else
|
|
280 {
|
|
281 def_char = xf->default_char;
|
|
282 goto once_more;
|
|
283 }
|
|
284 }
|
|
285 }
|
|
286
|
|
287 /* If all characters don't exist then there could potentially be
|
|
288 0-width characters lurking out there. Not setting this flag
|
|
289 trips an optimization that would make them appear to have width
|
|
290 to redisplay. This is bad. So we set it if not all characters
|
|
291 have the same width or if not all characters are defined.
|
|
292 */
|
|
293 /* #### This sucks. There is a measurable performance increase
|
|
294 when using proportional width fonts if this flag is not set.
|
|
295 Unfortunately so many of the fucking X fonts are not fully
|
|
296 defined that we could almost just get rid of this damn flag and
|
|
297 make it an assertion. */
|
|
298 f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
|
|
299 (/* x_handle_non_fully_specified_fonts */ 0 &&
|
|
300 !xf->all_chars_exist));
|
|
301 #if 0
|
|
302 f->width = gdk_char_width (gf, 'n');
|
|
303 f->proportional_p = (gdk_char_width (gf, '|') != gdk_char_width (gf, 'W')) ? 1 : 0;
|
|
304 #endif
|
|
305 return 1;
|
|
306 }
|
|
307
|
|
308 static void
|
|
309 gtk_mark_font_instance (struct Lisp_Font_Instance *f)
|
|
310 {
|
|
311 mark_object (FONT_INSTANCE_GTK_TRUENAME (f));
|
|
312 }
|
|
313
|
|
314 static void
|
|
315 gtk_print_font_instance (struct Lisp_Font_Instance *f,
|
|
316 Lisp_Object printcharfun,
|
|
317 int escapeflag)
|
|
318 {
|
800
|
319 write_fmt_string (printcharfun, " 0x%lx",
|
|
320 (unsigned long) gdk_font_id (FONT_INSTANCE_GTK_FONT (f)));
|
462
|
321 }
|
|
322
|
|
323 static void
|
|
324 gtk_finalize_font_instance (struct Lisp_Font_Instance *f)
|
|
325 {
|
|
326 if (f->data)
|
|
327 {
|
|
328 if (DEVICE_LIVE_P (XDEVICE (f->device)))
|
|
329 {
|
|
330 gdk_font_unref (FONT_INSTANCE_GTK_FONT (f));
|
|
331 }
|
|
332 xfree (f->data);
|
|
333 f->data = 0;
|
|
334 }
|
|
335 }
|
|
336
|
|
337 /* Forward declarations for X specific functions at the end of the file */
|
|
338 Lisp_Object __get_gtk_font_truename (GdkFont *gdk_font, int expandp);
|
|
339 static Lisp_Object __gtk_list_fonts_internal (const char *pattern);
|
|
340
|
|
341 static Lisp_Object
|
578
|
342 gtk_font_instance_truename (struct Lisp_Font_Instance *f, Error_Behavior errb)
|
462
|
343 {
|
|
344 if (NILP (FONT_INSTANCE_GTK_TRUENAME (f)))
|
|
345 {
|
|
346 FONT_INSTANCE_GTK_TRUENAME (f) = __get_gtk_font_truename (FONT_INSTANCE_GTK_FONT (f), 1);
|
|
347
|
|
348 if (NILP (FONT_INSTANCE_GTK_TRUENAME (f)))
|
|
349 {
|
|
350 /* Ok, just this once, return the font name as the truename.
|
|
351 (This is only used by Fequal() right now.) */
|
|
352 return f->name;
|
|
353 }
|
|
354 }
|
|
355 return (FONT_INSTANCE_GTK_TRUENAME (f));
|
|
356 }
|
|
357
|
|
358 static Lisp_Object
|
|
359 gtk_font_instance_properties (struct Lisp_Font_Instance *f)
|
|
360 {
|
|
361 Lisp_Object result = Qnil;
|
|
362
|
|
363 /* #### BILL!!! */
|
|
364 /* There seems to be no way to get this information under Gtk */
|
|
365 return result;
|
|
366 }
|
|
367
|
|
368 static Lisp_Object
|
|
369 gtk_list_fonts (Lisp_Object pattern, Lisp_Object device)
|
|
370 {
|
|
371 const char *patternext;
|
|
372
|
|
373 TO_EXTERNAL_FORMAT (LISP_STRING, pattern, C_STRING_ALLOCA, patternext, Qbinary);
|
|
374
|
|
375 return (__gtk_list_fonts_internal (patternext));
|
|
376 }
|
|
377
|
|
378 #ifdef MULE
|
|
379
|
|
380 static int
|
|
381 gtk_font_spec_matches_charset (struct device *d, Lisp_Object charset,
|
867
|
382 const Ibyte *nonreloc, Lisp_Object reloc,
|
462
|
383 Bytecount offset, Bytecount length)
|
|
384 {
|
|
385 if (UNBOUNDP (charset))
|
|
386 return 1;
|
|
387 /* Hack! Short font names don't have the registry in them,
|
|
388 so we just assume the user knows what they're doing in the
|
|
389 case of ASCII. For other charsets, you gotta give the
|
|
390 long form; sorry buster.
|
|
391 */
|
|
392 if (EQ (charset, Vcharset_ascii))
|
|
393 {
|
867
|
394 const Ibyte *the_nonreloc = nonreloc;
|
462
|
395 int i;
|
|
396 Bytecount the_length = length;
|
|
397
|
|
398 if (!the_nonreloc)
|
|
399 the_nonreloc = XSTRING_DATA (reloc);
|
|
400 fixup_internal_substring (nonreloc, reloc, offset, &the_length);
|
|
401 the_nonreloc += offset;
|
|
402 if (!memchr (the_nonreloc, '*', the_length))
|
|
403 {
|
|
404 for (i = 0;; i++)
|
|
405 {
|
867
|
406 const Ibyte *new_nonreloc = (const Ibyte *)
|
462
|
407 memchr (the_nonreloc, '-', the_length);
|
|
408 if (!new_nonreloc)
|
|
409 break;
|
|
410 new_nonreloc++;
|
|
411 the_length -= new_nonreloc - the_nonreloc;
|
|
412 the_nonreloc = new_nonreloc;
|
|
413 }
|
|
414
|
|
415 /* If it has less than 5 dashes, it's a short font.
|
|
416 Of course, long fonts always have 14 dashes or so, but short
|
|
417 fonts never have more than 1 or 2 dashes, so this is some
|
|
418 sort of reasonable heuristic. */
|
|
419 if (i < 5)
|
|
420 return 1;
|
|
421 }
|
|
422 }
|
|
423
|
|
424 return (fast_string_match (XCHARSET_REGISTRY (charset),
|
|
425 nonreloc, reloc, offset, length, 1,
|
|
426 ERROR_ME, 0) >= 0);
|
|
427 }
|
|
428
|
|
429 /* find a font spec that matches font spec FONT and also matches
|
|
430 (the registry of) CHARSET. */
|
|
431 static Lisp_Object gtk_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset);
|
|
432
|
|
433 #endif /* MULE */
|
|
434
|
|
435
|
|
436 /************************************************************************/
|
|
437 /* initialization */
|
|
438 /************************************************************************/
|
|
439
|
|
440 void
|
|
441 syms_of_objects_gtk (void)
|
|
442 {
|
|
443 }
|
|
444
|
|
445 void
|
|
446 console_type_create_objects_gtk (void)
|
|
447 {
|
|
448 /* object methods */
|
|
449
|
|
450 CONSOLE_HAS_METHOD (gtk, initialize_color_instance);
|
|
451 CONSOLE_HAS_METHOD (gtk, print_color_instance);
|
|
452 CONSOLE_HAS_METHOD (gtk, finalize_color_instance);
|
|
453 CONSOLE_HAS_METHOD (gtk, color_instance_equal);
|
|
454 CONSOLE_HAS_METHOD (gtk, color_instance_hash);
|
|
455 CONSOLE_HAS_METHOD (gtk, color_instance_rgb_components);
|
|
456 CONSOLE_HAS_METHOD (gtk, valid_color_name_p);
|
|
457
|
|
458 CONSOLE_HAS_METHOD (gtk, initialize_font_instance);
|
|
459 CONSOLE_HAS_METHOD (gtk, mark_font_instance);
|
|
460 CONSOLE_HAS_METHOD (gtk, print_font_instance);
|
|
461 CONSOLE_HAS_METHOD (gtk, finalize_font_instance);
|
|
462 CONSOLE_HAS_METHOD (gtk, font_instance_truename);
|
|
463 CONSOLE_HAS_METHOD (gtk, font_instance_properties);
|
|
464 CONSOLE_HAS_METHOD (gtk, list_fonts);
|
|
465 #ifdef MULE
|
|
466 CONSOLE_HAS_METHOD (gtk, find_charset_font);
|
|
467 CONSOLE_HAS_METHOD (gtk, font_spec_matches_charset);
|
|
468 #endif
|
|
469 }
|
|
470
|
|
471 void
|
|
472 vars_of_objects_gtk (void)
|
|
473 {
|
|
474 }
|
|
475
|
|
476 /* #### BILL!!! Try to make this go away eventually */
|
|
477 /* X Specific stuff */
|
|
478 #include <X11/Xatom.h>
|
|
479
|
|
480 /* Unbounded, for sufficiently small values of infinity... */
|
|
481 #define MAX_FONT_COUNT 5000
|
|
482
|
|
483 #ifdef MULE
|
|
484 /* find a font spec that matches font spec FONT and also matches
|
|
485 (the registry of) CHARSET. */
|
|
486 static Lisp_Object
|
|
487 gtk_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset)
|
|
488 {
|
|
489 char **names;
|
|
490 int count = 0;
|
|
491 Lisp_Object result = Qnil;
|
|
492 const char *patternext;
|
|
493 int i;
|
|
494
|
|
495 TO_EXTERNAL_FORMAT (LISP_STRING, font, C_STRING_ALLOCA, patternext, Qbinary);
|
|
496
|
|
497 names = XListFonts (GDK_DISPLAY (),
|
|
498 patternext, MAX_FONT_COUNT, &count);
|
788
|
499 /* #### This code seems awfully bogus -- mrb */
|
462
|
500 for (i = 0; i < count; i ++)
|
|
501 {
|
867
|
502 const Ibyte *intname;
|
462
|
503 Bytecount intlen;
|
|
504
|
|
505 TO_INTERNAL_FORMAT (C_STRING, names[i], ALLOCA, (intname, intlen),
|
|
506 Qctext);
|
|
507 if (gtk_font_spec_matches_charset (XDEVICE (device), charset,
|
|
508 intname, Qnil, 0, -1))
|
|
509 {
|
|
510 result = make_string ((char *) intname, intlen);
|
|
511 break;
|
|
512 }
|
|
513 }
|
|
514
|
|
515 if (names)
|
|
516 XFreeFontNames (names);
|
|
517
|
|
518 /* Check for a short font name. */
|
|
519 if (NILP (result)
|
|
520 && gtk_font_spec_matches_charset (XDEVICE (device), charset, 0,
|
|
521 font, 0, -1))
|
|
522 return font;
|
|
523
|
|
524 return result;
|
|
525 }
|
|
526 #endif /* MULE */
|
|
527
|
|
528 /* Unbounded, for sufficiently small values of infinity... */
|
|
529 #define MAX_FONT_COUNT 5000
|
|
530
|
|
531 static int
|
|
532 valid_font_name_p (Display *dpy, char *name)
|
|
533 {
|
|
534 /* Maybe this should be implemented by callign XLoadFont and trapping
|
|
535 the error. That would be a lot of work, and wasteful as hell, but
|
|
536 might be more correct.
|
|
537 */
|
|
538 int nnames = 0;
|
|
539 char **names = 0;
|
|
540 if (! name)
|
|
541 return 0;
|
|
542 names = XListFonts (dpy, name, 1, &nnames);
|
|
543 if (names)
|
|
544 XFreeFontNames (names);
|
|
545 return (nnames != 0);
|
|
546 }
|
|
547
|
|
548 Lisp_Object
|
|
549 __get_gtk_font_truename (GdkFont *gdk_font, int expandp)
|
|
550 {
|
|
551 Display *dpy = GDK_FONT_XDISPLAY (gdk_font);
|
|
552 GSList *names = ((GdkFontPrivate *) gdk_font)->names;
|
|
553 Lisp_Object font_name = Qnil;
|
|
554
|
|
555 while (names)
|
|
556 {
|
|
557 if (names->data)
|
|
558 {
|
|
559 if (valid_font_name_p (dpy, names->data))
|
|
560 {
|
|
561 if (!expandp)
|
|
562 {
|
|
563 /* They want the wildcarded version */
|
|
564 font_name = build_string (names->data);
|
|
565 }
|
|
566 else
|
|
567 {
|
|
568 /* Need to expand out */
|
|
569 int nnames = 0;
|
|
570 char **x_font_names = 0;
|
|
571
|
|
572 x_font_names = XListFonts (dpy, names->data, 1, &nnames);
|
|
573 if (x_font_names)
|
|
574 {
|
|
575 font_name = build_string (x_font_names[0]);
|
|
576 XFreeFontNames (x_font_names);
|
|
577 }
|
|
578 }
|
|
579 break;
|
|
580 }
|
|
581 }
|
|
582 names = names->next;
|
|
583 }
|
|
584 return (font_name);
|
|
585 }
|
|
586
|
|
587 static Lisp_Object __gtk_list_fonts_internal (const char *pattern)
|
|
588 {
|
|
589 char **names;
|
|
590 int count = 0;
|
|
591 Lisp_Object result = Qnil;
|
|
592
|
|
593 names = XListFonts (GDK_DISPLAY (), pattern, MAX_FONT_COUNT, &count);
|
|
594 while (count--)
|
|
595 result = Fcons (build_ext_string (names [count], Qbinary), result);
|
|
596 if (names)
|
|
597 XFreeFontNames (names);
|
|
598
|
|
599 return result;
|
|
600 }
|