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.
|
872
|
5 Copyright (C) 1995, 1996, 2002 Ben Wing.
|
462
|
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
|
872
|
33 #include "buffer.h"
|
|
34 #include "device-impl.h"
|
|
35 #include "insdel.h"
|
462
|
36
|
872
|
37 #include "console-gtk-impl.h"
|
|
38 #include "objects-gtk-impl.h"
|
462
|
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
|
2286
|
61 allocate_nearest_color (GdkColormap *colormap, GdkVisual *UNUSED (visual),
|
462
|
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,
|
2286
|
141 int UNUSED (escapeflag))
|
462
|
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 }
|
1726
|
162 xfree (c->data, void *);
|
462
|
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,
|
2286
|
175 int UNUSED (depth))
|
462
|
176 {
|
|
177 return (gdk_color_equal (COLOR_INSTANCE_GTK_COLOR (c1),
|
|
178 COLOR_INSTANCE_GTK_COLOR (c2)));
|
|
179 }
|
|
180
|
2515
|
181 static Hashcode
|
2286
|
182 gtk_color_instance_hash (struct Lisp_Color_Instance *c, int UNUSED (depth))
|
462
|
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
|
2286
|
197 gtk_valid_color_name_p (struct device *UNUSED (d), Lisp_Object color)
|
462
|
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
|
2527
|
209 static Lisp_Object
|
|
210 gtk_color_list (void)
|
|
211 {
|
|
212 /* #### BILL!!!
|
|
213 Is this correct? */
|
|
214 return call0 (intern ("x-color-list-internal"));
|
|
215 }
|
|
216
|
462
|
217
|
|
218 /************************************************************************/
|
|
219 /* font instances */
|
|
220 /************************************************************************/
|
|
221
|
|
222 static int
|
2286
|
223 gtk_initialize_font_instance (struct Lisp_Font_Instance *f,
|
|
224 Lisp_Object UNUSED (name),
|
|
225 Lisp_Object UNUSED (device), Error_Behavior errb)
|
462
|
226 {
|
|
227 GdkFont *gf;
|
|
228 XFontStruct *xf;
|
|
229 const char *extname;
|
|
230
|
|
231 TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, extname, Qctext);
|
|
232
|
|
233 gf = gdk_font_load (extname);
|
|
234
|
|
235 if (!gf)
|
|
236 {
|
563
|
237 maybe_signal_error (Qgui_error, "couldn't load font", f->name,
|
|
238 Qfont, errb);
|
462
|
239 return 0;
|
|
240 }
|
|
241
|
2054
|
242 xf = (XFontStruct*) GDK_FONT_XFONT (gf);
|
462
|
243
|
|
244 /* Don't allocate the data until we're sure that we will succeed,
|
|
245 or the finalize method may get fucked. */
|
|
246 f->data = xnew (struct gtk_font_instance_data);
|
|
247 FONT_INSTANCE_GTK_FONT (f) = gf;
|
|
248 f->ascent = gf->ascent;
|
|
249 f->descent = gf->descent;
|
|
250 f->height = gf->ascent + gf->descent;
|
|
251
|
|
252 /* Now lets figure out the width of the font */
|
|
253 {
|
|
254 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */
|
|
255 unsigned int def_char = 'n'; /*xf->default_char;*/
|
|
256 unsigned int byte1, byte2;
|
|
257
|
|
258 once_more:
|
|
259 byte1 = def_char >> 8;
|
|
260 byte2 = def_char & 0xFF;
|
|
261
|
|
262 if (xf->per_char)
|
|
263 {
|
|
264 /* Old versions of the R5 font server have garbage (>63k) as
|
|
265 def_char. 'n' might not be a valid character. */
|
|
266 if (byte1 < xf->min_byte1 ||
|
|
267 byte1 > xf->max_byte1 ||
|
|
268 byte2 < xf->min_char_or_byte2 ||
|
|
269 byte2 > xf->max_char_or_byte2)
|
|
270 f->width = 0;
|
|
271 else
|
|
272 f->width = xf->per_char[(byte1 - xf->min_byte1) *
|
|
273 (xf->max_char_or_byte2 -
|
|
274 xf->min_char_or_byte2 + 1) +
|
|
275 (byte2 - xf->min_char_or_byte2)].width;
|
|
276 }
|
|
277 else
|
|
278 f->width = xf->max_bounds.width;
|
|
279
|
|
280 /* Some fonts have a default char whose width is 0. This is no good.
|
|
281 If that's the case, first try 'n' as the default char, and if n has
|
|
282 0 width too (unlikely) then just use the max width. */
|
|
283 if (f->width == 0)
|
|
284 {
|
|
285 if (def_char == xf->default_char)
|
|
286 f->width = xf->max_bounds.width;
|
|
287 else
|
|
288 {
|
|
289 def_char = xf->default_char;
|
|
290 goto once_more;
|
|
291 }
|
|
292 }
|
|
293 }
|
|
294
|
|
295 /* If all characters don't exist then there could potentially be
|
|
296 0-width characters lurking out there. Not setting this flag
|
|
297 trips an optimization that would make them appear to have width
|
|
298 to redisplay. This is bad. So we set it if not all characters
|
|
299 have the same width or if not all characters are defined.
|
|
300 */
|
|
301 /* #### This sucks. There is a measurable performance increase
|
|
302 when using proportional width fonts if this flag is not set.
|
|
303 Unfortunately so many of the fucking X fonts are not fully
|
|
304 defined that we could almost just get rid of this damn flag and
|
|
305 make it an assertion. */
|
|
306 f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
|
|
307 (/* x_handle_non_fully_specified_fonts */ 0 &&
|
|
308 !xf->all_chars_exist));
|
|
309 #if 0
|
|
310 f->width = gdk_char_width (gf, 'n');
|
|
311 f->proportional_p = (gdk_char_width (gf, '|') != gdk_char_width (gf, 'W')) ? 1 : 0;
|
|
312 #endif
|
|
313 return 1;
|
|
314 }
|
|
315
|
|
316 static void
|
|
317 gtk_print_font_instance (struct Lisp_Font_Instance *f,
|
|
318 Lisp_Object printcharfun,
|
2286
|
319 int UNUSED (escapeflag))
|
462
|
320 {
|
800
|
321 write_fmt_string (printcharfun, " 0x%lx",
|
|
322 (unsigned long) gdk_font_id (FONT_INSTANCE_GTK_FONT (f)));
|
462
|
323 }
|
|
324
|
|
325 static void
|
|
326 gtk_finalize_font_instance (struct Lisp_Font_Instance *f)
|
|
327 {
|
|
328 if (f->data)
|
|
329 {
|
|
330 if (DEVICE_LIVE_P (XDEVICE (f->device)))
|
|
331 {
|
|
332 gdk_font_unref (FONT_INSTANCE_GTK_FONT (f));
|
|
333 }
|
1726
|
334 xfree (f->data, void *);
|
462
|
335 f->data = 0;
|
|
336 }
|
|
337 }
|
|
338
|
|
339 /* Forward declarations for X specific functions at the end of the file */
|
|
340 Lisp_Object __get_gtk_font_truename (GdkFont *gdk_font, int expandp);
|
2527
|
341 static Lisp_Object __gtk_font_list_internal (const char *pattern);
|
462
|
342
|
|
343 static Lisp_Object
|
2286
|
344 gtk_font_instance_truename (struct Lisp_Font_Instance *f,
|
|
345 Error_Behavior UNUSED (errb))
|
462
|
346 {
|
872
|
347 if (NILP (FONT_INSTANCE_TRUENAME (f)))
|
462
|
348 {
|
872
|
349 FONT_INSTANCE_TRUENAME (f) = __get_gtk_font_truename (FONT_INSTANCE_GTK_FONT (f), 1);
|
462
|
350
|
872
|
351 if (NILP (FONT_INSTANCE_TRUENAME (f)))
|
462
|
352 {
|
|
353 /* Ok, just this once, return the font name as the truename.
|
|
354 (This is only used by Fequal() right now.) */
|
|
355 return f->name;
|
|
356 }
|
|
357 }
|
872
|
358 return (FONT_INSTANCE_TRUENAME (f));
|
462
|
359 }
|
|
360
|
|
361 static Lisp_Object
|
2286
|
362 gtk_font_instance_properties (struct Lisp_Font_Instance *UNUSED (f))
|
462
|
363 {
|
|
364 Lisp_Object result = Qnil;
|
|
365
|
|
366 /* #### BILL!!! */
|
|
367 /* There seems to be no way to get this information under Gtk */
|
|
368 return result;
|
|
369 }
|
|
370
|
|
371 static Lisp_Object
|
2527
|
372 gtk_font_list (Lisp_Object pattern, Lisp_Object UNUSED (device),
|
2286
|
373 Lisp_Object UNUSED (maxnumber))
|
462
|
374 {
|
|
375 const char *patternext;
|
|
376
|
|
377 TO_EXTERNAL_FORMAT (LISP_STRING, pattern, C_STRING_ALLOCA, patternext, Qbinary);
|
|
378
|
2527
|
379 return (__gtk_font_list_internal (patternext));
|
462
|
380 }
|
|
381
|
|
382 #ifdef MULE
|
|
383
|
|
384 static int
|
2286
|
385 gtk_font_spec_matches_charset (struct device *UNUSED (d), Lisp_Object charset,
|
867
|
386 const Ibyte *nonreloc, Lisp_Object reloc,
|
872
|
387 Bytecount offset, Bytecount length,
|
|
388 int stage)
|
462
|
389 {
|
872
|
390 if (stage)
|
|
391 return 0;
|
|
392
|
462
|
393 if (UNBOUNDP (charset))
|
|
394 return 1;
|
|
395 /* Hack! Short font names don't have the registry in them,
|
|
396 so we just assume the user knows what they're doing in the
|
|
397 case of ASCII. For other charsets, you gotta give the
|
|
398 long form; sorry buster.
|
|
399 */
|
|
400 if (EQ (charset, Vcharset_ascii))
|
|
401 {
|
867
|
402 const Ibyte *the_nonreloc = nonreloc;
|
462
|
403 int i;
|
|
404 Bytecount the_length = length;
|
|
405
|
|
406 if (!the_nonreloc)
|
|
407 the_nonreloc = XSTRING_DATA (reloc);
|
|
408 fixup_internal_substring (nonreloc, reloc, offset, &the_length);
|
|
409 the_nonreloc += offset;
|
|
410 if (!memchr (the_nonreloc, '*', the_length))
|
|
411 {
|
|
412 for (i = 0;; i++)
|
|
413 {
|
867
|
414 const Ibyte *new_nonreloc = (const Ibyte *)
|
462
|
415 memchr (the_nonreloc, '-', the_length);
|
|
416 if (!new_nonreloc)
|
|
417 break;
|
|
418 new_nonreloc++;
|
|
419 the_length -= new_nonreloc - the_nonreloc;
|
|
420 the_nonreloc = new_nonreloc;
|
|
421 }
|
|
422
|
|
423 /* If it has less than 5 dashes, it's a short font.
|
|
424 Of course, long fonts always have 14 dashes or so, but short
|
|
425 fonts never have more than 1 or 2 dashes, so this is some
|
|
426 sort of reasonable heuristic. */
|
|
427 if (i < 5)
|
|
428 return 1;
|
|
429 }
|
|
430 }
|
|
431
|
|
432 return (fast_string_match (XCHARSET_REGISTRY (charset),
|
|
433 nonreloc, reloc, offset, length, 1,
|
|
434 ERROR_ME, 0) >= 0);
|
|
435 }
|
|
436
|
|
437 /* find a font spec that matches font spec FONT and also matches
|
|
438 (the registry of) CHARSET. */
|
950
|
439 static Lisp_Object gtk_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset, int stage);
|
462
|
440
|
|
441 #endif /* MULE */
|
|
442
|
|
443
|
|
444 /************************************************************************/
|
|
445 /* initialization */
|
|
446 /************************************************************************/
|
|
447
|
|
448 void
|
|
449 syms_of_objects_gtk (void)
|
|
450 {
|
|
451 }
|
|
452
|
|
453 void
|
|
454 console_type_create_objects_gtk (void)
|
|
455 {
|
|
456 /* object methods */
|
|
457
|
|
458 CONSOLE_HAS_METHOD (gtk, initialize_color_instance);
|
|
459 CONSOLE_HAS_METHOD (gtk, print_color_instance);
|
|
460 CONSOLE_HAS_METHOD (gtk, finalize_color_instance);
|
|
461 CONSOLE_HAS_METHOD (gtk, color_instance_equal);
|
|
462 CONSOLE_HAS_METHOD (gtk, color_instance_hash);
|
|
463 CONSOLE_HAS_METHOD (gtk, color_instance_rgb_components);
|
|
464 CONSOLE_HAS_METHOD (gtk, valid_color_name_p);
|
2527
|
465 CONSOLE_HAS_METHOD (gtk, color_list);
|
462
|
466
|
|
467 CONSOLE_HAS_METHOD (gtk, initialize_font_instance);
|
|
468 CONSOLE_HAS_METHOD (gtk, print_font_instance);
|
|
469 CONSOLE_HAS_METHOD (gtk, finalize_font_instance);
|
|
470 CONSOLE_HAS_METHOD (gtk, font_instance_truename);
|
|
471 CONSOLE_HAS_METHOD (gtk, font_instance_properties);
|
2527
|
472 CONSOLE_HAS_METHOD (gtk, font_list);
|
462
|
473 #ifdef MULE
|
|
474 CONSOLE_HAS_METHOD (gtk, find_charset_font);
|
|
475 CONSOLE_HAS_METHOD (gtk, font_spec_matches_charset);
|
|
476 #endif
|
|
477 }
|
|
478
|
|
479 void
|
|
480 vars_of_objects_gtk (void)
|
|
481 {
|
|
482 }
|
|
483
|
|
484 /* #### BILL!!! Try to make this go away eventually */
|
|
485 /* X Specific stuff */
|
|
486 #include <X11/Xatom.h>
|
|
487
|
|
488 /* Unbounded, for sufficiently small values of infinity... */
|
|
489 #define MAX_FONT_COUNT 5000
|
|
490
|
|
491 #ifdef MULE
|
|
492 /* find a font spec that matches font spec FONT and also matches
|
|
493 (the registry of) CHARSET. */
|
|
494 static Lisp_Object
|
872
|
495 gtk_find_charset_font (Lisp_Object device, Lisp_Object font,
|
|
496 Lisp_Object charset, int stage)
|
462
|
497 {
|
|
498 char **names;
|
|
499 int count = 0;
|
|
500 Lisp_Object result = Qnil;
|
|
501 const char *patternext;
|
|
502 int i;
|
|
503
|
872
|
504 if (stage)
|
|
505 return Qnil;
|
|
506
|
462
|
507 TO_EXTERNAL_FORMAT (LISP_STRING, font, C_STRING_ALLOCA, patternext, Qbinary);
|
|
508
|
|
509 names = XListFonts (GDK_DISPLAY (),
|
|
510 patternext, MAX_FONT_COUNT, &count);
|
788
|
511 /* #### This code seems awfully bogus -- mrb */
|
462
|
512 for (i = 0; i < count; i ++)
|
|
513 {
|
867
|
514 const Ibyte *intname;
|
462
|
515 Bytecount intlen;
|
|
516
|
|
517 TO_INTERNAL_FORMAT (C_STRING, names[i], ALLOCA, (intname, intlen),
|
|
518 Qctext);
|
|
519 if (gtk_font_spec_matches_charset (XDEVICE (device), charset,
|
872
|
520 intname, Qnil, 0, -1, 0))
|
462
|
521 {
|
2054
|
522 result = make_string (intname, intlen);
|
462
|
523 break;
|
|
524 }
|
|
525 }
|
|
526
|
|
527 if (names)
|
|
528 XFreeFontNames (names);
|
|
529
|
|
530 /* Check for a short font name. */
|
|
531 if (NILP (result)
|
|
532 && gtk_font_spec_matches_charset (XDEVICE (device), charset, 0,
|
872
|
533 font, 0, -1, 0))
|
462
|
534 return font;
|
|
535
|
|
536 return result;
|
|
537 }
|
|
538 #endif /* MULE */
|
|
539
|
|
540 /* Unbounded, for sufficiently small values of infinity... */
|
|
541 #define MAX_FONT_COUNT 5000
|
|
542
|
|
543 static int
|
|
544 valid_font_name_p (Display *dpy, char *name)
|
|
545 {
|
|
546 /* Maybe this should be implemented by callign XLoadFont and trapping
|
|
547 the error. That would be a lot of work, and wasteful as hell, but
|
|
548 might be more correct.
|
|
549 */
|
|
550 int nnames = 0;
|
|
551 char **names = 0;
|
|
552 if (! name)
|
|
553 return 0;
|
|
554 names = XListFonts (dpy, name, 1, &nnames);
|
|
555 if (names)
|
|
556 XFreeFontNames (names);
|
|
557 return (nnames != 0);
|
|
558 }
|
|
559
|
|
560 Lisp_Object
|
|
561 __get_gtk_font_truename (GdkFont *gdk_font, int expandp)
|
|
562 {
|
|
563 Display *dpy = GDK_FONT_XDISPLAY (gdk_font);
|
|
564 GSList *names = ((GdkFontPrivate *) gdk_font)->names;
|
|
565 Lisp_Object font_name = Qnil;
|
|
566
|
|
567 while (names)
|
|
568 {
|
|
569 if (names->data)
|
|
570 {
|
2054
|
571 if (valid_font_name_p (dpy, (char*) names->data))
|
462
|
572 {
|
|
573 if (!expandp)
|
|
574 {
|
|
575 /* They want the wildcarded version */
|
2054
|
576 font_name = build_string ((char*) names->data);
|
462
|
577 }
|
|
578 else
|
|
579 {
|
|
580 /* Need to expand out */
|
|
581 int nnames = 0;
|
|
582 char **x_font_names = 0;
|
|
583
|
2054
|
584 x_font_names = XListFonts (dpy, (char*) names->data, 1, &nnames);
|
462
|
585 if (x_font_names)
|
|
586 {
|
|
587 font_name = build_string (x_font_names[0]);
|
|
588 XFreeFontNames (x_font_names);
|
|
589 }
|
|
590 }
|
|
591 break;
|
|
592 }
|
|
593 }
|
|
594 names = names->next;
|
|
595 }
|
|
596 return (font_name);
|
|
597 }
|
|
598
|
2527
|
599 static Lisp_Object __gtk_font_list_internal (const char *pattern)
|
462
|
600 {
|
|
601 char **names;
|
|
602 int count = 0;
|
|
603 Lisp_Object result = Qnil;
|
|
604
|
|
605 names = XListFonts (GDK_DISPLAY (), pattern, MAX_FONT_COUNT, &count);
|
|
606 while (count--)
|
|
607 result = Fcons (build_ext_string (names [count], Qbinary), result);
|
|
608 if (names)
|
|
609 XFreeFontNames (names);
|
|
610
|
|
611 return result;
|
|
612 }
|